20 #include <QDomDocument> 21 #include <QDomElement> 22 #include <QDomImplementation> 26 #include <QTextStream> 62 return QStringLiteral(
".qmd" );
65 return QStringLiteral(
".qml" );
71 const QString &lyrname,
76 , mUndoStack( new QUndoStack( this ) )
77 , mUndoStackStyles( new QUndoStack( this ) )
79 , mRefreshTimer( new QTimer( this ) )
84 connect( mRefreshTimer, &QTimer::timeout,
this, [ = ] {
triggerRepaint(
true ); } );
99 for (
const QString &s : constStyles )
140 if ( flags == mFlags )
203 if ( mBlendMode == blendMode )
227 mnl = layerElement.namedItem( QStringLiteral(
"provider" ) );
228 mne = mnl.toElement();
229 provider = mne.text();
232 mnl = layerElement.namedItem( QStringLiteral(
"datasource" ) );
233 mne = mnl.toElement();
237 QRegExp rx(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
250 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
251 mne = mnl.toElement();
256 QDomNode srsNode = layerElement.namedItem( QStringLiteral(
"srs" ) );
275 mnl = layerElement.namedItem( QStringLiteral(
"id" ) );
276 if ( ! mnl.isNull() )
278 mne = mnl.toElement();
279 if ( ! mne.isNull() && mne.text().length() > 10 )
285 setAutoRefreshInterval( layerElement.attribute( QStringLiteral(
"autoRefreshTime" ), QStringLiteral(
"0" ) ).toInt() );
286 setAutoRefreshEnabled( layerElement.attribute( QStringLiteral(
"autoRefreshEnabled" ), QStringLiteral(
"0" ) ).toInt() );
288 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral(
"refreshOnNotifyEnabled" ), QStringLiteral(
"0" ) ).toInt() );
291 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
292 mne = mnl.toElement();
295 setName( context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), mne.text() ) );
298 layerError = !
readXml( layerElement, context );
307 QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral(
"shortname" ) );
308 if ( !shortNameElem.isNull() )
314 QDomElement titleElem = layerElement.firstChildElement( QStringLiteral(
"title" ) );
315 if ( !titleElem.isNull() )
317 mTitle = titleElem.text();
321 QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral(
"abstract" ) );
322 if ( !abstractElem.isNull() )
328 QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral(
"keywordList" ) );
329 if ( !keywordListElem.isNull() )
332 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
334 kwdList << n.toElement().text();
340 QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral(
"dataUrl" ) );
341 if ( !dataUrlElem.isNull() )
344 mDataUrlFormat = dataUrlElem.attribute( QStringLiteral(
"format" ), QString() );
348 QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral(
"legendUrl" ) );
349 if ( !legendUrlElem.isNull() )
352 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral(
"format" ), QString() );
356 QDomElement attribElem = layerElement.firstChildElement( QStringLiteral(
"attribution" ) );
357 if ( !attribElem.isNull() )
360 mAttributionUrl = attribElem.attribute( QStringLiteral(
"href" ), QString() );
364 QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral(
"metadataUrl" ) );
365 if ( !metaUrlElem.isNull() )
368 mMetadataUrlType = metaUrlElem.attribute( QStringLiteral(
"type" ), QString() );
373 QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral(
"resourceMetadata" ) );
382 Q_UNUSED( layer_node )
397 layerElement.setAttribute( QStringLiteral(
"autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
398 layerElement.setAttribute( QStringLiteral(
"autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
404 QDomElement layerId = document.createElement( QStringLiteral(
"id" ) );
405 QDomText layerIdText = document.createTextNode(
id() );
406 layerId.appendChild( layerIdText );
408 layerElement.appendChild( layerId );
411 QDomElement dataSource = document.createElement( QStringLiteral(
"datasource" ) );
413 QDomText dataSourceText = document.createTextNode( src );
414 dataSource.appendChild( dataSourceText );
415 layerElement.appendChild( dataSource );
418 QDomElement layerName = document.createElement( QStringLiteral(
"layername" ) );
419 QDomText layerNameText = document.createTextNode(
name() );
420 layerName.appendChild( layerNameText );
421 layerElement.appendChild( layerName );
426 QDomElement layerShortName = document.createElement( QStringLiteral(
"shortname" ) );
427 QDomText layerShortNameText = document.createTextNode(
mShortName );
428 layerShortName.appendChild( layerShortNameText );
429 layerElement.appendChild( layerShortName );
435 QDomElement layerTitle = document.createElement( QStringLiteral(
"title" ) );
436 QDomText layerTitleText = document.createTextNode(
mTitle );
437 layerTitle.appendChild( layerTitleText );
438 layerElement.appendChild( layerTitle );
444 QDomElement layerAbstract = document.createElement( QStringLiteral(
"abstract" ) );
445 QDomText layerAbstractText = document.createTextNode(
mAbstract );
446 layerAbstract.appendChild( layerAbstractText );
447 layerElement.appendChild( layerAbstract );
451 QStringList keywordStringList =
keywordList().split(
',' );
452 if ( !keywordStringList.isEmpty() )
454 QDomElement layerKeywordList = document.createElement( QStringLiteral(
"keywordList" ) );
455 for (
int i = 0; i < keywordStringList.size(); ++i )
457 QDomElement layerKeywordValue = document.createElement( QStringLiteral(
"value" ) );
458 QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
459 layerKeywordValue.appendChild( layerKeywordText );
460 layerKeywordList.appendChild( layerKeywordValue );
462 layerElement.appendChild( layerKeywordList );
467 if ( !aDataUrl.isEmpty() )
469 QDomElement layerDataUrl = document.createElement( QStringLiteral(
"dataUrl" ) );
470 QDomText layerDataUrlText = document.createTextNode( aDataUrl );
471 layerDataUrl.appendChild( layerDataUrlText );
472 layerDataUrl.setAttribute( QStringLiteral(
"format" ),
dataUrlFormat() );
473 layerElement.appendChild( layerDataUrl );
478 if ( !aLegendUrl.isEmpty() )
480 QDomElement layerLegendUrl = document.createElement( QStringLiteral(
"legendUrl" ) );
481 QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
482 layerLegendUrl.appendChild( layerLegendUrlText );
483 layerLegendUrl.setAttribute( QStringLiteral(
"format" ),
legendUrlFormat() );
484 layerElement.appendChild( layerLegendUrl );
489 if ( !aAttribution.isEmpty() )
491 QDomElement layerAttribution = document.createElement( QStringLiteral(
"attribution" ) );
492 QDomText layerAttributionText = document.createTextNode( aAttribution );
493 layerAttribution.appendChild( layerAttributionText );
494 layerAttribution.setAttribute( QStringLiteral(
"href" ),
attributionUrl() );
495 layerElement.appendChild( layerAttribution );
500 if ( !aMetadataUrl.isEmpty() )
502 QDomElement layerMetadataUrl = document.createElement( QStringLiteral(
"metadataUrl" ) );
503 QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
504 layerMetadataUrl.appendChild( layerMetadataUrlText );
505 layerMetadataUrl.setAttribute( QStringLiteral(
"type" ),
metadataUrlType() );
506 layerMetadataUrl.setAttribute( QStringLiteral(
"format" ),
metadataUrlFormat() );
507 layerElement.appendChild( layerMetadataUrl );
513 QDomElement stamp = document.createElement( QStringLiteral(
"timestamp" ) );
514 QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
515 stamp.appendChild( stampText );
516 layerElement.appendChild( stamp );
519 layerElement.appendChild( layerName );
526 QDomElement mySrsElement = document.createElement( QStringLiteral(
"srs" ) );
527 mCRS.
writeXml( mySrsElement, document );
528 layerElement.appendChild( mySrsElement );
531 QDomElement myMetadataElem = document.createElement( QStringLiteral(
"resourceMetadata" ) );
533 layerElement.appendChild( myMetadataElem );
536 return writeXml( layerElement, document, context );
543 QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
544 QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
545 layerElement.setAttribute( QStringLiteral(
"styleCategories" ), categoriesKeys );
550 layerElement.setAttribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ),
hasScaleBasedVisibility() ? 1 : 0 );
551 layerElement.setAttribute( QStringLiteral(
"maxScale" ), QString::number(
maximumScale() ) );
552 layerElement.setAttribute( QStringLiteral(
"minScale" ), QString::number(
minimumScale() ) );
559 QDomElement renderer3DElem = document.createElement( QStringLiteral(
"renderer-3d" ) );
560 renderer3DElem.setAttribute( QStringLiteral(
"type" ), m3DRenderer->
type() );
561 m3DRenderer->
writeXml( renderer3DElem, context );
562 layerElement.appendChild( renderer3DElem );
570 QDomElement layerFlagsElem = document.createElement( QStringLiteral(
"flags" ) );
571 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
572 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
574 bool flagValue = mFlags.testFlag( it.key() );
575 QDomElement flagElem = document.createElement( it.value() );
576 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
577 layerFlagsElem.appendChild( flagElem );
579 layerElement.appendChild( layerFlagsElem );
592 Q_UNUSED( layer_node )
609 Q_UNUSED( dataProvider )
623 mCustomProperties.
readXml( layerNode, keyStartsWith );
628 mCustomProperties.
writeXml( layerNode, doc );
633 QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral(
"map-layer-style-manager" ) );
634 if ( !styleMgrElem.isNull() )
635 mStyleManager->
readXml( styleMgrElem );
637 mStyleManager->
reset();
644 QDomElement styleMgrElem = doc.createElement( QStringLiteral(
"map-layer-style-manager" ) );
645 mStyleManager->
writeXml( styleMgrElem );
646 layerNode.appendChild( styleMgrElem );
656 void QgsMapLayer::connectNotify(
const char *signal )
665 return !mScaleBasedVisibility ||
667 && ( mMaxScale == 0 || scale < mMaxScale ) );
672 return mScaleBasedVisibility;
677 return mRefreshTimer->isActive();
682 return mRefreshTimer->interval();
689 mRefreshTimer->stop();
690 mRefreshTimer->setInterval( 0 );
694 mRefreshTimer->setInterval( interval );
702 mRefreshTimer->stop();
703 else if ( mRefreshTimer->interval() > 0 )
704 mRefreshTimer->start();
732 mScaleBasedVisibility = enabled;
742 return QStringList();
784 QString layerName( name );
785 layerName.replace(
'_',
' ' );
802 myURI = components[
"path"].toString();
805 QFileInfo myFileInfo( myURI );
808 if ( myFileInfo.exists() )
811 if ( myURI.endsWith( QLatin1String(
".gz" ), Qt::CaseInsensitive ) )
813 else if ( myURI.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) )
815 else if ( myURI.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
817 else if ( myURI.endsWith( QLatin1String(
".tar.gz" ), Qt::CaseInsensitive ) )
819 else if ( myURI.endsWith( QLatin1String(
".tgz" ), Qt::CaseInsensitive ) )
821 myFileInfo.setFile( myURI );
835 return baseURI( PropertyType::Metadata );
850 return baseURI( PropertyType::Style );
860 return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
865 return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
872 bool resultFlag =
false;
880 QgsDebugMsgLevel( QStringLiteral(
"Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
882 if ( db.isEmpty() || !QFile( db ).exists() )
885 myResult = database.
open_v2( db, SQLITE_OPEN_READONLY,
nullptr );
886 if ( myResult != SQLITE_OK )
895 mySql = QStringLiteral(
"select qmd from tbl_metadata where metadata=?" );
899 mySql = QStringLiteral(
"select qml from tbl_styles where style=?" );
903 statement = database.
prepare( mySql, myResult );
904 if ( myResult == SQLITE_OK )
906 QByteArray param = uri.toUtf8();
908 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
909 sqlite3_step( statement.get() ) == SQLITE_ROW )
911 xml = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
921 return loadNamedProperty( uri, PropertyType::Style, resultFlag, categories );
930 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
934 QString myErrorMessage;
937 if ( myFile.open( QFile::ReadOnly ) )
941 resultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
943 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
949 QgsDebugMsgLevel( QStringLiteral(
"project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
957 ( project.exists() &&
loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), uri, xml ) ) ||
960 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
963 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
968 myErrorMessage = tr(
"Style not found in database" );
976 ( project.exists() &&
loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() +
".qmldb" ), uri, xml ) ) ||
979 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
982 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
987 myErrorMessage = tr(
"Metadata not found in database" );
997 return myErrorMessage;
1005 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1010 myErrorMessage = tr(
"Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1013 return myErrorMessage;
1018 QDomElement myRoot = document.firstChildElement( QStringLiteral(
"qgis" ) );
1019 if ( myRoot.isNull() )
1021 errorMessage = tr(
"Root <qgis> element could not be found" );
1030 QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"qgis" ) );
1031 if ( myRoot.isNull() )
1033 myErrorMessage = tr(
"Root <qgis> element could not be found" );
1038 QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral(
"version" ) ) );
1041 if ( thisVersion > fileVersion )
1060 myErrorMessage = tr(
"Cannot apply style with symbology to layer with a different geometry type" );
1067 return readSymbology( myRoot, myErrorMessage, context, categories );
1072 QDomImplementation DomImplementation;
1073 QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1074 QDomDocument myDocument( documentType );
1076 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1077 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1078 myDocument.appendChild( myRootNode );
1082 errorMsg = QObject::tr(
"Could not save metadata" );
1091 QDomImplementation DomImplementation;
1092 QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1093 QDomDocument myDocument( documentType );
1095 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1096 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1097 myDocument.appendChild( myRootNode );
1099 if ( !
writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) )
1101 errorMsg = QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1113 QString geoType = QString::number( vl->
geometryType() );
1116 QDomElement layerGeometryType = myDocument.createElement( QStringLiteral(
"layerGeometryType" ) );
1117 QDomText
type = myDocument.createTextNode( geoType );
1119 layerGeometryType.appendChild( type );
1120 myRootNode.appendChild( layerGeometryType );
1149 if ( vlayer && vlayer->
providerType() == QLatin1String(
"ogr" ) )
1151 QStringList theURIParts = uri.split(
'|' );
1152 filename = theURIParts[0];
1154 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"gpx" ) )
1156 QStringList theURIParts = uri.split(
'?' );
1157 filename = theURIParts[0];
1159 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"delimitedtext" ) )
1161 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1163 if ( filename.isEmpty() )
1171 QString myErrorMessage;
1172 QDomDocument myDocument;
1185 QFileInfo myFileInfo( filename );
1188 QFileInfo myDirInfo( myFileInfo.path() );
1189 if ( !myDirInfo.isWritable() )
1191 return tr(
"The directory containing your dataset needs to be writable!" );
1197 QFile myFile( myFileName );
1198 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1200 QTextStream myFileStream( &myFile );
1202 myDocument.save( myFileStream, 2 );
1208 return tr(
"Created default metadata file as %1" ).arg( myFileName );
1211 return tr(
"Created default style file as %1" ).arg( myFileName );
1221 return tr(
"ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1224 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1230 QString qml = myDocument.toString();
1237 if ( myResult != SQLITE_OK )
1239 return tr(
"User database could not be opened." );
1242 QByteArray param0 = uri.toUtf8();
1243 QByteArray param1 = qml.toUtf8();
1249 mySql = QStringLiteral(
"create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
1253 mySql = QStringLiteral(
"create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
1257 statement = database.
prepare( mySql, myResult );
1258 if ( myResult == SQLITE_OK )
1260 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
1266 return tr(
"The metadata table could not be created." );
1269 return tr(
"The style table could not be created." );
1277 mySql = QStringLiteral(
"insert into tbl_metadata(metadata,qmd) values (?,?)" );
1281 mySql = QStringLiteral(
"insert into tbl_styles(style,qml) values (?,?)" );
1284 statement = database.
prepare( mySql, myResult );
1285 if ( myResult == SQLITE_OK )
1287 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1288 sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1289 sqlite3_step( statement.get() ) == SQLITE_DONE )
1295 myErrorMessage = tr(
"The metadata %1 was saved to database" ).arg( uri );
1299 myErrorMessage = tr(
"The style %1 was saved to database" ).arg( uri );
1311 mySql = QStringLiteral(
"update tbl_metadata set qmd=? where metadata=?" );
1315 mySql = QStringLiteral(
"update tbl_styles set qml=? where style=?" );
1318 statement = database.
prepare( mySql, myResult );
1319 if ( myResult == SQLITE_OK )
1321 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1322 sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1323 sqlite3_step( statement.get() ) == SQLITE_DONE )
1329 myErrorMessage = tr(
"The metadata %1 was updated in the database." ).arg( uri );
1333 myErrorMessage = tr(
"The style %1 was updated in the database." ).arg( uri );
1343 myErrorMessage = tr(
"The metadata %1 could not be updated in the database." ).arg( uri );
1347 myErrorMessage = tr(
"The style %1 could not be updated in the database." ).arg( uri );
1358 myErrorMessage = tr(
"The metadata %1 could not be inserted into database." ).arg( uri );
1362 myErrorMessage = tr(
"The style %1 could not be inserted into database." ).arg( uri );
1369 return myErrorMessage;
1379 QDomDocument myDocument = QDomDocument();
1381 QDomNode header = myDocument.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
1382 myDocument.appendChild( header );
1386 if ( !vlayer && !rlayer )
1388 errorMsg = tr(
"Could not save symbology because:\n%1" )
1389 .arg( tr(
"Only vector and raster layers are supported" ) );
1394 QDomElement root = myDocument.createElementNS( QStringLiteral(
"http://www.opengis.net/sld" ), QStringLiteral(
"StyledLayerDescriptor" ) );
1395 QDomElement layerNode;
1398 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1.0" ) );
1399 root.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
1400 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1401 root.setAttribute( QStringLiteral(
"xmlns:se" ), QStringLiteral(
"http://www.opengis.net/se" ) );
1402 root.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
1403 root.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
1404 myDocument.appendChild( root );
1407 layerNode = myDocument.createElement( QStringLiteral(
"NamedLayer" ) );
1408 root.appendChild( layerNode );
1415 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0.0" ) );
1416 root.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
1417 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
1418 root.setAttribute( QStringLiteral(
"xmlns:sld" ), QStringLiteral(
"http://www.opengis.net/sld" ) );
1419 myDocument.appendChild( root );
1422 layerNode = myDocument.createElement( QStringLiteral(
"UserLayer" ) );
1423 root.appendChild( layerNode );
1429 props[ QStringLiteral(
"scaleMinDenom" ) ] = QString::number( mMinScale );
1430 props[ QStringLiteral(
"scaleMaxDenom" ) ] = QString::number( mMaxScale );
1435 if ( !vlayer->
writeSld( layerNode, myDocument, errorMsg, props ) )
1437 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1444 if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1446 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1459 QDomDocument myDocument;
1461 if ( !errorMsg.isNull() )
1469 if ( mlayer->
providerType() == QLatin1String(
"ogr" ) )
1471 QStringList theURIParts = uri.split(
'|' );
1472 filename = theURIParts[0];
1474 else if ( mlayer->
providerType() == QLatin1String(
"gpx" ) )
1476 QStringList theURIParts = uri.split(
'?' );
1477 filename = theURIParts[0];
1479 else if ( mlayer->
providerType() == QLatin1String(
"delimitedtext" ) )
1481 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1483 if ( filename.isEmpty() )
1491 QFileInfo myFileInfo( filename );
1492 if ( myFileInfo.exists() || filename.endsWith( QLatin1String(
".sld" ), Qt::CaseInsensitive ) )
1494 QFileInfo myDirInfo( myFileInfo.path() );
1495 if ( !myDirInfo.isWritable() )
1497 return tr(
"The directory containing your dataset needs to be writable!" );
1501 QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
1503 QFile myFile( myFileName );
1504 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1506 QTextStream myFileStream( &myFile );
1508 myDocument.save( myFileStream, 2 );
1511 return tr(
"Created default style file as %1" ).arg( myFileName );
1516 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1523 QDomDocument myDocument;
1527 QString myErrorMessage;
1529 QFile myFile( uri );
1530 if ( myFile.open( QFile::ReadOnly ) )
1533 resultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
1535 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1540 myErrorMessage = tr(
"Unable to open file %1" ).arg( uri );
1545 return myErrorMessage;
1549 QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"StyledLayerDescriptor" ) );
1550 if ( myRoot.isNull() )
1552 myErrorMessage = QStringLiteral(
"Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
1554 return myErrorMessage;
1559 QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral(
"NamedLayer" ) );
1560 if ( namedLayerElem.isNull() )
1562 myErrorMessage = QStringLiteral(
"Info: NamedLayer element not found." );
1564 return myErrorMessage;
1568 resultFlag =
readSld( namedLayerElem, errorMsg );
1571 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
1572 return myErrorMessage;
1581 Q_UNUSED( errorMessage )
1583 Q_UNUSED( categories )
1592 Q_UNUSED( errorMessage )
1594 Q_UNUSED( categories )
1600 Q_UNUSED( dataSource )
1601 Q_UNUSED( baseName )
1602 Q_UNUSED( provider )
1604 Q_UNUSED( loadDefaultStyleFlag )
1614 QgsMapLayer::StyleCategories categories )
1619 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral(
"renderer-3d" ) );
1620 if ( !renderer3DElem.isNull() )
1622 QString type3D = renderer3DElem.attribute( QStringLiteral(
"type" ) );
1642 setScaleBasedVisibility( layerElement.attribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1643 if ( layerElement.hasAttribute( QStringLiteral(
"minimumScale" ) ) )
1646 setMaximumScale( layerElement.attribute( QStringLiteral(
"minimumScale" ) ).toDouble() );
1647 setMinimumScale( layerElement.attribute( QStringLiteral(
"maximumScale" ) ).toDouble() );
1651 setMaximumScale( layerElement.attribute( QStringLiteral(
"maxScale" ) ).toDouble() );
1652 setMinimumScale( layerElement.attribute( QStringLiteral(
"minScale" ) ).toDouble() );
1659 QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral(
"flags" ) );
1660 LayerFlags
flags = mFlags;
1661 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1662 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1664 QDomNode flagNode = flagsElem.namedItem( it.value() );
1665 if ( flagNode.isNull() )
1667 bool flagValue = flagNode.toElement().text() ==
"1" ? true :
false;
1668 if ( flags.testFlag( it.key() ) && !flagValue )
1670 else if ( !flags.testFlag( it.key() ) && flagValue )
1684 return mUndoStackStyles;
1689 return mCustomProperties.
keys();
1694 mCustomProperties.
setValue( key, value );
1699 mCustomProperties = properties;
1704 return mCustomProperties.
value( value, defaultValue );
1709 mCustomProperties.
remove( key );
1739 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
1740 if ( path.isEmpty() )
1744 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
1745 for (
const QString &tempPath : tempPaths )
1747 if ( path.startsWith( tempPath ) )
1761 if ( legend == mLegend )
1769 mLegend->setParent(
this );
1783 return mStyleManager;
1788 if ( renderer == m3DRenderer )
1792 m3DRenderer = renderer;
1803 if ( mRepaintRequestedFired )
1806 mRepaintRequestedFired =
true;
1808 mRepaintRequestedFired =
false;
1838 bool QgsMapLayer::isReadOnly()
const 1845 return mOriginalXmlProperties;
1856 QString uuid = QUuid::createUuid().toString();
1858 QString
id = layerName +
'_' + uuid.mid( 1, uuid.length() - 2 );
1865 id.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) );
1886 QSet<QgsMapLayerDependency> deps;
1887 const auto constODeps = oDeps;
1917 void QgsMapLayer::onNotifiedTriggerRepaint(
const QString &message )
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.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
The class is used as a container of context for various read/write operations on other objects...
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
A rectangle specified with double values.
Base class for all map layer types.
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
QStringList styles() const
Returns list of all defined style names.
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
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.
Base class for all renderers that may to participate in 3D view.
QgsMapLayerType type() const
Returns the type of the layer.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
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...
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=nullptr)
Sets state from DOM document.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from XML.
void reset()
Reset the style manager to a basic state - with one default style which is set as current...
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QgsMapLayerLegend * legend() const
Can be nullptr.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual QgsError error() const
Gets current status error.
Represents a raster layer.
void validate()
Perform some validation on this CRS.
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.
QString mProviderKey
Data provider key (name of the data provider)
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
QString providerType() const
Returns the provider type (provider key) for this layer.
PropertyType
Maplayer has a style and a metadata property.
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
virtual bool loadNamedStyleFromDatabase(const QString &db, const QString &uri, QString &qml)
Retrieve a named style for this layer from a sqlite database.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects...
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...
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
void crsChanged()
Emit a signal that layer's CRS has been reset.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
void configChanged()
Emitted whenever the configuration is changed.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns value for the given key. If the key is not stored, default value will be used.
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Allows entering a context category and takes care of leaving this category on deletion of the class...
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Abstract base class for spatial data provider implementations.
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...
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...
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
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...
bool isValid() const
Returns the status of the layer.
An interface for classes which can visit style entity (e.g.
void notify(const QString &msg)
Emitted when the datasource issues a notification.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
bool mIsRefreshOnNofifyEnabled
QMap< QString, QString > QgsStringMap
void remove(const QString &key)
Remove a key (entry) from the store.
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
QString mLayerName
Name of the layer - used for display.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
void styleChanged()
Signal emitted whenever a change affects the layer's style.
bool loadNamedMetadataFromDatabase(const QString &db, const QString &uri, QString &qmd)
Retrieve a named metadata for this layer from a sqlite database.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
virtual QgsRectangle extent() const
Returns the extent of the layer.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
QgsRectangle mExtent
Extent of the layer.
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
QString mMetadataUrl
MetadataUrl of the layer.
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
void setValidationHint(const QString &html)
Set user hint for validation.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store. If the entry with the keys exists already, it will be overwritten.
static QString version()
Version string.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted...
int autoRefreshInterval() const
Returns the auto refresh interval (in milliseconds).
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
#define QgsDebugMsgLevel(str, level)
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
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...
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
Rendering: scale visibility, simplify method, opacity.
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.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
virtual void setListening(bool isListening)
Set whether the provider will listen to datasource notifications If set, the provider will issue noti...
void nameChanged()
Emitted when the name has been changed.
A class to describe the version of a project.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
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.
QString mDataUrl
DataUrl of the layer.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
virtual bool isEditable() const
Returns true if the layer can be edited.
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 ...
QString legendUrl() const
Returns the URL for the layer's legend.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
double minimumScale() const
Returns the minimum map scale (i.e.
Contains information about the context in which a coordinate transform is executed.
double maximumScale() const
Returns the maximum map scale (i.e.
bool mValid
Indicates if the layer is valid and can be drawn.
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.
int open(const QString &path)
Opens the database at the specified file path.
QStringList keys() const
Returns list of stored keys.
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.
Convert just the first letter of each word to uppercase, leave the rest untouched.
QString mMetadataUrlFormat
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files...
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
static QString pkgDataPath()
Returns the common root path of all application data directories.
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
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 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.
QString mAttribution
Attribution of the layer.
QString mAbstract
Description of the layer.
General configuration: identifiable, removable, searchable, display expression, read-only.
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode() ...
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.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QString mRefreshOnNofifyMessage
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
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.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
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...
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 ...
Custom properties (by plugins for instance)
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones. ...
Setting options for creating vector data providers.
QString name() const
Returns the display name of the layer.
QgsMapLayer(QgsMapLayerType type=QgsMapLayerType::VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
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.
QString mDataSource
Data source description string, varies by layer type.
QString source() const
Returns the source for the layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QgsError is container for error messages (report).
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type) ...
QString mLegendUrl
WMS legend.
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 ...
This class represents a coordinate reference system (CRS).
void legendChanged()
Signal emitted when legend of the layer has changed.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
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.
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.
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
QgsMapLayerType
Types of layers that can be added to a map.
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request. ...
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled, the notification will triggerRepaint only if the notification message is equal to.
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 ...
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
This class models dependencies with or between map layers.
Management of styles for use with one map layer.
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Represents a vector layer which manages a vector based data sets.
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.
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
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 - should be used in constructor.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
void flagsChanged()
Emitted when layer's flags have been modified.
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
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.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.