QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
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 
901  QgsExpressionContext createExpressionContext() const override;
902  QgsExpressionContextScope *createExpressionContextScope() const override;
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 
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 
1580 
1588 
1593 
1600 
1606 
1612  void crsChanged();
1613 
1621  void ellipsoidChanged( const QString &ellipsoid );
1622 
1623 
1631 
1636  void missingDatumTransforms( const QStringList &missingTransforms );
1637 
1645 
1652 
1659 
1672 
1678 
1686 
1694 
1702 
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 
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 
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 
2085 
2107 class CORE_EXPORT QgsProjectDirtyBlocker
2108 {
2109  public:
2110 
2117  : mProject( project )
2118  {
2119  mProject->mDirtyBlockCount++;
2120  }
2121 
2124 
2127 
2129  {
2130  mProject->mDirtyBlockCount--;
2131  }
2132 
2133  private:
2134  QgsProject *mProject = nullptr;
2135 
2136 #ifdef SIP_RUN
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
QgsProject::layersRemoved
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
QgsProject::layerWillBeRemoved
void layerWillBeRemoved(const QString &layerId)
Emitted when a layer is about to be removed from the registry.
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsProject::transactionGroupsChanged
void transactionGroupsChanged()
Emitted whenever a new transaction group has been created or a transaction group has been removed.
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsProject::DataDefinedServerProperty
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:159
QgsProject::layers
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1070
qgscolorscheme.h
qgstranslationcontext.h
QgsTransactionGroup
Definition: qgstransactiongroup.h:32
QgsProject::trustLayerMetadata
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
Definition: qgsproject.h:1301
QgsLayoutManager
Manages storage of a set of layouts.
Definition: qgslayoutmanager.h:45
QgsRelationManager
This class manages a set of relations between layers.
Definition: qgsrelationmanager.h:35
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsProject::layersWillBeRemoved
void layersWillBeRemoved(const QStringList &layerIds)
Emitted when one or more layers are about to be removed from the registry.
QgsProject::fileNameChanged
void fileNameChanged()
Emitted when the file name of the project changes.
QgsProject::mapThemeCollectionChanged
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsProjectMetadata
A structured metadata store for a map layer.
Definition: qgsprojectmetadata.h:54
QgsProject::layersAdded
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
QgsProject::collectAttachedFiles
void collectAttachedFiles(QgsStringMap &files)
Emitted whenever the project is saved to a qgz file.
QgsProviderRegistry
A registry / canonical manager of data providers.
Definition: qgsproviderregistry.h:55
qgsreadwritecontext.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsProject::cleared
void cleared()
Emitted when the project is cleared (and additionally when an open project is cleared just before a n...
QgsProjectDisplaySettings
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Definition: qgsprojectdisplaysettings.h:37
QgsNamedColorList
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Definition: qgscolorscheme.h:34
QgsProjectDirtyBlocker::operator=
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProject::avoidIntersectionsLayersChanged
void avoidIntersectionsLayersChanged()
Emitted whenever avoidIntersectionsLayers has changed.
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:468
QgsProject::readProject
void readProject(const QDomDocument &)
Emitted when a project is being read.
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
qgsunittypes.h
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:145
QgsProject::layerWasAdded
void layerWasAdded(QgsMapLayer *layer)
Emitted when a layer was added to the registry.
QgsExpressionContextScopeGenerator
Abstract interface for generating an expression context scope.
Definition: qgsexpressioncontextscopegenerator.h:29
QgsProject::ReadFlag
ReadFlag
Flags which control project read behavior.
Definition: qgsproject.h:120
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
qgsmaplayerstore.h
QgsProject::homePathChanged
void homePathChanged()
Emitted when the home path of the project changes.
QgsProjectStorage
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
Definition: qgsprojectstorage.h:38
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
SIP_TRANSFERBACK
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
qgssnappingconfig.h
qgsprojecttranslator.h
QgsProject::selectionColorChanged
void selectionColorChanged()
Emitted whenever the project's selection color has been changed.
QgsProject::writeProject
void writeProject(QDomDocument &)
Emitted when the project is being written.
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsProject::writeMapLayer
void writeMapLayer(QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc)
Emitted when a layer is being saved.
QgsProject::mapThemeCollection
QgsMapThemeCollection * mapThemeCollection()
Returns pointer to the project's map theme collection.
QgsProject::crsChanged
void crsChanged()
Emitted when the CRS of the project has changed.
QgsMapLayerStore
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Definition: qgsmaplayerstore.h:36
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsProject::layerWillBeRemoved
void layerWillBeRemoved(QgsMapLayer *layer)
Emitted when a layer is about to be removed from the registry.
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayerTree
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:33
QgsProject::removeAll
void removeAll()
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals ar...
QgsProject::AvoidIntersectionsMode
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:143
QgsProject::nonIdentifiableLayersChanged
Q_DECL_DEPRECATED void nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers)
Emitted when the list of layer which are excluded from map identification changes.
QgsProjectDirtyBlocker::~QgsProjectDirtyBlocker
~QgsProjectDirtyBlocker()
Definition: qgsproject.h:2128
QgsProject::layersWillBeRemoved
void layersWillBeRemoved(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers are about to be removed from the registry.
QgsProject::projectSaved
void projectSaved()
Emitted when the project file has been written and closed.
QgsProject::loadingLayer
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
QgsLabelingEngineSettings
Stores global configuration for labeling engine.
Definition: qgslabelingenginesettings.h:31
QgsProjectDirtyBlocker::QgsProjectDirtyBlocker
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2116
QgsProject::backgroundColorChanged
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
QgsProject::FileFormat
FileFormat
Flags which control project read behavior.
Definition: qgsproject.h:132
QgsProject::projectColorsChanged
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
qgis_sip.h
QgsProject::readMapLayer
void readMapLayer(QgsMapLayer *mapLayer, const QDomElement &layerNode)
Emitted after the basic initialization of a layer from the project file is done.
QgsProjectBadLayerHandler
Interface for classes that handle missing layer files when reading project file.
Definition: qgsprojectbadlayerhandler.h:28
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:35
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsProject::layerRemoved
void layerRemoved(const QString &layerId)
Emitted after a layer was removed from the registry.
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:39
QgsAnnotationManager
Manages storage of a set of QgsAnnotation annotation objects.
Definition: qgsannotationmanager.h:45
QgsSnappingConfig
This is a container for configuration of the snapping of the project.
Definition: qgssnappingconfig.h:34
QgsTranslationContext
Used for the collecting of strings from projects for translation and creation of ts files.
Definition: qgstranslationcontext.h:36
QgsProjectViewSettings
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas,...
Definition: qgsprojectviewsettings.h:35
QgsExpressionNodeFunction
An expression node for expression functions.
Definition: qgsexpressionnodeimpl.h:317
QgsProject::transformContextChanged
void transformContextChanged()
Emitted when the project transformContext() is changed.
qgsprojectmetadata.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsServer
The QgsServer class provides OGC web services.
Definition: qgsserver.h:49
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext.
Definition: qgsexpressioncontext.h:112
qgsprojectproperty.h
SIP_INOUT
#define SIP_INOUT
Definition: qgis_sip.h:71
qgsexpressioncontextgenerator.h
QgsProjectTimeSettings
Contains temporal settings and properties for the project, this may be used when animating maps or sh...
Definition: qgsprojecttimesettings.h:37
QgsProject::legendLayersAdded
void legendLayersAdded(const QList< QgsMapLayer * > &layers)
Emitted, when a layer was added to the registry and the legend.
QgsProject::mapLayer
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1014
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:319
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:758
QgsProjectTranslator
Wherever an object of this class is available, the derived translate function can be called from.
Definition: qgsprojecttranslator.h:31
QgsProjectPropertyKey
Project property key node.
Definition: qgsprojectproperty.h:184
QgsZipUtils::unzip
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:34
QgsTolerance
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:33
QgsProjectDirtyBlocker
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2108
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsAttributeEditorContainer
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Definition: qgsattributeeditorelement.h:172
QgsAnnotationLayer
Represents a map layer containing a set of georeferenced annotations, e.g.
Definition: qgsannotationlayer.h:40
QgsProject::ellipsoidChanged
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
QgsProject::labelingEngineSettingsChanged
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
QgsProject::metadataChanged
void metadataChanged()
Emitted when the project's metadata is changed.
QgsAuxiliaryStorage
Class providing some utility methods to manage auxiliary storage.
Definition: qgsauxiliarystorage.h:260
QgsProject::mapLayersByShortName
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
QgsProject::avoidIntersectionsModeChanged
void avoidIntersectionsModeChanged()
Emitted whenever the avoid intersections mode has changed.
QgsProject::isDirtyChanged
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
qgsexpressioncontextscopegenerator.h
QgsProjectArchive
Class allowing to manage the zip/unzip actions on project file.
Definition: qgsarchive.h:116
QgsProject::readProjectWithContext
void readProjectWithContext(const QDomDocument &, QgsReadWriteContext &context)
Emitted when a project is being read.
QgsMapThemeCollection
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Definition: qgsmapthemecollection.h:45
QgsProject::oldProjectVersionWarning
void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
QgsProject::customVariablesChanged
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
QgsProjectDirtyBlocker::QgsProjectDirtyBlocker
QgsProjectDirtyBlocker(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
qgsprojectversion.h
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
qgsattributeeditorelement.h
QgsProject::snappingConfigChanged
void snappingConfigChanged(const QgsSnappingConfig &config)
Emitted whenever the configuration for snapping has changed.
qgsarchive.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:37
QgsScopedExpressionFunction
Expression function for use within a QgsExpressionContextScope.
Definition: qgsexpressioncontext.h:38
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
QgsZipUtils::zip
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
Definition: qgsziputils.cpp:132
QgsLayerTreeRegistryBridge
Listens to the updates in map layer registry and does changes in layer tree.
Definition: qgslayertreeregistrybridge.h:45
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32
QgsProject::missingDatumTransforms
void missingDatumTransforms(const QStringList &missingTransforms)
Emitted when datum transforms stored in the project are not available locally.
QgsProject::mapScalesChanged
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
QgsProjectVersion
A class to describe the version of a project.
Definition: qgsprojectversion.h:32
QgsProject::layerLoaded
void layerLoaded(int i, int n)
Emitted when a layer from a projects was read.
getVersion
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
Definition: qgsproject.cpp:1009
QgsProject::loadingLayerMessageReceived
void loadingLayerMessageReceived(const QString &layerName, const QList< QgsReadWriteContext::ReadWriteMessage > &messages)
Emitted when loading layers has produced some messages.
QgsProject::topologicalEditingChanged
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
SIP_MONKEYPATCH_SCOPEENUM
#define SIP_MONKEYPATCH_SCOPEENUM
Definition: qgis_sip.h:256