QGIS API Documentation  3.27.0-Master (597e8eebd4)
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 "qgsunittypes.h"
38 #include "qgssnappingconfig.h"
39 #include "qgsprojectversion.h"
44 #include "qgsprojectproperty.h"
45 #include "qgsmaplayerstore.h"
46 #include "qgsarchive.h"
47 #include "qgsreadwritecontext.h"
48 #include "qgsprojectmetadata.h"
49 #include "qgstranslationcontext.h"
50 #include "qgsprojecttranslator.h"
51 #include "qgscolorscheme.h"
52 #include "qgssettings.h"
53 #include "qgspropertycollection.h"
55 
56 #include "qgsrelationmanager.h"
57 #include "qgsmapthemecollection.h"
58 
59 class QFileInfo;
60 class QDomDocument;
61 class QDomElement;
62 class QDomNode;
63 
64 class QgsLayerTreeGroup;
66 class QgsMapLayer;
67 class QgsPathResolver;
69 class QgsProjectStorage;
70 class QgsTolerance;
72 class QgsVectorLayer;
74 class QgsLayoutManager;
75 class QgsLayerTree;
78 class QgsMapLayer;
79 class QgsBookmarkManager;
84 class QgsAnnotationLayer;
87 class QgsMapViewsManager;
89 
104 {
105  Q_OBJECT
106  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
107  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
108  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
109  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
110  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
111  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
112  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
113  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
114  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
115  Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
116  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
117  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
118  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
119  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
120  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
121 
122  public:
123 
133  {
134  NoProperty = 0,
135  AllProperties = 1,
136  WMSOnlineResource = 2,
137  };
138 
140  static QgsProject *instance();
141 
150  static void setInstance( QgsProject *project ) ;
151 
157  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
158 
159  ~QgsProject() override;
160 
170  void setTitle( const QString &title );
171 
178  QString title() const;
179 
188  Qgis::ProjectFlags flags() const { return mFlags; }
189 
198  void setFlags( Qgis::ProjectFlags flags );
199 
208  void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
209 
217  QString saveUser() const;
218 
226  QString saveUserFullName() const;
227 
233  QDateTime lastSaveDateTime() const;
234 
240  QgsProjectVersion lastSaveVersion() const;
241 
245  bool isDirty() const;
246 
253  void setFileName( const QString &name );
254 
261  QString fileName() const;
262 
274  void setOriginalPath( const QString &path );
275 
287  QString originalPath() const;
288 
299  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
300 
307  QgsProjectStorage *projectStorage() const;
308 
313  QDateTime lastModified() const;
314 
320  QString absoluteFilePath() const;
321 
327  QString absolutePath() const;
328 
333  QString baseName() const;
334 
341  Qgis::FilePathType filePathStorage() const;
342 
349  void setFilePathStorage( Qgis::FilePathType type );
350 
358 
368  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
369 
376  QString ellipsoid() const;
377 
384  void setEllipsoid( const QString &ellipsoid );
385 
386 
396  QgsCoordinateTransformContext transformContext() const;
397 
407  void setTransformContext( const QgsCoordinateTransformContext &context );
408 
414  void clear();
415 
422  bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
423 
432  bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
433 
443  bool readLayer( const QDomNode &layerNode );
444 
453  bool write( const QString &filename );
454 
460  bool write();
461 
473  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
474 
486  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
487 
498  bool writeEntry( const QString &scope, const QString &key, int value );
499 
510  bool writeEntry( const QString &scope, const QString &key, const QString &value );
511 
522  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
523 
534  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
535 
546  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
547 
558  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
559 
570  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
571 
582  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
583 
587  bool removeEntry( const QString &scope, const QString &key );
588 
597  QStringList entryList( const QString &scope, const QString &key ) const;
598 
607  QStringList subkeyList( const QString &scope, const QString &key ) const;
608 
609  // TODO Now slightly broken since re-factoring. Won't print out top-level key
610  // and redundantly prints sub-keys.
611 
615  void dumpProperties() const;
616 
622  QgsPathResolver pathResolver() const;
623 
629  QString writePath( const QString &filename ) const;
630 
634  QString readPath( const QString &filename ) const;
635 
637  QString error() const;
638 
643  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
644 
650  QString layerIsEmbedded( const QString &id ) const;
651 
660  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
661  bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
662 
670  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
671 
673  void setTopologicalEditing( bool enabled );
674 
676  bool topologicalEditing() const;
677 
684  QgsUnitTypes::DistanceUnit distanceUnits() const;
685 
692  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
693 
699  QgsUnitTypes::AreaUnit areaUnits() const;
700 
707  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
708 
721  QString homePath() const;
722 
735  QString presetHomePath() const;
736 
737  QgsRelationManager *relationManager() const;
738 
745  const QgsLayoutManager *layoutManager() const SIP_SKIP;
746 
752  QgsLayoutManager *layoutManager();
753 
760  const QgsMapViewsManager *viewsManager() const SIP_SKIP;
761 
767  QgsMapViewsManager *viewsManager();
768 
775  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
776 
782  QgsBookmarkManager *bookmarkManager();
783 
791  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
792 
799  QgsProjectViewSettings *viewSettings();
800 
808  const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
809 
816  QgsProjectStyleSettings *styleSettings();
817 
825  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
826 
833  QgsProjectTimeSettings *timeSettings();
834 
841  const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
842 
848  QgsProjectElevationProperties *elevationProperties();
849 
856  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
857 
863  QgsProjectDisplaySettings *displaySettings();
864 
869  QgsLayerTree *layerTreeRoot() const;
870 
875  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
876 
883 
888  QgsAnnotationManager *annotationManager();
889 
894  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
895 
900  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
901 
906  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
907 
912  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
913 
922  Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
923 
934  Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
935 
942  Qgis::TransactionMode transactionMode() const;
943 
953  bool setTransactionMode( Qgis::TransactionMode transactionMode );
954 
963  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
964 
972  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
973 
979  QgsVectorLayerEditBufferGroup *editBufferGroup();
980 
986  Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
987 
993  Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
994 
995  QgsExpressionContext createExpressionContext() const override;
996  QgsExpressionContextScope *createExpressionContextScope() const override;
997 
1003  QgsSnappingConfig snappingConfig() const;
1004 
1010  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1011 
1018  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1019 
1025  void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1026 
1032  Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1033 
1039  QVariantMap customVariables() const;
1040 
1045  void setCustomVariables( const QVariantMap &customVariables );
1046 
1051  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1052 
1057  const QgsLabelingEngineSettings &labelingEngineSettings() const;
1058 
1059  //
1060  // Functionality from QgsMapLayerRegistry
1061  //
1062 
1067  QgsMapLayerStore *layerStore();
1068 
1073  SIP_SKIP const QgsMapLayerStore *layerStore() const;
1074 
1076  int count() const;
1077 
1079  int validCount() const;
1080 
1088  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1089 
1090 #ifndef SIP_RUN
1091 
1107  template <class T>
1108  T mapLayer( const QString &layerId ) const
1109  {
1110  return qobject_cast<T>( mapLayer( layerId ) );
1111  }
1112 #endif
1113 
1121  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1122 
1132  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1133 
1134 
1143  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1144 
1148  bool isZipped() const;
1149 
1150 #ifndef SIP_RUN
1151 
1163  template <typename T>
1164  QVector<T> layers() const
1165  {
1166  return mLayerStore->layers<T>();
1167  }
1168 
1180  template <typename T>
1181  QVector<T> mapLayersByShortName( const QString &shortName ) const
1182  {
1183  QVector<T> layers;
1184  const auto constMapLayers { mLayerStore->layers<T>() };
1185  for ( const auto l : constMapLayers )
1186  {
1187  if ( ! l->shortName().isEmpty() )
1188  {
1189  if ( l->shortName() == shortName )
1190  layers << l;
1191  }
1192  else if ( l->name() == shortName )
1193  {
1194  layers << l;
1195  }
1196  }
1197  return layers;
1198  }
1199 
1200 #endif
1201 
1227  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1228  bool addToLegend = true,
1229  bool takeOwnership SIP_PYARGREMOVE = true );
1230 
1258  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1259  bool addToLegend = true,
1260  bool takeOwnership SIP_PYARGREMOVE = true );
1261 
1276  void removeMapLayers( const QStringList &layerIds );
1277 
1278  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1279 
1293  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1294 
1308  void removeMapLayer( const QString &layerId );
1309 
1323  void removeMapLayer( QgsMapLayer *layer );
1324 
1332  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1333 
1345  QgsAnnotationLayer *mainAnnotationLayer();
1346 
1357  void removeAllMapLayers();
1358 
1364  void reloadAllLayers();
1365 
1370  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1371 
1383  Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1384 
1395  Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1396 
1402  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1403 
1409  QgsAuxiliaryStorage *auxiliaryStorage();
1410 
1419  QString createAttachedFile( const QString &nameTemplate );
1420 
1427  QStringList attachedFiles() const;
1428 
1436  bool removeAttachedFile( const QString &path );
1437 
1446  QString attachmentIdentifier( const QString &attachedFile ) const;
1447 
1454  QString resolveAttachmentIdentifier( const QString &identifier ) const;
1455 
1462  const QgsProjectMetadata &metadata() const;
1463 
1470  void setMetadata( const QgsProjectMetadata &metadata );
1471 
1480  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1481 
1490  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1491 
1498  void setProjectColors( const QgsNamedColorList &colors );
1499 
1506  void setBackgroundColor( const QColor &color );
1507 
1514  QColor backgroundColor() const;
1515 
1522  void setSelectionColor( const QColor &color );
1523 
1530  QColor selectionColor() const;
1531 
1543  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1544 
1556  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1557 
1566  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1567 
1576  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1577 
1582  void generateTsFile( const QString &locale );
1583 
1594  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1595 
1605  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1606 
1607 #ifdef SIP_RUN
1608  SIP_PYOBJECT __repr__();
1609  % MethodCode
1610  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1611  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1612  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1613  % End
1614 #endif
1615 
1616  signals:
1617 
1625  void cleared();
1626 
1630  void readProject( const QDomDocument & );
1631 
1635  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1636 
1640  void writeProject( QDomDocument & );
1641 
1650  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1651 
1660  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1661 
1666 
1672  Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1673 
1684  void readVersionMismatchOccurred( const QString &fileVersion );
1685 
1691  void layerLoaded( int i, int n );
1692 
1694  void loadingLayer( const QString &layerName );
1695 
1702  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1703 
1708  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1709 
1712 
1720 
1725 
1732 
1738 
1744  void crsChanged();
1745 
1753  void ellipsoidChanged( const QString &ellipsoid );
1754 
1755 
1763 
1768  void missingDatumTransforms( const QStringList &missingTransforms );
1769 
1777 
1784 
1791 
1804 
1810 
1818 
1826 
1834 
1842 
1843  //
1844  // signals from QgsMapLayerRegistry
1845  //
1846 
1854  void layersWillBeRemoved( const QStringList &layerIds );
1855 
1863  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1864 
1874  void layerWillBeRemoved( const QString &layerId );
1875 
1886 
1893  void layersRemoved( const QStringList &layerIds );
1894 
1903  void layerRemoved( const QString &layerId );
1904 
1905  //TODO QGIS 4.0 - rename to past tense
1906 
1913  void removeAll();
1914 
1925  void layersAdded( const QList<QgsMapLayer *> &layers );
1926 
1933  void layerWasAdded( QgsMapLayer *layer );
1934 
1943  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1944 
1952  void isDirtyChanged( bool dirty );
1953 
1961  void dirtySet();
1962 
1971  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1972 
1973  public slots:
1974 
1980  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1981 
1982  // TODO QGIS 4.0 - rename b to dirty
1983 
1991  void setDirty( bool b = true );
1992 
2001  void setPresetHomePath( const QString &path );
2002 
2012  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2013 
2020  void registerTranslatableObjects( QgsTranslationContext *translationContext );
2021 
2028  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2029 
2036  QgsPropertyCollection dataDefinedServerProperties() const;
2037 
2054  bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2055 
2080  bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2081 
2090  bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2091 
2092  private slots:
2093  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2094  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2095  void cleanTransactionGroups( bool force = false );
2096  void updateTransactionGroups();
2097 
2098  private:
2099 
2100  static QgsProject *sProject;
2101 
2102 
2111  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2112 
2117  void setError( const QString &errorMessage ) SIP_SKIP;
2118 
2123  void clearError() SIP_SKIP;
2124 
2132  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2133 
2139  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2140 
2145  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2146 
2148  bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2149 
2151  bool writeProjectFile( const QString &filename );
2152 
2154  bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2155 
2157  bool zip( const QString &filename );
2158 
2160  bool saveAuxiliaryStorage( const QString &filename = QString() );
2161 
2163  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2164 
2165  std::unique_ptr< QgsMapLayerStore > mLayerStore;
2166 
2167  QString mErrorMessage;
2168 
2169  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2170 
2176  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2177 
2178  QgsSnappingConfig mSnappingConfig;
2179  Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2180 
2181  QgsRelationManager *mRelationManager = nullptr;
2182 
2183  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2184  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2185  std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2186 
2187  QgsBookmarkManager *mBookmarkManager = nullptr;
2188 
2189  QgsProjectViewSettings *mViewSettings = nullptr;
2190 
2191  QgsProjectStyleSettings *mStyleSettings = nullptr;
2192 
2193  QgsProjectTimeSettings *mTimeSettings = nullptr;
2194 
2195  QgsProjectElevationProperties *mElevationProperties = nullptr;
2196 
2197  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2198 
2199  QgsLayerTree *mRootGroup = nullptr;
2200 
2201  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2202 
2203  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2204 
2206  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2207 
2208  QgsVectorLayerEditBufferGroup mEditBufferGroup;
2209 
2210  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2211 
2212  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2213 
2214  QVariantMap mCustomVariables;
2215 
2216  std::unique_ptr<QgsArchive> mArchive;
2217 
2218  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2219 
2220  QFile mFile; // current physical project file
2221 
2222  QString mOriginalPath;
2223 
2224  QString mSaveUser; // last saved user.
2225  QString mSaveUserFull; // last saved user full name.
2226  QDateTime mSaveDateTime;
2227  QgsProjectVersion mSaveVersion;
2228 
2233  QString mHomePath;
2234  mutable QString mCachedHomePath;
2235 
2236  QColor mBackgroundColor;
2237  QColor mSelectionColor;
2238 
2239  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2240  Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2241 
2242  Qgis::ProjectFlags mFlags;
2244  bool mDirty = false; // project has been modified since it has been read or saved
2245  int mDirtyBlockCount = 0;
2246 
2247  QgsPropertyCollection mDataDefinedServerProperties;
2248 
2249  QgsCoordinateTransformContext mTransformContext;
2250 
2251  QgsProjectMetadata mMetadata;
2252 
2253  std::unique_ptr< QTranslator > mTranslator;
2254 
2255  bool mIsBeingDeleted = false;
2256 
2257  QgsSettings mSettings;
2258 
2259  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2260 
2261  int mBlockSnappingUpdates = 0;
2262 
2264 
2265  // Required to avoid creating a new project in it's destructor
2266  friend class QgsProviderRegistry;
2267 
2268  // Required by QGIS Server for switching the current project instance
2269  friend class QgsServer;
2270 
2271  friend class TestQgsProject;
2272 
2273  Q_DISABLE_COPY( QgsProject )
2274 };
2275 
2297 class CORE_EXPORT QgsProjectDirtyBlocker
2298 {
2299  public:
2300 
2307  : mProject( project )
2308  {
2309  mProject->mDirtyBlockCount++;
2310  }
2311 
2314 
2317 
2319  {
2320  mProject->mDirtyBlockCount--;
2321  }
2322 
2323  private:
2324  QgsProject *mProject = nullptr;
2325 
2326 #ifdef SIP_RUN
2328 #endif
2329 };
2330 
2336 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2337 
2338 
2339 
2341 #ifndef SIP_RUN
2342 class GetNamedProjectColor : public QgsScopedExpressionFunction
2343 {
2344  public:
2345  GetNamedProjectColor( const QgsProject *project );
2346 
2351  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2352 
2353  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2354  QgsScopedExpressionFunction *clone() const override;
2355 
2356  private:
2357 
2358  QHash< QString, QColor > mColors;
2359 
2360 };
2361 
2362 #endif
2364 
2365 #endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:72
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgis.h:1934
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:1827
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
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.
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:2298
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2306
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.
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:104
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:188
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:479
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.
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.
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 readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
QgsMapThemeCollection * mapThemeCollection()
Returns pointer to the project's map theme collection.
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:133
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.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1164
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
void readProject(const QDomDocument &)
Emitted when a project is being read.
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1108
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.
void writeProject(QDomDocument &)
Emitted when the project is being written.
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...
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:1181
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:62
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.
Helper functions for various unit types.
Definition: qgsunittypes.h:39
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:79
#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