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 QString uuid = QUuid::createUuid().toString();
86 mID = lyrname +
'_' + uuid.mid( 1, uuid.length() - 2 );
94 mID.replace( QRegExp(
"[\\W]" ), QStringLiteral(
"_" ) );
99 connect( mRefreshTimer, &QTimer::timeout,
this, [ = ] {
triggerRepaint(
true ); } );
106 delete mStyleManager;
113 Q_FOREACH (
const QString &s,
styleManager()->styles() )
153 if ( flags == mFlags )
211 if ( mBlendMode == blendMode )
234 mnl = layerElement.namedItem( QStringLiteral(
"provider" ) );
235 mne = mnl.toElement();
236 provider = mne.text();
239 mnl = layerElement.namedItem( QStringLiteral(
"datasource" ) );
240 mne = mnl.toElement();
244 QRegExp rx(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
257 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
258 mne = mnl.toElement();
263 QDomNode srsNode = layerElement.namedItem( QStringLiteral(
"srs" ) );
278 layerError = !
readXml( layerElement, context );
297 mnl = layerElement.namedItem( QStringLiteral(
"id" ) );
298 if ( ! mnl.isNull() )
300 mne = mnl.toElement();
301 if ( ! mne.isNull() && mne.text().length() > 10 )
307 setAutoRefreshInterval( layerElement.attribute( QStringLiteral(
"autoRefreshTime" ), QStringLiteral(
"0" ) ).toInt() );
308 setAutoRefreshEnabled( layerElement.attribute( QStringLiteral(
"autoRefreshEnabled" ), QStringLiteral(
"0" ) ).toInt() );
310 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral(
"refreshOnNotifyEnabled" ), QStringLiteral(
"0" ) ).toInt() );
314 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
315 mne = mnl.toElement();
318 setName( context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), mne.text() ) );
321 QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral(
"shortname" ) );
322 if ( !shortNameElem.isNull() )
328 QDomElement titleElem = layerElement.firstChildElement( QStringLiteral(
"title" ) );
329 if ( !titleElem.isNull() )
331 mTitle = titleElem.text();
335 QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral(
"abstract" ) );
336 if ( !abstractElem.isNull() )
342 QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral(
"keywordList" ) );
343 if ( !keywordListElem.isNull() )
346 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
348 kwdList << n.toElement().text();
354 QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral(
"dataUrl" ) );
355 if ( !dataUrlElem.isNull() )
358 mDataUrlFormat = dataUrlElem.attribute( QStringLiteral(
"format" ), QString() );
362 QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral(
"legendUrl" ) );
363 if ( !legendUrlElem.isNull() )
366 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral(
"format" ), QString() );
370 QDomElement attribElem = layerElement.firstChildElement( QStringLiteral(
"attribution" ) );
371 if ( !attribElem.isNull() )
374 mAttributionUrl = attribElem.attribute( QStringLiteral(
"href" ), QString() );
378 QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral(
"metadataUrl" ) );
379 if ( !metaUrlElem.isNull() )
382 mMetadataUrlType = metaUrlElem.attribute( QStringLiteral(
"type" ), QString() );
387 QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral(
"resourceMetadata" ) );
396 Q_UNUSED( layer_node );
411 layerElement.setAttribute( QStringLiteral(
"autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
412 layerElement.setAttribute( QStringLiteral(
"autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
418 QDomElement layerId = document.createElement( QStringLiteral(
"id" ) );
419 QDomText layerIdText = document.createTextNode(
id() );
420 layerId.appendChild( layerIdText );
422 layerElement.appendChild( layerId );
425 QDomElement dataSource = document.createElement( QStringLiteral(
"datasource" ) );
427 QDomText dataSourceText = document.createTextNode( src );
428 dataSource.appendChild( dataSourceText );
429 layerElement.appendChild( dataSource );
432 QDomElement layerName = document.createElement( QStringLiteral(
"layername" ) );
433 QDomText layerNameText = document.createTextNode(
name() );
434 layerName.appendChild( layerNameText );
435 layerElement.appendChild( layerName );
440 QDomElement layerShortName = document.createElement( QStringLiteral(
"shortname" ) );
441 QDomText layerShortNameText = document.createTextNode(
mShortName );
442 layerShortName.appendChild( layerShortNameText );
443 layerElement.appendChild( layerShortName );
449 QDomElement layerTitle = document.createElement( QStringLiteral(
"title" ) );
450 QDomText layerTitleText = document.createTextNode(
mTitle );
451 layerTitle.appendChild( layerTitleText );
452 layerElement.appendChild( layerTitle );
458 QDomElement layerAbstract = document.createElement( QStringLiteral(
"abstract" ) );
459 QDomText layerAbstractText = document.createTextNode(
mAbstract );
460 layerAbstract.appendChild( layerAbstractText );
461 layerElement.appendChild( layerAbstract );
465 QStringList keywordStringList =
keywordList().split(
',' );
466 if ( !keywordStringList.isEmpty() )
468 QDomElement layerKeywordList = document.createElement( QStringLiteral(
"keywordList" ) );
469 for (
int i = 0; i < keywordStringList.size(); ++i )
471 QDomElement layerKeywordValue = document.createElement( QStringLiteral(
"value" ) );
472 QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
473 layerKeywordValue.appendChild( layerKeywordText );
474 layerKeywordList.appendChild( layerKeywordValue );
476 layerElement.appendChild( layerKeywordList );
481 if ( !aDataUrl.isEmpty() )
483 QDomElement layerDataUrl = document.createElement( QStringLiteral(
"dataUrl" ) );
484 QDomText layerDataUrlText = document.createTextNode( aDataUrl );
485 layerDataUrl.appendChild( layerDataUrlText );
486 layerDataUrl.setAttribute( QStringLiteral(
"format" ),
dataUrlFormat() );
487 layerElement.appendChild( layerDataUrl );
492 if ( !aLegendUrl.isEmpty() )
494 QDomElement layerLegendUrl = document.createElement( QStringLiteral(
"legendUrl" ) );
495 QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
496 layerLegendUrl.appendChild( layerLegendUrlText );
497 layerLegendUrl.setAttribute( QStringLiteral(
"format" ),
legendUrlFormat() );
498 layerElement.appendChild( layerLegendUrl );
503 if ( !aAttribution.isEmpty() )
505 QDomElement layerAttribution = document.createElement( QStringLiteral(
"attribution" ) );
506 QDomText layerAttributionText = document.createTextNode( aAttribution );
507 layerAttribution.appendChild( layerAttributionText );
508 layerAttribution.setAttribute( QStringLiteral(
"href" ),
attributionUrl() );
509 layerElement.appendChild( layerAttribution );
514 if ( !aMetadataUrl.isEmpty() )
516 QDomElement layerMetadataUrl = document.createElement( QStringLiteral(
"metadataUrl" ) );
517 QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
518 layerMetadataUrl.appendChild( layerMetadataUrlText );
519 layerMetadataUrl.setAttribute( QStringLiteral(
"type" ),
metadataUrlType() );
520 layerMetadataUrl.setAttribute( QStringLiteral(
"format" ),
metadataUrlFormat() );
521 layerElement.appendChild( layerMetadataUrl );
527 QDomElement stamp = document.createElement( QStringLiteral(
"timestamp" ) );
528 QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
529 stamp.appendChild( stampText );
530 layerElement.appendChild( stamp );
533 layerElement.appendChild( layerName );
540 QDomElement mySrsElement = document.createElement( QStringLiteral(
"srs" ) );
541 mCRS.
writeXml( mySrsElement, document );
542 layerElement.appendChild( mySrsElement );
545 QDomElement myMetadataElem = document.createElement( QStringLiteral(
"resourceMetadata" ) );
547 layerElement.appendChild( myMetadataElem );
550 return writeXml( layerElement, document, context );
557 QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
558 QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
559 layerElement.setAttribute( QStringLiteral(
"styleCategories" ), categoriesKeys );
564 layerElement.setAttribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ),
hasScaleBasedVisibility() ? 1 : 0 );
565 layerElement.setAttribute( QStringLiteral(
"maxScale" ), QString::number(
maximumScale() ) );
566 layerElement.setAttribute( QStringLiteral(
"minScale" ), QString::number(
minimumScale() ) );
573 QDomElement renderer3DElem = document.createElement( QStringLiteral(
"renderer-3d" ) );
574 renderer3DElem.setAttribute( QStringLiteral(
"type" ), m3DRenderer->
type() );
575 m3DRenderer->
writeXml( renderer3DElem, context );
576 layerElement.appendChild( renderer3DElem );
584 QDomElement layerFlagsElem = document.createElement( QStringLiteral(
"flags" ) );
585 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
586 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
588 bool flagValue = mFlags.testFlag( it.key() );
589 QDomElement flagElem = document.createElement( it.value() );
590 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
591 layerFlagsElem.appendChild( flagElem );
593 layerElement.appendChild( layerFlagsElem );
606 Q_UNUSED( layer_node );
607 Q_UNUSED( document );
623 Q_UNUSED( dataProvider );
636 mCustomProperties.
readXml( layerNode, keyStartsWith );
641 mCustomProperties.
writeXml( layerNode, doc );
646 QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral(
"map-layer-style-manager" ) );
647 if ( !styleMgrElem.isNull() )
648 mStyleManager->
readXml( styleMgrElem );
650 mStyleManager->
reset();
657 QDomElement styleMgrElem = doc.createElement( QStringLiteral(
"map-layer-style-manager" ) );
658 mStyleManager->
writeXml( styleMgrElem );
659 layerNode.appendChild( styleMgrElem );
669 void QgsMapLayer::connectNotify(
const char *signal )
678 return !mScaleBasedVisibility ||
680 && ( mMaxScale == 0 || scale < mMaxScale ) );
685 return mScaleBasedVisibility;
690 return mRefreshTimer->isActive();
695 return mRefreshTimer->interval();
702 mRefreshTimer->stop();
703 mRefreshTimer->setInterval( 0 );
707 mRefreshTimer->setInterval( interval );
715 mRefreshTimer->stop();
716 else if ( mRefreshTimer->interval() > 0 )
717 mRefreshTimer->start();
745 mScaleBasedVisibility = enabled;
755 return QStringList();
792 QString layerName( name );
793 layerName.replace(
'_',
' ' );
807 if ( providerType == QLatin1String(
"ogr" ) || providerType == QLatin1String(
"delimitedtext" ) ||
808 providerType == QLatin1String(
"spatialite" ) )
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 );
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 );
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 )
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" ) );
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" ) );
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 );
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 );
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 );
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 );
1468 QDomDocument myDocument;
1470 if ( !errorMsg.isNull() )
1480 QStringList theURIParts = uri.split(
'|' );
1481 filename = theURIParts[0];
1485 QStringList theURIParts = uri.split(
'?' );
1486 filename = theURIParts[0];
1488 else if ( mlayer->
dataProvider()->
name() == 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 );
1591 Q_UNUSED( context );
1592 Q_UNUSED( categories );
1601 Q_UNUSED( errorMessage );
1602 Q_UNUSED( context );
1603 Q_UNUSED( categories );
1608 QgsMapLayer::StyleCategories categories )
1613 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral(
"renderer-3d" ) );
1614 if ( !renderer3DElem.isNull() )
1616 QString type3D = renderer3DElem.attribute( QStringLiteral(
"type" ) );
1636 setScaleBasedVisibility( layerElement.attribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1637 if ( layerElement.hasAttribute( QStringLiteral(
"minimumScale" ) ) )
1640 setMaximumScale( layerElement.attribute( QStringLiteral(
"minimumScale" ) ).toDouble() );
1641 setMinimumScale( layerElement.attribute( QStringLiteral(
"maximumScale" ) ).toDouble() );
1645 setMaximumScale( layerElement.attribute( QStringLiteral(
"maxScale" ) ).toDouble() );
1646 setMinimumScale( layerElement.attribute( QStringLiteral(
"minScale" ) ).toDouble() );
1653 QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral(
"flags" ) );
1654 LayerFlags
flags = mFlags;
1655 auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1656 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1658 QDomNode flagNode = flagsElem.namedItem( it.value() );
1659 if ( flagNode.isNull() )
1661 bool flagValue = flagNode.toElement().text() ==
"1" ?
true :
false;
1662 if ( flags.testFlag( it.key() ) && !flagValue )
1664 else if ( !flags.testFlag( it.key() ) && flagValue )
1678 return mUndoStackStyles;
1683 return mCustomProperties.
keys();
1688 mCustomProperties.
setValue( key, value );
1693 mCustomProperties = properties;
1698 return mCustomProperties.
value( value, defaultValue );
1703 mCustomProperties.
remove( key );
1730 if ( legend == mLegend )
1738 mLegend->setParent(
this );
1752 return mStyleManager;
1757 if ( renderer == m3DRenderer )
1761 m3DRenderer = renderer;
1802 static QList<const QgsMapLayer *> _depOutEdges(
const QgsMapLayer *vl,
const QgsMapLayer *that,
const QSet<QgsMapLayerDependency> &layers )
1804 QList<const QgsMapLayer *> lst;
1824 static bool _depHasCycleDFS(
const QgsMapLayer *n, QHash<const QgsMapLayer *, int> &mark,
const QgsMapLayer *that,
const QSet<QgsMapLayerDependency> &layers )
1826 if ( mark.value( n ) == 1 )
1828 if ( mark.value( n ) == 0 )
1831 Q_FOREACH (
const QgsMapLayer *m, _depOutEdges( n, that, layers ) )
1833 if ( _depHasCycleDFS( m, mark, that, layers ) )
1843 QHash<const QgsMapLayer *, int> marks;
1844 return _depHasCycleDFS(
this, marks,
this, layers );
1847 bool QgsMapLayer::isReadOnly()
const 1859 QSet<QgsMapLayerDependency> deps;
1891 void QgsMapLayer::onNotifiedTriggerRepaint(
const QString &message )
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual bool isEditable() const
Returns true if the layer can be edited.
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...
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.
static const QString QGIS_VERSION
Version string.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
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()
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
bool isValid() const
Returns the status of the layer.
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
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.
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...
QString name() const
Returns the display name of the layer.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
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.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
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...
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
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.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
void validate()
Perform some validation on this CRS.
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type) ...
double maximumScale() const
Returns the maximum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
PropertyType
Maplayer has a style and a metadata property.
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
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 writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
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...
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
void crsChanged()
Emit a signal that layer's CRS has been reset.
void configChanged()
Emitted whenever the configuration is changed.
int autoRefreshInterval() const
Returns the auto refresh interval (in milliseconds).
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context)
Sets state from DOM document.
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
QString source() const
Returns the source for the layer.
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)
Returns the components (e.g.
Abstract base class for spatial data provider implementations.
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.
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
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...
void notify(const QString &msg)
Emitted when 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.
QString mLayerName
Name of the layer - used for display.
virtual QString name() const =0
Returns a provider name.
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.
QgsMapLayer(QgsMapLayer::LayerType type=VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
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...
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.
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.
void setValidationHint(const QString &html)
Set user hint for validation.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
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.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
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...
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 QgsRectangle extent() const
Returns the extent of the layer.
Rendering: scale visibility, simplify method, opacity.
LayerType
Types of layers that can be added to a map.
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...
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
void nameChanged()
Emitted when the name has been changed.
A class to describe the version of a project.
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
QStringList keys() const
Returns list of stored keys.
QString mDataUrl
DataUrl of the layer.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
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 id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Reads and writes project states.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
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...
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.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString layerId() const
Returns the ID of the layer this dependency depends on.
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...
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.
Origin origin() const
Returns the dependency origin.
int open(const QString &path)
Opens the database at the specified file path.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
double minimumScale() const
Returns the minimum map scale (i.e.
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...
static QString pkgDataPath()
Returns the common root path of all application data directories.
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
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 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 const QgsLayerMetadata & metadata() const
Returns a reference to the layer's metadata store.
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.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
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.
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayerLegend * legend() const
Can be null.
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.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString providerType() const
Returns the provider type for this layer.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
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)
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones. ...
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...
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.
bool hasDependencyCycle(const QSet< QgsMapLayerDependency > &layers) const
Checks whether a new set of dependencies will introduce a cycle.
QString mDataSource
Data source description string, varies by layer type.
virtual QgsError error() const
Gets current status error.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QString legendUrl() const
Returns the URL for the layer's legend.
QgsMapLayer::LayerFlags flags() const
Returns the flags for this 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.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
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.
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
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...
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
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...
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh 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.
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
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 &)
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaine 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 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.
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
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.
Represents a vector layer which manages a vector based data sets.
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
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.
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
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.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
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 renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
static QString removePassword(const QString &aUri)
Removes password element from uris.
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.