24 #include "qgis_core.h" 32 #include <QStringList> 33 #include <QTranslator> 94 Q_PROPERTY( QStringList nonIdentifiableLayers READ nonIdentifiableLayers WRITE setNonIdentifiableLayers NOTIFY nonIdentifiableLayersChanged )
95 Q_PROPERTY( QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged )
96 Q_PROPERTY( QString homePath READ homePath WRITE setPresetHomePath NOTIFY homePathChanged )
99 Q_PROPERTY( QString ellipsoid READ ellipsoid WRITE setEllipsoid NOTIFY ellipsoidChanged )
101 Q_PROPERTY(
QgsSnappingConfig snappingConfig READ snappingConfig WRITE setSnappingConfig NOTIFY snappingConfigChanged )
103 Q_PROPERTY( QList<
QgsVectorLayer *> avoidIntersectionsLayers READ avoidIntersectionsLayers WRITE setAvoidIntersectionsLayers NOTIFY avoidIntersectionsLayersChanged )
105 Q_PROPERTY( QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged )
106 Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )
116 FlagDontResolveLayers = 1 << 0,
117 FlagDontLoadLayouts = 1 << 1,
119 Q_DECLARE_FLAGS( ReadFlags,
ReadFlag )
153 void setTitle(
const QString &title );
161 QString title()
const;
170 QString saveUser()
const;
179 QString saveUserFullName()
const;
184 bool isDirty()
const;
192 void setFileName(
const QString &name );
200 QString fileName()
const;
226 QDateTime lastModified()
const;
233 QString absoluteFilePath()
const;
240 QString absolutePath()
const;
246 QString baseName()
const;
273 QString ellipsoid()
const;
281 void setEllipsoid(
const QString &ellipsoid );
319 bool read(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
329 bool read( QgsProject::ReadFlags flags =
nullptr );
340 bool readLayer(
const QDomNode &layerNode );
350 bool write(
const QString &filename );
368 bool writeEntry(
const QString &scope,
const QString &key,
bool value )
SIP_PYNAME( writeEntryBool );
379 bool writeEntry(
const QString &scope,
const QString &key,
double value )
SIP_PYNAME( writeEntryDouble );
389 bool writeEntry(
const QString &scope,
const QString &key,
int value );
399 bool writeEntry(
const QString &scope,
const QString &key,
const QString &value );
409 bool writeEntry(
const QString &scope,
const QString &key,
const QStringList &value );
417 QStringList readListEntry(
const QString &scope,
const QString &key,
const QStringList &def = QStringList(),
bool *ok =
nullptr )
const;
419 QString readEntry(
const QString &scope,
const QString &key,
const QString &def = QString(),
bool *ok =
nullptr )
const;
420 int readNumEntry(
const QString &scope,
const QString &key,
int def = 0,
bool *ok =
nullptr )
const;
421 double readDoubleEntry(
const QString &scope,
const QString &key,
double def = 0,
bool *ok =
nullptr )
const;
422 bool readBoolEntry(
const QString &scope,
const QString &key,
bool def =
false,
bool *ok =
nullptr )
const;
426 bool removeEntry(
const QString &scope,
const QString &key );
434 QStringList entryList(
const QString &scope,
const QString &key )
const;
441 QStringList subkeyList(
const QString &scope,
const QString &key )
const;
449 void dumpProperties()
const;
463 QString writePath(
const QString &filename )
const;
466 QString readPath(
const QString &filename )
const;
469 QString error()
const;
478 QString layerIsEmbedded(
const QString &
id )
const;
488 bool createEmbeddedLayer(
const QString &layerId,
const QString &projectFilePath, QList<QDomNode> &brokenNodes,
489 bool saveFlag =
true, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
498 QgsLayerTreeGroup *createEmbeddedGroup(
const QString &groupName,
const QString &projectFilePath,
const QStringList &invisibleLayers, QgsProject::ReadFlags flags =
nullptr );
501 void setTopologicalEditing(
bool enabled );
504 bool topologicalEditing()
const;
549 QString homePath()
const;
563 QString presetHomePath()
const;
664 Q_DECL_DEPRECATED
void setNonIdentifiableLayers(
const QList<QgsMapLayer *> &layers );
670 Q_DECL_DEPRECATED
void setNonIdentifiableLayers(
const QStringList &layerIds );
676 Q_DECL_DEPRECATED QStringList nonIdentifiableLayers()
const;
685 bool autoTransaction()
const;
696 void setAutoTransaction(
bool autoTransaction );
715 QgsTransactionGroup *transactionGroup(
const QString &providerKey,
const QString &connString );
722 bool evaluateDefaultValues()
const;
729 void setEvaluateDefaultValues(
bool evaluateDefaultValues );
746 QList<QgsVectorLayer *> avoidIntersectionsLayers()
const;
753 void setAvoidIntersectionsLayers(
const QList<QgsVectorLayer *> &layers );
760 QVariantMap customVariables()
const;
766 void setCustomVariables(
const QVariantMap &customVariables );
800 int validCount()
const;
809 Q_INVOKABLE
QgsMapLayer *mapLayer(
const QString &layerId )
const;
831 return qobject_cast<T>( mapLayer( layerId ) );
842 QList<QgsMapLayer *> mapLayersByName(
const QString &layerName )
const;
853 QList<QgsMapLayer *> mapLayersByShortName(
const QString &shortName )
const;
864 QMap<QString, QgsMapLayer *> mapLayers(
const bool validOnly =
false )
const;
869 bool isZipped()
const;
884 template <
typename T>
887 return mLayerStore->layers<T>();
901 template <
typename T>
905 const auto constMapLayers { mLayerStore->layers<T>() };
906 for (
const auto l : constMapLayers )
908 if ( ! l->shortName().isEmpty() )
910 if ( l->shortName() == shortName )
913 else if ( l->name() == shortName )
948 QList<QgsMapLayer *> addMapLayers(
const QList<QgsMapLayer *> &mapLayers
SIP_TRANSFER,
949 bool addToLegend =
true,
980 bool addToLegend =
true,
997 void removeMapLayers(
const QStringList &layerIds );
1014 void removeMapLayers(
const QList<QgsMapLayer *> &layers );
1029 void removeMapLayer(
const QString &layerId );
1065 void removeAllMapLayers();
1072 void reloadAllLayers();
1091 void setTrustLayerMetadata(
bool trust );
1127 QString attachedFile(
const QString &fileName )
const SIP_SKIP;
1164 Q_DECL_DEPRECATED QSet<QgsMapLayer *> requiredLayers()
const;
1174 Q_DECL_DEPRECATED
void setRequiredLayers(
const QSet<QgsMapLayer *> &layers );
1190 void setBackgroundColor(
const QColor &color );
1198 QColor backgroundColor()
const;
1206 void setSelectionColor(
const QColor &color );
1214 QColor selectionColor()
const;
1227 Q_DECL_DEPRECATED
void setMapScales(
const QVector<double> &scales )
SIP_DEPRECATED;
1240 Q_DECL_DEPRECATED QVector<double> mapScales()
const SIP_DEPRECATED;
1250 Q_DECL_DEPRECATED
void setUseProjectScales(
bool enabled )
SIP_DEPRECATED;
1266 void generateTsFile(
const QString &locale );
1278 QString
translate(
const QString &context,
const QString &sourceText,
const char *disambiguation =
nullptr,
int n = -1 )
const override;
1292 SIP_PYOBJECT __repr__();
1294 QString str = QStringLiteral(
"<QgsProject: '%1'%2>" ).arg( sipCpp->fileName(),
1296 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1314 void readProject(
const QDomDocument & );
1324 void writeProject( QDomDocument & );
1334 void readMapLayer(
QgsMapLayer *mapLayer,
const QDomElement &layerNode );
1344 void writeMapLayer(
QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
1349 void projectSaved();
1354 void oldProjectVersionWarning(
const QString & );
1361 void layerLoaded(
int i,
int n );
1364 void loadingLayer(
const QString &layerName );
1372 void loadingLayerMessageReceived(
const QString &layerName,
const QList<QgsReadWriteContext::ReadWriteMessage> &messages );
1378 Q_DECL_DEPRECATED
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
1381 void fileNameChanged();
1389 void homePathChanged();
1400 void customVariablesChanged();
1416 void ellipsoidChanged(
const QString &ellipsoid );
1425 void transformContextChanged();
1431 void missingDatumTransforms(
const QStringList &missingTransforms );
1439 void transactionGroupsChanged();
1446 void topologicalEditingChanged();
1453 void avoidIntersectionsLayersChanged();
1466 void mapThemeCollectionChanged();
1472 void labelingEngineSettingsChanged();
1480 void metadataChanged();
1488 void projectColorsChanged();
1496 void backgroundColorChanged();
1504 void selectionColorChanged();
1517 void layersWillBeRemoved(
const QStringList &layerIds );
1526 void layersWillBeRemoved(
const QList<QgsMapLayer *> &layers );
1537 void layerWillBeRemoved(
const QString &layerId );
1556 void layersRemoved(
const QStringList &layerIds );
1566 void layerRemoved(
const QString &layerId );
1588 void layersAdded(
const QList<QgsMapLayer *> &layers );
1606 void legendLayersAdded(
const QList<QgsMapLayer *> &layers );
1615 void isDirtyChanged(
bool dirty );
1660 void setDirty(
bool b =
true );
1670 void setPresetHomePath(
const QString &path );
1692 void onMapLayersAdded(
const QList<QgsMapLayer *> &layers );
1693 void onMapLayersRemoved(
const QList<QgsMapLayer *> &layers );
1694 void cleanTransactionGroups(
bool force =
false );
1718 bool _getMapLayers(
const QDomDocument &doc, QList<QDomNode> &brokenNodes, QgsProject::ReadFlags flags =
nullptr );
1724 void setError(
const QString &errorMessage )
SIP_SKIP;
1739 bool addLayer(
const QDomElement &layerElem, QList<QDomNode> &brokenNodes,
QgsReadWriteContext &context, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
1746 void initializeEmbeddedSubtree(
const QString &projectFilePath,
QgsLayerTreeGroup *group, QgsProject::ReadFlags flags =
nullptr )
SIP_SKIP;
1755 bool readProjectFile(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
1758 bool writeProjectFile(
const QString &filename );
1761 bool unzip(
const QString &filename, QgsProject::ReadFlags flags =
nullptr );
1764 bool zip(
const QString &filename );
1767 bool saveAuxiliaryStorage(
const QString &filename = QString() );
1769 std::unique_ptr< QgsMapLayerStore > mLayerStore;
1771 QString mErrorMessage;
1780 QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
1786 std::unique_ptr<QgsAnnotationManager> mAnnotationManager;
1787 std::unique_ptr<QgsLayoutManager> mLayoutManager;
1802 std::unique_ptr<QgsMapThemeCollection> mMapThemeCollection;
1804 std::unique_ptr<QgsLabelingEngineSettings> mLabelingEngineSettings;
1806 QVariantMap mCustomVariables;
1808 std::unique_ptr<QgsProjectArchive> mArchive;
1810 std::unique_ptr<QgsAuxiliaryStorage> mAuxiliaryStorage;
1815 QString mSaveUserFull;
1822 mutable QString mCachedHomePath;
1824 QColor mBackgroundColor;
1825 QColor mSelectionColor;
1828 bool mAutoTransaction =
false;
1829 bool mEvaluateDefaultValues =
false;
1831 bool mDirty =
false;
1832 int mDirtyBlockCount = 0;
1833 bool mTrustLayerMetadata =
false;
1839 std::unique_ptr< QTranslator > mTranslator;
1841 bool mIsBeingDeleted =
false;
1843 mutable std::unique_ptr< QgsExpressionContextScope > mProjectScope;
1853 friend class TestQgsProject;
1856 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProject::ReadFlags )
1889 : mProject( project )
1891 mProject->mDirtyBlockCount++;
1895 QgsProjectDirtyBlocker(
const QgsProjectDirtyBlocker &other ) =
delete;
1898 QgsProjectDirtyBlocker &operator=(
const QgsProjectDirtyBlocker &other ) =
delete;
1902 mProject->mDirtyBlockCount--;
1909 QgsProjectDirtyBlocker(
const QgsProjectDirtyBlocker &other );
1927 GetNamedProjectColor(
const QgsProject *project );
1933 GetNamedProjectColor(
const QHash< QString, QColor > &colors );
1940 QHash< QString, QColor > mColors;
Class for parsing and evaluation of expressions (formerly called "search strings").
Layer tree group node serves as a container for layers and further groups.
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Manages storage of a set of QgsAnnotation annotation objects.
Class providing some utility methods to manage auxiliary storage.
#define SIP_MONKEYPATCH_SCOPEENUM
Manages storage of a set of bookmarks.
QgsLayerTreeRegistryBridge * layerTreeRegistryBridge() const
Returns pointer to the helper class that synchronizes map layer registry with layer tree...
const QgsCoordinateReferenceSystem & crs
An interface for classes which can visit style entity (e.g.
QMap< QString, QString > QgsStringMap
FileFormat
Flags which control project read behavior.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
T mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
bool trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
ReadFlag
Flags which control project read behavior.
Namespace with helper functions for layer tree operations.
CORE_EXPORT bool unzip(const QString &zip, const QString &dir, QStringList &files)
Unzip a zip file in an output directory.
CORE_EXPORT QgsProjectVersion getVersion(QDomDocument const &doc)
Returns the version string found in the given DOM document.
A class to describe the version of a project.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This is the class is providing tolerance value in map unit values.
Listens to the updates in map layer registry and does changes in layer tree.
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Single scope for storing variables and functions for use within a QgsExpressionContext.
An expression node for expression functions.
Contains information about the context in which a coordinate transform is executed.
Wherever an object of this class is available, the derived translate function can be called from...
Manages storage of a set of layouts.
Used for the collecting of strings from projects for translation and creation of ts files...
Abstract interface for generating an expression context.
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
Contains settings and properties relating to how a QgsProject should be displayed inside map canvas...
A registry / canonical manager of data providers.
Project property key node.
DistanceUnit
Units of distance.
Cache for server configuration.
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
virtual QgsExpressionContextScope * createExpressionContextScope() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
~QgsProjectDirtyBlocker()
Abstract interface for generating an expression context scope.
This class manages a set of relations between layers.
Stores global configuration for labeling engine.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Abstract interface for project storage - to be implemented by various backends and registered in QgsP...
QgsProjectDirtyBlocker(QgsProject *project)
Constructor for QgsProjectDirtyBlocker.
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Contains settings and properties relating to how a QgsProject should display values such as map coord...
Container class that allows storage of map themes consisting of visible map layers and layer styles...
This is a container for configuration of the snapping of the project.
Resolves relative paths into absolute paths and vice versa.
Represents a vector layer which manages a vector based data sets.
CORE_EXPORT bool zip(const QString &zip, const QStringList &files)
Zip the list of files in the zip file.
Expression function for use within a QgsExpressionContextScope.
Interface for classes that handle missing layer files when reading project file.
QVector< T > mapLayersByShortName(const QString &shortName) const
Retrieves a list of matching registered layers by layer shortName with a specified layer type...