QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
55 
56 #include "qgsrelationmanager.h"
57 #include "qgsmapthemecollection.h"
58 
59 class QFileInfo;
60 class QDomDocument;
61 class QDomElement;
62 class QDomNode;
63 
64 class QgsLayerTreeGroup;
66 class QgsMapLayer;
67 class QgsPathResolver;
69 class QgsProjectStorage;
70 class QgsTolerance;
72 class QgsVectorLayer;
74 class QgsLayoutManager;
75 class QgsLayerTree;
78 class QgsMapLayer;
79 class QgsBookmarkManager;
84 class QgsAnnotationLayer;
87 class QgsMapViewsManager;
89 
104 {
105  Q_OBJECT
106  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
107  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
108  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
109  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
110  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
111  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
112  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
113  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
114  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
115  Q_PROPERTY( Qgis::AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
116  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
117  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
118  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
119  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
120  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
121 
122  public:
123 
133  {
134  NoProperty = 0,
135  AllProperties = 1,
136  WMSOnlineResource = 2,
137  };
138 
140  static QgsProject *instance();
141 
150  static void setInstance( QgsProject *project ) ;
151 
160  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr, Qgis::ProjectCapabilities capabilities = Qgis::ProjectCapability::ProjectStyles );
161 
162  ~QgsProject() override;
163 
173  void setTitle( const QString &title );
174 
181  QString title() const;
182 
189  Qgis::ProjectCapabilities capabilities() const { return mCapabilities; }
190 
199  Qgis::ProjectFlags flags() const { return mFlags; }
200 
209  void setFlags( Qgis::ProjectFlags flags );
210 
219  void setFlag( Qgis::ProjectFlag flag, bool enabled = true );
220 
228  QString saveUser() const;
229 
237  QString saveUserFullName() const;
238 
244  QDateTime lastSaveDateTime() const;
245 
251  QgsProjectVersion lastSaveVersion() const;
252 
256  bool isDirty() const;
257 
264  void setFileName( const QString &name );
265 
272  QString fileName() const;
273 
285  void setOriginalPath( const QString &path );
286 
298  QString originalPath() const;
299 
310  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
311 
318  QgsProjectStorage *projectStorage() const;
319 
324  QDateTime lastModified() const;
325 
331  QString absoluteFilePath() const;
332 
338  QString absolutePath() const;
339 
344  QString baseName() const;
345 
352  Qgis::FilePathType filePathStorage() const;
353 
360  void setFilePathStorage( Qgis::FilePathType type );
361 
369 
379  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
380 
387  QString ellipsoid() const;
388 
395  void setEllipsoid( const QString &ellipsoid );
396 
397 
407  QgsCoordinateTransformContext transformContext() const;
408 
418  void setTransformContext( const QgsCoordinateTransformContext &context );
419 
425  void clear();
426 
433  bool read( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
434 
443  bool read( Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
444 
454  bool readLayer( const QDomNode &layerNode );
455 
464  bool write( const QString &filename );
465 
471  bool write();
472 
484  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
485 
497  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
498 
509  bool writeEntry( const QString &scope, const QString &key, int value );
510 
521  bool writeEntry( const QString &scope, const QString &key, const QString &value );
522 
533  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
534 
545  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
546 
557  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
558 
569  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
570 
581  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
582 
593  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
594 
598  bool removeEntry( const QString &scope, const QString &key );
599 
608  QStringList entryList( const QString &scope, const QString &key ) const;
609 
618  QStringList subkeyList( const QString &scope, const QString &key ) const;
619 
620  // TODO Now slightly broken since re-factoring. Won't print out top-level key
621  // and redundantly prints sub-keys.
622 
626  void dumpProperties() const;
627 
633  QgsPathResolver pathResolver() const;
634 
640  QString writePath( const QString &filename ) const;
641 
645  QString readPath( const QString &filename ) const;
646 
648  QString error() const;
649 
654  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
655 
661  QString layerIsEmbedded( const QString &id ) const;
662 
671  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
672  bool saveFlag = true, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
673 
681  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
682 
684  void setTopologicalEditing( bool enabled );
685 
687  bool topologicalEditing() const;
688 
695  QgsUnitTypes::DistanceUnit distanceUnits() const;
696 
703  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
704 
710  QgsUnitTypes::AreaUnit areaUnits() const;
711 
718  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
719 
732  QString homePath() const;
733 
746  QString presetHomePath() const;
747 
748  QgsRelationManager *relationManager() const;
749 
756  const QgsLayoutManager *layoutManager() const SIP_SKIP;
757 
763  QgsLayoutManager *layoutManager();
764 
771  const QgsMapViewsManager *viewsManager() const SIP_SKIP;
772 
778  QgsMapViewsManager *viewsManager();
779 
786  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
787 
793  QgsBookmarkManager *bookmarkManager();
794 
802  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
803 
810  QgsProjectViewSettings *viewSettings();
811 
819  const QgsProjectStyleSettings *styleSettings() const SIP_SKIP;
820 
827  QgsProjectStyleSettings *styleSettings();
828 
836  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
837 
844  QgsProjectTimeSettings *timeSettings();
845 
852  const QgsProjectElevationProperties *elevationProperties() const SIP_SKIP;
853 
859  QgsProjectElevationProperties *elevationProperties();
860 
867  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
868 
874  QgsProjectDisplaySettings *displaySettings();
875 
880  QgsLayerTree *layerTreeRoot() const;
881 
886  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
887 
893  QgsMapThemeCollection *mapThemeCollection();
894 
899  QgsAnnotationManager *annotationManager();
900 
905  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
906 
911  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
912 
917  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
918 
923  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
924 
933  Q_DECL_DEPRECATED bool autoTransaction() const SIP_DEPRECATED;
934 
945  Q_DECL_DEPRECATED void setAutoTransaction( bool autoTransaction ) SIP_DEPRECATED;
946 
953  Qgis::TransactionMode transactionMode() const;
954 
964  bool setTransactionMode( Qgis::TransactionMode transactionMode );
965 
974  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
975 
983  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
984 
990  QgsVectorLayerEditBufferGroup *editBufferGroup();
991 
997  Q_DECL_DEPRECATED bool evaluateDefaultValues() const SIP_DEPRECATED;
998 
1004  Q_DECL_DEPRECATED void setEvaluateDefaultValues( bool evaluateDefaultValues ) SIP_DEPRECATED;
1005 
1006  QgsExpressionContext createExpressionContext() const override;
1007  QgsExpressionContextScope *createExpressionContextScope() const override;
1008 
1014  QgsSnappingConfig snappingConfig() const;
1015 
1021  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
1022 
1029  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
1030 
1036  void setAvoidIntersectionsMode( const Qgis::AvoidIntersectionsMode mode );
1037 
1043  Qgis::AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
1044 
1050  QVariantMap customVariables() const;
1051 
1056  void setCustomVariables( const QVariantMap &customVariables );
1057 
1062  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
1063 
1068  const QgsLabelingEngineSettings &labelingEngineSettings() const;
1069 
1070  //
1071  // Functionality from QgsMapLayerRegistry
1072  //
1073 
1078  QgsMapLayerStore *layerStore();
1079 
1084  SIP_SKIP const QgsMapLayerStore *layerStore() const;
1085 
1087  int count() const;
1088 
1090  int validCount() const;
1091 
1099  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1100 
1101 #ifndef SIP_RUN
1102 
1118  template <class T>
1119  T mapLayer( const QString &layerId ) const
1120  {
1121  return qobject_cast<T>( mapLayer( layerId ) );
1122  }
1123 #endif
1124 
1132  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1133 
1143  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1144 
1145 
1154  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1155 
1159  bool isZipped() const;
1160 
1161 #ifndef SIP_RUN
1162 
1174  template <typename T>
1175  QVector<T> layers() const
1176  {
1177  return mLayerStore->layers<T>();
1178  }
1179 
1191  template <typename T>
1192  QVector<T> mapLayersByShortName( const QString &shortName ) const
1193  {
1194  QVector<T> layers;
1195  const auto constMapLayers { mLayerStore->layers<T>() };
1196  for ( const auto l : constMapLayers )
1197  {
1198  if ( ! l->shortName().isEmpty() )
1199  {
1200  if ( l->shortName() == shortName )
1201  layers << l;
1202  }
1203  else if ( l->name() == shortName )
1204  {
1205  layers << l;
1206  }
1207  }
1208  return layers;
1209  }
1210 
1211 #endif
1212 
1238  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1239  bool addToLegend = true,
1240  bool takeOwnership SIP_PYARGREMOVE = true );
1241 
1269  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1270  bool addToLegend = true,
1271  bool takeOwnership SIP_PYARGREMOVE = true );
1272 
1287  void removeMapLayers( const QStringList &layerIds );
1288 
1289  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1290 
1304  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1305 
1319  void removeMapLayer( const QString &layerId );
1320 
1334  void removeMapLayer( QgsMapLayer *layer );
1335 
1343  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1344 
1356  QgsAnnotationLayer *mainAnnotationLayer();
1357 
1368  void removeAllMapLayers();
1369 
1375  void reloadAllLayers();
1376 
1381  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1382 
1394  Q_DECL_DEPRECATED void setTrustLayerMetadata( bool trust ) SIP_DEPRECATED;
1395 
1406  Q_DECL_DEPRECATED bool trustLayerMetadata() const SIP_DEPRECATED;
1407 
1413  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1414 
1420  QgsAuxiliaryStorage *auxiliaryStorage();
1421 
1430  QString createAttachedFile( const QString &nameTemplate );
1431 
1438  QStringList attachedFiles() const;
1439 
1447  bool removeAttachedFile( const QString &path );
1448 
1457  QString attachmentIdentifier( const QString &attachedFile ) const;
1458 
1465  QString resolveAttachmentIdentifier( const QString &identifier ) const;
1466 
1473  const QgsProjectMetadata &metadata() const;
1474 
1481  void setMetadata( const QgsProjectMetadata &metadata );
1482 
1491  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1492 
1501  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1502 
1509  void setProjectColors( const QgsNamedColorList &colors );
1510 
1517  void setBackgroundColor( const QColor &color );
1518 
1525  QColor backgroundColor() const;
1526 
1533  void setSelectionColor( const QColor &color );
1534 
1541  QColor selectionColor() const;
1542 
1554  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1555 
1567  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1568 
1577  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1578 
1587  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1588 
1593  void generateTsFile( const QString &locale );
1594 
1605  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1606 
1616  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1617 
1618 #ifdef SIP_RUN
1619  SIP_PYOBJECT __repr__();
1620  % MethodCode
1621  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1622  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1623  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1624  % End
1625 #endif
1626 
1627  signals:
1628 
1636  void cleared();
1637 
1641  void readProject( const QDomDocument & );
1642 
1646  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1647 
1651  void writeProject( QDomDocument & );
1652 
1661  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1662 
1671  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1672 
1676  void projectSaved();
1677 
1683  Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1684 
1695  void readVersionMismatchOccurred( const QString &fileVersion );
1696 
1702  void layerLoaded( int i, int n );
1703 
1705  void loadingLayer( const QString &layerName );
1706 
1713  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1714 
1719  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1720 
1722  void fileNameChanged();
1723 
1730  void homePathChanged();
1731 
1735  void snappingConfigChanged( const QgsSnappingConfig &config );
1736 
1742  void avoidIntersectionsModeChanged();
1743 
1748  void customVariablesChanged();
1749 
1755  void crsChanged();
1756 
1764  void ellipsoidChanged( const QString &ellipsoid );
1765 
1766 
1773  void transformContextChanged();
1774 
1779  void missingDatumTransforms( const QStringList &missingTransforms );
1780 
1787  void transactionGroupsChanged();
1788 
1794  void topologicalEditingChanged();
1795 
1801  void avoidIntersectionsLayersChanged();
1802 
1814  void mapThemeCollectionChanged();
1815 
1820  void labelingEngineSettingsChanged();
1821 
1828  void metadataChanged();
1829 
1836  void projectColorsChanged();
1837 
1844  void backgroundColorChanged();
1845 
1852  void selectionColorChanged();
1853 
1854  //
1855  // signals from QgsMapLayerRegistry
1856  //
1857 
1865  void layersWillBeRemoved( const QStringList &layerIds );
1866 
1874  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1875 
1885  void layerWillBeRemoved( const QString &layerId );
1886 
1896  void layerWillBeRemoved( QgsMapLayer *layer );
1897 
1904  void layersRemoved( const QStringList &layerIds );
1905 
1914  void layerRemoved( const QString &layerId );
1915 
1916  //TODO QGIS 4.0 - rename to past tense
1917 
1924  void removeAll();
1925 
1936  void layersAdded( const QList<QgsMapLayer *> &layers );
1937 
1944  void layerWasAdded( QgsMapLayer *layer );
1945 
1954  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1955 
1963  void isDirtyChanged( bool dirty );
1964 
1972  void dirtySet();
1973 
1982  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1983 
1984  public slots:
1985 
1991  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1992 
1993  // TODO QGIS 4.0 - rename b to dirty
1994 
2002  void setDirty( bool b = true );
2003 
2012  void setPresetHomePath( const QString &path );
2013 
2023  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
2024 
2031  void registerTranslatableObjects( QgsTranslationContext *translationContext );
2032 
2039  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
2040 
2047  QgsPropertyCollection dataDefinedServerProperties() const;
2048 
2065  bool startEditing( QgsVectorLayer *vectorLayer = nullptr );
2066 
2094  bool commitChanges( QStringList &commitErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2095 
2110  bool rollBack( QStringList &rollbackErrors SIP_OUT, bool stopEditing = true, QgsVectorLayer *vectorLayer = nullptr );
2111 
2112  private slots:
2113  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
2114  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
2115  void cleanTransactionGroups( bool force = false );
2116  void updateTransactionGroups();
2117 
2118  private:
2119 
2120  static QgsProject *sProject;
2121 
2122 
2131  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2132 
2137  void setError( const QString &errorMessage ) SIP_SKIP;
2138 
2143  void clearError() SIP_SKIP;
2144 
2152  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2153 
2159  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2160 
2165  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() ) SIP_SKIP;
2166 
2168  bool readProjectFile( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2169 
2171  bool writeProjectFile( const QString &filename );
2172 
2174  bool unzip( const QString &filename, Qgis::ProjectReadFlags flags = Qgis::ProjectReadFlags() );
2175 
2177  bool zip( const QString &filename );
2178 
2180  bool saveAuxiliaryStorage( const QString &filename = QString() );
2181 
2183  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2184 
2185  Qgis::ProjectCapabilities mCapabilities;
2186 
2187  std::unique_ptr< QgsMapLayerStore > mLayerStore;
2188 
2189  QString mErrorMessage;
2190 
2191  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2192 
2198  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2199 
2200  QgsSnappingConfig mSnappingConfig;
2201  Qgis::AvoidIntersectionsMode mAvoidIntersectionsMode = Qgis::AvoidIntersectionsMode::AllowIntersections;
2202 
2203  QgsRelationManager *mRelationManager = nullptr;
2204 
2205  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2206  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2207  std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2208 
2209  QgsBookmarkManager *mBookmarkManager = nullptr;
2210 
2211  QgsProjectViewSettings *mViewSettings = nullptr;
2212 
2213  QgsProjectStyleSettings *mStyleSettings = nullptr;
2214 
2215  QgsProjectTimeSettings *mTimeSettings = nullptr;
2216 
2217  QgsProjectElevationProperties *mElevationProperties = nullptr;
2218 
2219  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2220 
2221  QgsLayerTree *mRootGroup = nullptr;
2222 
2223  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2224 
2225  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2226 
2228  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2229 
2230  QgsVectorLayerEditBufferGroup mEditBufferGroup;
2231 
2232  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2233 
2234  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2235 
2236  QVariantMap mCustomVariables;
2237 
2238  std::unique_ptr<QgsArchive> mArchive;
2239 
2240  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2241 
2242  QFile mFile; // current physical project file
2243 
2244  QString mOriginalPath;
2245 
2246  QString mSaveUser; // last saved user.
2247  QString mSaveUserFull; // last saved user full name.
2248  QDateTime mSaveDateTime;
2249  QgsProjectVersion mSaveVersion;
2250 
2255  QString mHomePath;
2256  mutable QString mCachedHomePath;
2257 
2258  QColor mBackgroundColor;
2259  QColor mSelectionColor;
2260 
2261  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2262  Qgis::TransactionMode mTransactionMode = Qgis::TransactionMode::Disabled; // transaction grouped editing
2263 
2264  Qgis::ProjectFlags mFlags;
2266  bool mDirty = false; // project has been modified since it has been read or saved
2267  int mDirtyBlockCount = 0;
2268 
2269  QgsPropertyCollection mDataDefinedServerProperties;
2270 
2271  QgsCoordinateTransformContext mTransformContext;
2272 
2273  QgsProjectMetadata mMetadata;
2274 
2275  std::unique_ptr< QTranslator > mTranslator;
2276 
2277  bool mIsBeingDeleted = false;
2278 
2279  QgsSettings mSettings;
2280 
2281  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2282 
2283  int mBlockSnappingUpdates = 0;
2284 
2286 
2287  // Required to avoid creating a new project in it's destructor
2288  friend class QgsProviderRegistry;
2289 
2290  // Required by QGIS Server for switching the current project instance
2291  friend class QgsServer;
2292 
2293  friend class TestQgsProject;
2294 
2295  Q_DISABLE_COPY( QgsProject )
2296 };
2297 
2319 class CORE_EXPORT QgsProjectDirtyBlocker
2320 {
2321  public:
2322 
2329  : mProject( project )
2330  {
2331  mProject->mDirtyBlockCount++;
2332  }
2333 
2335  QgsProjectDirtyBlocker( const QgsProjectDirtyBlocker &other ) = delete;
2336 
2338  QgsProjectDirtyBlocker &operator=( const QgsProjectDirtyBlocker &other ) = delete;
2339 
2341  {
2342  mProject->mDirtyBlockCount--;
2343  }
2344 
2345  private:
2346  QgsProject *mProject = nullptr;
2347 
2348 #ifdef SIP_RUN
2350 #endif
2351 };
2352 
2358 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2359 
2360 
2361 
2363 #ifndef SIP_RUN
2364 class GetNamedProjectColor : public QgsScopedExpressionFunction
2365 {
2366  public:
2367  GetNamedProjectColor( const QgsProject *project );
2368 
2373  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2374 
2375  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2376  QgsScopedExpressionFunction *clone() const override;
2377 
2378  private:
2379 
2380  QHash< QString, QColor > mColors;
2381 
2382 };
2383 
2384 #endif
2385 
2387 #endif
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
qgsvectorlayereditbuffergroup.h
QgsProject::DataDefinedServerProperty
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:132
QgsProject::layers
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:1175
qgscolorscheme.h
qgstranslationcontext.h
QgsTransactionGroup
Definition: qgstransactiongroup.h:31
QgsLayoutManager
Manages storage of a set of layouts.
Definition: qgslayoutmanager.h:44
QgsRelationManager
This class manages a set of relations between layers.
Definition: qgsrelationmanager.h:35
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsProjectMetadata
A structured metadata store for a map layer.
Definition: qgsprojectmetadata.h:53
qgsmapthemecollection.h
QgsProviderRegistry
A registry / canonical manager of data providers.
Definition: qgsproviderregistry.h:60
qgsreadwritecontext.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsProjectStyleSettings
Contains settings and properties relating to how a QgsProject should handle styling.
Definition: qgsprojectstylesettings.h:43
qgscoordinatetransformcontext.h
QgsVectorLayerEditBufferGroup
The edit buffer group manages a group of edit buffers.
Definition: qgsvectorlayereditbuffergroup.h:38
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsProjectDisplaySettings
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Definition: qgsprojectdisplaysettings.h:37
QgsNamedColorList
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Definition: qgscolorscheme.h:34
QgsMapViewsManager
Manages storage of a set of views.
Definition: qgsmapviewsmanager.h:40
qgis.h
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
qgsunittypes.h
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:145
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsExpressionContextScopeGenerator
Abstract interface for generating an expression context scope.
Definition: qgsexpressioncontextscopegenerator.h:28
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:151
QgsProjectElevationProperties
Contains elevation properties for a QgsProject.
Definition: qgsprojectelevationproperties.h:38
qgsmaplayerstore.h
QgsProjectStorage
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
Definition: qgsprojectstorage.h:36
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
SIP_TRANSFERBACK
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
qgssnappingconfig.h
qgsprojecttranslator.h
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsMapLayerStore
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Definition: qgsmaplayerstore.h:35
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayerTree
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
QgsProjectDirtyBlocker::~QgsProjectDirtyBlocker
~QgsProjectDirtyBlocker()
Definition: qgsproject.h:2340
QgsLabelingEngineSettings
Stores global configuration for labeling engine.
Definition: qgslabelingenginesettings.h:31
QgsProjectDirtyBlocker::QgsProjectDirtyBlocker
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2328
QgsProject::flags
Qgis::ProjectFlags flags() const
Returns the project's flags, which dictate the behavior of the project.
Definition: qgsproject.h:199
qgis_sip.h
QgsProjectBadLayerHandler
Interface for classes that handle missing layer files when reading project file.
Definition: qgsprojectbadlayerhandler.h:27
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayerTreeGroup
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:40
QgsUnitTypes
Helper functions for various unit types.
Definition: qgsunittypes.h:38
QgsAnnotationManager
Manages storage of a set of QgsAnnotation annotation objects.
Definition: qgsannotationmanager.h:44
QgsProject::capabilities
Qgis::ProjectCapabilities capabilities() const
Returns the project's capabilities, which dictate optional functionality which can be selectively ena...
Definition: qgsproject.h:189
QgsSnappingConfig
This is a container for configuration of the snapping of the project.
Definition: qgssnappingconfig.h:37
QgsTranslationContext
Used for the collecting of strings from projects for translation and creation of ts files.
Definition: qgstranslationcontext.h:35
QgsProjectViewSettings
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas,...
Definition: qgsprojectviewsettings.h:35
QgsExpressionNodeFunction
An expression node for expression functions.
Definition: qgsexpressionnodeimpl.h:395
qgsrelationmanager.h
qgsprojectmetadata.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsServer
The QgsServer class provides OGC web services.
Definition: qgsserver.h:48
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
qgsprojectproperty.h
qgsexpressioncontextgenerator.h
QgsProjectTimeSettings
Contains temporal settings and properties for the project, this may be used when animating maps or sh...
Definition: qgsprojecttimesettings.h:36
QgsProject::mapLayer
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
Definition: qgsproject.h:1119
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
Qgis::ProjectFlag
ProjectFlag
Flags which control the behavior of QgsProjects.
Definition: qgis.h:1808
QgsProjectTranslator
Wherever an object of this class is available, the derived translate function can be called from.
Definition: qgsprojecttranslator.h:30
QgsProjectPropertyKey
Project property key node.
Definition: qgsprojectproperty.h:183
QgsZipUtils::unzip
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:37
QgsTolerance
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:32
QgsProjectDirtyBlocker
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2319
str
#define str(x)
Definition: qgis.cpp:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsAttributeEditorContainer
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Definition: qgsattributeeditorcontainer.h:27
QgsAnnotationLayer
Represents a map layer containing a set of georeferenced annotations, e.g. markers,...
Definition: qgsannotationlayer.h:46
qgssettings.h
qgspropertycollection.h
QgsAuxiliaryStorage
Class providing some utility methods to manage auxiliary storage.
Definition: qgsauxiliarystorage.h:291
QgsProject::mapLayersByShortName
QVector< T > mapLayersByShortName(const QString &shortName) const
Retrieves a list of matching registered layers by layer shortName with a specified layer type,...
Definition: qgsproject.h:1192
Qgis
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:71
qgsexpressioncontextscopegenerator.h
QgsArchive
Class allowing to manage the zip/unzip actions.
Definition: qgsarchive.h:35
QgsMapThemeCollection
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Definition: qgsmapthemecollection.h:44
qgsprojectversion.h
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings")....
Definition: qgsexpression.h:102
qgsarchive.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
QgsScopedExpressionFunction
Expression function for use within a QgsExpressionContextScope. This differs from a standard QgsExpre...
Definition: qgsexpressioncontext.h:39
Qgis::ProjectCapability::ProjectStyles
@ ProjectStyles
Enable the project embedded style library. Enabling this flag can increase the time required to clear...
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgscoordinatereferencesystem.h
QgsZipUtils::zip
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
Definition: qgsziputils.cpp:135
QgsLayerTreeRegistryBridge
Listens to the updates in map layer registry and does changes in layer tree.
Definition: qgslayertreeregistrybridge.h:44
QgsPathResolver
Resolves relative paths into absolute paths and vice versa. Used for writing.
Definition: qgspathresolver.h:31
QgsProjectVersion
A class to describe the version of a project.
Definition: qgsprojectversion.h:32
getVersion
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
Definition: qgsproject.cpp:1170