QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
1119 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1120
1126 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1127
1133 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1134
1140 QVariantMap customVariables() const;
1141
1146 void setCustomVariables( const QVariantMap &customVariables );
1147
1151 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1152
1156 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1157
1158 //
1159 // Functionality from QgsMapLayerRegistry
1160 //
1161
1165 QgsMapLayerStore *layerStore();
1166
1170 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1171
1173 int count() const;
1174
1176 int validCount() const;
1177
1185 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1186
1187#ifndef SIP_RUN
1188
1204 template <class T>
1205 T mapLayer( const QString &layerId ) const
1206 {
1207 return qobject_cast<T>( mapLayer( layerId ) );
1208 }
1209#endif
1210
1218 Q_INVOKABLE QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1219
1229 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1230
1231
1240 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1241
1245 bool isZipped() const;
1246
1247#ifndef SIP_RUN
1248
1259 template <typename T>
1260 QVector<T> layers() const
1261 {
1262 return mLayerStore->layers<T>();
1263 }
1264
1276 template <typename T>
1277 QVector<T> mapLayersByShortName( const QString &shortName ) const
1278 {
1279 QVector<T> layers;
1280 const auto constMapLayers { mLayerStore->layers<T>() };
1281 for ( const auto l : constMapLayers )
1282 {
1283 if ( ! l->serverProperties()->shortName().isEmpty() )
1284 {
1285 if ( l->serverProperties()->shortName() == shortName )
1286 layers << l;
1287 }
1288 else if ( l->name() == shortName )
1289 {
1290 layers << l;
1291 }
1292 }
1293 return layers;
1294 }
1295
1296#endif
1297
1322 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1323 bool addToLegend = true,
1324 bool takeOwnership SIP_PYARGREMOVE = true );
1325
1353 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1354 bool addToLegend = true,
1355 bool takeOwnership SIP_PYARGREMOVE = true );
1356
1370 void removeMapLayers( const QStringList &layerIds );
1371
1372 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1373
1387 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1388
1402 void removeMapLayer( const QString &layerId );
1403
1417 void removeMapLayer( QgsMapLayer *layer );
1418
1425 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1426
1438 QgsAnnotationLayer *mainAnnotationLayer();
1439
1450 void removeAllMapLayers();
1451
1457 void reloadAllLayers();
1458
1463 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1464
1476 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1477
1488 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1489
1494 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1495
1500 QgsAuxiliaryStorage *auxiliaryStorage();
1501
1510 QString createAttachedFile( const QString &nameTemplate );
1511
1518 QStringList attachedFiles() const;
1519
1527 bool removeAttachedFile( const QString &path );
1528
1537 QString attachmentIdentifier( const QString &attachedFile ) const;
1538
1545 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1546
1553 const QgsProjectMetadata &metadata() const;
1554
1561 void setMetadata( const QgsProjectMetadata &metadata );
1562
1571 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1572
1581 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1582
1589 void setProjectColors( const QgsNamedColorList &colors );
1590
1597 void setBackgroundColor( const QColor &color );
1598
1605 QColor backgroundColor() const;
1606
1613 void setSelectionColor( const QColor &color );
1614
1621 QColor selectionColor() const;
1622
1634 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1635
1647 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1648
1657 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1658
1667 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1668
1673 void generateTsFile( const QString &locale );
1674
1675 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1676
1686 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1687
1693 QgsElevationShadingRenderer elevationShadingRenderer() const;
1694
1700 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1701
1710 bool loadFunctionsFromProject( bool force = false ) SIP_SKIP;
1711
1719 void cleanFunctionsFromProject() SIP_SKIP;
1720
1721
1722#ifdef SIP_RUN
1723 SIP_PYOBJECT __repr__();
1724 % MethodCode
1725 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1726 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() ); // skip-keyword-check
1727 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1728 % End
1729#endif
1730
1731 signals:
1732
1740 void cleared();
1741
1749
1753 void readProject( const QDomDocument &document );
1754
1758 void readProjectWithContext( const QDomDocument &document, QgsReadWriteContext &context );
1759
1763 void writeProject( QDomDocument &document );
1764
1773 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1774
1783 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1784
1789
1795 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString &warning ) SIP_DEPRECATED;
1796
1807 void readVersionMismatchOccurred( const QString &fileVersion );
1808
1814 void layerLoaded( int i, int n );
1815
1817 void loadingLayer( const QString &layerName );
1818
1825 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1826
1831 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1832
1835
1843
1848
1855
1860
1870
1882
1899
1906 void ellipsoidChanged( const QString &ellipsoid );
1907
1915
1923
1930
1934 void missingDatumTransforms( const QStringList &missingTransforms );
1935
1941
1948
1954
1960
1972
1977
1985
1993
2001
2009
2010 //
2011 // signals from QgsMapLayerRegistry
2012 //
2013
2021 void layersWillBeRemoved( const QStringList &layerIds );
2022
2030 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
2031
2041 void layerWillBeRemoved( const QString &layerId );
2042
2053
2060 void layersRemoved( const QStringList &layerIds );
2061
2070 void layerRemoved( const QString &layerId );
2071
2072 //TODO QGIS 4.0 - rename to past tense
2073
2081
2092 void layersAdded( const QList<QgsMapLayer *> &layers );
2093
2101
2110 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2111
2119 void isDirtyChanged( bool dirty );
2120
2128 void dirtySet();
2129
2138 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2139
2145 void elevationShadingRendererChanged();
2146
2147 public slots:
2148
2153 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2154
2155 // TODO QGIS 4.0 - rename b to dirty
2156
2163 void setDirty( bool b = true );
2164
2173 void setPresetHomePath( const QString &path );
2174
2184 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2185
2192 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2193
2200 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2201
2208 QgsPropertyCollection dataDefinedServerProperties() const;
2209
2226 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2227
2257 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2258
2275 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2276
2277 private slots:
2278 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2279 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2280 void cleanTransactionGroups( bool force = false );
2281 void updateTransactionGroups();
2282
2283 private:
2284
2285 static QgsProject *sProject;
2286
2287
2296 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2297
2302 void setError( const QString &errorMessage ) SIP_SKIP;
2303
2308 void clearError() SIP_SKIP;
2309
2319 bool addLayer( const QDomElement &layerElem,
2320 QList<QDomNode> &brokenNodes,
2321 QgsReadWriteContext &context,
2322 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2323 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2324
2328 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2329
2335 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2336
2341 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2342
2344 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2345
2347 bool writeProjectFile( const QString &filename );
2348
2350 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2351
2353 bool zip( const QString &filename );
2354
2356 bool saveAuxiliaryStorage( const QString &filename = QString() );
2357
2359 void loadProjectFlags( const QDomDocument *doc );
2360
2362 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2363
2365 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2366 const QgsReadWriteContext &context,
2367 QMap<QString, QgsDataProvider *> &loadedProviders,
2368 QgsMapLayer::ReadFlags layerReadFlags,
2369 int totalProviderCount );
2370
2375 void releaseHandlesToProjectArchive();
2376
2377 bool rebuildCrs3D( QString *error = nullptr );
2378
2379 Qgis::ProjectCapabilities mCapabilities;
2380
2381 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2382
2383 QString mErrorMessage;
2384
2385 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2386
2392 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2393
2394 QgsSnappingConfig mSnappingConfig;
2395 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2396
2397 QgsRelationManager *mRelationManager = nullptr;
2398
2399 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2400 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2401 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2402
2403 QgsBookmarkManager *mBookmarkManager = nullptr;
2404
2405 QgsSensorManager *mSensorManager = nullptr;
2406
2407 QgsProjectViewSettings *mViewSettings = nullptr;
2408
2409 QgsProjectStyleSettings *mStyleSettings = nullptr;
2410
2411 QgsProjectTimeSettings *mTimeSettings = nullptr;
2412
2413 QgsProjectElevationProperties *mElevationProperties = nullptr;
2414
2415 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2416
2417 QgsProjectGpsSettings *mGpsSettings = nullptr;
2418
2419 QgsLayerTree *mRootGroup = nullptr;
2420
2421 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2422
2423 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2424
2426 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2427
2428 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2429
2430 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2431
2432 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2433
2434 QVariantMap mCustomVariables;
2435
2436 std::unique_ptr<QgsArchive> mArchive;
2437
2438 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2439
2440 QFile mFile; // current physical project file
2441
2442 QString mOriginalPath;
2443
2444 QString mSaveUser; // last saved user.
2445 QString mSaveUserFull; // last saved user full name.
2446 QDateTime mSaveDateTime;
2447 QgsProjectVersion mSaveVersion;
2448
2453 QString mHomePath;
2454 mutable QString mCachedHomePath;
2455
2456 QColor mBackgroundColor;
2457 QColor mSelectionColor;
2458
2459 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2460 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2461
2462 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2463 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2464
2465 Qgis::ProjectFlags mFlags;
2467 QgsCoordinateReferenceSystem mVerticalCrs;
2469
2470 bool mDirty = false; // project has been modified since it has been read or saved
2471 int mDirtyBlockCount = 0;
2472
2473 QgsPropertyCollection mDataDefinedServerProperties;
2474
2475 QgsCoordinateTransformContext mTransformContext;
2476
2477 QgsProjectMetadata mMetadata;
2478
2479 std::unique_ptr< QTranslator > mTranslator;
2480
2481 bool mIsBeingDeleted = false;
2482
2483 QgsSettings mSettings;
2484
2485 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2486
2487 bool mBlockChangeSignalsDuringClear = false;
2488 int mBlockSnappingUpdates = 0;
2489
2490 QgsElevationShadingRenderer mElevationShadingRenderer;
2491
2492 friend class QgsApplication;
2493
2495
2496 // Required to avoid creating a new project in it's destructor
2498
2499 // Required by QGIS Server for switching the current project instance
2500 friend class QgsServer;
2501
2502 friend class TestQgsProject;
2503
2504 Q_DISABLE_COPY( QgsProject )
2505};
2506
2528class CORE_EXPORT QgsProjectDirtyBlocker
2529{
2530 public:
2531
2538 : mProject( project )
2539 {
2540 mProject->mDirtyBlockCount++;
2541 }
2542
2545
2547 {
2548 mProject->mDirtyBlockCount--;
2549 }
2550
2551 private:
2552 QgsProject *mProject = nullptr;
2553
2554#ifdef SIP_RUN
2556#endif
2557};
2558
2564CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2565
2566
2567
2569#ifndef SIP_RUN
2570class GetNamedProjectColor : public QgsScopedExpressionFunction
2571{
2572 public:
2573 GetNamedProjectColor( const QgsProject *project );
2574
2579 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2580
2581 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2582 QgsScopedExpressionFunction *clone() const override;
2583
2584 private:
2585
2586 QHash< QString, QColor > mColors;
2587};
2588
2589class GetNamedProjectColorObject : public QgsScopedExpressionFunction
2590{
2591 public:
2592 GetNamedProjectColorObject( const QgsProject *project );
2593
2598 GetNamedProjectColorObject( const QHash< QString, QColor > &colors );
2599
2600 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2601 QgsScopedExpressionFunction *clone() const override;
2602
2603 private:
2604
2605 QHash< QString, QColor > mColors;
2606};
2607
2608
2609
2610class GetSensorData : public QgsScopedExpressionFunction
2611{
2612 public:
2613 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2614 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2615 QgsScopedExpressionFunction *clone() const override;
2616
2617 private:
2618
2619 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2620};
2621#endif
2623
2624#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:4110
DistanceUnit
Units of distance.
Definition qgis.h:4740
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4817
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3872
QFlags< ProjectFlag > ProjectFlags
Definition qgis.h:3879
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:76
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(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
QgsProjectDirtyBlocker(const QgsProjectDirtyBlocker &other)=delete
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 project.
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...
An interface for objects which can translate project strings.
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
Q_DECL_DEPRECATED void oldProjectVersionWarning(const QString &warning)
Emitted when an old project file is read.
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
void readProjectWithContext(const QDomDocument &document, QgsReadWriteContext &context)
Emitted when a project is being read.
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...
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.
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 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,...
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 readProject(const QDomDocument &document)
Emitted when a project is being read.
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 writeProject(QDomDocument &document)
Emitted when the project is being written.
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 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