54#include <QDomDocument>
56#include <QDomImplementation>
64#include <QStandardPaths>
66#include <QRegularExpression>
75 return QStringLiteral(
".qmd" );
78 return QStringLiteral(
".qml" );
84 const QString &lyrname,
85 const QString &source )
86 : mDataSource( source )
87 , mLayerName( lyrname )
90 , mUndoStack( new QUndoStack( this ) )
91 , mUndoStackStyles( new QUndoStack( this ) )
93 , mRefreshTimer( new QTimer( this ) )
98 connect( mRefreshTimer, &QTimer::timeout,
this, [
this]
101 switch ( mAutoRefreshMode )
124 delete mStyleManager;
135 for (
const QString &s : constStyles )
145 layer->mExtent3D = mExtent3D;
147 layer->mExtent2D = mExtent2D;
183 if (
flags == mFlags )
208 if ( qobject_cast< QgsMapLayerStore * >( parent() ) )
261 mServerProperties->setShortName(
shortName );
268 return mServerProperties->shortName();
275 mServerProperties->setTitle(
title );
282 return mServerProperties->title();
289 mServerProperties->setAbstract(
abstract );
296 return mServerProperties->abstract();
303 mServerProperties->setKeywordList( keywords );
310 return mServerProperties->keywordList();
317 mServerProperties->setDataUrl(
dataUrl );
324 return mServerProperties->dataUrl();
338 return mServerProperties->dataUrlFormat();
345 mServerProperties->setAttribution( attrib );
352 return mServerProperties->attribution();
359 mServerProperties->setAttributionUrl( attribUrl );
366 return mServerProperties->attributionUrl();
375 if ( urls.isEmpty() )
378 urls.prepend( newItem );
384 urls.prepend( newItem );
393 if ( mServerProperties->metadataUrls().isEmpty() )
395 return QLatin1String();
399 return mServerProperties->metadataUrls().first().url;
407 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
408 if ( urls.isEmpty() )
411 urls.prepend( newItem );
417 urls.prepend( newItem );
419 mServerProperties->setMetadataUrls( urls );
426 if ( mServerProperties->metadataUrls().isEmpty() )
428 return QLatin1String();
432 return mServerProperties->metadataUrls().first().type;
440 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
441 if ( urls.isEmpty() )
444 urls.prepend( newItem );
450 urls.prepend( newItem );
452 mServerProperties->setMetadataUrls( urls );
459 if ( mServerProperties->metadataUrls().isEmpty() )
465 return mServerProperties->metadataUrls().first().format;
553 mnl = layerElement.namedItem( QStringLiteral(
"provider" ) );
554 mne = mnl.toElement();
555 provider = mne.text();
558 mnl = layerElement.namedItem( QStringLiteral(
"datasource" ) );
559 mne = mnl.toElement();
560 const QString dataSourceRaw = mne.text();
564 const thread_local QRegularExpression rx(
"authcfg=([a-z]|[A-Z]|[0-9]){7}" );
577 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
578 mne = mnl.toElement();
583 const QDomNode srsNode = layerElement.namedItem( QStringLiteral(
"srs" ) );
602 mnl = layerElement.namedItem( QStringLiteral(
"id" ) );
603 if ( ! mnl.isNull() )
605 mne = mnl.toElement();
606 if ( ! mne.isNull() && mne.text().length() > 10 )
608 const QString newId = mne.text();
618 mnl = layerElement.namedItem( QStringLiteral(
"layername" ) );
619 mne = mnl.toElement();
622 setName( context.
projectTranslator()->
translate( QStringLiteral(
"project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), mne.text() ) );
625 layerError = !
readXml( layerElement, context );
639 const QDomNode verticalCrsNode = layerElement.firstChildElement( QStringLiteral(
"verticalCrs" ) );
640 if ( !verticalCrsNode.isNull() )
649 const QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral(
"legendUrl" ) );
650 if ( !legendUrlElem.isNull() )
653 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral(
"format" ), QString() );
662 const QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral(
"metadataUrl" ) );
663 if ( !metaUrlElem.isNull() )
665 const QString url = metaUrlElem.text();
666 const QString
type = metaUrlElem.attribute( QStringLiteral(
"type" ), QString() );
667 const QString format = metaUrlElem.attribute( QStringLiteral(
"format" ), QString() );
669 mServerProperties->setMetadataUrls( QList<QgsMapLayerServerProperties::MetadataUrl>() << newItem );
674 const QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral(
"resourceMetadata" ) );
677 setAutoRefreshInterval( layerElement.attribute( QStringLiteral(
"autoRefreshTime" ), QStringLiteral(
"0" ) ).toInt() );
678 if ( layerElement.hasAttribute( QStringLiteral(
"autoRefreshMode" ) ) )
687 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral(
"refreshOnNotifyEnabled" ), QStringLiteral(
"0" ) ).toInt() );
692 const QDomNode wgs84ExtentNode = layerElement.namedItem( QStringLiteral(
"wgs84extent" ) );
693 if ( !wgs84ExtentNode.isNull() )
697 mLegendPlaceholderImage = layerElement.attribute( QStringLiteral(
"legendPlaceholderImage" ) );
701 if ( mCrs3D != oldCrs3D )
712 Q_UNUSED( layer_node )
719 const QDomNode extent3DNode = layer_node.namedItem( QStringLiteral(
"extent3D" ) );
720 if ( extent3DNode.isNull() )
722 const QDomNode extentNode = layer_node.namedItem( QStringLiteral(
"extent" ) );
723 if ( !extentNode.isNull() )
744 else if ( !mExtent2D.
isNull() )
752 layerElement.setAttribute( QStringLiteral(
"autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
753 layerElement.setAttribute( QStringLiteral(
"autoRefreshMode" ),
qgsEnumValueToKey( mAutoRefreshMode ) );
758 QDomElement layerId = document.createElement( QStringLiteral(
"id" ) );
759 const QDomText layerIdText = document.createTextNode(
id() );
760 layerId.appendChild( layerIdText );
762 layerElement.appendChild( layerId );
766 QDomElement verticalSrsNode = document.createElement( QStringLiteral(
"verticalCrs" ) );
767 mVerticalCrs.
writeXml( verticalSrsNode, document );
768 layerElement.appendChild( verticalSrsNode );
772 QDomElement dataSource = document.createElement( QStringLiteral(
"datasource" ) );
774 const QString providerKey = provider ? provider->
name() : QString();
777 const QDomText dataSourceText = document.createTextNode( src );
778 dataSource.appendChild( dataSourceText );
779 layerElement.appendChild( dataSource );
782 QDomElement layerName = document.createElement( QStringLiteral(
"layername" ) );
783 const QDomText layerNameText = document.createTextNode(
name() );
784 layerName.appendChild( layerNameText );
785 layerElement.appendChild( layerName );
791 if ( !mServerProperties->shortName().isEmpty() )
793 QDomElement layerShortName = document.createElement( QStringLiteral(
"shortname" ) );
794 const QDomText layerShortNameText = document.createTextNode( mServerProperties->shortName() );
795 layerShortName.appendChild( layerShortNameText );
796 layerElement.appendChild( layerShortName );
800 if ( !mServerProperties->title().isEmpty() )
802 QDomElement layerTitle = document.createElement( QStringLiteral(
"title" ) );
803 const QDomText layerTitleText = document.createTextNode( mServerProperties->title() );
804 layerTitle.appendChild( layerTitleText );
805 layerElement.appendChild( layerTitle );
809 if ( !mServerProperties->abstract().isEmpty() )
811 QDomElement layerAbstract = document.createElement( QStringLiteral(
"abstract" ) );
812 const QDomText layerAbstractText = document.createTextNode( mServerProperties->abstract() );
813 layerAbstract.appendChild( layerAbstractText );
814 layerElement.appendChild( layerAbstract );
818 const QStringList keywordStringList = mServerProperties->keywordList().split(
',' );
819 if ( !keywordStringList.isEmpty() )
821 QDomElement layerKeywordList = document.createElement( QStringLiteral(
"keywordList" ) );
822 for (
int i = 0; i < keywordStringList.size(); ++i )
824 QDomElement layerKeywordValue = document.createElement( QStringLiteral(
"value" ) );
825 const QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
826 layerKeywordValue.appendChild( layerKeywordText );
827 layerKeywordList.appendChild( layerKeywordValue );
829 layerElement.appendChild( layerKeywordList );
833 const QString aDataUrl = mServerProperties->dataUrl();
834 if ( !aDataUrl.isEmpty() )
836 QDomElement layerDataUrl = document.createElement( QStringLiteral(
"dataUrl" ) );
837 const QDomText layerDataUrlText = document.createTextNode( aDataUrl );
838 layerDataUrl.appendChild( layerDataUrlText );
839 layerDataUrl.setAttribute( QStringLiteral(
"format" ), mServerProperties->dataUrlFormat() );
840 layerElement.appendChild( layerDataUrl );
845 if ( !aLegendUrl.isEmpty() )
847 QDomElement layerLegendUrl = document.createElement( QStringLiteral(
"legendUrl" ) );
848 const QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
849 layerLegendUrl.appendChild( layerLegendUrlText );
850 layerLegendUrl.setAttribute( QStringLiteral(
"format" ),
legendUrlFormat() );
851 layerElement.appendChild( layerLegendUrl );
855 const QString aAttribution = mServerProperties->attribution();
856 if ( !aAttribution.isEmpty() )
858 QDomElement layerAttribution = document.createElement( QStringLiteral(
"attribution" ) );
859 const QDomText layerAttributionText = document.createTextNode( aAttribution );
860 layerAttribution.appendChild( layerAttributionText );
861 layerAttribution.setAttribute( QStringLiteral(
"href" ), mServerProperties->attributionUrl() );
862 layerElement.appendChild( layerAttribution );
868 QDomElement stamp = document.createElement( QStringLiteral(
"timestamp" ) );
869 const QDomText stampText = document.createTextNode(
timestamp().toString( Qt::ISODate ) );
870 stamp.appendChild( stampText );
871 layerElement.appendChild( stamp );
874 layerElement.appendChild( layerName );
881 QDomElement mySrsElement = document.createElement( QStringLiteral(
"srs" ) );
882 mCRS.
writeXml( mySrsElement, document );
883 layerElement.appendChild( mySrsElement );
886 QDomElement myMetadataElem = document.createElement( QStringLiteral(
"resourceMetadata" ) );
888 layerElement.appendChild( myMetadataElem );
890 layerElement.setAttribute( QStringLiteral(
"legendPlaceholderImage" ), mLegendPlaceholderImage );
893 return writeXml( layerElement, document, context );
902 const QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
903 const QString categoriesKeys( metaEnum.valueToKeys(
static_cast<int>( categories ) ) );
904 layerElement.setAttribute( QStringLiteral(
"styleCategories" ), categoriesKeys );
909 layerElement.setAttribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ),
hasScaleBasedVisibility() ? 1 : 0 );
910 layerElement.setAttribute( QStringLiteral(
"maxScale" ), QString::number(
maximumScale() ) );
911 layerElement.setAttribute( QStringLiteral(
"minScale" ), QString::number(
minimumScale() ) );
918 QDomElement renderer3DElem = document.createElement( QStringLiteral(
"renderer-3d" ) );
919 renderer3DElem.setAttribute( QStringLiteral(
"type" ), m3DRenderer->
type() );
920 m3DRenderer->
writeXml( renderer3DElem, context );
921 layerElement.appendChild( renderer3DElem );
929 QDomElement layerFlagsElem = document.createElement( QStringLiteral(
"flags" ) );
930 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
931 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
933 const bool flagValue = mFlags.testFlag( it.key() );
934 QDomElement flagElem = document.createElement( it.value() );
935 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
936 layerFlagsElem.appendChild( flagElem );
938 layerElement.appendChild( layerFlagsElem );
941 if ( categories.testFlag(
Temporal ) )
944 properties->writeXml( layerElement, document, context );
950 properties->writeXml( layerElement, document, context );
955 QDomElement notesElem = document.createElement( QStringLiteral(
"userNotes" ) );
957 layerElement.appendChild( notesElem );
972 Q_UNUSED( layer_node )
1013 mCustomProperties.
readXml( layerNode, keyStartsWith );
1015 for (
const QString &key : mCustomProperties.
keys() )
1017 if ( !oldKeys.contains( key ) || mCustomProperties.
value( key ) != oldKeys.value( key ) )
1028 mCustomProperties.
writeXml( layerNode, doc );
1035 const QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral(
"map-layer-style-manager" ) );
1036 if ( !styleMgrElem.isNull() )
1037 mStyleManager->
readXml( styleMgrElem );
1039 mStyleManager->
reset();
1046 if ( mStyleManager )
1048 QDomElement styleMgrElem = doc.createElement( QStringLiteral(
"map-layer-style-manager" ) );
1049 mStyleManager->
writeXml( styleMgrElem );
1050 layerNode.appendChild( styleMgrElem );
1058 return mMapTipTemplate;
1065 if ( mMapTipTemplate == mapTip )
1068 mMapTipTemplate = mapTip;
1076 if ( mMapTipsEnabled == enabled )
1079 mMapTipsEnabled = enabled;
1087 return mMapTipsEnabled;
1104 const QDomNode extent3DNode = layerNode.namedItem( QStringLiteral(
"extent3D" ) );
1105 if ( extent3DNode.isNull() )
1107 const QDomNode extentNode = layerNode.namedItem( QStringLiteral(
"extent" ) );
1108 if ( !extentNode.isNull() )
1131void QgsMapLayer::connectNotify(
const char *signal )
1143 return !mScaleBasedVisibility ||
1145 && ( mMaxScale == 0 || scale < mMaxScale ) );
1153 return mScaleBasedVisibility;
1167 return mAutoRefreshMode;
1174 return mRefreshTimer->interval();
1181 if ( interval <= 0 )
1183 mRefreshTimer->stop();
1184 mRefreshTimer->setInterval( 0 );
1189 mRefreshTimer->setInterval( interval );
1205 if ( mode == mAutoRefreshMode )
1208 mAutoRefreshMode = mode;
1209 switch ( mAutoRefreshMode )
1212 mRefreshTimer->stop();
1217 if ( mRefreshTimer->interval() > 0 )
1218 mRefreshTimer->start();
1257 mScaleBasedVisibility = enabled;
1271 return QStringList();
1308 switch ( mCRS.
type() )
1311 QgsDebugError( QStringLiteral(
"Layer has a vertical CRS set as the horizontal CRS!" ) );
1330 return mVerticalCrs;
1337 return mCrs3D.
isValid() ? mCrs3D : mCRS;
1365 if ( oldCrs3D != mCrs3D )
1394 *errorMessage = QObject::tr(
"Specified CRS is a %1 CRS, not a Vertical CRS" ).arg(
qgsEnumValueToKey(
crs.
type() ) );
1399 if (
crs != mVerticalCrs )
1404 switch ( mCRS.
type() )
1407 if (
crs != oldVerticalCrs )
1410 *errorMessage = QObject::tr(
"Layer CRS is a Compound CRS, specified Vertical CRS will be ignored" );
1416 if (
crs != oldVerticalCrs )
1419 *errorMessage = QObject::tr(
"Layer CRS is a Geographic 3D CRS, specified Vertical CRS will be ignored" );
1425 if (
crs != oldVerticalCrs )
1428 *errorMessage = QObject::tr(
"Layer CRS is a Geocentric CRS, specified Vertical CRS will be ignored" );
1437 *errorMessage = QObject::tr(
"Layer CRS is a Projected 3D CRS, specified Vertical CRS will be ignored" );
1455 res = rebuildCrs3D( errorMessage );
1461 if ( mCrs3D != oldCrs3D )
1477 QString layerName(
name );
1478 layerName.replace(
'_',
' ' );
1483QString QgsMapLayer::baseURI( PropertyType type )
const
1497 myURI = components[
"path"].toString();
1500 QFileInfo myFileInfo( myURI );
1503 if ( myFileInfo.exists() )
1506 if ( myURI.endsWith( QLatin1String(
".gz" ), Qt::CaseInsensitive ) )
1508 else if ( myURI.endsWith( QLatin1String(
".zip" ), Qt::CaseInsensitive ) )
1510 else if ( myURI.endsWith( QLatin1String(
".tar" ), Qt::CaseInsensitive ) )
1512 else if ( myURI.endsWith( QLatin1String(
".tar.gz" ), Qt::CaseInsensitive ) )
1514 else if ( myURI.endsWith( QLatin1String(
".tgz" ), Qt::CaseInsensitive ) )
1516 myFileInfo.setFile( myURI );
1545 QString errorMessage;
1548 return tr(
"Successfully saved default layer metadata" );
1550 return errorMessage;
1599bool QgsMapLayer::loadNamedPropertyFromDatabase(
const QString &db,
const QString &uri, QString &xml,
QgsMapLayer::PropertyType type )
1603 QgsDebugMsgLevel( QStringLiteral(
"db = %1 uri = %2" ).arg( db, uri ), 4 );
1605 bool resultFlag =
false;
1613 QgsDebugMsgLevel( QStringLiteral(
"Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
1615 if ( db.isEmpty() || !QFile( db ).exists() )
1618 myResult = database.
open_v2( db, SQLITE_OPEN_READONLY,
nullptr );
1619 if ( myResult != SQLITE_OK )
1628 mySql = QStringLiteral(
"select qmd from tbl_metadata where metadata=?" );
1632 mySql = QStringLiteral(
"select qml from tbl_styles where style=?" );
1636 statement = database.
prepare( mySql, myResult );
1637 if ( myResult == SQLITE_OK )
1639 QByteArray param = uri.toUtf8();
1641 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
1642 sqlite3_step( statement.get() ) == SQLITE_ROW )
1644 xml = QString::fromUtf8(
reinterpret_cast< const char *
>( sqlite3_column_text( statement.get(), 0 ) ) );
1665 namedPropertyExists =
false;
1666 propertySuccessfullyLoaded =
false;
1667 if ( uri.isEmpty() )
1670 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
1674 QString myErrorMessage;
1676 QFile myFile( uri );
1677 if ( myFile.open( QFile::ReadOnly ) )
1680 namedPropertyExists =
true;
1683 propertySuccessfullyLoaded = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
1684 if ( !propertySuccessfullyLoaded )
1685 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1702 namedPropertyExists =
true;
1703 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1704 if ( !propertySuccessfullyLoaded )
1706 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1713 myErrorMessage = tr(
"Style not found in database" );
1724 namedPropertyExists =
true;
1725 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1726 if ( !propertySuccessfullyLoaded )
1728 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1733 myErrorMessage = tr(
"Metadata not found in database" );
1740 if ( !propertySuccessfullyLoaded )
1742 return myErrorMessage;
1748 propertySuccessfullyLoaded =
importNamedStyle( myDocument, myErrorMessage, categories );
1749 if ( !propertySuccessfullyLoaded )
1750 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1754 if ( !propertySuccessfullyLoaded )
1755 myErrorMessage = tr(
"Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1758 return myErrorMessage;
1765 const QDomElement myRoot = document.firstChildElement( QStringLiteral(
"qgis" ) );
1766 if ( myRoot.isNull() )
1768 errorMessage = tr(
"Root <qgis> element could not be found" );
1779 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"qgis" ) );
1780 if ( myRoot.isNull() )
1782 myErrorMessage = tr(
"Root <qgis> element could not be found" );
1787 const QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral(
"version" ) ) );
1790 if ( thisVersion > fileVersion )
1809 myErrorMessage = tr(
"Cannot apply style with symbology to layer with a different geometry type" );
1816 return readSymbology( myRoot, myErrorMessage, context, categories );
1823 QDomImplementation DomImplementation;
1824 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1825 QDomDocument myDocument( documentType );
1827 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1828 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1829 myDocument.appendChild( myRootNode );
1833 errorMsg = QObject::tr(
"Could not save metadata" );
1844 QDomImplementation DomImplementation;
1845 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ), QStringLiteral(
"SYSTEM" ) );
1846 QDomDocument myDocument( documentType );
1848 QDomElement myRootNode = myDocument.createElement( QStringLiteral(
"qgis" ) );
1849 myRootNode.setAttribute( QStringLiteral(
"version" ),
Qgis::version() );
1850 myDocument.appendChild( myRootNode );
1852 if ( !
writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) )
1854 errorMsg = QObject::tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
1865 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>(
this );
1866 const QString geoType = QString::number(
static_cast<int>( vl->
geometryType() ) );
1869 QDomElement layerGeometryType = myDocument.createElement( QStringLiteral(
"layerGeometryType" ) );
1870 const QDomText
type = myDocument.createTextNode( geoType );
1872 layerGeometryType.appendChild(
type );
1873 myRootNode.appendChild( layerGeometryType );
1904 bool metadataExists =
false;
1905 bool metadataSuccessfullyLoaded =
false;
1906 const QString message = loadNamedProperty( uri,
QgsMapLayer::Metadata, metadataExists, metadataSuccessfullyLoaded );
1909 ( void )metadataExists;
1910 resultFlag = metadataSuccessfullyLoaded;
1914QString QgsMapLayer::saveNamedProperty(
const QString &uri,
QgsMapLayer::PropertyType type,
bool &resultFlag, StyleCategories categories )
1924 if ( vlayer && vlayer->
providerType() == QLatin1String(
"ogr" ) )
1926 QStringList theURIParts = uri.split(
'|' );
1927 filename = theURIParts[0];
1929 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"gpx" ) )
1931 QStringList theURIParts = uri.split(
'?' );
1932 filename = theURIParts[0];
1934 else if ( vlayer && vlayer->
providerType() == QLatin1String(
"delimitedtext" ) )
1936 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1938 if ( filename.isEmpty() )
1946 QString myErrorMessage;
1947 QDomDocument myDocument;
1960 const QFileInfo myFileInfo( filename );
1963 const QFileInfo myDirInfo( myFileInfo.path() );
1964 if ( !myDirInfo.isWritable() )
1967 return tr(
"The directory containing your dataset needs to be writable!" );
1973 QFile myFile( myFileName );
1974 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1976 QTextStream myFileStream( &myFile );
1978 myDocument.save( myFileStream, 2 );
1984 return tr(
"Created default metadata file as %1" ).arg( myFileName );
1987 return tr(
"Created default style file as %1" ).arg( myFileName );
1997 return tr(
"ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
2000 return tr(
"ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
2006 const QString qml = myDocument.toString();
2013 if ( myResult != SQLITE_OK )
2015 return tr(
"User database could not be opened." );
2018 QByteArray param0 = uri.toUtf8();
2019 QByteArray param1 = qml.toUtf8();
2025 mySql = QStringLiteral(
"create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
2029 mySql = QStringLiteral(
"create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
2033 statement = database.
prepare( mySql, myResult );
2034 if ( myResult == SQLITE_OK )
2036 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
2042 return tr(
"The metadata table could not be created." );
2045 return tr(
"The style table could not be created." );
2053 mySql = QStringLiteral(
"insert into tbl_metadata(metadata,qmd) values (?,?)" );
2057 mySql = QStringLiteral(
"insert into tbl_styles(style,qml) values (?,?)" );
2060 statement = database.
prepare( mySql, myResult );
2061 if ( myResult == SQLITE_OK )
2063 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
2064 sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
2065 sqlite3_step( statement.get() ) == SQLITE_DONE )
2071 myErrorMessage = tr(
"The metadata %1 was saved to database" ).arg( uri );
2075 myErrorMessage = tr(
"The style %1 was saved to database" ).arg( uri );
2087 mySql = QStringLiteral(
"update tbl_metadata set qmd=? where metadata=?" );
2091 mySql = QStringLiteral(
"update tbl_styles set qml=? where style=?" );
2094 statement = database.
prepare( mySql, myResult );
2095 if ( myResult == SQLITE_OK )
2097 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
2098 sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
2099 sqlite3_step( statement.get() ) == SQLITE_DONE )
2105 myErrorMessage = tr(
"The metadata %1 was updated in the database." ).arg( uri );
2109 myErrorMessage = tr(
"The style %1 was updated in the database." ).arg( uri );
2119 myErrorMessage = tr(
"The metadata %1 could not be updated in the database." ).arg( uri );
2123 myErrorMessage = tr(
"The style %1 could not be updated in the database." ).arg( uri );
2134 myErrorMessage = tr(
"The metadata %1 could not be inserted into database." ).arg( uri );
2138 myErrorMessage = tr(
"The style %1 could not be inserted into database." ).arg( uri );
2145 return myErrorMessage;
2165 QDomDocument myDocument = QDomDocument();
2167 const QDomNode header = myDocument.createProcessingInstruction( QStringLiteral(
"xml" ), QStringLiteral(
"version=\"1.0\" encoding=\"UTF-8\"" ) );
2168 myDocument.appendChild( header );
2170 const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>(
this );
2171 const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>(
this );
2172 if ( !vlayer && !rlayer )
2174 errorMsg = tr(
"Could not save symbology because:\n%1" )
2175 .arg( tr(
"Only vector and raster layers are supported" ) );
2180 QDomElement root = myDocument.createElementNS( QStringLiteral(
"http://www.opengis.net/sld" ), QStringLiteral(
"StyledLayerDescriptor" ) );
2181 QDomElement layerNode;
2184 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.1.0" ) );
2185 root.setAttribute( QStringLiteral(
"xsi:schemaLocation" ), QStringLiteral(
"http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
2186 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
2187 root.setAttribute( QStringLiteral(
"xmlns:se" ), QStringLiteral(
"http://www.opengis.net/se" ) );
2188 root.setAttribute( QStringLiteral(
"xmlns:xlink" ), QStringLiteral(
"http://www.w3.org/1999/xlink" ) );
2189 root.setAttribute( QStringLiteral(
"xmlns:xsi" ), QStringLiteral(
"http://www.w3.org/2001/XMLSchema-instance" ) );
2190 myDocument.appendChild( root );
2193 layerNode = myDocument.createElement( QStringLiteral(
"NamedLayer" ) );
2194 root.appendChild( layerNode );
2201 root.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"1.0.0" ) );
2202 root.setAttribute( QStringLiteral(
"xmlns:gml" ), QStringLiteral(
"http://www.opengis.net/gml" ) );
2203 root.setAttribute( QStringLiteral(
"xmlns:ogc" ), QStringLiteral(
"http://www.opengis.net/ogc" ) );
2204 root.setAttribute( QStringLiteral(
"xmlns:sld" ), QStringLiteral(
"http://www.opengis.net/sld" ) );
2205 myDocument.appendChild( root );
2208 layerNode = myDocument.createElement( QStringLiteral(
"UserLayer" ) );
2209 root.appendChild( layerNode );
2215 context.setValue( exportContext );
2217 props[ QStringLiteral(
"SldExportContext" ) ] = context;
2221 props[ QStringLiteral(
"scaleMinDenom" ) ] = QString::number( mMinScale );
2222 props[ QStringLiteral(
"scaleMaxDenom" ) ] = QString::number( mMaxScale );
2227 if ( !vlayer->
writeSld( layerNode, myDocument, errorMsg, props ) )
2229 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
2236 if ( !rlayer->
writeSld( layerNode, myDocument, errorMsg, props ) )
2238 errorMsg = tr(
"Could not save symbology because:\n%1" ).arg( errorMsg );
2257 const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>(
this );
2264 if ( mlayer->providerType() == QLatin1String(
"ogr" ) )
2266 QStringList theURIParts = uri.split(
'|' );
2267 filename = theURIParts[0];
2269 else if ( mlayer->providerType() == QLatin1String(
"gpx" ) )
2271 QStringList theURIParts = uri.split(
'?' );
2272 filename = theURIParts[0];
2274 else if ( mlayer->providerType() == QLatin1String(
"delimitedtext" ) )
2276 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
2278 if ( filename.isEmpty() )
2286 const QFileInfo myFileInfo( filename );
2287 if ( myFileInfo.exists() || filename.endsWith( QLatin1String(
".sld" ), Qt::CaseInsensitive ) )
2289 const QFileInfo myDirInfo( myFileInfo.path() );
2290 if ( !myDirInfo.isWritable() )
2293 return tr(
"The directory containing your dataset needs to be writable!" );
2297 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() +
".sld";
2300 QDomDocument myDocument;
2305 mlayer->exportSldStyleV2( myDocument, errorMsg, context );
2307 if ( !errorMsg.isNull() )
2313 QFile myFile( myFileName );
2314 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
2316 QTextStream myFileStream( &myFile );
2318 myDocument.save( myFileStream, 2 );
2321 return tr(
"Created default style file as %1" ).arg( myFileName );
2326 return tr(
"ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
2336 QDomDocument myDocument;
2340 QString myErrorMessage;
2342 QFile myFile( uri );
2343 if ( myFile.open( QFile::ReadOnly ) )
2346 resultFlag = myDocument.setContent( &myFile,
true, &myErrorMessage, &line, &column );
2348 myErrorMessage = tr(
"%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
2353 myErrorMessage = tr(
"Unable to open file %1" ).arg( uri );
2358 return myErrorMessage;
2362 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral(
"StyledLayerDescriptor" ) );
2363 if ( myRoot.isNull() )
2365 myErrorMessage = QStringLiteral(
"Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
2367 return myErrorMessage;
2372 const QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral(
"NamedLayer" ) );
2373 if ( namedLayerElem.isNull() )
2375 myErrorMessage = QStringLiteral(
"Info: NamedLayer element not found." );
2377 return myErrorMessage;
2381 resultFlag =
readSld( namedLayerElem, errorMsg );
2384 myErrorMessage = tr(
"Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
2385 return myErrorMessage;
2396 Q_UNUSED( errorMessage )
2398 Q_UNUSED( categories )
2409 Q_UNUSED( errorMessage )
2411 Q_UNUSED( categories )
2417 bool loadDefaultStyleFlag )
2424 if ( loadDefaultStyleFlag )
2442 if ( loadDefaultStyleFlag )
2464 setDataSourcePrivate( dataSource, baseName, provider, options,
flags );
2471void QgsMapLayer::setDataSourcePrivate(
const QString &dataSource,
const QString &baseName,
const QString &provider,
2476 Q_UNUSED( dataSource )
2477 Q_UNUSED( baseName )
2478 Q_UNUSED( provider )
2501 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral(
"renderer-3d" ) );
2502 if ( !renderer3DElem.isNull() )
2504 const QString type3D = renderer3DElem.attribute( QStringLiteral(
"type" ) );
2524 setScaleBasedVisibility( layerElement.attribute( QStringLiteral(
"hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
2525 if ( layerElement.hasAttribute( QStringLiteral(
"minimumScale" ) ) )
2528 setMaximumScale( layerElement.attribute( QStringLiteral(
"minimumScale" ) ).toDouble() );
2529 setMinimumScale( layerElement.attribute( QStringLiteral(
"maximumScale" ) ).toDouble() );
2533 setMaximumScale( layerElement.attribute( QStringLiteral(
"maxScale" ) ).toDouble() );
2534 setMinimumScale( layerElement.attribute( QStringLiteral(
"minScale" ) ).toDouble() );
2541 const QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral(
"flags" ) );
2543 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
2544 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
2546 const QDomNode flagNode = flagsElem.namedItem( it.value() );
2547 if ( flagNode.isNull() )
2549 const bool flagValue = flagNode.toElement().text() ==
"1" ? true :
false;
2550 if (
flags.testFlag( it.key() ) && !flagValue )
2552 else if ( !
flags.testFlag( it.key() ) && flagValue )
2558 if ( categories.testFlag(
Temporal ) )
2563 properties->readXml( layerElement.toElement(), context );
2571 properties->readXml( layerElement.toElement(), context );
2574 if ( categories.testFlag(
Notes ) )
2576 const QDomElement notesElem = layerElement.firstChildElement( QStringLiteral(
"userNotes" ) );
2577 if ( !notesElem.isNull() )
2579 const QString notes = notesElem.attribute( QStringLiteral(
"value" ) );
2596 return mUndoStackStyles;
2603 return mCustomProperties.
keys();
2610 if ( !mCustomProperties.
contains( key ) || mCustomProperties.
value( key ) != value )
2612 mCustomProperties.
setValue( key, value );
2622 for (
const QString &key : mCustomProperties.keys() )
2632 return mCustomProperties;
2640 return mCustomProperties.
value( value, defaultValue );
2647 if ( mCustomProperties.
contains( key ) )
2649 mCustomProperties.
remove( key );
2680 QString sldStyle, qmlStyle;
2681 QDomDocument qmlDocument, sldDocument;
2684 if ( !msgError.isNull() )
2688 qmlStyle = qmlDocument.toString();
2691 if ( !msgError.isNull() )
2695 sldStyle = sldDocument.toString();
2699 description, uiFileContent, useAsDefault, msgError );
2706 QString returnMessage;
2707 QString qml, errorMsg;
2715 if ( !qml.isEmpty() )
2717 QDomDocument myDocument( QStringLiteral(
"qgis" ) );
2718 myDocument.setContent( qml );
2720 returnMessage = QObject::tr(
"Loaded from Provider" );
2726 bool styleExists =
false;
2727 bool styleSuccessfullyLoaded =
false;
2729 returnMessage = loadNamedProperty( theURI,
PropertyType::Style, styleExists, styleSuccessfullyLoaded, categories,
flags );
2732 ( void )styleExists;
2733 resultFlag = styleSuccessfullyLoaded;
2736 if ( ! styleName.isEmpty() )
2744 return returnMessage;
2787 const QString path = sourceParts.value( QStringLiteral(
"path" ) ).toString();
2788 if ( path.isEmpty() )
2792 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
2793 for (
const QString &tempPath : tempPaths )
2795 if ( path.startsWith( tempPath ) )
2825 mLegend->setParent(
this );
2843 return mStyleManager;
2850 if ( renderer == m3DRenderer )
2854 m3DRenderer = renderer;
2871 if ( mRepaintRequestedFired )
2873 mRepaintRequestedFired =
true;
2875 mRepaintRequestedFired =
false;
2928bool QgsMapLayer::isReadOnly()
const
2939 return mOriginalXmlProperties;
2952 const QString uuid = QUuid::createUuid().toString();
2954 QString
id = layerName +
'_' + uuid.mid( 1, uuid.length() - 2 );
2961 const thread_local QRegularExpression idRx( QStringLiteral(
"[\\W]" ) );
2962 id.replace( idRx, QStringLiteral(
"_" ) );
2998 QSet<QgsMapLayerDependency> deps;
2999 const auto constODeps = oDeps;
3017 if ( !lDataProvider )
3022 lDataProvider->setListening( enabled );
3037 if (
QgsMapLayerStore *store = qobject_cast<QgsMapLayerStore *>( parent() ) )
3039 return qobject_cast<QgsProject *>( store->parent() );
3044void QgsMapLayer::onNotified(
const QString &message )
3061 if ( ! forceRecalculate && ! mWgs84Extent.
isNull() )
3065 else if ( ! mExtent2D.
isNull() || ! mExtent3D.
isNull() )
3068 transformer.setBallparkTransformsAreAppropriate(
true );
3071 if ( mExtent2D.
isNull() )
3074 wgs84Extent = transformer.transformBoundingBox( mExtent2D );
3085void QgsMapLayer::updateExtent(
const QgsRectangle &extent )
const
3089 if (
extent == mExtent2D )
3101void QgsMapLayer::updateExtent(
const QgsBox3D &extent )
const
3105 if (
extent == mExtent3D )
3113 updateExtent(
extent.toRectangle() );
3117 QgsDebugMsgLevel( QStringLiteral(
"Unable to update extent with empty parameter" ), 1 );
3132bool QgsMapLayer::rebuildCrs3D( QString *error )
3139 else if ( !mVerticalCrs.
isValid() )
3145 switch ( mCRS.
type() )
3201 QString
metadata = QStringLiteral(
"<h1>" ) + tr(
"General" ) + QStringLiteral(
"</h1>\n<hr>\n" ) + QStringLiteral(
"<table class=\"list-view\">\n" );
3204 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Name" ) + QStringLiteral(
"</td><td>" ) +
name() + QStringLiteral(
"</td></tr>\n" );
3207 bool isLocalPath =
false;
3212 if ( uriComponents.contains( QStringLiteral(
"path" ) ) )
3214 path = uriComponents[QStringLiteral(
"path" )].toString();
3215 QFileInfo fi( path );
3219 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Path" ) + QStringLiteral(
"</td><td>%1" ).arg( QStringLiteral(
"<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral(
"</td></tr>\n" );
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 += QStringLiteral(
"<tr><td class=\"highlight\">" ) + ( sidecarFiles.size() > 1 ? tr(
"Sidecar files" ) : tr(
"Sidecar file" ) ) + QStringLiteral(
"</td><td>%1" ).arg( sidecarFileNames.join( QLatin1String(
", " ) ) ) + QStringLiteral(
"</td></tr>\n" );
3244 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + ( !sidecarFiles.isEmpty() ? tr(
"Total size" ) : tr(
"Size" ) ) + QStringLiteral(
"</td><td>%1" ).arg(
QgsFileUtils::representFileSize( fileSize ) ) + QStringLiteral(
"</td></tr>\n" );
3246 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Last modified" ) + QStringLiteral(
"</td><td>%1" ).arg( QLocale().toString( fi.lastModified() ) ) + ( !lastModifiedFileName.isEmpty() ? QStringLiteral(
" (%1)" ).arg( lastModifiedFileName ) : QString() ) + QStringLiteral(
"</td></tr>\n" );
3249 if ( uriComponents.contains( QStringLiteral(
"url" ) ) )
3251 const QString url = uriComponents[QStringLiteral(
"url" )].toString();
3252 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"URL" ) + QStringLiteral(
"</td><td>%1" ).arg( QStringLiteral(
"<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral(
"</td></tr>\n" );
3258 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Source" ) + QStringLiteral(
"</td><td>%1" ).arg(
publicSource() != path ?
publicSource() : path ) + QStringLiteral(
"</td></tr>\n" );
3262 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Provider" ) + QStringLiteral(
"</td><td>%1" ).arg(
dataProvider()->
name() ) + QStringLiteral(
"</td></tr>\n" );
3264 metadata += QLatin1String(
"</table>\n<br><br>" );
3269 metadata += QStringLiteral(
"<h1>" ) + tr(
"Custom Properties" ) + QStringLiteral(
"</h1>\n<hr>\n" );
3270 metadata += QLatin1String(
"<table class=\"list-view\">\n<tbody>" );
3271 for (
const QString &key : keys )
3274 if ( key.startsWith(
'_' ) )
3278 QString stringValue;
3279 if ( propValue.type() == QVariant::List || propValue.type() == QVariant::StringList )
3281 for (
const QString &s : propValue.toStringList() )
3283 stringValue +=
"<p style=\"margin: 0;\">" + s.toHtmlEscaped() +
"</p>";
3288 stringValue = propValue.toString().toHtmlEscaped();
3292 stringValue = tr(
"<i>value cannot be displayed</i>" );
3295 metadata += QStringLiteral(
"<tr><td class=\"highlight\">%1</td><td>%2</td></tr>" ).arg( key.toHtmlEscaped(), stringValue );
3297 metadata += QLatin1String(
"</tbody></table>\n" );
3298 metadata += QLatin1String(
"<br><br>\n" );
3308 QString
metadata = QStringLiteral(
"<h1>" ) + tr(
"Coordinate Reference System (CRS)" ) + QStringLiteral(
"</h1>\n<hr>\n" );
3309 metadata += QLatin1String(
"<table class=\"list-view\">\n" );
3314 metadata += QStringLiteral(
"<tr><td colspan=\"2\" class=\"highlight\">" ) + tr(
"Unknown" ) + QStringLiteral(
"</td></tr>\n" );
3320 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Units" ) + QStringLiteral(
"</td><td>" )
3321 + (
c.isGeographic() ? tr(
"Geographic (uses latitude and longitude for coordinates)" ) :
QgsUnitTypes::toString(
c.mapUnits() ) )
3322 + QStringLiteral(
"</td></tr>\n" );
3328 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Method" ) + QStringLiteral(
"</td><td>" ) + operation.
description() + QStringLiteral(
"</td></tr>\n" );
3333 const QString celestialBody =
c.celestialBodyName();
3334 if ( !celestialBody.isEmpty() )
3336 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Celestial Body" ) + QStringLiteral(
"</td><td>" ) + celestialBody + QStringLiteral(
"</td></tr>\n" );
3344 QString accuracyString;
3346 if (
c.isDynamic() && std::isnan(
c.coordinateEpoch() ) )
3348 accuracyString = tr(
"Based on a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." );
3358 if ( !ensemble.
code().isEmpty() )
3359 id = QStringLiteral(
"<i>%1</i> (%2:%3)" ).arg( ensemble.
name(), ensemble.
authority(), ensemble.
code() );
3361 id = QStringLiteral(
"<i>%</i>”" ).arg( ensemble.
name() );
3365 accuracyString = tr(
"Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg(
id ).arg( ensemble.
accuracy() );
3369 accuracyString = tr(
"Based on %1, which has a limited accuracy." ).arg(
id );
3378 if ( !accuracyString.isEmpty() )
3380 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Accuracy" ) + QStringLiteral(
"</td><td>" ) + accuracyString + QStringLiteral(
"</td></tr>\n" );
3384 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Reference" ) + QStringLiteral(
"</td><td>%1</td></tr>\n" ).arg(
c.isDynamic() ? tr(
"Dynamic (relies on a datum which is not plate-fixed)" ) : tr(
"Static (relies on a datum which is plate-fixed)" ) );
3387 if ( !std::isnan(
c.coordinateEpoch() ) )
3389 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) + tr(
"Coordinate Epoch" ) + QStringLiteral(
"</td><td>%1</td></tr>\n" ).arg(
qgsDoubleToString(
c.coordinateEpoch(), 3 ) );
3393 metadata += QLatin1String(
"</table>\n<br><br>\n" );
static QString version()
Version string.
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
@ 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.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
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.
@ 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 may to participate in 3D view.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
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.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
A 3-dimensional box composed of x, y, z coordinates.
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
bool isNull() const
Test if the box is null (holding no spatial information).
static QString crsTypeToString(Qgis::CrsType type)
Returns a translated string representing a CRS type.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool hasVerticalAxis() const
Returns true if the CRS has a vertical axis.
void validate()
Perform some validation on this CRS.
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
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.
void setValidationHint(const QString &html)
Set user hint for validation.
QgsCoordinateReferenceSystem verticalCrs() const
Returns the vertical CRS associated with this CRS object.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Qgis::CrsType type() const
Returns the type of the 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.
@ FlagLoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
@ ForceReadOnly
Open layer in a read-only mode (since QGIS 3.28)
@ SkipGetExtent
Skip the extent from provider.
virtual QString name() const =0
Returns a provider name.
QFlags< ReadFlag > ReadFlags
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).
QgsError is container for error messages (report).
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.
This class models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
The QgsMapLayerLegend class is 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 copyTo(QgsMapLayerServerProperties *properties) const
Copy properties to another instance.
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.
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
void reset()
Reset the style manager to a basic state - with one default style which is set as current.
bool renameStyle(const QString &name, const QString &newName)
Rename a stored style to a different name.
QgsMapLayerStyle style(const QString &name) const
Returns data of a stored style - accessed by its unique name.
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
Base class for storage of map layer temporal properties.
Base class for all map layer types.
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.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
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 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 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.
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.
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...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
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.
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
QString mLegendUrl
WMS legend.
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...
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.
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 void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves named and sld style of the layer to the style table in the db.
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.
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 this layer, the generate ID is prefixed by layerName.
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()
virtual QString saveSldStyleV2(bool &resultFlag, const QgsSldExportContext &exportContext) const
Saves the properties of this layer to an SLD format file.
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...
@ 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.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
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...
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 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...
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.
@ Notes
Layer user notes (since QGIS 3.20)
@ Temporal
Temporal properties (since QGIS 3.14)
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Elevation
Elevation settings (since QGIS 3.18)
@ 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 ...
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
virtual void exportSldStyleV2(QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext) const
Export the properties of this layer as SLD style in a QDomDocument.
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 QgsDataProvider::ReadFlags providerReadFlags(const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
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 setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
QStringList keys() const
Returns a list of all stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void remove(const QString &key)
Removes a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
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
The derived translate() translates with QTranslator and qm file the sourceText.
A class to describe 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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
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.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
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.
bool saveStyle(const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
Represents a raster layer.
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.
The class is used as a container of context for various read/write operations on other objects.
MAYBE_UNUSED NODISCARD 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.
bool isNull() const
Test if the rectangle is null (holding no spatial information).
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
QString exportFilePath() const
Returns the export file path for the SLD.
void setExportFilePath(const QString &exportFilePath)
Sets the export file path for the SLD to exportFilePath.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
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 data sets.
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 QDomElement writeBox3D(const QgsBox3D &box, QDomDocument &doc, const QString &elementName=QStringLiteral("extent3D"))
Encodes a 3D box to a DOM 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=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
static QgsRectangle readRectangle(const QDomElement &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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.