QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
52#include "qgscolorscheme.h"
53#include "qgssettings.h"
56
57#include "qgsrelationmanager.h"
59
60class QFileInfo;
61class QDomDocument;
62class QDomElement;
63class QDomNode;
64
67class QgsMapLayer;
68class QgsPathResolver;
71class QgsTolerance;
73class QgsVectorLayer;
76class QgsLayerTree;
79class 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 Q_PROPERTY( QgsUnitTypes::DistanceUnit distanceUnits READ distanceUnits WRITE setDistanceUnits NOTIFY distanceUnitsChanged )
122 Q_PROPERTY( QgsUnitTypes::AreaUnit areaUnits READ areaUnits WRITE setAreaUnits NOTIFY areaUnitsChanged )
123 Q_PROPERTY( QgsProjectDisplaySettings *displaySettings READ displaySettings CONSTANT )
124
125 public:
126
136 {
137 NoProperty = 0,
138 AllProperties = 1,
139 WMSOnlineResource = 2,
140 };
141
143 static QgsProject *instance();
144
153 static void setInstance( QgsProject *project ) ;
154
163 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
164
165 ~QgsProject() override;
166
176 void setTitle( const QString &title );
177
184 QString title() const;
185
192 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
193
202 Qgis::ProjectFlags flags() const { return mFlags; }
203
212 void setFlags( Qgis::ProjectFlags flags );
213
222 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
223
231 QString saveUser() const;
232
240 QString saveUserFullName() const;
241
247 QDateTime lastSaveDateTime() const;
248
254 QgsProjectVersion lastSaveVersion() const;
255
259 bool isDirty() const;
260
267 void setFileName( const QString &name );
268
275 QString fileName() const;
276
288 void setOriginalPath( const QString &path );
289
301 QString originalPath() const;
302
313 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
314
321 QgsProjectStorage *projectStorage() const;
322
327 QDateTime lastModified() const;
328
334 QString absoluteFilePath() const;
335
341 QString absolutePath() const;
342
347 QString baseName() const;
348
355 Qgis::FilePathType filePathStorage() const;
356
363 void setFilePathStorage( Qgis::FilePathType type );
364
372
382 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
383
390 QString ellipsoid() const;
391
398 void setEllipsoid( const QString &ellipsoid );
399
400
410 QgsCoordinateTransformContext transformContext() const;
411
421 void setTransformContext( const QgsCoordinateTransformContext &context );
422
428 void clear();
429
436 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
437
446 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
447
457 bool readLayer( const QDomNode &layerNode );
458
467 bool write( const QString &filename );
468
474 bool write();
475
487 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
488
500 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
501
512 bool writeEntry( const QString &scope, const QString &key, int value );
513
524 bool writeEntry( const QString &scope, const QString &key, const QString &value );
525
536 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
537
548 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
549
560 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
561
572 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
573
584 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
585
596 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
597
601 bool removeEntry( const QString &scope, const QString &key );
602
611 QStringList entryList( const QString &scope, const QString &key ) const;
612
621 QStringList subkeyList( const QString &scope, const QString &key ) const;
622
623 // TODO Now slightly broken since re-factoring. Won't print out top-level key
624 // and redundantly prints sub-keys.
625
629 void dumpProperties() const;
630
636 QgsPathResolver pathResolver() const;
637
643 QString writePath( const QString &filename ) const;
644
648 QString readPath( const QString &filename ) const;
649
651 QString error() const;
652
657 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
658
664 QString layerIsEmbedded( const QString &id ) const;
665
674 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
675 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
676
684 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
685
687 void setTopologicalEditing( bool enabled );
688
690 bool topologicalEditing() const;
691
698 QgsUnitTypes::DistanceUnit distanceUnits() const { return mDistanceUnits; }
699
706 void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
707
713 QgsUnitTypes::AreaUnit areaUnits() const { return mAreaUnits; }
714
721 void setAreaUnits( QgsUnitTypes::AreaUnit unit );
722
735 QString homePath() const;
736
749 QString presetHomePath() const;
750
751 QgsRelationManager *relationManager() const;
752
759 const QgsLayoutManager *layoutManager() const SIP_SKIP;
760
766 QgsLayoutManager *layoutManager();
767
774 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
775
781 QgsMapViewsManager *viewsManager();
782
789 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
790
796 QgsBookmarkManager *bookmarkManager();
797
805 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
806
813 QgsProjectViewSettings *viewSettings();
814
822 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
823
830 QgsProjectStyleSettings *styleSettings();
831
839 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
840
847 QgsProjectTimeSettings *timeSettings();
848
855 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
856
862 QgsProjectElevationProperties *elevationProperties();
863
870 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
871
877 QgsProjectDisplaySettings *displaySettings();
878
883 QgsLayerTree *layerTreeRoot() const;
884
889 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
890
897
902 QgsAnnotationManager *annotationManager();
903
908 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
909
914 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
915
920 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
921
926 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
927
936 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
937
948 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
949
956 Qgis::TransactionMode transactionMode() const;
957
967 bool setTransactionMode( Qgis::TransactionMode transactionMode );
968
977 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
978
986 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
987
993 QgsVectorLayerEditBufferGroup *editBufferGroup();
994
1000 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1001
1007 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1008
1009 QgsExpressionContext createExpressionContext() const override;
1010 QgsExpressionContextScope *createExpressionContextScope() const override;
1011
1017 QgsSnappingConfig snappingConfig() const;
1018
1024 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1025
1032 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1033
1039 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1040
1046 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1047
1053 QVariantMap customVariables() const;
1054
1059 void setCustomVariables( const QVariantMap &customVariables );
1060
1065 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1066
1071 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1072
1073 //
1074 // Functionality from QgsMapLayerRegistry
1075 //
1076
1081 QgsMapLayerStore *layerStore();
1082
1087 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1088
1090 int count() const;
1091
1093 int validCount() const;
1094
1102 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1103
1104#ifndef SIP_RUN
1105
1121 template <class T>
1122 T mapLayer( const QString &layerId ) const
1123 {
1124 return qobject_cast<T>( mapLayer( layerId ) );
1125 }
1126#endif
1127
1135 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1136
1146 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1147
1148
1157 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1158
1162 bool isZipped() const;
1163
1164#ifndef SIP_RUN
1165
1177 template <typename T>
1178 QVector<T> layers() const
1179 {
1180 return mLayerStore->layers<T>();
1181 }
1182
1194 template <typename T>
1195 QVector<T> mapLayersByShortName( const QString &shortName ) const
1196 {
1197 QVector<T> layers;
1198 const auto constMapLayers { mLayerStore->layers<T>() };
1199 for ( const auto l : constMapLayers )
1200 {
1201 if ( ! l->shortName().isEmpty() )
1202 {
1203 if ( l->shortName() == shortName )
1204 layers << l;
1205 }
1206 else if ( l->name() == shortName )
1207 {
1208 layers << l;
1209 }
1210 }
1211 return layers;
1212 }
1213
1214#endif
1215
1241 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1242 bool addToLegend = true,
1243 bool takeOwnership SIP_PYARGREMOVE = true );
1244
1272 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1273 bool addToLegend = true,
1274 bool takeOwnership SIP_PYARGREMOVE = true );
1275
1290 void removeMapLayers( const QStringList &layerIds );
1291
1292 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1293
1307 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1308
1322 void removeMapLayer( const QString &layerId );
1323
1337 void removeMapLayer( QgsMapLayer *layer );
1338
1346 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1347
1359 QgsAnnotationLayer *mainAnnotationLayer();
1360
1371 void removeAllMapLayers();
1372
1378 void reloadAllLayers();
1379
1384 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1385
1397 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1398
1409 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1410
1416 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1417
1423 QgsAuxiliaryStorage *auxiliaryStorage();
1424
1433 QString createAttachedFile( const QString &nameTemplate );
1434
1441 QStringList attachedFiles() const;
1442
1450 bool removeAttachedFile( const QString &path );
1451
1460 QString attachmentIdentifier( const QString &attachedFile ) const;
1461
1468 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1469
1476 const QgsProjectMetadata &metadata() const;
1477
1484 void setMetadata( const QgsProjectMetadata &metadata );
1485
1494 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1495
1504 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1505
1512 void setProjectColors( const QgsNamedColorList &colors );
1513
1520 void setBackgroundColor( const QColor &color );
1521
1528 QColor backgroundColor() const;
1529
1536 void setSelectionColor( const QColor &color );
1537
1544 QColor selectionColor() const;
1545
1557 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1558
1570 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1571
1580 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1581
1590 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1591
1596 void generateTsFile( const QString &locale );
1597
1608 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1609
1619 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1620
1621#ifdef SIP_RUN
1622 SIP_PYOBJECT __repr__();
1623 % MethodCode
1624 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1625 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1626 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1627 % End
1628#endif
1629
1630 signals:
1631
1639 void cleared();
1640
1644 void readProject( const QDomDocument & );
1645
1649 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1650
1654 void writeProject( QDomDocument & );
1655
1664 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1665
1674 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1675
1680
1686 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1687
1698 void readVersionMismatchOccurred( const QString &fileVersion );
1699
1705 void layerLoaded( int i, int n );
1706
1708 void loadingLayer( const QString &layerName );
1709
1716 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1717
1722 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1723
1726
1734
1739
1746
1752
1759
1767 void ellipsoidChanged( const QString &ellipsoid );
1768
1776
1784
1792
1797 void missingDatumTransforms( const QStringList &missingTransforms );
1798
1806
1813
1820
1833
1839
1847
1855
1863
1871
1872 //
1873 // signals from QgsMapLayerRegistry
1874 //
1875
1883 void layersWillBeRemoved( const QStringList &layerIds );
1884
1892 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1893
1903 void layerWillBeRemoved( const QString &layerId );
1904
1915
1922 void layersRemoved( const QStringList &layerIds );
1923
1932 void layerRemoved( const QString &layerId );
1933
1934 //TODO QGIS 4.0 - rename to past tense
1935
1943
1954 void layersAdded( const QList<QgsMapLayer *> &layers );
1955
1963
1972 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1973
1981 void isDirtyChanged( bool dirty );
1982
1990 void dirtySet();
1991
2000 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2001
2002 public slots:
2003
2009 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2010
2011 // TODO QGIS 4.0 - rename b to dirty
2012
2020 void setDirty( bool b = true );
2021
2030 void setPresetHomePath( const QString &path );
2031
2041 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2042
2049 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2050
2057 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2058
2065 QgsPropertyCollection dataDefinedServerProperties() const;
2066
2083 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2084
2114 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2115
2132 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2133
2134 private slots:
2135 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2136 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2137 void cleanTransactionGroups( bool force = false );
2138 void updateTransactionGroups();
2139
2140 private:
2141
2142 static QgsProject *sProject;
2143
2144
2153 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2154
2159 void setError( const QString &errorMessage ) SIP_SKIP;
2160
2165 void clearError() SIP_SKIP;
2166
2174 bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2175
2179 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2180
2186 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2187
2192 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2193
2195 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2196
2198 bool writeProjectFile( const QString &filename );
2199
2201 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2202
2204 bool zip( const QString &filename );
2205
2207 bool saveAuxiliaryStorage( const QString &filename = QString() );
2208
2210 void loadProjectFlags( const QDomDocument *doc );
2211
2213 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2214
2215 Qgis::ProjectCapabilities mCapabilities;
2216
2217 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2218
2219 QString mErrorMessage;
2220
2221 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2222
2228 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2229
2230 QgsSnappingConfig mSnappingConfig;
2231 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2232
2233 QgsRelationManager *mRelationManager = nullptr;
2234
2235 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2236 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2237 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2238
2239 QgsBookmarkManager *mBookmarkManager = nullptr;
2240
2241 QgsProjectViewSettings *mViewSettings = nullptr;
2242
2243 QgsProjectStyleSettings *mStyleSettings = nullptr;
2244
2245 QgsProjectTimeSettings *mTimeSettings = nullptr;
2246
2247 QgsProjectElevationProperties *mElevationProperties = nullptr;
2248
2249 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2250
2251 QgsLayerTree *mRootGroup = nullptr;
2252
2253 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2254
2255 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2256
2258 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2259
2260 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2261
2262 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2263
2264 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2265
2266 QVariantMap mCustomVariables;
2267
2268 std::unique_ptr<QgsArchive> mArchive;
2269
2270 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2271
2272 QFile mFile; // current physical project file
2273
2274 QString mOriginalPath;
2275
2276 QString mSaveUser; // last saved user.
2277 QString mSaveUserFull; // last saved user full name.
2278 QDateTime mSaveDateTime;
2279 QgsProjectVersion mSaveVersion;
2280
2285 QString mHomePath;
2286 mutable QString mCachedHomePath;
2287
2288 QColor mBackgroundColor;
2289 QColor mSelectionColor;
2290
2291 QgsUnitTypes::DistanceUnit mDistanceUnits = QgsUnitTypes::DistanceMeters;
2292 QgsUnitTypes::AreaUnit mAreaUnits = QgsUnitTypes::AreaSquareMeters;
2293
2294 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2295 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2296
2297 Qgis::ProjectFlags mFlags;
2299 bool mDirty = false; // project has been modified since it has been read or saved
2300 int mDirtyBlockCount = 0;
2301
2302 QgsPropertyCollection mDataDefinedServerProperties;
2303
2304 QgsCoordinateTransformContext mTransformContext;
2305
2306 QgsProjectMetadata mMetadata;
2307
2308 std::unique_ptr< QTranslator > mTranslator;
2309
2310 bool mIsBeingDeleted = false;
2311
2312 QgsSettings mSettings;
2313
2314 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2315
2316 int mBlockSnappingUpdates = 0;
2317
2318 friend class QgsApplication;
2319
2321
2322 // Required to avoid creating a new project in it's destructor
2324
2325 // Required by QGIS Server for switching the current project instance
2326 friend class QgsServer;
2327
2328 friend class TestQgsProject;
2329
2330 Q_DISABLE_COPY( QgsProject )
2331};
2332
2354class CORE_EXPORT QgsProjectDirtyBlocker
2355{
2356 public:
2357
2364 : mProject( project )
2365 {
2366 mProject->mDirtyBlockCount++;
2367 }
2368
2371
2374
2376 {
2377 mProject->mDirtyBlockCount--;
2378 }
2379
2380 private:
2381 QgsProject *mProject = nullptr;
2382
2383#ifdef SIP_RUN
2385#endif
2386};
2387
2393CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2394
2395
2396
2398#ifndef SIP_RUN
2399class GetNamedProjectColor : public QgsScopedExpressionFunction
2400{
2401 public:
2402 GetNamedProjectColor( const QgsProject *project );
2403
2408 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2409
2410 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2411 QgsScopedExpressionFunction *clone() const override;
2412
2413 private:
2414
2415 QHash< QString, QColor > mColors;
2416
2417};
2418
2419#endif
2421
2422#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:2085
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:1978
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,...
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:2355
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2363
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:202
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
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.
QgsUnitTypes::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
Definition: qgsproject.h:713
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.
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:136
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:1178
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:1122
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:1195
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:192
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
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
AreaUnit
Units of area.
Definition: qgsunittypes.h:94
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:74
#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