2004-09-09 01:23:32 +00:00
|
|
|
/***************************************************************************
|
2004-10-16 21:59:14 +00:00
|
|
|
qgsproject.h
|
2004-09-09 01:23:32 +00:00
|
|
|
|
2004-10-16 21:59:14 +00:00
|
|
|
Implements persistent project state.
|
2004-09-09 01:23:32 +00:00
|
|
|
|
2004-10-16 21:59:14 +00:00
|
|
|
-------------------
|
2004-09-09 01:23:32 +00:00
|
|
|
begin : July 23, 2004
|
|
|
|
copyright : (C) 2004 by Mark Coletti
|
|
|
|
email : mcoletti at gmail.com
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef QGSPROJECT_H
|
|
|
|
#define QGSPROJECT_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <qmap.h>
|
|
|
|
#include <qvaluelist.h>
|
|
|
|
#include <qvariant.h>
|
|
|
|
|
|
|
|
|
|
|
|
class QFileInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
class QgsProject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
@todo XXX Should have semantics for saving project if dirty as last gasp?
|
|
|
|
*/
|
|
|
|
~QgsProject();
|
|
|
|
|
|
|
|
/// access to canonical QgsProject instance
|
|
|
|
static QgsProject * instance();
|
|
|
|
|
|
|
|
/**
|
|
|
|
sets the project file name
|
|
|
|
*/
|
|
|
|
void name( QString const & name );
|
|
|
|
|
|
|
|
/** returns file name */
|
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
/** read project file
|
|
|
|
|
|
|
|
@note Any current plug-in state is erased
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
@exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
bool read( QFileInfo const & file );
|
|
|
|
bool read( );
|
|
|
|
//@}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
bool write( QFileInfo const & file );
|
|
|
|
bool write( );
|
|
|
|
//@}
|
|
|
|
|
|
|
|
/// syntactic sugar for property lists
|
|
|
|
typedef QMap< QString, QValueList<QVariant> > Properties;
|
|
|
|
|
|
|
|
/** extra properties, typically added by plug-ins
|
|
|
|
|
|
|
|
@note
|
|
|
|
|
|
|
|
Use a QMap because the key string is a sort of "name space". Each
|
|
|
|
plug-in, provider, or whatever would presumably store its respective
|
|
|
|
properties under a name well known and specific to itself. E.g., open
|
|
|
|
modeller might use <code>"QgsProject::instance()->properties()["openmodeller"]</code>.
|
|
|
|
|
|
|
|
@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
|
|
|
|
namespace that stores its state in the properties list? E.g.,
|
|
|
|
QgsProject::instance()->properties()["qgis"] ?
|
|
|
|
*/
|
|
|
|
Properties & properties();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
QgsProject(); // private 'cause it's a singleton
|
|
|
|
|
|
|
|
QgsProject( QgsProject const & ); // private 'cause it's a singleton
|
|
|
|
|
|
|
|
struct Imp;
|
|
|
|
|
|
|
|
/// implementation handle
|
|
|
|
std::auto_ptr<Imp> imp_;
|
|
|
|
|
|
|
|
static QgsProject * theProject_;
|
|
|
|
|
|
|
|
}; // QgsProject
|
|
|
|
|
|
|
|
#endif
|