QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #include "qgsrelationmanager.h"
54 #include "qgsmapthemecollection.h"
55 
56 class QFileInfo;
57 class QDomDocument;
58 class QDomElement;
59 class QDomNode;
60 
61 class QgsLayerTreeGroup;
63 class QgsMapLayer;
64 class QgsPathResolver;
66 class QgsProjectStorage;
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 
1834  void dirtySet();
1835 
1850 
1859  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1860 
1861  public slots:
1862 
1868  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1869 
1870  // TODO QGIS 4.0 - rename b to dirty
1871 
1879  void setDirty( bool b = true );
1880 
1889  void setPresetHomePath( const QString &path );
1890 
1900  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1901 
1908  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1909 
1916  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1917 
1924  QgsPropertyCollection dataDefinedServerProperties() const;
1925 
1926  private slots:
1927  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1928  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1929  void cleanTransactionGroups( bool force = false );
1930 
1931  private:
1932 
1933  static QgsProject *sProject;
1934 
1935 
1944  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1945 
1950  void setError( const QString &errorMessage ) SIP_SKIP;
1951 
1956  void clearError() SIP_SKIP;
1957 
1965  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1966 
1972  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1973 
1978  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1979 
1981  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1982 
1984  bool writeProjectFile( const QString &filename );
1985 
1987  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1988 
1990  bool zip( const QString &filename );
1991 
1993  bool saveAuxiliaryStorage( const QString &filename = QString() );
1994 
1996  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
1997 
1998  std::unique_ptr< QgsMapLayerStore > mLayerStore;
1999 
2000  QString mErrorMessage;
2001 
2002  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2003 
2009  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2010 
2011  QgsSnappingConfig mSnappingConfig;
2012  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
2013 
2014  QgsRelationManager *mRelationManager = nullptr;
2015 
2016  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2017  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2018 
2019  QgsBookmarkManager *mBookmarkManager = nullptr;
2020 
2021  QgsProjectViewSettings *mViewSettings = nullptr;
2022 
2023  QgsProjectTimeSettings *mTimeSettings = nullptr;
2024 
2025  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2026 
2027  QgsLayerTree *mRootGroup = nullptr;
2028 
2029  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2030 
2031  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2032 
2034  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2035 
2036  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2037 
2038  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2039 
2040  QVariantMap mCustomVariables;
2041 
2042  std::unique_ptr<QgsProjectArchive> mArchive;
2043 
2044  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2045 
2046  QFile mFile; // current physical project file
2047 
2048  QString mOriginalPath;
2049 
2050  QString mSaveUser; // last saved user.
2051  QString mSaveUserFull; // last saved user full name.
2052  QDateTime mSaveDateTime;
2053  QgsProjectVersion mSaveVersion;
2054 
2059  QString mHomePath;
2060  mutable QString mCachedHomePath;
2061 
2062  QColor mBackgroundColor;
2063  QColor mSelectionColor;
2064 
2065  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2066  bool mAutoTransaction = false; // transaction grouped editing
2067  bool mEvaluateDefaultValues = false; // evaluate default values immediately
2069  bool mDirty = false; // project has been modified since it has been read or saved
2070  int mDirtyBlockCount = 0;
2071  bool mTrustLayerMetadata = false;
2072 
2073  QgsPropertyCollection mDataDefinedServerProperties;
2074 
2075  QgsCoordinateTransformContext mTransformContext;
2076 
2077  QgsProjectMetadata mMetadata;
2078 
2079  std::unique_ptr< QTranslator > mTranslator;
2080 
2081  bool mIsBeingDeleted = false;
2082 
2083  QgsSettings mSettings;
2084 
2085  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2086 
2087  int mBlockSnappingUpdates = 0;
2088 
2090 
2091  // Required to avoid creating a new project in it's destructor
2092  friend class QgsProviderRegistry;
2093 
2094  // Required by QGIS Server for switching the current project instance
2095  friend class QgsServer;
2096 
2097  friend class TestQgsProject;
2098 
2099  Q_DISABLE_COPY( QgsProject )
2100 };
2101 
2103 
2125 class CORE_EXPORT QgsProjectDirtyBlocker
2126 {
2127  public:
2128 
2135  : mProject( project )
2136  {
2137  mProject->mDirtyBlockCount++;
2138  }
2139 
2142 
2145 
2147  {
2148  mProject->mDirtyBlockCount--;
2149  }
2150 
2151  private:
2152  QgsProject *mProject = nullptr;
2153 
2154 #ifdef SIP_RUN
2156 #endif
2157 };
2158 
2164 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2165 
2166 
2167 
2169 #ifndef SIP_RUN
2170 class GetNamedProjectColor : public QgsScopedExpressionFunction
2171 {
2172  public:
2173  GetNamedProjectColor( const QgsProject *project );
2174 
2179  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2180 
2181  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2182  QgsScopedExpressionFunction *clone() const override;
2183 
2184  private:
2185 
2186  QHash< QString, QColor > mColors;
2187 
2188 };
2189 
2190 #endif
2192 
2193 #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:70
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:2126
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2134
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:467
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 dirtySet()
Emitted when setDirty(true) is called.
void layersAdded(const QList< QgsMapLayer * > &layers)
Emitted when one or more layers were added to the registry.
void isDirtyChanged(bool dirty)
Emitted when the project dirty status changes.
void topologicalEditingChanged()
Emitted when the topological editing flag has changed.
void avoidIntersectionsModeChanged()
Emitted whenever the avoid intersections mode has changed.
void loadingLayer(const QString &layerName)
Emitted when a layer is loaded.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A registry / canonical manager of data providers.
The class is used as a container of context for various read/write operations on other objects.
This class manages a set of relations between layers.
Expression function for use within a QgsExpressionContextScope.
The QgsServer class provides OGC web services.
Definition: qgsserver.h:49
This 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
#define str(x)
Definition: qgis.cpp:37
QMap< QString, QString > QgsStringMap
Definition: qgis.h:1041
#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