QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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;
85 class QgsMapViewsManager;
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  FlagDontLoad3DViews = 1 << 4,
132  };
133  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
134 
135 
139  enum class FileFormat
140  {
141  Qgz,
142  Qgs,
143  };
144  Q_ENUM( FileFormat )
145 
146 
151  {
152  AllowIntersections,
153  AvoidIntersectionsCurrentLayer,
154  AvoidIntersectionsLayers,
155  };
156  Q_ENUM( AvoidIntersectionsMode )
157 
158 
167  {
168  NoProperty = 0,
169  AllProperties = 1,
170  WMSOnlineResource = 2,
171  };
172 
174  static QgsProject *instance();
175 
184  static void setInstance( QgsProject *project ) ;
185 
186 
192  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
193 
194  ~QgsProject() override;
195 
205  void setTitle( const QString &title );
206 
213  QString title() const;
214 
222  QString saveUser() const;
223 
231  QString saveUserFullName() const;
232 
238  QDateTime lastSaveDateTime() const;
239 
245  QgsProjectVersion lastSaveVersion() const;
246 
250  bool isDirty() const;
251 
258  void setFileName( const QString &name );
259 
266  QString fileName() const;
267 
279  void setOriginalPath( const QString &path );
280 
292  QString originalPath() const;
293 
304  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
305 
312  QgsProjectStorage *projectStorage() const;
313 
318  QDateTime lastModified() const;
319 
325  QString absoluteFilePath() const;
326 
332  QString absolutePath() const;
333 
338  QString baseName() const;
339 
346  Qgis::FilePathType filePathStorage() const;
347 
354  void setFilePathStorage( Qgis::FilePathType type );
355 
363 
373  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
374 
381  QString ellipsoid() const;
382 
389  void setEllipsoid( const QString &ellipsoid );
390 
391 
401  QgsCoordinateTransformContext transformContext() const;
402 
412  void setTransformContext( const QgsCoordinateTransformContext &context );
413 
419  void clear();
420 
427  bool read( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
428 
437  bool read( QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
438 
448  bool readLayer( const QDomNode &layerNode );
449 
458  bool write( const QString &filename );
459 
465  bool write();
466 
478  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
479 
491  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
492 
503  bool writeEntry( const QString &scope, const QString &key, int value );
504 
515  bool writeEntry( const QString &scope, const QString &key, const QString &value );
516 
527  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
528 
539  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok SIP_OUT = nullptr ) const;
540 
551  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok SIP_OUT = nullptr ) const;
552 
563  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok SIP_OUT = nullptr ) const;
564 
575  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok SIP_OUT = nullptr ) const;
576 
587  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok SIP_OUT = nullptr ) const;
588 
592  bool removeEntry( const QString &scope, const QString &key );
593 
602  QStringList entryList( const QString &scope, const QString &key ) const;
603 
612  QStringList subkeyList( const QString &scope, const QString &key ) const;
613 
614  // TODO Now slightly broken since re-factoring. Won't print out top-level key
615  // and redundantly prints sub-keys.
616 
620  void dumpProperties() const;
621 
627  QgsPathResolver pathResolver() const;
628 
634  QString writePath( const QString &filename ) const;
635 
639  QString readPath( const QString &filename ) const;
640 
642  QString error() const;
643 
648  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
649 
655  QString layerIsEmbedded( const QString &id ) const;
656 
665  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
666  bool saveFlag = true, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
667 
675  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
676 
678  void setTopologicalEditing( bool enabled );
679 
681  bool topologicalEditing() const;
682 
689  QgsUnitTypes::DistanceUnit distanceUnits() const;
690 
697  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
698 
704  QgsUnitTypes::AreaUnit areaUnits() const;
705 
712  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
713 
726  QString homePath() const;
727 
740  QString presetHomePath() const;
741 
742  QgsRelationManager *relationManager() const;
743 
750  const QgsLayoutManager *layoutManager() const SIP_SKIP;
751 
757  QgsLayoutManager *layoutManager();
758 
765  const QgsMapViewsManager *viewsManager() const SIP_SKIP;
766 
772  QgsMapViewsManager *viewsManager();
773 
780  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
781 
787  QgsBookmarkManager *bookmarkManager();
788 
796  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
797 
804  QgsProjectViewSettings *viewSettings();
805 
813  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
814 
821  QgsProjectTimeSettings *timeSettings();
822 
829  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
830 
836  QgsProjectDisplaySettings *displaySettings();
837 
842  QgsLayerTree *layerTreeRoot() const;
843 
848  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
849 
856 
861  QgsAnnotationManager *annotationManager();
862 
867  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
868 
873  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
874 
879  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
880 
885  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
886 
894  bool autoTransaction() const;
895 
905  void setAutoTransaction( bool autoTransaction );
906 
915  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
916 
924  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
925 
931  bool evaluateDefaultValues() const;
932 
938  void setEvaluateDefaultValues( bool evaluateDefaultValues );
939 
940  QgsExpressionContext createExpressionContext() const override;
941  QgsExpressionContextScope *createExpressionContextScope() const override;
942 
948  QgsSnappingConfig snappingConfig() const;
949 
955  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
956 
963  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
964 
970  void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
971 
977  AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
978 
984  QVariantMap customVariables() const;
985 
990  void setCustomVariables( const QVariantMap &customVariables );
991 
996  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
997 
1002  const QgsLabelingEngineSettings &labelingEngineSettings() const;
1003 
1004  //
1005  // Functionality from QgsMapLayerRegistry
1006  //
1007 
1012  QgsMapLayerStore *layerStore();
1013 
1018  SIP_SKIP const QgsMapLayerStore *layerStore() const;
1019 
1021  int count() const;
1022 
1024  int validCount() const;
1025 
1033  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
1034 
1035 #ifndef SIP_RUN
1036 
1052  template <class T>
1053  T mapLayer( const QString &layerId ) const
1054  {
1055  return qobject_cast<T>( mapLayer( layerId ) );
1056  }
1057 #endif
1058 
1066  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
1067 
1077  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
1078 
1079 
1088  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
1089 
1093  bool isZipped() const;
1094 
1095 #ifndef SIP_RUN
1096 
1108  template <typename T>
1109  QVector<T> layers() const
1110  {
1111  return mLayerStore->layers<T>();
1112  }
1113 
1125  template <typename T>
1126  QVector<T> mapLayersByShortName( const QString &shortName ) const
1127  {
1128  QVector<T> layers;
1129  const auto constMapLayers { mLayerStore->layers<T>() };
1130  for ( const auto l : constMapLayers )
1131  {
1132  if ( ! l->shortName().isEmpty() )
1133  {
1134  if ( l->shortName() == shortName )
1135  layers << l;
1136  }
1137  else if ( l->name() == shortName )
1138  {
1139  layers << l;
1140  }
1141  }
1142  return layers;
1143  }
1144 
1145 #endif
1146 
1172  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1173  bool addToLegend = true,
1174  bool takeOwnership SIP_PYARGREMOVE = true );
1175 
1203  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1204  bool addToLegend = true,
1205  bool takeOwnership SIP_PYARGREMOVE = true );
1206 
1221  void removeMapLayers( const QStringList &layerIds );
1222 
1223  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1224 
1238  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1239 
1253  void removeMapLayer( const QString &layerId );
1254 
1268  void removeMapLayer( QgsMapLayer *layer );
1269 
1277  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1278 
1290  QgsAnnotationLayer *mainAnnotationLayer();
1291 
1302  void removeAllMapLayers();
1303 
1309  void reloadAllLayers();
1310 
1315  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1316 
1328  void setTrustLayerMetadata( bool trust );
1329 
1340  bool trustLayerMetadata() const { return mTrustLayerMetadata; }
1341 
1347  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1348 
1354  QgsAuxiliaryStorage *auxiliaryStorage();
1355 
1364  QString createAttachedFile( const QString &nameTemplate );
1365 
1372  QStringList attachedFiles() const;
1373 
1381  bool removeAttachedFile( const QString &path );
1382 
1391  QString attachmentIdentifier( const QString &attachedFile ) const;
1392 
1399  QString resolveAttachmentIdentifier( const QString &identifier ) const;
1400 
1407  const QgsProjectMetadata &metadata() const;
1408 
1415  void setMetadata( const QgsProjectMetadata &metadata );
1416 
1425  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1426 
1435  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1436 
1443  void setProjectColors( const QgsNamedColorList &colors );
1444 
1451  void setBackgroundColor( const QColor &color );
1452 
1459  QColor backgroundColor() const;
1460 
1467  void setSelectionColor( const QColor &color );
1468 
1475  QColor selectionColor() const;
1476 
1488  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1489 
1501  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1502 
1511  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1512 
1521  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1522 
1527  void generateTsFile( const QString &locale );
1528 
1539  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1540 
1550  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1551 
1552 #ifdef SIP_RUN
1553  SIP_PYOBJECT __repr__();
1554  % MethodCode
1555  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1556  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1557  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1558  % End
1559 #endif
1560 
1561  signals:
1562 
1570  void cleared();
1571 
1575  void readProject( const QDomDocument & );
1576 
1580  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1581 
1585  void writeProject( QDomDocument & );
1586 
1595  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1596 
1605  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1606 
1611 
1617  Q_DECL_DEPRECATED void oldProjectVersionWarning( const QString & ) SIP_DEPRECATED;
1618 
1629  void readVersionMismatchOccurred( const QString &fileVersion );
1630 
1636  void layerLoaded( int i, int n );
1637 
1639  void loadingLayer( const QString &layerName );
1640 
1647  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1648 
1653  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1654 
1657 
1665 
1670 
1677 
1683 
1689  void crsChanged();
1690 
1698  void ellipsoidChanged( const QString &ellipsoid );
1699 
1700 
1708 
1713  void missingDatumTransforms( const QStringList &missingTransforms );
1714 
1722 
1729 
1736 
1749 
1755 
1763 
1771 
1779 
1787 
1788  //
1789  // signals from QgsMapLayerRegistry
1790  //
1791 
1799  void layersWillBeRemoved( const QStringList &layerIds );
1800 
1808  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1809 
1819  void layerWillBeRemoved( const QString &layerId );
1820 
1831 
1838  void layersRemoved( const QStringList &layerIds );
1839 
1848  void layerRemoved( const QString &layerId );
1849 
1850  //TODO QGIS 4.0 - rename to past tense
1851 
1858  void removeAll();
1859 
1870  void layersAdded( const QList<QgsMapLayer *> &layers );
1871 
1878  void layerWasAdded( QgsMapLayer *layer );
1879 
1888  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1889 
1897  void isDirtyChanged( bool dirty );
1898 
1906  void dirtySet();
1907 
1916  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1917 
1918  public slots:
1919 
1925  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1926 
1927  // TODO QGIS 4.0 - rename b to dirty
1928 
1936  void setDirty( bool b = true );
1937 
1946  void setPresetHomePath( const QString &path );
1947 
1957  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1958 
1965  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1966 
1973  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1974 
1981  QgsPropertyCollection dataDefinedServerProperties() const;
1982 
1983  private slots:
1984  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1985  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1986  void cleanTransactionGroups( bool force = false );
1987 
1988  private:
1989 
1990  static QgsProject *sProject;
1991 
1992 
2001  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
2002 
2007  void setError( const QString &errorMessage ) SIP_SKIP;
2008 
2013  void clearError() SIP_SKIP;
2014 
2022  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
2023 
2029  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
2030 
2035  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
2036 
2038  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
2039 
2041  bool writeProjectFile( const QString &filename );
2042 
2044  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
2045 
2047  bool zip( const QString &filename );
2048 
2050  bool saveAuxiliaryStorage( const QString &filename = QString() );
2051 
2053  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
2054 
2055  std::unique_ptr< QgsMapLayerStore > mLayerStore;
2056 
2057  QString mErrorMessage;
2058 
2059  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
2060 
2066  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
2067 
2068  QgsSnappingConfig mSnappingConfig;
2069  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
2070 
2071  QgsRelationManager *mRelationManager = nullptr;
2072 
2073  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
2074  std::unique_ptr<QgsLayoutManager> mLayoutManager;
2075  std::unique_ptr<QgsMapViewsManager> m3DViewsManager;
2076 
2077  QgsBookmarkManager *mBookmarkManager = nullptr;
2078 
2079  QgsProjectViewSettings *mViewSettings = nullptr;
2080 
2081  QgsProjectTimeSettings *mTimeSettings = nullptr;
2082 
2083  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
2084 
2085  QgsLayerTree *mRootGroup = nullptr;
2086 
2087  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
2088 
2089  QgsAnnotationLayer *mMainAnnotationLayer = nullptr;
2090 
2092  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
2093 
2094  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
2095 
2096  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
2097 
2098  QVariantMap mCustomVariables;
2099 
2100  std::unique_ptr<QgsArchive> mArchive;
2101 
2102  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
2103 
2104  QFile mFile; // current physical project file
2105 
2106  QString mOriginalPath;
2107 
2108  QString mSaveUser; // last saved user.
2109  QString mSaveUserFull; // last saved user full name.
2110  QDateTime mSaveDateTime;
2111  QgsProjectVersion mSaveVersion;
2112 
2117  QString mHomePath;
2118  mutable QString mCachedHomePath;
2119 
2120  QColor mBackgroundColor;
2121  QColor mSelectionColor;
2122 
2123  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
2124  bool mAutoTransaction = false; // transaction grouped editing
2125  bool mEvaluateDefaultValues = false; // evaluate default values immediately
2127  bool mDirty = false; // project has been modified since it has been read or saved
2128  int mDirtyBlockCount = 0;
2129  bool mTrustLayerMetadata = false;
2130 
2131  QgsPropertyCollection mDataDefinedServerProperties;
2132 
2133  QgsCoordinateTransformContext mTransformContext;
2134 
2135  QgsProjectMetadata mMetadata;
2136 
2137  std::unique_ptr< QTranslator > mTranslator;
2138 
2139  bool mIsBeingDeleted = false;
2140 
2141  QgsSettings mSettings;
2142 
2143  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
2144 
2145  int mBlockSnappingUpdates = 0;
2146 
2148 
2149  // Required to avoid creating a new project in it's destructor
2150  friend class QgsProviderRegistry;
2151 
2152  // Required by QGIS Server for switching the current project instance
2153  friend class QgsServer;
2154 
2155  friend class TestQgsProject;
2156 
2157  Q_DISABLE_COPY( QgsProject )
2158 };
2159 
2161 
2183 class CORE_EXPORT QgsProjectDirtyBlocker
2184 {
2185  public:
2186 
2193  : mProject( project )
2194  {
2195  mProject->mDirtyBlockCount++;
2196  }
2197 
2200 
2203 
2205  {
2206  mProject->mDirtyBlockCount--;
2207  }
2208 
2209  private:
2210  QgsProject *mProject = nullptr;
2211 
2212 #ifdef SIP_RUN
2214 #endif
2215 };
2216 
2222 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2223 
2224 
2225 
2227 #ifndef SIP_RUN
2228 class GetNamedProjectColor : public QgsScopedExpressionFunction
2229 {
2230  public:
2231  GetNamedProjectColor( const QgsProject *project );
2232 
2237  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2238 
2239  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2240  QgsScopedExpressionFunction *clone() const override;
2241 
2242  private:
2243 
2244  QHash< QString, QColor > mColors;
2245 
2246 };
2247 
2248 #endif
2250 
2251 #endif
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:64
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
This is a container for attribute editors, used to group them visually in the attribute form if it is...
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.
Manages storage of a set of views.
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:2184
QgsProjectDirtyBlocker & operator=(const QgsProjectDirtyBlocker &other)=delete
QgsProjectDirtyBlocker cannot be copied.
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2192
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:470
Q_DECL_DEPRECATED void mapScalesChanged()
Emitted when the list of custom project map scales changes.
void readVersionMismatchOccurred(const QString &fileVersion)
Emitted when a project is read and the version of QGIS used to save the project differs from the curr...
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:167
Q_DECL_DEPRECATED void oldProjectVersionWarning(const QString &)
Emitted when an old project file is read.
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:1109
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:151
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:1053
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:140
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:1340
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:1126
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 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 class is a composition of two QSettings instances:
Definition: qgssettings.h:62
This is a container for configuration of the snapping of the project.
An interface for classes which can visit style entity (e.g.
This is the class is providing tolerance value in map unit values.
Definition: qgstolerance.h:33
Used for the collecting of strings from projects for translation and creation of ts files.
Helper functions for various unit types.
Definition: qgsunittypes.h:39
Represents a vector layer which manages a vector based data sets.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
Definition: qgsziputils.cpp:34
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#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