QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsproject.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproject.h
3 
4  Implements persistent project state.
5 
6  -------------------
7  begin : July 23, 2004
8  copyright : (C) 2004 by Mark Coletti
9  email : mcoletti at gmail.com
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 #ifndef QGSPROJECT_H
22 #define QGSPROJECT_H
23 
24 #include "qgis_core.h"
25 #include "qgis_sip.h"
26 #include <memory>
27 #include <QHash>
28 #include <QList>
29 #include <QObject>
30 #include <QPair>
31 #include <QFileInfo>
32 #include <QStringList>
33 #include <QTranslator>
34 
35 #include "qgsunittypes.h"
36 #include "qgssnappingconfig.h"
37 #include "qgsprojectversion.h"
42 #include "qgsprojectproperty.h"
43 #include "qgsmaplayerstore.h"
44 #include "qgsarchive.h"
45 #include "qgsreadwritecontext.h"
46 #include "qgsprojectmetadata.h"
47 #include "qgstranslationcontext.h"
48 #include "qgsprojecttranslator.h"
50 #include "qgscolorscheme.h"
51 
52 class QFileInfo;
53 class QDomDocument;
54 class QDomElement;
55 class QDomNode;
56 
57 class QgsLayerTreeGroup;
59 class QgsMapLayer;
61 class QgsPathResolver;
63 class QgsProjectStorage;
64 class QgsRelationManager;
65 class QgsTolerance;
67 class QgsVectorLayer;
69 class QgsLayoutManager;
70 class QgsLayerTree;
73 class QgsMapLayer;
74 class QgsBookmarkManager;
78 
92 class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenerator, public QgsExpressionContextScopeGenerator, public QgsProjectTranslator
93 {
94  Q_OBJECT
95  Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
96  Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
97  Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
98  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
99  Q_PROPERTY( QgsCoordinateTransformContext transformContext READ transformContext WRITE setTransformContext NOTIFY transformContextChanged )
100  Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
101  Q_PROPERTY( QgsMapThemeCollection *mapThemeCollection READ mapThemeCollection NOTIFY mapThemeCollectionChanged )
102  Q_PROPERTY( QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
103  Q_PROPERTY( QgsRelationManager *relationManager READ relationManager )
104  Q_PROPERTY( AvoidIntersectionsMode avoidIntersectionsMode READ avoidIntersectionsMode WRITE setAvoidIntersectionsMode NOTIFY avoidIntersectionsModeChanged )
105  Q_PROPERTY( QList<QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
106  Q_PROPERTY( QgsProjectMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
107  Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
108  Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
109  Q_PROPERTY( bool topologicalEditing READ topologicalEditing WRITE setTopologicalEditing NOTIFY topologicalEditingChanged )
110 
111  public:
112 
118  {
119  FlagDontResolveLayers = 1 << 0,
120  FlagDontLoadLayouts = 1 << 1,
121  };
122  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
123 
124 
128  enum class FileFormat
129  {
130  Qgz,
131  Qgs,
132  };
133  Q_ENUM( FileFormat )
134 
135 
140  {
141  AllowIntersections,
142  AvoidIntersectionsCurrentLayer,
143  AvoidIntersectionsLayers,
144  };
145  Q_ENUM( AvoidIntersectionsMode )
146 
147 
156  {
157  NoProperty = 0,
158  AllProperties = 1,
159  WMSOnlineResource = 2,
160  };
161 
163  static QgsProject *instance();
164 
170  explicit QgsProject( QObject *parent SIP_TRANSFERTHIS = nullptr );
171 
172  ~QgsProject() override;
173 
183  void setTitle( const QString &title );
184 
191  QString title() const;
192 
200  QString saveUser() const;
201 
209  QString saveUserFullName() const;
210 
216  QDateTime lastSaveDateTime() const;
217 
221  bool isDirty() const;
222 
229  void setFileName( const QString &name );
230 
237  QString fileName() const;
238 
250  void setOriginalPath( const QString &path );
251 
263  QString originalPath() const;
264 
275  Q_DECL_DEPRECATED QFileInfo fileInfo() const SIP_DEPRECATED;
276 
283  QgsProjectStorage *projectStorage() const;
284 
289  QDateTime lastModified() const;
290 
296  QString absoluteFilePath() const;
297 
303  QString absolutePath() const;
304 
309  QString baseName() const;
310 
318 
328  void setCrs( const QgsCoordinateReferenceSystem &crs, bool adjustEllipsoid = false );
329 
336  QString ellipsoid() const;
337 
344  void setEllipsoid( const QString &ellipsoid );
345 
346 
356  QgsCoordinateTransformContext transformContext() const;
357 
367  void setTransformContext( const QgsCoordinateTransformContext &context );
368 
374  void clear();
375 
382  bool read( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
383 
392  bool read( QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
393 
403  bool readLayer( const QDomNode &layerNode );
404 
413  bool write( const QString &filename );
414 
420  bool write();
421 
431  bool writeEntry( const QString &scope, const QString &key, bool value ) SIP_PYNAME( writeEntryBool );
432 
442  bool writeEntry( const QString &scope, const QString &key, double value ) SIP_PYNAME( writeEntryDouble );
443 
452  bool writeEntry( const QString &scope, const QString &key, int value );
453 
462  bool writeEntry( const QString &scope, const QString &key, const QString &value );
463 
472  bool writeEntry( const QString &scope, const QString &key, const QStringList &value );
473 
480  QStringList readListEntry( const QString &scope, const QString &key, const QStringList &def = QStringList(), bool *ok = nullptr ) const;
481 
482  QString readEntry( const QString &scope, const QString &key, const QString &def = QString(), bool *ok = nullptr ) const;
483  int readNumEntry( const QString &scope, const QString &key, int def = 0, bool *ok = nullptr ) const;
484  double readDoubleEntry( const QString &scope, const QString &key, double def = 0, bool *ok = nullptr ) const;
485  bool readBoolEntry( const QString &scope, const QString &key, bool def = false, bool *ok = nullptr ) const;
486 
488  bool removeEntry( const QString &scope, const QString &key );
489 
490 
496  QStringList entryList( const QString &scope, const QString &key ) const;
497 
503  QStringList subkeyList( const QString &scope, const QString &key ) const;
504 
505 
509  // TODO Now slightly broken since re-factoring. Won't print out top-level key
510  // and redundantly prints sub-keys.
511  void dumpProperties() const;
512 
518  QgsPathResolver pathResolver() const;
519 
525  QString writePath( const QString &filename ) const;
526 
528  QString readPath( const QString &filename ) const;
529 
531  QString error() const;
532 
537  void setBadLayerHandler( QgsProjectBadLayerHandler *handler SIP_TRANSFER );
538 
540  QString layerIsEmbedded( const QString &id ) const;
541 
550  bool createEmbeddedLayer( const QString &layerId, const QString &projectFilePath, QList<QDomNode> &brokenNodes,
551  bool saveFlag = true, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
552 
560  QgsLayerTreeGroup *createEmbeddedGroup( const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
561 
563  void setTopologicalEditing( bool enabled );
564 
566  bool topologicalEditing() const;
567 
574  QgsUnitTypes::DistanceUnit distanceUnits() const;
575 
582  void setDistanceUnits( QgsUnitTypes::DistanceUnit unit );
583 
589  QgsUnitTypes::AreaUnit areaUnits() const;
590 
597  void setAreaUnits( QgsUnitTypes::AreaUnit unit );
598 
611  QString homePath() const;
612 
625  QString presetHomePath() const;
626 
627  QgsRelationManager *relationManager() const;
628 
635  const QgsLayoutManager *layoutManager() const SIP_SKIP;
636 
642  QgsLayoutManager *layoutManager();
643 
650  const QgsBookmarkManager *bookmarkManager() const SIP_SKIP;
651 
657  QgsBookmarkManager *bookmarkManager();
658 
666  const QgsProjectViewSettings *viewSettings() const SIP_SKIP;
667 
674  QgsProjectViewSettings *viewSettings();
675 
683  const QgsProjectTimeSettings *timeSettings() const SIP_SKIP;
684 
691  QgsProjectTimeSettings *timeSettings();
692 
699  const QgsProjectDisplaySettings *displaySettings() const SIP_SKIP;
700 
706  QgsProjectDisplaySettings *displaySettings();
707 
712  QgsLayerTree *layerTreeRoot() const;
713 
718  QgsLayerTreeRegistryBridge *layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
719 
725  QgsMapThemeCollection *mapThemeCollection();
726 
731  QgsAnnotationManager *annotationManager();
732 
737  const QgsAnnotationManager *annotationManager() const SIP_SKIP;
738 
743  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QList<QgsMapLayer *> &layers );
744 
749  Q_DECL_DEPRECATED void setNonIdentifiableLayers( const QStringList &layerIds );
750 
755  Q_DECL_DEPRECATED QStringList nonIdentifiableLayers() const;
756 
764  bool autoTransaction() const;
765 
775  void setAutoTransaction( bool autoTransaction );
776 
785  QMap< QPair< QString, QString>, QgsTransactionGroup *> transactionGroups() SIP_SKIP;
786 
794  QgsTransactionGroup *transactionGroup( const QString &providerKey, const QString &connString );
795 
801  bool evaluateDefaultValues() const;
802 
808  void setEvaluateDefaultValues( bool evaluateDefaultValues );
809 
810  QgsExpressionContext createExpressionContext() const override;
811  QgsExpressionContextScope *createExpressionContextScope() const override;
812 
818  QgsSnappingConfig snappingConfig() const;
819 
825  QList<QgsVectorLayer *> avoidIntersectionsLayers() const;
826 
833  void setAvoidIntersectionsLayers( const QList<QgsVectorLayer *> &layers );
834 
840  void setAvoidIntersectionsMode( const AvoidIntersectionsMode mode );
841 
847  AvoidIntersectionsMode avoidIntersectionsMode() const { return mAvoidIntersectionsMode; }
848 
854  QVariantMap customVariables() const;
855 
860  void setCustomVariables( const QVariantMap &customVariables );
861 
866  void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
867 
872  const QgsLabelingEngineSettings &labelingEngineSettings() const;
873 
874  //
875  // Functionality from QgsMapLayerRegistry
876  //
877 
882  QgsMapLayerStore *layerStore();
883 
888  SIP_SKIP const QgsMapLayerStore *layerStore() const;
889 
891  int count() const;
892 
894  int validCount() const;
895 
903  Q_INVOKABLE QgsMapLayer *mapLayer( const QString &layerId ) const;
904 
905 #ifndef SIP_RUN
906 
922  template <class T>
923  T mapLayer( const QString &layerId ) const
924  {
925  return qobject_cast<T>( mapLayer( layerId ) );
926  }
927 #endif
928 
936  QList<QgsMapLayer *> mapLayersByName( const QString &layerName ) const;
937 
947  QList<QgsMapLayer *> mapLayersByShortName( const QString &shortName ) const;
948 
949 
958  QMap<QString, QgsMapLayer *> mapLayers( const bool validOnly = false ) const;
959 
963  bool isZipped() const;
964 
965 #ifndef SIP_RUN
966 
978  template <typename T>
979  QVector<T> layers() const
980  {
981  return mLayerStore->layers<T>();
982  }
983 
995  template <typename T>
996  QVector<T> mapLayersByShortName( const QString &shortName ) const
997  {
998  QVector<T> layers;
999  const auto constMapLayers { mLayerStore->layers<T>() };
1000  for ( const auto l : constMapLayers )
1001  {
1002  if ( ! l->shortName().isEmpty() )
1003  {
1004  if ( l->shortName() == shortName )
1005  layers << l;
1006  }
1007  else if ( l->name() == shortName )
1008  {
1009  layers << l;
1010  }
1011  }
1012  return layers;
1013  }
1014 
1015 #endif
1016 
1042  QList<QgsMapLayer *> addMapLayers( const QList<QgsMapLayer *> &mapLayers SIP_TRANSFER,
1043  bool addToLegend = true,
1044  bool takeOwnership SIP_PYARGREMOVE = true );
1045 
1073  QgsMapLayer *addMapLayer( QgsMapLayer *mapLayer SIP_TRANSFER,
1074  bool addToLegend = true,
1075  bool takeOwnership SIP_PYARGREMOVE = true );
1076 
1091  void removeMapLayers( const QStringList &layerIds );
1092 
1093  //TODO QGIS 4.0 - add PyName alias to avoid list type conversion error
1094 
1108  void removeMapLayers( const QList<QgsMapLayer *> &layers );
1109 
1123  void removeMapLayer( const QString &layerId );
1124 
1138  void removeMapLayer( QgsMapLayer *layer );
1139 
1147  QgsMapLayer *takeMapLayer( QgsMapLayer *layer ) SIP_TRANSFERBACK;
1148 
1159  void removeAllMapLayers();
1160 
1166  void reloadAllLayers();
1167 
1172  QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
1173 
1185  void setTrustLayerMetadata( bool trust );
1186 
1197  bool trustLayerMetadata() const { return mTrustLayerMetadata; }
1198 
1204  const QgsAuxiliaryStorage *auxiliaryStorage() const SIP_SKIP;
1205 
1211  QgsAuxiliaryStorage *auxiliaryStorage();
1212 
1221  QString attachedFile( const QString &fileName ) const SIP_SKIP;
1222 
1232  QgsStringMap attachedFiles() const SIP_SKIP;
1233 
1240  const QgsProjectMetadata &metadata() const;
1241 
1248  void setMetadata( const QgsProjectMetadata &metadata );
1249 
1258  Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers() const;
1259 
1268  Q_DECL_DEPRECATED void setRequiredLayers( const QSet<QgsMapLayer *> &layers );
1269 
1276  void setProjectColors( const QgsNamedColorList &colors );
1277 
1284  void setBackgroundColor( const QColor &color );
1285 
1292  QColor backgroundColor() const;
1293 
1300  void setSelectionColor( const QColor &color );
1301 
1308  QColor selectionColor() const;
1309 
1321  Q_DECL_DEPRECATED void setMapScales( const QVector<double> &scales ) SIP_DEPRECATED;
1322 
1334  Q_DECL_DEPRECATED QVector<double> mapScales() const SIP_DEPRECATED;
1335 
1344  Q_DECL_DEPRECATED void setUseProjectScales( bool enabled ) SIP_DEPRECATED;
1345 
1354  Q_DECL_DEPRECATED bool useProjectScales() const SIP_DEPRECATED;
1355 
1360  void generateTsFile( const QString &locale );
1361 
1372  QString translate( const QString &context, const QString &sourceText, const char *disambiguation = nullptr, int n = -1 ) const override;
1373 
1383  bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1384 
1385 #ifdef SIP_RUN
1386  SIP_PYOBJECT __repr__();
1387  % MethodCode
1388  QString str = QStringLiteral( "<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1389  sipCpp == QgsProject::instance() ? QStringLiteral( " (singleton instance)" ) : QString() );
1390  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1391  % End
1392 #endif
1393 
1394  signals:
1395 
1403  void cleared();
1404 
1408  void readProject( const QDomDocument & );
1409 
1413  void readProjectWithContext( const QDomDocument &, QgsReadWriteContext &context );
1414 
1418  void writeProject( QDomDocument & );
1419 
1428  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
1429 
1438  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1439 
1443  void projectSaved();
1444 
1448  void oldProjectVersionWarning( const QString & );
1449 
1455  void layerLoaded( int i, int n );
1456 
1458  void loadingLayer( const QString &layerName );
1459 
1466  void loadingLayerMessageReceived( const QString &layerName, const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1467 
1472  Q_DECL_DEPRECATED void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1473 
1475  void fileNameChanged();
1476 
1483  void homePathChanged();
1484 
1488  void snappingConfigChanged( const QgsSnappingConfig &config );
1489 
1495  void avoidIntersectionsModeChanged();
1496 
1501  void customVariablesChanged();
1502 
1508  void crsChanged();
1509 
1517  void ellipsoidChanged( const QString &ellipsoid );
1518 
1519 
1526  void transformContextChanged();
1527 
1532  void missingDatumTransforms( const QStringList &missingTransforms );
1533 
1540  void transactionGroupsChanged();
1541 
1547  void topologicalEditingChanged();
1548 
1554  void avoidIntersectionsLayersChanged();
1555 
1567  void mapThemeCollectionChanged();
1568 
1573  void labelingEngineSettingsChanged();
1574 
1581  void metadataChanged();
1582 
1589  void projectColorsChanged();
1590 
1597  void backgroundColorChanged();
1598 
1605  void selectionColorChanged();
1606 
1607  //
1608  // signals from QgsMapLayerRegistry
1609  //
1610 
1618  void layersWillBeRemoved( const QStringList &layerIds );
1619 
1627  void layersWillBeRemoved( const QList<QgsMapLayer *> &layers );
1628 
1638  void layerWillBeRemoved( const QString &layerId );
1639 
1649  void layerWillBeRemoved( QgsMapLayer *layer );
1650 
1657  void layersRemoved( const QStringList &layerIds );
1658 
1667  void layerRemoved( const QString &layerId );
1668 
1669  //TODO QGIS 4.0 - rename to past tense
1670 
1677  void removeAll();
1678 
1689  void layersAdded( const QList<QgsMapLayer *> &layers );
1690 
1697  void layerWasAdded( QgsMapLayer *layer );
1698 
1707  void legendLayersAdded( const QList<QgsMapLayer *> &layers );
1708 
1716  void isDirtyChanged( bool dirty );
1717 
1731  void collectAttachedFiles( QgsStringMap &files SIP_INOUT ) SIP_SKIP;
1732 
1741  Q_DECL_DEPRECATED void mapScalesChanged() SIP_DEPRECATED;
1742 
1743  public slots:
1744 
1750  void setSnappingConfig( const QgsSnappingConfig &snappingConfig );
1751 
1752  // TODO QGIS 4.0 - rename b to dirty
1753 
1761  void setDirty( bool b = true );
1762 
1771  void setPresetHomePath( const QString &path );
1772 
1782  void registerTranslatableContainers( QgsTranslationContext *translationContext, QgsAttributeEditorContainer *parent, const QString &layerId );
1783 
1790  void registerTranslatableObjects( QgsTranslationContext *translationContext );
1791 
1798  void setDataDefinedServerProperties( const QgsPropertyCollection &properties );
1799 
1806  QgsPropertyCollection dataDefinedServerProperties() const;
1807 
1808  private slots:
1809  void onMapLayersAdded( const QList<QgsMapLayer *> &layers );
1810  void onMapLayersRemoved( const QList<QgsMapLayer *> &layers );
1811  void cleanTransactionGroups( bool force = false );
1812 
1813  private:
1814 
1815  static QgsProject *sProject;
1816 
1825  static void setInstance( QgsProject *project ) SIP_SKIP;
1826 
1835  bool _getMapLayers( const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1836 
1841  void setError( const QString &errorMessage ) SIP_SKIP;
1842 
1847  void clearError() SIP_SKIP;
1848 
1856  bool addLayer( const QDomElement &layerElem, QList<QDomNode> &brokenNodes, QgsReadWriteContext &context, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1857 
1863  void initializeEmbeddedSubtree( const QString &projectFilePath, QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1864 
1869  bool loadEmbeddedNodes( QgsLayerTreeGroup *group, QgsProject::ReadFlags flags = QgsProject::ReadFlags() ) SIP_SKIP;
1870 
1872  bool readProjectFile( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1873 
1875  bool writeProjectFile( const QString &filename );
1876 
1878  bool unzip( const QString &filename, QgsProject::ReadFlags flags = QgsProject::ReadFlags() );
1879 
1881  bool zip( const QString &filename );
1882 
1884  bool saveAuxiliaryStorage( const QString &filename = QString() );
1885 
1887  static QgsPropertiesDefinition &dataDefinedServerPropertyDefinitions();
1888 
1889  std::unique_ptr< QgsMapLayerStore > mLayerStore;
1890 
1891  QString mErrorMessage;
1892 
1893  QgsProjectBadLayerHandler *mBadLayerHandler = nullptr;
1894 
1900  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
1901 
1902  QgsSnappingConfig mSnappingConfig;
1903  AvoidIntersectionsMode mAvoidIntersectionsMode = AvoidIntersectionsMode::AllowIntersections;
1904 
1905  QgsRelationManager *mRelationManager = nullptr;
1906 
1907  std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
1908  std::unique_ptr<QgsLayoutManager> mLayoutManager;
1909 
1910  QgsBookmarkManager *mBookmarkManager = nullptr;
1911 
1912  QgsProjectViewSettings *mViewSettings = nullptr;
1913 
1914  QgsProjectTimeSettings *mTimeSettings = nullptr;
1915 
1916  QgsProjectDisplaySettings *mDisplaySettings = nullptr;
1917 
1918  QgsLayerTree *mRootGroup = nullptr;
1919 
1920  QgsLayerTreeRegistryBridge *mLayerTreeRegistryBridge = nullptr;
1921 
1923  QMap< QPair< QString, QString>, QgsTransactionGroup *> mTransactionGroups;
1924 
1925  std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
1926 
1927  std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
1928 
1929  QVariantMap mCustomVariables;
1930 
1931  std::unique_ptr<QgsProjectArchive> mArchive;
1932 
1933  std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
1934 
1935  QFile mFile; // current physical project file
1936 
1937  QString mOriginalPath;
1938 
1939  QString mSaveUser; // last saved user.
1940  QString mSaveUserFull; // last saved user full name.
1941  QDateTime mSaveDateTime;
1942 
1947  QString mHomePath;
1948  mutable QString mCachedHomePath;
1949 
1950  QColor mBackgroundColor;
1951  QColor mSelectionColor;
1952 
1953  mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
1954  bool mAutoTransaction = false; // transaction grouped editing
1955  bool mEvaluateDefaultValues = false; // evaluate default values immediately
1957  bool mDirty = false; // project has been modified since it has been read or saved
1958  int mDirtyBlockCount = 0;
1959  bool mTrustLayerMetadata = false;
1960 
1961  QgsPropertyCollection mDataDefinedServerProperties;
1962 
1963  QgsCoordinateTransformContext mTransformContext;
1964 
1965  QgsProjectMetadata mMetadata;
1966 
1967  std::unique_ptr< QTranslator > mTranslator;
1968 
1969  bool mIsBeingDeleted = false;
1970 
1971  mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
1972 
1974 
1975  // Required to avoid creating a new project in it's destructor
1976  friend class QgsProviderRegistry;
1977 
1978  // Required by QGIS Server for switching the current project instance
1979  friend class QgsConfigCache;
1980 
1981  friend class TestQgsProject;
1982 };
1983 
1984 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProject::ReadFlags )
1985 
2007 class CORE_EXPORT QgsProjectDirtyBlocker
2008 {
2009  public:
2010 
2017  : mProject( project )
2018  {
2019  mProject->mDirtyBlockCount++;
2020  }
2021 
2023  QgsProjectDirtyBlocker( const QgsProjectDirtyBlocker &other ) = delete;
2024 
2026  QgsProjectDirtyBlocker &operator=( const QgsProjectDirtyBlocker &other ) = delete;
2027 
2029  {
2030  mProject->mDirtyBlockCount--;
2031  }
2032 
2033  private:
2034  QgsProject *mProject = nullptr;
2035 
2036 #ifdef SIP_RUN
2038 #endif
2039 };
2040 
2046 CORE_EXPORT QgsProjectVersion getVersion( QDomDocument const &doc ) SIP_SKIP;
2047 
2048 
2049 
2051 #ifndef SIP_RUN
2052 class GetNamedProjectColor : public QgsScopedExpressionFunction
2053 {
2054  public:
2055  GetNamedProjectColor( const QgsProject *project );
2056 
2061  GetNamedProjectColor( const QHash< QString, QColor > &colors );
2062 
2063  QVariant func( const QVariantList &values, const QgsExpressionContext *, QgsExpression *, const QgsExpressionNodeFunction * ) override;
2064  QgsScopedExpressionFunction *clone() const override;
2065 
2066  private:
2067 
2068  QHash< QString, QColor > mColors;
2069 
2070 };
2071 
2072 #endif
2073 
2075 #endif
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
SIP_PYNAME
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
QgsProject::DataDefinedServerProperty
DataDefinedServerProperty
Data defined properties.
Definition: qgsproject.h:155
QgsProject::layers
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
Definition: qgsproject.h:979
qgscolorscheme.h
qgstranslationcontext.h
QgsTransactionGroup
Definition: qgstransactiongroup.h:31
QgsProject::trustLayerMetadata
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
Definition: qgsproject.h:1197
QgsLayoutManager
Manages storage of a set of layouts.
Definition: qgslayoutmanager.h:44
QgsRelationManager
Definition: qgsrelationmanager.h:34
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsProjectMetadata
A structured metadata store for a map layer.
Definition: qgsprojectmetadata.h:53
QgsConfigCache
Cache for server configuration.
Definition: qgsconfigcache.h:38
QgsProviderRegistry
Definition: qgsproviderregistry.h:54
qgsreadwritecontext.h
qgscoordinatetransformcontext.h
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:36
QgsNamedColorList
QList< QPair< QColor, QString > > QgsNamedColorList
Definition: qgscolorscheme.h:34
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:458
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
qgsunittypes.h
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:144
QgsExpressionContextScopeGenerator
Definition: qgsexpressioncontextscopegenerator.h:28
QgsProject::ReadFlag
ReadFlag
Flags which control project read behavior.
Definition: qgsproject.h:117
SIP_PYARGREMOVE
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
qgsmaplayerstore.h
QgsProjectStorage
Definition: qgsprojectstorage.h:37
QgsProject
Definition: qgsproject.h:92
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
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
Definition: qgslayertree.h:32
QgsProject::AvoidIntersectionsMode
AvoidIntersectionsMode
Flags which control how intersections of pre-existing feature are handled when digitizing new feature...
Definition: qgsproject.h:139
QgsProjectDirtyBlocker::~QgsProjectDirtyBlocker
~QgsProjectDirtyBlocker()
Definition: qgsproject.h:2028
QgsLabelingEngineSettings
Definition: qgslabelingenginesettings.h:30
QgsProjectDirtyBlocker::QgsProjectDirtyBlocker
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Definition: qgsproject.h:2016
QgsProject::FileFormat
FileFormat
Flags which control project read behavior.
Definition: qgsproject.h:128
qgis_sip.h
QgsProjectBadLayerHandler
Definition: qgsprojectbadlayerhandler.h:27
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
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
QgsSnappingConfig
Definition: qgssnappingconfig.h:33
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:34
QgsExpressionNodeFunction
An expression node for expression functions.
Definition: qgsexpressionnodeimpl.h:316
qgsprojectmetadata.h
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
qgsprojectproperty.h
SIP_INOUT
#define SIP_INOUT
Definition: qgis_sip.h:71
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:923
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsProjectTranslator
Definition: qgsprojecttranslator.h:30
QgsProjectPropertyKey
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:34
QgsTolerance
Definition: qgstolerance.h:32
QgsProjectDirtyBlocker
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2007
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsAttributeEditorContainer
Definition: qgsattributeeditorelement.h:170
QgsAuxiliaryStorage
Class providing some utility methods to manage auxiliary storage.
Definition: qgsauxiliarystorage.h:259
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:996
qgsexpressioncontextscopegenerator.h
QgsProjectArchive
Class allowing to manage the zip/unzip actions on project file.
Definition: qgsarchive.h:115
QgsMapThemeCollection
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Definition: qgsmapthemecollection.h:44
qgsprojectversion.h
QgsExpression
Definition: qgsexpression.h:113
qgsattributeeditorelement.h
qgsarchive.h
QgsExpressionContextGenerator
Definition: qgsexpressioncontextgenerator.h:36
QgsScopedExpressionFunction
Expression function for use within a QgsExpressionContextScope. This differs from a standard QgsExpre...
Definition: qgsexpressioncontext.h:37
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:132
QgsLayerTreeRegistryBridge
Definition: qgslayertreeregistrybridge.h:44
QgsPathResolver
Definition: qgspathresolver.h:31
QgsProjectVersion
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:990
SIP_MONKEYPATCH_SCOPEENUM
#define SIP_MONKEYPATCH_SCOPEENUM
Definition: qgis_sip.h:251