QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
20 #include <QDomDocument>
21 #include <QDomElement>
22 #include <QDomImplementation>
26 #include <QTextStream>
63 return QStringLiteral(
".qmd" );
66 return QStringLiteral(
".qml" );
72 const QString &lyrname,
73 const QString &source )
74 : mDataSource( source )
75 , mLayerName( lyrname )
77 , mUndoStack( new QUndoStack( this ) )
78 , mUndoStackStyles( new QUndoStack( this ) )
80 , mRefreshTimer( new QTimer( this ) )
85 connect( mRefreshTimer, &QTimer::timeout,
this, [ = ] {
triggerRepaint(
true ); } );
100 for (
const QString &s : constStyles )
141 if (
flags == mFlags )
228 mnl = layerElement.namedItem( QStringLiteral(
"provider" ) );
229 mne = mnl.toElement();
230 provider = mne.text();
233 mnl = layerElement.namedItem( QStringLiteral(
"datasource" ) );
234 mne = mnl.toElement();
238 QRegExp rx(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
251 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
252 mne = mnl.toElement();
257 QDomNode srsNode = layerElement.namedItem( QStringLiteral(
"srs" ) );
276 mnl = layerElement.namedItem( QStringLiteral(
"id" ) );
277 if ( ! mnl.isNull() )
279 mne = mnl.toElement();
280 if ( ! mne.isNull() && mne.text().length() > 10 )
286 setAutoRefreshInterval( layerElement.attribute( QStringLiteral(
"autoRefreshTime" ), QStringLiteral(
"0" ) ).toInt() );
287 setAutoRefreshEnabled( layerElement.attribute( QStringLiteral(
"autoRefreshEnabled" ), QStringLiteral(
"0" ) ).toInt() );
289 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral(
"refreshOnNotifyEnabled" ), QStringLiteral(
"0" ) ).toInt() );
292 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
293 mne = mnl.toElement();
296 setName( context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), mne.text() ) );
299 layerError = !
readXml( layerElement, context );
308 QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral(
"shortname" ) );
309 if ( !shortNameElem.isNull() )
315 QDomElement titleElem = layerElement.firstChildElement( QStringLiteral(
"title" ) );
316 if ( !titleElem.isNull() )
318 mTitle = titleElem.text();
322 QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral(
"abstract" ) );
323 if ( !abstractElem.isNull() )
329 QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral(
"keywordList" ) );
330 if ( !keywordListElem.isNull() )
333 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
335 kwdList << n.toElement().text();
341 QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral(
"dataUrl" ) );
342 if ( !dataUrlElem.isNull() )
345 mDataUrlFormat = dataUrlElem.attribute( QStringLiteral(
"format" ), QString() );
349 QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral(
"legendUrl" ) );
350 if ( !legendUrlElem.isNull() )
353 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral(
"format" ), QString() );
357 QDomElement attribElem = layerElement.firstChildElement( QStringLiteral(
"attribution" ) );
358 if ( !attribElem.isNull() )
361 mAttributionUrl = attribElem.attribute( QStringLiteral(
"href" ), QString() );
365 QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral(
"metadataUrl" ) );
366 if ( !metaUrlElem.isNull() )
369 mMetadataUrlType = metaUrlElem.attribute( QStringLiteral(
"type" ), QString() );
374 QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral(
"resourceMetadata" ) );
383 Q_UNUSED( layer_node )
398 layerElement.setAttribute( QStringLiteral(
"autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
399 layerElement.setAttribute( QStringLiteral(
"autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
405 QDomElement layerId = document.createElement( QStringLiteral(
"id" ) );
406 QDomText layerIdText = document.createTextNode(
id() );
407 layerId.appendChild( layerIdText );
409 layerElement.appendChild( layerId );
412 QDomElement dataSource = document.createElement( QStringLiteral(
"datasource" ) );
414 QDomText dataSourceText = document.createTextNode( src );
415 dataSource.appendChild( dataSourceText );
416 layerElement.appendChild( dataSource );
419 QDomElement layerName = document.createElement( QStringLiteral(
"layername" ) );
420 QDomText layerNameText = document.createTextNode(
name() );
421 layerName.appendChild( layerNameText );
422 layerElement.appendChild( layerName );
427 QDomElement layerShortName = document.createElement( QStringLiteral(
"shortname" ) );
428 QDomText layerShortNameText = document.createTextNode(
mShortName );
429 layerShortName.appendChild( layerShortNameText );
430 layerElement.appendChild( layerShortName );
436 QDomElement layerTitle = document.createElement( QStringLiteral(
"title" ) );
437 QDomText layerTitleText = document.createTextNode(
mTitle );
438 layerTitle.appendChild( layerTitleText );
439 layerElement.appendChild( layerTitle );
445 QDomElement layerAbstract = document.createElement( QStringLiteral(
"abstract" ) );
446 QDomText layerAbstractText = document.createTextNode(
mAbstract );
447 layerAbstract.appendChild( layerAbstractText );
448 layerElement.appendChild( layerAbstract );
452 QStringList keywordStringList =
keywordList().split(
',' );
453 if ( !keywordStringList.isEmpty() )
455 QDomElement layerKeywordList = document.createElement( QStringLiteral(
"keywordList" ) );
456 for (
int i = 0; i < keywordStringList.size(); ++i )
458 QDomElement layerKeywordValue = document.createElement( QStringLiteral(
"value" ) );
459 QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
460 layerKeywordValue.appendChild( layerKeywordText );
461 layerKeywordList.appendChild( layerKeywordValue );
463 layerElement.appendChild( layerKeywordList );
468 if ( !aDataUrl.isEmpty() )
470 QDomElement layerDataUrl = document.createElement( QStringLiteral(
"dataUrl" ) );
471 QDomText layerDataUrlText = document.createTextNode( aDataUrl );
472 layerDataUrl.appendChild( layerDataUrlText );
473 layerDataUrl.setAttribute( QStringLiteral(
"format" ),
dataUrlFormat() );
474 layerElement.appendChild( layerDataUrl );
479 if ( !aLegendUrl.isEmpty() )
481 QDomElement layerLegendUrl = document.createElement( QStringLiteral(
"legendUrl" ) );
482 QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
483 layerLegendUrl.appendChild( layerLegendUrlText );
484 layerLegendUrl.setAttribute( QStringLiteral(
"format" ),
legendUrlFormat() );
485 layerElement.appendChild( layerLegendUrl );
490 if ( !aAttribution.isEmpty() )
492 QDomElement layerAttribution = document.createElement( QStringLiteral(
"attribution" ) );
493 QDomText layerAttributionText = document.createTextNode( aAttribution );
494 layerAttribution.appendChild( layerAttributionText );
495 layerAttribution.setAttribute( QStringLiteral(
"href" ),
attributionUrl() );
496 layerElement.appendChild( layerAttribution );
501 if ( !aMetadataUrl.isEmpty() )
503 QDomElement layerMetadataUrl = document.createElement( QStringLiteral(
"metadataUrl" ) );
504 QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
505 layerMetadataUrl.appendChild( layerMetadataUrlText );
506 layerMetadataUrl.setAttribute( QStringLiteral(
"type" ),
metadataUrlType() );
507 layerMetadataUrl.setAttribute( QStringLiteral(
"format" ),
metadataUrlFormat() );
508 layerElement.appendChild( layerMetadataUrl );
514 QDomElement stamp = document.createElement( QStringLiteral(
"timestamp" ) );
515 QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
516 stamp.appendChild( stampText );
517 layerElement.appendChild( stamp );
520 layerElement.appendChild( layerName );
527 QDomElement mySrsElement = document.createElement( QStringLiteral(
"srs" ) );
528 mCRS.
writeXml( mySrsElement, document );
529 layerElement.appendChild( mySrsElement );
532 QDomElement myMetadataElem = document.createElement( QStringLiteral(
"resourceMetadata" ) );
534 layerElement.appendChild( myMetadataElem );
537 return writeXml( layerElement, document, context );
544 QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
545 QString categoriesKeys( metaEnum.valueToKeys(
static_cast<int>( categories ) ) );
546 layerElement.setAttribute( QStringLiteral(
"styleCategories" ), categoriesKeys );
551 layerElement.setAttribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ),
hasScaleBasedVisibility() ? 1 : 0 );
552 layerElement.setAttribute( QStringLiteral(
"maxScale" ), QString::number(
maximumScale() ) );
553 layerElement.setAttribute( QStringLiteral(
"minScale" ), QString::number(
minimumScale() ) );
560 QDomElement renderer3DElem = document.createElement( QStringLiteral(
"renderer-3d" ) );
561 renderer3DElem.setAttribute( QStringLiteral(
"type" ), m3DRenderer->
type() );
562 m3DRenderer->
writeXml( renderer3DElem, context );
563 layerElement.appendChild( renderer3DElem );
571 QDomElement layerFlagsElem = document.createElement( QStringLiteral(
"flags" ) );
572 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
573 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
575 bool flagValue = mFlags.testFlag( it.key() );
576 QDomElement flagElem = document.createElement( it.value() );
577 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
578 layerFlagsElem.appendChild( flagElem );
580 layerElement.appendChild( layerFlagsElem );
583 if ( categories.testFlag(
Temporal ) )
586 if ( lTemporalProperties )
587 lTemporalProperties->
writeXml( layerElement, document, context );
600 Q_UNUSED( layer_node )
631 mCustomProperties.
readXml( layerNode, keyStartsWith );
636 mCustomProperties.
writeXml( layerNode, doc );
641 QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral(
"map-layer-style-manager" ) );
642 if ( !styleMgrElem.isNull() )
643 mStyleManager->
readXml( styleMgrElem );
645 mStyleManager->
reset();
652 QDomElement styleMgrElem = doc.createElement( QStringLiteral(
"map-layer-style-manager" ) );
653 mStyleManager->
writeXml( styleMgrElem );
654 layerNode.appendChild( styleMgrElem );
664 void QgsMapLayer::connectNotify(
const char *signal )
673 return !mScaleBasedVisibility ||
675 && ( mMaxScale == 0 || scale < mMaxScale ) );
680 return mScaleBasedVisibility;
685 return mRefreshTimer->isActive();
690 return mRefreshTimer->interval();
697 mRefreshTimer->stop();
698 mRefreshTimer->setInterval( 0 );
702 mRefreshTimer->setInterval( interval );
710 mRefreshTimer->stop();
711 else if ( mRefreshTimer->interval() > 0 )
712 mRefreshTimer->start();
740 mScaleBasedVisibility = enabled;
750 return QStringList();
793 QString layerName(
name );
794 layerName.replace(
'_',
' ' );
799 QString QgsMapLayer::baseURI( PropertyType type )
const
811 myURI = components[
"path"].toString();
814 QFileInfo myFileInfo( myURI );
817 if ( myFileInfo.exists() )
820 if ( myURI.endsWith( QLatin1String(
".gz" ), Qt::CaseInsensitive ) )
822 else if ( myURI.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) )
824 else if ( myURI.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
826 else if ( myURI.endsWith( QLatin1String(
".tar.gz" ), Qt::CaseInsensitive ) )
828 else if ( myURI.endsWith( QLatin1String(
".tgz" ), Qt::CaseInsensitive ) )
830 myFileInfo.setFile( myURI );
844 return baseURI( PropertyType::Metadata );
859 return baseURI( PropertyType::Style );
869 return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
874 return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
877 bool QgsMapLayer::loadNamedPropertyFromDatabase(
const QString &db,
const QString &uri, QString &xml,
QgsMapLayer::PropertyType type )
881 bool resultFlag =
false;
889 QgsDebugMsgLevel( QStringLiteral(
"Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
891 if ( db.isEmpty() || !QFile( db ).exists() )
894 myResult = database.
open_v2( db, SQLITE_OPEN_READONLY,
nullptr );
895 if ( myResult != SQLITE_OK )
904 mySql = QStringLiteral(
"select qmd from tbl_metadata where metadata=?" );
908 mySql = QStringLiteral(
"select qml from tbl_styles where style=?" );
912 statement = database.
prepare( mySql, myResult );
913 if ( myResult == SQLITE_OK )
915 QByteArray param = uri.toUtf8();
917 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
918 sqlite3_step( statement.get() ) == SQLITE_ROW )
920 xml = QString::fromUtf8(
reinterpret_cast< const char *
>( sqlite3_column_text( statement.get(), 0 ) ) );
930 return loadNamedProperty( uri, PropertyType::Style, resultFlag, categories );
933 QString QgsMapLayer::loadNamedProperty(
const QString &uri,
QgsMapLayer::PropertyType type,
bool &resultFlag, StyleCategories categories )
939 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
943 QString myErrorMessage;
946 if ( myFile.open( QFile::ReadOnly ) )
950 resultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
952 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
958 QgsDebugMsgLevel( QStringLiteral(
"project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
966 ( project.exists() &&
loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), uri, xml ) ) ||
969 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
972 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
977 myErrorMessage = tr(
"Style not found in database" );
985 ( project.exists() &&
loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), uri, xml ) ) ||
988 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
991 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
996 myErrorMessage = tr(
"Metadata not found in database" );
1006 return myErrorMessage;
1014 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1019 myErrorMessage = tr(
"Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1022 return myErrorMessage;
1027 QDomElement myRoot = document.firstChildElement( QStringLiteral(
"qgis" ) );
1028 if ( myRoot.isNull() )
1030 errorMessage = tr(
"Root <qgis> element could not be found" );
1039 QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"qgis" ) );
1040 if ( myRoot.isNull() )
1042 myErrorMessage = tr(
"Root <qgis> element could not be found" );
1047 QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral(
"version" ) ) );
1050 if ( thisVersion > fileVersion )
1067 if ( importLayerGeometryType != QgsWkbTypes::GeometryType::UnknownGeometry && vl->
geometryType() != importLayerGeometryType )
1069 myErrorMessage = tr(
"Cannot apply style with symbology to layer with a different geometry type" );
1076 return readSymbology( myRoot, myErrorMessage, context, categories );
1081 QDomImplementation DomImplementation;
1082 QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1083 QDomDocument myDocument( documentType );
1085 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1086 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1087 myDocument.appendChild( myRootNode );
1091 errorMsg = QObject::tr(
"Could not save metadata" );
1100 QDomImplementation DomImplementation;
1101 QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1102 QDomDocument myDocument( documentType );
1104 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1105 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1106 myDocument.appendChild( myRootNode );
1108 if ( !
writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) )
1110 errorMsg = QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1121 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>(
this );
1122 QString geoType = QString::number( vl->
geometryType() );
1125 QDomElement layerGeometryType = myDocument.createElement( QStringLiteral(
"layerGeometryType" ) );
1126 QDomText
type = myDocument.createTextNode( geoType );
1128 layerGeometryType.appendChild(
type );
1129 myRootNode.appendChild( layerGeometryType );
1150 QString QgsMapLayer::saveNamedProperty(
const QString &uri,
QgsMapLayer::PropertyType type,
bool &resultFlag, StyleCategories categories )
1158 if ( vlayer && vlayer->
providerType() == QLatin1String(
"ogr" ) )
1160 QStringList theURIParts = uri.split(
'|' );
1161 filename = theURIParts[0];
1163 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"gpx" ) )
1165 QStringList theURIParts = uri.split(
'?' );
1166 filename = theURIParts[0];
1168 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"delimitedtext" ) )
1170 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1172 if ( filename.isEmpty() )
1180 QString myErrorMessage;
1181 QDomDocument myDocument;
1194 QFileInfo myFileInfo( filename );
1197 QFileInfo myDirInfo( myFileInfo.path() );
1198 if ( !myDirInfo.isWritable() )
1200 return tr(
"The directory containing your dataset needs to be writable!" );
1206 QFile myFile( myFileName );
1207 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1209 QTextStream myFileStream( &myFile );
1211 myDocument.save( myFileStream, 2 );
1217 return tr(
"Created default metadata file as %1" ).arg( myFileName );
1220 return tr(
"Created default style file as %1" ).arg( myFileName );
1230 return tr(
"ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1233 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1239 QString qml = myDocument.toString();
1246 if ( myResult != SQLITE_OK )
1248 return tr(
"User database could not be opened." );
1251 QByteArray param0 = uri.toUtf8();
1252 QByteArray param1 = qml.toUtf8();
1258 mySql = QStringLiteral(
"create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
1262 mySql = QStringLiteral(
"create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
1266 statement = database.
prepare( mySql, myResult );
1267 if ( myResult == SQLITE_OK )
1269 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
1275 return tr(
"The metadata table could not be created." );
1278 return tr(
"The style table could not be created." );
1286 mySql = QStringLiteral(
"insert into tbl_metadata(metadata,qmd) values (?,?)" );
1290 mySql = QStringLiteral(
"insert into tbl_styles(style,qml) values (?,?)" );
1293 statement = database.
prepare( mySql, myResult );
1294 if ( myResult == SQLITE_OK )
1296 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1297 sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1298 sqlite3_step( statement.get() ) == SQLITE_DONE )
1304 myErrorMessage = tr(
"The metadata %1 was saved to database" ).arg( uri );
1308 myErrorMessage = tr(
"The style %1 was saved to database" ).arg( uri );
1320 mySql = QStringLiteral(
"update tbl_metadata set qmd=? where metadata=?" );
1324 mySql = QStringLiteral(
"update tbl_styles set qml=? where style=?" );
1327 statement = database.
prepare( mySql, myResult );
1328 if ( myResult == SQLITE_OK )
1330 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1331 sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1332 sqlite3_step( statement.get() ) == SQLITE_DONE )
1338 myErrorMessage = tr(
"The metadata %1 was updated in the database." ).arg( uri );
1342 myErrorMessage = tr(
"The style %1 was updated in the database." ).arg( uri );
1352 myErrorMessage = tr(
"The metadata %1 could not be updated in the database." ).arg( uri );
1356 myErrorMessage = tr(
"The style %1 could not be updated in the database." ).arg( uri );
1367 myErrorMessage = tr(
"The metadata %1 could not be inserted into database." ).arg( uri );
1371 myErrorMessage = tr(
"The style %1 could not be inserted into database." ).arg( uri );
1378 return myErrorMessage;
1388 QDomDocument myDocument = QDomDocument();
1390 QDomNode header = myDocument.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
1391 myDocument.appendChild( header );
1393 const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>(
this );
1394 const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>(
this );
1395 if ( !vlayer && !rlayer )
1397 errorMsg = tr(
"Could not save symbology because:\n%1" )
1398 .arg( tr(
"Only vector and raster layers are supported" ) );
1403 QDomElement root = myDocument.createElementNS( QStringLiteral(
"http://www.opengis.net/sld" ), QStringLiteral(
"StyledLayerDescriptor" ) );
1404 QDomElement layerNode;
1407 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1.0" ) );
1408 root.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
1409 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1410 root.setAttribute( QStringLiteral(
"xmlns:se" ), QStringLiteral(
"http://www.opengis.net/se" ) );
1411 root.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1412 root.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1413 myDocument.appendChild( root );
1416 layerNode = myDocument.createElement( QStringLiteral(
"NamedLayer" ) );
1417 root.appendChild( layerNode );
1424 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0.0" ) );
1425 root.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1426 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1427 root.setAttribute( QStringLiteral(
"xmlns:sld" ), QStringLiteral(
"http://www.opengis.net/sld" ) );
1428 myDocument.appendChild( root );
1431 layerNode = myDocument.createElement( QStringLiteral(
"UserLayer" ) );
1432 root.appendChild( layerNode );
1438 props[ QStringLiteral(
"scaleMinDenom" ) ] = QString::number( mMinScale );
1439 props[ QStringLiteral(
"scaleMaxDenom" ) ] = QString::number( mMaxScale );
1444 if ( !vlayer->
writeSld( layerNode, myDocument, errorMsg, props ) )
1446 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1453 if ( !rlayer->
writeSld( layerNode, myDocument, errorMsg, props ) )
1455 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1465 const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>(
this );
1468 QDomDocument myDocument;
1470 if ( !errorMsg.isNull() )
1478 if ( mlayer->
providerType() == QLatin1String(
"ogr" ) )
1480 QStringList theURIParts = uri.split(
'|' );
1481 filename = theURIParts[0];
1483 else if ( mlayer->
providerType() == QLatin1String(
"gpx" ) )
1485 QStringList theURIParts = uri.split(
'?' );
1486 filename = theURIParts[0];
1488 else if ( mlayer->
providerType() == QLatin1String(
"delimitedtext" ) )
1490 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1492 if ( filename.isEmpty() )
1500 QFileInfo myFileInfo( filename );
1501 if ( myFileInfo.exists() || filename.endsWith( QLatin1String(
".sld" ), Qt::CaseInsensitive ) )
1503 QFileInfo myDirInfo( myFileInfo.path() );
1504 if ( !myDirInfo.isWritable() )
1506 return tr(
"The directory containing your dataset needs to be writable!" );
1510 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
1512 QFile myFile( myFileName );
1513 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1515 QTextStream myFileStream( &myFile );
1517 myDocument.save( myFileStream, 2 );
1520 return tr(
"Created default style file as %1" ).arg( myFileName );
1525 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1532 QDomDocument myDocument;
1536 QString myErrorMessage;
1538 QFile myFile( uri );
1539 if ( myFile.open( QFile::ReadOnly ) )
1542 resultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
1544 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1549 myErrorMessage = tr(
"Unable to open file %1" ).arg( uri );
1554 return myErrorMessage;
1558 QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"StyledLayerDescriptor" ) );
1559 if ( myRoot.isNull() )
1561 myErrorMessage = QStringLiteral(
"Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
1563 return myErrorMessage;
1568 QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral(
"NamedLayer" ) );
1569 if ( namedLayerElem.isNull() )
1571 myErrorMessage = QStringLiteral(
"Info: NamedLayer element not found." );
1573 return myErrorMessage;
1577 resultFlag =
readSld( namedLayerElem, errorMsg );
1580 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
1581 return myErrorMessage;
1590 Q_UNUSED( errorMessage )
1592 Q_UNUSED( categories )
1601 Q_UNUSED( errorMessage )
1603 Q_UNUSED( categories )
1609 Q_UNUSED( dataSource )
1610 Q_UNUSED( baseName )
1611 Q_UNUSED( provider )
1613 Q_UNUSED( loadDefaultStyleFlag )
1623 QgsMapLayer::StyleCategories categories )
1628 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral(
"renderer-3d" ) );
1629 if ( !renderer3DElem.isNull() )
1631 QString type3D = renderer3DElem.attribute( QStringLiteral(
"type" ) );
1651 setScaleBasedVisibility( layerElement.attribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1652 if ( layerElement.hasAttribute( QStringLiteral(
"minimumScale" ) ) )
1655 setMaximumScale( layerElement.attribute( QStringLiteral(
"minimumScale" ) ).toDouble() );
1656 setMinimumScale( layerElement.attribute( QStringLiteral(
"maximumScale" ) ).toDouble() );
1660 setMaximumScale( layerElement.attribute( QStringLiteral(
"maxScale" ) ).toDouble() );
1661 setMinimumScale( layerElement.attribute( QStringLiteral(
"minScale" ) ).toDouble() );
1668 QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral(
"flags" ) );
1669 LayerFlags
flags = mFlags;
1670 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1671 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1673 QDomNode flagNode = flagsElem.namedItem( it.value() );
1674 if ( flagNode.isNull() )
1676 bool flagValue = flagNode.toElement().text() ==
"1" ? true :
false;
1677 if (
flags.testFlag( it.key() ) && !flagValue )
1679 else if ( !
flags.testFlag( it.key() ) && flagValue )
1685 if ( categories.testFlag(
Temporal ) )
1688 if ( lTemporalProperties )
1689 lTemporalProperties->
readXml( layerElement.toElement(), context );
1700 return mUndoStackStyles;
1705 return mCustomProperties.
keys();
1710 mCustomProperties.
setValue( key, value );
1715 mCustomProperties = properties;
1720 return mCustomProperties;
1725 return mCustomProperties.
value( value, defaultValue );
1730 mCustomProperties.
remove( key );
1760 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
1761 if ( path.isEmpty() )
1765 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
1766 for (
const QString &tempPath : tempPaths )
1768 if ( path.startsWith( tempPath ) )
1794 mLegend->setParent(
this );
1808 return mStyleManager;
1813 if ( renderer == m3DRenderer )
1817 m3DRenderer = renderer;
1828 if ( mRepaintRequestedFired )
1831 mRepaintRequestedFired =
true;
1833 mRepaintRequestedFired =
false;
1863 bool QgsMapLayer::isReadOnly()
const
1870 return mOriginalXmlProperties;
1881 QString uuid = QUuid::createUuid().toString();
1883 QString
id = layerName +
'_' + uuid.mid( 1, uuid.length() - 2 );
1890 id.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) );
1911 QSet<QgsMapLayerDependency> deps;
1912 const auto constODeps = oDeps;
1927 if ( !lDataProvider )
1943 void QgsMapLayer::onNotifiedTriggerRepaint(
const QString &message )
QStringList styles() const
Returns list of all defined style names.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
QgsCoordinateReferenceSystem crs
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
void flagsChanged()
Emitted when layer's flags have been modified.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
void dependenciesChanged()
Emitted when dependencies are changed.
virtual QString loadSldStyle(const QString &uri, bool &resultFlag)
Attempts to style the layer using the formatting from an SLD type file.
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
virtual QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context)=0
Writes the properties to a DOM element, to be used later with readXml().
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
static QString version()
Version string.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
int open(const QString &path)
Opens the database at the specified file path.
Contains information about the context in which a coordinate transform is executed.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
void configChanged()
Emitted whenever the configuration is changed.
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Setting options for creating vector data providers.
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
The class is used as a container of context for various read/write operations on other objects.
Abstract base class for spatial data provider implementations.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
#define QgsDebugMsgLevel(str, level)
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
Base class for all renderers that may to participate in 3D view.
bool mIsRefreshOnNofifyEnabled
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
virtual bool loadNamedStyleFromDatabase(const QString &db, const QString &uri, QString &qml)
Retrieve a named style for this layer from a sqlite database.
@ Symbology3D
3D symbology
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
bool loadNamedMetadataFromDatabase(const QString &db, const QString &uri, QString &qmd)
Retrieve a named metadata for this layer from a sqlite database.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QgsMapLayerType
Types of layers that can be added to a map.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
QgsError is container for error messages (report).
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
static QgsProject * instance()
Returns the QgsProject singleton instance.
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
An interface for classes which can visit style entity (e.g.
PropertyType
Maplayer has a style and a metadata property.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
virtual QString saveNamedStyle(const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
void notify(const QString &msg)
Emitted when the datasource issues a notification.
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
void reset()
Reset the style manager to a basic state - with one default style which is set as current.
void crsChanged()
Emit a signal that layer's CRS has been reset.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
QgsMapLayerLegend * legend() const
Can be nullptr.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
A rectangle specified with double values.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
virtual QString styleURI() const
Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users styl...
QString mProviderKey
Data provider key (name of the data provider)
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QString saveNamedMetadata(const QString &uri, bool &resultFlag)
Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a re...
@ Rendering
Rendering: scale visibility, simplify method, opacity.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
virtual bool readXml(const QDomElement &element, const QgsReadWriteContext &context)=0
Reads temporal properties from a DOM element previously written by writeXml().
@ Temporal
Temporal properties.
QString mLayerName
Name of the layer - used for display.
virtual QString saveDefaultMetadata(bool &resultFlag)
Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as ...
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
Allows entering a context category and takes care of leaving this category on deletion of the class.
Management of styles for use with one map layer.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
bool mValid
Indicates if the layer is valid and can be drawn.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
QgsRectangle mExtent
Extent of the layer.
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
QString mMetadataUrl
MetadataUrl of the layer.
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString mAttribution
Attribution of the layer.
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode()
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
void isValidChanged()
Emitted when the validity of this layer changed.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
void nameChanged()
Emitted when the name has been changed.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props=QgsStringMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
QString mDataUrl
DataUrl of the layer.
QString mMetadataUrlFormat
QgsMapLayer(QgsMapLayerType type=QgsMapLayerType::VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
virtual bool isEditable() const
Returns true if the layer can be edited.
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Base class for storage of map layer temporal properties.
QString mDataSource
Data source description string, varies by layer type.
static QString pkgDataPath()
Returns the common root path of all application data directories.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
Represents a raster layer.
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
void validate()
Perform some validation on this CRS.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
double minimumScale() const
Returns the minimum map scale (i.e.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
double maximumScale() const
Returns the maximum map scale (i.e.
This class represents a coordinate reference system (CRS).
void remove(const QString &key)
Removes a key (entry) from the store.
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
void legendChanged()
Signal emitted when legend of the layer has changed.
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type)
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
QString legendUrl() const
Returns the URL for the layer's legend.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QString source() const
Returns the source for the layer.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
virtual void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QMap< QString, QString > QgsStringMap
QString mAbstract
Description of the layer.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the docment provided.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
void setName(const QString &name)
Set the display name of the layer.
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Represents a vector layer which manages a vector based data sets.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Base class for all map layer types.
QStringList keys() const
Returns a list of all stored keys.
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
This class models dependencies with or between map layers.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags())
Sets state from DOM document.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
virtual QString loadDefaultMetadata(bool &resultFlag)
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
@ CustomProperties
Custom properties (by plugins for instance)
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
QString mRefreshOnNofifyMessage
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
QString mLegendUrl
WMS legend.
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
virtual QString metadataUri() const
Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users s...
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
void setValidationHint(const QString &html)
Set user hint for validation.
virtual QString saveDefaultStyle(bool &resultFlag)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
void setValid(bool valid)
Sets whether layer is valid or not.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
virtual QString loadNamedMetadata(const QString &uri, bool &resultFlag)
Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record ...
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
QgsLayerMetadata metadata
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
A class to describe the version of a project.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
virtual void setListening(bool isListening)
Set whether the provider will listen to datasource notifications If set, the provider will issue noti...
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual QgsError error() const
Gets current status error.