QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
Reads and writes project states. More...
#include <qgsproject.h>
Classes | |
struct | Imp |
Public Slots | |
void | emitVariablesChanged () |
Causes the project to emit the variablesChanged() signal. More... | |
void | setDirty (bool b=true) |
Flag the project as dirty (modified). More... | |
Signals | |
void | fileNameChanged () |
Emitted when the file name of the project changes. More... | |
void | homePathChanged () |
Emitted when the home path of the project changes. More... | |
void | layerLoaded (int i, int n) |
emitted when a layer from a projects was read More... | |
void | loadingLayer (const QString &) |
void | nonIdentifiableLayersChanged (QStringList nonIdentifiableLayers) |
Emitted when the list of layer which are excluded from map identification changes. More... | |
void | oldProjectVersionWarning (const QString &) |
emitted when an old project file is read. More... | |
void | projectSaved () |
emitted when the project file has been written and closed More... | |
void | readMapLayer (QgsMapLayer *mapLayer, const QDomElement &layerNode) |
Emitted, after the basic initialization of a layer from the project file is done. More... | |
void | readProject (const QDomDocument &) |
emitted when project is being read More... | |
void | snapSettingsChanged () |
void | variablesChanged () |
Emitted whenever the expression variables stored in the project have been changed. More... | |
void | writeMapLayer (QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc) |
Emitted, when a layer is being saved. More... | |
void | writeProject (QDomDocument &) |
emitted when project is being written More... | |
Public Member Functions | |
~QgsProject () | |
QgsUnitTypes::AreaUnit | areaUnits () const |
Convenience function to query default area measurement units for project. More... | |
bool | 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. More... | |
void | clear () |
Clear the project - removes all settings and resets it back to an empty, default state. More... | |
Q_DECL_DEPRECATED void | clearProperties () |
Removes all project properties. More... | |
QgsLayerTreeGroup * | createEmbeddedGroup (const QString &groupName, const QString &projectFilePath, const QStringList &invisibleLayers) |
Create layer group instance defined in an arbitrary project file. More... | |
bool | createEmbeddedLayer (const QString &layerId, const QString &projectFilePath, QList< QDomNode > &brokenNodes, QList< QPair< QgsVectorLayer *, QDomElement > > &vectorLayerList, bool saveFlag=true) |
Creates a maplayer instance defined in an arbitrary project file. More... | |
Q_DECL_DEPRECATED void | dirty (bool b) |
Flag the project as dirty (modified). More... | |
QGis::UnitType | distanceUnits () const |
Convenience function to query default distance measurement units for project. More... | |
void | dumpProperties () const |
Dump out current project properties to stderr. More... | |
QStringList | entryList (const QString &scope, const QString &key) const |
Return keys with values – do not return keys that contain other keys. More... | |
QString | error () const |
Return error message from previous read/write. More... | |
bool | evaluateDefaultValues () const |
Should default values be evaluated on provider side when requested and not when committed. More... | |
QFileInfo | fileInfo () const |
Returns QFileInfo object for the project's associated file. More... | |
QString | fileName () const |
Returns the project's file name. More... | |
QString | homePath () const |
Return project's home path. More... | |
bool | isDirty () const |
Returns true if the project has been modified since the last write() More... | |
QString | layerIsEmbedded (const QString &id) const |
Returns project file path if layer is embedded from other project file. More... | |
QgsLayerTreeRegistryBridge * | layerTreeRegistryBridge () const |
Return pointer to the helper class that synchronizes map layer registry with layer tree. More... | |
QgsLayerTreeGroup * | layerTreeRoot () const |
Return pointer to the root (invisible) node of the project's layer tree. More... | |
QStringList | nonIdentifiableLayers () const |
Get the list of layers which currently should not be taken into account on map identification. More... | |
bool | read (const QFileInfo &file) |
Reads a project file. More... | |
bool | read () |
Reads the current project file. More... | |
bool | read (QDomNode &layerNode) |
Reads the layer described in the associated DOM node. More... | |
bool | readBoolEntry (const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const |
double | readDoubleEntry (const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const |
QString | readEntry (const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const |
QStringList | readListEntry (const QString &scope, const QString &key, const QStringList &def=QStringList(), bool *ok=nullptr) const |
Key value accessors. More... | |
int | readNumEntry (const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const |
QString | readPath (QString filename, const QString &relativeBasePath=QString()) const |
Turn filename read from the project file to an absolute path. More... | |
QgsRelationManager * | relationManager () const |
bool | removeEntry (const QString &scope, const QString &key) |
Remove the given key. More... | |
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. More... | |
void | setBadLayerHandler (QgsProjectBadLayerHandler *handler) |
Change handler for missing layers. More... | |
void | setEvaluateDefaultValues (bool evaluateDefaultValues) |
Defines if default values should be evaluated on provider side when requested and not when committed. More... | |
void | setFileName (const QString &name) |
Sets the file name associated with the project. More... | |
void | setNonIdentifiableLayers (QList< QgsMapLayer *> layers) |
Set a list of layers which should not be taken into account on map identification. More... | |
void | setNonIdentifiableLayers (const QStringList &layerIds) |
Set a list of layers which should not be taken into account on map identification. More... | |
void | setSnapSettingsForLayer (const QString &layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection) |
Convenience function to set snap settings per layer. More... | |
void | setTitle (const QString &title) |
Sets the project's title. More... | |
void | setTopologicalEditing (bool enabled) |
Convenience function to set topological editing. More... | |
bool | snapSettingsForLayer (const QString &layerId, bool &enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType &units, double &tolerance, bool &avoidIntersection) const |
Convenience function to query snap settings of a layer. More... | |
QStringList | subkeyList (const QString &scope, const QString &key) const |
Return keys with keys – do not return keys that contain only values. More... | |
Q_DECL_DEPRECATED void | title (const QString &title) |
Every project has an associated title string. More... | |
QString | title () const |
Returns the project's title. More... | |
bool | topologicalEditing () const |
Convenience function to query topological editing status. More... | |
QMap< QPair< QString, QString >, QgsTransactionGroup * > | transactionGroups () |
Map of transaction groups. More... | |
QgsVisibilityPresetCollection * | visibilityPresetCollection () |
Returns pointer to the project's visibility preset collection. More... | |
bool | write (const QFileInfo &file) |
Writes the project to a file. More... | |
bool | write () |
Writes the project to its current associated file (see fileName() ). More... | |
bool | writeEntry (const QString &scope, const QString &key, bool value) |
bool | writeEntry (const QString &scope, const QString &key, double value) |
bool | writeEntry (const QString &scope, const QString &key, int value) |
bool | writeEntry (const QString &scope, const QString &key, const QString &value) |
bool | writeEntry (const QString &scope, const QString &key, const QStringList &value) |
QString | writePath (const QString &filename, const QString &relativeBasePath=QString()) const |
Prepare a filename to save it to the project file. More... | |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QObject (QObject *parent, const char *name) | |
virtual | ~QObject () |
bool | blockSignals (bool block) |
QObject * | child (const char *objName, const char *inheritsClass, bool recursiveSearch) const |
const QObjectList & | children () const |
const char * | className () const |
bool | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const QObject *receiver, const char *method) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QByteArray > | dynamicPropertyNames () const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name) const |
QList< T > | findChildren (const QRegExp ®Exp) const |
QList< T > | findChildren (const QString &name) const |
bool | inherits (const char *className) const |
void | insertChild (QObject *object) |
void | installEventFilter (QObject *filterObj) |
bool | isA (const char *className) const |
bool | isWidgetType () const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
const char * | name () const |
const char * | name (const char *defaultName) const |
QString | objectName () const |
QObject * | parent () const |
QVariant | property (const char *name) const |
void | removeChild (QObject *object) |
void | removeEventFilter (QObject *obj) |
void | setName (const char *name) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval) |
QThread * | thread () const |
Static Public Member Functions | |
static QgsProject * | instance () |
Returns the QgsProject singleton instance. More... | |
Static Public Member Functions inherited from QObject | |
bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
Protected Member Functions | |
bool | addLayer (const QDomElement &layerElem, QList< QDomNode > &brokenNodes, QList< QPair< QgsVectorLayer *, QDomElement > > &vectorLayerList) |
Creates layer and adds it to maplayer registry. More... | |
void | clearError () |
Clear error message. More... | |
void | initializeEmbeddedSubtree (const QString &projectFilePath, QgsLayerTreeGroup *group) |
void | loadEmbeddedNodes (QgsLayerTreeGroup *group) |
void | setError (const QString &errorMessage) |
Set error message from read/write operation. More... | |
Protected Member Functions inherited from QObject | |
bool | checkConnectArgs (const char *signal, const QObject *object, const char *method) |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const char *signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const char *signal) |
int | receivers (const char *signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties | |
QString | fileName |
QString | homePath |
QStringList | nonIdentifiableLayers |
Properties inherited from QObject | |
objectName | |
Additional Inherited Members | |
Static Protected Member Functions inherited from QObject | |
QByteArray | normalizeSignalSlot (const char *signalSlot) |
Reads and writes project states.
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.
Definition at line 71 of file qgsproject.h.
QgsProject::~QgsProject | ( | ) |
Definition at line 374 of file qgsproject.cpp.
|
protected |
Creates layer and adds it to maplayer registry.
Definition at line 684 of file qgsproject.cpp.
QgsUnitTypes::AreaUnit QgsProject::areaUnits | ( | ) | const |
Convenience function to query default area measurement units for project.
Definition at line 2097 of file qgsproject.cpp.
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.
Definition at line 2174 of file qgsproject.cpp.
void QgsProject::clear | ( | ) |
Clear the project - removes all settings and resets it back to an empty, default state.
Definition at line 447 of file qgsproject.cpp.
|
protected |
Clear error message.
Definition at line 1652 of file qgsproject.cpp.
void QgsProject::clearProperties | ( | ) |
Removes all project properties.
Definition at line 1222 of file qgsproject.cpp.
QgsLayerTreeGroup * QgsProject::createEmbeddedGroup | ( | const QString & | groupName, |
const QString & | projectFilePath, | ||
const QStringList & | invisibleLayers | ||
) |
Create layer group instance defined in an arbitrary project file.
Definition at line 1823 of file qgsproject.cpp.
bool QgsProject::createEmbeddedLayer | ( | const QString & | layerId, |
const QString & | projectFilePath, | ||
QList< QDomNode > & | brokenNodes, | ||
QList< QPair< QgsVectorLayer *, QDomElement > > & | vectorLayerList, | ||
bool | saveFlag = true |
||
) |
Creates a maplayer instance defined in an arbitrary project file.
Caller takes ownership
Definition at line 1673 of file qgsproject.cpp.
|
inline |
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.
Definition at line 116 of file qgsproject.h.
QGis::UnitType QgsProject::distanceUnits | ( | ) | const |
Convenience function to query default distance measurement units for project.
Definition at line 2084 of file qgsproject.cpp.
void QgsProject::dumpProperties | ( | ) | const |
Dump out current project properties to stderr.
Definition at line 1430 of file qgsproject.cpp.
|
slot |
Causes the project to emit the variablesChanged() signal.
This should be called whenever expression variables related to the project are changed.
Definition at line 415 of file qgsproject.cpp.
QStringList QgsProject::entryList | ( | const QString & | scope, |
const QString & | key | ||
) | const |
Return keys with values – do not return keys that contain other keys.
Definition at line 1396 of file qgsproject.cpp.
QString QgsProject::error | ( | ) | const |
Return error message from previous read/write.
Definition at line 1647 of file qgsproject.cpp.
bool QgsProject::evaluateDefaultValues | ( | ) | const |
Should default values be evaluated on provider side when requested and not when committed.
Definition at line 2054 of file qgsproject.cpp.
QFileInfo QgsProject::fileInfo | ( | ) | const |
Returns QFileInfo object for the project's associated file.
Definition at line 442 of file qgsproject.cpp.
QString QgsProject::fileName | ( | ) | const |
Returns the project's file name.
This is the file which contains the project's XML representation.
|
signal |
Emitted when the file name of the project changes.
QString QgsProject::homePath | ( | ) | const |
Return project's home path.
|
signal |
Emitted when the home path of the project changes.
|
protected |
Definition at line 1905 of file qgsproject.cpp.
|
static |
Returns the QgsProject singleton instance.
Definition at line 382 of file qgsproject.cpp.
bool QgsProject::isDirty | ( | ) | const |
Returns true if the project has been modified since the last write()
Definition at line 405 of file qgsproject.cpp.
Returns project file path if layer is embedded from other project file.
Returns empty string if layer is not embedded
Definition at line 1663 of file qgsproject.cpp.
|
signal |
emitted when a layer from a projects was read
|
inline |
Return pointer to the helper class that synchronizes map layer registry with layer tree.
Definition at line 327 of file qgsproject.h.
QgsLayerTreeGroup * QgsProject::layerTreeRoot | ( | ) | const |
Return pointer to the root (invisible) node of the project's layer tree.
Definition at line 2129 of file qgsproject.cpp.
|
protected |
Definition at line 906 of file qgsproject.cpp.
|
signal |
QStringList QgsProject::nonIdentifiableLayers | ( | ) | const |
Get the list of layers which currently should not be taken into account on map identification.
|
signal |
Emitted when the list of layer which are excluded from map identification changes.
|
signal |
emitted when an old project file is read.
|
signal |
emitted when the project file has been written and closed
bool QgsProject::read | ( | const QFileInfo & | file | ) |
Reads a project file.
file | name of project file to read |
Definition at line 739 of file qgsproject.cpp.
bool QgsProject::read | ( | ) |
Reads the current project file.
Shows a warning when an old project file is read.
Definition at line 746 of file qgsproject.cpp.
bool QgsProject::read | ( | QDomNode & | layerNode | ) |
Reads the layer described in the associated DOM node.
layerNode | represents a QgsProject DOM node that encodes a specific layer. |
QgsProject raises an exception when one of the QgsProject::read() implementations fails. Since the read()s are invoked from qgisapp, then qgisapp handles the exception. It prompts the user for the new location of the data, if any. If there is a new location, the DOM node associated with the layer has its datasource tag corrected. Then that node is passed to this member function to be re-opened.
Definition at line 997 of file qgsproject.cpp.
bool QgsProject::readBoolEntry | ( | const QString & | scope, |
const QString & | key, | ||
bool | def = false , |
||
bool * | ok = nullptr |
||
) | const |
Definition at line 1365 of file qgsproject.cpp.
double QgsProject::readDoubleEntry | ( | const QString & | scope, |
const QString & | key, | ||
double | def = 0 , |
||
bool * | ok = nullptr |
||
) | const |
Definition at line 1345 of file qgsproject.cpp.
QString QgsProject::readEntry | ( | const QString & | scope, |
const QString & | key, | ||
const QString & | def = QString::null , |
||
bool * | ok = nullptr |
||
) | const |
Definition at line 1294 of file qgsproject.cpp.
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 QSettings-like '/' delimited entries, implying a hierarchy of keys and corresponding values
Definition at line 1267 of file qgsproject.cpp.
|
signal |
Emitted, after the basic initialization of a layer from the project file is done.
You can use this signal to read additional information from the project file.
mapLayer | The map layer which is being initialized |
layerNode | The layer node from the project file |
int QgsProject::readNumEntry | ( | const QString & | scope, |
const QString & | key, | ||
int | def = 0 , |
||
bool * | ok = nullptr |
||
) | const |
Definition at line 1318 of file qgsproject.cpp.
QString QgsProject::readPath | ( | QString | filename, |
const QString & | relativeBasePath = QString() |
||
) | const |
Turn filename read from the project file to an absolute path.
Definition at line 1435 of file qgsproject.cpp.
|
signal |
emitted when project is being read
QgsRelationManager * QgsProject::relationManager | ( | ) | const |
Definition at line 2124 of file qgsproject.cpp.
Remove the given key.
Definition at line 1386 of file qgsproject.cpp.
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.
Definition at line 2179 of file qgsproject.cpp.
void QgsProject::setBadLayerHandler | ( | QgsProjectBadLayerHandler * | handler | ) |
Change handler for missing layers.
Deletes old handler and takes ownership of the new one.
Definition at line 1657 of file qgsproject.cpp.
|
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.
Definition at line 410 of file qgsproject.cpp.
|
protected |
Set error message from read/write operation.
Definition at line 1642 of file qgsproject.cpp.
void QgsProject::setEvaluateDefaultValues | ( | bool | evaluateDefaultValues | ) |
Defines if default values should be evaluated on provider side when requested and not when committed.
Definition at line 2059 of file qgsproject.cpp.
void QgsProject::setFileName | ( | const QString & | name | ) |
Sets the file name associated with the project.
This is the file which contains the project's XML representation.
name | project file name |
Definition at line 420 of file qgsproject.cpp.
void QgsProject::setNonIdentifiableLayers | ( | QList< QgsMapLayer *> | layers | ) |
Set a list of layers which should not be taken into account on map identification.
Definition at line 2139 of file qgsproject.cpp.
void QgsProject::setNonIdentifiableLayers | ( | const QStringList & | layerIds | ) |
Set a list of layers which should not be taken into account on map identification.
Definition at line 2162 of file qgsproject.cpp.
void QgsProject::setSnapSettingsForLayer | ( | const QString & | layerId, |
bool | enabled, | ||
QgsSnapper::SnappingType | type, | ||
QgsTolerance::UnitType | unit, | ||
double | tolerance, | ||
bool | avoidIntersection | ||
) |
Convenience function to set snap settings per layer.
Definition at line 1926 of file qgsproject.cpp.
void QgsProject::setTitle | ( | const QString & | title | ) |
Sets the project's title.
title | new title |
Definition at line 391 of file qgsproject.cpp.
void QgsProject::setTopologicalEditing | ( | bool | enabled | ) |
Convenience function to set topological editing.
Definition at line 2073 of file qgsproject.cpp.
|
signal |
bool QgsProject::snapSettingsForLayer | ( | const QString & | layerId, |
bool & | enabled, | ||
QgsSnapper::SnappingType & | type, | ||
QgsTolerance::UnitType & | units, | ||
double & | tolerance, | ||
bool & | avoidIntersection | ||
) | const |
Convenience function to query snap settings of a layer.
Definition at line 1983 of file qgsproject.cpp.
QStringList QgsProject::subkeyList | ( | const QString & | scope, |
const QString & | key | ||
) | const |
Return keys with keys – do not return keys that contain only values.
Definition at line 1413 of file qgsproject.cpp.
|
inline |
Every project has an associated title string.
Definition at line 91 of file qgsproject.h.
QString QgsProject::title | ( | ) | const |
bool QgsProject::topologicalEditing | ( | ) | const |
Convenience function to query topological editing status.
Definition at line 2079 of file qgsproject.cpp.
QMap< QPair< QString, QString >, QgsTransactionGroup * > QgsProject::transactionGroups | ( | ) |
Map of transaction groups.
QPair( providerKey, connString ) -> transactionGroup
Definition at line 2192 of file qgsproject.cpp.
|
signal |
Emitted whenever the expression variables stored in the project have been changed.
QgsVisibilityPresetCollection * QgsProject::visibilityPresetCollection | ( | ) |
Returns pointer to the project's visibility preset collection.
Definition at line 2134 of file qgsproject.cpp.
bool QgsProject::write | ( | const QFileInfo & | file | ) |
Writes the project to a file.
file | destination file |
Definition at line 1021 of file qgsproject.cpp.
bool QgsProject::write | ( | ) |
Writes the project to its current associated file (see fileName() ).
Definition at line 1028 of file qgsproject.cpp.
Definition at line 1229 of file qgsproject.cpp.
Definition at line 1236 of file qgsproject.cpp.
Definition at line 1244 of file qgsproject.cpp.
Definition at line 1251 of file qgsproject.cpp.
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
const QStringList & | value | ||
) |
Definition at line 1259 of file qgsproject.cpp.
|
signal |
Emitted, when a layer is being saved.
You can use this method to save additional information to the layer.
mapLayer | The map layer which is being initialized |
layerElem | The layer element from the project file |
doc | The document |
QString QgsProject::writePath | ( | const QString & | filename, |
const QString & | relativeBasePath = QString() |
||
) | const |
Prepare a filename to save it to the project file.
Creates an absolute or relative path to writes it to the project file.
Definition at line 1548 of file qgsproject.cpp.
|
signal |
emitted when project is being written
|
readwrite |
Definition at line 75 of file qgsproject.h.
|
read |
Definition at line 76 of file qgsproject.h.
|
readwrite |
Definition at line 74 of file qgsproject.h.