QGIS API Documentation  3.19.0-Master (67c226385a)
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"
49 #include "qgscolorscheme.h"
50 #include "qgssettings.h"
51 #include "qgspropertycollection.h"
52 
53 
54 class QFileInfo;
55 class QDomDocument;
56 class QDomElement;
57 class QDomNode;
58 
59 class QgsLayerTreeGroup;
61 class QgsMapLayer;
63 class QgsPathResolver;
65 class QgsProjectStorage;
66 class QgsRelationManager;
67 class QgsTolerance;
69 class QgsVectorLayer;
71 class QgsLayoutManager;
72 class QgsLayerTree;
75 class QgsMapLayer;
76 class QgsBookmarkManager;
80 class QgsAnnotationLayer;
81 class QgsAttributeEditorContainer;
83 
84 
98 class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenerator, public QgsExpressionContextScopeGenerator, public QgsProjectTranslator
99 {
100  Q_OBJECT
101  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
102  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
103  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
104  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
105  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
106  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
107  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
108  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
109  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
110  Q_PROPERTY( AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
111  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
112  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
113  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
114  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
115  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
116 
117  public:
118 
124  {
125  FlagDontResolveLayers = 1 << 0,
126  FlagDontLoadLayouts = 1 << 1,
127  FlagTrustLayerMetadata = 1 << 2,
128  FlagDontStoreOriginalStyles = 1 << 3,
129  };
130  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
131 
132 
136  enum class FileFormat
137  {
138  Qgz,
139  Qgs,
140  };
141  Q_ENUM( FileFormat )
142 
143 
148  {
149  AllowIntersections,
150  AvoidIntersectionsCurrentLayer,
151  AvoidIntersectionsLayers,
152  };
153  Q_ENUM( AvoidIntersectionsMode )
154 
155 
164  {
165  NoProperty = 0,
166  AllProperties = 1,
167  WMSOnlineResource = 2,
168  };
169 
171  static QgsProject *instance();
172 
181  static void setInstance( QgsProject *project ) ;
182 
183 
189  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
190 
191  ~QgsProject() override;
192 
202  void setTitle( const QString &title );
203 
210  QString title() const;
211 
219  QString saveUser() const;
220 
228  QString saveUserFullName() const;
229 
235  QDateTime lastSaveDateTime() const;
236 
242  QgsProjectVersion lastSaveVersion() const;
243 
247  bool isDirty() const;
248 
255  void setFileName( const QString &name );
256 
263  QString fileName() const;
264 
276  void setOriginalPath( const QString &path );
277 
289  QString originalPath() const;
290 
301  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
302 
309  QgsProjectStorage *projectStorage() const;
310 
315  QDateTime lastModified() const;
316 
322  QString absoluteFilePath() const;
323 
329  QString absolutePath() const;
330 
335  QString baseName() const;
336 
344 
354  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
355 
362  QString ellipsoid() const;
363 
370  void setEllipsoid( const QString &ellipsoid );
371 
372 
382  QgsCoordinateTransformContext transformContext() const;
383 
393  void setTransformContext( const QgsCoordinateTransformContext &context );
394 
400  void clear();
401 
408  bool read( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
409 
418  bool read( QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
419 
429  bool readLayer( const QDomNode &layerNode );
430 
439  bool write( const QString &filename );
440 
446  bool write();
447 
459  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
460 
472  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
473 
484  bool writeEntry( const QString &scope, const QString &key, int value );
485 
496  bool writeEntry( const QString &scope, const QString &key, const QString &value );
497 
508  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
509 
520  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
521 
532  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
533 
544  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
545 
556  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
557 
568  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
569 
573  bool removeEntry( const QString &scope, const QString &key );
574 
583  QStringList entryList( const QString &scope, const QString &key ) const;
584 
593  QStringList subkeyList( const QString &scope, const QString &key ) const;
594 
595  // TODO Now slightly broken since re-factoring. Won't print out top-level key
596  // and redundantly prints sub-keys.
597 
601  void dumpProperties() const;
602 
608  QgsPathResolver pathResolver() const;
609 
615  QString writePath( const QString &filename ) const;
616 
620  QString readPath( const QString &filename ) const;
621 
623  QString error() const;
624 
629  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
630 
636  QString layerIsEmbedded( const QString &id ) const;
637 
646  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
647  bool saveFlag = true, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
648 
656  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
657 
659  void setTopologicalEditing( bool enabled );
660 
662  bool topologicalEditing() const;
663 
670  QgsUnitTypes::DistanceUnit distanceUnits() const;
671 
678  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
679 
685  QgsUnitTypes::AreaUnit areaUnits() const;
686 
693  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
694 
707  QString homePath() const;
708 
721  QString presetHomePath() const;
722 
723  QgsRelationManager *relationManager() const;
724 
731  const QgsLayoutManager *layoutManager() const SIP_SKIP;
732 
738  QgsLayoutManager *layoutManager();
739 
746  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
747 
753  QgsBookmarkManager *bookmarkManager();
754 
762  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
763 
770  QgsProjectViewSettings *viewSettings();
771 
779  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
780 
787  QgsProjectTimeSettings *timeSettings();
788 
795  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
796 
802  QgsProjectDisplaySettings *displaySettings();
803 
808  QgsLayerTree *layerTreeRoot() const;
809 
814  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
815 
822 
827  QgsAnnotationManager *annotationManager();
828 
833  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
834 
839  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
840 
845  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
846 
851  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
852 
860  bool autoTransaction() const;
861 
871  void setAutoTransaction( bool autoTransaction );
872 
881  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
882 
890  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
891 
897  bool evaluateDefaultValues() const;
898 
904  void setEvaluateDefaultValues( bool evaluateDefaultValues );
905 
906  QgsExpressionContext createExpressionContext() const override;
907  QgsExpressionContextScope *createExpressionContextScope() const override;
908 
914  QgsSnappingConfig snappingConfig() const;
915 
921  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
922 
929  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
930 
936  void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
937 
943  AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
944 
950  QVariantMap customVariables() const;
951 
956  void setCustomVariables( const QVariantMap &customVariables );
957 
962  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
963 
968  const QgsLabelingEngineSettings &labelingEngineSettings() const;
969 
970  //
971  // Functionality from QgsMapLayerRegistry
972  //
973 
978  QgsMapLayerStore *layerStore();
979 
984  SIP_SKIP const QgsMapLayerStore *layerStore() const;
985 
987  int count() const;
988 
990  int validCount() const;
991 
999  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1000 
1001 #ifndef SIP_RUN
1002 
1018  template <class T>
1019  T mapLayer( const QString &layerId ) const
1020  {
1021  return qobject_cast<T>( mapLayer( layerId ) );
1022  }
1023 #endif
1024 
1032  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1033 
1043  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1044 
1045 
1054  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1055 
1059  bool isZipped() const;
1060 
1061 #ifndef SIP_RUN
1062 
1074  template <typename T>
1075  QVector<T> layers() const
1076  {
1077  return mLayerStore->layers<T>();
1078  }
1079 
1091  template <typename T>
1092  QVector<T> mapLayersByShortName( const QString &shortName ) const
1093  {
1094  QVector<T> layers;
1095  const auto constMapLayers { mLayerStore->layers<T>() };
1096  for ( const auto l : constMapLayers )
1097  {
1098  if ( ! l->shortName().isEmpty() )
1099  {
1100  if ( l->shortName() == shortName )
1101  layers << l;
1102  }
1103  else if ( l->name() == shortName )
1104  {
1105  layers << l;
1106  }
1107  }
1108  return layers;
1109  }
1110 
1111 #endif
1112 
1138  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1139  bool addToLegend = true,
1140  bool takeOwnership SIP_PYARGREMOVE = true );
1141 
1169  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1170  bool addToLegend = true,
1171  bool takeOwnership SIP_PYARGREMOVE = true );
1172 
1187  void removeMapLayers( const QStringList &layerIds );
1188 
1189  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1190 
1204  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1205 
1219  void removeMapLayer( const QString &layerId );
1220 
1234  void removeMapLayer( QgsMapLayer *layer );
1235 
1243  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1244 
1256  QgsAnnotationLayer *mainAnnotationLayer();
1257 
1268  void removeAllMapLayers();
1269 
1275  void reloadAllLayers();
1276 
1281  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1282 
1294  void setTrustLayerMetadata( bool trust );
1295 
1306  bool trustLayerMetadata() const { return mTrustLayerMetadata; }
1307 
1313  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1314 
1320  QgsAuxiliaryStorage *auxiliaryStorage();
1321 
1330  QString attachedFile( const QString &fileName ) const SIP_SKIP;
1331 
1341  QgsStringMap attachedFiles() const SIP_SKIP;
1342 
1349  const QgsProjectMetadata &metadata() const;
1350 
1357  void setMetadata( const QgsProjectMetadata &metadata );
1358 
1367  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1368 
1377  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1378 
1385  void setProjectColors( const QgsNamedColorList &colors );
1386 
1393  void setBackgroundColor( const QColor &color );
1394 
1401  QColor backgroundColor() const;
1402 
1409  void setSelectionColor( const QColor &color );
1410 
1417  QColor selectionColor() const;
1418 
1430  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1431 
1443  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1444 
1453  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1454 
1463  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1464 
1469  void generateTsFile( const QString &locale );
1470 
1481  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1482 
1492  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1493 
1494 #ifdef SIP_RUN
1495  SIP_PYOBJECT __repr__();
1496  % MethodCode
1497  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1498  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1499  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1500  % End
1501 #endif
1502 
1503  signals:
1504 
1512  void cleared();
1513 
1517  void readProject( const QDomDocument & );
1518 
1522  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1523 
1527  void writeProject( QDomDocument & );
1528 
1537  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1538 
1547  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1548 
1553 
1557  void oldProjectVersionWarning( const QString & );
1558 
1564  void layerLoaded( int i, int n );
1565 
1567  void loadingLayer( const QString &layerName );
1568 
1575  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1576 
1581  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1582 
1585 
1593 
1598 
1605 
1611 
1617  void crsChanged();
1618 
1626  void ellipsoidChanged( const QString &ellipsoid );
1627 
1628 
1636 
1641  void missingDatumTransforms( const QStringList &missingTransforms );
1642 
1650 
1657 
1664 
1677 
1683 
1691 
1699 
1707 
1715 
1716  //
1717  // signals from QgsMapLayerRegistry
1718  //
1719 
1727  void layersWillBeRemoved( const QStringList &layerIds );
1728 
1736  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1737 
1747  void layerWillBeRemoved( const QString &layerId );
1748 
1759 
1766  void layersRemoved( const QStringList &layerIds );
1767 
1776  void layerRemoved( const QString &layerId );
1777 
1778  //TODO QGIS 4.0 - rename to past tense
1779 
1786  void removeAll();
1787 
1798  void layersAdded( const QList<QgsMapLayer *> &layers );
1799 
1806  void layerWasAdded( QgsMapLayer *layer );
1807 
1816  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1817 
1825  void isDirtyChanged( bool dirty );
1826 
1841 
1850  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1851 
1852  public slots:
1853 
1859  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1860 
1861  // TODO QGIS 4.0 - rename b to dirty
1862 
1870  void setDirty( bool b = true );
1871 
1880  void setPresetHomePath( const QString &path );
1881 
1891  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1892 
1899  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1900 
1907  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1908 
1915  QgsPropertyCollection dataDefinedServerProperties() const;
1916 
1917  private slots:
1918  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1919  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1920  void cleanTransactionGroups( bool force = false );
1921 
1922  private:
1923 
1924  static QgsProject *sProject;
1925 
1926 
1935  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1936 
1941  void setError( const QString &errorMessage ) SIP_SKIP;
1942 
1947  void clearError() SIP_SKIP;
1948 
1956  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1957 
1963  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1964 
1969  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1970 
1972  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1973 
1975  bool writeProjectFile( const QString &filename );
1976 
1978  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1979 
1981  bool zip( const QString &filename );
1982 
1984  bool saveAuxiliaryStorage( const QString &filename = QString() );
1985 
1987  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
1988 
1989  std::unique_ptr< QgsMapLayerStore > mLayerStore;
1990 
1991  QString mErrorMessage;
1992 
1993  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
1994 
2000  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2001 
2002  QgsSnappingConfig mSnappingConfig;
2003  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
2004 
2005  QgsRelationManager *mRelationManager = nullptr;
2006 
2007  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2008  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2009 
2010  QgsBookmarkManager *mBookmarkManager = nullptr;
2011 
2012  QgsProjectViewSettings *mViewSettings = nullptr;
2013 
2014  QgsProjectTimeSettings *mTimeSettings = nullptr;
2015 
2016  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2017 
2018  QgsLayerTree *mRootGroup = nullptr;
2019 
2020  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2021 
2022  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2023 
2025  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2026 
2027  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2028 
2029  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2030 
2031  QVariantMap mCustomVariables;
2032 
2033  std::unique_ptr<QgsProjectArchive> mArchive;
2034 
2035  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2036 
2037  QFile mFile; // current physical project file
2038 
2039  QString mOriginalPath;
2040 
2041  QString mSaveUser; // last saved user.
2042  QString mSaveUserFull; // last saved user full name.
2043  QDateTime mSaveDateTime;
2044  QgsProjectVersion mSaveVersion;
2045 
2050  QString mHomePath;
2051  mutable QString mCachedHomePath;
2052 
2053  QColor mBackgroundColor;
2054  QColor mSelectionColor;
2055 
2056  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2057  bool mAutoTransaction = false; // transaction grouped editing
2058  bool mEvaluateDefaultValues = false; // evaluate default values immediately
2060  bool mDirty = false; // project has been modified since it has been read or saved
2061  int mDirtyBlockCount = 0;
2062  bool mTrustLayerMetadata = false;
2063 
2064  QgsPropertyCollection mDataDefinedServerProperties;
2065 
2066  QgsCoordinateTransformContext mTransformContext;
2067 
2068  QgsProjectMetadata mMetadata;
2069 
2070  std::unique_ptr< QTranslator > mTranslator;
2071 
2072  bool mIsBeingDeleted = false;
2073 
2074  QgsSettings mSettings;
2075 
2076  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2077 
2078  int mBlockSnappingUpdates = 0;
2079 
2081 
2082  // Required to avoid creating a new project in it's destructor
2083  friend class QgsProviderRegistry;
2084 
2085  // Required by QGIS Server for switching the current project instance
2086  friend class QgsServer;
2087 
2088  friend class TestQgsProject;
2089 
2090  Q_DISABLE_COPY( QgsProject )
2091 };
2092 
2094 
2116 class CORE_EXPORT QgsProjectDirtyBlocker
2117 {
2118  public:
2119 
2126  : mProject( project )
2127  {
2128  mProject->mDirtyBlockCount++;
2129  }
2130 
2133 
2136 
2138  {
2139  mProject->mDirtyBlockCount--;
2140  }
2141 
2142  private:
2143  QgsProject *mProject = nullptr;
2144 
2145 #ifdef SIP_RUN
2147 #endif
2148 };
2149 
2155 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2156 
2157 
2158 
2160 #ifndef SIP_RUN
2161 class GetNamedProjectColor : public QgsScopedExpressionFunction
2162 {
2163  public:
2164  GetNamedProjectColor( const QgsProject *project );
2165 
2170  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2171 
2172  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2173  QgsScopedExpressionFunction *clone() const override;
2174 
2175  private:
2176 
2177  QHash< QString, QColor > mColors;
2178 
2179 };
2180 
2181 #endif
2183 
2184 #endif
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
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:85
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Resolves relative paths into absolute paths and vice versa.
Class allowing to manage the zip/unzip actions on project file.
Definition: qgsarchive.h:116
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:2117
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2125
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...
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 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:99
void layersRemoved(const QStringList &layerIds)
Emitted after one or more layers were removed from the registry.
void mapThemeCollectionChanged()
Emitted when the map theme collection changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:498
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
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:164
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:1075
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:148
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void collectAttachedFiles(QgsStringMap &files)
Emitted whenever the project is saved to a qgz file.
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:1019
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.
FileFormat
Flags which control project read behavior.
Definition: qgsproject.h:137
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.
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
Definition: qgsproject.h:1306
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:1092
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
ReadFlag
Flags which control project read behavior.
Definition: qgsproject.h:124
void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
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 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
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:34
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
QMap< QString, QString > QgsStringMap
Definition: qgis.h:759
#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:146
#define SIP_MONKEYPATCH_SCOPEENUM
Definition: qgis_sip.h:256
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
#define SIP_INOUT
Definition: qgis_sip.h:71
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.
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