QGIS API Documentation 3.43.0-Master (e737cc10456)
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 Q_PROPERTY( Qgis::ScaleCalculationMethod scaleMethod READ scaleMethod WRITE setScaleMethod NOTIFY scaleMethodChanged )
129
130 public:
131
132 // *INDENT-OFF*
133
143 {
144 NoProperty = 0,
145 AllProperties = 1,
146 WMSOnlineResource = 2,
147 };
148 // *INDENT-ON*
149
151 static QgsProject *instance();
152
161 static void setInstance( QgsProject *project ) ;
162
171 explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
172
173 ~QgsProject() override;
174
183 void setTitle( const QString &title );
184
191 QString title() const;
192
199 Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
200
209 Qgis::ProjectFlags flags() const { return mFlags; }
210
219 void setFlags( Qgis::ProjectFlags flags );
220
229 void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
230
238 QString saveUser() const;
239
247 QString saveUserFullName() const;
248
254 QDateTime lastSaveDateTime() const;
255
261 QgsProjectVersion lastSaveVersion() const;
262
266 bool isDirty() const;
267
274 void setFileName( const QString &name );
275
282 QString fileName() const;
283
295 void setOriginalPath( const QString &path );
296
308 QString originalPath() const;
309
320 Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
321
328 QgsProjectStorage *projectStorage() const;
329
334 QDateTime lastModified() const;
335
341 QString absoluteFilePath() const;
342
348 QString absolutePath() const;
349
354 QString baseName() const;
355
362 Qgis::FilePathType filePathStorage() const;
363
370 void setFilePathStorage( Qgis::FilePathType type );
371
385
404 QgsCoordinateReferenceSystem crs3D() const;
405
420 void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
421
429 QString ellipsoid() const;
430
438 void setEllipsoid( const QString &ellipsoid );
439
458 QgsCoordinateReferenceSystem verticalCrs() const;
459
479 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
480
489 QgsCoordinateTransformContext transformContext() const;
490
499 void setTransformContext( const QgsCoordinateTransformContext &context );
500
505 void clear();
506
513 bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
514
523 bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
524
534 bool readLayer( const QDomNode &layerNode );
535
543 bool write( const QString &filename );
544
550 bool write();
551
563 bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
564
576 bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
577
588 bool writeEntry( const QString &scope, const QString &key, int value );
589
600 bool writeEntry( const QString &scope, const QString &key, const QString &value );
601
612 bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
613
624 QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
625
636 QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
637
648 int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
649
660 double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
661
672 bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
673
677 bool removeEntry( const QString &scope, const QString &key );
678
687 QStringList entryList( const QString &scope, const QString &key ) const;
688
697 QStringList subkeyList( const QString &scope, const QString &key ) const;
698
699 // TODO Now slightly broken since re-factoring. Won't print out top-level key
700 // and redundantly prints sub-keys.
701
705 void dumpProperties() const;
706
711 QgsPathResolver pathResolver() const;
712
718 QString writePath( const QString &filename ) const;
719
723 QString readPath( const QString &filename ) const;
724
726 QString error() const;
727
732 void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
733
739 QString layerIsEmbedded( const QString &id ) const;
740
749 bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
750 bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
751
758 QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
759
761 void setTopologicalEditing( bool enabled );
762
764 bool topologicalEditing() const;
765
771 Qgis::DistanceUnit distanceUnits() const { return mDistanceUnits; }
772
778 void setDistanceUnits( Qgis::DistanceUnit unit );
779
784 Qgis::AreaUnit areaUnits() const { return mAreaUnits; }
785
791 void setAreaUnits( Qgis::AreaUnit unit );
792
800 Qgis::ScaleCalculationMethod scaleMethod() const { return mScaleMethod; }
801
809 void setScaleMethod( Qgis::ScaleCalculationMethod method );
810
823 QString homePath() const;
824
837 QString presetHomePath() const;
838
839 QgsRelationManager *relationManager() const;
840
846 const QgsLayoutManager *layoutManager() const SIP_SKIP;
847
852 QgsLayoutManager *layoutManager();
853
860 const QgsMapViewsManager *viewsManager() const SIP_SKIP;
861
867 QgsMapViewsManager *viewsManager();
868
875 const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
876
882 QgsBookmarkManager *bookmarkManager();
883
890 const QgsSensorManager *sensorManager() const SIP_SKIP;
891
897 QgsSensorManager *sensorManager();
898
906 const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
907
914 QgsProjectViewSettings *viewSettings();
915
923 const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
924
931 QgsProjectStyleSettings *styleSettings();
932
940 const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
941
948 QgsProjectTimeSettings *timeSettings();
949
956 const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
957
963 QgsProjectElevationProperties *elevationProperties();
964
971 const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
972
978 QgsProjectDisplaySettings *displaySettings();
979
986 const QgsProjectGpsSettings *gpsSettings() const SIP_SKIP;
987
993 QgsProjectGpsSettings *gpsSettings();
994
998 QgsLayerTree *layerTreeRoot() const;
999
1003 QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge.get(); }
1004
1010
1014 QgsAnnotationManager *annotationManager();
1015
1019 const QgsAnnotationManager *annotationManager() const SIP_SKIP;
1020
1025 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
1026
1031 Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
1032
1037 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
1038
1046 Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
1047
1057 Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
1058
1065 Qgis::TransactionMode transactionMode() const;
1066
1076 bool setTransactionMode( Qgis::TransactionMode transactionMode );
1077
1085 QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
1086
1094 QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
1095
1101 QgsVectorLayerEditBufferGroup *editBufferGroup();
1102
1108 Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
1109
1115 Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1116
1117 QgsExpressionContext createExpressionContext() const override;
1118 QgsExpressionContextScope *createExpressionContextScope() const override;
1119
1124 QgsSnappingConfig snappingConfig() const;
1125
1130 QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1131
1138 void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1139
1145 void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1146
1152 Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1153
1159 QVariantMap customVariables() const;
1160
1165 void setCustomVariables( const QVariantMap &customVariables );
1166
1170 void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1171
1175 const QgsLabelingEngineSettings &labelingEngineSettings() const;
1176
1177 //
1178 // Functionality from QgsMapLayerRegistry
1179 //
1180
1184 QgsMapLayerStore *layerStore();
1185
1189 SIP_SKIP const QgsMapLayerStore *layerStore() const;
1190
1192 int count() const;
1193
1195 int validCount() const;
1196
1204 Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1205
1206#ifndef SIP_RUN
1207
1223 template <class T>
1224 T mapLayer( const QString &layerId ) const
1225 {
1226 return qobject_cast<T>( mapLayer( layerId ) );
1227 }
1228#endif
1229
1237 Q_INVOKABLE QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1238
1248 QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1249
1250
1259 QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1260
1264 bool isZipped() const;
1265
1266#ifndef SIP_RUN
1267
1278 template <typename T>
1279 QVector<T> layers() const
1280 {
1281 return mLayerStore->layers<T>();
1282 }
1283
1295 template <typename T>
1296 QVector<T> mapLayersByShortName( const QString &shortName ) const
1297 {
1298 QVector<T> layers;
1299 const auto constMapLayers { mLayerStore->layers<T>() };
1300 for ( const auto l : constMapLayers )
1301 {
1302 if ( ! l->serverProperties()->shortName().isEmpty() )
1303 {
1304 if ( l->serverProperties()->shortName() == shortName )
1305 layers << l;
1306 }
1307 else if ( l->name() == shortName )
1308 {
1309 layers << l;
1310 }
1311 }
1312 return layers;
1313 }
1314
1315#endif
1316
1341 QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1342 bool addToLegend = true,
1343 bool takeOwnership SIP_PYARGREMOVE = true );
1344
1372 QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1373 bool addToLegend = true,
1374 bool takeOwnership SIP_PYARGREMOVE = true );
1375
1376#ifndef SIP_RUN
1390 void removeMapLayers( const QStringList &layerIds );
1391
1392 //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1393
1407 void removeMapLayers( const QList<QgsMapLayer *> &layers );
1408#else
1409
1423 void removeMapLayers( SIP_PYOBJECT layers SIP_TYPEHINT( Union[List[QgsVectorLayer], List[str]] ) );
1424 % MethodCode
1425 if ( !PyList_Check( a0 ) )
1426 {
1427 sipIsErr = 1;
1428 PyErr_SetString( PyExc_TypeError, "Expected a list of layers or layers IDs" );
1429 }
1430 else if ( PyList_GET_SIZE( a0 ) )
1431 {
1432 PyObject *firstLayerPyObj = PyList_GetItem( a0, 0 );
1433 if ( firstLayerPyObj )
1434 {
1435 int state;
1436 if ( sipCanConvertToType( firstLayerPyObj, sipType_QgsMapLayer, SIP_NOT_NONE ) )
1437 {
1438 const sipTypeDef *qlist_type = sipFindType( "QList<QgsMapLayer *>" );
1439 QList<QgsMapLayer *> *layersList = reinterpret_cast<QList<QgsMapLayer *> *>( sipConvertToType( a0, qlist_type, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1440 if ( !sipIsErr )
1441 {
1442 sipCpp->removeMapLayers( *layersList );
1443 }
1444 sipReleaseType( layersList, qlist_type, state );
1445 }
1446 else if ( sipCanConvertToType( firstLayerPyObj, sipType_QString, SIP_NOT_NONE ) )
1447 {
1448 QStringList *layersId = reinterpret_cast<QStringList *>( sipConvertToType( a0, sipType_QStringList, 0, SIP_NOT_NONE, &state, &sipIsErr ) );
1449 if ( !sipIsErr )
1450 {
1451 sipCpp->removeMapLayers( *layersId );
1452 }
1453 sipReleaseType( layersId, sipType_QStringList, state );
1454 }
1455 else
1456 {
1457 sipIsErr = 1;
1458 PyErr_SetString( PyExc_TypeError, "Expected a list of layers or layers IDs" );
1459 }
1460 }
1461 }
1462 % End
1463#endif
1464
1478 void removeMapLayer( const QString &layerId );
1479
1493 void removeMapLayer( QgsMapLayer *layer );
1494
1501 QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1502
1514 QgsAnnotationLayer *mainAnnotationLayer();
1515
1526 void removeAllMapLayers();
1527
1533 void reloadAllLayers();
1534
1539 QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1540
1552 Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1553
1564 Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1565
1570 const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1571
1576 QgsAuxiliaryStorage *auxiliaryStorage();
1577
1586 QString createAttachedFile( const QString &nameTemplate );
1587
1594 QStringList attachedFiles() const;
1595
1603 bool removeAttachedFile( const QString &path );
1604
1613 QString attachmentIdentifier( const QString &attachedFile ) const;
1614
1621 QString resolveAttachmentIdentifier( const QString &identifier ) const;
1622
1629 const QgsProjectMetadata &metadata() const;
1630
1637 void setMetadata( const QgsProjectMetadata &metadata );
1638
1647 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1648
1657 Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1658
1665 void setProjectColors( const QgsNamedColorList &colors );
1666
1673 void setBackgroundColor( const QColor &color );
1674
1681 QColor backgroundColor() const;
1682
1689 void setSelectionColor( const QColor &color );
1690
1697 QColor selectionColor() const;
1698
1710 Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1711
1723 Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1724
1733 Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1734
1743 Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1744
1749 void generateTsFile( const QString &locale );
1750
1751 QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1752
1762 bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1763
1769 QgsElevationShadingRenderer elevationShadingRenderer() const;
1770
1776 void setElevationShadingRenderer( const QgsElevationShadingRenderer &elevationShadingRenderer );
1777
1786 bool loadFunctionsFromProject( bool force = false ) SIP_SKIP;
1787
1795 void cleanFunctionsFromProject() SIP_SKIP;
1796
1797
1798#ifdef SIP_RUN
1799 SIP_PYOBJECT __repr__();
1800 % MethodCode
1801 QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1802 sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() ); // skip-keyword-check
1803 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1804 % End
1805#endif
1806
1807 signals:
1808
1816 void cleared();
1817
1825
1829 void readProject( const QDomDocument &document );
1830
1834 void readProjectWithContext( const QDomDocument &document, QgsReadWriteContext &context );
1835
1839 void writeProject( QDomDocument &document );
1840
1849 void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1850
1859 void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1860
1865
1871 Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString &warning ) SIP_DEPRECATED;
1872
1883 void readVersionMismatchOccurred( const QString &fileVersion );
1884
1890 void layerLoaded( int i, int n );
1891
1893 void loadingLayer( const QString &layerName );
1894
1901 void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1902
1907 Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1908
1911
1919
1924
1931
1936
1946
1958
1975
1982 void ellipsoidChanged( const QString &ellipsoid );
1983
1991
1999
2008
2015
2019 void missingDatumTransforms( const QStringList &missingTransforms );
2020
2026
2033
2039
2045
2057
2062
2070
2078
2086
2094
2095 //
2096 // signals from QgsMapLayerRegistry
2097 //
2098
2106 void layersWillBeRemoved( const QStringList &layerIds );
2107
2115 void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
2116
2126 void layerWillBeRemoved( const QString &layerId );
2127
2138
2145 void layersRemoved( const QStringList &layerIds );
2146
2155 void layerRemoved( const QString &layerId );
2156
2157 //TODO QGIS 4.0 - rename to past tense
2158
2166
2177 void layersAdded( const QList<QgsMapLayer *> &layers );
2178
2186
2195 void legendLayersAdded( const QList<QgsMapLayer *> &layers );
2196
2204 void isDirtyChanged( bool dirty );
2205
2213 void dirtySet();
2214
2223 Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
2224
2230 void elevationShadingRendererChanged();
2231
2232 public slots:
2233
2238 void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
2239
2240 // TODO QGIS 4.0 - rename b to dirty
2241
2248 void setDirty( bool b = true );
2249
2258 void setPresetHomePath( const QString &path );
2259
2269 void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2270
2277 void registerTranslatableObjects( QgsTranslationContext *translationContext );
2278
2285 void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2286
2293 QgsPropertyCollection dataDefinedServerProperties() const;
2294
2311 bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2312
2342 bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2343
2360 bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2361
2362 private slots:
2363 void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2364 void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2365 void cleanTransactionGroups( bool force = false );
2366 void updateTransactionGroups();
2367
2368 private:
2369
2370 static QgsProject *sProject;
2371
2372
2381 bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2382
2387 void setError( const QString &errorMessage ) SIP_SKIP;
2388
2393 void clearError() SIP_SKIP;
2394
2404 bool addLayer( const QDomElement &layerElem,
2405 QList<QDomNode> &brokenNodes,
2406 QgsReadWriteContext &context,
2407 Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags(),
2408 QgsDataProvider *provider = nullptr ) SIP_SKIP;
2409
2413 void removeAuxiliaryLayer( const QgsMapLayer *ml );
2414
2420 void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2421
2426 bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2427
2429 bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2430
2432 bool writeProjectFile( const QString &filename );
2433
2435 bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2436
2438 bool zip( const QString &filename );
2439
2441 bool saveAuxiliaryStorage( const QString &filename = QString() );
2442
2444 void loadProjectFlags( const QDomDocument *doc );
2445
2447 static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2448
2450 void preloadProviders( const QVector<QDomNode> &asynchronusLayerNodes,
2451 const QgsReadWriteContext &context,
2452 QMap<QString, QgsDataProvider *> &loadedProviders,
2453 QgsMapLayer::ReadFlags layerReadFlags,
2454 int totalProviderCount );
2455
2460 void releaseHandlesToProjectArchive();
2461
2462 bool rebuildCrs3D( QString *error = nullptr );
2463
2464 Qgis::ProjectCapabilities mCapabilities;
2465
2466 std::unique_ptr< QgsMapLayerStore > mLayerStore;
2467
2468 QString mErrorMessage;
2469
2470 std::unique_ptr<QgsProjectBadLayerHandler> mBadLayerHandler;
2471
2477 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2478
2479 QgsSnappingConfig mSnappingConfig;
2480 Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2481
2482 std::unique_ptr<QgsRelationManager> mRelationManager;
2483
2484 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2485 std::unique_ptr<QgsLayoutManager> mLayoutManager;
2486 std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2487
2488 QgsBookmarkManager *mBookmarkManager = nullptr;
2489
2490 QgsSensorManager *mSensorManager = nullptr;
2491
2492 QgsProjectViewSettings *mViewSettings = nullptr;
2493
2494 QgsProjectStyleSettings *mStyleSettings = nullptr;
2495
2496 QgsProjectTimeSettings *mTimeSettings = nullptr;
2497
2498 QgsProjectElevationProperties *mElevationProperties = nullptr;
2499
2500 QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2501
2502 QgsProjectGpsSettings *mGpsSettings = nullptr;
2503
2504 std::unique_ptr<QgsLayerTree> mRootGroup;
2505
2506 std::unique_ptr<QgsLayerTreeRegistryBridge> mLayerTreeRegistryBridge;
2507
2508 QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2509
2511 QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2512
2513 QgsVectorLayerEditBufferGroup mEditBufferGroup;
2514
2515 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2516
2517 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2518
2519 QVariantMap mCustomVariables;
2520
2521 std::unique_ptr<QgsArchive> mArchive;
2522
2523 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2524
2525 QFile mFile; // current physical project file
2526
2527 QString mOriginalPath;
2528
2529 QString mSaveUser; // last saved user.
2530 QString mSaveUserFull; // last saved user full name.
2531 QDateTime mSaveDateTime;
2532 QgsProjectVersion mSaveVersion;
2533
2538 QString mHomePath;
2539 mutable QString mCachedHomePath;
2540
2541 QColor mBackgroundColor;
2542 QColor mSelectionColor;
2543
2544 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Meters;
2545 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::SquareMeters;
2546 Qgis::ScaleCalculationMethod mScaleMethod = Qgis::ScaleCalculationMethod::HorizontalMiddle;
2547
2548 mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2549 Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2550
2551 Qgis::ProjectFlags mFlags;
2553 QgsCoordinateReferenceSystem mVerticalCrs;
2555
2556 bool mDirty = false; // project has been modified since it has been read or saved
2557 int mDirtyBlockCount = 0;
2558
2559 QgsPropertyCollection mDataDefinedServerProperties;
2560
2561 QgsCoordinateTransformContext mTransformContext;
2562
2563 QgsProjectMetadata mMetadata;
2564
2565 std::unique_ptr< QTranslator > mTranslator;
2566
2567 bool mIsBeingDeleted = false;
2568
2569 QgsSettings mSettings;
2570
2571 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2572
2573 bool mBlockChangeSignalsDuringClear = false;
2574 int mBlockSnappingUpdates = 0;
2575
2576 QgsElevationShadingRenderer mElevationShadingRenderer;
2577
2578 friend class QgsApplication;
2579
2581
2582 // Required to avoid creating a new project in it's destructor
2584
2585 // Required by QGIS Server for switching the current project instance
2586 friend class QgsServer;
2587
2588 friend class TestQgsProject;
2589
2590 Q_DISABLE_COPY( QgsProject )
2591};
2592
2614class CORE_EXPORT QgsProjectDirtyBlocker
2615{
2616 public:
2617
2624 : mProject( project )
2625 {
2626 mProject->mDirtyBlockCount++;
2627 }
2628
2631
2633 {
2634 mProject->mDirtyBlockCount--;
2635 }
2636
2637 private:
2638 QgsProject *mProject = nullptr;
2639
2640#ifdef SIP_RUN
2642#endif
2643};
2644
2650CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2651
2652
2653
2655#ifndef SIP_RUN
2656class GetNamedProjectColor : public QgsScopedExpressionFunction
2657{
2658 public:
2659 GetNamedProjectColor( const QgsProject *project );
2660
2665 GetNamedProjectColor( const QHash< QString, QColor > &colors );
2666
2667 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2668 QgsScopedExpressionFunction *clone() const override;
2669
2670 private:
2671
2672 QHash< QString, QColor > mColors;
2673};
2674
2675class GetNamedProjectColorObject : public QgsScopedExpressionFunction
2676{
2677 public:
2678 GetNamedProjectColorObject( const QgsProject *project );
2679
2684 GetNamedProjectColorObject( const QHash< QString, QColor > &colors );
2685
2686 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2687 QgsScopedExpressionFunction *clone() const override;
2688
2689 private:
2690
2691 QHash< QString, QColor > mColors;
2692};
2693
2694
2695
2696class GetSensorData : public QgsScopedExpressionFunction
2697{
2698 public:
2699 GetSensorData( const QMap<QString, QgsAbstractSensor::SensorData> &sensorData = QMap<QString, QgsAbstractSensor::SensorData>() );
2700 QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2701 QgsScopedExpressionFunction *clone() const override;
2702
2703 private:
2704
2705 QMap<QString, QgsAbstractSensor::SensorData> mSensorData;
2706};
2707#endif
2709
2710#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
QFlags< ProjectCapability > ProjectCapabilities
Flags which control project capabilities.
Definition qgis.h:4209
DistanceUnit
Units of distance.
Definition qgis.h:4859
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
AreaUnit
Units of area.
Definition qgis.h:4936
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition qgis.h:3958
ScaleCalculationMethod
Scale calculation logic.
Definition qgis.h:5096
QFlags< ProjectFlag > ProjectFlags
Definition qgis.h:3965
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,...
Manages zip/unzip operations for an archive.
Definition qgsarchive.h:35
A container for attribute editors, used to group them visually in the attribute form if it is set to ...
Providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
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.
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
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.
Handles 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 layer changes from a QgsProject and applies changes to a QgsLayerTree.
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:77
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 files.
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.
Describes 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:209
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:784
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:143
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 scaleMethodChanged()
Emitted when the project's scale method is changed.
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
void 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::ScaleCalculationMethod scaleMethod() const
Returns the method to use for map scale calculations for the project.
Definition qgsproject.h:800
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition qgsproject.h:199
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 an integer key value.
A registry / canonical manager of data providers.
A container for the context for various read/write operations on objects.
Manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
Manages sensors.
A server which provides OGC web services.
Definition qgsserver.h:49
Stores settings for use within QGIS.
Definition qgssettings.h:65
Stores configuration of snapping settings for the project.
An interface for classes which can visit style entity (e.g.
Provides calculations for tolerance values in map units.
Represents a transaction group.
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 dataset.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#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