59 #include <QApplication> 63 #include <QTextStream> 64 #include <QTemporaryFile> 70 #include <sys/utime.h> 88 QStringList keyTokens = QStringList( scope );
89 keyTokens += key.split(
'/', QString::SkipEmptyParts );
92 keyTokens.push_front( QStringLiteral(
"properties" ) );
95 for (
int i = 0; i < keyTokens.size(); ++i )
97 QString keyToken = keyTokens.at( i );
101 QString nameCharRegexp = QStringLiteral(
"[^:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD\\-\\.0-9\\xB7\\x0300-\\x036F\\x203F-\\x2040]" );
102 QString nameStartCharRegexp = QStringLiteral(
"^[^:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x2FF\\x370-\\x37D\\x37F-\\x1FFF\\x200C-\\x200D\\x2070-\\x218F\\x2C00-\\x2FEF\\x3001-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFFD]" );
104 if ( keyToken.contains( QRegExp( nameCharRegexp ) ) || keyToken.contains( QRegExp( nameStartCharRegexp ) ) )
107 QString errorString = QObject::tr(
"Entry token invalid : '%1'. The token will not be saved to file." ).arg( keyToken );
137 while ( !keySequence.isEmpty() )
141 if ( keySequence.first() == currentProperty->
name() )
144 keySequence.pop_front();
146 if ( 1 == keySequence.count() )
149 return currentProperty->
find( keySequence.front() );
151 else if ( keySequence.isEmpty() )
156 return currentProperty;
158 else if ( ( nextProperty = currentProperty->
find( keySequence.first() ) ) )
160 if ( nextProperty->
isKey() )
164 else if ( nextProperty->
isValue() && 1 == keySequence.count() )
170 return currentProperty;
208 const QVariant &value,
209 bool &propertiesModified )
218 propertiesModified =
false;
219 while ( ! keySequence.isEmpty() )
223 if ( keySequence.first() == currentProperty->
name() )
226 keySequence.pop_front();
230 if ( 1 == keySequence.count() )
233 if ( !property || property->value() != value )
235 currentProperty->
setValue( keySequence.front(), value );
236 propertiesModified =
true;
239 return currentProperty;
243 else if ( keySequence.isEmpty() )
245 if ( currentProperty->
value() != value )
248 propertiesModified =
true;
251 return currentProperty;
253 else if ( ( nextProperty = currentProperty->
find( keySequence.first() ) ) )
257 if ( currentProperty )
268 if ( ( newPropertyKey = currentProperty->
addKey( keySequence.first() ) ) )
270 currentProperty = newPropertyKey;
303 while ( ! keySequence.isEmpty() )
307 if ( keySequence.first() == currentProperty->
name() )
310 keySequence.pop_front();
314 if ( 1 == keySequence.count() )
316 currentProperty->
removeKey( keySequence.front() );
321 else if ( keySequence.isEmpty() )
323 previousQgsPropertyKey->
removeKey( currentProperty->
name() );
325 else if ( ( nextProperty = currentProperty->
find( keySequence.first() ) ) )
327 previousQgsPropertyKey = currentProperty;
330 if ( currentProperty )
356 , mSnappingConfig( this )
365 mProperties.
setName( QStringLiteral(
"properties" ) );
397 [ = ](
const QList<QgsMapLayer *> &
layers )
399 for (
const auto &layer :
layers )
406 [ = ](
const QList<QgsMapLayer *> &
layers )
408 for (
const auto &layer :
layers )
419 mIsBeingDeleted =
true;
422 delete mBadLayerHandler;
423 delete mRelationManager;
424 delete mLayerTreeRegistryBridge;
426 if (
this == sProject )
432 void QgsProject::setInstance(
QgsProject *project )
449 if ( title == mMetadata.
title() )
460 return mMetadata.
title();
470 if ( dirty && mDirtyBlockCount > 0 )
473 if ( mDirty == dirty )
482 if ( path == mHomePath )
493 const QList<QgsAttributeEditorElement *> elements = parent->
children();
501 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:formcontainers" ).arg( layerId ), container->
name() );
503 if ( !container->
children().empty() )
516 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1" ).arg( layer->layerId() ), layer->name() );
525 for (
const QgsField &field : fields )
528 if ( field.alias().isEmpty() )
529 fieldName = field.name();
531 fieldName = field.alias();
533 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( vlayer->
id() ), fieldName );
535 if ( field.editorWidgetSetup().type() == QStringLiteral(
"ValueRelation" ) )
537 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg( vlayer->
id(), field.name() ), field.editorWidgetSetup().config().value( QStringLiteral(
"Value" ) ).toString() );
548 const QList<QgsLayerTreeGroup *> groupLayers = mRootGroup->
findGroups();
551 translationContext->
registerTranslation( QStringLiteral(
"project:layergroups" ), groupLayer->name() );
555 const QList<QgsRelation> &relations = mRelationManager->
relations().values();
558 translationContext->
registerTranslation( QStringLiteral(
"project:relations" ), relation.name() );
564 if ( name == mFile.fileName() )
569 mFile.setFileName( name );
573 if ( newHomePath != oldHomePath )
581 return mFile.fileName();
586 return QFileInfo( mFile );
599 storage->readProjectStorageMetadata( mFile.fileName(),
metadata );
613 if ( mFile.fileName().isEmpty() )
624 if ( mFile.fileName().isEmpty() )
635 storage->readProjectStorageMetadata( mFile.fileName(),
metadata );
636 return metadata.
name;
640 return QFileInfo( mFile.fileName() ).completeBaseName();
655 writeEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectionsEnabled" ), crs.
isValid() ? 1 : 0 );
662 if ( !
crs().isValid() )
665 return readEntry( QStringLiteral(
"Measure" ), QStringLiteral(
"/Ellipsoid" ),
GEO_NONE );
670 writeEntry( QStringLiteral(
"Measure" ), QStringLiteral(
"/Ellipsoid" ), ellipsoid );
676 return mTransformContext;
681 if ( context == mTransformContext )
684 mTransformContext = context;
685 for (
auto &layer : mLayerStore.get()->mapLayers() )
687 layer->setTransformContext( context );
696 mFile.setFileName( QString() );
698 mHomePath = QString();
699 mAutoTransaction =
false;
700 mEvaluateDefaultValues =
false;
702 mTrustLayerMetadata =
false;
703 mCustomVariables.clear();
716 mEmbeddedLayers.clear();
717 mRelationManager->
clear();
718 mAnnotationManager->clear();
719 mLayoutManager->clear();
720 mSnappingConfig.
reset();
727 mLabelingEngineSettings->clear();
734 if ( !mIsBeingDeleted )
742 writeEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/Automatic" ),
true );
743 writeEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DecimalPlaces" ), 2 );
744 writeEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
false );
747 writeEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/DistanceUnits" ), s.
value( QStringLiteral(
"/qgis/measure/displayunits" ) ).toString() );
748 writeEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/AreaUnits" ), s.
value( QStringLiteral(
"/qgis/measure/areaunits" ) ).toString() );
761 QgsDebugMsg( QStringLiteral(
"current properties:" ) );
762 topQgsPropertyKey.
dump();
798 QDomElement propertiesElem = doc.documentElement().firstChildElement( QStringLiteral(
"properties" ) );
800 if ( propertiesElem.isNull() )
805 QDomNodeList scopes = propertiesElem.childNodes();
807 if ( scopes.count() < 1 )
809 QgsDebugMsg( QStringLiteral(
"empty ``properties'' XML tag ... bailing" ) );
813 if ( ! project_properties.
readXml( propertiesElem ) )
815 QgsDebugMsg( QStringLiteral(
"Project_properties.readXml() failed" ) );
824 static void _getTitle(
const QDomDocument &doc, QString &
title )
826 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"title" ) );
832 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
836 QDomNode titleNode = nl.item( 0 );
838 if ( !titleNode.hasChildNodes() )
840 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
844 QDomNode titleTextNode = titleNode.firstChild();
846 if ( !titleTextNode.isText() )
848 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
852 QDomText titleText = titleTextNode.toText();
854 title = titleText.data();
860 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"qgis" ) );
864 QgsDebugMsg( QStringLiteral(
" unable to find qgis element in project file" ) );
868 QDomNode qgisNode = nl.item( 0 );
870 QDomElement qgisElement = qgisNode.toElement();
871 QgsProjectVersion projectVersion( qgisElement.attribute( QStringLiteral(
"version" ) ) );
872 return projectVersion;
878 return mSnappingConfig;
883 if ( mSnappingConfig == snappingConfig )
891 bool QgsProject::_getMapLayers(
const QDomDocument &doc, QList<QDomNode> &brokenNodes )
896 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"maplayer" ) );
900 if ( 0 == nl.count() )
910 bool returnStatus =
true;
916 if ( depSorter.hasCycle() || depSorter.hasMissingDependency() )
919 const QVector<QDomNode> sortedLayerNodes = depSorter.sortedLayerNodes();
922 for (
const QDomNode &node : sortedLayerNodes )
924 const QDomElement element = node.toElement();
926 const QString name =
translate( QStringLiteral(
"project:layers:%1" ).arg( node.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), node.namedItem( QStringLiteral(
"layername" ) ).toElement().text() );
927 if ( !name.isNull() )
928 emit
loadingLayer( tr(
"Loading layer %1" ).arg( name ) );
930 if ( element.attribute( QStringLiteral(
"embedded" ) ) == QLatin1String(
"1" ) )
932 createEmbeddedLayer( element.attribute( QStringLiteral(
"id" ) ),
readPath( element.attribute( QStringLiteral(
"project" ) ) ), brokenNodes );
941 if ( !addLayer( element, brokenNodes, context ) )
943 returnStatus =
false;
946 if ( !messages.isEmpty() )
958 bool QgsProject::addLayer(
const QDomElement &layerElem, QList<QDomNode> &brokenNodes,
QgsReadWriteContext &context )
960 QString type = layerElem.attribute( QStringLiteral(
"type" ) );
962 std::unique_ptr<QgsMapLayer>
mapLayer;
964 if ( type == QLatin1String(
"vector" ) )
966 mapLayer = qgis::make_unique<QgsVectorLayer>();
968 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mapLayer.get() ) )
970 vl->setReadExtentFromXml( mTrustLayerMetadata );
973 else if ( type == QLatin1String(
"raster" ) )
975 mapLayer = qgis::make_unique<QgsRasterLayer>();
977 else if ( type == QLatin1String(
"mesh" ) )
979 mapLayer = qgis::make_unique<QgsMeshLayer>();
981 else if ( type == QLatin1String(
"plugin" ) )
983 QString
typeName = layerElem.attribute( QStringLiteral(
"name" ) );
989 QgsDebugMsg( QStringLiteral(
"Unable to create layer" ) );
993 Q_CHECK_PTR( mapLayer );
997 const QString layerId { layerElem.namedItem( QStringLiteral(
"id" ) ).toElement().text() };
998 Q_ASSERT( ! layerId.isEmpty() );
1002 bool layerIsValid = mapLayer->
readLayerXml( layerElem, context ) && mapLayer->isValid();
1003 QList<QgsMapLayer *> newLayers;
1004 newLayers << mapLayer.get();
1015 QgsDebugMsg(
"Unable to load " + type +
" layer" );
1016 brokenNodes.push_back( layerElem );
1021 if ( ! layerWasStored )
1026 return layerIsValid;
1031 mFile.setFileName( filename );
1038 QString filename = mFile.fileName();
1043 QTemporaryFile inDevice;
1044 if ( !inDevice.open() )
1046 setError( tr(
"Unable to open %1" ).arg( inDevice.fileName() ) );
1052 if ( !storage->readProject( filename, &inDevice, context ) )
1054 QString err = tr(
"Unable to open %1" ).arg( filename );
1055 QList<QgsReadWriteContext::ReadWriteMessage> messages = context.
takeMessages();
1056 if ( !messages.isEmpty() )
1057 err += QStringLiteral(
"\n\n" ) + messages.last().message();
1061 returnValue = unzip( inDevice.fileName() );
1067 returnValue = unzip( mFile.fileName() );
1072 returnValue = readProjectFile( mFile.fileName() );
1078 mFile.setFileName( filename );
1083 mTranslator.reset(
nullptr );
1090 bool QgsProject::readProjectFile(
const QString &filename )
1092 QFile projectFile( filename );
1097 QString localeFileName = QStringLiteral(
"%1_%2" ).arg( QFileInfo( projectFile.fileName() ).
baseName(), settings.
value( QStringLiteral(
"locale/userLocale" ), QString() ).toString() );
1099 if ( QFile( QStringLiteral(
"%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).
absolutePath(), localeFileName ) ).exists() )
1101 mTranslator.reset(
new QTranslator() );
1102 mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).
absolutePath() );
1105 std::unique_ptr<QDomDocument> doc(
new QDomDocument( QStringLiteral(
"qgis" ) ) );
1107 if ( !projectFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
1109 projectFile.close();
1111 setError( tr(
"Unable to open %1" ).arg( projectFile.fileName() ) );
1120 if ( !doc->setContent( &projectFile, &errorMsg, &line, &column ) )
1124 QMessageBox::critical( 0, tr(
"Read Project File" ),
1125 tr(
"%1 at line %2 column %3" ).arg( errorMsg ).arg( line ).arg( column ) );
1128 QString errorString = tr(
"Project file read error in file %1: %2 at line %3 column %4" )
1129 .arg( projectFile.fileName(), errorMsg ).arg( line ).arg( column );
1133 projectFile.close();
1135 setError( tr(
"%1 for file %2" ).arg( errorString, projectFile.fileName() ) );
1140 projectFile.close();
1142 QgsDebugMsg(
"Opened document " + projectFile.fileName() );
1148 if ( thisVersion > fileVersion )
1151 "version of qgis (saved in " + fileVersion.text() +
1153 "). Problems may occur." );
1159 QgsDebugMsg( QStringLiteral(
"Emitting oldProjectVersionWarning(oldVersion)." ) );
1161 projectFile.updateRevision( thisVersion );
1165 QString
fileName = mFile.fileName();
1166 std::unique_ptr<QgsAuxiliaryStorage> aStorage = std::move( mAuxiliaryStorage );
1168 mAuxiliaryStorage = std::move( aStorage );
1169 mFile.setFileName( fileName );
1174 QgsDebugMsg( QString::number( mProperties.
count() ) +
" properties read" );
1176 dump_( mProperties );
1180 _getTitle( *doc, oldTitle );
1182 QDomNodeList homePathNl = doc->elementsByTagName( QStringLiteral(
"homePath" ) );
1183 if ( homePathNl.count() > 0 )
1185 QDomElement homePathElement = homePathNl.at( 0 ).toElement();
1186 QString
homePath = homePathElement.attribute( QStringLiteral(
"path" ) );
1187 if ( !homePath.isEmpty() )
1201 if (
readNumEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectionsEnabled" ), 0 ) )
1204 QDomNode srsNode = doc->documentElement().namedItem( QStringLiteral(
"projectCrs" ) );
1205 if ( !srsNode.isNull() )
1207 projectCrs.
readXml( srsNode );
1212 QString projCrsString =
readEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectCRSProj4String" ) );
1213 long currentCRS =
readNumEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectCRSID" ), -1 );
1216 if ( currentCRS >= 0 )
1222 if ( !projCrsString.isEmpty() && ( !projectCrs.
isValid() || projectCrs.
toProj4() != projCrsString ) )
1236 QStringList datumErrors;
1237 if ( !mTransformContext.
readXml( doc->documentElement(), context, datumErrors ) && !datumErrors.empty() )
1243 QDomNodeList nl = doc->elementsByTagName( QStringLiteral(
"projectMetadata" ) );
1244 if ( !nl.isEmpty() )
1246 QDomElement metadataElement = nl.at( 0 ).toElement();
1254 if ( mMetadata.
title().isEmpty() && !oldTitle.isEmpty() )
1261 nl = doc->elementsByTagName( QStringLiteral(
"autotransaction" ) );
1264 QDomElement transactionElement = nl.at( 0 ).toElement();
1265 if ( transactionElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1266 mAutoTransaction =
true;
1269 nl = doc->elementsByTagName( QStringLiteral(
"evaluateDefaultValues" ) );
1272 QDomElement evaluateDefaultValuesElement = nl.at( 0 ).toElement();
1273 if ( evaluateDefaultValuesElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1274 mEvaluateDefaultValues =
true;
1277 nl = doc->elementsByTagName( QStringLiteral(
"trust" ) );
1280 QDomElement trustElement = nl.at( 0 ).toElement();
1281 if ( trustElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1282 mTrustLayerMetadata =
true;
1289 QDomElement layerTreeElem = doc->documentElement().firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1290 if ( !layerTreeElem.isNull() )
1299 mLayerTreeRegistryBridge->
setEnabled(
false );
1302 QList<QDomNode> brokenNodes;
1303 bool clean = _getMapLayers( *doc, brokenNodes );
1308 QgsDebugMsg( QStringLiteral(
"Unable to get map layers from project file." ) );
1310 if ( !brokenNodes.isEmpty() )
1312 QgsDebugMsg(
"there are " + QString::number( brokenNodes.size() ) +
" broken layers" );
1322 QMap<QString, QgsMapLayer *>
layers = mLayerStore->mapLayers();
1323 for ( QMap<QString, QgsMapLayer *>::iterator it = layers.begin(); it != layers.end(); it++ )
1325 it.value()->resolveReferences(
this );
1328 mLayerTreeRegistryBridge->
setEnabled(
true );
1331 loadEmbeddedNodes( mRootGroup );
1337 if ( !layerTreeElem.isNull() )
1343 QDomElement layerTreeCanvasElem = doc->documentElement().firstChildElement( QStringLiteral(
"layer-tree-canvas" ) );
1344 if ( !layerTreeCanvasElem.isNull( ) )
1352 const QStringList requiredLayerIds =
readListEntry( QStringLiteral(
"RequiredLayers" ), QStringLiteral(
"Layers" ) );
1353 for (
const QString &layerId : requiredLayerIds )
1357 layer->setFlags( layer->flags() & ~
QgsMapLayer::Removable );
1360 const QStringList disabledLayerIds =
readListEntry( QStringLiteral(
"Identify" ), QStringLiteral(
"/disabledLayers" ) );
1361 for (
const QString &layerId : disabledLayerIds )
1365 layer->setFlags( layer->flags() & ~
QgsMapLayer::Identifiable );
1379 mMapThemeCollection->readXml( *doc );
1381 mLabelingEngineSettings->readSettingsFromProject(
this );
1384 mAnnotationManager->readXml( doc->documentElement(), context );
1385 mLayoutManager->readXml( doc->documentElement(), *doc );
1388 QMap<QString, QgsMapLayer *> existingMaps =
mapLayers();
1389 for ( QMap<QString, QgsMapLayer *>::iterator it = existingMaps.begin(); it != existingMaps.end(); it++ )
1391 it.value()->setDependencies( it.value()->dependencies() );
1396 QStringList variableNames =
readListEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableNames" ) );
1397 QStringList variableValues =
readListEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableValues" ) );
1399 mCustomVariables.clear();
1400 if ( variableNames.length() == variableValues.length() )
1402 for (
int i = 0; i < variableNames.length(); ++i )
1404 mCustomVariables.insert( variableNames.at( i ), variableValues.at( i ) );
1409 QgsMessageLog::logMessage( tr(
"Project Variables Invalid" ), tr(
"The project contains invalid variable settings." ) );
1433 QString newFileName( QStringLiteral(
"%1/%2.qgs" ).arg( QFileInfo( projectFile.fileName() ).
absolutePath(), localeFileName ) );
1453 const auto constChildren = group->
children();
1459 if ( childGroup->
customProperty( QStringLiteral(
"embedded" ) ).toInt() )
1462 QString projectPath =
readPath( childGroup->
customProperty( QStringLiteral(
"embedded_project" ) ).toString() );
1463 childGroup->
setCustomProperty( QStringLiteral(
"embedded_project" ), projectPath );
1467 QList<QgsLayerTreeNode *> clonedChildren;
1468 const auto constChildren = newGroup->
children();
1470 clonedChildren << newGroupChild->clone();
1478 loadEmbeddedNodes( childGroup );
1483 if ( child->customProperty( QStringLiteral(
"embedded" ) ).toInt() )
1485 QList<QDomNode> brokenNodes;
1495 return mCustomVariables;
1500 if ( variables == mCustomVariables )
1504 QStringList variableNames;
1505 QStringList variableValues;
1507 QVariantMap::const_iterator it = variables.constBegin();
1508 for ( ; it != variables.constEnd(); ++it )
1510 variableNames << it.key();
1511 variableValues << it.value().toString();
1514 writeEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableNames" ), variableNames );
1515 writeEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableValues" ), variableValues );
1517 mCustomVariables = variables;
1524 *mLabelingEngineSettings = settings;
1530 return *mLabelingEngineSettings;
1535 return mLayerStore.get();
1540 return mLayerStore.get();
1545 QList<QgsVectorLayer *>
layers;
1546 QStringList layerIds =
readListEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/AvoidIntersectionsList" ), QStringList() );
1547 const auto constLayerIds = layerIds;
1548 for (
const QString &layerId : constLayerIds )
1559 const auto constLayers =
layers;
1561 list << layer->id();
1562 writeEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/AvoidIntersectionsList" ), list );
1576 void QgsProject::onMapLayersAdded(
const QList<QgsMapLayer *> &
layers )
1578 QMap<QString, QgsMapLayer *> existingMaps =
mapLayers();
1580 bool tgChanged =
false;
1582 const auto constLayers =
layers;
1585 if ( layer->isValid() )
1602 mTransactionGroups.insert( qMakePair( key, connString ), tg );
1617 for ( QMap<QString, QgsMapLayer *>::iterator it = existingMaps.begin(); it != existingMaps.end(); it++ )
1619 QSet<QgsMapLayerDependency> deps = it.value()->dependencies();
1620 if ( deps.contains( layer->id() ) )
1623 it.value()->setDependencies( deps );
1629 if ( mSnappingConfig.
addLayers( layers ) )
1633 void QgsProject::onMapLayersRemoved(
const QList<QgsMapLayer *> &
layers )
1639 void QgsProject::cleanTransactionGroups(
bool force )
1641 bool changed =
false;
1642 for ( QMap< QPair< QString, QString>,
QgsTransactionGroup *>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
1644 if ( tg.value()->isEmpty() || force )
1647 tg = mTransactionGroups.erase( tg );
1665 QList<QDomNode> brokenNodes;
1666 if ( addLayer( layerNode.toElement(), brokenNodes, context ) )
1670 QVector<QgsVectorLayer *> vectorLayers = layers<QgsVectorLayer *>();
1671 const auto constVectorLayers = vectorLayers;
1675 layer->resolveReferences(
this );
1685 mFile.setFileName( filename );
1696 writeEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
true );
1698 QString tempPath = QStandardPaths::standardLocations( QStandardPaths::TempLocation ).at( 0 );
1699 QString tmpZipFilename( tempPath + QDir::separator() + QUuid::createUuid().toString() );
1701 if ( !zip( tmpZipFilename ) )
1704 QFile tmpZipFile( tmpZipFilename );
1705 if ( !tmpZipFile.open( QIODevice::ReadOnly ) )
1707 setError( tr(
"Unable to read file %1" ).arg( tmpZipFilename ) );
1713 if ( !storage->writeProject( mFile.fileName(), &tmpZipFile, context ) )
1715 QString err = tr(
"Unable to save project to storage %1" ).arg( mFile.fileName() );
1716 QList<QgsReadWriteContext::ReadWriteMessage> messages = context.
takeMessages();
1717 if ( !messages.isEmpty() )
1718 err += QStringLiteral(
"\n\n" ) + messages.last().message();
1724 QFile::remove( tmpZipFilename );
1731 return zip( mFile.fileName() );
1737 const bool asOk = saveAuxiliaryStorage();
1738 const bool writeOk = writeProjectFile( mFile.fileName() );
1741 if ( !asOk && writeOk )
1743 const QString err = mAuxiliaryStorage->errorString();
1744 setError( tr(
"Unable to save auxiliary storage ('%1')" ).arg( err ) );
1747 return asOk && writeOk;
1751 bool QgsProject::writeProjectFile(
const QString &filename )
1753 QFile projectFile( filename );
1759 QFileInfo myFileInfo( projectFile );
1760 if ( myFileInfo.exists() && !myFileInfo.isWritable() )
1762 setError( tr(
"%1 is not writable. Please adjust permissions (if possible) and try again." )
1763 .arg( projectFile.fileName() ) );
1771 QDomImplementation DomImplementation;
1772 DomImplementation.setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
1774 QDomDocumentType documentType =
1775 DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ),
1776 QStringLiteral(
"SYSTEM" ) );
1777 std::unique_ptr<QDomDocument> doc(
new QDomDocument( documentType ) );
1779 QDomElement qgisNode = doc->createElement( QStringLiteral(
"qgis" ) );
1780 qgisNode.setAttribute( QStringLiteral(
"projectname" ),
title() );
1781 qgisNode.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"%1" ).arg(
Qgis::QGIS_VERSION ) );
1783 doc->appendChild( qgisNode );
1785 QDomElement homePathNode = doc->createElement( QStringLiteral(
"homePath" ) );
1786 homePathNode.setAttribute( QStringLiteral(
"path" ), mHomePath );
1787 qgisNode.appendChild( homePathNode );
1790 QDomElement titleNode = doc->createElement( QStringLiteral(
"title" ) );
1791 qgisNode.appendChild( titleNode );
1793 QDomElement transactionNode = doc->createElement( QStringLiteral(
"autotransaction" ) );
1794 transactionNode.setAttribute( QStringLiteral(
"active" ), mAutoTransaction ? 1 : 0 );
1795 qgisNode.appendChild( transactionNode );
1797 QDomElement evaluateDefaultValuesNode = doc->createElement( QStringLiteral(
"evaluateDefaultValues" ) );
1798 evaluateDefaultValuesNode.setAttribute( QStringLiteral(
"active" ), mEvaluateDefaultValues ? 1 : 0 );
1799 qgisNode.appendChild( evaluateDefaultValuesNode );
1801 QDomElement trustNode = doc->createElement( QStringLiteral(
"trust" ) );
1802 trustNode.setAttribute( QStringLiteral(
"active" ), mTrustLayerMetadata ? 1 : 0 );
1803 qgisNode.appendChild( trustNode );
1805 QDomText titleText = doc->createTextNode(
title() );
1806 titleNode.appendChild( titleText );
1809 QDomElement srsNode = doc->createElement( QStringLiteral(
"projectCrs" ) );
1811 qgisNode.appendChild( srsNode );
1818 clonedRoot->
writeXml( qgisNode, context );
1831 QDomElement projectLayersNode = doc->createElement( QStringLiteral(
"projectlayers" ) );
1833 QMap<QString, QgsMapLayer *>::ConstIterator li = layers.constBegin();
1834 while ( li != layers.end() )
1840 QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.constFind( ml->
id() );
1841 if ( emIt == mEmbeddedLayers.constEnd() )
1843 QDomElement maplayerElem;
1849 maplayerElem = doc->createElement( QStringLiteral(
"maplayer" ) );
1854 QDomDocument document;
1857 maplayerElem = document.firstChildElement();
1861 QgsDebugMsg( QStringLiteral(
"Could not restore layer properties for layer %1" ).arg( ml->
id() ) );
1867 projectLayersNode.appendChild( maplayerElem );
1873 if ( emIt.value().second )
1875 QDomElement mapLayerElem = doc->createElement( QStringLiteral(
"maplayer" ) );
1876 mapLayerElem.setAttribute( QStringLiteral(
"embedded" ), 1 );
1877 mapLayerElem.setAttribute( QStringLiteral(
"project" ),
writePath( emIt.value().first ) );
1878 mapLayerElem.setAttribute( QStringLiteral(
"id" ), ml->
id() );
1879 projectLayersNode.appendChild( mapLayerElem );
1886 qgisNode.appendChild( projectLayersNode );
1888 QDomElement layerOrderNode = doc->createElement( QStringLiteral(
"layerorder" ) );
1890 for (
QgsMapLayer *layer : constCustomLayerOrder )
1892 QDomElement mapLayerElem = doc->createElement( QStringLiteral(
"layer" ) );
1893 mapLayerElem.setAttribute( QStringLiteral(
"id" ), layer->id() );
1894 layerOrderNode.appendChild( mapLayerElem );
1896 qgisNode.appendChild( layerOrderNode );
1898 mLabelingEngineSettings->writeSettingsToProject(
this );
1902 dump_( mProperties );
1904 QgsDebugMsg( QStringLiteral(
"there are %1 property scopes" ).arg( static_cast<int>( mProperties.
count() ) ) );
1909 mProperties.
writeXml( QStringLiteral(
"properties" ), qgisNode, *doc );
1912 mMapThemeCollection->writeXml( *doc );
1914 mTransformContext.
writeXml( qgisNode, context );
1916 QDomElement metadataElem = doc->createElement( QStringLiteral(
"projectMetadata" ) );
1918 qgisNode.appendChild( metadataElem );
1920 QDomElement annotationsElem = mAnnotationManager->writeXml( *doc, context );
1921 qgisNode.appendChild( annotationsElem );
1923 QDomElement layoutElem = mLayoutManager->writeXml( *doc );
1924 qgisNode.appendChild( layoutElem );
1932 QFile backupFile( QStringLiteral(
"%1~" ).arg( filename ) );
1934 ok &= backupFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
1935 ok &= projectFile.open( QIODevice::ReadOnly );
1938 while ( ok && !projectFile.atEnd() )
1940 ba = projectFile.read( 10240 );
1941 ok &= backupFile.write( ba ) == ba.size();
1944 projectFile.close();
1949 setError( tr(
"Unable to create backup file %1" ).arg( backupFile.fileName() ) );
1954 struct utimbuf tb = {
static_cast<time_t
>( fi.lastRead().toSecsSinceEpoch() ), static_cast<time_t>( fi.lastModified().toSecsSinceEpoch() ) };
1955 utime( backupFile.fileName().toUtf8().constData(), &tb );
1958 if ( !projectFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1960 projectFile.close();
1963 setError( tr(
"Unable to save to file %1" ).arg( projectFile.fileName() ) );
1967 QTemporaryFile tempFile;
1968 bool ok = tempFile.open();
1971 QTextStream projectFileStream( &tempFile );
1972 doc->save( projectFileStream, 2 );
1973 ok &= projectFileStream.pos() > -1;
1975 ok &= tempFile.seek( 0 );
1978 while ( ok && !tempFile.atEnd() )
1980 ba = tempFile.read( 10240 );
1981 ok &= projectFile.write( ba ) == ba.size();
1984 ok &= projectFile.error() == QFile::NoError;
1986 projectFile.close();
1993 setError( tr(
"Unable to save to file %1. Your project " 1994 "may be corrupted on disk. Try clearing some space on the volume and " 1995 "check file permissions before pressing save again." )
1996 .arg( projectFile.fileName() ) );
2009 bool propertiesModified;
2010 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2012 if ( propertiesModified )
2020 bool propertiesModified;
2021 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2023 if ( propertiesModified )
2031 bool propertiesModified;
2032 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2034 if ( propertiesModified )
2042 bool propertiesModified;
2043 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2045 if ( propertiesModified )
2053 bool propertiesModified;
2054 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2056 if ( propertiesModified )
2064 const QStringList &def,
2073 value =
property->value();
2075 bool valid = QVariant::StringList == value.type();
2081 return value.toStringList();
2100 value =
property->value();
2102 bool valid = value.canConvert( QVariant::String );
2107 return value.toString();
2122 value =
property->value();
2125 bool valid = value.canConvert( QVariant::Int );
2134 return value.toInt();
2147 QVariant value =
property->value();
2149 bool valid = value.canConvert( QVariant::Double );
2154 return value.toDouble();
2167 QVariant value =
property->value();
2169 bool valid = value.canConvert( QVariant::Bool );
2174 return value.toBool();
2183 if (
findKey_( scope, key, mProperties ) )
2189 return !
findKey_( scope, key, mProperties );
2197 QStringList entries;
2199 if ( foundProperty )
2214 QStringList entries;
2216 if ( foundProperty )
2229 dump_( mProperties );
2234 bool absolutePaths =
readBoolEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
false );
2248 void QgsProject::setError(
const QString &errorMessage )
2250 mErrorMessage = errorMessage;
2255 return mErrorMessage;
2258 void QgsProject::clearError()
2260 setError( QString() );
2265 delete mBadLayerHandler;
2266 mBadLayerHandler = handler;
2271 QHash< QString, QPair< QString, bool > >::const_iterator it = mEmbeddedLayers.find(
id );
2272 if ( it == mEmbeddedLayers.constEnd() )
2276 return it.value().first;
2284 static QString sPrevProjectFilePath;
2285 static QDateTime sPrevProjectFileTimestamp;
2286 static QDomDocument sProjectDocument;
2288 QDateTime projectFileTimestamp = QFileInfo( projectFilePath ).lastModified();
2290 if ( projectFilePath != sPrevProjectFilePath || projectFileTimestamp != sPrevProjectFileTimestamp )
2292 sPrevProjectFilePath.clear();
2294 QFile projectFile( projectFilePath );
2295 if ( !projectFile.open( QIODevice::ReadOnly ) )
2300 if ( !sProjectDocument.setContent( &projectFile ) )
2305 sPrevProjectFilePath = projectFilePath;
2306 sPrevProjectFileTimestamp = projectFileTimestamp;
2310 bool useAbsolutePaths =
true;
2312 QDomElement propertiesElem = sProjectDocument.documentElement().firstChildElement( QStringLiteral(
"properties" ) );
2313 if ( !propertiesElem.isNull() )
2315 QDomElement absElem = propertiesElem.firstChildElement( QStringLiteral(
"Paths" ) ).firstChildElement( QStringLiteral(
"Absolute" ) );
2316 if ( !absElem.isNull() )
2318 useAbsolutePaths = absElem.text().compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
2323 if ( !useAbsolutePaths )
2328 QDomElement projectLayersElem = sProjectDocument.documentElement().firstChildElement( QStringLiteral(
"projectlayers" ) );
2329 if ( projectLayersElem.isNull() )
2334 QDomNodeList mapLayerNodes = projectLayersElem.elementsByTagName( QStringLiteral(
"maplayer" ) );
2335 for (
int i = 0; i < mapLayerNodes.size(); ++i )
2338 QDomElement mapLayerElem = mapLayerNodes.at( i ).toElement();
2339 QString
id = mapLayerElem.firstChildElement( QStringLiteral(
"id" ) ).text();
2340 if (
id == layerId )
2343 if ( mapLayerElem.attribute( QStringLiteral(
"embedded" ) ) == QLatin1String(
"1" ) )
2348 mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );
2350 if ( addLayer( mapLayerElem, brokenNodes, embeddedContext ) )
2356 mEmbeddedLayers.remove( layerId );
2369 QFile projectFile( projectFilePath );
2370 if ( !projectFile.open( QIODevice::ReadOnly ) )
2375 QDomDocument projectDocument;
2376 if ( !projectDocument.setContent( &projectFile ) )
2388 QDomElement layerTreeElem = projectDocument.documentElement().firstChildElement( QStringLiteral(
"layer-tree-group" ) );
2389 if ( !layerTreeElem.isNull() )
2399 if ( !group || group->customProperty( QStringLiteral(
"embedded" ) ).toBool() )
2412 newGroup->
setCustomProperty( QStringLiteral(
"embedded_project" ), projectFilePath );
2415 mLayerTreeRegistryBridge->
setEnabled(
false );
2416 initializeEmbeddedSubtree( projectFilePath, newGroup );
2417 mLayerTreeRegistryBridge->
setEnabled(
true );
2420 const auto constFindLayerIds = newGroup->
findLayerIds();
2421 for (
const QString &layerId : constFindLayerIds )
2434 void QgsProject::initializeEmbeddedSubtree(
const QString &projectFilePath,
QgsLayerTreeGroup *group )
2436 const auto constChildren = group->
children();
2440 child->setCustomProperty( QStringLiteral(
"embedded" ), 1 );
2449 QList<QDomNode> brokenNodes;
2457 return mEvaluateDefaultValues;
2462 if ( evaluateDefaultValues == mEvaluateDefaultValues )
2466 QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
2467 for ( ; layerIt != layers.constEnd(); ++layerIt )
2481 writeEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/TopologicalEditing" ), ( enabled ? 1 : 0 ) );
2487 return readNumEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/TopologicalEditing" ), 0 );
2492 QString distanceUnitString =
readEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/DistanceUnits" ), QString() );
2493 if ( !distanceUnitString.isEmpty() )
2510 QString areaUnitString =
readEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/AreaUnits" ), QString() );
2511 if ( !areaUnitString.isEmpty() )
2528 if ( !mHomePath.isEmpty() )
2530 QFileInfo homeInfo( mHomePath );
2531 if ( !homeInfo.isRelative() )
2536 if ( !pfi.exists() )
2539 if ( !mHomePath.isEmpty() )
2542 return QDir::cleanPath( pfi.path() +
'/' + mHomePath );
2546 return pfi.canonicalPath();
2557 return mRelationManager;
2562 return mLayoutManager.get();
2567 return mLayoutManager.get();
2577 return mMapThemeCollection.get();
2582 return mAnnotationManager.get();
2587 return mAnnotationManager.get();
2592 const QMap<QString, QgsMapLayer *> &projectLayers =
mapLayers();
2593 for ( QMap<QString, QgsMapLayer *>::const_iterator it = projectLayers.constBegin(); it != projectLayers.constEnd(); ++it )
2598 if ( layers.contains( it.value() ) )
2599 it.value()->setFlags( it.value()->flags() & ~
QgsMapLayer::Identifiable );
2612 nonIdentifiableLayers.reserve( layerIds.count() );
2613 for (
const QString &layerId : layerIds )
2617 nonIdentifiableLayers << layer;
2629 for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
2633 nonIdentifiableLayers.append( it.value()->id() );
2641 return mAutoTransaction;
2646 if ( autoTransaction != mAutoTransaction )
2650 if ( autoTransaction )
2651 onMapLayersAdded(
mapLayers().values() );
2653 cleanTransactionGroups(
true );
2659 return mTransactionGroups;
2670 return mLayerStore->count();
2675 return mLayerStore->validCount();
2680 return mLayerStore->mapLayer( layerId );
2685 return mLayerStore->mapLayersByName( layerName );
2688 bool QgsProject::unzip(
const QString &filename )
2694 if ( !archive->unzip( filename ) )
2696 setError( tr(
"Unable to unzip file '%1'" ).arg( filename ) );
2701 if ( archive->projectFile().isEmpty() )
2703 setError( tr(
"Zip archive does not provide a project file" ) );
2708 if ( !archive->auxiliaryStorageFile().isEmpty() )
2712 mAuxiliaryStorage.reset(
new QgsAuxiliaryStorage( archive->auxiliaryStorageFile(), false ) );
2720 if ( ! readProjectFile( archive->projectFile() ) )
2722 setError( tr(
"Cannot read unzipped qgs project file" ) );
2727 mArchive = std::move( archive );
2728 mArchive->clearProjectFile();
2733 bool QgsProject::zip(
const QString &filename )
2739 const QString
baseName = QFileInfo( filename ).baseName();
2740 const QString qgsFileName = QStringLiteral(
"%1.qgs" ).arg( baseName );
2741 QFile qgsFile( QDir( archive->dir() ).filePath( qgsFileName ) );
2743 bool writeOk =
false;
2744 if ( qgsFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
2746 writeOk = writeProjectFile( qgsFile.fileName() );
2753 setError( tr(
"Unable to write temporary qgs file" ) );
2758 const QFileInfo info( qgsFile );
2761 if ( ! saveAuxiliaryStorage( asFileName ) )
2763 const QString err = mAuxiliaryStorage->errorString();
2764 setError( tr(
"Unable to save auxiliary storage ('%1')" ).arg( err ) );
2769 archive->addFile( qgsFile.fileName() );
2770 archive->addFile( asFileName );
2773 if ( !archive->zip( filename ) )
2775 setError( tr(
"Unable to perform zip" ) );
2788 const QList<QgsMapLayer *> &
layers,
2790 bool takeOwnership )
2792 const QList<QgsMapLayer *> myResultList { mLayerStore->addMapLayers( layers, takeOwnership ) };
2793 if ( !myResultList.isEmpty() )
2796 for (
auto &l : myResultList )
2806 if ( mAuxiliaryStorage )
2821 return myResultList;
2827 bool takeOwnership )
2829 QList<QgsMapLayer *> addedLayers;
2830 addedLayers =
addMapLayers( QList<QgsMapLayer *>() << layer, addToLegend, takeOwnership );
2831 return addedLayers.isEmpty() ? nullptr : addedLayers[0];
2836 mLayerStore->removeMapLayers( layerIds );
2841 mLayerStore->removeMapLayers( layers );
2846 mLayerStore->removeMapLayer( layerId );
2851 mLayerStore->removeMapLayer( layer );
2856 return mLayerStore->takeMapLayer( layer );
2861 mLayerStore->removeAllMapLayers();
2866 QMap<QString, QgsMapLayer *>
layers = mLayerStore->mapLayers();
2867 QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin();
2868 for ( ; it != layers.constEnd(); ++it )
2870 it.value()->reload();
2876 return validOnly ? mLayerStore->validMapLayers() : mLayerStore->mapLayers();
2881 return mTransactionGroups.value( qMakePair( providerKey, connString ) );
2888 if ( settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"prompt" ) ).toString() == QStringLiteral(
"useProject" )
2889 || settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"prompt" ) ).toString() == QStringLiteral(
"prompt" ) )
2898 QString layerDefaultCrs = settings.
value( QStringLiteral(
"/Projections/layerDefaultCrs" ),
GEO_EPSG_CRS_AUTHID ).toString();
2907 mTrustLayerMetadata = trust;
2910 for (
auto it =
layers.constBegin(); it !=
layers.constEnd(); ++it )
2920 bool QgsProject::saveAuxiliaryStorage(
const QString &filename )
2924 for (
auto it = layers.constBegin(); it != layers.constEnd(); ++it )
2937 if ( !mAuxiliaryStorage->exists( *
this ) && filename.isEmpty() && empty )
2941 else if ( !filename.isEmpty() )
2943 return mAuxiliaryStorage->saveAs( filename );
2947 return mAuxiliaryStorage->saveAs( *
this );
2953 return mAuxiliaryStorage.get();
2958 return mAuxiliaryStorage.get();
2968 if ( metadata == mMetadata )
2982 for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
2986 requiredLayers.insert( it.value() );
2994 const QMap<QString, QgsMapLayer *> &projectLayers =
mapLayers();
2995 for ( QMap<QString, QgsMapLayer *>::const_iterator it = projectLayers.constBegin(); it != projectLayers.constEnd(); ++it )
3000 if ( layers.contains( it.value() ) )
3001 it.value()->setFlags( it.value()->flags() & ~
QgsMapLayer::Removable );
3010 QStringList customColors;
3011 QStringList customColorLabels;
3013 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
3014 for ( ; colorIt != colors.constEnd(); ++colorIt )
3017 QString label = ( *colorIt ).second;
3018 customColors.append( color );
3019 customColorLabels.append( label );
3021 writeEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Colors" ), customColors );
3022 writeEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Labels" ), customColorLabels );
3037 QString
QgsProject::translate(
const QString &context,
const QString &sourceText,
const char *disambiguation,
int n )
const 3044 QString result = mTranslator->translate( context.toUtf8(), sourceText.toUtf8(), disambiguation, n );
3046 if ( result.isEmpty() )
Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const
Gets the list of layers which currently should not be taken into account on map identification.
Layer tree group node serves as a container for layers and further groups.
void setDirty(bool b=true)
Flag the project as dirty (modified).
void setTrustLayerMetadata(bool trust)
Sets the trust option allowing to indicate if the extent has to be read from the XML document when da...
The class is used as a container of context for various read/write operations on other objects...
void readChildrenFromXml(QDomElement &element, const QgsReadWriteContext &context)
Read children from XML and append them to the group.
QString error() const
Returns error message from previous read/write.
bool isDirty() const
Returns true if the project has been modified since the last write()
static Q_INVOKABLE AreaUnit decodeAreaUnit(const QString &string, bool *ok=nullptr)
Decodes an areal unit from a string.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
QList< QgsMapLayer * > addMapLayers(const QList< QgsMapLayer *> &mapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
Base class for all map layer types.
void layersAdded(const QList< QgsMapLayer *> &layers)
Emitted when one or more layers were added to the registry.
QDateTime lastModified() const
Returns last modified time of the project file as returned by the file system (or other project stora...
static QgsCoordinateReferenceSystem fromProj4(const QString &proj4)
Creates a CRS from a proj4 style formatted string.
static const QString QGIS_VERSION
Version string.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
QgsRelationManager * relationManager() const
const QgsAuxiliaryStorage * auxiliaryStorage() const
Returns the current const auxiliary storage.
This is an abstract base class for any elements of a drag and drop form.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
QgsMapLayerType type() const
Returns the type of the layer.
void setAvoidIntersectionsLayers(const QList< QgsVectorLayer *> &layers)
A list of layers with which intersections should be avoided.
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
QgsTransactionGroup * transactionGroup(const QString &providerKey, const QString &connString)
Returns the matching transaction group from a provider key and connection string. ...
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the store.
bool save()
Commits changes and starts editing then.
Manages storage of a set of QgsAnnotation annotation objects.
void dump_(const QgsProjectPropertyKey &topQgsPropertyKey)
void setTopologicalEditing(bool enabled)
Convenience function to set topological editing.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
const QgsProjectMetadata & metadata() const
Returns a reference to the project's metadata store.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
This class is a composition of two QSettings instances:
void requestForTranslatableObjects(QgsTranslationContext *translationContext)
Emitted when project strings which require translation are being collected for inclusion in a ...
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
void setSnappingConfig(const QgsSnappingConfig &snappingConfig)
The snapping configuration for this project.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
void writeProject(QDomDocument &doc)
Writes the configuration to the specified QGIS project document.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
static void warning(const QString &msg)
Goes to qWarning.
Class used to work with layer dependencies stored in a XML project or layer definition file...
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
QString providerType() const
Returns the provider type (provider key) for this layer.
QgsProjectPropertyKey * addKey(const QString &keyName)
Adds the specified property key as a sub-key.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
#define Q_NOWARN_DEPRECATED_PUSH
static bool readOldLegend(QgsLayerTreeGroup *root, const QDomElement &legendElem)
Try to load layer tree from.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
void setFileName(const QString &name)
Sets the file name associated with the project.
Class providing some utility methods to manage auxiliary storage.
void crsChanged()
Emitted when the CRS of the project has changed.
void layersAdded(const QList< QgsMapLayer *> &layers)
Emitted when one or more layers were added to the store.
void generateTsFile(const QString &locale)
Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile() ...
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the store.
void entryList(QStringList &entries) const
Returns any sub-keys contained by this property that do not contain other keys.
void configChanged()
Emitted whenever the configuration is changed.
Container of fields for a vector layer.
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context)
Sets state from DOM document.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
static QgsPluginLayerRegistry * pluginLayerRegistry()
Returns the application's plugin layer registry, used for managing plugin layer types.
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
int count() const
Returns the number of registered layers.
void metadataChanged()
Emitted when the project's metadata is changed.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
void updateRelationsStatus()
Updates relations status.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
void reloadAllLayers()
Reload all registered layer's provider data caches, synchronising the layer with any changes in the d...
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Calls resolveReferences() on child tree nodes.
void legendLayersAdded(const QList< QgsMapLayer *> &layers)
Emitted, when a layer was added to the registry and the legend.
bool isValid() const
Returns the status of the layer.
void removeKey(const QString &keyName)
Removes the specified key.
void projectSaved()
Emitted when the project file has been written and closed.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the store.
void reset()
reset to default values
void allLayersRemoved()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
QgsMapLayerStore * layerStore()
Returns a pointer to the project's internal layer store.
QgsCoordinateTransformContext transformContext() const
Returns a copy of the project's coordinate transform context, which stores various information regard...
QList< QgsMapLayer * > customLayerOrder() const
The order in which layers will be rendered on the canvas.
void clear()
Remove any relation managed by this class.
QgsProject(QObject *parent=nullptr)
Create a new QgsProject.
static QString extension()
Returns the extension used for auxiliary databases.
static QString userFullName()
Returns the user's operating system login account full display name.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QgsProjectVersion getVersion(const QDomDocument &doc)
Returns the version string found in the given DOM document.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
void fileNameChanged()
Emitted when the file name of the project changes.
void readProject(const QDomDocument &doc)
Reads the configuration from the specified QGIS project document.
static QString encodeColor(const QColor &color)
Class allowing to manage the zip/unzip actions on project file.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context, QStringList &missingTransforms)
Reads the context's state from a DOM element.
QgsProjectProperty * find(const QString &propertyName) const
Attempts to find a property with a matching sub-key name.
Q_DECL_DEPRECATED void setNonIdentifiableLayers(const QList< QgsMapLayer *> &layers)
Set a list of layers which should not be taken into account on map identification.
virtual bool isKey() const =0
Returns true if the property is a QgsProjectPropertyKey.
QString presetHomePath() const
Returns any manual project home path setting, or an empty string if not set.
bool writeEntry(const QString &scope, const QString &key, bool value)
Write a boolean entry to the project file.
QgsProjectPropertyValue * setValue(const QString &name, const QVariant &value)
Sets the value associated with this key.
void readSettings()
Reads the context's state from application settings.
void missingDatumTransforms(const QStringList &missingTransforms)
Emitted when datum transforms stored in the project are not available locally.
bool read()
Reads the project from its currently associated file (see fileName() ).
void readProjectWithContext(const QDomDocument &, QgsReadWriteContext &context)
Emitted when a project is being read.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
bool evaluateDefaultValues() const
Should default values be evaluated on provider side when requested and not when committed.
QgsMapLayer * takeMapLayer(QgsMapLayer *layer)
Takes a layer from the registry.
Q_DECL_DEPRECATED void setRequiredLayers(const QSet< QgsMapLayer *> &layers)
Configures a set of map layers that are required in the project and therefore they should not get rem...
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QString name() const
The name of the property is used as identifier.
Namespace with helper functions for layer tree operations.
QVariant value() const override
If this key has a value, it will be stored by its name in its properties.
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
#define QgsDebugMsgLevel(str, level)
QgsUnitTypes::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
void setAreaUnits(QgsUnitTypes::AreaUnit unit)
Sets the default area measurement units for the project.
void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
A class to describe the version of a project.
QString layerIsEmbedded(const QString &id) const
Returns project file path if layer is embedded from other project file. Returns empty string if layer...
int count() const
Returns the number of sub-keys contained by this property.
virtual void clearKeys()
Deletes any sub-nodes from the property.
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the store.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsCoordinateReferenceSystem defaultCrsForNewLayers() const
Returns the default CRS for new layers based on the settings and the current project CRS...
void setBadLayerHandler(QgsProjectBadLayerHandler *handler)
Change handler for missing layers.
void dumpProperties() const
Dump out current project properties to stderr.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QMap< QString, QgsRelation > relations() const
Gets access to the relations managed by this class.
void readProject(const QDomDocument &)
Emitted when a project is being read.
QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const override
Translates the project with QTranslator and qm file.
Listens to the updates in map layer registry and does changes in layer tree.
bool addLayer(QgsVectorLayer *layer)
Add a layer to this transaction group.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file...
QStringList subkeyList(const QString &scope, const QString &key) const
Returns keys with keys – do not return keys that contain only values.
void clear()
Clear any information from this layer tree.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the project's native coordinate reference system.
QList< QgsLayerTreeGroup * > findGroups() const
Find all group layer nodes.
static void replaceChildrenOfEmbeddedGroups(QgsLayerTreeGroup *group)
Remove subtree of embedded groups and replaces it with a custom property embedded-visible-layers.
void layerLoaded(int i, int n)
Emitted when a layer from a projects was read.
void dump(int tabs=0) const override
Dumps out the keys and values.
QStringList readListEntry(const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const
Key value accessors.
void setDistanceUnits(QgsUnitTypes::DistanceUnit unit)
Sets the default distance measurement units for the project.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
bool removeEntry(const QString &scope, const QString &key)
Remove the given key.
Reads and writes project states.
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
void setEllipsoid(const QString &ellipsoid)
Sets the project's ellipsoid from a proj string representation, e.g., "WGS84".
void setProjectColors(const QgsNamedColorList &colors)
Sets the colors for the project's color scheme (see QgsProjectColorScheme).
void insertChildNodes(int index, const QList< QgsLayerTreeNode *> &nodes)
Insert existing nodes at specified position.
static bool supportsTransaction(const QgsVectorLayer *layer)
Checks if the provider of a given layer supports transactions.
QList< QgsReadWriteContext::ReadWriteMessage > takeMessages()
Returns the stored messages and remove them.
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted when a layer is being saved.
Encapsulate a field in an attribute table or data source.
void removeAllMapLayers()
Removes all registered layers.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file...
virtual bool isValue() const =0
Returns true if the property is a QgsProjectPropertyValue.
Contains information about the context in which a coordinate transform is executed.
void removeKey_(const QString &scope, const QString &key, QgsProjectPropertyKey &rootProperty)
Remove a given key.
QgsEditFormConfig editFormConfig
void setCustomVariables(const QVariantMap &customVariables)
A map of custom project variables.
Manages storage of a set of layouts.
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the store.
QList< QgsMapLayer * > mapLayersByName(const QString &layerName) const
Retrieve a list of matching registered layers by layer name.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
static QgsProjectStorageRegistry * projectStorageRegistry()
Returns registry of available project storage implementations.
void setProviderProperty(ProviderProperty property, const QVariant &value)
Allows setting arbitrary properties on the provider.
QgsProjectStorage * projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file...
bool write()
Writes the project to its current associated file (see fileName() ).
Used for the collecting of strings from projects for translation and creation of ts files...
QgsAnnotationManager * annotationManager()
Returns pointer to the project's annotation manager.
void readLayerOrderFromXml(const QDomElement &doc)
Load the layer order from an XML element.
const QgsLayoutManager * layoutManager() const
Returns the project's layout manager, which manages compositions within the project.
QStringList makeKeyTokens_(const QString &scope, const QString &key)
Take the given scope and key and convert them to a string list of key tokens that will be used to nav...
bool loadAuxiliaryLayer(const QgsAuxiliaryStorage &storage, const QString &key=QString())
Loads the auxiliary layer for this vector layer.
bool removeLayers(const QList< QgsMapLayer *> &layers)
Removes the specified layers from the individual layer configuration.
QgsLayerTreeGroup * createEmbeddedGroup(const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers)
Create layer group instance defined in an arbitrary project file.
void registerTranslatableObjects(QgsTranslationContext *translationContext)
Registers the objects that require translation into the translationContext.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QString absolutePath() const
Returns full absolute path to the project folder if the project is stored in a file system - derived ...
void setMetadata(const QgsProjectMetadata &metadata)
Sets the project's metadata store.
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
bool topologicalEditing() const
Convenience function to query topological editing status.
bool readLayer(const QDomNode &layerNode)
Reads the layer described in the associated DOM node.
QString homePath() const
Returns the project's home path.
bool isEmpty() const
Returns true if this property contains no sub-keys.
QgsMapThemeCollection * mapThemeCollection()
Returns pointer to the project's map theme collection.
QString fileName() const
Returns the project's file name.
Project property key node.
DistanceUnit
Units of distance.
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes the context's state to a DOM element.
void transactionGroupsChanged()
Emitted whenever a new transaction group has been created or a transaction group has been removed...
void setPresetHomePath(const QString &path)
Sets the project's home path.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the registry.
void writeTsFile(const QString &locale)
Writes the Ts-file.
#define Q_NOWARN_DEPRECATED_POP
void setFileName(const QString &fileName)
Sets the fileName of the TS file.
void registerTranslation(const QString &context, const QString &source)
Registers the source to be translated.
void writeProject(QDomDocument &)
Emitted when the project is being written.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
bool isZipped() const
Returns true if the project comes from a zip archive, false otherwise.
void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
Q_DECL_DEPRECATED QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Resolves reference to layer from stored layer ID (if it has not been resolved already) ...
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
bool autoTransaction() const
Transactional editing means that on supported datasources (postgres databases) the edit state of all ...
void setAutoTransaction(bool autoTransaction)
Transactional editing means that on supported datasources (postgres databases) the edit state of all ...
QString source() const
Returns the source for the layer.
QMap< QPair< QString, QString >, QgsTransactionGroup * > transactionGroups()
Map of transaction groups.
void setProject(QgsProject *project)
Sets the project being translated.
void registerTranslatableContainers(QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId)
Registers the containers that require translation into the translationContext.
virtual void handleBadLayers(const QList< QDomNode > &layers)
This method will be called whenever the project tries to load layers which cannot be accessed...
This class manages a set of relations between layers.
QgsLayerTreeGroup * findGroup(const QString &name)
Find group node with specified name.
QgsSnappingConfig snappingConfig() const
The snapping configuration for this project.
bool createEmbeddedLayer(const QString &layerId, const QString &projectFilePath, QList< QDomNode > &brokenNodes, bool saveFlag=true)
Creates a maplayer instance defined in an arbitrary project file.
Stores global configuration for labeling engine.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void removeMapLayer(const QString &layerId)
Remove a layer from the registry by layer ID.
CORE_EXPORT bool isZipFile(const QString &filename)
Returns true if the file name is a zipped file ( i.e with a '.qgz' extension, false otherwise...
This class represents a coordinate reference system (CRS).
static void storeOriginalLayersProperties(QgsLayerTreeGroup *group, const QDomDocument *doc)
Stores in a layer's originalXmlProperties the layer properties information.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the project's coordinate transform context, which stores various information regarding which dat...
void setTitle(const QString &title)
Sets the project's title.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
QgsCoordinateReferenceSystem crs() const
Returns the project's native coordinate reference system.
bool isEmpty() const
Checks whether the container is empty.
void setEnabled(bool enabled)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
If the layer can be removed from the project. The layer will not be removable from the legend menu en...
void loadingLayerMessageReceived(const QString &layerName, const QList< QgsReadWriteContext::ReadWriteMessage > &messages)
Emitted when loading layers has produced some messages.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
An Abstract Base Class for QGIS project property hierarchys.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
QgsMapLayer * addMapLayer(QgsMapLayer *mapLayer, bool addToLegend=true, bool takeOwnership=true)
Add a layer to the map of loaded layers.
void homePathChanged()
Emitted when the home path of the project changes.
void removeMapLayers(const QStringList &layerIds)
Remove a set of layers from the registry by layer ID.
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
void subkeyList(QStringList &entries) const
Returns any sub-keys contained by this property which themselves contain other keys.
bool readXml(const QDomNode &keyNode) override
Restores the property hierarchy from a specified DOM node.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
QString name() const override
Returns the group's name.
void avoidIntersectionsLayersChanged()
Emitted whenever avoidIntersectionsLayers has changed.
QStringList findLayerIds() const
Find layer IDs used in all layer nodes.
Container class that allows storage of map themes consisting of visible map layers and layer styles...
void transformContextChanged()
Emitted when the project transformContext() is changed.
QString title() const
Returns the project's title.
This is a container for configuration of the snapping of the project.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QgsUnitTypes::DistanceUnit distanceUnits() const
Convenience function to query default distance measurement units for project.
QgsFields auxiliaryFields() const
Returns a list of all auxiliary fields currently managed by the layer.
QVariantMap customVariables() const
A map of custom project variables.
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
QString ellipsoid() const
Returns a proj string representing the project's ellipsoid setting, e.g., "WGS84".
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
Resolves relative paths into absolute paths and vice versa.
bool addLayers(const QList< QgsMapLayer *> &layers)
Adds the specified layers as individual layers to the configuration with standard configuration...
void collectTranslatableObjects(QgsTranslationContext *translationContext)
Emits the signal to collect all the strings of .qgs to be included in ts file.
Class for storing the component parts of a RDBMS data source URI (e.g.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
QgsProjectProperty * findKey_(const QString &scope, const QString &key, QgsProjectPropertyKey &rootProperty)
return the property that matches the given key sequence, if any
void setEvaluateDefaultValues(bool evaluateDefaultValues)
Defines if default values should be evaluated on provider side when requested and not when committed...
Represents a vector layer which manages a vector based data sets.
QgsMapLayer * mapLayer(const QString &id) const
Retrieve a pointer to a layer by layer id.
QString name() const
Returns the name of this element.
QList< QgsVectorLayer * > avoidIntersectionsLayers() const
A list of layers with which intersections should be avoided.
QgsProjectStorage * projectStorageFromUri(const QString &uri)
Returns storage implementation if the URI matches one. Returns nullptr otherwise (it is a normal file...
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
QgsLayerTree * clone() const override
Create a copy of the node. Returns new instance.
void setName(const QString &name)
The name of the property is used as identifier.
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
QgsProjectProperty * addKey_(const QString &scope, const QString &key, QgsProjectPropertyKey *rootProperty, const QVariant &value, bool &propertiesModified)
Add the given key and value.
If the layer is identifiable using the identify map tool and as a WMS layer.
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
QStringList entryList(const QString &scope, const QString &key) const
Returns keys with values – do not return keys that contain other keys.
void removeAll()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
void _getProperties(const QDomDocument &doc, QgsProjectPropertyKey &project_properties)
Restore any optional properties found in "doc" to "properties".
bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document) override
Writes the property hierarchy to a specified DOM element.
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets project's global labeling engine settings.
void clear()
Clears the project, removing all settings and resetting it back to an empty, default state...
Q_DECL_DEPRECATED QSet< QgsMapLayer * > requiredLayers() const
Returns a set of map layers that are required in the project and therefore they should not get remove...
static void updateEmbeddedGroupsProjectPath(QgsLayerTreeGroup *group, const QgsProject *project)
Updates an embedded group from a project.
Interface for classes that handle missing layer files when reading project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Q_DECL_DEPRECATED void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the registry.
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file...
Layer tree node points to a map layer.
void setReadExtentFromXml(bool readExtentFromXml)
Flag allowing to indicate if the extent has to be read from the XML document when data source has no ...
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
int validCount() const
Returns the number of registered valid layers.