QGIS API Documentation 3.29.0-Master (8c80f25a4f)
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;
90
105{
106 Q_OBJECT
107 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
108 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
109 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
110 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
111 Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
112 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
113 Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
114 Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
115 Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
116 Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
117 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
118 Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
119 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
120 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
121 Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
122 Q_PROPERTY( QgsUnitTypes::DistanceUnit distanceUnits READ distanceUnits WRITE setDistanceUnits NOTIFY distanceUnitsChanged )
123 Q_PROPERTY( QgsUnitTypes::AreaUnit areaUnits READ areaUnits WRITE setAreaUnits NOTIFY areaUnitsChanged )
124 Q_PROPERTY( QgsProjectDisplaySettings *displaySettings READ displaySettings CONSTANT )
125
126 public:
127
137 {
138 NoProperty = 0,
139 AllProperties = 1,
140 WMSOnlineResource = 2,
141 };
142
144 static QgsProject *instance();
145
154 static void setInstance( QgsProject *project ) ;
155
164 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
165
166 ~QgsProject() override;
167
177 void setTitle( const QString &title );
178
185 QString title() const;
186
193 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
194
203 Qgis::ProjectFlags flags() const { return mFlags; }
204
213 void setFlags( Qgis::ProjectFlags flags );
214
223 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
224
232 QString saveUser() const;
233
241 QString saveUserFullName() const;
242
248 QDateTime lastSaveDateTime() const;
249
255 QgsProjectVersion lastSaveVersion() const;
256
260 bool isDirty() const;
261
268 void setFileName( const QString &name );
269
276 QString fileName() const;
277
289 void setOriginalPath( const QString &path );
290
302 QString originalPath() const;
303
314 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
315
322 QgsProjectStorage *projectStorage() const;
323
328 QDateTime lastModified() const;
329
335 QString absoluteFilePath() const;
336
342 QString absolutePath() const;
343
348 QString baseName() const;
349
356 Qgis::FilePathType filePathStorage() const;
357
364 void setFilePathStorage( Qgis::FilePathType type );
365
373
383 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
384
391 QString ellipsoid() const;
392
399 void setEllipsoid( const QString &ellipsoid );
400
401
411 QgsCoordinateTransformContext transformContext() const;
412
422 void setTransformContext( const QgsCoordinateTransformContext &context );
423
429 void clear();
430
437 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
438
447 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
448
458 bool readLayer( const QDomNode &layerNode );
459
468 bool write( const QString &filename );
469
475 bool write();
476
488 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
489
501 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
502
513 bool writeEntry( const QString &scope, const QString &key, int value );
514
525 bool writeEntry( const QString &scope, const QString &key, const QString &value );
526
537 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
538
549 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
550
561 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
562
573 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
574
585 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
586
597 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
598
602 bool removeEntry( const QString &scope, const QString &key );
603
612 QStringList entryList( const QString &scope, const QString &key ) const;
613
622 QStringList subkeyList( const QString &scope, const QString &key ) const;
623
624 // TODO Now slightly broken since re-factoring. Won't print out top-level key
625 // and redundantly prints sub-keys.
626
630 void dumpProperties() const;
631
637 QgsPathResolver pathResolver() const;
638
644 QString writePath( const QString &filename ) const;
645
649 QString readPath( const QString &filename ) const;
650
652 QString error() const;
653
658 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
659
665 QString layerIsEmbedded( const QString &id ) const;
666
675 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
676 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
677
685 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
686
688 void setTopologicalEditing( bool enabled );
689
691 bool topologicalEditing() const;
692
699 QgsUnitTypes::DistanceUnit distanceUnits() const { return mDistanceUnits; }
700
707 void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
708
714 QgsUnitTypes::AreaUnit areaUnits() const { return mAreaUnits; }
715
722 void setAreaUnits( QgsUnitTypes::AreaUnit unit );
723
736 QString homePath() const;
737
750 QString presetHomePath() const;
751
752 QgsRelationManager *relationManager() const;
753
760 const QgsLayoutManager *layoutManager() const SIP_SKIP;
761
767 QgsLayoutManager *layoutManager();
768
775 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
776
782 QgsMapViewsManager *viewsManager();
783
790 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
791
797 QgsBookmarkManager *bookmarkManager();
798
806 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
807
814 QgsProjectViewSettings *viewSettings();
815
823 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
824
831 QgsProjectStyleSettings *styleSettings();
832
840 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
841
848 QgsProjectTimeSettings *timeSettings();
849
856 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
857
863 QgsProjectElevationProperties *elevationProperties();
864
871 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
872
878 QgsProjectDisplaySettings *displaySettings();
879
886 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
887
893 QgsProjectGpsSettings *gpsSettings();
894
899 QgsLayerTree *layerTreeRoot() const;
900
905 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
906
913
918 QgsAnnotationManager *annotationManager();
919
924 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
925
930 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
931
936 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
937
942 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
943
952 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
953
964 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
965
972 Qgis::TransactionMode transactionMode() const;
973
983 bool setTransactionMode( Qgis::TransactionMode transactionMode );
984
993 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
994
1002 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1003
1009 QgsVectorLayerEditBufferGroup *editBufferGroup();
1010
1016 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1017
1023 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1024
1025 QgsExpressionContext createExpressionContext() const override;
1026 QgsExpressionContextScope *createExpressionContextScope() const override;
1027
1033 QgsSnappingConfig snappingConfig() const;
1034
1040 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1041
1048 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1049
1055 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1056
1062 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1063
1069 QVariantMap customVariables() const;
1070
1075 void setCustomVariables( const QVariantMap &customVariables );
1076
1081 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1082
1087 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1088
1089 //
1090 // Functionality from QgsMapLayerRegistry
1091 //
1092
1097 QgsMapLayerStore *layerStore();
1098
1103 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1104
1106 int count() const;
1107
1109 int validCount() const;
1110
1118 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1119
1120#ifndef SIP_RUN
1121
1137 template <class T>
1138 T mapLayer( const QString &layerId ) const
1139 {
1140 return qobject_cast<T>( mapLayer( layerId ) );
1141 }
1142#endif
1143
1151 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1152
1162 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1163
1164
1173 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1174
1178 bool isZipped() const;
1179
1180#ifndef SIP_RUN
1181
1193 template <typename T>
1194 QVector<T> layers() const
1195 {
1196 return mLayerStore->layers<T>();
1197 }
1198
1210 template <typename T>
1211 QVector<T> mapLayersByShortName( const QString &shortName ) const
1212 {
1213 QVector<T> layers;
1214 const auto constMapLayers { mLayerStore->layers<T>() };
1215 for ( const auto l : constMapLayers )
1216 {
1217 if ( ! l->shortName().isEmpty() )
1218 {
1219 if ( l->shortName() == shortName )
1220 layers << l;
1221 }
1222 else if ( l->name() == shortName )
1223 {
1224 layers << l;
1225 }
1226 }
1227 return layers;
1228 }
1229
1230#endif
1231
1257 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1258 bool addToLegend = true,
1259 bool takeOwnership SIP_PYARGREMOVE = true );
1260
1288 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1289 bool addToLegend = true,
1290 bool takeOwnership SIP_PYARGREMOVE = true );
1291
1306 void removeMapLayers( const QStringList &layerIds );
1307
1308 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1309
1323 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1324
1338 void removeMapLayer( const QString &layerId );
1339
1353 void removeMapLayer( QgsMapLayer *layer );
1354
1362 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1363
1375 QgsAnnotationLayer *mainAnnotationLayer();
1376
1387 void removeAllMapLayers();
1388
1394 void reloadAllLayers();
1395
1400 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1401
1413 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1414
1425 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1426
1432 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1433
1439 QgsAuxiliaryStorage *auxiliaryStorage();
1440
1449 QString createAttachedFile( const QString &nameTemplate );
1450
1457 QStringList attachedFiles() const;
1458
1466 bool removeAttachedFile( const QString &path );
1467
1476 QString attachmentIdentifier( const QString &attachedFile ) const;
1477
1484 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1485
1492 const QgsProjectMetadata &metadata() const;
1493
1500 void setMetadata( const QgsProjectMetadata &metadata );
1501
1510 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1511
1520 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1521
1528 void setProjectColors( const QgsNamedColorList &colors );
1529
1536 void setBackgroundColor( const QColor &color );
1537
1544 QColor backgroundColor() const;
1545
1552 void setSelectionColor( const QColor &color );
1553
1560 QColor selectionColor() const;
1561
1573 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1574
1586 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1587
1596 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1597
1606 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1607
1612 void generateTsFile( const QString &locale );
1613
1624 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1625
1635 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1636
1637#ifdef SIP_RUN
1638 SIP_PYOBJECT __repr__();
1639 % MethodCode
1640 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1641 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1642 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1643 % End
1644#endif
1645
1646 signals:
1647
1655 void cleared();
1656
1660 void readProject( const QDomDocument & );
1661
1665 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1666
1670 void writeProject( QDomDocument & );
1671
1680 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1681
1690 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1691
1696
1702 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1703
1714 void readVersionMismatchOccurred( const QString &fileVersion );
1715
1721 void layerLoaded( int i, int n );
1722
1724 void loadingLayer( const QString &layerName );
1725
1732 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1733
1738 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1739
1742
1750
1755
1762
1768
1775
1783 void ellipsoidChanged( const QString &ellipsoid );
1784
1792
1800
1808
1813 void missingDatumTransforms( const QStringList &missingTransforms );
1814
1822
1829
1836
1849
1855
1863
1871
1879
1887
1888 //
1889 // signals from QgsMapLayerRegistry
1890 //
1891
1899 void layersWillBeRemoved( const QStringList &layerIds );
1900
1908 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1909
1919 void layerWillBeRemoved( const QString &layerId );
1920
1931
1938 void layersRemoved( const QStringList &layerIds );
1939
1948 void layerRemoved( const QString &layerId );
1949
1950 //TODO QGIS 4.0 - rename to past tense
1951
1959
1970 void layersAdded( const QList<QgsMapLayer *> &layers );
1971
1979
1988 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1989
1997 void isDirtyChanged( bool dirty );
1998
2006 void dirtySet();
2007
2016 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2017
2018 public slots:
2019
2025 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2026
2027 // TODO QGIS 4.0 - rename b to dirty
2028
2036 void setDirty( bool b = true );
2037
2046 void setPresetHomePath( const QString &path );
2047
2057 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2058
2065 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2066
2073 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2074
2081 QgsPropertyCollection dataDefinedServerProperties() const;
2082
2099 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2100
2130 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2131
2148 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2149
2150 private slots:
2151 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2152 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2153 void cleanTransactionGroups( bool force = false );
2154 void updateTransactionGroups();
2155
2156 private:
2157
2158 static QgsProject *sProject;
2159
2160
2169 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2170
2175 void setError( const QString &errorMessage ) SIP_SKIP;
2176
2181 void clearError() SIP_SKIP;
2182
2190 bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2191
2195 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2196
2202 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2203
2208 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2209
2211 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2212
2214 bool writeProjectFile( const QString &filename );
2215
2217 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2218
2220 bool zip( const QString &filename );
2221
2223 bool saveAuxiliaryStorage( const QString &filename = QString() );
2224
2226 void loadProjectFlags( const QDomDocument *doc );
2227
2229 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2230
2231 Qgis::ProjectCapabilities mCapabilities;
2232
2233 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2234
2235 QString mErrorMessage;
2236
2237 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2238
2244 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2245
2246 QgsSnappingConfig mSnappingConfig;
2247 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2248
2249 QgsRelationManager *mRelationManager = nullptr;
2250
2251 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2252 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2253 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2254
2255 QgsBookmarkManager *mBookmarkManager = nullptr;
2256
2257 QgsProjectViewSettings *mViewSettings = nullptr;
2258
2259 QgsProjectStyleSettings *mStyleSettings = nullptr;
2260
2261 QgsProjectTimeSettings *mTimeSettings = nullptr;
2262
2263 QgsProjectElevationProperties *mElevationProperties = nullptr;
2264
2265 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2266
2267 QgsProjectGpsSettings *mGpsSettings = nullptr;
2268
2269 QgsLayerTree *mRootGroup = nullptr;
2270
2271 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2272
2273 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2274
2276 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2277
2278 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2279
2280 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2281
2282 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2283
2284 QVariantMap mCustomVariables;
2285
2286 std::unique_ptr<QgsArchive> mArchive;
2287
2288 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2289
2290 QFile mFile; // current physical project file
2291
2292 QString mOriginalPath;
2293
2294 QString mSaveUser; // last saved user.
2295 QString mSaveUserFull; // last saved user full name.
2296 QDateTime mSaveDateTime;
2297 QgsProjectVersion mSaveVersion;
2298
2303 QString mHomePath;
2304 mutable QString mCachedHomePath;
2305
2306 QColor mBackgroundColor;
2307 QColor mSelectionColor;
2308
2309 QgsUnitTypes::DistanceUnit mDistanceUnits = QgsUnitTypes::DistanceMeters;
2310 QgsUnitTypes::AreaUnit mAreaUnits = QgsUnitTypes::AreaSquareMeters;
2311
2312 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2313 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2314
2315 Qgis::ProjectFlags mFlags;
2317 bool mDirty = false; // project has been modified since it has been read or saved
2318 int mDirtyBlockCount = 0;
2319
2320 QgsPropertyCollection mDataDefinedServerProperties;
2321
2322 QgsCoordinateTransformContext mTransformContext;
2323
2324 QgsProjectMetadata mMetadata;
2325
2326 std::unique_ptr< QTranslator > mTranslator;
2327
2328 bool mIsBeingDeleted = false;
2329
2330 QgsSettings mSettings;
2331
2332 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2333
2334 int mBlockSnappingUpdates = 0;
2335
2336 friend class QgsApplication;
2337
2339
2340 // Required to avoid creating a new project in it's destructor
2342
2343 // Required by QGIS Server for switching the current project instance
2344 friend class QgsServer;
2345
2346 friend class TestQgsProject;
2347
2348 Q_DISABLE_COPY( QgsProject )
2349};
2350
2372class CORE_EXPORT QgsProjectDirtyBlocker
2373{
2374 public:
2375
2382 : mProject( project )
2383 {
2384 mProject->mDirtyBlockCount++;
2385 }
2386
2389
2392
2394 {
2395 mProject->mDirtyBlockCount--;
2396 }
2397
2398 private:
2399 QgsProject *mProject = nullptr;
2400
2401#ifdef SIP_RUN
2403#endif
2404};
2405
2411CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2412
2413
2414
2416#ifndef SIP_RUN
2417class GetNamedProjectColor : public QgsScopedExpressionFunction
2418{
2419 public:
2420 GetNamedProjectColor( const QgsProject *project );
2421
2426 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2427
2428 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2429 QgsScopedExpressionFunction *clone() const override;
2430
2431 private:
2432
2433 QHash< QString, QColor > mColors;
2434
2435};
2436
2437#endif
2439
2440#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:2316
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:2209
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:2373
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2381
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.
Contains settings and properties relating to how a QgsProject should interact with a GPS device.
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:105
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:203
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:476
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:714
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:137
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:1194
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:1138
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:1211
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:193
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