QGIS API Documentation 3.38.0-Grenoble (exported)
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 Q_PROPERTY( Qgis::TransactionMode transactionMode READ transactionMode WRITE setTransactionMode NOTIFY transactionModeChanged )
128
129 public:
130
131 // *INDENT-OFF*
132
142 {
143 NoProperty = 0,
144 AllProperties = 1,
145 WMSOnlineResource = 2,
146 };
147 // *INDENT-ON*
148
150 static QgsProject *instance();
151
160 static void setInstance( QgsProject *project ) ;
161
170 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
171
172 ~QgsProject() override;
173
182 void setTitle( const QString &title );
183
190 QString title() const;
191
198 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
199
208 Qgis::ProjectFlags flags() const { return mFlags; }
209
218 void setFlags( Qgis::ProjectFlags flags );
219
228 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
229
237 QString saveUser() const;
238
246 QString saveUserFullName() const;
247
253 QDateTime lastSaveDateTime() const;
254
260 QgsProjectVersion lastSaveVersion() const;
261
265 bool isDirty() const;
266
273 void setFileName( const QString &name );
274
281 QString fileName() const;
282
294 void setOriginalPath( const QString &path );
295
307 QString originalPath() const;
308
319 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
320
327 QgsProjectStorage *projectStorage() const;
328
333 QDateTime lastModified() const;
334
340 QString absoluteFilePath() const;
341
347 QString absolutePath() const;
348
353 QString baseName() const;
354
361 Qgis::FilePathType filePathStorage() const;
362
369 void setFilePathStorage( Qgis::FilePathType type );
370
384
403 QgsCoordinateReferenceSystem crs3D() const;
404
419 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
420
428 QString ellipsoid() const;
429
437 void setEllipsoid( const QString &ellipsoid );
438
457 QgsCoordinateReferenceSystem verticalCrs() const;
458
478 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
479
488 QgsCoordinateTransformContext transformContext() const;
489
498 void setTransformContext( const QgsCoordinateTransformContext &context );
499
504 void clear();
505
512 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
513
522 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
523
533 bool readLayer( const QDomNode &layerNode );
534
542 bool write( const QString &filename );
543
549 bool write();
550
562 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
563
575 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
576
587 bool writeEntry( const QString &scope, const QString &key, int value );
588
599 bool writeEntry( const QString &scope, const QString &key, const QString &value );
600
611 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
612
623 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
624
635 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
636
647 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
648
659 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
660
671 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
672
676 bool removeEntry( const QString &scope, const QString &key );
677
686 QStringList entryList( const QString &scope, const QString &key ) const;
687
696 QStringList subkeyList( const QString &scope, const QString &key ) const;
697
698 // TODO Now slightly broken since re-factoring. Won't print out top-level key
699 // and redundantly prints sub-keys.
700
704 void dumpProperties() const;
705
710 QgsPathResolver pathResolver() const;
711
717 QString writePath( const QString &filename ) const;
718
722 QString readPath( const QString &filename ) const;
723
725 QString error() const;
726
731 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
732
738 QString layerIsEmbedded( const QString &id ) const;
739
748 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
749 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
750
757 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
758
760 void setTopologicalEditing( bool enabled );
761
763 bool topologicalEditing() const;
764
770 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
771
777 void setDistanceUnits( Qgis::DistanceUnit unit );
778
783 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
784
790 void setAreaUnits( Qgis::AreaUnit unit );
791
804 QString homePath() const;
805
818 QString presetHomePath() const;
819
820 QgsRelationManager *relationManager() const;
821
827 const QgsLayoutManager *layoutManager() const SIP_SKIP;
828
833 QgsLayoutManager *layoutManager();
834
841 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
842
848 QgsMapViewsManager *viewsManager();
849
856 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
857
863 QgsBookmarkManager *bookmarkManager();
864
871 const QgsSensorManager *sensorManager() const SIP_SKIP;
872
878 QgsSensorManager *sensorManager();
879
887 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
888
895 QgsProjectViewSettings *viewSettings();
896
904 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
905
912 QgsProjectStyleSettings *styleSettings();
913
921 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
922
929 QgsProjectTimeSettings *timeSettings();
930
937 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
938
944 QgsProjectElevationProperties *elevationProperties();
945
952 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
953
959 QgsProjectDisplaySettings *displaySettings();
960
967 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
968
974 QgsProjectGpsSettings *gpsSettings();
975
979 QgsLayerTree *layerTreeRoot() const;
980
984 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
985
991
995 QgsAnnotationManager *annotationManager();
996
1000 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
1001
1006 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
1007
1012 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
1013
1018 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
1019
1027 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
1028
1038 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
1039
1046 Qgis::TransactionMode transactionMode() const;
1047
1057 bool setTransactionMode( Qgis::TransactionMode transactionMode );
1058
1066 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
1067
1075 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1076
1082 QgsVectorLayerEditBufferGroup *editBufferGroup();
1083
1089 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1090
1096 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1097
1098 QgsExpressionContext createExpressionContext() const override;
1099 QgsExpressionContextScope *createExpressionContextScope() const override;
1100
1105 QgsSnappingConfig snappingConfig() const;
1106
1111 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1112
1118 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1119
1125 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1126
1132 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1133
1139 QVariantMap customVariables() const;
1140
1145 void setCustomVariables( const QVariantMap &customVariables );
1146
1150 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1151
1155 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1156
1157 //
1158 // Functionality from QgsMapLayerRegistry
1159 //
1160
1164 QgsMapLayerStore *layerStore();
1165
1169 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1170
1172 int count() const;
1173
1175 int validCount() const;
1176
1184 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1185
1186#ifndef SIP_RUN
1187
1203 template <class T>
1204 T mapLayer( const QString &layerId ) const
1205 {
1206 return qobject_cast<T>( mapLayer( layerId ) );
1207 }
1208#endif
1209
1217 Q_INVOKABLE QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1218
1228 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1229
1230
1239 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1240
1244 bool isZipped() const;
1245
1246#ifndef SIP_RUN
1247
1258 template <typename T>
1259 QVector<T> layers() const
1260 {
1261 return mLayerStore->layers<T>();
1262 }
1263
1275 template <typename T>
1276 QVector<T> mapLayersByShortName( const QString &shortName ) const
1277 {
1278 QVector<T> layers;
1279 const auto constMapLayers { mLayerStore->layers<T>() };
1280 for ( const auto l : constMapLayers )
1281 {
1282 if ( ! l->serverProperties()->shortName().isEmpty() )
1283 {
1284 if ( l->serverProperties()->shortName() == shortName )
1285 layers << l;
1286 }
1287 else if ( l->name() == shortName )
1288 {
1289 layers << l;
1290 }
1291 }
1292 return layers;
1293 }
1294
1295#endif
1296
1321 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1322 bool addToLegend = true,
1323 bool takeOwnership SIP_PYARGREMOVE = true );
1324
1352 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1353 bool addToLegend = true,
1354 bool takeOwnership SIP_PYARGREMOVE = true );
1355
1369 void removeMapLayers( const QStringList &layerIds );
1370
1371 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1372
1386 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1387
1401 void removeMapLayer( const QString &layerId );
1402
1416 void removeMapLayer( QgsMapLayer *layer );
1417
1424 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1425
1437 QgsAnnotationLayer *mainAnnotationLayer();
1438
1449 void removeAllMapLayers();
1450
1456 void reloadAllLayers();
1457
1462 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1463
1475 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1476
1487 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1488
1493 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1494
1499 QgsAuxiliaryStorage *auxiliaryStorage();
1500
1509 QString createAttachedFile( const QString &nameTemplate );
1510
1517 QStringList attachedFiles() const;
1518
1526 bool removeAttachedFile( const QString &path );
1527
1536 QString attachmentIdentifier( const QString &attachedFile ) const;
1537
1544 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1545
1552 const QgsProjectMetadata &metadata() const;
1553
1560 void setMetadata( const QgsProjectMetadata &metadata );
1561
1570 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1571
1580 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1581
1588 void setProjectColors( const QgsNamedColorList &colors );
1589
1596 void setBackgroundColor( const QColor &color );
1597
1604 QColor backgroundColor() const;
1605
1612 void setSelectionColor( const QColor &color );
1613
1620 QColor selectionColor() const;
1621
1633 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1634
1646 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1647
1656 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1657
1666 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1667
1672 void generateTsFile( const QString &locale );
1673
1684 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1685
1695 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1696
1702 QgsElevationShadingRenderer elevationShadingRenderer() const;
1703
1709 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1710
1711#ifdef SIP_RUN
1712 SIP_PYOBJECT __repr__();
1713 % MethodCode
1714 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1715 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1716 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1717 % End
1718#endif
1719
1720 signals:
1721
1729 void cleared();
1730
1738
1742 void readProject( const QDomDocument & );
1743
1747 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1748
1752 void writeProject( QDomDocument & );
1753
1762 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1763
1772 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1773
1778
1784 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1785
1796 void readVersionMismatchOccurred( const QString &fileVersion );
1797
1803 void layerLoaded( int i, int n );
1804
1806 void loadingLayer( const QString &layerName );
1807
1814 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1815
1820 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1821
1824
1832
1837
1844
1849
1859
1871
1888
1895 void ellipsoidChanged( const QString &ellipsoid );
1896
1904
1912
1919
1923 void missingDatumTransforms( const QStringList &missingTransforms );
1924
1930
1937
1943
1949
1961
1966
1974
1982
1990
1998
1999 //
2000 // signals from QgsMapLayerRegistry
2001 //
2002
2010 void layersWillBeRemoved( const QStringList &layerIds );
2011
2019 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
2020
2030 void layerWillBeRemoved( const QString &layerId );
2031
2042
2049 void layersRemoved( const QStringList &layerIds );
2050
2059 void layerRemoved( const QString &layerId );
2060
2061 //TODO QGIS 4.0 - rename to past tense
2062
2070
2081 void layersAdded( const QList<QgsMapLayer *> &layers );
2082
2090
2099 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2100
2108 void isDirtyChanged( bool dirty );
2109
2117 void dirtySet();
2118
2127 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2128
2134 void elevationShadingRendererChanged();
2135
2136 public slots:
2137
2142 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2143
2144 // TODO QGIS 4.0 - rename b to dirty
2145
2152 void setDirty( bool b = true );
2153
2162 void setPresetHomePath( const QString &path );
2163
2173 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2174
2181 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2182
2189 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2190
2197 QgsPropertyCollection dataDefinedServerProperties() const;
2198
2215 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2216
2246 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2247
2264 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2265
2266 private slots:
2267 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2268 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2269 void cleanTransactionGroups( bool force = false );
2270 void updateTransactionGroups();
2271
2272 private:
2273
2274 static QgsProject *sProject;
2275
2276
2285 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2286
2291 void setError( const QString &errorMessage ) SIP_SKIP;
2292
2297 void clearError() SIP_SKIP;
2298
2308 bool addLayer( const QDomElement &layerElem,
2309 QList<QDomNode> &brokenNodes,
2310 QgsReadWriteContext &context,
2311 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2312 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2313
2317 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2318
2324 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2325
2330 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2331
2333 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2334
2336 bool writeProjectFile( const QString &filename );
2337
2339 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2340
2342 bool zip( const QString &filename );
2343
2345 bool saveAuxiliaryStorage( const QString &filename = QString() );
2346
2348 void loadProjectFlags( const QDomDocument *doc );
2349
2351 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2352
2354 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2355 const QgsReadWriteContext &context,
2356 QMap<QString, QgsDataProvider *> &loadedProviders,
2357 QgsMapLayer::ReadFlags layerReadFlags,
2358 int totalProviderCount );
2359
2364 void releaseHandlesToProjectArchive();
2365
2366 bool rebuildCrs3D( QString *error = nullptr );
2367
2368 Qgis::ProjectCapabilities mCapabilities;
2369
2370 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2371
2372 QString mErrorMessage;
2373
2374 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2375
2381 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2382
2383 QgsSnappingConfig mSnappingConfig;
2384 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2385
2386 QgsRelationManager *mRelationManager = nullptr;
2387
2388 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2389 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2390 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2391
2392 QgsBookmarkManager *mBookmarkManager = nullptr;
2393
2394 QgsSensorManager *mSensorManager = nullptr;
2395
2396 QgsProjectViewSettings *mViewSettings = nullptr;
2397
2398 QgsProjectStyleSettings *mStyleSettings = nullptr;
2399
2400 QgsProjectTimeSettings *mTimeSettings = nullptr;
2401
2402 QgsProjectElevationProperties *mElevationProperties = nullptr;
2403
2404 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2405
2406 QgsProjectGpsSettings *mGpsSettings = nullptr;
2407
2408 QgsLayerTree *mRootGroup = nullptr;
2409
2410 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2411
2412 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2413
2415 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2416
2417 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2418
2419 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2420
2421 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2422
2423 QVariantMap mCustomVariables;
2424
2425 std::unique_ptr<QgsArchive> mArchive;
2426
2427 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2428
2429 QFile mFile; // current physical project file
2430
2431 QString mOriginalPath;
2432
2433 QString mSaveUser; // last saved user.
2434 QString mSaveUserFull; // last saved user full name.
2435 QDateTime mSaveDateTime;
2436 QgsProjectVersion mSaveVersion;
2437
2442 QString mHomePath;
2443 mutable QString mCachedHomePath;
2444
2445 QColor mBackgroundColor;
2446 QColor mSelectionColor;
2447
2448 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2449 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2450
2451 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2452 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2453
2454 Qgis::ProjectFlags mFlags;
2456 QgsCoordinateReferenceSystem mVerticalCrs;
2458
2459 bool mDirty = false; // project has been modified since it has been read or saved
2460 int mDirtyBlockCount = 0;
2461
2462 QgsPropertyCollection mDataDefinedServerProperties;
2463
2464 QgsCoordinateTransformContext mTransformContext;
2465
2466 QgsProjectMetadata mMetadata;
2467
2468 std::unique_ptr< QTranslator > mTranslator;
2469
2470 bool mIsBeingDeleted = false;
2471
2472 QgsSettings mSettings;
2473
2474 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2475
2476 bool mBlockChangeSignalsDuringClear = false;
2477 int mBlockSnappingUpdates = 0;
2478
2479 QgsElevationShadingRenderer mElevationShadingRenderer;
2480
2481 friend class QgsApplication;
2482
2484
2485 // Required to avoid creating a new project in it's destructor
2487
2488 // Required by QGIS Server for switching the current project instance
2489 friend class QgsServer;
2490
2491 friend class TestQgsProject;
2492
2493 Q_DISABLE_COPY( QgsProject )
2494};
2495
2517class CORE_EXPORT QgsProjectDirtyBlocker
2518{
2519 public:
2520
2527 : mProject( project )
2528 {
2529 mProject->mDirtyBlockCount++;
2530 }
2531
2534
2537
2539 {
2540 mProject->mDirtyBlockCount--;
2541 }
2542
2543 private:
2544 QgsProject *mProject = nullptr;
2545
2546#ifdef SIP_RUN
2548#endif
2549};
2550
2556CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2557
2558
2559
2561#ifndef SIP_RUN
2562class GetNamedProjectColor : public QgsScopedExpressionFunction
2563{
2564 public:
2565 GetNamedProjectColor( const QgsProject *project );
2566
2571 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2572
2573 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2574 QgsScopedExpressionFunction *clone() const override;
2575
2576 private:
2577
2578 QHash< QString, QColor > mColors;
2579
2580};
2581
2582class GetSensorData : public QgsScopedExpressionFunction
2583{
2584 public:
2585 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2586 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2587 QgsScopedExpressionFunction *clone() const override;
2588
2589 private:
2590
2591 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2592};
2593#endif
2595
2596#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< ProjectCapability > ProjectCapabilities
Flags which control project capabilities.
Definition qgis.h:3750
DistanceUnit
Units of distance.
Definition qgis.h:4358
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4396
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3513
QFlags< ProjectFlag > ProjectFlags
Definition qgis.h:3520
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:208
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:783
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:142
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 crs3DChanged()
Emitted when the crs3D() of the project has 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 transactionModeChanged()
Emitted when the transaction mode has changed.
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:198
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 verticalCrsChanged()
Emitted when the verticalCrs() of the project has changed.
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