QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsproject.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsproject.h
3
4 Implements persistent project state.
5
6 -------------------
7 begin : July 23, 2004
8 copyright : (C) 2004 by Mark Coletti
9 email : mcoletti at gmail.com
10 ***************************************************************************/
11
12/***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21#ifndef QGSPROJECT_H
22#define QGSPROJECT_H
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgis.h"
27
28#include <memory>
29#include <QHash>
30#include <QList>
31#include <QObject>
32#include <QPair>
33#include <QFileInfo>
34#include <QStringList>
35#include <QTranslator>
36
37#include "qgssnappingconfig.h"
38#include "qgsprojectversion.h"
43#include "qgsprojectproperty.h"
44#include "qgsmaplayerstore.h"
45#include "qgsarchive.h"
46#include "qgsreadwritecontext.h"
47#include "qgsprojectmetadata.h"
51#include "qgscolorscheme.h"
52#include "qgssettings.h"
56#include "qgsabstractsensor.h"
57
58#include "qgsrelationmanager.h"
60
61class QFileInfo;
62class QDomDocument;
63class QDomElement;
64class QDomNode;
65
68class QgsMapLayer;
69class QgsPathResolver;
72class QgsTolerance;
74class QgsVectorLayer;
77class QgsLayerTree;
80class QgsMapLayer;
92
107{
108 Q_OBJECT
109 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
110 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
111 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
112 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
113 Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
114 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
115 Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
116 Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
117 Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
118 Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
119 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
120 Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
121 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
122 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
123 Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
124 Q_PROPERTY( Qgis::DistanceUnit distanceUnits READ distanceUnits WRITE setDistanceUnits NOTIFY distanceUnitsChanged )
125 Q_PROPERTY( Qgis::AreaUnit areaUnits READ areaUnits WRITE setAreaUnits NOTIFY areaUnitsChanged )
126 Q_PROPERTY( QgsProjectDisplaySettings *displaySettings READ displaySettings CONSTANT )
127
128 public:
129
139 {
140 NoProperty = 0,
141 AllProperties = 1,
142 WMSOnlineResource = 2,
143 };
144
146 static QgsProject *instance();
147
156 static void setInstance( QgsProject *project ) ;
157
166 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
167
168 ~QgsProject() override;
169
179 void setTitle( const QString &title );
180
187 QString title() const;
188
195 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
196
205 Qgis::ProjectFlags flags() const { return mFlags; }
206
215 void setFlags( Qgis::ProjectFlags flags );
216
225 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
226
234 QString saveUser() const;
235
243 QString saveUserFullName() const;
244
250 QDateTime lastSaveDateTime() const;
251
257 QgsProjectVersion lastSaveVersion() const;
258
262 bool isDirty() const;
263
270 void setFileName( const QString &name );
271
278 QString fileName() const;
279
291 void setOriginalPath( const QString &path );
292
304 QString originalPath() const;
305
316 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
317
324 QgsProjectStorage *projectStorage() const;
325
330 QDateTime lastModified() const;
331
337 QString absoluteFilePath() const;
338
344 QString absolutePath() const;
345
350 QString baseName() const;
351
358 Qgis::FilePathType filePathStorage() const;
359
366 void setFilePathStorage( Qgis::FilePathType type );
367
375
385 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
386
393 QString ellipsoid() const;
394
401 void setEllipsoid( const QString &ellipsoid );
402
403
413 QgsCoordinateTransformContext transformContext() const;
414
424 void setTransformContext( const QgsCoordinateTransformContext &context );
425
431 void clear();
432
439 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
440
449 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
450
460 bool readLayer( const QDomNode &layerNode );
461
470 bool write( const QString &filename );
471
477 bool write();
478
490 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
491
503 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
504
515 bool writeEntry( const QString &scope, const QString &key, int value );
516
527 bool writeEntry( const QString &scope, const QString &key, const QString &value );
528
539 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
540
551 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
552
563 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
564
575 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
576
587 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
588
599 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
600
604 bool removeEntry( const QString &scope, const QString &key );
605
614 QStringList entryList( const QString &scope, const QString &key ) const;
615
624 QStringList subkeyList( const QString &scope, const QString &key ) const;
625
626 // TODO Now slightly broken since re-factoring. Won't print out top-level key
627 // and redundantly prints sub-keys.
628
632 void dumpProperties() const;
633
639 QgsPathResolver pathResolver() const;
640
646 QString writePath( const QString &filename ) const;
647
651 QString readPath( const QString &filename ) const;
652
654 QString error() const;
655
660 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
661
667 QString layerIsEmbedded( const QString &id ) const;
668
677 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
678 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
679
687 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
688
690 void setTopologicalEditing( bool enabled );
691
693 bool topologicalEditing() const;
694
701 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
702
709 void setDistanceUnits( Qgis::DistanceUnit unit );
710
716 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
717
724 void setAreaUnits( Qgis::AreaUnit unit );
725
738 QString homePath() const;
739
752 QString presetHomePath() const;
753
754 QgsRelationManager *relationManager() const;
755
762 const QgsLayoutManager *layoutManager() const SIP_SKIP;
763
769 QgsLayoutManager *layoutManager();
770
777 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
778
784 QgsMapViewsManager *viewsManager();
785
792 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
793
799 QgsBookmarkManager *bookmarkManager();
800
807 const QgsSensorManager *sensorManager() const SIP_SKIP;
808
814 QgsSensorManager *sensorManager();
815
823 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
824
831 QgsProjectViewSettings *viewSettings();
832
840 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
841
848 QgsProjectStyleSettings *styleSettings();
849
857 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
858
865 QgsProjectTimeSettings *timeSettings();
866
873 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
874
880 QgsProjectElevationProperties *elevationProperties();
881
888 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
889
895 QgsProjectDisplaySettings *displaySettings();
896
903 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
904
910 QgsProjectGpsSettings *gpsSettings();
911
916 QgsLayerTree *layerTreeRoot() const;
917
922 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
923
930
935 QgsAnnotationManager *annotationManager();
936
941 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
942
947 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
948
953 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
954
959 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
960
969 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
970
981 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
982
989 Qgis::TransactionMode transactionMode() const;
990
1000 bool setTransactionMode( Qgis::TransactionMode transactionMode );
1001
1010 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
1011
1019 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1020
1026 QgsVectorLayerEditBufferGroup *editBufferGroup();
1027
1033 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1034
1040 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1041
1042 QgsExpressionContext createExpressionContext() const override;
1043 QgsExpressionContextScope *createExpressionContextScope() const override;
1044
1050 QgsSnappingConfig snappingConfig() const;
1051
1057 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1058
1065 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1066
1072 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1073
1079 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1080
1086 QVariantMap customVariables() const;
1087
1092 void setCustomVariables( const QVariantMap &customVariables );
1093
1098 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1099
1104 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1105
1106 //
1107 // Functionality from QgsMapLayerRegistry
1108 //
1109
1114 QgsMapLayerStore *layerStore();
1115
1120 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1121
1123 int count() const;
1124
1126 int validCount() const;
1127
1135 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1136
1137#ifndef SIP_RUN
1138
1154 template <class T>
1155 T mapLayer( const QString &layerId ) const
1156 {
1157 return qobject_cast<T>( mapLayer( layerId ) );
1158 }
1159#endif
1160
1168 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1169
1179 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1180
1181
1190 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1191
1195 bool isZipped() const;
1196
1197#ifndef SIP_RUN
1198
1210 template <typename T>
1211 QVector<T> layers() const
1212 {
1213 return mLayerStore->layers<T>();
1214 }
1215
1227 template <typename T>
1228 QVector<T> mapLayersByShortName( const QString &shortName ) const
1229 {
1230 QVector<T> layers;
1231 const auto constMapLayers { mLayerStore->layers<T>() };
1232 for ( const auto l : constMapLayers )
1233 {
1234 if ( ! l->shortName().isEmpty() )
1235 {
1236 if ( l->shortName() == shortName )
1237 layers << l;
1238 }
1239 else if ( l->name() == shortName )
1240 {
1241 layers << l;
1242 }
1243 }
1244 return layers;
1245 }
1246
1247#endif
1248
1274 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1275 bool addToLegend = true,
1276 bool takeOwnership SIP_PYARGREMOVE = true );
1277
1305 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1306 bool addToLegend = true,
1307 bool takeOwnership SIP_PYARGREMOVE = true );
1308
1323 void removeMapLayers( const QStringList &layerIds );
1324
1325 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1326
1340 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1341
1355 void removeMapLayer( const QString &layerId );
1356
1370 void removeMapLayer( QgsMapLayer *layer );
1371
1379 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1380
1392 QgsAnnotationLayer *mainAnnotationLayer();
1393
1404 void removeAllMapLayers();
1405
1411 void reloadAllLayers();
1412
1417 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1418
1430 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1431
1442 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1443
1449 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1450
1456 QgsAuxiliaryStorage *auxiliaryStorage();
1457
1466 QString createAttachedFile( const QString &nameTemplate );
1467
1474 QStringList attachedFiles() const;
1475
1483 bool removeAttachedFile( const QString &path );
1484
1493 QString attachmentIdentifier( const QString &attachedFile ) const;
1494
1501 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1502
1509 const QgsProjectMetadata &metadata() const;
1510
1517 void setMetadata( const QgsProjectMetadata &metadata );
1518
1527 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1528
1537 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1538
1545 void setProjectColors( const QgsNamedColorList &colors );
1546
1553 void setBackgroundColor( const QColor &color );
1554
1561 QColor backgroundColor() const;
1562
1569 void setSelectionColor( const QColor &color );
1570
1577 QColor selectionColor() const;
1578
1590 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1591
1603 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1604
1613 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1614
1623 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1624
1629 void generateTsFile( const QString &locale );
1630
1641 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1642
1652 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1653
1659 QgsElevationShadingRenderer elevationShadingRenderer() const;
1660
1666 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1667
1668#ifdef SIP_RUN
1669 SIP_PYOBJECT __repr__();
1670 % MethodCode
1671 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1672 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1673 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1674 % End
1675#endif
1676
1677 signals:
1678
1686 void cleared();
1687
1691 void readProject( const QDomDocument & );
1692
1696 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1697
1701 void writeProject( QDomDocument & );
1702
1711 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1712
1721 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1722
1727
1733 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1734
1745 void readVersionMismatchOccurred( const QString &fileVersion );
1746
1752 void layerLoaded( int i, int n );
1753
1755 void loadingLayer( const QString &layerName );
1756
1763 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1764
1769 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1770
1773
1781
1786
1793
1799
1806
1814 void ellipsoidChanged( const QString &ellipsoid );
1815
1823
1831
1839
1844 void missingDatumTransforms( const QStringList &missingTransforms );
1845
1853
1860
1867
1880
1886
1894
1902
1910
1918
1919 //
1920 // signals from QgsMapLayerRegistry
1921 //
1922
1930 void layersWillBeRemoved( const QStringList &layerIds );
1931
1939 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1940
1950 void layerWillBeRemoved( const QString &layerId );
1951
1962
1969 void layersRemoved( const QStringList &layerIds );
1970
1979 void layerRemoved( const QString &layerId );
1980
1981 //TODO QGIS 4.0 - rename to past tense
1982
1990
2001 void layersAdded( const QList<QgsMapLayer *> &layers );
2002
2010
2019 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2020
2028 void isDirtyChanged( bool dirty );
2029
2037 void dirtySet();
2038
2047 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2048
2054 void elevationShadingRendererChanged();
2055
2056 public slots:
2057
2063 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2064
2065 // TODO QGIS 4.0 - rename b to dirty
2066
2074 void setDirty( bool b = true );
2075
2084 void setPresetHomePath( const QString &path );
2085
2095 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2096
2103 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2104
2111 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2112
2119 QgsPropertyCollection dataDefinedServerProperties() const;
2120
2137 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2138
2168 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2169
2186 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2187
2188 private slots:
2189 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2190 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2191 void cleanTransactionGroups( bool force = false );
2192 void updateTransactionGroups();
2193
2194 private:
2195
2196 static QgsProject *sProject;
2197
2198
2207 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2208
2213 void setError( const QString &errorMessage ) SIP_SKIP;
2214
2219 void clearError() SIP_SKIP;
2220
2230 bool addLayer( const QDomElement &layerElem,
2231 QList<QDomNode> &brokenNodes,
2232 QgsReadWriteContext &context,
2233 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2234 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2235
2239 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2240
2246 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2247
2252 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2253
2255 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2256
2258 bool writeProjectFile( const QString &filename );
2259
2261 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2262
2264 bool zip( const QString &filename );
2265
2267 bool saveAuxiliaryStorage( const QString &filename = QString() );
2268
2270 void loadProjectFlags( const QDomDocument *doc );
2271
2273 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2274
2276 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2277 const QgsReadWriteContext &context,
2278 QMap<QString, QgsDataProvider *> &loadedProviders,
2279 QgsMapLayer::ReadFlags layerReadFlags,
2280 int totalProviderCount );
2281
2286 void releaseHandlesToProjectArchive();
2287
2288 Qgis::ProjectCapabilities mCapabilities;
2289
2290 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2291
2292 QString mErrorMessage;
2293
2294 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2295
2301 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2302
2303 QgsSnappingConfig mSnappingConfig;
2304 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2305
2306 QgsRelationManager *mRelationManager = nullptr;
2307
2308 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2309 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2310 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2311
2312 QgsBookmarkManager *mBookmarkManager = nullptr;
2313
2314 QgsSensorManager *mSensorManager = nullptr;
2315
2316 QgsProjectViewSettings *mViewSettings = nullptr;
2317
2318 QgsProjectStyleSettings *mStyleSettings = nullptr;
2319
2320 QgsProjectTimeSettings *mTimeSettings = nullptr;
2321
2322 QgsProjectElevationProperties *mElevationProperties = nullptr;
2323
2324 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2325
2326 QgsProjectGpsSettings *mGpsSettings = nullptr;
2327
2328 QgsLayerTree *mRootGroup = nullptr;
2329
2330 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2331
2332 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2333
2335 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2336
2337 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2338
2339 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2340
2341 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2342
2343 QVariantMap mCustomVariables;
2344
2345 std::unique_ptr<QgsArchive> mArchive;
2346
2347 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2348
2349 QFile mFile; // current physical project file
2350
2351 QString mOriginalPath;
2352
2353 QString mSaveUser; // last saved user.
2354 QString mSaveUserFull; // last saved user full name.
2355 QDateTime mSaveDateTime;
2356 QgsProjectVersion mSaveVersion;
2357
2362 QString mHomePath;
2363 mutable QString mCachedHomePath;
2364
2365 QColor mBackgroundColor;
2366 QColor mSelectionColor;
2367
2368 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2369 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2370
2371 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2372 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2373
2374 Qgis::ProjectFlags mFlags;
2376 bool mDirty = false; // project has been modified since it has been read or saved
2377 int mDirtyBlockCount = 0;
2378
2379 QgsPropertyCollection mDataDefinedServerProperties;
2380
2381 QgsCoordinateTransformContext mTransformContext;
2382
2383 QgsProjectMetadata mMetadata;
2384
2385 std::unique_ptr< QTranslator > mTranslator;
2386
2387 bool mIsBeingDeleted = false;
2388
2389 QgsSettings mSettings;
2390
2391 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2392
2393 int mBlockSnappingUpdates = 0;
2394
2395 QgsElevationShadingRenderer mElevationShadingRenderer;
2396
2397 friend class QgsApplication;
2398
2400
2401 // Required to avoid creating a new project in it's destructor
2403
2404 // Required by QGIS Server for switching the current project instance
2405 friend class QgsServer;
2406
2407 friend class TestQgsProject;
2408
2409 Q_DISABLE_COPY( QgsProject )
2410};
2411
2433class CORE_EXPORT QgsProjectDirtyBlocker
2434{
2435 public:
2436
2443 : mProject( project )
2444 {
2445 mProject->mDirtyBlockCount++;
2446 }
2447
2450
2453
2455 {
2456 mProject->mDirtyBlockCount--;
2457 }
2458
2459 private:
2460 QgsProject *mProject = nullptr;
2461
2462#ifdef SIP_RUN
2464#endif
2465};
2466
2472CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2473
2474
2475
2477#ifndef SIP_RUN
2478class GetNamedProjectColor : public QgsScopedExpressionFunction
2479{
2480 public:
2481 GetNamedProjectColor( const QgsProject *project );
2482
2487 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2488
2489 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2490 QgsScopedExpressionFunction *clone() const override;
2491
2492 private:
2493
2494 QHash< QString, QColor > mColors;
2495
2496};
2497
2498class GetSensorData : public QgsScopedExpressionFunction
2499{
2500 public:
2501 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2502 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2503 QgsScopedExpressionFunction *clone() const override;
2504
2505 private:
2506
2507 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2508};
2509#endif
2511
2512#endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
DistanceUnit
Units of distance.
Definition: qgis.h:3310
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition: qgis.h:3348
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgis.h:2717
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:2571
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 base class for spatial data provider implementations.
This class can render elevation shading on an image with different methods (eye dome lighting,...
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:2434
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2442
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:107
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:205
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:484
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
void readVersionMismatchOccurred(const QString &fileVersion)
Emitted when a project is read and the version of QGIS used to save the project differs from the curr...
void fileNameChanged()
Emitted when the file name of the project changes.
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted when a layer is being saved.
void areaUnitsChanged()
Emitted when the default area units changes.
Q_DECL_DEPRECATED void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the registry.
void crsChanged()
Emitted when the CRS of the project has changed.
Qgis::AreaUnit areaUnits() const
Convenience function to query default area measurement units for project.
Definition: qgsproject.h:716
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:139
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:1211
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:1155
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:1228
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:195
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.
Manages sensors.
The QgsServer class provides OGC web services.
Definition: qgsserver.h:49
This class is a composition of two QSettings instances:
Definition: qgssettings.h:63
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.
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 zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files, bool checkConsistency=true)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:37
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74
#define str(x)
Definition: qgis.cpp:38
#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