QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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 "qgsunittypes.h"
38#include "qgssnappingconfig.h"
39#include "qgsprojectversion.h"
44#include "qgsprojectproperty.h"
45#include "qgsmaplayerstore.h"
46#include "qgsarchive.h"
47#include "qgsreadwritecontext.h"
48#include "qgsprojectmetadata.h"
51#include "qgscolorscheme.h"
52#include "qgssettings.h"
55
56#include "qgsrelationmanager.h"
58
59class QFileInfo;
60class QDomDocument;
61class QDomElement;
62class QDomNode;
63
66class QgsMapLayer;
67class QgsPathResolver;
70class QgsTolerance;
72class QgsVectorLayer;
75class QgsLayerTree;
78class QgsMapLayer;
89
104{
105 Q_OBJECT
106 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
107 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
108 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
109 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
110 Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
111 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
112 Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
113 Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
114 Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
115 Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
116 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
117 Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
118 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
119 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
120 Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
121
122 public:
123
133 {
134 NoProperty = 0,
135 AllProperties = 1,
136 WMSOnlineResource = 2,
137 };
138
140 static QgsProject *instance();
141
150 static void setInstance( QgsProject *project ) ;
151
160 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
161
162 ~QgsProject() override;
163
173 void setTitle( const QString &title );
174
181 QString title() const;
182
189 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
190
199 Qgis::ProjectFlags flags() const { return mFlags; }
200
209 void setFlags( Qgis::ProjectFlags flags );
210
219 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
220
228 QString saveUser() const;
229
237 QString saveUserFullName() const;
238
244 QDateTime lastSaveDateTime() const;
245
251 QgsProjectVersion lastSaveVersion() const;
252
256 bool isDirty() const;
257
264 void setFileName( const QString &name );
265
272 QString fileName() const;
273
285 void setOriginalPath( const QString &path );
286
298 QString originalPath() const;
299
310 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
311
318 QgsProjectStorage *projectStorage() const;
319
324 QDateTime lastModified() const;
325
331 QString absoluteFilePath() const;
332
338 QString absolutePath() const;
339
344 QString baseName() const;
345
352 Qgis::FilePathType filePathStorage() const;
353
360 void setFilePathStorage( Qgis::FilePathType type );
361
369
379 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
380
387 QString ellipsoid() const;
388
395 void setEllipsoid( const QString &ellipsoid );
396
397
407 QgsCoordinateTransformContext transformContext() const;
408
418 void setTransformContext( const QgsCoordinateTransformContext &context );
419
425 void clear();
426
433 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
434
443 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
444
454 bool readLayer( const QDomNode &layerNode );
455
464 bool write( const QString &filename );
465
471 bool write();
472
484 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
485
497 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
498
509 bool writeEntry( const QString &scope, const QString &key, int value );
510
521 bool writeEntry( const QString &scope, const QString &key, const QString &value );
522
533 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
534
545 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
546
557 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
558
569 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
570
581 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
582
593 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
594
598 bool removeEntry( const QString &scope, const QString &key );
599
608 QStringList entryList( const QString &scope, const QString &key ) const;
609
618 QStringList subkeyList( const QString &scope, const QString &key ) const;
619
620 // TODO Now slightly broken since re-factoring. Won't print out top-level key
621 // and redundantly prints sub-keys.
622
626 void dumpProperties() const;
627
633 QgsPathResolver pathResolver() const;
634
640 QString writePath( const QString &filename ) const;
641
645 QString readPath( const QString &filename ) const;
646
648 QString error() const;
649
654 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
655
661 QString layerIsEmbedded( const QString &id ) const;
662
671 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
672 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
673
681 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
682
684 void setTopologicalEditing( bool enabled );
685
687 bool topologicalEditing() const;
688
695 QgsUnitTypes::DistanceUnit distanceUnits() const;
696
703 void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
704
710 QgsUnitTypes::AreaUnit areaUnits() const;
711
718 void setAreaUnits( QgsUnitTypes::AreaUnit unit );
719
732 QString homePath() const;
733
746 QString presetHomePath() const;
747
748 QgsRelationManager *relationManager() const;
749
756 const QgsLayoutManager *layoutManager() const SIP_SKIP;
757
763 QgsLayoutManager *layoutManager();
764
771 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
772
778 QgsMapViewsManager *viewsManager();
779
786 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
787
793 QgsBookmarkManager *bookmarkManager();
794
802 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
803
810 QgsProjectViewSettings *viewSettings();
811
819 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
820
827 QgsProjectStyleSettings *styleSettings();
828
836 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
837
844 QgsProjectTimeSettings *timeSettings();
845
852 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
853
859 QgsProjectElevationProperties *elevationProperties();
860
867 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
868
874 QgsProjectDisplaySettings *displaySettings();
875
880 QgsLayerTree *layerTreeRoot() const;
881
886 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
887
894
899 QgsAnnotationManager *annotationManager();
900
905 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
906
911 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
912
917 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
918
923 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
924
933 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
934
945 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
946
953 Qgis::TransactionMode transactionMode() const;
954
964 bool setTransactionMode( Qgis::TransactionMode transactionMode );
965
974 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
975
983 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
984
990 QgsVectorLayerEditBufferGroup *editBufferGroup();
991
997 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
998
1004 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1005
1006 QgsExpressionContext createExpressionContext() const override;
1007 QgsExpressionContextScope *createExpressionContextScope() const override;
1008
1014 QgsSnappingConfig snappingConfig() const;
1015
1021 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1022
1029 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1030
1036 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1037
1043 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1044
1050 QVariantMap customVariables() const;
1051
1056 void setCustomVariables( const QVariantMap &customVariables );
1057
1062 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1063
1068 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1069
1070 //
1071 // Functionality from QgsMapLayerRegistry
1072 //
1073
1078 QgsMapLayerStore *layerStore();
1079
1084 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1085
1087 int count() const;
1088
1090 int validCount() const;
1091
1099 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1100
1101#ifndef SIP_RUN
1102
1118 template <class T>
1119 T mapLayer( const QString &layerId ) const
1120 {
1121 return qobject_cast<T>( mapLayer( layerId ) );
1122 }
1123#endif
1124
1132 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1133
1143 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1144
1145
1154 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1155
1159 bool isZipped() const;
1160
1161#ifndef SIP_RUN
1162
1174 template <typename T>
1175 QVector<T> layers() const
1176 {
1177 return mLayerStore->layers<T>();
1178 }
1179
1191 template <typename T>
1192 QVector<T> mapLayersByShortName( const QString &shortName ) const
1193 {
1194 QVector<T> layers;
1195 const auto constMapLayers { mLayerStore->layers<T>() };
1196 for ( const auto l : constMapLayers )
1197 {
1198 if ( ! l->shortName().isEmpty() )
1199 {
1200 if ( l->shortName() == shortName )
1201 layers << l;
1202 }
1203 else if ( l->name() == shortName )
1204 {
1205 layers << l;
1206 }
1207 }
1208 return layers;
1209 }
1210
1211#endif
1212
1238 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1239 bool addToLegend = true,
1240 bool takeOwnership SIP_PYARGREMOVE = true );
1241
1269 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1270 bool addToLegend = true,
1271 bool takeOwnership SIP_PYARGREMOVE = true );
1272
1287 void removeMapLayers( const QStringList &layerIds );
1288
1289 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1290
1304 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1305
1319 void removeMapLayer( const QString &layerId );
1320
1334 void removeMapLayer( QgsMapLayer *layer );
1335
1343 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1344
1356 QgsAnnotationLayer *mainAnnotationLayer();
1357
1368 void removeAllMapLayers();
1369
1375 void reloadAllLayers();
1376
1381 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1382
1394 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1395
1406 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1407
1413 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1414
1420 QgsAuxiliaryStorage *auxiliaryStorage();
1421
1430 QString createAttachedFile( const QString &nameTemplate );
1431
1438 QStringList attachedFiles() const;
1439
1447 bool removeAttachedFile( const QString &path );
1448
1457 QString attachmentIdentifier( const QString &attachedFile ) const;
1458
1465 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1466
1473 const QgsProjectMetadata &metadata() const;
1474
1481 void setMetadata( const QgsProjectMetadata &metadata );
1482
1491 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1492
1501 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1502
1509 void setProjectColors( const QgsNamedColorList &colors );
1510
1517 void setBackgroundColor( const QColor &color );
1518
1525 QColor backgroundColor() const;
1526
1533 void setSelectionColor( const QColor &color );
1534
1541 QColor selectionColor() const;
1542
1554 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1555
1567 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1568
1577 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1578
1587 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1588
1593 void generateTsFile( const QString &locale );
1594
1605 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1606
1616 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1617
1618#ifdef SIP_RUN
1619 SIP_PYOBJECT __repr__();
1620 % MethodCode
1621 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1622 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1623 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1624 % End
1625#endif
1626
1627 signals:
1628
1636 void cleared();
1637
1641 void readProject( const QDomDocument & );
1642
1646 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1647
1651 void writeProject( QDomDocument & );
1652
1661 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1662
1671 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1672
1677
1683 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1684
1695 void readVersionMismatchOccurred( const QString &fileVersion );
1696
1702 void layerLoaded( int i, int n );
1703
1705 void loadingLayer( const QString &layerName );
1706
1713 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1714
1719 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1720
1723
1731
1736
1743
1749
1756
1764 void ellipsoidChanged( const QString &ellipsoid );
1765
1766
1774
1779 void missingDatumTransforms( const QStringList &missingTransforms );
1780
1788
1795
1802
1815
1821
1829
1837
1845
1853
1854 //
1855 // signals from QgsMapLayerRegistry
1856 //
1857
1865 void layersWillBeRemoved( const QStringList &layerIds );
1866
1874 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1875
1885 void layerWillBeRemoved( const QString &layerId );
1886
1897
1904 void layersRemoved( const QStringList &layerIds );
1905
1914 void layerRemoved( const QString &layerId );
1915
1916 //TODO QGIS 4.0 - rename to past tense
1917
1925
1936 void layersAdded( const QList<QgsMapLayer *> &layers );
1937
1945
1954 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1955
1963 void isDirtyChanged( bool dirty );
1964
1972 void dirtySet();
1973
1982 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1983
1984 public slots:
1985
1991 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1992
1993 // TODO QGIS 4.0 - rename b to dirty
1994
2002 void setDirty( bool b = true );
2003
2012 void setPresetHomePath( const QString &path );
2013
2023 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2024
2031 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2032
2039 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2040
2047 QgsPropertyCollection dataDefinedServerProperties() const;
2048
2065 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2066
2091 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2092
2101 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2102
2103 private slots:
2104 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2105 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2106 void cleanTransactionGroups( bool force = false );
2107 void updateTransactionGroups();
2108
2109 private:
2110
2111 static QgsProject *sProject;
2112
2113
2122 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2123
2128 void setError( const QString &errorMessage ) SIP_SKIP;
2129
2134 void clearError() SIP_SKIP;
2135
2143 bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2144
2150 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2151
2156 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2157
2159 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2160
2162 bool writeProjectFile( const QString &filename );
2163
2165 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2166
2168 bool zip( const QString &filename );
2169
2171 bool saveAuxiliaryStorage( const QString &filename = QString() );
2172
2174 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2175
2176 Qgis::ProjectCapabilities mCapabilities;
2177
2178 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2179
2180 QString mErrorMessage;
2181
2182 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2183
2189 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2190
2191 QgsSnappingConfig mSnappingConfig;
2192 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2193
2194 QgsRelationManager *mRelationManager = nullptr;
2195
2196 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2197 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2198 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2199
2200 QgsBookmarkManager *mBookmarkManager = nullptr;
2201
2202 QgsProjectViewSettings *mViewSettings = nullptr;
2203
2204 QgsProjectStyleSettings *mStyleSettings = nullptr;
2205
2206 QgsProjectTimeSettings *mTimeSettings = nullptr;
2207
2208 QgsProjectElevationProperties *mElevationProperties = nullptr;
2209
2210 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2211
2212 QgsLayerTree *mRootGroup = nullptr;
2213
2214 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2215
2216 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2217
2219 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2220
2221 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2222
2223 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2224
2225 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2226
2227 QVariantMap mCustomVariables;
2228
2229 std::unique_ptr<QgsArchive> mArchive;
2230
2231 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2232
2233 QFile mFile; // current physical project file
2234
2235 QString mOriginalPath;
2236
2237 QString mSaveUser; // last saved user.
2238 QString mSaveUserFull; // last saved user full name.
2239 QDateTime mSaveDateTime;
2240 QgsProjectVersion mSaveVersion;
2241
2246 QString mHomePath;
2247 mutable QString mCachedHomePath;
2248
2249 QColor mBackgroundColor;
2250 QColor mSelectionColor;
2251
2252 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2253 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2254
2255 Qgis::ProjectFlags mFlags;
2257 bool mDirty = false; // project has been modified since it has been read or saved
2258 int mDirtyBlockCount = 0;
2259
2260 QgsPropertyCollection mDataDefinedServerProperties;
2261
2262 QgsCoordinateTransformContext mTransformContext;
2263
2264 QgsProjectMetadata mMetadata;
2265
2266 std::unique_ptr< QTranslator > mTranslator;
2267
2268 bool mIsBeingDeleted = false;
2269
2270 QgsSettings mSettings;
2271
2272 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2273
2274 int mBlockSnappingUpdates = 0;
2275
2277
2278 // Required to avoid creating a new project in it's destructor
2280
2281 // Required by QGIS Server for switching the current project instance
2282 friend class QgsServer;
2283
2284 friend class TestQgsProject;
2285
2286 Q_DISABLE_COPY( QgsProject )
2287};
2288
2310class CORE_EXPORT QgsProjectDirtyBlocker
2311{
2312 public:
2313
2320 : mProject( project )
2321 {
2322 mProject->mDirtyBlockCount++;
2323 }
2324
2327
2330
2332 {
2333 mProject->mDirtyBlockCount--;
2334 }
2335
2336 private:
2337 QgsProject *mProject = nullptr;
2338
2339#ifdef SIP_RUN
2341#endif
2342};
2343
2349CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2350
2351
2352
2354#ifndef SIP_RUN
2355class GetNamedProjectColor : public QgsScopedExpressionFunction
2356{
2357 public:
2358 GetNamedProjectColor( const QgsProject *project );
2359
2364 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2365
2366 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2367 QgsScopedExpressionFunction *clone() const override;
2368
2369 private:
2370
2371 QHash< QString, QColor > mColors;
2372
2373};
2374
2375#endif
2377
2378#endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgis.h:1968
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:1861
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
Class allowing to manage the zip/unzip actions.
Definition: qgsarchive.h:36
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Class providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
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.
Class for 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 the updates in map layer registry and does changes in layer tree.
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:33
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:73
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 file.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2311
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2319
QgsProjectDirtyBlocker(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Contains elevation properties for a QgsProject.
A structured metadata store for a map layer.
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...
Wherever an object of this class is available, the derived translate function can be called from.
A class to describe 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:104
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
Qgis::ProjectFlags flags() const
Returns the project's flags, which dictate the behavior of the project.
Definition: qgsproject.h:199
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
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.
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.
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 readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:133
Q_DECL_DEPRECATED void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
void metadataChanged()
Emitted when the project's metadata 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.
Definition: qgsproject.h:1175
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.
void readProject(const QDomDocument &)
Emitted when a project is being read.
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1119
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 readProjectWithContext(const QDomDocument &, QgsReadWriteContext &context)
Emitted when a project is being read.
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,...
Definition: qgsproject.h:1192
void writeProject(QDomDocument &)
Emitted when the project is being written.
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition: qgsproject.h:189
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 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 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 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 a integer key value.
A registry / canonical manager of data providers.
The class is used as a container of context for various read/write operations on other objects.
This class manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
The QgsServer class provides OGC web services.
Definition: qgsserver.h:49
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
This is a container for configuration of the snapping of the project.
An interface for classes which can visit style entity (e.g.
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:33
Used for the collecting of strings from projects for translation and creation of ts files.
Helper functions for various unit types.
Definition: qgsunittypes.h:39
The edit buffer group manages a group of edit buffers.
Represents a vector layer which manages a vector based data sets.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:37
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define str(x)
Definition: qgis.cpp:37
#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_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
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs