QgsProject class
Reads and writes project states.
Contents
Has two general kinds of state to make persistent. (I.e., to read and write.) First, QGIS proprietary information. Second plug-in information.
A singleton since there shall only be one active project at a time; and provides canonical location for plug-ins and main app to find/set properties.
Base classes
- class QgsExpressionContextGenerator
- Abstract interface for generating an expression context.
- class QgsProjectTranslator
- Wherever an object of this class is available, the derived translate function can be called from.
Public static functions
- static auto instance() -> QgsProject*
- Returns the QgsProject singleton instance.
Constructors, destructors, conversion operators
- QgsProject(QObject* parent = nullptr) explicit
- Create a new QgsProject.
Public functions
- auto absoluteFilePath() const -> QString
- Returns full absolute path to the project file if the project is stored in a file system - derived from fileName().
- auto absolutePath() const -> QString
- Returns full absolute path to the project folder if the project is stored in a file system - derived from fileName().
- auto addMapLayer(QgsMapLayer* mapLayer, bool addToLegend = true, bool takeOwnership = true) -> QgsMapLayer*
- Add a layer to the map of loaded layers.
- auto addMapLayers(const QList<QgsMapLayer*>& mapLayers, bool addToLegend = true, bool takeOwnership = true) -> QList<QgsMapLayer*>
- Add a list of layers to the map of loaded layers.
- auto annotationManager() -> QgsAnnotationManager*
- Returns pointer to the project's annotation manager.
- auto annotationManager() const -> const QgsAnnotationManager*
- Returns a const pointer to the project's annotation manager.
-
auto areaUnits() const -> QgsUnitTypes::
AreaUnit - Convenience function to query default area measurement units for project.
- auto autoTransaction() const -> bool
- Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
- auto auxiliaryStorage() const -> const QgsAuxiliaryStorage*
- Returns the current const auxiliary storage.
- auto auxiliaryStorage() -> QgsAuxiliaryStorage*
- Returns the current auxiliary storage.
- auto avoidIntersectionsLayers() const -> QList<QgsVectorLayer*>
- A list of layers with which intersections should be avoided.
- auto baseName() const -> QString
- Returns the base name of the project file without the path and without extension - derived from fileName().
- void clear()
- Clears the project, removing all settings and resetting it back to an empty, default state.
- auto count() const -> int
- Returns the number of registered layers.
- auto createEmbeddedGroup(const QString& groupName, const QString& projectFilePath, const QStringList& invisibleLayers) -> QgsLayerTreeGroup*
- Create layer group instance defined in an arbitrary project file.
- auto createEmbeddedLayer(const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, bool saveFlag = true) -> bool
- Creates a maplayer instance defined in an arbitrary project file.
- auto createExpressionContext() const -> QgsExpressionContext override
- This method needs to be reimplemented in all classes which implement this interface and return an expression context.
- auto crs() const -> QgsCoordinateReferenceSystem
- Returns the project's native coordinate reference system.
- auto customVariables() const -> QVariantMap
- A map of custom project variables.
- auto defaultCrsForNewLayers() const -> QgsCoordinateReferenceSystem
- Returns the default CRS for new layers based on the settings and the current project CRS.
-
auto distanceUnits() const -> QgsUnitTypes::
DistanceUnit - Convenience function to query default distance measurement units for project.
- void dumpProperties() const
- Dump out current project properties to stderr.
- auto ellipsoid() const -> QString
- Returns a proj string representing the project's ellipsoid setting, e.g., "WGS84".
- auto entryList(const QString& scope, const QString& key) const -> QStringList
- Returns keys with values – do not return keys that contain other keys.
- auto error() const -> QString
- Returns error message from previous read/write.
- auto evaluateDefaultValues() const -> bool
- Should default values be evaluated on provider side when requested and not when committed.
- auto fileInfo() const -> Q_DECL_DEPRECATED QFileInfo deprecated
- Returns QFileInfo object for the project's associated file.
- auto fileName() const -> QString
- Returns the project's file name.
- void generateTsFile(const QString& locale)
- Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile()
- auto homePath() const -> QString
- Returns the project's home path.
- auto isDirty() const -> bool
- Returns true if the project has been modified since the last write()
- auto isZipped() const -> bool
- Returns true if the project comes from a zip archive, false otherwise.
- auto labelingEngineSettings() const -> const QgsLabelingEngineSettings&
- Returns project's global labeling engine settings.
- auto lastModified() const -> QDateTime
- Returns last modified time of the project file as returned by the file system (or other project storage).
- auto layerIsEmbedded(const QString& id) const -> QString
- Returns project file path if layer is embedded from other project file. Returns empty string if layer is not embedded.
-
template<typename T>auto layers() const -> QVector<T>
- Returns a list of registered map layers with a specified layer type.
- auto layerStore() -> QgsMapLayerStore*
- Returns a pointer to the project's internal layer store.
- auto layerStore() const -> const QgsMapLayerStore*
- Returns a pointer to the project's internal layer store.
- auto layerTreeRegistryBridge() const -> QgsLayerTreeRegistryBridge*
- Returns pointer to the helper class that synchronizes map layer registry with layer tree.
- auto layerTreeRoot() const -> QgsLayerTree*
- Returns pointer to the root (invisible) node of the project's layer tree.
- auto layoutManager() const -> const QgsLayoutManager*
- Returns the project's layout manager, which manages compositions within the project.
- auto layoutManager() -> QgsLayoutManager*
- Returns the project's layout manager, which manages compositions within the project.
- auto mapLayer(const QString& layerId) const -> QgsMapLayer*
- Retrieve a pointer to a registered layer by layer ID.
-
template<class T>auto mapLayer(const QString& layerId) const -> T
- Retrieve a pointer to a registered layer by
layerIdconverted to type T. - auto mapLayers(const bool validOnly = false) const -> QMap<QString, QgsMapLayer*>
- Returns a map of all registered layers by layer ID.
- auto mapLayersByName(const QString& layerName) const -> QList<QgsMapLayer*>
- Retrieve a list of matching registered layers by layer name.
- auto mapThemeCollection() -> QgsMapThemeCollection*
- Returns pointer to the project's map theme collection.
- auto metadata() const -> const QgsProjectMetadata&
- Returns a reference to the project's metadata store.
- auto nonIdentifiableLayers() const -> Q_DECL_DEPRECATED QStringList deprecated
- Gets the list of layers which currently should not be taken into account on map identification.
- auto pathResolver() const -> QgsPathResolver
- Returns path resolver object with considering whether the project uses absolute or relative paths and using current project's path.
- auto presetHomePath() const -> QString
- Returns any manual project home path setting, or an empty string if not set.
- auto projectStorage() const -> QgsProjectStorage*
- Returns pointer to project storage implementation that handles read/write of the project file.
- auto read(const QString& filename) -> bool
- Reads given project file from the given file.
- auto read() -> bool
- Reads the project from its currently associated file (see fileName() ).
- auto readLayer(const QDomNode& layerNode) -> bool
- Reads the layer described in the associated DOM node.
- auto readListEntry(const QString& scope, const QString& key, const QStringList& def = QStringList(), bool* ok = nullptr) const -> QStringList
- Key value accessors.
- auto readPath(const QString& filename) const -> QString
- Turn filename read from the project file to an absolute path.
- void reloadAllLayers()
- Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource.
- void removeAllMapLayers()
- Removes all registered layers.
- auto removeEntry(const QString& scope, const QString& key) -> bool
- Remove the given key.
- void removeMapLayer(const QString& layerId)
- Remove a layer from the registry by layer ID.
- void removeMapLayer(QgsMapLayer* layer)
- Remove a layer from the registry.
- void removeMapLayers(const QStringList& layerIds)
- Remove a set of layers from the registry by layer ID.
- void removeMapLayers(const QList<QgsMapLayer*>& layers)
- Remove a set of layers from the registry.
- auto requiredLayers() const -> Q_DECL_DEPRECATED QSet<QgsMapLayer*> deprecated
- Returns a set of map layers that are required in the project and therefore they should not get removed from the project.
-
void setAreaUnits(QgsUnitTypes::
AreaUnit unit) - Sets the default area measurement units for the project.
- void setAutoTransaction(bool autoTransaction)
- Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
- void setAvoidIntersectionsLayers(const QList<QgsVectorLayer*>& layers)
- A list of layers with which intersections should be avoided.
- void setBadLayerHandler(QgsProjectBadLayerHandler* handler)
- Change handler for missing layers.
- void setCrs(const QgsCoordinateReferenceSystem& crs)
- Sets the project's native coordinate reference system.
- void setCustomVariables(const QVariantMap& customVariables)
- A map of custom project variables.
-
void setDistanceUnits(QgsUnitTypes::
DistanceUnit unit) - Sets the default distance measurement units for the project.
- void setEllipsoid(const QString& ellipsoid)
- Sets the project's ellipsoid from a proj string representation, e.g., "WGS84".
- void setEvaluateDefaultValues(bool evaluateDefaultValues)
- Defines if default values should be evaluated on provider side when requested and not when committed.
- void setFileName(const QString& name)
- Sets the file name associated with the project.
- void setLabelingEngineSettings(const QgsLabelingEngineSettings& settings)
- Sets project's global labeling engine settings.
- void setMetadata(const QgsProjectMetadata& metadata)
- Sets the project's metadata store.
- auto setNonIdentifiableLayers(const QList<QgsMapLayer*>& layers) -> Q_DECL_DEPRECATED void deprecated
- Set a list of layers which should not be taken into account on map identification.
- auto setNonIdentifiableLayers(const QStringList& layerIds) -> Q_DECL_DEPRECATED void deprecated
- Set a list of layers which should not be taken into account on map identification.
- void setProjectColors(const QgsNamedColorList& colors)
- Sets the colors for the project's color scheme (see QgsProjectColorScheme).
- auto setRequiredLayers(const QSet<QgsMapLayer*>& layers) -> Q_DECL_DEPRECATED void deprecated
- Configures a set of map layers that are required in the project and therefore they should not get removed from the project.
- void setTitle(const QString& title)
- Sets the project's title.
- void setTopologicalEditing(bool enabled)
- Convenience function to set topological editing.
- void setTransformContext(const QgsCoordinateTransformContext& context)
- Sets the project's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
- void setTrustLayerMetadata(bool trust)
- Sets the trust option allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it.
- auto snappingConfig() const -> QgsSnappingConfig
- The snapping configuration for this project.
- auto subkeyList(const QString& scope, const QString& key) const -> QStringList
- Returns keys with keys – do not return keys that contain only values.
- auto takeMapLayer(QgsMapLayer* layer) -> QgsMapLayer*
- Takes a layer from the registry.
- auto title() const -> QString
- Returns the project's title.
- auto topologicalEditing() const -> bool
- Convenience function to query topological editing status.
- auto transactionGroup(const QString& providerKey, const QString& connString) -> QgsTransactionGroup*
- Returns the matching transaction group from a provider key and connection string.
- auto transactionGroups() -> QMap<QPair<QString, QString>, QgsTransactionGroup*>
- Map of transaction groups.
- auto transformContext() const -> QgsCoordinateTransformContext
- Returns a copy of the project's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
- auto translate(const QString& context, const QString& sourceText, const char* disambiguation = nullptr, int n = -1) const -> QString override
- Translates the project with QTranslator and qm file.
- auto trustLayerMetadata() const -> bool
- Returns true if the trust option is activated, false otherwise.
- auto validCount() const -> int
- Returns the number of registered valid layers.
- auto write(const QString& filename) -> bool
- Writes the project to a file.
- auto write() -> bool
- Writes the project to its current associated file (see fileName() ).
- auto writeEntry(const QString& scope, const QString& key, bool value) -> bool
- Write a boolean entry to the project file.
- auto writeEntry(const QString& scope, const QString& key, double value) -> bool
- Write a double entry to the project file.
- auto writeEntry(const QString& scope, const QString& key, int value) -> bool
- Write an integer entry to the project file.
- auto writeEntry(const QString& scope, const QString& key, const QString& value) -> bool
- Write a string entry to the project file.
- auto writeEntry(const QString& scope, const QString& key, const QStringList& value) -> bool
- Write a string list entry to the project file.
- auto writePath(const QString& filename) const -> QString
- Prepare a filename to save it to the project file.
Signals
- void avoidIntersectionsLayersChanged()
- Emitted whenever avoidIntersectionsLayers has changed.
- void cleared()
- Emitted when the project is cleared (and additionally when an open project is cleared just before a new project is read).
- void crsChanged()
- Emitted when the CRS of the project has changed.
- void customVariablesChanged()
- Emitted whenever the expression variables stored in the project have been changed.
- void ellipsoidChanged(const QString& ellipsoid)
- Emitted when the project ellipsoid is changed.
- void fileNameChanged()
- Emitted when the file name of the project changes.
- void homePathChanged()
- Emitted when the home path of the project changes.
- void isDirtyChanged(bool dirty)
- Emitted when the project dirty status changes.
- void labelingEngineSettingsChanged()
- Emitted when global configuration of the labeling engine changes.
- void layerLoaded(int i, int n)
- Emitted when a layer from a projects was read.
- void layerRemoved(const QString& layerId)
- Emitted after a layer was removed from the registry.
- void layersAdded(const QList<QgsMapLayer*>& layers)
- Emitted when one or more layers were added to the registry.
- void layersRemoved(const QStringList& layerIds)
- Emitted after one or more layers were removed from the registry.
- void layersWillBeRemoved(const QStringList& layerIds)
- Emitted when one or more layers are about to be removed from the registry.
- void layersWillBeRemoved(const QList<QgsMapLayer*>& layers)
- Emitted when one or more layers are about to be removed from the registry.
- void layerWasAdded(QgsMapLayer* layer)
- Emitted when a layer was added to the registry.
- void layerWillBeRemoved(const QString& layerId)
- Emitted when a layer is about to be removed from the registry.
- void layerWillBeRemoved(QgsMapLayer* layer)
- Emitted when a layer is about to be removed from the registry.
- void legendLayersAdded(const QList<QgsMapLayer*>& layers)
- Emitted, when a layer was added to the registry and the legend.
- void loadingLayer(const QString& layerName)
- Emitted when a layer is loaded.
-
void loadingLayerMessageReceived(const QString& layerName,
const QList<QgsReadWriteContext::
ReadWriteMessage>& messages) - Emitted when loading layers has produced some messages.
- void mapThemeCollectionChanged()
- Emitted when the map theme collection changes.
- void metadataChanged()
- Emitted when the project's metadata is changed.
- void missingDatumTransforms(const QStringList& missingTransforms)
- Emitted when datum transforms stored in the project are not available locally.
- auto nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers) -> Q_DECL_DEPRECATED void deprecated
- Emitted when the list of layer which are excluded from map identification changes.
- void oldProjectVersionWarning(const QString&)
- Emitted when an old project file is read.
- void projectColorsChanged()
- Emitted whenever the project's color scheme has been changed.
- void projectSaved()
- Emitted when the project file has been written and closed.
- void readMapLayer(QgsMapLayer* mapLayer, const QDomElement& layerNode)
- Emitted after the basic initialization of a layer from the project file is done.
- void readProject(const QDomDocument&)
- Emitted when a project is being read.
- void readProjectWithContext(const QDomDocument&, QgsReadWriteContext& context)
- Emitted when a project is being read.
- void removeAll()
- Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted.
- void snappingConfigChanged(const QgsSnappingConfig& config)
- Emitted whenever the configuration for snapping has changed.
- void topologicalEditingChanged()
- Emitted when the topological editing flag has changed.
- void transactionGroupsChanged()
- Emitted whenever a new transaction group has been created or a transaction group has been removed.
- void transformContextChanged()
- Emitted when the project transformContext() is changed.
- void writeMapLayer(QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc)
- Emitted when a layer is being saved.
- void writeProject(QDomDocument&)
- Emitted when the project is being written.
Public slots
- void registerTranslatableContainers(QgsTranslationContext* translationContext, QgsAttributeEditorContainer* parent, const QString& layerId)
- Registers the containers that require translation into the translationContext.
- void registerTranslatableObjects(QgsTranslationContext* translationContext)
- Registers the objects that require translation into the translationContext.
- void setDirty(bool b = true)
- Flag the project as dirty (modified).
- void setPresetHomePath(const QString& path)
- Sets the project's home path.
- void setSnappingConfig(const QgsSnappingConfig& snappingConfig)
- The snapping configuration for this project.
Function documentation
QgsProject:: QgsProject(QObject* parent = nullptr) explicit
Create a new QgsProject.
Most of the time you want to use QgsProject::
QString QgsProject:: absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
QString QgsProject:: absolutePath() const
Returns full absolute path to the project folder if the project is stored in a file system - derived from fileName().
Returns empty string when the project is stored in a project storage (there is no concept of paths for custom project storages).
QgsMapLayer* QgsProject:: addMapLayer(QgsMapLayer* mapLayer,
bool addToLegend = true,
bool takeOwnership = true)
Add a layer to the map of loaded layers.
| Parameters | |
|---|---|
| mapLayer | A layer to add to the registry |
| addToLegend | If true (by default), the layer will be added to the legend and to the main canvas. If you have a private layer you can set this parameter to false to hide it. |
| takeOwnership | Ownership will be transferred to the layer registry. If you specify false here you have take care of deleting the layer yourself. Not available in Python. |
| Returns | nullptr if unable to add layer, otherwise pointer to newly added layer |
The layersAdded() and layerWasAdded() signals will always be emitted. The legendLayersAdded() signal is emitted only if addToLegend is true. If you are adding multiple layers at once, you should use addMapLayers() instead.
QList<QgsMapLayer*> QgsProject:: addMapLayers(const QList<QgsMapLayer*>& mapLayers,
bool addToLegend = true,
bool takeOwnership = true)
Add a list of layers to the map of loaded layers.
| Parameters | |
|---|---|
| mapLayers | A list of layer which should be added to the registry |
| addToLegend | If true (by default), the layers will be added to the legend and to the main canvas. If you have a private layer you can set this parameter to false to hide it. |
| takeOwnership | Ownership will be transferred to the layer registry. If you specify false here you have take care of deleting the layers yourself. Not available in Python. |
| Returns | a list of the map layers that were added successfully. If a layer or already exists in the registry, it will not be part of the returned QList. |
The layersAdded() and layerWasAdded() signals will always be emitted. The legendLayersAdded() signal is emitted only if addToLegend is true.
QgsAnnotationManager* QgsProject:: annotationManager()
Returns pointer to the project's annotation manager.
const QgsAnnotationManager* QgsProject:: annotationManager() const
Returns a const pointer to the project's annotation manager.
QgsUnitTypes:: AreaUnit QgsProject:: areaUnits() const
Convenience function to query default area measurement units for project.
bool QgsProject:: autoTransaction() const
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
const QgsAuxiliaryStorage* QgsProject:: auxiliaryStorage() const
Returns the current const auxiliary storage.
QgsAuxiliaryStorage* QgsProject:: auxiliaryStorage()
Returns the current auxiliary storage.
QList<QgsVectorLayer*> QgsProject:: avoidIntersectionsLayers() const
A list of layers with which intersections should be avoided.
QString QgsProject:: baseName() const
Returns the base name of the project file without the path and without extension - derived from fileName().
void QgsProject:: clear()
Clears the project, removing all settings and resetting it back to an empty, default state.
QgsLayerTreeGroup* QgsProject:: createEmbeddedGroup(const QString& groupName,
const QString& projectFilePath,
const QStringList& invisibleLayers)
Create layer group instance defined in an arbitrary project file.
bool QgsProject:: createEmbeddedLayer(const QString& layerId,
const QString& projectFilePath,
QList<QDomNode>& brokenNodes,
bool saveFlag = true)
Creates a maplayer instance defined in an arbitrary project file.
| Returns | the layer or 0 in case of error |
|---|
Caller takes ownership
QgsExpressionContext QgsProject:: createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an expression context.
QgsCoordinateReferenceSystem QgsProject:: crs() const
Returns the project's native coordinate reference system.
QVariantMap QgsProject:: customVariables() const
A map of custom project variables.
To get all available variables including generated ones use QgsExpressionContextUtils::
QgsUnitTypes:: DistanceUnit QgsProject:: distanceUnits() const
Convenience function to query default distance measurement units for project.
QString QgsProject:: ellipsoid() const
Returns a proj string representing the project's ellipsoid setting, e.g., "WGS84".
QStringList QgsProject:: entryList(const QString& scope,
const QString& key) const
Returns keys with values – do not return keys that contain other keys.
bool QgsProject:: evaluateDefaultValues() const
Should default values be evaluated on provider side when requested and not when committed.
Q_DECL_DEPRECATED QFileInfo QgsProject:: fileInfo() const
Returns QFileInfo object for the project's associated file.
QString QgsProject:: fileName() const
Returns the project's file name.
This is the file which contains the project's XML representation.
void QgsProject:: generateTsFile(const QString& locale)
Triggers the collection strings of .qgs to be included in ts file and calls writeTsFile()
QString QgsProject:: homePath() const
Returns the project's home path.
This will either be a manually set home path (see presetHomePath()) or the path containing the project file itself.
This method always returns the absolute path to the project's home. See presetHomePath() to retrieve any manual project home path override (e.g. relative home paths).
const QgsLabelingEngineSettings& QgsProject:: labelingEngineSettings() const
Returns project's global labeling engine settings.
QDateTime QgsProject:: lastModified() const
Returns last modified time of the project file as returned by the file system (or other project storage).
template<typename T>
QVector<T> QgsProject:: layers() const
Returns a list of registered map layers with a specified layer type.
Example:
QVector<QgsVectorLayer*> vectorLayers = QgsProject::instance()->layers<QgsVectorLayer*>();
QgsMapLayerStore* QgsProject:: layerStore()
Returns a pointer to the project's internal layer store.
/since QGIS 3.0
const QgsMapLayerStore* QgsProject:: layerStore() const
Returns a pointer to the project's internal layer store.
/since QGIS 3.0
QgsLayerTreeRegistryBridge* QgsProject:: layerTreeRegistryBridge() const
Returns pointer to the helper class that synchronizes map layer registry with layer tree.
QgsLayerTree* QgsProject:: layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
const QgsLayoutManager* QgsProject:: layoutManager() const
Returns the project's layout manager, which manages compositions within the project.
QgsLayoutManager* QgsProject:: layoutManager()
Returns the project's layout manager, which manages compositions within the project.
QgsMapLayer* QgsProject:: mapLayer(const QString& layerId) const
Retrieve a pointer to a registered layer by layer ID.
| Parameters | |
|---|---|
| layerId | ID of layer to retrieve |
| Returns | matching layer, or nullptr if no matching layer found |
template<class T>
T QgsProject:: mapLayer(const QString& layerId) const
Retrieve a pointer to a registered layer by layerId converted to type T.
This is a convenience template. A nullptr will be returned if the layer is not found or if it cannot be cast to type T.
QgsVectorLayer *layer = project->mapLayer<QgsVectorLayer*>( layerId );
QMap<QString, QgsMapLayer*> QgsProject:: mapLayers(const bool validOnly = false) const
Returns a map of all registered layers by layer ID.
| Parameters | |
|---|---|
| validOnly | if set only valid layers will be returned |
QList<QgsMapLayer*> QgsProject:: mapLayersByName(const QString& layerName) const
Retrieve a list of matching registered layers by layer name.
| Parameters | |
|---|---|
| layerName | name of layers to match |
| Returns | list of matching layers |
QgsMapThemeCollection* QgsProject:: mapThemeCollection()
Returns pointer to the project's map theme collection.
const QgsProjectMetadata& QgsProject:: metadata() const
Returns a reference to the project's metadata store.
Q_DECL_DEPRECATED QStringList QgsProject:: nonIdentifiableLayers() const
Gets the list of layers which currently should not be taken into account on map identification.
QgsPathResolver QgsProject:: pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and using current project's path.
QString QgsProject:: presetHomePath() const
Returns any manual project home path setting, or an empty string if not set.
This path may be a relative path. See homePath() to retrieve a path which is always an absolute path.
QgsProjectStorage* QgsProject:: projectStorage() const
Returns pointer to project storage implementation that handles read/write of the project file.
If the project file is stored in the local file system, returns null pointer. The project storage object is inferred from fileName() of the project.
bool QgsProject:: read(const QString& filename)
Reads given project file from the given file.
| Parameters | |
|---|---|
| filename | name of project file to read |
| Returns | true if project file has been read successfully |
bool QgsProject:: read()
Reads the project from its currently associated file (see fileName() ).
| Returns | true if project file has been read successfully |
|---|
bool QgsProject:: readLayer(const QDomNode& layerNode)
Reads the layer described in the associated DOM node.
| Parameters | |
|---|---|
| layerNode | represents a QgsProject DOM node that encodes a specific layer. |
QStringList QgsProject:: readListEntry(const QString& scope,
const QString& key,
const QStringList& def = QStringList(),
bool* ok = nullptr) const
Key value accessors.
keys would be the familiar QgsSettings-like '/' delimited entries, implying a hierarchy of keys and corresponding values
void QgsProject:: reloadAllLayers()
Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource.
void QgsProject:: removeAllMapLayers()
Removes all registered layers.
If the registry has ownership of any layers these layers will also be deleted.
void QgsProject:: removeMapLayer(const QString& layerId)
Remove a layer from the registry by layer ID.
| Parameters | |
|---|---|
| layerId | ID of the layer to remove |
The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
void QgsProject:: removeMapLayer(QgsMapLayer* layer)
Remove a layer from the registry.
| Parameters | |
|---|---|
| layer | The layer to remove. Null pointers are ignored. |
The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
void QgsProject:: removeMapLayers(const QStringList& layerIds)
Remove a set of layers from the registry by layer ID.
| Parameters | |
|---|---|
| layerIds | list of IDs of the layers to remove |
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
void QgsProject:: removeMapLayers(const QList<QgsMapLayer*>& layers)
Remove a set of layers from the registry.
| Parameters | |
|---|---|
| layers | A list of layers to remove. Null pointers are ignored. |
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
Q_DECL_DEPRECATED QSet<QgsMapLayer*> QgsProject:: requiredLayers() const
Returns a set of map layers that are required in the project and therefore they should not get removed from the project.
The set of layers may be configured by users in project properties. and it is mainly a hint for the user interface to protect users from removing layers that important in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here.
void QgsProject:: setAreaUnits(QgsUnitTypes:: AreaUnit unit)
Sets the default area measurement units for the project.
void QgsProject:: setAutoTransaction(bool autoTransaction)
Transactional editing means that on supported datasources (postgres databases) the edit state of all tables that originate from the same database are synchronized and executed in a server side transaction.
Make sure that this is only called when all layers are not in edit mode.
void QgsProject:: setAvoidIntersectionsLayers(const QList<QgsVectorLayer*>& layers)
A list of layers with which intersections should be avoided.
void QgsProject:: setBadLayerHandler(QgsProjectBadLayerHandler* handler)
Change handler for missing layers.
Deletes old handler and takes ownership of the new one.
void QgsProject:: setCrs(const QgsCoordinateReferenceSystem& crs)
Sets the project's native coordinate reference system.
void QgsProject:: setCustomVariables(const QVariantMap& customVariables)
A map of custom project variables.
Be careful not to set generated variables.
void QgsProject:: setDistanceUnits(QgsUnitTypes:: DistanceUnit unit)
Sets the default distance measurement units for the project.
void QgsProject:: setEllipsoid(const QString& ellipsoid)
Sets the project's ellipsoid from a proj string representation, e.g., "WGS84".
void QgsProject:: setEvaluateDefaultValues(bool evaluateDefaultValues)
Defines if default values should be evaluated on provider side when requested and not when committed.
void QgsProject:: setFileName(const QString& name)
Sets the file name associated with the project.
| Parameters | |
|---|---|
| name | project file name |
This is the file which contains the project's XML representation.
void QgsProject:: setLabelingEngineSettings(const QgsLabelingEngineSettings& settings)
Sets project's global labeling engine settings.
void QgsProject:: setMetadata(const QgsProjectMetadata& metadata)
Sets the project's metadata store.
Q_DECL_DEPRECATED void QgsProject:: setNonIdentifiableLayers(const QList<QgsMapLayer*>& layers)
Set a list of layers which should not be taken into account on map identification.
Q_DECL_DEPRECATED void QgsProject:: setNonIdentifiableLayers(const QStringList& layerIds)
Set a list of layers which should not be taken into account on map identification.
void QgsProject:: setProjectColors(const QgsNamedColorList& colors)
Sets the colors for the project's color scheme (see QgsProjectColorScheme).
Q_DECL_DEPRECATED void QgsProject:: setRequiredLayers(const QSet<QgsMapLayer*>& layers)
Configures a set of map layers that are required in the project and therefore they should not get removed from the project.
The set of layers may be configured by users in project properties. and it is mainly a hint for the user interface to protect users from removing layers that important in the project. The removeMapLayer(), removeMapLayers() calls do not block removal of layers listed here.
void QgsProject:: setTitle(const QString& title)
Sets the project's title.
| Parameters | |
|---|---|
| title | new title |
void QgsProject:: setTransformContext(const QgsCoordinateTransformContext& context)
Sets the project's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
void QgsProject:: setTrustLayerMetadata(bool trust)
Sets the trust option allowing to indicate if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it.
| Parameters | |
|---|---|
| trust | True to trust the project, false otherwise |
Moreover, when this option is activated, primary key unicity is not checked for views and materialized views with Postgres provider.
QgsSnappingConfig QgsProject:: snappingConfig() const
The snapping configuration for this project.
QStringList QgsProject:: subkeyList(const QString& scope,
const QString& key) const
Returns keys with keys – do not return keys that contain only values.
QgsMapLayer* QgsProject:: takeMapLayer(QgsMapLayer* layer)
Takes a layer from the registry.
If the layer was owned by the project, the layer will be returned without deleting it. The caller takes ownership of the layer and is responsible for deleting it.
QString QgsProject:: title() const
Returns the project's title.
QgsTransactionGroup* QgsProject:: transactionGroup(const QString& providerKey,
const QString& connString)
Returns the matching transaction group from a provider key and connection string.
Returns nullptr if a matching transaction group is not available.
QMap<QPair<QString, QString>, QgsTransactionGroup*> QgsProject:: transactionGroups()
Map of transaction groups.
QPair( providerKey, connString ) -> transactionGroup
QgsCoordinateTransformContext QgsProject:: transformContext() const
Returns a copy of the project's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.
QString QgsProject:: translate(const QString& context,
const QString& sourceText,
const char* disambiguation = nullptr,
int n = -1) const override
Translates the project with QTranslator and qm file.
| Parameters | |
|---|---|
| context | describing layer etc. |
| sourceText | is the identifier of this text |
| disambiguation | it's the disambiguation |
| n | if -1 uses the appropriate form |
| Returns | the result string (in case there is no QTranslator loaded the sourceText) |
bool QgsProject:: trustLayerMetadata() const
Returns true if the trust option is activated, false otherwise.
This option allows indicateing if the extent has to be read from the XML document when data source has no metadata or if the data provider has to determine it. Moreover, when this option is activated, primary key unicity is not checked for views and materialized views with Postgres provider.
bool QgsProject:: write(const QString& filename)
Writes the project to a file.
| Parameters | |
|---|---|
| filename | destination file |
| Returns | true if project was written successfully |
bool QgsProject:: write()
Writes the project to its current associated file (see fileName() ).
| Returns | true if project was written successfully |
|---|
bool QgsProject:: writeEntry(const QString& scope,
const QString& key,
bool value)
Write a boolean entry to the project file.
Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
bool QgsProject:: writeEntry(const QString& scope,
const QString& key,
double value)
Write a double entry to the project file.
Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
bool QgsProject:: writeEntry(const QString& scope,
const QString& key,
int value)
Write an integer entry to the project file.
Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
bool QgsProject:: writeEntry(const QString& scope,
const QString& key,
const QString& value)
Write a string entry to the project file.
Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
bool QgsProject:: writeEntry(const QString& scope,
const QString& key,
const QStringList& value)
Write a string list entry to the project file.
Keys are '/'-delimited entries, implying a hierarchy of keys and corresponding values
QString QgsProject:: writePath(const QString& filename) const
Prepare a filename to save it to the project file.
Creates an absolute or relative path according to the project settings. Paths written to the project file should be prepared with this method.
void QgsProject:: avoidIntersectionsLayersChanged() signal
Emitted whenever avoidIntersectionsLayers has changed.
void QgsProject:: cleared() signal
Emitted when the project is cleared (and additionally when an open project is cleared just before a new project is read).
void QgsProject:: crsChanged() signal
Emitted when the CRS of the project has changed.
void QgsProject:: customVariablesChanged() signal
Emitted whenever the expression variables stored in the project have been changed.
void QgsProject:: ellipsoidChanged(const QString& ellipsoid) signal
Emitted when the project ellipsoid is changed.
void QgsProject:: homePathChanged() signal
Emitted when the home path of the project changes.
void QgsProject:: isDirtyChanged(bool dirty) signal
Emitted when the project dirty status changes.
| Parameters | |
|---|---|
| dirty | True if the project is in a dirty state and has pending unsaved changes. |
void QgsProject:: labelingEngineSettingsChanged() signal
Emitted when global configuration of the labeling engine changes.
void QgsProject:: layerLoaded(int i,
int n) signal
Emitted when a layer from a projects was read.
| Parameters | |
|---|---|
| i | current layer |
| n | number of layers |
void QgsProject:: layerRemoved(const QString& layerId) signal
Emitted after a layer was removed from the registry.
| Parameters | |
|---|---|
| layerId | The ID of the layer removed. |
void QgsProject:: layersAdded(const QList<QgsMapLayer*>& layers) signal
Emitted when one or more layers were added to the registry.
| Parameters | |
|---|---|
| layers | List of layers which have been added. |
This signal is also emitted for layers added to the registry, but not to the legend.
void QgsProject:: layersRemoved(const QStringList& layerIds) signal
Emitted after one or more layers were removed from the registry.
| Parameters | |
|---|---|
| layerIds | A list of IDs of the layers which were removed. |
void QgsProject:: layersWillBeRemoved(const QStringList& layerIds) signal
Emitted when one or more layers are about to be removed from the registry.
| Parameters | |
|---|---|
| layerIds | A list of IDs for the layers which are to be removed. |
void QgsProject:: layersWillBeRemoved(const QList<QgsMapLayer*>& layers) signal
Emitted when one or more layers are about to be removed from the registry.
| Parameters | |
|---|---|
| layers | A list of layers which are to be removed. |
void QgsProject:: layerWasAdded(QgsMapLayer* layer) signal
Emitted when a layer was added to the registry.
void QgsProject:: layerWillBeRemoved(const QString& layerId) signal
Emitted when a layer is about to be removed from the registry.
| Parameters | |
|---|---|
| layerId | The ID of the layer to be removed. |
void QgsProject:: layerWillBeRemoved(QgsMapLayer* layer) signal
Emitted when a layer is about to be removed from the registry.
| Parameters | |
|---|---|
| layer | The layer to be removed. |
void QgsProject:: legendLayersAdded(const QList<QgsMapLayer*>& layers) signal
Emitted, when a layer was added to the registry and the legend.
| Parameters | |
|---|---|
| layers | List of QgsMapLayer which were added to the legend. |
Layers can also be private layers, which are signalled by layersAdded() and layerWasAdded() but will not be advertised by this signal.
void QgsProject:: loadingLayerMessageReceived(const QString& layerName,
const QList<QgsReadWriteContext:: ReadWriteMessage>& messages) signal
Emitted when loading layers has produced some messages.
| Parameters | |
|---|---|
| layerName | the layer name |
| messages | a list of pairs of Qgis:: |
void QgsProject:: mapThemeCollectionChanged() signal
Emitted when the map theme collection changes.
This only happens when the map theme collection is reset. Any pointer previously received from mapThemeCollection() must no longer be used after this signal is emitted. You must still connect to signals from the map theme collection if you want to be notified about new map themes being added and map themes being removed.
void QgsProject:: metadataChanged() signal
Emitted when the project's metadata is changed.
void QgsProject:: missingDatumTransforms(const QStringList& missingTransforms) signal
Emitted when datum transforms stored in the project are not available locally.
Q_DECL_DEPRECATED void QgsProject:: nonIdentifiableLayersChanged(QStringList nonIdentifiableLayers) signal
Emitted when the list of layer which are excluded from map identification changes.
void QgsProject:: projectColorsChanged() signal
Emitted whenever the project's color scheme has been changed.
void QgsProject:: readMapLayer(QgsMapLayer* mapLayer,
const QDomElement& layerNode) signal
Emitted after the basic initialization of a layer from the project file is done.
| Parameters | |
|---|---|
| mapLayer | The map layer which is being initialized |
| layerNode | The layer node from the project file |
You can use this signal to read additional information from the project file.
void QgsProject:: readProjectWithContext(const QDomDocument&,
QgsReadWriteContext& context) signal
Emitted when a project is being read.
And passing the /a context
void QgsProject:: removeAll() signal
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted.
The layersWillBeRemoved() and layerWillBeRemoved() signals will still be emitted following this signal. You can use this signal to do easy (and fast) cleanup.
void QgsProject:: topologicalEditingChanged() signal
Emitted when the topological editing flag has changed.
void QgsProject:: transactionGroupsChanged() signal
Emitted whenever a new transaction group has been created or a transaction group has been removed.
void QgsProject:: transformContextChanged() signal
Emitted when the project transformContext() is changed.
void QgsProject:: writeMapLayer(QgsMapLayer* mapLayer,
QDomElement& layerElem,
QDomDocument& doc) signal
Emitted when a layer is being saved.
| Parameters | |
|---|---|
| mapLayer | The map layer which is being initialized |
| layerElem | The layer element from the project file |
| doc | The document |
You can use this method to save additional information to the layer.
void QgsProject:: registerTranslatableContainers(QgsTranslationContext* translationContext,
QgsAttributeEditorContainer* parent,
const QString& layerId) public slot
Registers the containers that require translation into the translationContext.
| Parameters | |
|---|---|
| translationContext | where the objects will be registered |
| parent | parent-container containing list of children |
| layerId | to store under the correct context |
This is a recursive function to get all the child containers.
void QgsProject:: registerTranslatableObjects(QgsTranslationContext* translationContext) public slot
Registers the objects that require translation into the translationContext.
So there can be created a ts file with these values.
void QgsProject:: setDirty(bool b = true) public slot
Flag the project as dirty (modified).
If this flag is set, the user will be asked to save changes to the project before closing the current project.
void QgsProject:: setPresetHomePath(const QString& path) public slot
Sets the project's home path.
If an empty path is specified than the home path will be automatically determined from the project's file path.
void QgsProject:: setSnappingConfig(const QgsSnappingConfig& snappingConfig) public slot
The snapping configuration for this project.