QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
130 // *INDENT-OFF*
131
141 {
142 NoProperty = 0,
143 AllProperties = 1,
144 WMSOnlineResource = 2,
145 };
146 // *INDENT-ON*
147
149 static QgsProject *instance();
150
159 static void setInstance( QgsProject *project ) ;
160
169 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
170
171 ~QgsProject() override;
172
181 void setTitle( const QString &title );
182
189 QString title() const;
190
197 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
198
207 Qgis::ProjectFlags flags() const { return mFlags; }
208
217 void setFlags( Qgis::ProjectFlags flags );
218
227 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
228
236 QString saveUser() const;
237
245 QString saveUserFullName() const;
246
252 QDateTime lastSaveDateTime() const;
253
259 QgsProjectVersion lastSaveVersion() const;
260
264 bool isDirty() const;
265
272 void setFileName( const QString &name );
273
280 QString fileName() const;
281
293 void setOriginalPath( const QString &path );
294
306 QString originalPath() const;
307
318 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
319
326 QgsProjectStorage *projectStorage() const;
327
332 QDateTime lastModified() const;
333
339 QString absoluteFilePath() const;
340
346 QString absolutePath() const;
347
352 QString baseName() const;
353
360 Qgis::FilePathType filePathStorage() const;
361
368 void setFilePathStorage( Qgis::FilePathType type );
369
376
385 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
386
392 QString ellipsoid() const;
393
399 void setEllipsoid( const QString &ellipsoid );
400
401
410 QgsCoordinateTransformContext transformContext() const;
411
420 void setTransformContext( const QgsCoordinateTransformContext &context );
421
426 void clear();
427
434 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
435
444 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
445
455 bool readLayer( const QDomNode &layerNode );
456
464 bool write( const QString &filename );
465
471 bool write();
472
484 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
485
497 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
498
509 bool writeEntry( const QString &scope, const QString &key, int value );
510
521 bool writeEntry( const QString &scope, const QString &key, const QString &value );
522
533 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
534
545 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
546
557 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
558
569 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
570
581 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
582
593 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
594
598 bool removeEntry( const QString &scope, const QString &key );
599
608 QStringList entryList( const QString &scope, const QString &key ) const;
609
618 QStringList subkeyList( const QString &scope, const QString &key ) const;
619
620 // TODO Now slightly broken since re-factoring. Won't print out top-level key
621 // and redundantly prints sub-keys.
622
626 void dumpProperties() const;
627
632 QgsPathResolver pathResolver() const;
633
639 QString writePath( const QString &filename ) const;
640
644 QString readPath( const QString &filename ) const;
645
647 QString error() const;
648
653 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
654
660 QString layerIsEmbedded( const QString &id ) const;
661
670 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
671 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
672
679 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
680
682 void setTopologicalEditing( bool enabled );
683
685 bool topologicalEditing() const;
686
692 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
693
699 void setDistanceUnits( Qgis::DistanceUnit unit );
700
705 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
706
712 void setAreaUnits( Qgis::AreaUnit unit );
713
726 QString homePath() const;
727
740 QString presetHomePath() const;
741
742 QgsRelationManager *relationManager() const;
743
749 const QgsLayoutManager *layoutManager() const SIP_SKIP;
750
755 QgsLayoutManager *layoutManager();
756
763 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
764
770 QgsMapViewsManager *viewsManager();
771
778 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
779
785 QgsBookmarkManager *bookmarkManager();
786
793 const QgsSensorManager *sensorManager() const SIP_SKIP;
794
800 QgsSensorManager *sensorManager();
801
809 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
810
817 QgsProjectViewSettings *viewSettings();
818
826 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
827
834 QgsProjectStyleSettings *styleSettings();
835
843 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
844
851 QgsProjectTimeSettings *timeSettings();
852
859 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
860
866 QgsProjectElevationProperties *elevationProperties();
867
874 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
875
881 QgsProjectDisplaySettings *displaySettings();
882
889 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
890
896 QgsProjectGpsSettings *gpsSettings();
897
901 QgsLayerTree *layerTreeRoot() const;
902
906 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
907
913
917 QgsAnnotationManager *annotationManager();
918
922 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
923
928 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
929
934 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
935
940 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
941
949 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
950
960 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
961
968 Qgis::TransactionMode transactionMode() const;
969
979 bool setTransactionMode( Qgis::TransactionMode transactionMode );
980
988 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
989
997 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
998
1004 QgsVectorLayerEditBufferGroup *editBufferGroup();
1005
1011 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1012
1018 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1019
1020 QgsExpressionContext createExpressionContext() const override;
1021 QgsExpressionContextScope *createExpressionContextScope() const override;
1022
1027 QgsSnappingConfig snappingConfig() const;
1028
1033 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1034
1040 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1041
1047 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1048
1054 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1055
1061 QVariantMap customVariables() const;
1062
1067 void setCustomVariables( const QVariantMap &customVariables );
1068
1072 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1073
1077 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1078
1079 //
1080 // Functionality from QgsMapLayerRegistry
1081 //
1082
1086 QgsMapLayerStore *layerStore();
1087
1091 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1092
1094 int count() const;
1095
1097 int validCount() const;
1098
1106 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1107
1108#ifndef SIP_RUN
1109
1125 template <class T>
1126 T mapLayer( const QString &layerId ) const
1127 {
1128 return qobject_cast<T>( mapLayer( layerId ) );
1129 }
1130#endif
1131
1139 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1140
1150 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1151
1152
1161 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1162
1166 bool isZipped() const;
1167
1168#ifndef SIP_RUN
1169
1180 template <typename T>
1181 QVector<T> layers() const
1182 {
1183 return mLayerStore->layers<T>();
1184 }
1185
1197 template <typename T>
1198 QVector<T> mapLayersByShortName( const QString &shortName ) const
1199 {
1200 QVector<T> layers;
1201 const auto constMapLayers { mLayerStore->layers<T>() };
1202 for ( const auto l : constMapLayers )
1203 {
1204 if ( ! l->shortName().isEmpty() )
1205 {
1206 if ( l->shortName() == shortName )
1207 layers << l;
1208 }
1209 else if ( l->name() == shortName )
1210 {
1211 layers << l;
1212 }
1213 }
1214 return layers;
1215 }
1216
1217#endif
1218
1243 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1244 bool addToLegend = true,
1245 bool takeOwnership SIP_PYARGREMOVE = true );
1246
1274 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1275 bool addToLegend = true,
1276 bool takeOwnership SIP_PYARGREMOVE = true );
1277
1291 void removeMapLayers( const QStringList &layerIds );
1292
1293 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1294
1308 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1309
1323 void removeMapLayer( const QString &layerId );
1324
1338 void removeMapLayer( QgsMapLayer *layer );
1339
1346 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1347
1359 QgsAnnotationLayer *mainAnnotationLayer();
1360
1371 void removeAllMapLayers();
1372
1378 void reloadAllLayers();
1379
1384 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1385
1397 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1398
1409 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1410
1415 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1416
1421 QgsAuxiliaryStorage *auxiliaryStorage();
1422
1431 QString createAttachedFile( const QString &nameTemplate );
1432
1439 QStringList attachedFiles() const;
1440
1448 bool removeAttachedFile( const QString &path );
1449
1458 QString attachmentIdentifier( const QString &attachedFile ) const;
1459
1466 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1467
1474 const QgsProjectMetadata &metadata() const;
1475
1482 void setMetadata( const QgsProjectMetadata &metadata );
1483
1492 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1493
1502 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1503
1510 void setProjectColors( const QgsNamedColorList &colors );
1511
1518 void setBackgroundColor( const QColor &color );
1519
1526 QColor backgroundColor() const;
1527
1534 void setSelectionColor( const QColor &color );
1535
1542 QColor selectionColor() const;
1543
1555 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1556
1568 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1569
1578 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1579
1588 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1589
1594 void generateTsFile( const QString &locale );
1595
1606 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1607
1617 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1618
1624 QgsElevationShadingRenderer elevationShadingRenderer() const;
1625
1631 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1632
1633#ifdef SIP_RUN
1634 SIP_PYOBJECT __repr__();
1635 % MethodCode
1636 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1637 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1638 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1639 % End
1640#endif
1641
1642 signals:
1643
1651 void cleared();
1652
1660
1664 void readProject( const QDomDocument & );
1665
1669 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1670
1674 void writeProject( QDomDocument & );
1675
1684 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1685
1694 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1695
1700
1706 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1707
1718 void readVersionMismatchOccurred( const QString &fileVersion );
1719
1725 void layerLoaded( int i, int n );
1726
1728 void loadingLayer( const QString &layerName );
1729
1736 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1737
1742 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1743
1746
1754
1759
1766
1771
1777
1784 void ellipsoidChanged( const QString &ellipsoid );
1785
1793
1801
1808
1812 void missingDatumTransforms( const QStringList &missingTransforms );
1813
1820
1826
1832
1844
1849
1857
1865
1873
1881
1882 //
1883 // signals from QgsMapLayerRegistry
1884 //
1885
1893 void layersWillBeRemoved( const QStringList &layerIds );
1894
1902 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1903
1913 void layerWillBeRemoved( const QString &layerId );
1914
1925
1932 void layersRemoved( const QStringList &layerIds );
1933
1942 void layerRemoved( const QString &layerId );
1943
1944 //TODO QGIS 4.0 - rename to past tense
1945
1953
1964 void layersAdded( const QList<QgsMapLayer *> &layers );
1965
1973
1982 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1983
1991 void isDirtyChanged( bool dirty );
1992
2000 void dirtySet();
2001
2010 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2011
2017 void elevationShadingRendererChanged();
2018
2019 public slots:
2020
2025 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2026
2027 // TODO QGIS 4.0 - rename b to dirty
2028
2035 void setDirty( bool b = true );
2036
2045 void setPresetHomePath( const QString &path );
2046
2056 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2057
2064 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2065
2072 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2073
2080 QgsPropertyCollection dataDefinedServerProperties() const;
2081
2098 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2099
2129 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2130
2147 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2148
2149 private slots:
2150 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2151 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2152 void cleanTransactionGroups( bool force = false );
2153 void updateTransactionGroups();
2154
2155 private:
2156
2157 static QgsProject *sProject;
2158
2159
2168 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2169
2174 void setError( const QString &errorMessage ) SIP_SKIP;
2175
2180 void clearError() SIP_SKIP;
2181
2191 bool addLayer( const QDomElement &layerElem,
2192 QList<QDomNode> &brokenNodes,
2193 QgsReadWriteContext &context,
2194 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2195 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2196
2200 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2201
2207 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2208
2213 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2214
2216 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2217
2219 bool writeProjectFile( const QString &filename );
2220
2222 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2223
2225 bool zip( const QString &filename );
2226
2228 bool saveAuxiliaryStorage( const QString &filename = QString() );
2229
2231 void loadProjectFlags( const QDomDocument *doc );
2232
2234 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2235
2237 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2238 const QgsReadWriteContext &context,
2239 QMap<QString, QgsDataProvider *> &loadedProviders,
2240 QgsMapLayer::ReadFlags layerReadFlags,
2241 int totalProviderCount );
2242
2247 void releaseHandlesToProjectArchive();
2248
2249 Qgis::ProjectCapabilities mCapabilities;
2250
2251 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2252
2253 QString mErrorMessage;
2254
2255 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2256
2262 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2263
2264 QgsSnappingConfig mSnappingConfig;
2265 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2266
2267 QgsRelationManager *mRelationManager = nullptr;
2268
2269 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2270 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2271 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2272
2273 QgsBookmarkManager *mBookmarkManager = nullptr;
2274
2275 QgsSensorManager *mSensorManager = nullptr;
2276
2277 QgsProjectViewSettings *mViewSettings = nullptr;
2278
2279 QgsProjectStyleSettings *mStyleSettings = nullptr;
2280
2281 QgsProjectTimeSettings *mTimeSettings = nullptr;
2282
2283 QgsProjectElevationProperties *mElevationProperties = nullptr;
2284
2285 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2286
2287 QgsProjectGpsSettings *mGpsSettings = nullptr;
2288
2289 QgsLayerTree *mRootGroup = nullptr;
2290
2291 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2292
2293 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2294
2296 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2297
2298 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2299
2300 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2301
2302 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2303
2304 QVariantMap mCustomVariables;
2305
2306 std::unique_ptr<QgsArchive> mArchive;
2307
2308 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2309
2310 QFile mFile; // current physical project file
2311
2312 QString mOriginalPath;
2313
2314 QString mSaveUser; // last saved user.
2315 QString mSaveUserFull; // last saved user full name.
2316 QDateTime mSaveDateTime;
2317 QgsProjectVersion mSaveVersion;
2318
2323 QString mHomePath;
2324 mutable QString mCachedHomePath;
2325
2326 QColor mBackgroundColor;
2327 QColor mSelectionColor;
2328
2329 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2330 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2331
2332 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2333 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2334
2335 Qgis::ProjectFlags mFlags;
2337 bool mDirty = false; // project has been modified since it has been read or saved
2338 int mDirtyBlockCount = 0;
2339
2340 QgsPropertyCollection mDataDefinedServerProperties;
2341
2342 QgsCoordinateTransformContext mTransformContext;
2343
2344 QgsProjectMetadata mMetadata;
2345
2346 std::unique_ptr< QTranslator > mTranslator;
2347
2348 bool mIsBeingDeleted = false;
2349
2350 QgsSettings mSettings;
2351
2352 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2353
2354 int mBlockSnappingUpdates = 0;
2355
2356 QgsElevationShadingRenderer mElevationShadingRenderer;
2357
2358 friend class QgsApplication;
2359
2361
2362 // Required to avoid creating a new project in it's destructor
2364
2365 // Required by QGIS Server for switching the current project instance
2366 friend class QgsServer;
2367
2368 friend class TestQgsProject;
2369
2370 Q_DISABLE_COPY( QgsProject )
2371};
2372
2394class CORE_EXPORT QgsProjectDirtyBlocker
2395{
2396 public:
2397
2404 : mProject( project )
2405 {
2406 mProject->mDirtyBlockCount++;
2407 }
2408
2411
2414
2416 {
2417 mProject->mDirtyBlockCount--;
2418 }
2419
2420 private:
2421 QgsProject *mProject = nullptr;
2422
2423#ifdef SIP_RUN
2425#endif
2426};
2427
2433CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2434
2435
2436
2438#ifndef SIP_RUN
2439class GetNamedProjectColor : public QgsScopedExpressionFunction
2440{
2441 public:
2442 GetNamedProjectColor( const QgsProject *project );
2443
2448 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2449
2450 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2451 QgsScopedExpressionFunction *clone() const override;
2452
2453 private:
2454
2455 QHash< QString, QColor > mColors;
2456
2457};
2458
2459class GetSensorData : public QgsScopedExpressionFunction
2460{
2461 public:
2462 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2463 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2464 QgsScopedExpressionFunction *clone() const override;
2465
2466 private:
2467
2468 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2469};
2470#endif
2472
2473#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DistanceUnit
Units of distance.
Definition qgis.h:4062
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4100
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3285
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:35
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:75
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:207
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:705
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.
DataDefinedServerProperty
Data defined properties.
Definition qgsproject.h:141
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...
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:197
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:64
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_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#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