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" ) );
393 [ = ](
const QList<QgsMapLayer *> &
layers )
395 for (
const auto &layer : layers )
400 [ = ](
const QList<QgsMapLayer *> &layers )
402 for (
const auto &layer : layers )
411 mIsBeingDeleted =
true;
414 delete mBadLayerHandler;
415 delete mRelationManager;
416 delete mLayerTreeRegistryBridge;
418 if (
this == sProject )
424 void QgsProject::setInstance(
QgsProject *project )
441 if ( title == mMetadata.
title() )
452 return mMetadata.
title();
462 if ( dirty && mDirtyBlockCount > 0 )
465 if ( mDirty == dirty )
474 if ( path == mHomePath )
485 const QList<QgsAttributeEditorElement *> elements = parent->
children();
493 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:formcontainers" ).arg( layerId ), container->
name() );
495 if ( !container->
children().empty() )
508 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1" ).arg( layer->layerId() ), layer->name() );
517 for (
const QgsField &field : fields )
520 if ( field.alias().isEmpty() )
521 fieldName = field.name();
523 fieldName = field.alias();
525 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:fieldaliases" ).arg( vlayer->
id() ), fieldName );
527 if ( field.editorWidgetSetup().type() == QStringLiteral(
"ValueRelation" ) )
529 translationContext->
registerTranslation( QStringLiteral(
"project:layers:%1:fields:%2:valuerelationvalue" ).arg( vlayer->
id(), field.name() ), field.editorWidgetSetup().config().value( QStringLiteral(
"Value" ) ).toString() );
540 const QList<QgsLayerTreeGroup *> groupLayers = mRootGroup->
findGroups();
543 translationContext->
registerTranslation( QStringLiteral(
"project:layergroups" ), groupLayer->name() );
547 const QList<QgsRelation> &relations = mRelationManager->
relations().values();
550 translationContext->
registerTranslation( QStringLiteral(
"project:relations" ), relation.name() );
556 if ( name == mFile.fileName() )
561 mFile.setFileName( name );
565 if ( newHomePath != oldHomePath )
573 return mFile.fileName();
578 return QFileInfo( mFile );
591 storage->readProjectStorageMetadata( mFile.fileName(),
metadata );
605 if ( mFile.fileName().isEmpty() )
616 if ( mFile.fileName().isEmpty() )
627 storage->readProjectStorageMetadata( mFile.fileName(),
metadata );
628 return metadata.
name;
632 return QFileInfo( mFile.fileName() ).completeBaseName();
647 writeEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectionsEnabled" ), crs.
isValid() ? 1 : 0 );
654 if ( !
crs().isValid() )
657 return readEntry( QStringLiteral(
"Measure" ), QStringLiteral(
"/Ellipsoid" ),
GEO_NONE );
662 writeEntry( QStringLiteral(
"Measure" ), QStringLiteral(
"/Ellipsoid" ), ellipsoid );
668 return mTransformContext;
673 if ( context == mTransformContext )
676 mTransformContext = context;
684 mFile.setFileName( QString() );
687 mAutoTransaction =
false;
688 mEvaluateDefaultValues =
false;
690 mTrustLayerMetadata =
false;
691 mCustomVariables.clear();
704 mEmbeddedLayers.clear();
705 mRelationManager->
clear();
706 mAnnotationManager->clear();
707 mLayoutManager->clear();
708 mSnappingConfig.
reset();
715 mLabelingEngineSettings->clear();
722 if ( !mIsBeingDeleted )
730 writeEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/Automatic" ),
true );
731 writeEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DecimalPlaces" ), 2 );
732 writeEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
false );
735 writeEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/DistanceUnits" ), s.
value( QStringLiteral(
"/qgis/measure/displayunits" ) ).toString() );
736 writeEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/AreaUnits" ), s.
value( QStringLiteral(
"/qgis/measure/areaunits" ) ).toString() );
748 QgsDebugMsg( QStringLiteral(
"current properties:" ) );
749 topQgsPropertyKey.
dump();
785 QDomElement propertiesElem = doc.documentElement().firstChildElement( QStringLiteral(
"properties" ) );
787 if ( propertiesElem.isNull() )
792 QDomNodeList scopes = propertiesElem.childNodes();
794 if ( scopes.count() < 1 )
796 QgsDebugMsg( QStringLiteral(
"empty ``properties'' XML tag ... bailing" ) );
800 if ( ! project_properties.
readXml( propertiesElem ) )
802 QgsDebugMsg( QStringLiteral(
"Project_properties.readXml() failed" ) );
811 static void _getTitle(
const QDomDocument &doc, QString &
title )
813 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"title" ) );
819 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
823 QDomNode titleNode = nl.item( 0 );
825 if ( !titleNode.hasChildNodes() )
827 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
831 QDomNode titleTextNode = titleNode.firstChild();
833 if ( !titleTextNode.isText() )
835 QgsDebugMsg( QStringLiteral(
"unable to find title element" ) );
839 QDomText titleText = titleTextNode.toText();
841 title = titleText.data();
847 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"qgis" ) );
851 QgsDebugMsg( QStringLiteral(
" unable to find qgis element in project file" ) );
855 QDomNode qgisNode = nl.item( 0 );
857 QDomElement qgisElement = qgisNode.toElement();
858 QgsProjectVersion projectVersion( qgisElement.attribute( QStringLiteral(
"version" ) ) );
859 return projectVersion;
865 return mSnappingConfig;
870 if ( mSnappingConfig == snappingConfig )
878 bool QgsProject::_getMapLayers(
const QDomDocument &doc, QList<QDomNode> &brokenNodes )
883 QDomNodeList nl = doc.elementsByTagName( QStringLiteral(
"maplayer" ) );
887 if ( 0 == nl.count() )
897 bool returnStatus =
true;
903 if ( depSorter.hasCycle() || depSorter.hasMissingDependency() )
906 const QVector<QDomNode> sortedLayerNodes = depSorter.sortedLayerNodes();
909 for (
const QDomNode &node : sortedLayerNodes )
911 const QDomElement element = node.toElement();
913 const QString name =
translate( QStringLiteral(
"project:layers:%1" ).arg( node.namedItem( QStringLiteral(
"id" ) ).toElement().text() ), node.namedItem( QStringLiteral(
"layername" ) ).toElement().text() );
914 if ( !name.isNull() )
915 emit
loadingLayer( tr(
"Loading layer %1" ).arg( name ) );
917 if ( element.attribute( QStringLiteral(
"embedded" ) ) == QLatin1String(
"1" ) )
919 createEmbeddedLayer( element.attribute( QStringLiteral(
"id" ) ),
readPath( element.attribute( QStringLiteral(
"project" ) ) ), brokenNodes );
926 if ( !addLayer( element, brokenNodes, context ) )
928 returnStatus =
false;
931 if ( messages.count() )
943 bool QgsProject::addLayer(
const QDomElement &layerElem, QList<QDomNode> &brokenNodes,
QgsReadWriteContext &context )
945 QString type = layerElem.attribute( QStringLiteral(
"type" ) );
949 if ( type == QLatin1String(
"vector" ) )
954 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mapLayer ) )
959 else if ( type == QLatin1String(
"raster" ) )
963 else if ( type == QLatin1String(
"mesh" ) )
967 else if ( type == QLatin1String(
"plugin" ) )
969 QString
typeName = layerElem.attribute( QStringLiteral(
"name" ) );
975 QgsDebugMsg( QStringLiteral(
"Unable to create layer" ) );
979 Q_CHECK_PTR( mapLayer );
983 QList<QgsMapLayer *> newLayers;
995 QgsDebugMsg(
"Unable to load " + type +
" layer" );
996 brokenNodes.push_back( layerElem );
1003 mFile.setFileName( filename );
1010 QString filename = mFile.fileName();
1015 QTemporaryFile inDevice;
1016 if ( !inDevice.open() )
1018 setError( tr(
"Unable to open %1" ).arg( inDevice.fileName() ) );
1024 if ( !storage->readProject( filename, &inDevice, context ) )
1026 QString err = tr(
"Unable to open %1" ).arg( filename );
1027 QList<QgsReadWriteContext::ReadWriteMessage> messages = context.
takeMessages();
1028 if ( !messages.isEmpty() )
1029 err += QStringLiteral(
"\n\n" ) + messages.last().message();
1034 return unzip( inDevice.fileName() );
1039 rc = unzip( mFile.fileName() );
1044 rc = readProjectFile( mFile.fileName() );
1050 mFile.setFileName( filename );
1055 mTranslator.reset(
nullptr );
1061 bool QgsProject::readProjectFile(
const QString &filename )
1063 QFile projectFile( filename );
1068 QString localeFileName = QStringLiteral(
"%1_%2" ).arg( QFileInfo( projectFile.fileName() ).
baseName(), settings.
value( QStringLiteral(
"locale/userLocale" ), QString() ).toString() );
1070 if ( QFile( QStringLiteral(
"%1/%2.qm" ).arg( QFileInfo( projectFile.fileName() ).
absolutePath(), localeFileName ) ).exists() )
1072 mTranslator.reset(
new QTranslator() );
1073 mTranslator->load( localeFileName, QFileInfo( projectFile.fileName() ).
absolutePath() );
1076 std::unique_ptr<QDomDocument> doc(
new QDomDocument( QStringLiteral(
"qgis" ) ) );
1078 if ( !projectFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
1080 projectFile.close();
1082 setError( tr(
"Unable to open %1" ).arg( projectFile.fileName() ) );
1091 if ( !doc->setContent( &projectFile, &errorMsg, &line, &column ) )
1095 QMessageBox::critical( 0, tr(
"Read Project File" ),
1096 tr(
"%1 at line %2 column %3" ).arg( errorMsg ).arg( line ).arg( column ) );
1099 QString errorString = tr(
"Project file read error in file %1: %2 at line %3 column %4" )
1100 .arg( projectFile.fileName(), errorMsg ).arg( line ).arg( column );
1104 projectFile.close();
1106 setError( tr(
"%1 for file %2" ).arg( errorString, projectFile.fileName() ) );
1111 projectFile.close();
1113 QgsDebugMsg(
"Opened document " + projectFile.fileName() );
1119 if ( thisVersion > fileVersion )
1122 "version of qgis (saved in " + fileVersion.text() +
1124 "). Problems may occur." );
1130 QgsDebugMsg( QStringLiteral(
"Emitting oldProjectVersionWarning(oldVersion)." ) );
1132 projectFile.updateRevision( thisVersion );
1136 QString
fileName = mFile.fileName();
1137 std::unique_ptr<QgsAuxiliaryStorage> aStorage = std::move( mAuxiliaryStorage );
1139 mAuxiliaryStorage = std::move( aStorage );
1140 mFile.setFileName( fileName );
1145 QgsDebugMsg( QString::number( mProperties.
count() ) +
" properties read" );
1147 dump_( mProperties );
1151 _getTitle( *doc, oldTitle );
1153 QDomNodeList homePathNl = doc->elementsByTagName( QStringLiteral(
"homePath" ) );
1154 if ( homePathNl.count() > 0 )
1156 QDomElement homePathElement = homePathNl.at( 0 ).toElement();
1157 QString
homePath = homePathElement.attribute( QStringLiteral(
"path" ) );
1158 if ( !homePath.isEmpty() )
1172 if (
readNumEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectionsEnabled" ), 0 ) )
1175 QDomNode srsNode = doc->documentElement().namedItem( QStringLiteral(
"projectCrs" ) );
1176 if ( !srsNode.isNull() )
1178 projectCrs.
readXml( srsNode );
1183 QString projCrsString =
readEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectCRSProj4String" ) );
1184 long currentCRS =
readNumEntry( QStringLiteral(
"SpatialRefSys" ), QStringLiteral(
"/ProjectCRSID" ), -1 );
1187 if ( currentCRS >= 0 )
1193 if ( !projCrsString.isEmpty() && ( !projectCrs.
isValid() || projectCrs.
toProj4() != projCrsString ) )
1207 QStringList datumErrors;
1208 if ( !mTransformContext.
readXml( doc->documentElement(), context, datumErrors ) )
1214 QDomNodeList nl = doc->elementsByTagName( QStringLiteral(
"projectMetadata" ) );
1215 if ( !nl.isEmpty() )
1217 QDomElement metadataElement = nl.at( 0 ).toElement();
1225 if ( mMetadata.
title().isEmpty() && !oldTitle.isEmpty() )
1232 nl = doc->elementsByTagName( QStringLiteral(
"autotransaction" ) );
1235 QDomElement transactionElement = nl.at( 0 ).toElement();
1236 if ( transactionElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1237 mAutoTransaction =
true;
1240 nl = doc->elementsByTagName( QStringLiteral(
"evaluateDefaultValues" ) );
1243 QDomElement evaluateDefaultValuesElement = nl.at( 0 ).toElement();
1244 if ( evaluateDefaultValuesElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1245 mEvaluateDefaultValues =
true;
1248 nl = doc->elementsByTagName( QStringLiteral(
"trust" ) );
1251 QDomElement trustElement = nl.at( 0 ).toElement();
1252 if ( trustElement.attribute( QStringLiteral(
"active" ), QStringLiteral(
"0" ) ).toInt() == 1 )
1253 mTrustLayerMetadata =
true;
1260 QDomElement layerTreeElem = doc->documentElement().firstChildElement( QStringLiteral(
"layer-tree-group" ) );
1261 if ( !layerTreeElem.isNull() )
1270 mLayerTreeRegistryBridge->
setEnabled(
false );
1273 QList<QDomNode> brokenNodes;
1274 bool clean = _getMapLayers( *doc, brokenNodes );
1279 QgsDebugMsg( QStringLiteral(
"Unable to get map layers from project file." ) );
1281 if ( !brokenNodes.isEmpty() )
1283 QgsDebugMsg(
"there are " + QString::number( brokenNodes.size() ) +
" broken layers" );
1293 QMap<QString, QgsMapLayer *>
layers = mLayerStore->mapLayers();
1294 for ( QMap<QString, QgsMapLayer *>::iterator it = layers.begin(); it != layers.end(); it++ )
1296 it.value()->resolveReferences(
this );
1299 mLayerTreeRegistryBridge->
setEnabled(
true );
1302 loadEmbeddedNodes( mRootGroup );
1308 if ( !layerTreeElem.isNull() )
1314 QDomElement layerTreeCanvasElem = doc->documentElement().firstChildElement( QStringLiteral(
"layer-tree-canvas" ) );
1315 if ( !layerTreeCanvasElem.isNull( ) )
1323 const QStringList requiredLayerIds =
readListEntry( QStringLiteral(
"RequiredLayers" ), QStringLiteral(
"Layers" ) );
1324 for (
const QString &layerId : requiredLayerIds )
1328 layer->setFlags( layer->flags() & ~
QgsMapLayer::Removable );
1331 const QStringList disabledLayerIds =
readListEntry( QStringLiteral(
"Identify" ), QStringLiteral(
"/disabledLayers" ) );
1332 for (
const QString &layerId : disabledLayerIds )
1336 layer->setFlags( layer->flags() & ~
QgsMapLayer::Identifiable );
1350 mMapThemeCollection->readXml( *doc );
1352 mLabelingEngineSettings->readSettingsFromProject(
this );
1355 mAnnotationManager->readXml( doc->documentElement(), context );
1356 mLayoutManager->readXml( doc->documentElement(), *doc );
1359 QMap<QString, QgsMapLayer *> existingMaps =
mapLayers();
1360 for ( QMap<QString, QgsMapLayer *>::iterator it = existingMaps.begin(); it != existingMaps.end(); it++ )
1362 it.value()->setDependencies( it.value()->dependencies() );
1367 QStringList variableNames =
readListEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableNames" ) );
1368 QStringList variableValues =
readListEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableValues" ) );
1370 mCustomVariables.clear();
1371 if ( variableNames.length() == variableValues.length() )
1373 for (
int i = 0; i < variableNames.length(); ++i )
1375 mCustomVariables.insert( variableNames.at( i ), variableValues.at( i ) );
1380 QgsMessageLog::logMessage( tr(
"Project Variables Invalid" ), tr(
"The project contains invalid variable settings." ) );
1404 QString newFileName( QStringLiteral(
"%1/%2.qgs" ).arg( QFileInfo( projectFile.fileName() ).
absolutePath(), localeFileName ) );
1429 if ( childGroup->
customProperty( QStringLiteral(
"embedded" ) ).toInt() )
1432 QString projectPath =
readPath( childGroup->
customProperty( QStringLiteral(
"embedded_project" ) ).toString() );
1433 childGroup->
setCustomProperty( QStringLiteral(
"embedded_project" ), projectPath );
1437 QList<QgsLayerTreeNode *> clonedChildren;
1439 clonedChildren << newGroupChild->
clone();
1447 loadEmbeddedNodes( childGroup );
1452 if ( child->
customProperty( QStringLiteral(
"embedded" ) ).toInt() )
1454 QList<QDomNode> brokenNodes;
1464 return mCustomVariables;
1469 if ( variables == mCustomVariables )
1473 QStringList variableNames;
1474 QStringList variableValues;
1476 QVariantMap::const_iterator it = variables.constBegin();
1477 for ( ; it != variables.constEnd(); ++it )
1479 variableNames << it.key();
1480 variableValues << it.value().toString();
1483 writeEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableNames" ), variableNames );
1484 writeEntry( QStringLiteral(
"Variables" ), QStringLiteral(
"/variableValues" ), variableValues );
1486 mCustomVariables = variables;
1493 *mLabelingEngineSettings = settings;
1499 return *mLabelingEngineSettings;
1504 return mLayerStore.get();
1509 return mLayerStore.get();
1514 QList<QgsVectorLayer *>
layers;
1515 QStringList layerIds =
readListEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/AvoidIntersectionsList" ), QStringList() );
1516 Q_FOREACH (
const QString &layerId, layerIds )
1528 list << layer->
id();
1529 writeEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/AvoidIntersectionsList" ), list );
1543 void QgsProject::onMapLayersAdded(
const QList<QgsMapLayer *> &
layers )
1545 QMap<QString, QgsMapLayer *> existingMaps =
mapLayers();
1547 bool tgChanged =
false;
1568 mTransactionGroups.insert( qMakePair( key, connString ), tg );
1583 for ( QMap<QString, QgsMapLayer *>::iterator it = existingMaps.begin(); it != existingMaps.end(); it++ )
1585 QSet<QgsMapLayerDependency> deps = it.value()->dependencies();
1586 if ( deps.contains( layer->
id() ) )
1589 it.value()->setDependencies( deps );
1595 if ( mSnappingConfig.
addLayers( layers ) )
1599 void QgsProject::onMapLayersRemoved(
const QList<QgsMapLayer *> &
layers )
1605 void QgsProject::cleanTransactionGroups(
bool force )
1607 bool changed =
false;
1608 for ( QMap< QPair< QString, QString>,
QgsTransactionGroup *>::Iterator tg = mTransactionGroups.begin(); tg != mTransactionGroups.end(); )
1610 if ( tg.value()->isEmpty() || force )
1613 tg = mTransactionGroups.erase( tg );
1630 QList<QDomNode> brokenNodes;
1631 if ( addLayer( layerNode.toElement(), brokenNodes, context ) )
1635 QVector<QgsVectorLayer *> vectorLayers = layers<QgsVectorLayer *>();
1649 mFile.setFileName( filename );
1660 writeEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
true );
1662 QString tempPath = QStandardPaths::standardLocations( QStandardPaths::TempLocation ).at( 0 );
1663 QString tmpZipFilename( tempPath + QDir::separator() + QUuid::createUuid().toString() );
1665 if ( !zip( tmpZipFilename ) )
1668 QFile tmpZipFile( tmpZipFilename );
1669 if ( !tmpZipFile.open( QIODevice::ReadOnly ) )
1671 setError( tr(
"Unable to read file %1" ).arg( tmpZipFilename ) );
1676 if ( !storage->writeProject( mFile.fileName(), &tmpZipFile, context ) )
1678 QString err = tr(
"Unable to save project to storage %1" ).arg( mFile.fileName() );
1679 QList<QgsReadWriteContext::ReadWriteMessage> messages = context.
takeMessages();
1680 if ( !messages.isEmpty() )
1681 err += QStringLiteral(
"\n\n" ) + messages.last().message();
1687 QFile::remove( tmpZipFilename );
1694 return zip( mFile.fileName() );
1700 const bool asOk = saveAuxiliaryStorage();
1701 const bool writeOk = writeProjectFile( mFile.fileName() );
1704 if ( !asOk && writeOk )
1706 const QString err = mAuxiliaryStorage->errorString();
1707 setError( tr(
"Unable to save auxiliary storage ('%1')" ).arg( err ) );
1710 return asOk && writeOk;
1714 bool QgsProject::writeProjectFile(
const QString &filename )
1716 QFile projectFile( filename );
1722 QFileInfo myFileInfo( projectFile );
1723 if ( myFileInfo.exists() && !myFileInfo.isWritable() )
1725 setError( tr(
"%1 is not writable. Please adjust permissions (if possible) and try again." )
1726 .arg( projectFile.fileName() ) );
1733 QDomImplementation DomImplementation;
1734 DomImplementation.setInvalidDataPolicy( QDomImplementation::DropInvalidChars );
1736 QDomDocumentType documentType =
1737 DomImplementation.createDocumentType( QStringLiteral(
"qgis" ), QStringLiteral(
"http://mrcc.com/qgis.dtd" ),
1738 QStringLiteral(
"SYSTEM" ) );
1739 std::unique_ptr<QDomDocument> doc(
new QDomDocument( documentType ) );
1741 QDomElement qgisNode = doc->createElement( QStringLiteral(
"qgis" ) );
1742 qgisNode.setAttribute( QStringLiteral(
"projectname" ),
title() );
1743 qgisNode.setAttribute( QStringLiteral(
"version" ), QStringLiteral(
"%1" ).arg(
Qgis::QGIS_VERSION ) );
1745 doc->appendChild( qgisNode );
1747 QDomElement homePathNode = doc->createElement( QStringLiteral(
"homePath" ) );
1748 homePathNode.setAttribute( QStringLiteral(
"path" ), mHomePath );
1749 qgisNode.appendChild( homePathNode );
1752 QDomElement titleNode = doc->createElement( QStringLiteral(
"title" ) );
1753 qgisNode.appendChild( titleNode );
1755 QDomElement transactionNode = doc->createElement( QStringLiteral(
"autotransaction" ) );
1756 transactionNode.setAttribute( QStringLiteral(
"active" ), mAutoTransaction ? 1 : 0 );
1757 qgisNode.appendChild( transactionNode );
1759 QDomElement evaluateDefaultValuesNode = doc->createElement( QStringLiteral(
"evaluateDefaultValues" ) );
1760 evaluateDefaultValuesNode.setAttribute( QStringLiteral(
"active" ), mEvaluateDefaultValues ? 1 : 0 );
1761 qgisNode.appendChild( evaluateDefaultValuesNode );
1763 QDomElement trustNode = doc->createElement( QStringLiteral(
"trust" ) );
1764 trustNode.setAttribute( QStringLiteral(
"active" ), mTrustLayerMetadata ? 1 : 0 );
1765 qgisNode.appendChild( trustNode );
1767 QDomText titleText = doc->createTextNode(
title() );
1768 titleNode.appendChild( titleText );
1771 QDomElement srsNode = doc->createElement( QStringLiteral(
"projectCrs" ) );
1773 qgisNode.appendChild( srsNode );
1780 clonedRoot->
writeXml( qgisNode, context );
1793 QDomElement projectLayersNode = doc->createElement( QStringLiteral(
"projectlayers" ) );
1795 QMap<QString, QgsMapLayer *>::ConstIterator li = layers.constBegin();
1796 while ( li != layers.end() )
1802 QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.constFind( ml->
id() );
1803 if ( emIt == mEmbeddedLayers.constEnd() )
1805 QDomElement maplayerElem;
1810 maplayerElem = doc->createElement( QStringLiteral(
"maplayer" ) );
1815 QDomDocument document;
1818 maplayerElem = document.firstChildElement();
1822 QgsDebugMsg( QStringLiteral(
"Could not restore layer properties for layer %1" ).arg( ml->
id() ) );
1828 projectLayersNode.appendChild( maplayerElem );
1834 if ( emIt.value().second )
1836 QDomElement mapLayerElem = doc->createElement( QStringLiteral(
"maplayer" ) );
1837 mapLayerElem.setAttribute( QStringLiteral(
"embedded" ), 1 );
1838 mapLayerElem.setAttribute( QStringLiteral(
"project" ),
writePath( emIt.value().first ) );
1839 mapLayerElem.setAttribute( QStringLiteral(
"id" ), ml->
id() );
1840 projectLayersNode.appendChild( mapLayerElem );
1847 qgisNode.appendChild( projectLayersNode );
1849 QDomElement layerOrderNode = doc->createElement( QStringLiteral(
"layerorder" ) );
1852 QDomElement mapLayerElem = doc->createElement( QStringLiteral(
"layer" ) );
1853 mapLayerElem.setAttribute( QStringLiteral(
"id" ), layer->
id() );
1854 layerOrderNode.appendChild( mapLayerElem );
1856 qgisNode.appendChild( layerOrderNode );
1858 mLabelingEngineSettings->writeSettingsToProject(
this );
1862 dump_( mProperties );
1864 QgsDebugMsg( QStringLiteral(
"there are %1 property scopes" ).arg( static_cast<int>( mProperties.
count() ) ) );
1869 mProperties.
writeXml( QStringLiteral(
"properties" ), qgisNode, *doc );
1872 mMapThemeCollection->writeXml( *doc );
1874 mTransformContext.
writeXml( qgisNode, context );
1876 QDomElement metadataElem = doc->createElement( QStringLiteral(
"projectMetadata" ) );
1878 qgisNode.appendChild( metadataElem );
1880 QDomElement annotationsElem = mAnnotationManager->writeXml( *doc, context );
1881 qgisNode.appendChild( annotationsElem );
1883 QDomElement layoutElem = mLayoutManager->writeXml( *doc );
1884 qgisNode.appendChild( layoutElem );
1892 QFile backupFile( QStringLiteral(
"%1~" ).arg( filename ) );
1894 ok &= backupFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
1895 ok &= projectFile.open( QIODevice::ReadOnly );
1898 while ( ok && !projectFile.atEnd() )
1900 ba = projectFile.read( 10240 );
1901 ok &= backupFile.write( ba ) == ba.size();
1904 projectFile.close();
1909 setError( tr(
"Unable to create backup file %1" ).arg( backupFile.fileName() ) );
1914 struct utimbuf tb = {
static_cast<time_t
>( fi.lastRead().toSecsSinceEpoch() ), static_cast<time_t>( fi.lastModified().toSecsSinceEpoch() ) };
1915 utime( backupFile.fileName().toUtf8().constData(), &tb );
1918 if ( !projectFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
1920 projectFile.close();
1923 setError( tr(
"Unable to save to file %1" ).arg( projectFile.fileName() ) );
1927 QTemporaryFile tempFile;
1928 bool ok = tempFile.open();
1931 QTextStream projectFileStream( &tempFile );
1932 doc->save( projectFileStream, 2 );
1933 ok &= projectFileStream.pos() > -1;
1935 ok &= tempFile.seek( 0 );
1938 while ( ok && !tempFile.atEnd() )
1940 ba = tempFile.read( 10240 );
1941 ok &= projectFile.write( ba ) == ba.size();
1944 ok &= projectFile.error() == QFile::NoError;
1946 projectFile.close();
1953 setError( tr(
"Unable to save to file %1. Your project " 1954 "may be corrupted on disk. Try clearing some space on the volume and " 1955 "check file permissions before pressing save again." )
1956 .arg( projectFile.fileName() ) );
1969 bool propertiesModified;
1970 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
1972 if ( propertiesModified )
1980 bool propertiesModified;
1981 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
1983 if ( propertiesModified )
1991 bool propertiesModified;
1992 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
1994 if ( propertiesModified )
2002 bool propertiesModified;
2003 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2005 if ( propertiesModified )
2013 bool propertiesModified;
2014 bool success =
addKey_( scope, key, &mProperties, value, propertiesModified );
2016 if ( propertiesModified )
2024 const QStringList &def,
2033 value =
property->value();
2035 bool valid = QVariant::StringList == value.type();
2041 return value.toStringList();
2060 value =
property->value();
2062 bool valid = value.canConvert( QVariant::String );
2067 return value.toString();
2082 value =
property->value();
2085 bool valid = value.canConvert( QVariant::Int );
2094 return value.toInt();
2107 QVariant value =
property->value();
2109 bool valid = value.canConvert( QVariant::Double );
2114 return value.toDouble();
2127 QVariant value =
property->value();
2129 bool valid = value.canConvert( QVariant::Bool );
2134 return value.toBool();
2143 if (
findKey_( scope, key, mProperties ) )
2149 return !
findKey_( scope, key, mProperties );
2157 QStringList entries;
2159 if ( foundProperty )
2174 QStringList entries;
2176 if ( foundProperty )
2189 dump_( mProperties );
2194 bool absolutePaths =
readBoolEntry( QStringLiteral(
"Paths" ), QStringLiteral(
"/Absolute" ),
false );
2208 void QgsProject::setError(
const QString &errorMessage )
2210 mErrorMessage = errorMessage;
2215 return mErrorMessage;
2218 void QgsProject::clearError()
2220 setError( QString() );
2225 delete mBadLayerHandler;
2226 mBadLayerHandler = handler;
2231 QHash< QString, QPair< QString, bool > >::const_iterator it = mEmbeddedLayers.find(
id );
2232 if ( it == mEmbeddedLayers.constEnd() )
2236 return it.value().first;
2244 static QString sPrevProjectFilePath;
2245 static QDateTime sPrevProjectFileTimestamp;
2246 static QDomDocument sProjectDocument;
2248 QDateTime projectFileTimestamp = QFileInfo( projectFilePath ).lastModified();
2250 if ( projectFilePath != sPrevProjectFilePath || projectFileTimestamp != sPrevProjectFileTimestamp )
2252 sPrevProjectFilePath.clear();
2254 QFile projectFile( projectFilePath );
2255 if ( !projectFile.open( QIODevice::ReadOnly ) )
2260 if ( !sProjectDocument.setContent( &projectFile ) )
2265 sPrevProjectFilePath = projectFilePath;
2266 sPrevProjectFileTimestamp = projectFileTimestamp;
2270 bool useAbsolutePaths =
true;
2272 QDomElement propertiesElem = sProjectDocument.documentElement().firstChildElement( QStringLiteral(
"properties" ) );
2273 if ( !propertiesElem.isNull() )
2275 QDomElement absElem = propertiesElem.firstChildElement( QStringLiteral(
"Paths" ) ).firstChildElement( QStringLiteral(
"Absolute" ) );
2276 if ( !absElem.isNull() )
2278 useAbsolutePaths = absElem.text().compare( QLatin1String(
"true" ), Qt::CaseInsensitive ) == 0;
2283 if ( !useAbsolutePaths )
2287 QDomElement projectLayersElem = sProjectDocument.documentElement().firstChildElement( QStringLiteral(
"projectlayers" ) );
2288 if ( projectLayersElem.isNull() )
2293 QDomNodeList mapLayerNodes = projectLayersElem.elementsByTagName( QStringLiteral(
"maplayer" ) );
2294 for (
int i = 0; i < mapLayerNodes.size(); ++i )
2297 QDomElement mapLayerElem = mapLayerNodes.at( i ).toElement();
2298 QString
id = mapLayerElem.firstChildElement( QStringLiteral(
"id" ) ).text();
2299 if (
id == layerId )
2302 if ( mapLayerElem.attribute( QStringLiteral(
"embedded" ) ) == QLatin1String(
"1" ) )
2307 mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );
2309 if ( addLayer( mapLayerElem, brokenNodes, embeddedContext ) )
2315 mEmbeddedLayers.remove( layerId );
2328 QFile projectFile( projectFilePath );
2329 if ( !projectFile.open( QIODevice::ReadOnly ) )
2334 QDomDocument projectDocument;
2335 if ( !projectDocument.setContent( &projectFile ) )
2346 QDomElement layerTreeElem = projectDocument.documentElement().firstChildElement( QStringLiteral(
"layer-tree-group" ) );
2347 if ( !layerTreeElem.isNull() )
2357 if ( !group || group->customProperty( QStringLiteral(
"embedded" ) ).toBool() )
2370 newGroup->
setCustomProperty( QStringLiteral(
"embedded_project" ), projectFilePath );
2373 mLayerTreeRegistryBridge->
setEnabled(
false );
2374 initializeEmbeddedSubtree( projectFilePath, newGroup );
2375 mLayerTreeRegistryBridge->
setEnabled(
true );
2378 Q_FOREACH (
const QString &layerId, newGroup->
findLayerIds() )
2391 void QgsProject::initializeEmbeddedSubtree(
const QString &projectFilePath,
QgsLayerTreeGroup *group )
2405 QList<QDomNode> brokenNodes;
2413 return mEvaluateDefaultValues;
2418 if ( evaluateDefaultValues == mEvaluateDefaultValues )
2422 QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
2423 for ( ; layerIt != layers.constEnd(); ++layerIt )
2437 writeEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/TopologicalEditing" ), ( enabled ? 1 : 0 ) );
2443 return readNumEntry( QStringLiteral(
"Digitizing" ), QStringLiteral(
"/TopologicalEditing" ), 0 );
2448 QString distanceUnitString =
readEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/DistanceUnits" ), QString() );
2449 if ( !distanceUnitString.isEmpty() )
2466 QString areaUnitString =
readEntry( QStringLiteral(
"Measurement" ), QStringLiteral(
"/AreaUnits" ), QString() );
2467 if ( !areaUnitString.isEmpty() )
2484 if ( !mHomePath.isEmpty() )
2486 QFileInfo homeInfo( mHomePath );
2487 if ( !homeInfo.isRelative() )
2492 if ( !pfi.exists() )
2495 if ( !mHomePath.isEmpty() )
2498 return QDir::cleanPath( pfi.path() +
'/' + mHomePath );
2502 return pfi.canonicalPath();
2513 return mRelationManager;
2518 return mLayoutManager.get();
2523 return mLayoutManager.get();
2533 return mMapThemeCollection.get();
2538 return mAnnotationManager.get();
2543 return mAnnotationManager.get();
2548 const QMap<QString, QgsMapLayer *> &projectLayers =
mapLayers();
2549 for ( QMap<QString, QgsMapLayer *>::const_iterator it = projectLayers.constBegin(); it != projectLayers.constEnd(); ++it )
2554 if ( layers.contains( it.value() ) )
2555 it.value()->setFlags( it.value()->flags() & ~
QgsMapLayer::Identifiable );
2568 nonIdentifiableLayers.reserve( layerIds.count() );
2569 for (
const QString &layerId : layerIds )
2573 nonIdentifiableLayers << layer;
2585 for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
2589 nonIdentifiableLayers.append( it.value()->id() );
2597 return mAutoTransaction;
2602 if ( autoTransaction != mAutoTransaction )
2606 if ( autoTransaction )
2607 onMapLayersAdded(
mapLayers().values() );
2609 cleanTransactionGroups(
true );
2615 return mTransactionGroups;
2626 return mLayerStore->count();
2631 return mLayerStore->validCount();
2636 return mLayerStore->mapLayer( layerId );
2641 return mLayerStore->mapLayersByName( layerName );
2644 bool QgsProject::unzip(
const QString &filename )
2650 if ( !archive->unzip( filename ) )
2652 setError( tr(
"Unable to unzip file '%1'" ).arg( filename ) );
2657 if ( archive->projectFile().isEmpty() )
2659 setError( tr(
"Zip archive does not provide a project file" ) );
2664 if ( !archive->auxiliaryStorageFile().isEmpty() )
2668 mAuxiliaryStorage.reset(
new QgsAuxiliaryStorage( archive->auxiliaryStorageFile(), false ) );
2676 if ( ! readProjectFile( archive->projectFile() ) )
2678 setError( tr(
"Cannot read unzipped qgs project file" ) );
2683 mArchive = std::move( archive );
2684 mArchive->clearProjectFile();
2689 bool QgsProject::zip(
const QString &filename )
2695 const QString
baseName = QFileInfo( filename ).baseName();
2696 const QString qgsFileName = QStringLiteral(
"%1.qgs" ).arg( baseName );
2697 QFile qgsFile( QDir( archive->dir() ).filePath( qgsFileName ) );
2699 bool writeOk =
false;
2700 if ( qgsFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
2702 writeOk = writeProjectFile( qgsFile.fileName() );
2709 setError( tr(
"Unable to write temporary qgs file" ) );
2714 const QFileInfo info( qgsFile );
2717 if ( ! saveAuxiliaryStorage( asFileName ) )
2719 const QString err = mAuxiliaryStorage->errorString();
2720 setError( tr(
"Unable to save auxiliary storage ('%1')" ).arg( err ) );
2725 archive->addFile( qgsFile.fileName() );
2726 archive->addFile( asFileName );
2729 if ( !archive->zip( filename ) )
2731 setError( tr(
"Unable to perform zip" ) );
2744 const QList<QgsMapLayer *> &
layers,
2746 bool takeOwnership )
2748 const QList<QgsMapLayer *> myResultList = mLayerStore->addMapLayers( layers, takeOwnership );
2749 if ( !myResultList.isEmpty() )
2755 if ( mAuxiliaryStorage )
2770 return myResultList;
2776 bool takeOwnership )
2778 QList<QgsMapLayer *> addedLayers;
2779 addedLayers =
addMapLayers( QList<QgsMapLayer *>() << layer, addToLegend, takeOwnership );
2780 return addedLayers.isEmpty() ? nullptr : addedLayers[0];
2785 mLayerStore->removeMapLayers( layerIds );
2790 mLayerStore->removeMapLayers( layers );
2795 mLayerStore->removeMapLayer( layerId );
2800 mLayerStore->removeMapLayer( layer );
2805 return mLayerStore->takeMapLayer( layer );
2810 mLayerStore->removeAllMapLayers();
2815 QMap<QString, QgsMapLayer *>
layers = mLayerStore->mapLayers();
2816 QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin();
2817 for ( ; it != layers.constEnd(); ++it )
2819 it.value()->reload();
2825 return validOnly ? mLayerStore->validMapLayers() : mLayerStore->mapLayers();
2830 return mTransactionGroups.value( qMakePair( providerKey, connString ) );
2837 if ( settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"prompt" ) ).toString() == QStringLiteral(
"useProject" )
2838 || settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"prompt" ) ).toString() == QStringLiteral(
"prompt" ) )
2847 QString layerDefaultCrs = settings.
value( QStringLiteral(
"/Projections/layerDefaultCrs" ),
GEO_EPSG_CRS_AUTHID ).toString();
2856 mTrustLayerMetadata = trust;
2859 for (
auto it =
layers.constBegin(); it !=
layers.constEnd(); ++it )
2869 bool QgsProject::saveAuxiliaryStorage(
const QString &filename )
2873 for (
auto it = layers.constBegin(); it != layers.constEnd(); ++it )
2886 if ( !mAuxiliaryStorage->exists( *
this ) && filename.isEmpty() && empty )
2890 else if ( !filename.isEmpty() )
2892 return mAuxiliaryStorage->saveAs( filename );
2896 return mAuxiliaryStorage->saveAs( *
this );
2902 return mAuxiliaryStorage.get();
2907 return mAuxiliaryStorage.get();
2917 if ( metadata == mMetadata )
2931 for ( QMap<QString, QgsMapLayer *>::const_iterator it = layers.constBegin(); it != layers.constEnd(); ++it )
2935 requiredLayers.insert( it.value() );
2943 const QMap<QString, QgsMapLayer *> &projectLayers =
mapLayers();
2944 for ( QMap<QString, QgsMapLayer *>::const_iterator it = projectLayers.constBegin(); it != projectLayers.constEnd(); ++it )
2949 if ( layers.contains( it.value() ) )
2950 it.value()->setFlags( it.value()->flags() & ~
QgsMapLayer::Removable );
2959 QStringList customColors;
2960 QStringList customColorLabels;
2962 QgsNamedColorList::const_iterator colorIt = colors.constBegin();
2963 for ( ; colorIt != colors.constEnd(); ++colorIt )
2966 QString label = ( *colorIt ).second;
2967 customColors.append( color );
2968 customColorLabels.append( label );
2970 writeEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Colors" ), customColors );
2971 writeEntry( QStringLiteral(
"Palette" ), QStringLiteral(
"/Labels" ), customColorLabels );
2986 QString
QgsProject::translate(
const QString &context,
const QString &sourceText,
const char *disambiguation,
int n )
const 2993 QString result = mTranslator->translate( context.toUtf8(), sourceText.toUtf8(), disambiguation, n );
2995 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.
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.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
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.
void resolveReferences(QgsProject *project) FINAL
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects...
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.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
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.
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
Represents a mesh layer supporting display of data on structured or unstructured meshes.
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 null.
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 PostgreSQL/RDBMS datasource URI.
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.
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 null pointer otherwise (it is a normal...
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.
QgsPluginLayer * createLayer(const QString &typeName, const QString &uri=QString())
Returns new layer if corresponding plugin has been found else returns a nullptr.
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.