QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
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
1695
1699 void readProject( const QDomDocument & );
1700
1704 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1705
1709 void writeProject( QDomDocument & );
1710
1719 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1720
1729 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1730
1735
1741 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1742
1753 void readVersionMismatchOccurred( const QString &fileVersion );
1754
1760 void layerLoaded( int i, int n );
1761
1763 void loadingLayer( const QString &layerName );
1764
1771 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1772
1777 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1778
1781
1789
1794
1801
1807
1814
1822 void ellipsoidChanged( const QString &ellipsoid );
1823
1831
1839
1847
1852 void missingDatumTransforms( const QStringList &missingTransforms );
1853
1861
1868
1875
1888
1894
1902
1910
1918
1926
1927 //
1928 // signals from QgsMapLayerRegistry
1929 //
1930
1938 void layersWillBeRemoved( const QStringList &layerIds );
1939
1947 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1948
1958 void layerWillBeRemoved( const QString &layerId );
1959
1970
1977 void layersRemoved( const QStringList &layerIds );
1978
1987 void layerRemoved( const QString &layerId );
1988
1989 //TODO QGIS 4.0 - rename to past tense
1990
1998
2009 void layersAdded( const QList<QgsMapLayer *> &layers );
2010
2018
2027 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2028
2036 void isDirtyChanged( bool dirty );
2037
2045 void dirtySet();
2046
2055 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2056
2062 void elevationShadingRendererChanged();
2063
2064 public slots:
2065
2071 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2072
2073 // TODO QGIS 4.0 - rename b to dirty
2074
2082 void setDirty( bool b = true );
2083
2092 void setPresetHomePath( const QString &path );
2093
2103 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2104
2111 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2112
2119 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2120
2127 QgsPropertyCollection dataDefinedServerProperties() const;
2128
2145 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2146
2176 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2177
2194 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2195
2196 private slots:
2197 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2198 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2199 void cleanTransactionGroups( bool force = false );
2200 void updateTransactionGroups();
2201
2202 private:
2203
2204 static QgsProject *sProject;
2205
2206
2215 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2216
2221 void setError( const QString &errorMessage ) SIP_SKIP;
2222
2227 void clearError() SIP_SKIP;
2228
2238 bool addLayer( const QDomElement &layerElem,
2239 QList<QDomNode> &brokenNodes,
2240 QgsReadWriteContext &context,
2241 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2242 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2243
2247 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2248
2254 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2255
2260 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2261
2263 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2264
2266 bool writeProjectFile( const QString &filename );
2267
2269 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2270
2272 bool zip( const QString &filename );
2273
2275 bool saveAuxiliaryStorage( const QString &filename = QString() );
2276
2278 void loadProjectFlags( const QDomDocument *doc );
2279
2281 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2282
2284 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2285 const QgsReadWriteContext &context,
2286 QMap<QString, QgsDataProvider *> &loadedProviders,
2287 QgsMapLayer::ReadFlags layerReadFlags,
2288 int totalProviderCount );
2289
2294 void releaseHandlesToProjectArchive();
2295
2296 Qgis::ProjectCapabilities mCapabilities;
2297
2298 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2299
2300 QString mErrorMessage;
2301
2302 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2303
2309 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2310
2311 QgsSnappingConfig mSnappingConfig;
2312 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2313
2314 QgsRelationManager *mRelationManager = nullptr;
2315
2316 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2317 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2318 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2319
2320 QgsBookmarkManager *mBookmarkManager = nullptr;
2321
2322 QgsSensorManager *mSensorManager = nullptr;
2323
2324 QgsProjectViewSettings *mViewSettings = nullptr;
2325
2326 QgsProjectStyleSettings *mStyleSettings = nullptr;
2327
2328 QgsProjectTimeSettings *mTimeSettings = nullptr;
2329
2330 QgsProjectElevationProperties *mElevationProperties = nullptr;
2331
2332 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2333
2334 QgsProjectGpsSettings *mGpsSettings = nullptr;
2335
2336 QgsLayerTree *mRootGroup = nullptr;
2337
2338 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2339
2340 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2341
2343 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2344
2345 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2346
2347 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2348
2349 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2350
2351 QVariantMap mCustomVariables;
2352
2353 std::unique_ptr<QgsArchive> mArchive;
2354
2355 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2356
2357 QFile mFile; // current physical project file
2358
2359 QString mOriginalPath;
2360
2361 QString mSaveUser; // last saved user.
2362 QString mSaveUserFull; // last saved user full name.
2363 QDateTime mSaveDateTime;
2364 QgsProjectVersion mSaveVersion;
2365
2370 QString mHomePath;
2371 mutable QString mCachedHomePath;
2372
2373 QColor mBackgroundColor;
2374 QColor mSelectionColor;
2375
2376 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2377 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2378
2379 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2380 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2381
2382 Qgis::ProjectFlags mFlags;
2384 bool mDirty = false; // project has been modified since it has been read or saved
2385 int mDirtyBlockCount = 0;
2386
2387 QgsPropertyCollection mDataDefinedServerProperties;
2388
2389 QgsCoordinateTransformContext mTransformContext;
2390
2391 QgsProjectMetadata mMetadata;
2392
2393 std::unique_ptr< QTranslator > mTranslator;
2394
2395 bool mIsBeingDeleted = false;
2396
2397 QgsSettings mSettings;
2398
2399 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2400
2401 int mBlockSnappingUpdates = 0;
2402
2403 QgsElevationShadingRenderer mElevationShadingRenderer;
2404
2405 friend class QgsApplication;
2406
2408
2409 // Required to avoid creating a new project in it's destructor
2411
2412 // Required by QGIS Server for switching the current project instance
2413 friend class QgsServer;
2414
2415 friend class TestQgsProject;
2416
2417 Q_DISABLE_COPY( QgsProject )
2418};
2419
2441class CORE_EXPORT QgsProjectDirtyBlocker
2442{
2443 public:
2444
2451 : mProject( project )
2452 {
2453 mProject->mDirtyBlockCount++;
2454 }
2455
2458
2461
2463 {
2464 mProject->mDirtyBlockCount--;
2465 }
2466
2467 private:
2468 QgsProject *mProject = nullptr;
2469
2470#ifdef SIP_RUN
2472#endif
2473};
2474
2480CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2481
2482
2483
2485#ifndef SIP_RUN
2486class GetNamedProjectColor : public QgsScopedExpressionFunction
2487{
2488 public:
2489 GetNamedProjectColor( const QgsProject *project );
2490
2495 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2496
2497 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2498 QgsScopedExpressionFunction *clone() const override;
2499
2500 private:
2501
2502 QHash< QString, QColor > mColors;
2503
2504};
2505
2506class GetSensorData : public QgsScopedExpressionFunction
2507{
2508 public:
2509 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2510 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2511 QgsScopedExpressionFunction *clone() const override;
2512
2513 private:
2514
2515 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2516};
2517#endif
2519
2520#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DistanceUnit
Units of distance.
Definition qgis.h:3496
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:3534
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:2757
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.
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:74
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.
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
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.
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 aboutToBeCleared()
Emitted when the project is about to be cleared.
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
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.
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.
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,...
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.
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.
#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
QgsProjectVersion getVersion(const QDomDocument &doc)
Returns the version string found in the given DOM document.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs