QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
57#include "qgsrelationmanager.h"
59
60class QFileInfo;
61class QDomDocument;
62class QDomElement;
63class QDomNode;
64
67class QgsMapLayer;
68class QgsPathResolver;
71class QgsTolerance;
73class QgsVectorLayer;
76class QgsLayerTree;
79class QgsMapLayer;
90
105{
106 Q_OBJECT
107 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
108 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
109 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
110 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
111 Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
112 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
113 Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
114 Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
115 Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
116 Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
117 Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
118 Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
119 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
120 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
121 Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
122 Q_PROPERTY( Qgis::DistanceUnit distanceUnits READ distanceUnits WRITE setDistanceUnits NOTIFY distanceUnitsChanged )
123 Q_PROPERTY( Qgis::AreaUnit areaUnits READ areaUnits WRITE setAreaUnits NOTIFY areaUnitsChanged )
124 Q_PROPERTY( QgsProjectDisplaySettings *displaySettings READ displaySettings CONSTANT )
125
126 public:
127
137 {
138 NoProperty = 0,
139 AllProperties = 1,
140 WMSOnlineResource = 2,
141 };
142
144 static QgsProject *instance();
145
154 static void setInstance( QgsProject *project ) ;
155
164 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
165
166 ~QgsProject() override;
167
177 void setTitle( const QString &title );
178
185 QString title() const;
186
193 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
194
203 Qgis::ProjectFlags flags() const { return mFlags; }
204
213 void setFlags( Qgis::ProjectFlags flags );
214
223 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
224
232 QString saveUser() const;
233
241 QString saveUserFullName() const;
242
248 QDateTime lastSaveDateTime() const;
249
255 QgsProjectVersion lastSaveVersion() const;
256
260 bool isDirty() const;
261
268 void setFileName( const QString &name );
269
276 QString fileName() const;
277
289 void setOriginalPath( const QString &path );
290
302 QString originalPath() const;
303
314 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
315
322 QgsProjectStorage *projectStorage() const;
323
328 QDateTime lastModified() const;
329
335 QString absoluteFilePath() const;
336
342 QString absolutePath() const;
343
348 QString baseName() const;
349
356 Qgis::FilePathType filePathStorage() const;
357
364 void setFilePathStorage( Qgis::FilePathType type );
365
373
383 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
384
391 QString ellipsoid() const;
392
399 void setEllipsoid( const QString &ellipsoid );
400
401
411 QgsCoordinateTransformContext transformContext() const;
412
422 void setTransformContext( const QgsCoordinateTransformContext &context );
423
429 void clear();
430
437 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
438
447 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
448
458 bool readLayer( const QDomNode &layerNode );
459
468 bool write( const QString &filename );
469
475 bool write();
476
488 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
489
501 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
502
513 bool writeEntry( const QString &scope, const QString &key, int value );
514
525 bool writeEntry( const QString &scope, const QString &key, const QString &value );
526
537 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
538
549 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
550
561 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
562
573 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
574
585 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
586
597 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
598
602 bool removeEntry( const QString &scope, const QString &key );
603
612 QStringList entryList( const QString &scope, const QString &key ) const;
613
622 QStringList subkeyList( const QString &scope, const QString &key ) const;
623
624 // TODO Now slightly broken since re-factoring. Won't print out top-level key
625 // and redundantly prints sub-keys.
626
630 void dumpProperties() const;
631
637 QgsPathResolver pathResolver() const;
638
644 QString writePath( const QString &filename ) const;
645
649 QString readPath( const QString &filename ) const;
650
652 QString error() const;
653
658 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
659
665 QString layerIsEmbedded( const QString &id ) const;
666
675 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
676 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
677
685 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
686
688 void setTopologicalEditing( bool enabled );
689
691 bool topologicalEditing() const;
692
699 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
700
707 void setDistanceUnits( Qgis::DistanceUnit unit );
708
714 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
715
722 void setAreaUnits( Qgis::AreaUnit unit );
723
736 QString homePath() const;
737
750 QString presetHomePath() const;
751
752 QgsRelationManager *relationManager() const;
753
760 const QgsLayoutManager *layoutManager() const SIP_SKIP;
761
767 QgsLayoutManager *layoutManager();
768
775 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
776
782 QgsMapViewsManager *viewsManager();
783
790 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
791
797 QgsBookmarkManager *bookmarkManager();
798
806 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
807
814 QgsProjectViewSettings *viewSettings();
815
823 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
824
831 QgsProjectStyleSettings *styleSettings();
832
840 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
841
848 QgsProjectTimeSettings *timeSettings();
849
856 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
857
863 QgsProjectElevationProperties *elevationProperties();
864
871 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
872
878 QgsProjectDisplaySettings *displaySettings();
879
886 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
887
893 QgsProjectGpsSettings *gpsSettings();
894
899 QgsLayerTree *layerTreeRoot() const;
900
905 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
906
913
918 QgsAnnotationManager *annotationManager();
919
924 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
925
930 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
931
936 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
937
942 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
943
952 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
953
964 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
965
972 Qgis::TransactionMode transactionMode() const;
973
983 bool setTransactionMode( Qgis::TransactionMode transactionMode );
984
993 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
994
1002 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1003
1009 QgsVectorLayerEditBufferGroup *editBufferGroup();
1010
1016 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1017
1023 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1024
1025 QgsExpressionContext createExpressionContext() const override;
1026 QgsExpressionContextScope *createExpressionContextScope() const override;
1027
1033 QgsSnappingConfig snappingConfig() const;
1034
1040 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1041
1048 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1049
1055 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1056
1062 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1063
1069 QVariantMap customVariables() const;
1070
1075 void setCustomVariables( const QVariantMap &customVariables );
1076
1081 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1082
1087 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1088
1089 //
1090 // Functionality from QgsMapLayerRegistry
1091 //
1092
1097 QgsMapLayerStore *layerStore();
1098
1103 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1104
1106 int count() const;
1107
1109 int validCount() const;
1110
1118 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1119
1120#ifndef SIP_RUN
1121
1137 template <class T>
1138 T mapLayer( const QString &layerId ) const
1139 {
1140 return qobject_cast<T>( mapLayer( layerId ) );
1141 }
1142#endif
1143
1151 QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1152
1162 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1163
1164
1173 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1174
1178 bool isZipped() const;
1179
1180#ifndef SIP_RUN
1181
1193 template <typename T>
1194 QVector<T> layers() const
1195 {
1196 return mLayerStore->layers<T>();
1197 }
1198
1210 template <typename T>
1211 QVector<T> mapLayersByShortName( const QString &shortName ) const
1212 {
1213 QVector<T> layers;
1214 const auto constMapLayers { mLayerStore->layers<T>() };
1215 for ( const auto l : constMapLayers )
1216 {
1217 if ( ! l->shortName().isEmpty() )
1218 {
1219 if ( l->shortName() == shortName )
1220 layers << l;
1221 }
1222 else if ( l->name() == shortName )
1223 {
1224 layers << l;
1225 }
1226 }
1227 return layers;
1228 }
1229
1230#endif
1231
1257 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1258 bool addToLegend = true,
1259 bool takeOwnership SIP_PYARGREMOVE = true );
1260
1288 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1289 bool addToLegend = true,
1290 bool takeOwnership SIP_PYARGREMOVE = true );
1291
1306 void removeMapLayers( const QStringList &layerIds );
1307
1308 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1309
1323 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1324
1338 void removeMapLayer( const QString &layerId );
1339
1353 void removeMapLayer( QgsMapLayer *layer );
1354
1362 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1363
1375 QgsAnnotationLayer *mainAnnotationLayer();
1376
1387 void removeAllMapLayers();
1388
1394 void reloadAllLayers();
1395
1400 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1401
1413 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1414
1425 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1426
1432 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1433
1439 QgsAuxiliaryStorage *auxiliaryStorage();
1440
1449 QString createAttachedFile( const QString &nameTemplate );
1450
1457 QStringList attachedFiles() const;
1458
1466 bool removeAttachedFile( const QString &path );
1467
1476 QString attachmentIdentifier( const QString &attachedFile ) const;
1477
1484 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1485
1492 const QgsProjectMetadata &metadata() const;
1493
1500 void setMetadata( const QgsProjectMetadata &metadata );
1501
1510 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1511
1520 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1521
1528 void setProjectColors( const QgsNamedColorList &colors );
1529
1536 void setBackgroundColor( const QColor &color );
1537
1544 QColor backgroundColor() const;
1545
1552 void setSelectionColor( const QColor &color );
1553
1560 QColor selectionColor() const;
1561
1573 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1574
1586 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1587
1596 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1597
1606 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1607
1612 void generateTsFile( const QString &locale );
1613
1624 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1625
1635 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1636
1642 QgsElevationShadingRenderer elevationShadingRenderer() const;
1643
1649 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1650
1651#ifdef SIP_RUN
1652 SIP_PYOBJECT __repr__();
1653 % MethodCode
1654 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1655 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1656 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1657 % End
1658#endif
1659
1660 signals:
1661
1669 void cleared();
1670
1674 void readProject( const QDomDocument & );
1675
1679 void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1680
1684 void writeProject( QDomDocument & );
1685
1694 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1695
1704 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1705
1710
1716 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1717
1728 void readVersionMismatchOccurred( const QString &fileVersion );
1729
1735 void layerLoaded( int i, int n );
1736
1738 void loadingLayer( const QString &layerName );
1739
1746 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1747
1752 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1753
1756
1764
1769
1776
1782
1789
1797 void ellipsoidChanged( const QString &ellipsoid );
1798
1806
1814
1822
1827 void missingDatumTransforms( const QStringList &missingTransforms );
1828
1836
1843
1850
1863
1869
1877
1885
1893
1901
1902 //
1903 // signals from QgsMapLayerRegistry
1904 //
1905
1913 void layersWillBeRemoved( const QStringList &layerIds );
1914
1922 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1923
1933 void layerWillBeRemoved( const QString &layerId );
1934
1945
1952 void layersRemoved( const QStringList &layerIds );
1953
1962 void layerRemoved( const QString &layerId );
1963
1964 //TODO QGIS 4.0 - rename to past tense
1965
1973
1984 void layersAdded( const QList<QgsMapLayer *> &layers );
1985
1993
2002 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2003
2011 void isDirtyChanged( bool dirty );
2012
2020 void dirtySet();
2021
2030 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2031
2037 void elevationShadingRendererChanged();
2038
2039 public slots:
2040
2046 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2047
2048 // TODO QGIS 4.0 - rename b to dirty
2049
2057 void setDirty( bool b = true );
2058
2067 void setPresetHomePath( const QString &path );
2068
2078 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2079
2086 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2087
2094 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2095
2102 QgsPropertyCollection dataDefinedServerProperties() const;
2103
2120 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2121
2151 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2152
2169 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2170
2171 private slots:
2172 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2173 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2174 void cleanTransactionGroups( bool force = false );
2175 void updateTransactionGroups();
2176
2177 private:
2178
2179 static QgsProject *sProject;
2180
2181
2190 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2191
2196 void setError( const QString &errorMessage ) SIP_SKIP;
2197
2202 void clearError() SIP_SKIP;
2203
2211 bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2212
2216 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2217
2223 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2224
2229 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2230
2232 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2233
2235 bool writeProjectFile( const QString &filename );
2236
2238 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2239
2241 bool zip( const QString &filename );
2242
2244 bool saveAuxiliaryStorage( const QString &filename = QString() );
2245
2247 void loadProjectFlags( const QDomDocument *doc );
2248
2250 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2251
2252 Qgis::ProjectCapabilities mCapabilities;
2253
2254 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2255
2256 QString mErrorMessage;
2257
2258 QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2259
2265 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2266
2267 QgsSnappingConfig mSnappingConfig;
2268 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2269
2270 QgsRelationManager *mRelationManager = nullptr;
2271
2272 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2273 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2274 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2275
2276 QgsBookmarkManager *mBookmarkManager = nullptr;
2277
2278 QgsProjectViewSettings *mViewSettings = nullptr;
2279
2280 QgsProjectStyleSettings *mStyleSettings = nullptr;
2281
2282 QgsProjectTimeSettings *mTimeSettings = nullptr;
2283
2284 QgsProjectElevationProperties *mElevationProperties = nullptr;
2285
2286 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2287
2288 QgsProjectGpsSettings *mGpsSettings = nullptr;
2289
2290 QgsLayerTree *mRootGroup = nullptr;
2291
2292 QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2293
2294 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2295
2297 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2298
2299 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2300
2301 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2302
2303 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2304
2305 QVariantMap mCustomVariables;
2306
2307 std::unique_ptr<QgsArchive> mArchive;
2308
2309 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2310
2311 QFile mFile; // current physical project file
2312
2313 QString mOriginalPath;
2314
2315 QString mSaveUser; // last saved user.
2316 QString mSaveUserFull; // last saved user full name.
2317 QDateTime mSaveDateTime;
2318 QgsProjectVersion mSaveVersion;
2319
2324 QString mHomePath;
2325 mutable QString mCachedHomePath;
2326
2327 QColor mBackgroundColor;
2328 QColor mSelectionColor;
2329
2330 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2331 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2332
2333 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2334 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2335
2336 Qgis::ProjectFlags mFlags;
2338 bool mDirty = false; // project has been modified since it has been read or saved
2339 int mDirtyBlockCount = 0;
2340
2341 QgsPropertyCollection mDataDefinedServerProperties;
2342
2343 QgsCoordinateTransformContext mTransformContext;
2344
2345 QgsProjectMetadata mMetadata;
2346
2347 std::unique_ptr< QTranslator > mTranslator;
2348
2349 bool mIsBeingDeleted = false;
2350
2351 QgsSettings mSettings;
2352
2353 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2354
2355 int mBlockSnappingUpdates = 0;
2356
2357 QgsElevationShadingRenderer mElevationShadingRenderer;
2358
2359 friend class QgsApplication;
2360
2362
2363 // Required to avoid creating a new project in it's destructor
2365
2366 // Required by QGIS Server for switching the current project instance
2367 friend class QgsServer;
2368
2369 friend class TestQgsProject;
2370
2371 Q_DISABLE_COPY( QgsProject )
2372};
2373
2395class CORE_EXPORT QgsProjectDirtyBlocker
2396{
2397 public:
2398
2405 : mProject( project )
2406 {
2407 mProject->mDirtyBlockCount++;
2408 }
2409
2412
2415
2417 {
2418 mProject->mDirtyBlockCount--;
2419 }
2420
2421 private:
2422 QgsProject *mProject = nullptr;
2423
2424#ifdef SIP_RUN
2426#endif
2427};
2428
2434CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2435
2436
2437
2439#ifndef SIP_RUN
2440class GetNamedProjectColor : public QgsScopedExpressionFunction
2441{
2442 public:
2443 GetNamedProjectColor( const QgsProject *project );
2444
2449 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2450
2451 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2452 QgsScopedExpressionFunction *clone() const override;
2453
2454 private:
2455
2456 QHash< QString, QColor > mColors;
2457
2458};
2459
2460#endif
2462
2463#endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:55
DistanceUnit
Units of distance.
Definition: qgis.h:3047
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition: qgis.h:3084
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgis.h:2512
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:2380
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
Class allowing to manage the zip/unzip actions.
Definition: qgsarchive.h:36
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Class providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
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.
Definition: qgslayertree.h:33
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:73
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.
Definition: qgsproject.h:2396
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2404
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:105
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:203
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
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:714
void avoidIntersectionsLayersChanged()
Emitted whenever avoidIntersectionsLayers has changed.
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the registry.
void distanceUnitsChanged()
Emitted when the default distance units changes.
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:137
Q_DECL_DEPRECATED void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
void metadataChanged()
Emitted when the project's metadata is changed.
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1194
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.
Definition: qgsproject.h:1138
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,...
Definition: qgsproject.h:1211
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:193
void projectSaved()
Emitted when the project file has been written and closed.
void layersWillBeRemoved(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers are about to be removed from the registry.
void layerLoaded(int i, int n)
Emitted when a layer from a projects was read.
void selectionColorChanged()
Emitted whenever the project's selection color has been changed.
void removeAll()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
void transformContextChanged()
Emitted when the project transformContext() is changed.
void legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted, when a layer was added to the registry and the legend.
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
void homePathChanged()
Emitted when the home path of the project changes.
void dirtySet()
Emitted when setDirty(true) is called.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
void avoidIntersectionsModeChanged()
Emitted whenever the avoid intersections mode has changed.
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A registry / canonical manager of data providers.
The class is used as a container of context for various read/write operations on other objects.
This class manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
The QgsServer class provides OGC web services.
Definition: qgsserver.h:49
This class is a composition of two QSettings instances:
Definition: qgssettings.h:63
This is a container for configuration of the snapping of the project.
An interface for classes which can visit style entity (e.g.
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:33
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.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:37
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74
#define str(x)
Definition: qgis.cpp:37
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs