QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsproject.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproject.h
3 
4  Implements persistent project state.
5 
6  -------------------
7  begin : July 23, 2004
8  copyright : (C) 2004 by Mark Coletti
9  email : mcoletti at gmail.com
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 #ifndef QGSPROJECT_H
22 #define QGSPROJECT_H
23 
24 #include "qgis_core.h"
25 #include "qgis_sip.h"
26 #include "qgis.h"
27 
28 #include <memory>
29 #include <QHash>
30 #include <QList>
31 #include <QObject>
32 #include <QPair>
33 #include <QFileInfo>
34 #include <QStringList>
35 #include <QTranslator>
36 
37 #include "qgsunittypes.h"
38 #include "qgssnappingconfig.h"
39 #include "qgsprojectversion.h"
44 #include "qgsprojectproperty.h"
45 #include "qgsmaplayerstore.h"
46 #include "qgsarchive.h"
47 #include "qgsreadwritecontext.h"
48 #include "qgsprojectmetadata.h"
49 #include "qgstranslationcontext.h"
50 #include "qgsprojecttranslator.h"
51 #include "qgscolorscheme.h"
52 #include "qgssettings.h"
53 #include "qgspropertycollection.h"
54 
55 #include "qgsrelationmanager.h"
56 #include "qgsmapthemecollection.h"
57 
58 class QFileInfo;
59 class QDomDocument;
60 class QDomElement;
61 class QDomNode;
62 
63 class QgsLayerTreeGroup;
65 class QgsMapLayer;
66 class QgsPathResolver;
68 class QgsProjectStorage;
69 class QgsTolerance;
71 class QgsVectorLayer;
73 class QgsLayoutManager;
74 class QgsLayerTree;
77 class QgsMapLayer;
78 class QgsBookmarkManager;
82 class QgsAnnotationLayer;
83 class QgsAttributeEditorContainer;
85 
86 
101 {
102  Q_OBJECT
103  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
104  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
105  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
106  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
107  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
108  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
109  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
110  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
111  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
112  Q_PROPERTY( AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
113  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
114  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
115  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
116  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
117  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
118 
119  public:
120 
126  {
127  FlagDontResolveLayers = 1 << 0,
128  FlagDontLoadLayouts = 1 << 1,
129  FlagTrustLayerMetadata = 1 << 2,
130  FlagDontStoreOriginalStyles = 1 << 3,
131  };
132  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
133 
134 
138  enum class FileFormat
139  {
140  Qgz,
141  Qgs,
142  };
143  Q_ENUM( FileFormat )
144 
145 
150  {
151  AllowIntersections,
152  AvoidIntersectionsCurrentLayer,
153  AvoidIntersectionsLayers,
154  };
155  Q_ENUM( AvoidIntersectionsMode )
156 
157 
166  {
167  NoProperty = 0,
168  AllProperties = 1,
169  WMSOnlineResource = 2,
170  };
171 
173  static QgsProject *instance();
174 
183  static void setInstance( QgsProject *project ) ;
184 
185 
191  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
192 
193  ~QgsProject() override;
194 
204  void setTitle( const QString &title );
205 
212  QString title() const;
213 
221  QString saveUser() const;
222 
230  QString saveUserFullName() const;
231 
237  QDateTime lastSaveDateTime() const;
238 
244  QgsProjectVersion lastSaveVersion() const;
245 
249  bool isDirty() const;
250 
257  void setFileName( const QString &name );
258 
265  QString fileName() const;
266 
278  void setOriginalPath( const QString &path );
279 
291  QString originalPath() const;
292 
303  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
304 
311  QgsProjectStorage *projectStorage() const;
312 
317  QDateTime lastModified() const;
318 
324  QString absoluteFilePath() const;
325 
331  QString absolutePath() const;
332 
337  QString baseName() const;
338 
345  Qgis::FilePathType filePathStorage() const;
346 
353  void setFilePathStorage( Qgis::FilePathType type );
354 
362 
372  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
373 
380  QString ellipsoid() const;
381 
388  void setEllipsoid( const QString &ellipsoid );
389 
390 
400  QgsCoordinateTransformContext transformContext() const;
401 
411  void setTransformContext( const QgsCoordinateTransformContext &context );
412 
418  void clear();
419 
426  bool read( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
427 
436  bool read( QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
437 
447  bool readLayer( const QDomNode &layerNode );
448 
457  bool write( const QString &filename );
458 
464  bool write();
465 
477  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
478 
490  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
491 
502  bool writeEntry( const QString &scope, const QString &key, int value );
503 
514  bool writeEntry( const QString &scope, const QString &key, const QString &value );
515 
526  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
527 
538  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
539 
550  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
551 
562  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
563 
574  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
575 
586  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
587 
591  bool removeEntry( const QString &scope, const QString &key );
592 
601  QStringList entryList( const QString &scope, const QString &key ) const;
602 
611  QStringList subkeyList( const QString &scope, const QString &key ) const;
612 
613  // TODO Now slightly broken since re-factoring. Won't print out top-level key
614  // and redundantly prints sub-keys.
615 
619  void dumpProperties() const;
620 
626  QgsPathResolver pathResolver() const;
627 
633  QString writePath( const QString &filename ) const;
634 
638  QString readPath( const QString &filename ) const;
639 
641  QString error() const;
642 
647  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
648 
654  QString layerIsEmbedded( const QString &id ) const;
655 
664  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
665  bool saveFlag = true, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
666 
674  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
675 
677  void setTopologicalEditing( bool enabled );
678 
680  bool topologicalEditing() const;
681 
688  QgsUnitTypes::DistanceUnit distanceUnits() const;
689 
696  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
697 
703  QgsUnitTypes::AreaUnit areaUnits() const;
704 
711  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
712 
725  QString homePath() const;
726 
739  QString presetHomePath() const;
740 
741  QgsRelationManager *relationManager() const;
742 
749  const QgsLayoutManager *layoutManager() const SIP_SKIP;
750 
756  QgsLayoutManager *layoutManager();
757 
764  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
765 
771  QgsBookmarkManager *bookmarkManager();
772 
780  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
781 
788  QgsProjectViewSettings *viewSettings();
789 
797  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
798 
805  QgsProjectTimeSettings *timeSettings();
806 
813  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
814 
820  QgsProjectDisplaySettings *displaySettings();
821 
826  QgsLayerTree *layerTreeRoot() const;
827 
832  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
833 
840 
845  QgsAnnotationManager *annotationManager();
846 
851  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
852 
857  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
858 
863  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
864 
869  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
870 
878  bool autoTransaction() const;
879 
889  void setAutoTransaction( bool autoTransaction );
890 
899  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
900 
908  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
909 
915  bool evaluateDefaultValues() const;
916 
922  void setEvaluateDefaultValues( bool evaluateDefaultValues );
923 
924  QgsExpressionContext createExpressionContext() const override;
925  QgsExpressionContextScope *createExpressionContextScope() const override;
926 
932  QgsSnappingConfig snappingConfig() const;
933 
939  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
940 
947  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
948 
954  void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
955 
961  AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
962 
968  QVariantMap customVariables() const;
969 
974  void setCustomVariables( const QVariantMap &customVariables );
975 
980  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
981 
986  const QgsLabelingEngineSettings &labelingEngineSettings() const;
987 
988  //
989  // Functionality from QgsMapLayerRegistry
990  //
991 
996  QgsMapLayerStore *layerStore();
997 
1002  SIP_SKIP const QgsMapLayerStore *layerStore() const;
1003 
1005  int count() const;
1006 
1008  int validCount() const;
1009 
1017  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1018 
1019 #ifndef SIP_RUN
1020 
1036  template <class T>
1037  T mapLayer( const QString &layerId ) const
1038  {
1039  return qobject_cast<T>( mapLayer( layerId ) );
1040  }
1041 #endif
1042 
1050  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1051 
1061  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1062 
1063 
1072  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1073 
1077  bool isZipped() const;
1078 
1079 #ifndef SIP_RUN
1080 
1092  template <typename T>
1093  QVector<T> layers() const
1094  {
1095  return mLayerStore->layers<T>();
1096  }
1097 
1109  template <typename T>
1110  QVector<T> mapLayersByShortName( const QString &shortName ) const
1111  {
1112  QVector<T> layers;
1113  const auto constMapLayers { mLayerStore->layers<T>() };
1114  for ( const auto l : constMapLayers )
1115  {
1116  if ( ! l->shortName().isEmpty() )
1117  {
1118  if ( l->shortName() == shortName )
1119  layers << l;
1120  }
1121  else if ( l->name() == shortName )
1122  {
1123  layers << l;
1124  }
1125  }
1126  return layers;
1127  }
1128 
1129 #endif
1130 
1156  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1157  bool addToLegend = true,
1158  bool takeOwnership SIP_PYARGREMOVE = true );
1159 
1187  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1188  bool addToLegend = true,
1189  bool takeOwnership SIP_PYARGREMOVE = true );
1190 
1205  void removeMapLayers( const QStringList &layerIds );
1206 
1207  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1208 
1222  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1223 
1237  void removeMapLayer( const QString &layerId );
1238 
1252  void removeMapLayer( QgsMapLayer *layer );
1253 
1261  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1262 
1274  QgsAnnotationLayer *mainAnnotationLayer();
1275 
1286  void removeAllMapLayers();
1287 
1293  void reloadAllLayers();
1294 
1299  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1300 
1312  void setTrustLayerMetadata( bool trust );
1313 
1324  bool trustLayerMetadata() const { return mTrustLayerMetadata; }
1325 
1331  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1332 
1338  QgsAuxiliaryStorage *auxiliaryStorage();
1339 
1346  QString createAttachedFile( const QString &nameTemplate );
1347 
1354  QStringList attachedFiles() const;
1355 
1363  bool removeAttachedFile( const QString &path );
1364 
1373  QString attachmentIdentifier( const QString &attachedFile ) const;
1374 
1381  QString resolveAttachmentIdentifier( const QString &identifier ) const;
1382 
1389  const QgsProjectMetadata &metadata() const;
1390 
1397  void setMetadata( const QgsProjectMetadata &metadata );
1398 
1407  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1408 
1417  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1418 
1425  void setProjectColors( const QgsNamedColorList &colors );
1426 
1433  void setBackgroundColor( const QColor &color );
1434 
1441  QColor backgroundColor() const;
1442 
1449  void setSelectionColor( const QColor &color );
1450 
1457  QColor selectionColor() const;
1458 
1470  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1471 
1483  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1484 
1493  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1494 
1503  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1504 
1509  void generateTsFile( const QString &locale );
1510 
1521  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1522 
1532  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1533 
1534 #ifdef SIP_RUN
1535  SIP_PYOBJECT __repr__();
1536  % MethodCode
1537  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1538  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1539  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1540  % End
1541 #endif
1542 
1543  signals:
1544 
1552  void cleared();
1553 
1557  void readProject( const QDomDocument & );
1558 
1562  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1563 
1567  void writeProject( QDomDocument & );
1568 
1577  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1578 
1587  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1588 
1593 
1597  void oldProjectVersionWarning( const QString & );
1598 
1604  void layerLoaded( int i, int n );
1605 
1607  void loadingLayer( const QString &layerName );
1608 
1615  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1616 
1621  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1622 
1625 
1633 
1638 
1645 
1651 
1657  void crsChanged();
1658 
1666  void ellipsoidChanged( const QString &ellipsoid );
1667 
1668 
1676 
1681  void missingDatumTransforms( const QStringList &missingTransforms );
1682 
1690 
1697 
1704 
1717 
1723 
1731 
1739 
1747 
1755 
1756  //
1757  // signals from QgsMapLayerRegistry
1758  //
1759 
1767  void layersWillBeRemoved( const QStringList &layerIds );
1768 
1776  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1777 
1787  void layerWillBeRemoved( const QString &layerId );
1788 
1799 
1806  void layersRemoved( const QStringList &layerIds );
1807 
1816  void layerRemoved( const QString &layerId );
1817 
1818  //TODO QGIS 4.0 - rename to past tense
1819 
1826  void removeAll();
1827 
1838  void layersAdded( const QList<QgsMapLayer *> &layers );
1839 
1846  void layerWasAdded( QgsMapLayer *layer );
1847 
1856  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1857 
1865  void isDirtyChanged( bool dirty );
1866 
1874  void dirtySet();
1875 
1884  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1885 
1886  public slots:
1887 
1893  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1894 
1895  // TODO QGIS 4.0 - rename b to dirty
1896 
1904  void setDirty( bool b = true );
1905 
1914  void setPresetHomePath( const QString &path );
1915 
1925  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1926 
1933  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1934 
1941  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1942 
1949  QgsPropertyCollection dataDefinedServerProperties() const;
1950 
1951  private slots:
1952  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1953  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1954  void cleanTransactionGroups( bool force = false );
1955 
1956  private:
1957 
1958  static QgsProject *sProject;
1959 
1960 
1969  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1970 
1975  void setError( const QString &errorMessage ) SIP_SKIP;
1976 
1981  void clearError() SIP_SKIP;
1982 
1990  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1991 
1997  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1998 
2003  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
2004 
2006  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
2007 
2009  bool writeProjectFile( const QString &filename );
2010 
2012  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
2013 
2015  bool zip( const QString &filename );
2016 
2018  bool saveAuxiliaryStorage( const QString &filename = QString() );
2019 
2021  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2022 
2023  std::unique_ptr< QgsMapLayerStore > mLayerStore;
2024 
2025  QString mErrorMessage;
2026 
2027  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2028 
2034  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2035 
2036  QgsSnappingConfig mSnappingConfig;
2037  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
2038 
2039  QgsRelationManager *mRelationManager = nullptr;
2040 
2041  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2042  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2043 
2044  QgsBookmarkManager *mBookmarkManager = nullptr;
2045 
2046  QgsProjectViewSettings *mViewSettings = nullptr;
2047 
2048  QgsProjectTimeSettings *mTimeSettings = nullptr;
2049 
2050  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2051 
2052  QgsLayerTree *mRootGroup = nullptr;
2053 
2054  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2055 
2056  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2057 
2059  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2060 
2061  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2062 
2063  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2064 
2065  QVariantMap mCustomVariables;
2066 
2067  std::unique_ptr<QgsArchive> mArchive;
2068 
2069  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2070 
2071  QFile mFile; // current physical project file
2072 
2073  QString mOriginalPath;
2074 
2075  QString mSaveUser; // last saved user.
2076  QString mSaveUserFull; // last saved user full name.
2077  QDateTime mSaveDateTime;
2078  QgsProjectVersion mSaveVersion;
2079 
2084  QString mHomePath;
2085  mutable QString mCachedHomePath;
2086 
2087  QColor mBackgroundColor;
2088  QColor mSelectionColor;
2089 
2090  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2091  bool mAutoTransaction = false; // transaction grouped editing
2092  bool mEvaluateDefaultValues = false; // evaluate default values immediately
2094  bool mDirty = false; // project has been modified since it has been read or saved
2095  int mDirtyBlockCount = 0;
2096  bool mTrustLayerMetadata = false;
2097 
2098  QgsPropertyCollection mDataDefinedServerProperties;
2099 
2100  QgsCoordinateTransformContext mTransformContext;
2101 
2102  QgsProjectMetadata mMetadata;
2103 
2104  std::unique_ptr< QTranslator > mTranslator;
2105 
2106  bool mIsBeingDeleted = false;
2107 
2108  QgsSettings mSettings;
2109 
2110  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2111 
2112  int mBlockSnappingUpdates = 0;
2113 
2115 
2116  // Required to avoid creating a new project in it's destructor
2117  friend class QgsProviderRegistry;
2118 
2119  // Required by QGIS Server for switching the current project instance
2120  friend class QgsServer;
2121 
2122  friend class TestQgsProject;
2123 
2124  Q_DISABLE_COPY( QgsProject )
2125 };
2126 
2128 
2150 class CORE_EXPORT QgsProjectDirtyBlocker
2151 {
2152  public:
2153 
2160  : mProject( project )
2161  {
2162  mProject->mDirtyBlockCount++;
2163  }
2164 
2167 
2170 
2172  {
2173  mProject->mDirtyBlockCount--;
2174  }
2175 
2176  private:
2177  QgsProject *mProject = nullptr;
2178 
2179 #ifdef SIP_RUN
2181 #endif
2182 };
2183 
2189 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2190 
2191 
2192 
2194 #ifndef SIP_RUN
2195 class GetNamedProjectColor : public QgsScopedExpressionFunction
2196 {
2197  public:
2198  GetNamedProjectColor( const QgsProject *project );
2199 
2204  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2205 
2206  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2207  QgsScopedExpressionFunction *clone() const override;
2208 
2209  private:
2210 
2211  QHash< QString, QColor > mColors;
2212 
2213 };
2214 
2215 #endif
2217 
2218 #endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:63
Represents a map layer containing a set of georeferenced annotations, e.g.
Manages storage of a set of QgsAnnotation annotation objects.
Class allowing to manage the zip/unzip actions.
Definition: qgsarchive.h:36
Class providing some utility methods to manage auxiliary storage.
Manages storage of a set of bookmarks.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract interface for generating an expression context.
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An expression node for expression functions.
Class for parsing and evaluation of expressions (formerly called "search strings").
Stores global configuration for labeling engine.
Layer tree group node serves as a container for layers and further groups.
Listens to the updates in map layer registry and does changes in layer tree.
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:33
Manages storage of a set of layouts.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Base class for all map layer types.
Definition: qgsmaplayer.h:73
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Resolves relative paths into absolute paths and vice versa.
Interface for classes that handle missing layer files when reading project file.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2151
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2159
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:101
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:166
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:1093
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:150
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
void labelingEngineSettingsChanged()
Emitted when global configuration of the labeling engine changes.
void customVariablesChanged()
Emitted whenever the expression variables stored in the project have been changed.
void readProject(const QDomDocument &)
Emitted when a project is being read.
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1037
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:139
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:1324
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:1110
void backgroundColorChanged()
Emitted whenever the project's canvas background color has been changed.
ReadFlag
Flags which control project read behavior.
Definition: qgsproject.h:126
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
#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
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