QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
1674 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1675
1685 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1686
1692 QgsElevationShadingRenderer elevationShadingRenderer() const;
1693
1699 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1700
1709 bool loadFunctionsFromProject( bool force = false ) SIP_SKIP;
1710
1718 void cleanFunctionsFromProject() SIP_SKIP;
1719
1720
1721#ifdef SIP_RUN
1722 SIP_PYOBJECT __repr__();
1723 % MethodCode
1724 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1725 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() ); // skip-keyword-check
1726 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1727 % End
1728#endif
1729
1730 signals:
1731
1739 void cleared();
1740
1748
1752 void readProject( const QDomDocument &document );
1753
1757 void readProjectWithContext( const QDomDocument &document, QgsReadWriteContext &context );
1758
1762 void writeProject( QDomDocument &document );
1763
1772 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1773
1782 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1783
1788
1794 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString &warning ) SIP_DEPRECATED;
1795
1806 void readVersionMismatchOccurred( const QString &fileVersion );
1807
1813 void layerLoaded( int i, int n );
1814
1816 void loadingLayer( const QString &layerName );
1817
1824 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1825
1830 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1831
1834
1842
1847
1854
1859
1869
1881
1898
1905 void ellipsoidChanged( const QString &ellipsoid );
1906
1914
1922
1929
1933 void missingDatumTransforms( const QStringList &missingTransforms );
1934
1940
1947
1953
1959
1971
1976
1984
1992
2000
2008
2009 //
2010 // signals from QgsMapLayerRegistry
2011 //
2012
2020 void layersWillBeRemoved( const QStringList &layerIds );
2021
2029 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
2030
2040 void layerWillBeRemoved( const QString &layerId );
2041
2052
2059 void layersRemoved( const QStringList &layerIds );
2060
2069 void layerRemoved( const QString &layerId );
2070
2071 //TODO QGIS 4.0 - rename to past tense
2072
2080
2091 void layersAdded( const QList<QgsMapLayer *> &layers );
2092
2100
2109 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2110
2118 void isDirtyChanged( bool dirty );
2119
2127 void dirtySet();
2128
2137 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2138
2144 void elevationShadingRendererChanged();
2145
2146 public slots:
2147
2152 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2153
2154 // TODO QGIS 4.0 - rename b to dirty
2155
2162 void setDirty( bool b = true );
2163
2172 void setPresetHomePath( const QString &path );
2173
2183 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2184
2191 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2192
2199 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2200
2207 QgsPropertyCollection dataDefinedServerProperties() const;
2208
2225 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2226
2256 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2257
2274 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2275
2276 private slots:
2277 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2278 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2279 void cleanTransactionGroups( bool force = false );
2280 void updateTransactionGroups();
2281
2282 private:
2283
2284 static QgsProject *sProject;
2285
2286
2295 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2296
2301 void setError( const QString &errorMessage ) SIP_SKIP;
2302
2307 void clearError() SIP_SKIP;
2308
2318 bool addLayer( const QDomElement &layerElem,
2319 QList<QDomNode> &brokenNodes,
2320 QgsReadWriteContext &context,
2321 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2322 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2323
2327 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2328
2334 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2335
2340 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2341
2343 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2344
2346 bool writeProjectFile( const QString &filename );
2347
2349 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2350
2352 bool zip( const QString &filename );
2353
2355 bool saveAuxiliaryStorage( const QString &filename = QString() );
2356
2358 void loadProjectFlags( const QDomDocument *doc );
2359
2361 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2362
2364 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2365 const QgsReadWriteContext &context,
2366 QMap<QString, QgsDataProvider *> &loadedProviders,
2367 QgsMapLayer::ReadFlags layerReadFlags,
2368 int totalProviderCount );
2369
2374 void releaseHandlesToProjectArchive();
2375
2376 bool rebuildCrs3D( QString *error = nullptr );
2377
2378 Qgis::ProjectCapabilities mCapabilities;
2379
2380 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2381
2382 QString mErrorMessage;
2383
2384 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2385
2391 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2392
2393 QgsSnappingConfig mSnappingConfig;
2394 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2395
2396 QgsRelationManager *mRelationManager = nullptr;
2397
2398 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2399 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2400 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2401
2402 QgsBookmarkManager *mBookmarkManager = nullptr;
2403
2404 QgsSensorManager *mSensorManager = nullptr;
2405
2406 QgsProjectViewSettings *mViewSettings = nullptr;
2407
2408 QgsProjectStyleSettings *mStyleSettings = nullptr;
2409
2410 QgsProjectTimeSettings *mTimeSettings = nullptr;
2411
2412 QgsProjectElevationProperties *mElevationProperties = nullptr;
2413
2414 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2415
2416 QgsProjectGpsSettings *mGpsSettings = nullptr;
2417
2418 QgsLayerTree *mRootGroup = nullptr;
2419
2420 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2421
2422 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2423
2425 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2426
2427 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2428
2429 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2430
2431 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2432
2433 QVariantMap mCustomVariables;
2434
2435 std::unique_ptr<QgsArchive> mArchive;
2436
2437 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2438
2439 QFile mFile; // current physical project file
2440
2441 QString mOriginalPath;
2442
2443 QString mSaveUser; // last saved user.
2444 QString mSaveUserFull; // last saved user full name.
2445 QDateTime mSaveDateTime;
2446 QgsProjectVersion mSaveVersion;
2447
2452 QString mHomePath;
2453 mutable QString mCachedHomePath;
2454
2455 QColor mBackgroundColor;
2456 QColor mSelectionColor;
2457
2458 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2459 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2460
2461 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2462 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2463
2464 Qgis::ProjectFlags mFlags;
2466 QgsCoordinateReferenceSystem mVerticalCrs;
2468
2469 bool mDirty = false; // project has been modified since it has been read or saved
2470 int mDirtyBlockCount = 0;
2471
2472 QgsPropertyCollection mDataDefinedServerProperties;
2473
2474 QgsCoordinateTransformContext mTransformContext;
2475
2476 QgsProjectMetadata mMetadata;
2477
2478 std::unique_ptr< QTranslator > mTranslator;
2479
2480 bool mIsBeingDeleted = false;
2481
2482 QgsSettings mSettings;
2483
2484 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2485
2486 bool mBlockChangeSignalsDuringClear = false;
2487 int mBlockSnappingUpdates = 0;
2488
2489 QgsElevationShadingRenderer mElevationShadingRenderer;
2490
2491 friend class QgsApplication;
2492
2494
2495 // Required to avoid creating a new project in it's destructor
2497
2498 // Required by QGIS Server for switching the current project instance
2499 friend class QgsServer;
2500
2501 friend class TestQgsProject;
2502
2503 Q_DISABLE_COPY( QgsProject )
2504};
2505
2527class CORE_EXPORT QgsProjectDirtyBlocker
2528{
2529 public:
2530
2537 : mProject( project )
2538 {
2539 mProject->mDirtyBlockCount++;
2540 }
2541
2544
2546 {
2547 mProject->mDirtyBlockCount--;
2548 }
2549
2550 private:
2551 QgsProject *mProject = nullptr;
2552
2553#ifdef SIP_RUN
2555#endif
2556};
2557
2563CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2564
2565
2566
2568#ifndef SIP_RUN
2569class GetNamedProjectColor : public QgsScopedExpressionFunction
2570{
2571 public:
2572 GetNamedProjectColor( const QgsProject *project );
2573
2578 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2579
2580 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2581 QgsScopedExpressionFunction *clone() const override;
2582
2583 private:
2584
2585 QHash< QString, QColor > mColors;
2586};
2587
2588class GetNamedProjectColorObject : public QgsScopedExpressionFunction
2589{
2590 public:
2591 GetNamedProjectColorObject( const QgsProject *project );
2592
2597 GetNamedProjectColorObject( const QHash< QString, QColor > &colors );
2598
2599 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2600 QgsScopedExpressionFunction *clone() const override;
2601
2602 private:
2603
2604 QHash< QString, QColor > mColors;
2605};
2606
2607
2608
2609class GetSensorData : public QgsScopedExpressionFunction
2610{
2611 public:
2612 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2613 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2614 QgsScopedExpressionFunction *clone() const override;
2615
2616 private:
2617
2618 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2619};
2620#endif
2622
2623#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:4039
DistanceUnit
Units of distance.
Definition qgis.h:4669
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4746
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3801
QFlags< ProjectFlag > ProjectFlags
Definition qgis.h:3808
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 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...
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 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