QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgsproject.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsproject.h
3
4 Implements persistent project state.
5
6 -------------------
7 begin : July 23, 2004
8 copyright : (C) 2004 by Mark Coletti
9 email : mcoletti at gmail.com
10 ***************************************************************************/
11
12/***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21#ifndef QGSPROJECT_H
22#define QGSPROJECT_H
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgis.h"
27
28#include <memory>
29#include <QHash>
30#include <QList>
31#include <QObject>
32#include <QPair>
33#include <QFileInfo>
34#include <QStringList>
35#include <QTranslator>
36
37#include "qgssnappingconfig.h"
38#include "qgsprojectversion.h"
43#include "qgsprojectproperty.h"
44#include "qgsmaplayerstore.h"
45#include "qgsarchive.h"
46#include "qgsreadwritecontext.h"
47#include "qgsprojectmetadata.h"
51#include "qgscolorscheme.h"
52#include "qgssettings.h"
56#include "qgsabstractsensor.h"
57
58#include "qgsrelationmanager.h"
60
61class QFileInfo;
62class QDomDocument;
63class QDomElement;
64class QDomNode;
65
68class QgsMapLayer;
69class QgsPathResolver;
72class QgsTolerance;
74class QgsVectorLayer;
77class QgsLayerTree;
80class QgsMapLayer;
92
107{
108 Q_OBJECT
109 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
110 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
111 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
112 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
113 Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
114 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
115 Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
116 Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
117 Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
118 Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
119 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
120 Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
121 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
122 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
123 Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
124 Q_PROPERTY( Qgis::DistanceUnit distanceUnits READ distanceUnits WRITE setDistanceUnits NOTIFY distanceUnitsChanged )
125 Q_PROPERTY( Qgis::AreaUnit areaUnits READ areaUnits WRITE setAreaUnits NOTIFY areaUnitsChanged )
126 Q_PROPERTY( QgsProjectDisplaySettings *displaySettings READ displaySettings CONSTANT )
127 Q_PROPERTY( Qgis::TransactionMode transactionMode READ transactionMode WRITE setTransactionMode NOTIFY transactionModeChanged )
128 Q_PROPERTY( Qgis::ScaleCalculationMethod scaleMethod READ scaleMethod WRITE setScaleMethod NOTIFY scaleMethodChanged )
129
130 public:
131
132 // *INDENT-OFF*
133
143 {
144 NoProperty = 0,
145 AllProperties = 1,
146 WMSOnlineResource = 2,
147 };
148 // *INDENT-ON*
149
151 static QgsProject *instance();
152
161 static void setInstance( QgsProject *project ) ;
162
171 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
172
173 ~QgsProject() override;
174
183 void setTitle( const QString &title );
184
191 QString title() const;
192
199 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
200
209 Qgis::ProjectFlags flags() const { return mFlags; }
210
219 void setFlags( Qgis::ProjectFlags flags );
220
229 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
230
238 QString saveUser() const;
239
247 QString saveUserFullName() const;
248
254 QDateTime lastSaveDateTime() const;
255
261 QgsProjectVersion lastSaveVersion() const;
262
266 bool isDirty() const;
267
274 void setFileName( const QString &name );
275
282 QString fileName() const;
283
295 void setOriginalPath( const QString &path );
296
308 QString originalPath() const;
309
320 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
321
328 QgsProjectStorage *projectStorage() const;
329
334 QDateTime lastModified() const;
335
341 QString absoluteFilePath() const;
342
348 QString absolutePath() const;
349
354 QString baseName() const;
355
362 Qgis::FilePathType filePathStorage() const;
363
370 void setFilePathStorage( Qgis::FilePathType type );
371
385
404 QgsCoordinateReferenceSystem crs3D() const;
405
420 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
421
429 QString ellipsoid() const;
430
438 void setEllipsoid( const QString &ellipsoid );
439
458 QgsCoordinateReferenceSystem verticalCrs() const;
459
479 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
480
489 QgsCoordinateTransformContext transformContext() const;
490
499 void setTransformContext( const QgsCoordinateTransformContext &context );
500
505 void clear();
506
513 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
514
523 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
524
534 bool readLayer( const QDomNode &layerNode );
535
543 bool write( const QString &filename );
544
550 bool write();
551
563 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
564
576 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
577
588 bool writeEntry( const QString &scope, const QString &key, int value );
589
600 bool writeEntry( const QString &scope, const QString &key, const QString &value );
601
612 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
613
624 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
625
636 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
637
648 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
649
660 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
661
672 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
673
677 bool removeEntry( const QString &scope, const QString &key );
678
687 QStringList entryList( const QString &scope, const QString &key ) const;
688
697 QStringList subkeyList( const QString &scope, const QString &key ) const;
698
699 // TODO Now slightly broken since re-factoring. Won't print out top-level key
700 // and redundantly prints sub-keys.
701
705 void dumpProperties() const;
706
711 QgsPathResolver pathResolver() const;
712
718 QString writePath( const QString &filename ) const;
719
723 QString readPath( const QString &filename ) const;
724
726 QString error() const;
727
732 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
733
739 QString layerIsEmbedded( const QString &id ) const;
740
749 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
750 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
751
758 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
759
761 void setTopologicalEditing( bool enabled );
762
764 bool topologicalEditing() const;
765
771 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
772
778 void setDistanceUnits( Qgis::DistanceUnit unit );
779
784 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
785
791 void setAreaUnits( Qgis::AreaUnit unit );
792
800 Qgis::ScaleCalculationMethod scaleMethod() const { return mScaleMethod; }
801
809 void setScaleMethod( Qgis::ScaleCalculationMethod method );
810
823 QString homePath() const;
824
837 QString presetHomePath() const;
838
839 QgsRelationManager *relationManager() const;
840
846 const QgsLayoutManager *layoutManager() const SIP_SKIP;
847
852 QgsLayoutManager *layoutManager();
853
860 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
861
867 QgsMapViewsManager *viewsManager();
868
875 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
876
882 QgsBookmarkManager *bookmarkManager();
883
890 const QgsSensorManager *sensorManager() const SIP_SKIP;
891
897 QgsSensorManager *sensorManager();
898
906 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
907
914 QgsProjectViewSettings *viewSettings();
915
923 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
924
931 QgsProjectStyleSettings *styleSettings();
932
940 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
941
948 QgsProjectTimeSettings *timeSettings();
949
956 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
957
963 QgsProjectElevationProperties *elevationProperties();
964
971 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
972
978 QgsProjectDisplaySettings *displaySettings();
979
986 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
987
993 QgsProjectGpsSettings *gpsSettings();
994
998 QgsLayerTree *layerTreeRoot() const;
999
1003 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
1004
1010
1014 QgsAnnotationManager *annotationManager();
1015
1019 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
1020
1025 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
1026
1031 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
1032
1037 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
1038
1046 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
1047
1057 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
1058
1065 Qgis::TransactionMode transactionMode() const;
1066
1076 bool setTransactionMode( Qgis::TransactionMode transactionMode );
1077
1085 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
1086
1094 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1095
1101 QgsVectorLayerEditBufferGroup *editBufferGroup();
1102
1108 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1109
1115 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1116
1117 QgsExpressionContext createExpressionContext() const override;
1118 QgsExpressionContextScope *createExpressionContextScope() const override;
1119
1124 QgsSnappingConfig snappingConfig() const;
1125
1130 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1131
1138 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1139
1145 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1146
1152 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1153
1159 QVariantMap customVariables() const;
1160
1165 void setCustomVariables( const QVariantMap &customVariables );
1166
1170 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1171
1175 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1176
1177 //
1178 // Functionality from QgsMapLayerRegistry
1179 //
1180
1184 QgsMapLayerStore *layerStore();
1185
1189 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1190
1192 int count() const;
1193
1195 int validCount() const;
1196
1204 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1205
1206#ifndef SIP_RUN
1207
1223 template <class T>
1224 T mapLayer( const QString &layerId ) const
1225 {
1226 return qobject_cast<T>( mapLayer( layerId ) );
1227 }
1228#endif
1229
1237 Q_INVOKABLE QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1238
1248 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1249
1250
1259 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1260
1264 bool isZipped() const;
1265
1266#ifndef SIP_RUN
1267
1278 template <typename T>
1279 QVector<T> layers() const
1280 {
1281 return mLayerStore->layers<T>();
1282 }
1283
1295 template <typename T>
1296 QVector<T> mapLayersByShortName( const QString &shortName ) const
1297 {
1298 QVector<T> layers;
1299 const auto constMapLayers { mLayerStore->layers<T>() };
1300 for ( const auto l : constMapLayers )
1301 {
1302 if ( ! l->serverProperties()->shortName().isEmpty() )
1303 {
1304 if ( l->serverProperties()->shortName() == shortName )
1305 layers << l;
1306 }
1307 else if ( l->name() == shortName )
1308 {
1309 layers << l;
1310 }
1311 }
1312 return layers;
1313 }
1314
1315#endif
1316
1341 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1342 bool addToLegend = true,
1343 bool takeOwnership SIP_PYARGREMOVE = true );
1344
1372 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1373 bool addToLegend = true,
1374 bool takeOwnership SIP_PYARGREMOVE = true );
1375
1389 void removeMapLayers( const QStringList &layerIds );
1390
1391 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1392
1406 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1407
1421 void removeMapLayer( const QString &layerId );
1422
1436 void removeMapLayer( QgsMapLayer *layer );
1437
1444 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1445
1457 QgsAnnotationLayer *mainAnnotationLayer();
1458
1469 void removeAllMapLayers();
1470
1476 void reloadAllLayers();
1477
1482 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1483
1495 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1496
1507 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1508
1513 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1514
1519 QgsAuxiliaryStorage *auxiliaryStorage();
1520
1529 QString createAttachedFile( const QString &nameTemplate );
1530
1537 QStringList attachedFiles() const;
1538
1546 bool removeAttachedFile( const QString &path );
1547
1556 QString attachmentIdentifier( const QString &attachedFile ) const;
1557
1564 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1565
1572 const QgsProjectMetadata &metadata() const;
1573
1580 void setMetadata( const QgsProjectMetadata &metadata );
1581
1590 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1591
1600 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1601
1608 void setProjectColors( const QgsNamedColorList &colors );
1609
1616 void setBackgroundColor( const QColor &color );
1617
1624 QColor backgroundColor() const;
1625
1632 void setSelectionColor( const QColor &color );
1633
1640 QColor selectionColor() const;
1641
1653 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1654
1666 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1667
1676 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1677
1686 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1687
1692 void generateTsFile( const QString &locale );
1693
1694 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1695
1705 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1706
1712 QgsElevationShadingRenderer elevationShadingRenderer() const;
1713
1719 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1720
1729 bool loadFunctionsFromProject( bool force = false ) SIP_SKIP;
1730
1738 void cleanFunctionsFromProject() SIP_SKIP;
1739
1740
1741#ifdef SIP_RUN
1742 SIP_PYOBJECT __repr__();
1743 % MethodCode
1744 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1745 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() ); // skip-keyword-check
1746 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1747 % End
1748#endif
1749
1750 signals:
1751
1759 void cleared();
1760
1768
1772 void readProject( const QDomDocument &document );
1773
1777 void readProjectWithContext( const QDomDocument &document, QgsReadWriteContext &context );
1778
1782 void writeProject( QDomDocument &document );
1783
1792 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1793
1802 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1803
1808
1814 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString &warning ) SIP_DEPRECATED;
1815
1826 void readVersionMismatchOccurred( const QString &fileVersion );
1827
1833 void layerLoaded( int i, int n );
1834
1836 void loadingLayer( const QString &layerName );
1837
1844 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1845
1850 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1851
1854
1862
1867
1874
1879
1889
1901
1918
1925 void ellipsoidChanged( const QString &ellipsoid );
1926
1934
1942
1951
1958
1962 void missingDatumTransforms( const QStringList &missingTransforms );
1963
1969
1976
1982
1988
2000
2005
2013
2021
2029
2037
2038 //
2039 // signals from QgsMapLayerRegistry
2040 //
2041
2049 void layersWillBeRemoved( const QStringList &layerIds );
2050
2058 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
2059
2069 void layerWillBeRemoved( const QString &layerId );
2070
2081
2088 void layersRemoved( const QStringList &layerIds );
2089
2098 void layerRemoved( const QString &layerId );
2099
2100 //TODO QGIS 4.0 - rename to past tense
2101
2109
2120 void layersAdded( const QList<QgsMapLayer *> &layers );
2121
2129
2138 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2139
2147 void isDirtyChanged( bool dirty );
2148
2156 void dirtySet();
2157
2166 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2167
2173 void elevationShadingRendererChanged();
2174
2175 public slots:
2176
2181 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2182
2183 // TODO QGIS 4.0 - rename b to dirty
2184
2191 void setDirty( bool b = true );
2192
2201 void setPresetHomePath( const QString &path );
2202
2212 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2213
2220 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2221
2228 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2229
2236 QgsPropertyCollection dataDefinedServerProperties() const;
2237
2254 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2255
2285 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2286
2303 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2304
2305 private slots:
2306 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2307 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2308 void cleanTransactionGroups( bool force = false );
2309 void updateTransactionGroups();
2310
2311 private:
2312
2313 static QgsProject *sProject;
2314
2315
2324 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2325
2330 void setError( const QString &errorMessage ) SIP_SKIP;
2331
2336 void clearError() SIP_SKIP;
2337
2347 bool addLayer( const QDomElement &layerElem,
2348 QList<QDomNode> &brokenNodes,
2349 QgsReadWriteContext &context,
2350 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2351 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2352
2356 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2357
2363 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2364
2369 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2370
2372 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2373
2375 bool writeProjectFile( const QString &filename );
2376
2378 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2379
2381 bool zip( const QString &filename );
2382
2384 bool saveAuxiliaryStorage( const QString &filename = QString() );
2385
2387 void loadProjectFlags( const QDomDocument *doc );
2388
2390 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2391
2393 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2394 const QgsReadWriteContext &context,
2395 QMap<QString, QgsDataProvider *> &loadedProviders,
2396 QgsMapLayer::ReadFlags layerReadFlags,
2397 int totalProviderCount );
2398
2403 void releaseHandlesToProjectArchive();
2404
2405 bool rebuildCrs3D( QString *error = nullptr );
2406
2407 Qgis::ProjectCapabilities mCapabilities;
2408
2409 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2410
2411 QString mErrorMessage;
2412
2413 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2414
2420 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2421
2422 QgsSnappingConfig mSnappingConfig;
2423 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2424
2425 QgsRelationManager *mRelationManager = nullptr;
2426
2427 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2428 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2429 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2430
2431 QgsBookmarkManager *mBookmarkManager = nullptr;
2432
2433 QgsSensorManager *mSensorManager = nullptr;
2434
2435 QgsProjectViewSettings *mViewSettings = nullptr;
2436
2437 QgsProjectStyleSettings *mStyleSettings = nullptr;
2438
2439 QgsProjectTimeSettings *mTimeSettings = nullptr;
2440
2441 QgsProjectElevationProperties *mElevationProperties = nullptr;
2442
2443 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2444
2445 QgsProjectGpsSettings *mGpsSettings = nullptr;
2446
2447 QgsLayerTree *mRootGroup = nullptr;
2448
2449 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2450
2451 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2452
2454 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2455
2456 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2457
2458 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2459
2460 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2461
2462 QVariantMap mCustomVariables;
2463
2464 std::unique_ptr<QgsArchive> mArchive;
2465
2466 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2467
2468 QFile mFile; // current physical project file
2469
2470 QString mOriginalPath;
2471
2472 QString mSaveUser; // last saved user.
2473 QString mSaveUserFull; // last saved user full name.
2474 QDateTime mSaveDateTime;
2475 QgsProjectVersion mSaveVersion;
2476
2481 QString mHomePath;
2482 mutable QString mCachedHomePath;
2483
2484 QColor mBackgroundColor;
2485 QColor mSelectionColor;
2486
2487 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2488 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2489 Qgis::ScaleCalculationMethod mScaleMethod = Qgis::ScaleCalculationMethod::HorizontalMiddle;
2490
2491 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2492 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2493
2494 Qgis::ProjectFlags mFlags;
2496 QgsCoordinateReferenceSystem mVerticalCrs;
2498
2499 bool mDirty = false; // project has been modified since it has been read or saved
2500 int mDirtyBlockCount = 0;
2501
2502 QgsPropertyCollection mDataDefinedServerProperties;
2503
2504 QgsCoordinateTransformContext mTransformContext;
2505
2506 QgsProjectMetadata mMetadata;
2507
2508 std::unique_ptr< QTranslator > mTranslator;
2509
2510 bool mIsBeingDeleted = false;
2511
2512 QgsSettings mSettings;
2513
2514 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2515
2516 bool mBlockChangeSignalsDuringClear = false;
2517 int mBlockSnappingUpdates = 0;
2518
2519 QgsElevationShadingRenderer mElevationShadingRenderer;
2520
2521 friend class QgsApplication;
2522
2524
2525 // Required to avoid creating a new project in it's destructor
2527
2528 // Required by QGIS Server for switching the current project instance
2529 friend class QgsServer;
2530
2531 friend class TestQgsProject;
2532
2533 Q_DISABLE_COPY( QgsProject )
2534};
2535
2557class CORE_EXPORT QgsProjectDirtyBlocker
2558{
2559 public:
2560
2567 : mProject( project )
2568 {
2569 mProject->mDirtyBlockCount++;
2570 }
2571
2574
2576 {
2577 mProject->mDirtyBlockCount--;
2578 }
2579
2580 private:
2581 QgsProject *mProject = nullptr;
2582
2583#ifdef SIP_RUN
2585#endif
2586};
2587
2593CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2594
2595
2596
2598#ifndef SIP_RUN
2599class GetNamedProjectColor : public QgsScopedExpressionFunction
2600{
2601 public:
2602 GetNamedProjectColor( const QgsProject *project );
2603
2608 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2609
2610 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2611 QgsScopedExpressionFunction *clone() const override;
2612
2613 private:
2614
2615 QHash< QString, QColor > mColors;
2616};
2617
2618class GetNamedProjectColorObject : public QgsScopedExpressionFunction
2619{
2620 public:
2621 GetNamedProjectColorObject( const QgsProject *project );
2622
2627 GetNamedProjectColorObject( const QHash< QString, QColor > &colors );
2628
2629 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2630 QgsScopedExpressionFunction *clone() const override;
2631
2632 private:
2633
2634 QHash< QString, QColor > mColors;
2635};
2636
2637
2638
2639class GetSensorData : public QgsScopedExpressionFunction
2640{
2641 public:
2642 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2643 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2644 QgsScopedExpressionFunction *clone() const override;
2645
2646 private:
2647
2648 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2649};
2650#endif
2652
2653#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
QFlags< ProjectCapability > ProjectCapabilities
Flags which control project capabilities.
Definition qgis.h:4194
DistanceUnit
Units of distance.
Definition qgis.h:4843
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4920
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3943
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5080
QFlags< ProjectFlag > ProjectFlags
Definition qgis.h:3950
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
Manages zip/unzip operations for an archive.
Definition qgsarchive.h:35
A container for attribute editors, used to group them visually in the attribute form if it is set to ...
Providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
Abstract interface for generating an expression context.
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An expression node for expression functions.
Handles parsing and evaluation of expressions (formerly called "search strings").
Stores global configuration for labeling engine.
Layer tree group node serves as a container for layers and further groups.
Listens to layer changes from a QgsProject and applies changes to a QgsLayerTree.
Namespace with helper functions for layer tree operations.
Manages storage of a set of layouts.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Base class for all map layer types.
Definition qgsmaplayer.h:77
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Manages storage of a set of views.
Resolves relative paths into absolute paths and vice versa.
Interface for classes that handle missing layer files when reading project files.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
QgsProjectDirtyBlocker(const QgsProjectDirtyBlocker &other)=delete
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Contains elevation properties for a QgsProject.
Contains settings and properties relating to how a QgsProject should interact with a GPS device.
A structured metadata store for a project.
Project property key node.
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
Contains settings and properties relating to how a QgsProject should handle styling.
Contains temporal settings and properties for the project, this may be used when animating maps or sh...
An interface for objects which can translate project strings.
Describes the version of a project.
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas,...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Q_DECL_DEPRECATED void oldProjectVersionWarning(const QString &warning)
Emitted when an old project file is read.
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
void readProjectWithContext(const QDomDocument &document, QgsReadWriteContext &context)
Emitted when a project is being read.
Qgis::ProjectFlags flags() const
Returns the project's flags, which dictate the behavior of the project.
Definition qgsproject.h:209
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
void readVersionMismatchOccurred(const QString &fileVersion)
Emitted when a project is read and the version of QGIS used to save the project differs from the curr...
void fileNameChanged()
Emitted when the file name of the project changes.
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted when a layer is being saved.
void areaUnitsChanged()
Emitted when the default area units changes.
Q_DECL_DEPRECATED void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the registry.
void crsChanged()
Emitted when the crs() of the project has changed.
Qgis::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
Definition qgsproject.h:784
void avoidIntersectionsLayersChanged()
Emitted whenever avoidIntersectionsLayers has changed.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the registry.
void distanceUnitsChanged()
Emitted when the default distance units changes.
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
DataDefinedServerProperty
Data defined properties.
Definition qgsproject.h:143
void aboutToBeCleared()
Emitted when the project is about to be cleared.
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
void metadataChanged()
Emitted when the project's metadata is changed.
void crs3DChanged()
Emitted when the crs3D() of the project has changed.
void scaleMethodChanged()
Emitted when the project's scale method is changed.
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
void transactionModeChanged()
Emitted when the transaction mode has changed.
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
QgsMapThemeCollection * mapThemeCollection()
Returns pointer to the project's map theme collection.
void missingDatumTransforms(const QStringList &missingTransforms)
Emitted when datum transforms stored in the project are not available locally.
void layerWillBeRemoved(QgsMapLayer *layer)
Emitted when a layer is about to be removed from the registry.
void transactionGroupsChanged()
Emitted whenever a new transaction group has been created or a transaction group has been removed.
void loadingLayerMessageReceived(const QString &layerName, const QList< QgsReadWriteContext::ReadWriteMessage > &messages)
Emitted when loading layers has produced some messages.
QVector< T > mapLayersByShortName(const QString &shortName) const
Retrieves a list of matching registered layers by layer shortName with a specified layer type,...
Qgis::ScaleCalculationMethod scaleMethod() const
Returns the method to use for map scale calculations for the project.
Definition qgsproject.h:800
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition qgsproject.h:199
void projectSaved()
Emitted when the project file has been written and closed.
void layersWillBeRemoved(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers are about to be removed from the registry.
void readProject(const QDomDocument &document)
Emitted when a project is being read.
void layerLoaded(int i, int n)
Emitted when a layer from a projects was read.
void selectionColorChanged()
Emitted whenever the project's selection color has been changed.
void removeAll()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
void transformContextChanged()
Emitted when the project transformContext() is changed.
void legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted, when a layer was added to the registry and the legend.
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
void homePathChanged()
Emitted when the home path of the project changes.
void dirtySet()
Emitted when setDirty(true) is called.
void writeProject(QDomDocument &document)
Emitted when the project is being written.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
void verticalCrsChanged()
Emitted when the verticalCrs() of the project has changed.
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
void avoidIntersectionsModeChanged()
Emitted whenever the avoid intersections mode has changed.
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A registry / canonical manager of data providers.
A container for the context for various read/write operations on objects.
Manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
Manages sensors.
A server which provides OGC web services.
Definition qgsserver.h:49
Stores settings for use within QGIS.
Definition qgssettings.h:66
Stores configuration of snapping settings for the project.
An interface for classes which can visit style entity (e.g.
Provides calculations for tolerance values in map units.
Represents a transaction group.
Used for the collecting of strings from projects for translation and creation of ts files.
The edit buffer group manages a group of edit buffers.
Represents a vector layer which manages a vector based dataset.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_PYNAME(name)
Definition qgis_sip.h:81
#define SIP_PYARGREMOVE
Definition qgis_sip.h:151
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_TRANSFERBACK
Definition qgis_sip.h:48
QgsProjectVersion getVersion(const QDomDocument &doc)
Returns the version string found in the given DOM document.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs