60#include <QDomDocument>
62#include <QDomImplementation>
67#include <QRegularExpression>
68#include <QStandardPaths>
73#include <QXmlStreamReader>
75#include "moc_qgsmaplayer.cpp"
77using namespace Qt::StringLiterals;
97 , mUndoStack( new QUndoStack( this ) )
98 , mUndoStackStyles( new QUndoStack( this ) )
100 , mRefreshTimer( new QTimer( this ) )
105 connect( mRefreshTimer, &QTimer::timeout,
this, [
this] {
106 switch ( mAutoRefreshMode )
136 for (
const QString &s : constStyles )
146 layer->mExtent3D = mExtent3D;
148 layer->mExtent2D = mExtent2D;
182 if (
flags == mFlags )
207 if ( qobject_cast< QgsMapLayerStore * >( parent() ) )
265 mServerProperties->setShortName(
shortName );
272 return mServerProperties->shortName();
279 mServerProperties->setTitle(
title );
286 return mServerProperties->title();
293 mServerProperties->setAbstract(
abstract );
300 return mServerProperties->abstract();
307 mServerProperties->setKeywordList( keywords );
314 return mServerProperties->keywordList();
321 mServerProperties->setDataUrl(
dataUrl );
328 return mServerProperties->dataUrl();
342 return mServerProperties->dataUrlFormat();
349 mServerProperties->setAttribution( attrib );
356 return mServerProperties->attribution();
363 mServerProperties->setAttributionUrl( attribUrl );
370 return mServerProperties->attributionUrl();
377 mServerProperties->setLegendUrl(
legendUrl );
384 return mServerProperties->legendUrl();
398 return mServerProperties->legendUrlFormat();
406 if ( urls.isEmpty() )
409 urls.prepend( newItem );
415 urls.prepend( newItem );
424 if ( mServerProperties->metadataUrls().isEmpty() )
426 return QLatin1String();
430 return mServerProperties->metadataUrls().first().url;
438 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
439 if ( urls.isEmpty() )
442 urls.prepend( newItem );
448 urls.prepend( newItem );
450 mServerProperties->setMetadataUrls( urls );
457 if ( mServerProperties->metadataUrls().isEmpty() )
459 return QLatin1String();
463 return mServerProperties->metadataUrls().first().type;
471 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
472 if ( urls.isEmpty() )
475 urls.prepend( newItem );
481 urls.prepend( newItem );
483 mServerProperties->setMetadataUrls( urls );
490 if ( mServerProperties->metadataUrls().isEmpty() )
496 return mServerProperties->metadataUrls().first().format;
527 return mExtent2D.isNull() ? mExtent3D.toRectangle() : mExtent2D;
594 mnl = layerElement.namedItem( u
"provider"_s );
595 mne = mnl.toElement();
596 provider = mne.text();
599 mnl = layerElement.namedItem( u
"datasource"_s );
600 mne = mnl.toElement();
601 const QString dataSourceRaw = mne.text();
604 const thread_local QRegularExpression rx(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
616 mnl = layerElement.namedItem( u
"layername"_s );
617 mne = mnl.toElement();
622 const QDomNode srsNode = layerElement.namedItem( u
"srs"_s );
623 mCRS.readXml( srsNode );
624 mCRS.setValidationHint( tr(
"Specify CRS for layer %1" ).arg( mne.text() ) );
641 mnl = layerElement.namedItem( u
"id"_s );
644 mne = mnl.toElement();
645 if ( !mne.isNull() && mne.text().length() > 10 )
647 const QString newId = mne.text();
657 mnl = layerElement.namedItem( u
"layername"_s );
658 mne = mnl.toElement();
664 layerError = !
readXml( layerElement, context );
678 const QDomNode verticalCrsNode = layerElement.firstChildElement( u
"verticalCrs"_s );
679 if ( !verticalCrsNode.isNull() )
690 const QDomElement metadataElem = layerElement.firstChildElement( u
"resourceMetadata"_s );
691 mMetadata.readMetadataXml( metadataElem, context );
694 if ( layerElement.hasAttribute( u
"autoRefreshMode"_s ) )
708 const QDomNode wgs84ExtentNode = layerElement.namedItem( u
"wgs84extent"_s );
709 if ( !wgs84ExtentNode.isNull() )
713 mLegendPlaceholderImage = layerElement.attribute( u
"legendPlaceholderImage"_s );
717 if ( mCrs3D != oldCrs3D )
728 Q_UNUSED( layer_node )
735 const QDomNode extent3DNode = layer_node.namedItem( u
"extent3D"_s );
736 if ( extent3DNode.isNull() )
738 const QDomNode extentNode = layer_node.namedItem( u
"extent"_s );
739 if ( !extentNode.isNull() )
775 layerElement.setAttribute( u
"autoRefreshTime"_s, QString::number( mRefreshTimer->interval() ) );
776 layerElement.setAttribute( u
"autoRefreshMode"_s,
qgsEnumValueToKey( mAutoRefreshMode ) );
781 QDomElement layerId = document.createElement( u
"id"_s );
782 const QDomText layerIdText = document.createTextNode(
id() );
783 layerId.appendChild( layerIdText );
785 layerElement.appendChild( layerId );
787 if ( mVerticalCrs.isValid() )
789 QDomElement verticalSrsNode = document.createElement( u
"verticalCrs"_s );
790 mVerticalCrs.writeXml( verticalSrsNode, document );
791 layerElement.appendChild( verticalSrsNode );
795 QDomElement dataSource = document.createElement( u
"datasource"_s );
797 const QDomText dataSourceText = document.createTextNode( src );
798 dataSource.appendChild( dataSourceText );
799 layerElement.appendChild( dataSource );
802 QDomElement layerName = document.createElement( u
"layername"_s );
803 const QDomText layerNameText = document.createTextNode(
name() );
804 layerName.appendChild( layerNameText );
805 layerElement.appendChild( layerName );
810 QDomElement stamp = document.createElement( u
"timestamp"_s );
811 const QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
812 stamp.appendChild( stampText );
813 layerElement.appendChild( stamp );
816 layerElement.appendChild( layerName );
823 QDomElement mySrsElement = document.createElement( u
"srs"_s );
824 mCRS.writeXml( mySrsElement, document );
825 layerElement.appendChild( mySrsElement );
828 QDomElement myMetadataElem = document.createElement( u
"resourceMetadata"_s );
829 mMetadata.writeMetadataXml( myMetadataElem, document );
830 layerElement.appendChild( myMetadataElem );
832 layerElement.setAttribute( u
"legendPlaceholderImage"_s, mLegendPlaceholderImage );
837 return writeXml( layerElement, document, context );
845 const QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
846 const QString categoriesKeys( metaEnum.valueToKeys(
static_cast<int>( categories ) ) );
847 layerElement.setAttribute( u
"styleCategories"_s, categoriesKeys );
856 layerElement.setAttribute( u
"maxScale"_s, QString::number(
maximumScale() ) );
857 layerElement.setAttribute( u
"minScale"_s, QString::number(
minimumScale() ) );
858 layerElement.setAttribute( u
"autoRefreshMode"_s,
qgsEnumValueToKey( mAutoRefreshMode ) );
859 layerElement.setAttribute( u
"autoRefreshTime"_s, QString::number(
autoRefreshInterval() ) );
866 QDomElement renderer3DElem = document.createElement( u
"renderer-3d"_s );
867 renderer3DElem.setAttribute( u
"type"_s, m3DRenderer->type() );
868 m3DRenderer->writeXml( renderer3DElem, context );
869 layerElement.appendChild( renderer3DElem );
877 QDomElement layerFlagsElem = document.createElement( u
"flags"_s );
879 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
881 const bool flagValue = mFlags.testFlag( it.key() );
882 QDomElement flagElem = document.createElement( it.value() );
883 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
884 layerFlagsElem.appendChild( flagElem );
886 layerElement.appendChild( layerFlagsElem );
889 if ( categories.testFlag(
Temporal ) )
892 properties->writeXml( layerElement, document, context );
898 properties->writeXml( layerElement, document, context );
903 QDomElement notesElem = document.createElement( u
"userNotes"_s );
905 layerElement.appendChild( notesElem );
920 Q_UNUSED( layer_node )
951 m3DRenderer->resolveReferences( *
project );
961 mCustomProperties.
readXml( layerNode, keyStartsWith );
963 for (
const QString &key : mCustomProperties.keys() )
965 if ( !oldKeys.contains( key ) || mCustomProperties.value( key ) != oldKeys.value( key ) )
976 mCustomProperties.writeXml( layerNode, doc );
983 const QDomElement styleMgrElem = layerNode.firstChildElement( u
"map-layer-style-manager"_s );
984 if ( !styleMgrElem.isNull() )
985 mStyleManager->readXml( styleMgrElem );
987 mStyleManager->reset();
996 QDomElement styleMgrElem = doc.createElement( u
"map-layer-style-manager"_s );
997 mStyleManager->writeXml( styleMgrElem );
998 layerNode.appendChild( styleMgrElem );
1006 return mMapTipTemplate;
1013 if ( mMapTipTemplate == mapTip )
1016 mMapTipTemplate = mapTip;
1024 if ( mMapTipsEnabled == enabled )
1027 mMapTipsEnabled = enabled;
1035 return mMapTipsEnabled;
1052 const QDomNode extent3DNode = layerNode.namedItem( u
"extent3D"_s );
1053 if ( extent3DNode.isNull() )
1055 const QDomNode extentNode = layerNode.namedItem( u
"extent"_s );
1056 if ( !extentNode.isNull() )
1079void QgsMapLayer::connectNotify(
const char *signal )
1093 return !mScaleBasedVisibility
1102 return mScaleBasedVisibility;
1117 return mAutoRefreshMode;
1124 return mRefreshTimer->interval();
1131 if ( interval <= 0 )
1133 mRefreshTimer->stop();
1134 mRefreshTimer->setInterval( 0 );
1139 mRefreshTimer->setInterval( interval );
1155 if ( mode == mAutoRefreshMode )
1158 mAutoRefreshMode = mode;
1159 switch ( mAutoRefreshMode )
1162 mRefreshTimer->stop();
1167 if ( mRefreshTimer->interval() > 0 )
1168 mRefreshTimer->start();
1207 mScaleBasedVisibility = enabled;
1221 return QStringList();
1259 switch ( mCRS.type() )
1262 QgsDebugError( u
"Layer has a vertical CRS set as the horizontal CRS!"_s );
1266 return mCRS.verticalCrs();
1281 return mVerticalCrs;
1288 return mCrs3D.isValid() ? mCrs3D : mCRS;
1296 if ( mCRS == srs && !needToValidateCrs )
1305 if ( needToValidateCrs )
1307 mCRS.setValidationHint( tr(
"Specify CRS for layer %1" ).arg(
name() ) );
1313 if ( emitSignal && mCRS != oldCrs )
1319 if ( oldCrs3D != mCrs3D )
1327 if (
crs.isValid() )
1330 switch (
crs.type() )
1348 *errorMessage = QObject::tr(
"Specified CRS is a %1 CRS, not a Vertical CRS" ).arg(
qgsEnumValueToKey(
crs.type() ) );
1353 if (
crs != mVerticalCrs )
1358 switch ( mCRS.type() )
1361 if (
crs != oldVerticalCrs )
1364 *errorMessage = QObject::tr(
"Layer CRS is a Compound CRS, specified Vertical CRS will be ignored" );
1370 if (
crs != oldVerticalCrs )
1373 *errorMessage = QObject::tr(
"Layer CRS is a Geographic 3D CRS, specified Vertical CRS will be ignored" );
1379 if (
crs != oldVerticalCrs )
1382 *errorMessage = QObject::tr(
"Layer CRS is a Geocentric CRS, specified Vertical CRS will be ignored" );
1388 if ( mCRS.hasVerticalAxis() &&
crs != oldVerticalCrs )
1391 *errorMessage = QObject::tr(
"Layer CRS is a Projected 3D CRS, specified Vertical CRS will be ignored" );
1409 res = rebuildCrs3D( errorMessage );
1415 if ( mCrs3D != oldCrs3D )
1431 QString layerName(
name );
1432 layerName.replace(
'_',
' ' );
1437QString QgsMapLayer::baseURI( PropertyType type )
const
1450 myURI = components[
"path"].toString();
1453 QFileInfo myFileInfo( myURI );
1456 if ( myFileInfo.exists() )
1459 if ( myURI.endsWith(
".gz"_L1, Qt::CaseInsensitive ) )
1461 else if ( myURI.endsWith(
".zip"_L1, Qt::CaseInsensitive ) )
1463 else if ( myURI.endsWith(
".tar"_L1, Qt::CaseInsensitive ) )
1465 else if ( myURI.endsWith(
".tar.gz"_L1, Qt::CaseInsensitive ) )
1467 else if ( myURI.endsWith(
".tgz"_L1, Qt::CaseInsensitive ) )
1469 myFileInfo.setFile( myURI );
1498 QString errorMessage;
1501 return tr(
"Successfully saved default layer metadata" );
1503 return errorMessage;
1552bool QgsMapLayer::loadNamedPropertyFromDatabase(
const QString &db,
const QString &uri, QString &xml,
QgsMapLayer::PropertyType type )
1558 bool resultFlag =
false;
1566 QgsDebugMsgLevel( u
"Trying to load style or metadata for \"%1\" from \"%2\""_s.arg( uri, db ), 4 );
1568 if ( db.isEmpty() || !QFile( db ).exists() )
1571 myResult = database.
open_v2( db, SQLITE_OPEN_READONLY,
nullptr );
1572 if ( myResult != SQLITE_OK )
1581 mySql = u
"select qmd from tbl_metadata where metadata=?"_s;
1585 mySql = u
"select qml from tbl_styles where style=?"_s;
1589 statement = database.
prepare( mySql, myResult );
1590 if ( myResult == SQLITE_OK )
1592 QByteArray param = uri.toUtf8();
1594 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
1596 xml = QString::fromUtf8(
reinterpret_cast< const char *
>( sqlite3_column_text( statement.get(), 0 ) ) );
1617 namedPropertyExists =
false;
1618 propertySuccessfullyLoaded =
false;
1619 if ( uri.isEmpty() )
1622 QDomDocument myDocument( u
"qgis"_s );
1626 QString myErrorMessage;
1628 QFile myFile( uri );
1629 if ( myFile.open( QFile::ReadOnly ) )
1632 namedPropertyExists =
true;
1635 propertySuccessfullyLoaded = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
1636 if ( !propertySuccessfullyLoaded )
1637 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1642 QString projectFileName;
1643 if ( QgsProject *lProject =
project() )
1645 projectFileName = lProject->fileName();
1648 const QFileInfo
project( projectFileName );
1660 namedPropertyExists =
true;
1661 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1662 if ( !propertySuccessfullyLoaded )
1664 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1671 myErrorMessage = tr(
"Style not found in database" );
1682 namedPropertyExists =
true;
1683 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1684 if ( !propertySuccessfullyLoaded )
1686 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1691 myErrorMessage = tr(
"Metadata not found in database" );
1698 if ( !propertySuccessfullyLoaded )
1700 return myErrorMessage;
1706 propertySuccessfullyLoaded =
importNamedStyle( myDocument, myErrorMessage, categories );
1707 if ( !propertySuccessfullyLoaded )
1708 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1712 if ( !propertySuccessfullyLoaded )
1713 myErrorMessage = tr(
"Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1716 return myErrorMessage;
1723 const QDomElement myRoot = document.firstChildElement( u
"qgis"_s );
1724 if ( myRoot.isNull() )
1726 errorMessage = tr(
"Root <qgis> element could not be found" );
1730 return mMetadata.readMetadataXml( myRoot );
1737 const QDomElement myRoot = myDocument.firstChildElement( u
"qgis"_s );
1738 if ( myRoot.isNull() )
1740 myErrorMessage = tr(
"Root <qgis> element could not be found" );
1748 if ( thisVersion > fileVersion )
1767 myErrorMessage = tr(
"Cannot apply style with symbology to layer with a different geometry type" );
1775 return readSymbology( myRoot, myErrorMessage, context, categories & sourceCategories );
1782 QDomImplementation DomImplementation;
1783 const QDomDocumentType documentType = DomImplementation.createDocumentType( u
"qgis"_s, u
"http://mrcc.com/qgis.dtd"_s, u
"SYSTEM"_s );
1784 QDomDocument myDocument( documentType );
1786 QDomElement myRootNode = myDocument.createElement( u
"qgis"_s );
1788 myDocument.appendChild( myRootNode );
1790 if ( !mMetadata.writeMetadataXml( myRootNode, myDocument ) )
1792 errorMsg = QObject::tr(
"Could not save metadata" );
1803 QDomImplementation DomImplementation;
1804 const QDomDocumentType documentType = DomImplementation.createDocumentType( u
"qgis"_s, u
"http://mrcc.com/qgis.dtd"_s, u
"SYSTEM"_s );
1805 QDomDocument myDocument( documentType );
1807 QDomElement myRootNode = myDocument.createElement( u
"qgis"_s );
1809 myDocument.appendChild( myRootNode );
1811 if ( !
writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) )
1813 errorMsg = QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1824 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>(
this );
1825 const QString geoType = QString::number(
static_cast<int>( vl->
geometryType() ) );
1828 QDomElement layerGeometryType = myDocument.createElement( u
"layerGeometryType"_s );
1829 const QDomText
type = myDocument.createTextNode( geoType );
1831 layerGeometryType.appendChild(
type );
1832 myRootNode.appendChild( layerGeometryType );
1863 bool metadataExists =
false;
1864 bool metadataSuccessfullyLoaded =
false;
1865 const QString message = loadNamedProperty( uri,
QgsMapLayer::Metadata, metadataExists, metadataSuccessfullyLoaded );
1868 ( void ) metadataExists;
1869 resultFlag = metadataSuccessfullyLoaded;
1873QString QgsMapLayer::saveNamedProperty(
const QString &uri,
QgsMapLayer::PropertyType type,
bool &resultFlag, StyleCategories categories )
1885 QStringList theURIParts = uri.split(
'|' );
1886 filename = theURIParts[0];
1888 else if ( vlayer && vlayer->
providerType() ==
"gpx"_L1 )
1890 QStringList theURIParts = uri.split(
'?' );
1891 filename = theURIParts[0];
1893 else if ( vlayer && vlayer->
providerType() ==
"delimitedtext"_L1 )
1895 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1897 if ( filename.isEmpty() )
1905 QString myErrorMessage;
1906 QDomDocument myDocument;
1914 const QgsReadWriteContext context;
1919 const QFileInfo myFileInfo( filename );
1922 const QFileInfo myDirInfo( myFileInfo.path() );
1923 if ( !myDirInfo.isWritable() )
1926 return tr(
"The directory containing your dataset needs to be writable!" );
1932 QFile myFile( myFileName );
1933 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1935 QTextStream myFileStream( &myFile );
1937 myDocument.save( myFileStream, 2 );
1943 return tr(
"Created default metadata file as %1" ).arg( myFileName );
1946 return tr(
"Created default style file as %1" ).arg( myFileName );
1955 return tr(
"ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1958 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1964 const QString qml = myDocument.toString();
1967 sqlite3_database_unique_ptr database;
1968 sqlite3_statement_unique_ptr statement;
1971 if ( myResult != SQLITE_OK )
1973 return tr(
"User database could not be opened." );
1976 QByteArray param0 = uri.toUtf8();
1977 QByteArray param1 = qml.toUtf8();
1983 mySql = u
"create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)"_s;
1987 mySql = u
"create table if not exists tbl_styles(style varchar primary key,qml varchar)"_s;
1991 statement = database.
prepare( mySql, myResult );
1992 if ( myResult == SQLITE_OK )
1994 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
2000 return tr(
"The metadata table could not be created." );
2003 return tr(
"The style table could not be created." );
2011 mySql = u
"insert into tbl_metadata(metadata,qmd) values (?,?)"_s;
2015 mySql = u
"insert into tbl_styles(style,qml) values (?,?)"_s;
2018 statement = database.
prepare( mySql, myResult );
2019 if ( myResult == SQLITE_OK )
2021 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK
2022 && sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK
2023 && sqlite3_step( statement.get() ) == SQLITE_DONE )
2029 myErrorMessage = tr(
"The metadata %1 was saved to database" ).arg( uri );
2033 myErrorMessage = tr(
"The style %1 was saved to database" ).arg( uri );
2045 mySql = u
"update tbl_metadata set qmd=? where metadata=?"_s;
2049 mySql = u
"update tbl_styles set qml=? where style=?"_s;
2052 statement = database.
prepare( mySql, myResult );
2053 if ( myResult == SQLITE_OK )
2055 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK
2056 && sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK
2057 && sqlite3_step( statement.get() ) == SQLITE_DONE )
2063 myErrorMessage = tr(
"The metadata %1 was updated in the database." ).arg( uri );
2067 myErrorMessage = tr(
"The style %1 was updated in the database." ).arg( uri );
2077 myErrorMessage = tr(
"The metadata %1 could not be updated in the database." ).arg( uri );
2081 myErrorMessage = tr(
"The style %1 could not be updated in the database." ).arg( uri );
2092 myErrorMessage = tr(
"The metadata %1 could not be inserted into database." ).arg( uri );
2096 myErrorMessage = tr(
"The style %1 could not be inserted into database." ).arg( uri );
2103 return myErrorMessage;
2117 if ( !exportContext.
errors().empty() )
2118 errorMsg = exportContext.
errors().join(
"\n" );
2125 if ( !exportContext.
errors().empty() )
2126 errorMsg = exportContext.
errors().join(
"\n" );
2133 QDomDocument myDocument = QDomDocument();
2135 const QDomNode header = myDocument.createProcessingInstruction( u
"xml"_s, u
"version=\"1.0\" encoding=\"UTF-8\""_s );
2136 myDocument.appendChild( header );
2138 const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>(
this );
2139 const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>(
this );
2140 if ( !vlayer && !rlayer )
2142 exportContext.
pushError( tr(
"Could not save symbology because:\n%1" ).arg( tr(
"Only vector and raster layers are supported" ) ) );
2147 QDomElement root = myDocument.createElementNS( u
"http://www.opengis.net/sld"_s, u
"StyledLayerDescriptor"_s );
2148 QDomElement layerNode;
2151 root.setAttribute( u
"version"_s, u
"1.1.0"_s );
2152 root.setAttribute( u
"xsi:schemaLocation"_s, u
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd"_s );
2153 root.setAttribute( u
"xmlns:ogc"_s, u
"http://www.opengis.net/ogc"_s );
2154 root.setAttribute( u
"xmlns:se"_s, u
"http://www.opengis.net/se"_s );
2155 root.setAttribute( u
"xmlns:xlink"_s, u
"http://www.w3.org/1999/xlink"_s );
2156 root.setAttribute( u
"xmlns:xsi"_s, u
"http://www.w3.org/2001/XMLSchema-instance"_s );
2157 myDocument.appendChild( root );
2160 layerNode = myDocument.createElement( u
"NamedLayer"_s );
2161 root.appendChild( layerNode );
2168 root.setAttribute( u
"version"_s, u
"1.0.0"_s );
2169 root.setAttribute( u
"xmlns:gml"_s, u
"http://www.opengis.net/gml"_s );
2170 root.setAttribute( u
"xmlns:ogc"_s, u
"http://www.opengis.net/ogc"_s );
2171 root.setAttribute( u
"xmlns:sld"_s, u
"http://www.opengis.net/sld"_s );
2172 myDocument.appendChild( root );
2175 layerNode = myDocument.createElement( u
"UserLayer"_s );
2176 root.appendChild( layerNode );
2182 context.setValue( exportContext );
2185 props[u
"SldExportContext"_s] = context;
2189 props[u
"scaleMinDenom"_s] = QString::number( mMinScale );
2190 props[u
"scaleMaxDenom"_s] = QString::number( mMaxScale );
2196 if ( !vlayer->
writeSld( layerNode, myDocument, exportContext ) )
2203 if ( !rlayer->
writeSld( layerNode, myDocument, exportContext ) )
2223 const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>(
this );
2230 if ( mlayer->providerType() ==
"ogr"_L1 )
2232 QStringList theURIParts = uri.split(
'|' );
2233 filename = theURIParts[0];
2235 else if ( mlayer->providerType() ==
"gpx"_L1 )
2237 QStringList theURIParts = uri.split(
'?' );
2238 filename = theURIParts[0];
2240 else if ( mlayer->providerType() ==
"delimitedtext"_L1 )
2242 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
2244 if ( filename.isEmpty() )
2252 const QFileInfo myFileInfo( filename );
2253 if ( myFileInfo.exists() || filename.endsWith(
".sld"_L1, Qt::CaseInsensitive ) )
2255 const QFileInfo myDirInfo( myFileInfo.path() );
2256 if ( !myDirInfo.isWritable() )
2259 return tr(
"The directory containing your dataset needs to be writable!" );
2263 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
2268 QDomDocument myDocument = mlayer->exportSldStyleV3( context );
2270 if ( !context.
errors().empty() )
2273 return context.
errors().join(
'\n' );
2276 QFile myFile( myFileName );
2277 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
2279 QTextStream myFileStream( &myFile );
2281 myDocument.save( myFileStream, 2 );
2284 return tr(
"Created default style file as %1" ).arg( myFileName );
2289 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
2298 QDomDocument myDocument;
2301 int line = 0, column = 0;
2302 QString myErrorMessage;
2304 QFile myFile( uri );
2305 if ( myFile.open( QFile::ReadOnly ) )
2308#if QT_VERSION >= QT_VERSION_CHECK( 6, 5, 0 )
2309 QXmlStreamReader xmlReader( &myFile );
2310 xmlReader.addExtraNamespaceDeclaration( QXmlStreamNamespaceDeclaration( u
"sld"_s, u
"http://www.opengis.net/sld"_s ) );
2311 xmlReader.addExtraNamespaceDeclaration( QXmlStreamNamespaceDeclaration( u
"fes"_s, u
"http://www.opengis.net/fes/2.0"_s ) );
2312 xmlReader.addExtraNamespaceDeclaration( QXmlStreamNamespaceDeclaration( u
"ogc"_s, u
"http://www.opengis.net/ogc"_s ) );
2313 const QDomDocument::ParseResult result = myDocument.setContent( &xmlReader, QDomDocument::ParseOption::UseNamespaceProcessing );
2320 myErrorMessage = result.errorMessage;
2321 line = result.errorLine;
2322 column = result.errorColumn;
2325 resultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
2328 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
2333 myErrorMessage = tr(
"Unable to open file %1" ).arg( uri );
2338 return myErrorMessage;
2342 const QDomElement myRoot = myDocument.firstChildElement( u
"StyledLayerDescriptor"_s );
2343 if ( myRoot.isNull() )
2345 myErrorMessage = u
"Error: StyledLayerDescriptor element not found in %1"_s.arg( uri );
2347 return myErrorMessage;
2352 const QDomElement namedLayerElem = myRoot.firstChildElement( u
"NamedLayer"_s );
2353 if ( namedLayerElem.isNull() )
2355 myErrorMessage = u
"Info: NamedLayer element not found."_s;
2357 return myErrorMessage;
2361 resultFlag =
readSld( namedLayerElem, errorMsg );
2364 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
2365 return myErrorMessage;
2376 Q_UNUSED( errorMessage )
2378 Q_UNUSED( categories )
2388 Q_UNUSED( errorMessage )
2390 Q_UNUSED( categories )
2402 if ( loadDefaultStyleFlag )
2419 if ( loadDefaultStyleFlag )
2439 setDataSourcePrivate( dataSource, baseName, provider, options,
flags );
2450 Q_UNUSED( dataSource )
2451 Q_UNUSED( baseName )
2452 Q_UNUSED( provider )
2474 QDomElement renderer3DElem = layerElement.firstChildElement( u
"renderer-3d"_s );
2475 if ( !renderer3DElem.isNull() )
2477 const QString type3D = renderer3DElem.attribute( u
"type"_s );
2498 if ( layerElement.hasAttribute( u
"minimumScale"_s ) )
2501 setMaximumScale( layerElement.attribute( u
"minimumScale"_s ).toDouble() );
2502 setMinimumScale( layerElement.attribute( u
"maximumScale"_s ).toDouble() );
2506 setMaximumScale( layerElement.attribute( u
"maxScale"_s ).toDouble() );
2507 setMinimumScale( layerElement.attribute( u
"minScale"_s ).toDouble() );
2509 if ( layerElement.hasAttribute( u
"autoRefreshMode"_s ) )
2519 const QDomElement flagsElem = layerElement.firstChildElement( u
"flags"_s );
2522 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
2524 const QDomNode flagNode = flagsElem.namedItem( it.value() );
2525 if ( flagNode.isNull() )
2527 const bool flagValue = flagNode.toElement().text() ==
"1" ? true :
false;
2528 if (
flags.testFlag( it.key() ) && !flagValue )
2530 else if ( !
flags.testFlag( it.key() ) && flagValue )
2536 if ( categories.testFlag(
Temporal ) )
2541 properties->readXml( layerElement.toElement(), context );
2549 properties->readXml( layerElement.toElement(), context );
2552 if ( categories.testFlag(
Notes ) )
2554 const QDomElement notesElem = layerElement.firstChildElement( u
"userNotes"_s );
2555 if ( !notesElem.isNull() )
2557 const QString notes = notesElem.attribute( u
"value"_s );
2574 return mUndoStackStyles;
2581 return mCustomProperties.keys();
2588 if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
2590 mCustomProperties.setValue( key, value );
2600 for (
const QString &key : mCustomProperties.keys() )
2610 return mCustomProperties;
2618 return mCustomProperties.value( value, defaultValue );
2625 if ( mCustomProperties.contains( key ) )
2627 mCustomProperties.remove( key );
2659 const QString &
name,
const QString &description,
bool useAsDefault,
const QString &uiFileContent, QString &msgError,
QgsMapLayer::StyleCategories categories
2666 msgError = result.providerSaveStyleError.isEmpty() ? result.qmlError : result.providerSaveStyleError;
2667 return result.saveResult;
2683 QString returnMessage;
2684 QString qml, errorMsg;
2692 if ( !qml.isEmpty() )
2694 QDomDocument myDocument( u
"qgis"_s );
2695 myDocument.setContent( qml );
2697 returnMessage = QObject::tr(
"Loaded from Provider" );
2703 bool styleExists =
false;
2704 bool styleSuccessfullyLoaded =
false;
2706 returnMessage = loadNamedProperty( theURI,
PropertyType::Style, styleExists, styleSuccessfullyLoaded, categories,
flags );
2709 ( void ) styleExists;
2710 resultFlag = styleSuccessfullyLoaded;
2713 if ( !styleName.isEmpty() )
2721 return returnMessage;
2764 const QString path = sourceParts.value( u
"path"_s ).toString();
2765 if ( path.isEmpty() )
2768 const QFileInfo fileInfo( path );
2769 const QString cleanedPath = QDir::cleanPath( fileInfo.canonicalFilePath() );
2772 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
2773 for (
const QString &tempPath : std::as_const( tempPaths ) )
2775#if defined( Q_OS_WIN )
2776 if ( cleanedPath.startsWith( tempPath, Qt::CaseSensitivity::CaseInsensitive ) )
2778 if ( cleanedPath.startsWith( tempPath, Qt::CaseSensitivity::CaseSensitive ) )
2809 mLegend->setParent(
this );
2827 return mStyleManager;
2834 if ( renderer == m3DRenderer.get() )
2837 m3DRenderer.reset( renderer );
2847 return m3DRenderer.get();
2854 if ( mRepaintRequestedFired )
2856 mRepaintRequestedFired =
true;
2858 mRepaintRequestedFired =
false;
2911bool QgsMapLayer::isReadOnly()
const
2922 return mOriginalXmlProperties;
2934 constexpr int UUID_SUFFIX_LENGTH = 36 + 1;
2935 constexpr int MAX_ID_LENGTH = 100;
2936 constexpr int MAX_PREFIX_LENGTH = MAX_ID_LENGTH - UUID_SUFFIX_LENGTH;
2939 const QString prefix = layerName.left( MAX_PREFIX_LENGTH );
2983 QSet<QgsMapLayerDependency> deps;
2984 const auto constODeps = oDeps;
3002 if ( !lDataProvider )
3007 lDataProvider->setListening( enabled );
3023 if (
QgsMapLayerStore *store = qobject_cast<QgsMapLayerStore *>( parent() ) )
3025 return qobject_cast<QgsProject *>( store->parent() );
3030void QgsMapLayer::onNotified(
const QString &message )
3045 if ( !
crs().isEarthCrs() )
3056 if ( !forceRecalculate && !mWgs84Extent.isNull() )
3060 else if ( !mExtent2D.isNull() || !mExtent3D.isNull() )
3066 if ( mExtent2D.isNull() )
3080void QgsMapLayer::updateExtent(
const QgsRectangle &extent )
const
3084 if (
extent == mExtent2D )
3096void QgsMapLayer::updateExtent(
const QgsBox3D &extent )
const
3100 if (
extent == mExtent3D )
3105 if ( !
extent.toRectangle().isNull() )
3108 updateExtent(
extent.toRectangle() );
3127bool QgsMapLayer::rebuildCrs3D( QString *error )
3130 if ( !mCRS.isValid() )
3132 mCrs3D = QgsCoordinateReferenceSystem();
3134 else if ( !mVerticalCrs.isValid() )
3140 switch ( mCRS.type() )
3152 res = mCrs3D.isValid();
3158 mCrs3D = QgsCoordinateReferenceSystem();
3173 res = mCrs3D.isValid();
3196 QString
metadata = u
"<h1>"_s + tr(
"General" ) + u
"</h1>\n<hr>\n"_s + u
"<table class=\"list-view\">\n"_s;
3199 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Name" ) + u
"</td><td>"_s +
name() + u
"</td></tr>\n"_s;
3204 bool isLocalPath =
false;
3209 if ( uriComponents.contains( u
"path"_s ) )
3211 path = uriComponents[u
"path"_s].toString();
3212 QFileInfo fi( path );
3216 metadata += u
"<tr><td class=\"highlight\">"_s
3218 + u
"</td><td>%1"_s.arg( u
"<a href=\"%1\">%2</a>"_s.arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) )
3219 + u
"</td></tr>\n"_s;
3221 QDateTime lastModified = fi.lastModified();
3222 QString lastModifiedFileName;
3226 qint64 fileSize = fi.size();
3227 if ( !sidecarFiles.isEmpty() )
3229 lastModifiedFileName = fi.fileName();
3230 QStringList sidecarFileNames;
3231 for (
const QString &sidecarFile : sidecarFiles )
3233 QFileInfo sidecarFi( sidecarFile );
3234 fileSize += sidecarFi.size();
3235 if ( sidecarFi.lastModified() > lastModified )
3237 lastModified = sidecarFi.lastModified();
3238 lastModifiedFileName = sidecarFi.fileName();
3240 sidecarFileNames << sidecarFi.fileName();
3242 metadata += u
"<tr><td class=\"highlight\">"_s
3243 + ( sidecarFiles.size() > 1 ? tr(
"Sidecar files" ) : tr(
"Sidecar file" ) )
3244 + u
"</td><td>%1"_s.arg( sidecarFileNames.join(
", "_L1 ) )
3245 + u
"</td></tr>\n"_s;
3247 metadata += u
"<tr><td class=\"highlight\">"_s
3248 + ( !sidecarFiles.isEmpty() ? tr(
"Total size" ) : tr(
"Size" ) )
3250 + u
"</td></tr>\n"_s;
3252 metadata += u
"<tr><td class=\"highlight\">"_s
3253 + tr(
"Last modified" )
3254 + u
"</td><td>%1"_s.arg( QLocale().toString( fi.lastModified() ) )
3255 + ( !lastModifiedFileName.isEmpty() ? u
" (%1)"_s.arg( lastModifiedFileName ) : QString() )
3256 + u
"</td></tr>\n"_s;
3259 if ( uriComponents.contains( u
"url"_s ) )
3261 QUrl decodedUri = QUrl::fromPercentEncoding( uriComponents[u
"url"_s].toString().toLocal8Bit() );
3262 const QString url = decodedUri.toString();
3263 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"URL" ) + u
"</td><td>%1"_s.arg( u
"<a href=\"%1\">%2</a>"_s.arg( url, url ) ) + u
"</td></tr>\n"_s;
3268 if ( lPublicSource != path || !isLocalPath )
3269 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Source" ) + u
"</td><td>%1"_s.arg( lPublicSource != path ? lPublicSource : path ) + u
"</td></tr>\n"_s;
3273 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Provider" ) + u
"</td><td>%1"_s.arg(
dataProvider()->
name() ) + u
"</td></tr>\n"_s;
3276 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Layer ID" ) + u
"</td><td>%1"_s.arg(
id() ) + u
"</td></tr>\n"_s;
3278 metadata +=
"</table>\n<br><br>"_L1;
3289 metadata += u
"<h1>"_s + tr(
"Custom properties" ) + u
"</h1>\n<hr>\n"_s;
3290 metadata +=
"<table class=\"list-view\">\n<tbody>"_L1;
3291 for (
const QString &key : keys )
3294 if ( key.startsWith(
'_' ) )
3298 QString stringValue;
3299 if ( propValue.typeId() == QMetaType::Type::QVariantList || propValue.typeId() == QMetaType::Type::QStringList )
3301 for (
const QString &s : propValue.toStringList() )
3303 stringValue +=
"<p style=\"margin: 0;\">" + s.toHtmlEscaped() +
"</p>";
3308 stringValue = propValue.toString().toHtmlEscaped();
3312 stringValue = tr(
"<i>value cannot be displayed</i>" );
3315 metadata += u
"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>"_s.arg( key.toHtmlEscaped(), stringValue );
3317 metadata +=
"</tbody></table>\n"_L1;
3330 metadata += u
"<tr><td colspan=\"2\" class=\"highlight\">"_s + tr(
"Unknown" ) + u
"</td></tr>\n"_s;
3336 metadata += u
"<tr><td class=\"highlight\">"_s
3339 + (
c.isGeographic() ? tr(
"Geographic (uses latitude and longitude for coordinates)" ) :
QgsUnitTypes::toString(
c.mapUnits() ) )
3340 + u
"</td></tr>\n"_s;
3347 if ( includeOperation )
3351 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Method" ) + u
"</td><td>"_s + operation.
description() + u
"</td></tr>\n"_s;
3354 if ( includeCelestialBody )
3359 const QString celestialBody =
c.celestialBodyName();
3360 if ( !celestialBody.isEmpty() )
3362 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Celestial Body" ) + u
"</td><td>"_s + celestialBody + u
"</td></tr>\n"_s;
3369 QString accuracyString;
3371 if (
c.isDynamic() && std::isnan(
c.coordinateEpoch() ) )
3373 accuracyString = tr(
"Based on a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." );
3383 if ( !ensemble.
code().isEmpty() )
3384 id = u
"<i>%1</i> (%2:%3)"_s.arg( ensemble.
name(), ensemble.
authority(), ensemble.
code() );
3386 id = u
"<i>%1</i>”"_s.arg( ensemble.
name() );
3390 accuracyString = tr(
"Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg(
id ).arg( ensemble.
accuracy() );
3394 accuracyString = tr(
"Based on %1, which has a limited accuracy." ).arg(
id );
3401 if ( !accuracyString.isEmpty() )
3403 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Accuracy" ) + u
"</td><td>"_s + accuracyString + u
"</td></tr>\n"_s;
3407 metadata += u
"<tr><td class=\"highlight\">"_s
3409 + u
"</td><td>%1</td></tr>\n"_s.arg(
c.isDynamic() ? tr(
"Dynamic (relies on a datum which is not plate-fixed)" ) : tr(
"Static (relies on a datum which is plate-fixed)" ) );
3412 if ( !std::isnan(
c.coordinateEpoch() ) )
3414 metadata += u
"<tr><td class=\"highlight\">"_s + tr(
"Coordinate Epoch" ) + u
"</td><td>%1</td></tr>\n"_s.arg(
qgsDoubleToString(
c.coordinateEpoch(), 3 ) );
3419 metadata += u
"<h1>"_s + tr(
"Coordinate Reference System (CRS)" ) + u
"</h1>\n<hr>\n"_s;
3420 metadata +=
"<table class=\"list-view\">\n"_L1;
3421 addCrsInfo(
crs().horizontalCrs(),
true,
true,
true );
3422 metadata +=
"</table>\n<br><br>\n"_L1;
3426 metadata += u
"<h1>"_s + tr(
"Vertical Coordinate Reference System (CRS)" ) + u
"</h1>\n<hr>\n"_s;
3427 metadata +=
"<table class=\"list-view\">\n"_L1;
3429 metadata +=
"</table>\n<br><br>\n"_L1;
static QString version()
Version string.
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
@ Compound
Compound (horizontal + vertical) CRS.
@ Projected
Projected CRS.
@ DerivedProjected
Derived projected CRS.
@ Engineering
Engineering CRS.
@ Geographic3d
3D geopraphic CRS
@ Geographic2d
2D geographic CRS
@ Geocentric
Geocentric CRS.
@ RemoveCredentials
Completely remove credentials (eg passwords) from the URI. This flag is not compatible with the Redac...
@ RedactCredentials
Replace the value of credentials (eg passwords) with 'xxxxxxxx'. This flag is not compatible with the...
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
QFlags< SaveStyleFormat > SaveStyleFormats
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
LayerType
Types of layers that can be added to a map.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ ForceReadOnly
Open layer in a read-only mode.
@ SkipGetExtent
Skip the extent from provider.
@ TrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
@ IgnoreMissingStyleErrors
If the style is missing, then don't flag it as an error. This flag can be used when the caller is not...
AutoRefreshMode
Map layer automatic refresh modes.
@ RedrawOnly
Redraw current data only.
@ ReloadData
Reload data (and draw the new data).
@ Disabled
Automatic refreshing is disabled.
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type).
Base class for all renderers that participate in 3D views.
static QString pkgDataPath()
Returns the common root path of all application data directories.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
A 3-dimensional box composed of x, y, z coordinates.
static QString crsTypeToString(Qgis::CrsType type)
Returns a translated string representing a CRS type.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
static QgsCoordinateReferenceSystem createCompoundCrs(const QgsCoordinateReferenceSystem &horizontalCrs, const QgsCoordinateReferenceSystem &verticalCrs, QString &error)
Given a horizontal and vertical CRS, attempts to create a compound CRS from them.
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
virtual bool containsElevationData() const
Returns true if the data provider definitely contains elevation related data.
Abstract base class for spatial data provider implementations.
void notify(const QString &msg)
Emitted when the datasource issues a notification.
virtual QgsDataProviderElevationProperties * elevationProperties()
Returns the provider's elevation properties.
static QString removePassword(const QString &aUri, bool hide=false)
Removes the password element from a URI.
Contains information about a datum ensemble.
QString code() const
Identification code, e.g.
QString authority() const
Authority name, e.g.
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
QString name() const
Display name of datum ensemble.
double accuracy() const
Positional accuracy (in meters).
A container for error messages.
static QSet< QString > sidecarFilesForPath(const QString &path)
Returns a list of the sidecar files which exist for the dataset a the specified path.
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
static void setLayerNotes(QgsMapLayer *layer, const QString ¬es)
Sets the notes for the specified layer, where notes is a HTML formatted string.
static bool layerHasNotes(const QgsMapLayer *layer)
Returns true if the specified layer has notes available.
static QString layerNotes(const QgsMapLayer *layer)
Returns the notes for the specified layer.
Models dependencies with or between map layers.
@ FromUser
Dependency given by the user.
Base class for storage of map layer elevation properties.
An abstract interface for implementations of legends for one map layer.
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
Manages QGIS Server properties for a map layer.
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves server properties to xml under the layer node.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Management of styles for use with one map layer.
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
QStringList styles() const
Returns list of all defined style names.
bool renameStyle(const QString &name, const QString &newName)
Rename a stored style to a different name.
Base class for storage of map layer temporal properties.
static QgsSaveStyleResult saveLayerStyleToDatabase(QgsMapLayer *layer, const QString &providerKey, const QString &targetDataSource, const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, const Qgis::SaveStyleFormats formats=Qgis::SaveStyleFormats(Qgis::SaveStyleFormat::QML|Qgis::SaveStyleFormat::SLD), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of layer's style to a table in the database identified by providerK...
void crs3DChanged()
Emitted when the crs3D() of the layer has changed.
Q_DECL_DEPRECATED void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
virtual bool deleteStyleFromDatabase(const QString &styleId, QString &msgError)
Deletes a style from the database.
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
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 document provided.
Q_DECL_DEPRECATED QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Q_INVOKABLE QgsRectangle wgs84Extent(bool forceRecalculate=false) const
Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
virtual Q_DECL_DEPRECATED void exportSldStyleV2(QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext) const
Export the properties of this layer as SLD style in a QDomDocument.
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.
bool setId(const QString &id)
Sets the layer's id.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
void dependenciesChanged()
Emitted when dependencies are changed.
virtual bool hasMapTips() const
Returns true if the layer contains map tips.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
void legendChanged()
Signal emitted when legend of the layer has changed.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsMapLayerLegend * legend() const
Can be nullptr.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
Q_DECL_DEPRECATED void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual Q_INVOKABLE QgsRectangle extent() const
Returns the extent of the layer.
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
QString source() const
Returns the source for the layer.
Q_DECL_DEPRECATED void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual void setExtent3D(const QgsBox3D &box)
Sets the extent.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Qgis::AutoRefreshMode autoRefreshMode() const
Returns the layer's automatic refresh mode.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void configChanged()
Emitted whenever the configuration is changed.
void trigger3DUpdate()
Will advise any 3D maps that this layer requires to be updated in the scene.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
static Qgis::DataProviderReadFlags providerReadFlags(const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that...
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
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...
QgsCoordinateReferenceSystem crs3D
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
void isValidChanged()
Emitted when the validity of this layer changed.
QgsCoordinateReferenceSystem crs
bool loadNamedMetadataFromDatabase(const QString &db, const QString &uri, QString &qmd)
Retrieve a named metadata for this layer from a sqlite database.
friend class QgsVectorLayer
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Q_DECL_DEPRECATED QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
QString mRefreshOnNofifyMessage
virtual int listStylesInDatabase(QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
Lists all the style in db split into related to the layer and not related to.
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...
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QString mLayerName
Name of the layer - used for display.
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 ...
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.
Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
Q_DECL_DEPRECATED void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of the layer's style to a table in the database.
Q_DECL_DEPRECATED void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsLayerMetadata metadata
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
Q_DECL_DEPRECATED QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
Q_DECL_DEPRECATED QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Q_DECL_DEPRECATED void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Q_DECL_DEPRECATED void setKeywordList(const QString &keywords)
Sets the keyword list of the layerused by QGIS Server in GetCapabilities request.
Q_DECL_DEPRECATED void setAttribution(const QString &attrib)
Sets the attribution of the layerused by QGIS Server in GetCapabilities request.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Q_DECL_DEPRECATED QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
virtual QString loadSldStyle(const QString &uri, bool &resultFlag)
Attempts to style the layer using the formatting from an SLD type file.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
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.
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 ...
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
Q_DECL_DEPRECATED void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QFlags< StyleCategory > StyleCategories
virtual Q_DECL_DEPRECATED void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of the layer's style to a table in the database.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString mProviderKey
Data provider key (name of the data provider).
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void styleChanged()
Signal emitted whenever a change affects the layer's style.
virtual bool isEditable() const
Returns true if the layer can be edited.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
Q_DECL_DEPRECATED QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void crsChanged()
Emitted when the crs() of the layer has changed.
virtual QgsError error() const
Gets current status error.
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
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 setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
void idChanged(const QString &id)
Emitted when the layer's ID has been changed.
Q_DECL_DEPRECATED QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer::LayerFlags flags
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
Q_DECL_DEPRECATED QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
static QString generateId(const QString &layerName)
Generates an unique identifier for the layer with the specified layerName.
QgsProviderMetadata * providerMetadata() const
Returns the layer data provider's metadata, it may be nullptr.
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
virtual bool isModified() const
Returns true if the layer has been modified since last commit/save.
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QString getStyleFromDatabase(const QString &styleId, QString &msgError)
Returns the named style corresponding to style id provided.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
void dataChanged()
Data of layer changed.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
Q_DECL_DEPRECATED void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
virtual bool loadNamedStyleFromDatabase(const QString &db, const QString &uri, QString &qml)
Retrieve a named style for this layer from a sqlite database.
void verticalCrsChanged()
Emitted when the verticalCrs() of the layer has changed.
virtual QgsBox3D extent3D() const
Returns the 3D extent of the layer.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode().
void setName(const QString &name)
Set the display name of the layer.
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
Q_DECL_DEPRECATED QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
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...
QString mDataSource
Data source description string, varies by layer type.
void setAutoRefreshMode(Qgis::AutoRefreshMode mode)
Sets the automatic refresh mode for the layer.
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
void setMapTipsEnabled(bool enabled)
Enable or disable map tips for this layer.
virtual QString loadDefaultMetadata(bool &resultFlag)
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
virtual QString saveSldStyleV2(bool &resultFlag, QgsSldExportContext &exportContext) const
Saves the properties of this layer to an SLD format file.
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
@ FlagForceReadOnly
Force open as read only.
void setValid(bool valid)
Sets whether layer is valid or not.
Q_DECL_DEPRECATED QString attributionUrl() const
Returns the attribution URL 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.
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
virtual QDomDocument exportSldStyleV3(QgsSldExportContext &exportContext) const
Export the properties of this layer as SLD style in a QDomDocument.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Q_DECL_DEPRECATED QString legendUrl() const
Returns the URL for the layer's legend.
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
Q_DECL_DEPRECATED void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
virtual QString saveNamedStyle(const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
virtual Q_DECL_DEPRECATED void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
Q_DECL_DEPRECATED void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
bool setVerticalCrs(const QgsCoordinateReferenceSystem &crs, QString *errorMessage=nullptr)
Sets the layer's vertical coordinate reference system.
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Q_DECL_DEPRECATED void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider=nullptr)
Sets state from DOM document.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
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 nameChanged()
Emitted when the name has been changed.
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...
QgsSaveStyleResult saveStyleToDatabaseV3(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, const Qgis::SaveStyleFormats formats, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves selected representation of the layer's style to a table in the database.
QgsCoordinateReferenceSystem verticalCrs
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.
bool mIsRefreshOnNofifyEnabled
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
double mLayerOpacity
Layer opacity.
bool mValid
Indicates if the layer is valid and can be drawn.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
@ Temporal
Temporal properties.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Elevation
Elevation settings.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance).
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
void setProviderType(const QString &providerType)
Sets the providerType (provider key).
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
virtual QString saveDefaultStyle(bool &resultFlag, StyleCategories categories)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
QFlags< SaveStyleResult > SaveStyleResults
Results of saving styles to database.
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
QString customPropertyHtmlMetadata() const
Returns an HTML fragment containing custom property information, for use in the htmlMetadata() method...
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
Q_DECL_DEPRECATED QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
double maximumScale() const
Returns the maximum map scale (i.e.
Q_DECL_DEPRECATED QString keywordList() const
Returns the keyword list 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.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
Q_DECL_DEPRECATED void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
PropertyType
Maplayer has a style and a metadata property.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Custom exception class which is raised when an operation is not supported.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
An interface for classes which can visit various object entity (e.g.
A QgsObjectEntityVisitorInterface context object.
Contains information about a PROJ operation.
QString description() const
Description.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
Translates a string using the Qt QTranslator mechanism.
Describes the version of a project.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
bool removeAttachedFile(const QString &path)
Removes the attached file.
QString getStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Gets a layer style defined by styleId.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
bool saveLayerMetadata(const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage)
Saves metadata to the layer corresponding to the specified uri.
bool deleteStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Deletes a layer style defined by styleId.
QString loadStoredStyle(const QString &providerKey, const QString &uri, QString &styleName, QString &errCause)
Loads a layer style from the provider storage, reporting its name.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
int listStyles(const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by providerKey and uri.
Represents a raster layer.
Q_DECL_DEPRECATED bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
Allows entering a context category and takes care of leaving this category on deletion of the class.
A container for the context for various read/write operations on objects.
QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
A rectangle specified with double values.
Represents the result of saving a style.
static bool equalToOrGreaterThanMinimumScale(const double scale, const double minScale)
Returns whether the scale is equal to or greater than the minScale, taking non-round numbers into acc...
static bool lessThanMaximumScale(const double scale, const double maxScale)
Returns whether the scale is less than the maxScale, taking non-round numbers into account.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
QString exportFilePath() const
Returns the export file path for the SLD.
QStringList errors() const
Returns a list of errors which occurred during the conversion.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
void setExportFilePath(const QString &exportFilePath)
Sets the export file path for the SLD to exportFilePath.
QVariantMap extraProperties() const
Returns the open ended set of properties that can drive/inform the SLD encoding.
void pushError(const QString &error)
Pushes a error message generated during the conversion.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
static QString createUniqueId(const QString &base=QString())
Generates a unique identifier by appending a random UUID to base.
An interface for classes which can visit style entity (e.g.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
Q_DECL_DEPRECATED bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
static QgsBox3D readBox3D(const QDomElement &element)
Decodes a DOM element to a 3D box.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=u"extent"_s)
Encodes a rectangle to a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
static QDomElement writeBox3D(const QgsBox3D &box, QDomDocument &doc, const QString &elementName=u"extent3D"_s)
Encodes a 3D box to a DOM element.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
const QMap< T, QString > qgsEnumMap()
Returns a map of all enum entries.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
#define QGIS_CHECK_QOBJECT_THREAD_EQUALITY(other)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.