2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
/** Reads and writes project states.
|
|
|
|
|
|
|
|
|
|
|
|
@note
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
2007-01-09 02:39:15 +00:00
|
|
|
class QgsProject : QObject
|
2004-09-09 01:23:32 +00:00
|
|
|
{
|
2007-01-09 02:39:15 +00:00
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsproject.h>
|
|
|
|
%End
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
@todo XXX Should have semantics for saving project if dirty as last gasp?
|
|
|
|
*/
|
|
|
|
~QgsProject();
|
|
|
|
|
|
|
|
/// access to canonical QgsProject instance
|
|
|
|
static QgsProject * instance();
|
|
|
|
|
|
|
|
/**
|
2004-10-21 17:27:38 +00:00
|
|
|
Every project has an associated title string
|
|
|
|
|
|
|
|
@todo However current dialogs don't allow setting of it yet
|
2004-09-09 01:23:32 +00:00
|
|
|
*/
|
2004-10-21 17:27:38 +00:00
|
|
|
//@{
|
2007-01-09 02:39:15 +00:00
|
|
|
void title( const QString & title );
|
2004-10-21 17:27:38 +00:00
|
|
|
|
|
|
|
/** returns title */
|
2007-01-09 02:39:15 +00:00
|
|
|
const QString & title() const;
|
2004-10-21 17:27:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
the dirty flag is true if the project has been modified since the last
|
|
|
|
write()
|
|
|
|
*/
|
|
|
|
//@{
|
2008-08-23 09:19:49 +00:00
|
|
|
bool isDirty() const;
|
2004-10-21 17:27:38 +00:00
|
|
|
|
2006-03-09 22:50:13 +00:00
|
|
|
void dirty( bool b );
|
2004-10-21 17:27:38 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Every project has an associated file that contains its XML
|
|
|
|
*/
|
|
|
|
//@{
|
2008-08-23 19:55:27 +00:00
|
|
|
void setFileName( const QString & name );
|
2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
/** returns file name */
|
2008-08-23 19:38:17 +00:00
|
|
|
QString fileName() const;
|
2004-10-21 17:27:38 +00:00
|
|
|
//@}
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
/** read project file
|
|
|
|
|
|
|
|
@note Any current plug-in state is erased
|
|
|
|
|
2004-10-21 17:27:38 +00:00
|
|
|
@note dirty set to false after successful invocation
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
@note file name argument implicitly sets file
|
|
|
|
|
|
|
|
(Is that really desirable behavior? Maybe prompt to save before
|
|
|
|
reading new one?)
|
|
|
|
|
|
|
|
Should we presume the file is opened elsewhere? Or do we open it
|
|
|
|
ourselves?
|
|
|
|
|
|
|
|
XXX How to best get modify access to Qgis state? Actually we can finagle
|
|
|
|
that by searching for qgisapp in object hiearchy.
|
|
|
|
|
|
|
|
@note
|
|
|
|
|
|
|
|
- Gets the extents
|
|
|
|
- Creates maplayers
|
|
|
|
- Registers maplayers
|
|
|
|
|
2004-10-21 17:27:38 +00:00
|
|
|
@note it's presumed that the caller has already reset the map canvas, map registry, and legend
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
@exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
//@{
|
2007-01-09 02:39:15 +00:00
|
|
|
bool read( const QFileInfo & file );
|
2004-09-09 01:23:32 +00:00
|
|
|
bool read( );
|
|
|
|
//@}
|
|
|
|
|
2005-05-05 21:06:00 +00:00
|
|
|
|
2008-08-23 09:19:49 +00:00
|
|
|
/** read the layer described in the associated Dom node
|
2005-05-05 21:06:00 +00:00
|
|
|
|
2008-08-23 09:19:49 +00:00
|
|
|
@param layerNode represents a QgsProject Dom node that maps to a specific layer.
|
2005-05-05 21:06:00 +00:00
|
|
|
|
|
|
|
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
|
2008-08-23 09:19:49 +00:00
|
|
|
location of the data, if any. If there is a new location, the Dom
|
2005-05-05 21:06:00 +00:00
|
|
|
node associated with the layer has its <datasource> tag corrected.
|
|
|
|
Then that node is passed to this member function to be re-opened.
|
|
|
|
|
|
|
|
*/
|
|
|
|
bool read( QDomNode & layerNode );
|
|
|
|
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
/** 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.
|
|
|
|
|
|
|
|
@note file name argument implicitly sets file
|
|
|
|
|
2004-10-21 17:27:38 +00:00
|
|
|
@note dirty set to false after successful invocation
|
2004-09-09 01:23:32 +00:00
|
|
|
*/
|
|
|
|
//@{
|
2007-01-09 02:39:15 +00:00
|
|
|
bool write( const QFileInfo & file );
|
2004-09-09 01:23:32 +00:00
|
|
|
bool write( );
|
|
|
|
//@}
|
|
|
|
|
2004-10-21 17:27:38 +00:00
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
/// syntactic sugar for property lists
|
2004-11-19 22:27:07 +00:00
|
|
|
// DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
|
|
|
|
// DEPRECATED typedef QValueList< PropertyValue > Properties;
|
2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
/** extra properties, typically added by plug-ins
|
|
|
|
|
2004-11-04 20:09:58 +00:00
|
|
|
This allows for extra properties to be associated with projects. Think
|
|
|
|
of it as a registry bound to a project.
|
2004-09-09 01:23:32 +00:00
|
|
|
|
2004-11-04 20:09:58 +00:00
|
|
|
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".
|
|
|
|
|
|
|
|
@note
|
|
|
|
|
|
|
|
E.g., open modeller might use:
|
|
|
|
|
|
|
|
<code>"QgsProject::instance()->properties("openmodeller")["foo"]</code>.
|
2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
@todo "properties" is, overall, a good name; but that might imply that
|
|
|
|
the qgis specific state properites are different since they aren't
|
|
|
|
accessible here. Actually, what if we make "qgis" yet another
|
2004-11-04 20:09:58 +00:00
|
|
|
scope that stores its state in the properties list? E.g.,
|
|
|
|
QgsProject::instance()->properties()["qgis"]?
|
|
|
|
|
|
|
|
|
2004-09-09 01:23:32 +00:00
|
|
|
*/
|
2004-11-19 22:27:07 +00:00
|
|
|
// DEPRECATED Properties & properties( QString const & scope );
|
2004-09-09 01:23:32 +00:00
|
|
|
|
2004-11-06 00:42:28 +00:00
|
|
|
/**
|
|
|
|
removes all project properties
|
|
|
|
*/
|
|
|
|
void clearProperties();
|
|
|
|
|
2004-11-19 22:27:07 +00:00
|
|
|
|
|
|
|
/* key value mutators
|
|
|
|
|
|
|
|
keys would be the familiar QSettings-like '/' delimited entries, implying
|
|
|
|
a hierarchy of keys and corresponding values
|
|
|
|
|
2004-11-26 18:30:01 +00:00
|
|
|
@note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
|
2004-11-19 22:27:07 +00:00
|
|
|
*/
|
|
|
|
//@{
|
2007-01-09 02:39:15 +00:00
|
|
|
// TODO: resolve somehow to use always correct function
|
|
|
|
//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 );
|
2004-11-19 22:27:07 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/** key value accessors
|
|
|
|
|
|
|
|
keys would be the familiar QSettings-like '/' delimited entries,
|
|
|
|
implying a hierarchy of keys and corresponding values
|
|
|
|
|
2004-11-26 18:30:01 +00:00
|
|
|
|
|
|
|
@note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
|
2004-11-19 22:27:07 +00:00
|
|
|
*/
|
|
|
|
//@{
|
2007-01-09 02:39:15 +00:00
|
|
|
QStringList readListEntry ( const QString & scope, const QString & key, bool * ok = 0 ) const;
|
2004-11-19 22:27:07 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
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;
|
2004-11-19 22:27:07 +00:00
|
|
|
//@}
|
|
|
|
|
2005-01-19 22:03:09 +00:00
|
|
|
|
2005-03-02 23:34:00 +00:00
|
|
|
/** remove the given key */
|
2007-01-09 02:39:15 +00:00
|
|
|
bool removeEntry ( const QString & scope, const QString & key );
|
2005-03-02 23:34:00 +00:00
|
|
|
|
|
|
|
|
2005-01-19 22:03:09 +00:00
|
|
|
/** return keys with values -- do not return keys that contain other keys
|
|
|
|
|
|
|
|
@note equivalent to QSettings entryList()
|
|
|
|
*/
|
2007-01-09 02:39:15 +00:00
|
|
|
QStringList entryList ( const QString & scope, const QString & key ) const;
|
2005-01-19 22:03:09 +00:00
|
|
|
|
2005-03-02 23:34:00 +00:00
|
|
|
/** return keys with keys -- do not return keys that contain only values
|
2005-02-21 10:13:26 +00:00
|
|
|
|
2005-03-02 23:34:00 +00:00
|
|
|
@note equivalent to QSettings subkeyList()
|
2005-02-21 10:13:26 +00:00
|
|
|
*/
|
2007-01-09 02:39:15 +00:00
|
|
|
QStringList subkeyList ( const QString & scope, const QString & key ) const;
|
2005-01-19 22:03:09 +00:00
|
|
|
|
2005-03-02 23:34:00 +00:00
|
|
|
|
|
|
|
/** dump out current project properties to stderr
|
|
|
|
|
|
|
|
@todo XXX Now slightly broken since re-factoring. Won't print out top-level key
|
|
|
|
and redundantly prints sub-keys.
|
|
|
|
*/
|
|
|
|
void dumpProperties() const;
|
|
|
|
|
2009-09-05 19:49:10 +00:00
|
|
|
/** prepare a filename to save it to the project file
|
|
|
|
@note added in 1.3 */
|
|
|
|
QString writePath( QString filename ) const;
|
|
|
|
|
|
|
|
/** turn filename read from the project file to an absolute path
|
|
|
|
@note added in 1.3 */
|
|
|
|
QString readPath( QString filename ) const;
|
|
|
|
|
2009-12-07 14:22:37 +00:00
|
|
|
/** Return error message from previous read/write
|
|
|
|
@note added in 1.4 */
|
|
|
|
QString error() const;
|
|
|
|
|
2009-12-07 17:14:41 +00:00
|
|
|
/** Change handler for missing layers.
|
|
|
|
Deletes old handler and takes ownership of the new one.
|
|
|
|
@note added in 1.4 */
|
|
|
|
void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
|
|
|
|
|
2009-12-07 14:22:37 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
/** Set error message from read/write operation
|
|
|
|
@note added in 1.4 */
|
|
|
|
void setError( QString errorMessage );
|
|
|
|
|
|
|
|
/** Clear error message
|
|
|
|
@note added in 1.4 */
|
|
|
|
void clearError();
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
//! emitted when project is being read
|
|
|
|
void readProject(const QDomDocument &);
|
|
|
|
|
|
|
|
//! emitted when project is being written
|
|
|
|
void writeProject(QDomDocument &);
|
2005-03-02 23:34:00 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
private:
|
2004-09-09 01:23:32 +00:00
|
|
|
|
|
|
|
QgsProject(); // private 'cause it's a singleton
|
|
|
|
|
|
|
|
}; // QgsProject
|
|
|
|
|
2009-12-07 17:14:41 +00:00
|
|
|
|
|
|
|
/** Interface for classes that handle missing layer files when reading project file.
|
|
|
|
@note added in 1.4 */
|
|
|
|
class QgsProjectBadLayerHandler
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsproject.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
|
|
|
|
virtual ~QgsProjectBadLayerHandler();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** Default bad layer handler which ignores any missing layers.
|
|
|
|
@note added in 1.4 */
|
|
|
|
class QgsProjectBadLayerDefaultHandler : QgsProjectBadLayerHandler
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsproject.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
|
|
|
|
|
|
|
|
};
|