QGIS API Documentation  3.17.0-Master (a035f434f4)
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 <memory>
27 #include <QHash>
28 #include <QList>
29 #include <QObject>
30 #include <QPair>
31 #include <QFileInfo>
32 #include <QStringList>
33 #include <QTranslator>
34 
35 #include "qgsunittypes.h"
36 #include "qgssnappingconfig.h"
37 #include "qgsprojectversion.h"
42 #include "qgsprojectproperty.h"
43 #include "qgsmaplayerstore.h"
44 #include "qgsarchive.h"
45 #include "qgsreadwritecontext.h"
46 #include "qgsprojectmetadata.h"
47 #include "qgstranslationcontext.h"
48 #include "qgsprojecttranslator.h"
50 #include "qgscolorscheme.h"
51 
52 class QFileInfo;
53 class QDomDocument;
54 class QDomElement;
55 class QDomNode;
56 
57 class QgsLayerTreeGroup;
59 class QgsMapLayer;
61 class QgsPathResolver;
63 class QgsProjectStorage;
64 class QgsRelationManager;
65 class QgsTolerance;
67 class QgsVectorLayer;
69 class QgsLayoutManager;
70 class QgsLayerTree;
73 class QgsMapLayer;
74 class QgsBookmarkManager;
78 class QgsAnnotationLayer;
79 
80 
94 class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenerator, public QgsExpressionContextScopeGenerator, public QgsProjectTranslator
95 {
96  Q_OBJECT
97  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
98  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
99  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
100  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
101  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
102  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
103  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
104  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
105  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
106  Q_PROPERTY( AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
107  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
108  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
109  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
110  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
111  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
112 
113  public:
114 
120  {
121  FlagDontResolveLayers = 1 << 0,
122  FlagDontLoadLayouts = 1 << 1,
123  FlagTrustLayerMetadata = 1 << 2,
124  };
125  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
126 
127 
131  enum class FileFormat
132  {
133  Qgz,
134  Qgs,
135  };
136  Q_ENUM( FileFormat )
137 
138 
143  {
144  AllowIntersections,
145  AvoidIntersectionsCurrentLayer,
146  AvoidIntersectionsLayers,
147  };
148  Q_ENUM( AvoidIntersectionsMode )
149 
150 
159  {
160  NoProperty = 0,
161  AllProperties = 1,
162  WMSOnlineResource = 2,
163  };
164 
166  static QgsProject *instance();
167 
176  static void setInstance( QgsProject *project ) ;
177 
178 
184  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
185 
186  ~QgsProject() override;
187 
197  void setTitle( const QString &title );
198 
205  QString title() const;
206 
214  QString saveUser() const;
215 
223  QString saveUserFullName() const;
224 
230  QDateTime lastSaveDateTime() const;
231 
237  QgsProjectVersion lastSaveVersion() const;
238 
242  bool isDirty() const;
243 
250  void setFileName( const QString &name );
251 
258  QString fileName() const;
259 
271  void setOriginalPath( const QString &path );
272 
284  QString originalPath() const;
285 
296  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
297 
304  QgsProjectStorage *projectStorage() const;
305 
310  QDateTime lastModified() const;
311 
317  QString absoluteFilePath() const;
318 
324  QString absolutePath() const;
325 
330  QString baseName() const;
331 
339 
349  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
350 
357  QString ellipsoid() const;
358 
365  void setEllipsoid( const QString &ellipsoid );
366 
367 
377  QgsCoordinateTransformContext transformContext() const;
378 
388  void setTransformContext( const QgsCoordinateTransformContext &context );
389 
395  void clear();
396 
403  bool read( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
404 
413  bool read( QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
414 
424  bool readLayer( const QDomNode &layerNode );
425 
434  bool write( const QString &filename );
435 
441  bool write();
442 
454  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
455 
467  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
468 
479  bool writeEntry( const QString &scope, const QString &key, int value );
480 
491  bool writeEntry( const QString &scope, const QString &key, const QString &value );
492 
503  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
504 
515  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
516 
527  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
528 
539  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
540 
551  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
552 
563  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
564 
568  bool removeEntry( const QString &scope, const QString &key );
569 
578  QStringList entryList( const QString &scope, const QString &key ) const;
579 
588  QStringList subkeyList( const QString &scope, const QString &key ) const;
589 
590  // TODO Now slightly broken since re-factoring. Won't print out top-level key
591  // and redundantly prints sub-keys.
592 
596  void dumpProperties() const;
597 
603  QgsPathResolver pathResolver() const;
604 
610  QString writePath( const QString &filename ) const;
611 
615  QString readPath( const QString &filename ) const;
616 
618  QString error() const;
619 
624  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
625 
631  QString layerIsEmbedded( const QString &id ) const;
632 
641  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
642  bool saveFlag = true, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
643 
651  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
652 
654  void setTopologicalEditing( bool enabled );
655 
657  bool topologicalEditing() const;
658 
665  QgsUnitTypes::DistanceUnit distanceUnits() const;
666 
673  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
674 
680  QgsUnitTypes::AreaUnit areaUnits() const;
681 
688  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
689 
702  QString homePath() const;
703 
716  QString presetHomePath() const;
717 
718  QgsRelationManager *relationManager() const;
719 
726  const QgsLayoutManager *layoutManager() const SIP_SKIP;
727 
733  QgsLayoutManager *layoutManager();
734 
741  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
742 
748  QgsBookmarkManager *bookmarkManager();
749 
757  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
758 
765  QgsProjectViewSettings *viewSettings();
766 
774  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
775 
782  QgsProjectTimeSettings *timeSettings();
783 
790  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
791 
797  QgsProjectDisplaySettings *displaySettings();
798 
803  QgsLayerTree *layerTreeRoot() const;
804 
809  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
810 
816  QgsMapThemeCollection *mapThemeCollection();
817 
822  QgsAnnotationManager *annotationManager();
823 
828  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
829 
834  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
835 
840  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
841 
846  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
847 
855  bool autoTransaction() const;
856 
866  void setAutoTransaction( bool autoTransaction );
867 
876  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
877 
885  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
886 
892  bool evaluateDefaultValues() const;
893 
899  void setEvaluateDefaultValues( bool evaluateDefaultValues );
900 
903 
909  QgsSnappingConfig snappingConfig() const;
910 
916  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
917 
924  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
925 
931  void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
932 
938  AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
939 
945  QVariantMap customVariables() const;
946 
951  void setCustomVariables( const QVariantMap &customVariables );
952 
957  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
958 
963  const QgsLabelingEngineSettings &labelingEngineSettings() const;
964 
965  //
966  // Functionality from QgsMapLayerRegistry
967  //
968 
973  QgsMapLayerStore *layerStore();
974 
979  SIP_SKIP const QgsMapLayerStore *layerStore() const;
980 
982  int count() const;
983 
985  int validCount() const;
986 
994  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
995 
996 #ifndef SIP_RUN
997 
1013  template <class T>
1014  T mapLayer( const QString &layerId ) const
1015  {
1016  return qobject_cast<T>( mapLayer( layerId ) );
1017  }
1018 #endif
1019 
1027  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1028 
1038  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1039 
1040 
1049  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1050 
1054  bool isZipped() const;
1055 
1056 #ifndef SIP_RUN
1057 
1069  template <typename T>
1070  QVector<T> layers() const
1071  {
1072  return mLayerStore->layers<T>();
1073  }
1074 
1086  template <typename T>
1087  QVector<T> mapLayersByShortName( const QString &shortName ) const
1088  {
1089  QVector<T> layers;
1090  const auto constMapLayers { mLayerStore->layers<T>() };
1091  for ( const auto l : constMapLayers )
1092  {
1093  if ( ! l->shortName().isEmpty() )
1094  {
1095  if ( l->shortName() == shortName )
1096  layers << l;
1097  }
1098  else if ( l->name() == shortName )
1099  {
1100  layers << l;
1101  }
1102  }
1103  return layers;
1104  }
1105 
1106 #endif
1107 
1133  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1134  bool addToLegend = true,
1135  bool takeOwnership SIP_PYARGREMOVE = true );
1136 
1164  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1165  bool addToLegend = true,
1166  bool takeOwnership SIP_PYARGREMOVE = true );
1167 
1182  void removeMapLayers( const QStringList &layerIds );
1183 
1184  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1185 
1199  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1200 
1214  void removeMapLayer( const QString &layerId );
1215 
1229  void removeMapLayer( QgsMapLayer *layer );
1230 
1238  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1239 
1251  QgsAnnotationLayer *mainAnnotationLayer();
1252 
1263  void removeAllMapLayers();
1264 
1270  void reloadAllLayers();
1271 
1276  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1277 
1289  void setTrustLayerMetadata( bool trust );
1290 
1301  bool trustLayerMetadata() const { return mTrustLayerMetadata; }
1302 
1308  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1309 
1315  QgsAuxiliaryStorage *auxiliaryStorage();
1316 
1325  QString attachedFile( const QString &fileName ) const SIP_SKIP;
1326 
1336  QgsStringMap attachedFiles() const SIP_SKIP;
1337 
1344  const QgsProjectMetadata &metadata() const;
1345 
1352  void setMetadata( const QgsProjectMetadata &metadata );
1353 
1362  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1363 
1372  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1373 
1380  void setProjectColors( const QgsNamedColorList &colors );
1381 
1388  void setBackgroundColor( const QColor &color );
1389 
1396  QColor backgroundColor() const;
1397 
1404  void setSelectionColor( const QColor &color );
1405 
1412  QColor selectionColor() const;
1413 
1425  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1426 
1438  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1439 
1448  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1449 
1458  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1459 
1464  void generateTsFile( const QString &locale );
1465 
1476  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1477 
1487  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1488 
1489 #ifdef SIP_RUN
1490  SIP_PYOBJECT __repr__();
1491  % MethodCode
1492  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1493  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1494  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1495  % End
1496 #endif
1497 
1498  signals:
1499 
1507  void cleared();
1508 
1512  void readProject( const QDomDocument & );
1513 
1517  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1518 
1522  void writeProject( QDomDocument & );
1523 
1532  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1533 
1542  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1543 
1547  void projectSaved();
1548 
1552  void oldProjectVersionWarning( const QString & );
1553 
1559  void layerLoaded( int i, int n );
1560 
1562  void loadingLayer( const QString &layerName );
1563 
1570  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1571 
1576  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1577 
1579  void fileNameChanged();
1580 
1587  void homePathChanged();
1588 
1592  void snappingConfigChanged( const QgsSnappingConfig &config );
1593 
1599  void avoidIntersectionsModeChanged();
1600 
1605  void customVariablesChanged();
1606 
1612  void crsChanged();
1613 
1621  void ellipsoidChanged( const QString &ellipsoid );
1622 
1623 
1630  void transformContextChanged();
1631 
1636  void missingDatumTransforms( const QStringList &missingTransforms );
1637 
1644  void transactionGroupsChanged();
1645 
1651  void topologicalEditingChanged();
1652 
1658  void avoidIntersectionsLayersChanged();
1659 
1671  void mapThemeCollectionChanged();
1672 
1677  void labelingEngineSettingsChanged();
1678 
1685  void metadataChanged();
1686 
1693  void projectColorsChanged();
1694 
1701  void backgroundColorChanged();
1702 
1709  void selectionColorChanged();
1710 
1711  //
1712  // signals from QgsMapLayerRegistry
1713  //
1714 
1722  void layersWillBeRemoved( const QStringList &layerIds );
1723 
1731  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1732 
1742  void layerWillBeRemoved( const QString &layerId );
1743 
1753  void layerWillBeRemoved( QgsMapLayer *layer );
1754 
1761  void layersRemoved( const QStringList &layerIds );
1762 
1771  void layerRemoved( const QString &layerId );
1772 
1773  //TODO QGIS 4.0 - rename to past tense
1774 
1781  void removeAll();
1782 
1793  void layersAdded( const QList<QgsMapLayer *> &layers );
1794 
1801  void layerWasAdded( QgsMapLayer *layer );
1802 
1811  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1812 
1820  void isDirtyChanged( bool dirty );
1821 
1835  void collectAttachedFiles( QgsStringMap &files SIP_INOUT ) SIP_SKIP;
1836 
1845  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1846 
1847  public slots:
1848 
1854  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1855 
1856  // TODO QGIS 4.0 - rename b to dirty
1857 
1865  void setDirty( bool b = true );
1866 
1875  void setPresetHomePath( const QString &path );
1876 
1886  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1887 
1894  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1895 
1902  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1903 
1910  QgsPropertyCollection dataDefinedServerProperties() const;
1911 
1912  private slots:
1913  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1914  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1915  void cleanTransactionGroups( bool force = false );
1916 
1917  private:
1918 
1919  static QgsProject *sProject;
1920 
1921 
1930  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1931 
1936  void setError( const QString &errorMessage ) SIP_SKIP;
1937 
1942  void clearError() SIP_SKIP;
1943 
1951  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1952 
1958  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1959 
1964  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1965 
1967  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1968 
1970  bool writeProjectFile( const QString &filename );
1971 
1973  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1974 
1976  bool zip( const QString &filename );
1977 
1979  bool saveAuxiliaryStorage( const QString &filename = QString() );
1980 
1982  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
1983 
1984  std::unique_ptr< QgsMapLayerStore > mLayerStore;
1985 
1986  QString mErrorMessage;
1987 
1988  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
1989 
1995  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
1996 
1997  QgsSnappingConfig mSnappingConfig;
1998  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
1999 
2000  QgsRelationManager *mRelationManager = nullptr;
2001 
2002  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2003  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2004 
2005  QgsBookmarkManager *mBookmarkManager = nullptr;
2006 
2007  QgsProjectViewSettings *mViewSettings = nullptr;
2008 
2009  QgsProjectTimeSettings *mTimeSettings = nullptr;
2010 
2011  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2012 
2013  QgsLayerTree *mRootGroup = nullptr;
2014 
2015  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2016 
2017  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2018 
2020  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2021 
2022  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2023 
2024  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2025 
2026  QVariantMap mCustomVariables;
2027 
2028  std::unique_ptr<QgsProjectArchive> mArchive;
2029 
2030  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2031 
2032  QFile mFile; // current physical project file
2033 
2034  QString mOriginalPath;
2035 
2036  QString mSaveUser; // last saved user.
2037  QString mSaveUserFull; // last saved user full name.
2038  QDateTime mSaveDateTime;
2039  QgsProjectVersion mSaveVersion;
2040 
2045  QString mHomePath;
2046  mutable QString mCachedHomePath;
2047 
2048  QColor mBackgroundColor;
2049  QColor mSelectionColor;
2050 
2051  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2052  bool mAutoTransaction = false; // transaction grouped editing
2053  bool mEvaluateDefaultValues = false; // evaluate default values immediately
2055  bool mDirty = false; // project has been modified since it has been read or saved
2056  int mDirtyBlockCount = 0;
2057  bool mTrustLayerMetadata = false;
2058 
2059  QgsPropertyCollection mDataDefinedServerProperties;
2060 
2061  QgsCoordinateTransformContext mTransformContext;
2062 
2063  QgsProjectMetadata mMetadata;
2064 
2065  std::unique_ptr< QTranslator > mTranslator;
2066 
2067  bool mIsBeingDeleted = false;
2068 
2069  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2070 
2072 
2073  // Required to avoid creating a new project in it's destructor
2074  friend class QgsProviderRegistry;
2075 
2076  // Required by QGIS Server for switching the current project instance
2077  friend class QgsServer;
2078 
2079  friend class TestQgsProject;
2080 
2081  Q_DISABLE_COPY( QgsProject )
2082 };
2083 
2084 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProject::ReadFlags )
2085 
2086 
2107 class CORE_EXPORT QgsProjectDirtyBlocker
2108 {
2109  public:
2110 
2117  : mProject( project )
2118  {
2119  mProject->mDirtyBlockCount++;
2120  }
2121 
2123  QgsProjectDirtyBlocker( const QgsProjectDirtyBlocker &other ) = delete;
2124 
2126  QgsProjectDirtyBlocker &operator=( const QgsProjectDirtyBlocker &other ) = delete;
2127 
2129  {
2130  mProject->mDirtyBlockCount--;
2131  }
2132 
2133  private:
2134  QgsProject *mProject = nullptr;
2135 
2136 #ifdef SIP_RUN
2137  QgsProjectDirtyBlocker( const QgsProjectDirtyBlocker &other );
2138 #endif
2139 };
2140 
2146 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2147 
2148 
2149 
2151 #ifndef SIP_RUN
2152 class GetNamedProjectColor : public QgsScopedExpressionFunction
2153 {
2154  public:
2155  GetNamedProjectColor( const QgsProject *project );
2156 
2161  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2162 
2163  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2164  QgsScopedExpressionFunction *clone() const override;
2165 
2166  private:
2167 
2168  QHash< QString, QColor > mColors;
2169 
2170 };
2171 
2172 #endif
2173 
2175 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
Contains temporal settings and properties for the project, this may be used when animating maps or sh...
Base class for all map layer types.
Definition: qgsmaplayer.h:83
AvoidIntersectionsMode avoidIntersectionsMode() const
Returns the current avoid intersections mode.
Definition: qgsproject.h:938
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Manages storage of a set of QgsAnnotation annotation objects.
Represents a map layer containing a set of georeferenced annotations, e.g.
Helper functions for various unit types.
Definition: qgsunittypes.h:38
Class providing some utility methods to manage auxiliary storage.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
#define SIP_MONKEYPATCH_SCOPEENUM
Definition: qgis_sip.h:256
Manages storage of a set of bookmarks.
#define SIP_INOUT
Definition: qgis_sip.h:71
const QgsCoordinateReferenceSystem & crs
An interface for classes which can visit style entity (e.g.
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
QMap< QString, QString > QgsStringMap
Definition: qgis.h:759
FileFormat
Flags which control project read behavior.
Definition: qgsproject.h:131
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1014
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
Definition: qgsproject.h:1301
ReadFlag
Flags which control project read behavior.
Definition: qgsproject.h:119
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:34
#define SIP_SKIP
Definition: qgis_sip.h:126
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
A class to describe the version of a project.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:32
Listens to the updates in map layer registry and does changes in layer tree.
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:158
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:94
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
Contains information about the context in which a coordinate transform is executed.
Wherever an object of this class is available, the derived translate function can be called from...
The QgsServer class provides OGC web services.
Definition: qgsserver.h:48
Manages storage of a set of layouts.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Used for the collecting of strings from projects for translation and creation of ts files...
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Abstract interface for generating an expression context.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas...
A registry / canonical manager of data providers.
Project property key node.
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1070
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Abstract interface for generating an expression context scope.
This class manages a set of relations between layers.
#define SIP_OUT
Definition: qgis_sip.h:58
Stores global configuration for labeling engine.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:469
This class represents a coordinate reference system (CRS).
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2116
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2107
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Container class that allows storage of map themes consisting of visible map layers and layer styles...
This is a container for configuration of the snapping of the project.
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:142
Resolves relative paths into absolute paths and vice versa.
Represents a vector layer which manages a vector based data sets.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
Expression function for use within a QgsExpressionContextScope.
Interface for classes that handle missing layer files when reading project file.
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:1087
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
A structured metadata store for a map layer.