QGIS API Documentation
2.6.0-Brighton
|
Reads and writes project states. More...
#include <qgsproject.h>
Classes | |
struct | Imp |
Signals | |
void | readProject (const QDomDocument &) |
emitted when project is being read | |
void | writeProject (QDomDocument &) |
emitted when project is being written | |
void | readMapLayer (QgsMapLayer *mapLayer, const QDomElement &layerNode) |
Emitted, after the basic initialisation of a layer from the project file is done. | |
void | writeMapLayer (QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc) |
Emitted, when a layer is being saved. | |
void | projectSaved () |
emitted when the project file has been written and closed | |
void | oldProjectVersionWarning (QString) |
emitted when an old project file is read. | |
void | layerLoaded (int i, int n) |
emitted when a layer from a projects was read | |
void | loadingLayer (QString) |
void | snapSettingsChanged () |
Public Member Functions | |
~QgsProject () | |
void | clear () |
Clear the project. | |
bool | read (QDomNode &layerNode) |
read the layer described in the associated Dom node | |
void | clearProperties () |
syntactic sugar for property lists | |
bool | removeEntry (const QString &scope, const QString &key) |
remove the given key | |
QStringList | entryList (const QString &scope, const QString &key) const |
return keys with values – do not return keys that contain other keys | |
QStringList | subkeyList (const QString &scope, const QString &key) const |
return keys with keys – do not return keys that contain only values | |
void | dumpProperties () const |
dump out current project properties to stderr | |
QString | writePath (QString filename, QString relativeBasePath=QString::null) const |
prepare a filename to save it to the project file | |
QString | readPath (QString filename) const |
turn filename read from the project file to an absolute path | |
QString | error () const |
Return error message from previous read/write. | |
void | setBadLayerHandler (QgsProjectBadLayerHandler *handler) |
Change handler for missing layers. | |
QString | layerIsEmbedded (const QString &id) const |
Returns project file path if layer is embedded from other project file. | |
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. | |
QgsLayerTreeGroup * | createEmbeddedGroup (const QString &groupName, const QString &projectFilePath) |
Create layer group instance defined in an arbitrary project file. | |
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. | |
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. | |
void | setTopologicalEditing (bool enabled) |
Convenience function to set topological editing. | |
bool | topologicalEditing () const |
Convenience function to query topological editing status. | |
QString | homePath () const |
Return project's home path. | |
QgsRelationManager * | relationManager () const |
QgsLayerTreeGroup * | layerTreeRoot () const |
Return pointer to the root (invisible) node of the project's layer tree. | |
QgsLayerTreeRegistryBridge * | layerTreeRegistryBridge () const |
Return pointer to the helper class that synchronizes map layer registry with layer tree. | |
void | title (const QString &title) |
Every project has an associated title string. | |
void | setTitle (const QString &title) |
Set project title. | |
const QString & | title () const |
returns title | |
bool | isDirty () const |
the dirty flag is true if the project has been modified since the last write() | |
void | dirty (bool b) |
void | setDirty (bool b) |
Set project as dirty (modified). | |
void | setFileName (const QString &name) |
Every project has an associated file that contains its XML. | |
QString | fileName () const |
returns file name | |
bool | read (const QFileInfo &file) |
read project file | |
bool | read () |
presuming that the caller has already reset the map canvas, map registry, and legend | |
bool | write (const QFileInfo &file) |
write project file | |
bool | write () |
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) |
QStringList | readListEntry (const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const |
key value accessors | |
QString | readEntry (const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const |
int | readNumEntry (const QString &scope, const QString &key, int def=0, bool *ok=0) const |
double | readDoubleEntry (const QString &scope, const QString &key, double def=0, bool *ok=0) const |
bool | readBoolEntry (const QString &scope, const QString &key, bool def=false, bool *ok=0) const |
Static Public Member Functions | |
static QgsProject * | instance () |
access to canonical QgsProject instance |
Protected Member Functions | |
void | setError (QString errorMessage) |
Set error message from read/write operation. | |
void | clearError () |
Clear error message. | |
bool | addLayer (const QDomElement &layerElem, QList< QDomNode > &brokenNodes, QList< QPair< QgsVectorLayer *, QDomElement > > &vectorLayerList) |
void | initializeEmbeddedSubtree (const QString &projectFilePath, QgsLayerTreeGroup *group) |
void | loadEmbeddedNodes (QgsLayerTreeGroup *group) |
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.
Might want to consider moving from Singleton; i.e., allowing more than one project. Just as the GIMP can have simultaneous multiple images, perhaps qgis can one day have simultaneous multiple projects.
QgsProject::~QgsProject | ( | ) |
|
protected |
void QgsProject::clear | ( | ) |
Clear the project.
|
protected |
Clear error message.
void QgsProject::clearProperties | ( | ) |
syntactic sugar for property lists
extra properties, typically added by plug-ins
This allows for extra properties to be associated with projects. Think of it as a registry bound to a project.
Properties are arbitrary values keyed by a name and associated with a scope. The scope would presumably refer to your plug-in. E.g., "openmodeller".
E.g., open modeller might use:
"QgsProject::instance()->properties("openmodeller")["foo"]
.
removes all project properties
QgsLayerTreeGroup * QgsProject::createEmbeddedGroup | ( | const QString & | groupName, |
const QString & | projectFilePath | ||
) |
Create layer group instance defined in an arbitrary project file.
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
void QgsProject::dirty | ( | bool | b | ) |
void QgsProject::dumpProperties | ( | ) | const |
dump out current project properties to stderr
QStringList QgsProject::entryList | ( | const QString & | scope, |
const QString & | key | ||
) | const |
return keys with values – do not return keys that contain other keys
QString QgsProject::error | ( | ) | const |
Return error message from previous read/write.
QString QgsProject::fileName | ( | ) | const |
returns file name
QString QgsProject::homePath | ( | ) | const |
Return project's home path.
|
protected |
|
static |
access to canonical QgsProject instance
bool QgsProject::isDirty | ( | ) | const |
the dirty flag is true if the project has been modified since the last write()
QString QgsProject::layerIsEmbedded | ( | const QString & | id | ) | const |
Returns project file path if layer is embedded from other project file.
Returns empty string if layer is not embedded
|
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.
QgsLayerTreeGroup * QgsProject::layerTreeRoot | ( | ) | const |
Return pointer to the root (invisible) node of the project's layer tree.
|
protected |
|
signal |
|
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 | ) |
read project file
Please note that most of the contents were copied from qgsproject.
bool QgsProject::read | ( | ) |
presuming that the caller has already reset the map canvas, map registry, and legend
Shows a warning when an old project file is read.
bool QgsProject::read | ( | QDomNode & | layerNode | ) |
read the layer described in the associated Dom node
layerNode | represents a QgsProject Dom node that maps to 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.
bool QgsProject::readBoolEntry | ( | const QString & | scope, |
const QString & | key, | ||
bool | def = false , |
||
bool * | ok = 0 |
||
) | const |
double QgsProject::readDoubleEntry | ( | const QString & | scope, |
const QString & | key, | ||
double | def = 0 , |
||
bool * | ok = 0 |
||
) | const |
QString QgsProject::readEntry | ( | const QString & | scope, |
const QString & | key, | ||
const QString & | def = QString::null , |
||
bool * | ok = 0 |
||
) | const |
QStringList QgsProject::readListEntry | ( | const QString & | scope, |
const QString & | key, | ||
QStringList | def = QStringList() , |
||
bool * | ok = 0 |
||
) | const |
key value accessors
keys would be the familiar QSettings-like '/' delimited entries, implying a hierarchy of keys and corresponding values
|
signal |
Emitted, after the basic initialisation 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 = 0 |
||
) | const |
QString QgsProject::readPath | ( | QString | filename | ) | const |
turn filename read from the project file to an absolute path
|
signal |
emitted when project is being read
QgsRelationManager * QgsProject::relationManager | ( | ) | const |
bool QgsProject::removeEntry | ( | const QString & | scope, |
const QString & | key | ||
) |
remove the given key
void QgsProject::setBadLayerHandler | ( | QgsProjectBadLayerHandler * | handler | ) |
Change handler for missing layers.
Deletes old handler and takes ownership of the new one.
void QgsProject::setDirty | ( | bool | b | ) |
Set project as dirty (modified).
|
protected |
Set error message from read/write operation.
void QgsProject::setFileName | ( | const QString & | name | ) |
Every project has an associated file that contains its XML.
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.
void QgsProject::setTitle | ( | const QString & | title | ) |
Set project title.
void QgsProject::setTopologicalEditing | ( | bool | enabled | ) |
Convenience function to set topological editing.
|
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.
QStringList QgsProject::subkeyList | ( | const QString & | scope, |
const QString & | key | ||
) | const |
return keys with keys – do not return keys that contain only values
void QgsProject::title | ( | const QString & | title | ) |
Every project has an associated title string.
QString const & QgsProject::title | ( | ) | const |
returns title
bool QgsProject::topologicalEditing | ( | ) | const |
Convenience function to query topological editing status.
bool QgsProject::write | ( | const QFileInfo & | file | ) |
write project file
XXX How to best get read access to Qgis state? Actually we can finagle that by searching for qgisapp in object hiearchy.
bool QgsProject::write | ( | ) |
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
bool | value | ||
) |
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
double | value | ||
) |
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
int | value | ||
) |
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
const QString & | value | ||
) |
bool QgsProject::writeEntry | ( | const QString & | scope, |
const QString & | key, | ||
const QStringList & | value | ||
) |
|
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 | ( | QString | filename, |
QString | relativeBasePath = QString::null |
||
) | const |
prepare a filename to save it to the project file
|
signal |
emitted when project is being written