Quantum GIS API Documentation  1.8
src/core/qgsproject.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                                   qgsproject.h
00003 
00004                       Implements persistent project state.
00005 
00006                               -------------------
00007   begin                : July 23, 2004
00008   copyright            : (C) 2004 by Mark Coletti
00009   email                : mcoletti at gmail.com
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 #ifndef QGSPROJECT_H
00022 #define QGSPROJECT_H
00023 
00024 #include <memory>
00025 #include "qgsprojectversion.h"
00026 #include <QHash>
00027 #include <QList>
00028 #include <QObject>
00029 #include <QPair>
00030 
00031 //#include <QDomDocument>
00032 
00033 class QFileInfo;
00034 class QDomDocument;
00035 class QDomElement;
00036 class QDomNode;
00037 
00038 class QgsMapLayer;
00039 class QgsProjectBadLayerHandler;
00040 class QgsVectorLayer;
00041 
00060 class CORE_EXPORT QgsProject : public QObject
00061 {
00062     Q_OBJECT
00063 
00064   public:
00065 
00069     ~QgsProject();
00070 
00072     static QgsProject * instance();
00073 
00080     void title( QString const & title );
00081 
00083     QString const & title() const;
00085 
00091     bool isDirty() const;
00092 
00093     void dirty( bool b );
00095 
00096 
00101     void setFileName( QString const & name );
00102 
00104     QString fileName() const;
00106 
00107 
00134     bool read( QFileInfo const & file );
00135     bool read( );
00137 
00138 
00151     bool read( QDomNode & layerNode );
00152 
00153 
00164     bool write( QFileInfo const & file );
00165     bool write( );
00167 
00168 
00170     // DEPRECATED typedef QPair< QString, QVariant >  PropertyValue;
00171     // DEPRECATED typedef QValueList< PropertyValue > Properties;
00172 
00196     // DEPRECATED Properties & properties( QString const & scope );
00197 
00201     void clearProperties();
00202 
00203 
00204     /* key value mutators
00205 
00206       keys would be the familiar QSettings-like '/' delimited entries, implying
00207       a hierarchy of keys and corresponding values
00208 
00209       @note The key string <em>must</em> include '/'s.  E.g., "/foo" not "foo".
00210     */
00212     bool writeEntry( QString const & scope, const QString & key, bool value );
00213     bool writeEntry( QString const & scope, const QString & key, double value );
00214     bool writeEntry( QString const & scope, const QString & key, int value );
00215     bool writeEntry( QString const & scope, const QString & key, const QString & value );
00216     bool writeEntry( QString const & scope, const QString & key, const QStringList & value );
00218 
00228     QStringList readListEntry( QString const & scope, const QString & key, bool * ok = 0 ) const;
00229 
00230     QString readEntry( QString const & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
00231     int readNumEntry( QString const & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
00232     double readDoubleEntry( QString const & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
00233     bool readBoolEntry( QString const & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
00235 
00236 
00238     bool removeEntry( QString const & scope, const QString & key );
00239 
00240 
00245     QStringList entryList( QString const & scope, QString const & key ) const;
00246 
00251     QStringList subkeyList( QString const & scope, QString const & key ) const;
00252 
00253 
00259     void dumpProperties() const;
00260 
00261 
00264     QString writePath( QString filename ) const;
00265 
00268     QString readPath( QString filename ) const;
00269 
00272     QString error() const;
00273 
00277     void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
00278 
00280     QString layerIsEmbedded( const QString& id ) const;
00281 
00285     //static QgsMapLayer* createEmbeddedLayer( const QString& layerId, const QString& projectFilePath );
00286     bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
00287                               QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
00288 
00289   protected:
00290 
00293     void setError( QString errorMessage );
00294 
00297     void clearError();
00298 
00299     //Creates layer and adds it to maplayer registry
00300     bool addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
00301 
00302   signals:
00303 
00305     void readProject( const QDomDocument & );
00306 
00308     void writeProject( QDomDocument & );
00309 
00311     void oldProjectVersionWarning( QString );
00312 
00314     // @param i current layer
00315     // @param n number of layers
00316     void layerLoaded( int i, int n );
00317 
00318   private:
00319 
00320     QgsProject(); // private 'cause it's a singleton
00321 
00322     QgsProject( QgsProject const & ); // private 'cause it's a singleton
00323 
00324     struct Imp;
00325 
00327     std::auto_ptr<Imp> imp_;
00328 
00329     static QgsProject * theProject_;
00330 
00331     QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
00332 
00333     QString mErrorMessage;
00334 
00335     QgsProjectBadLayerHandler* mBadLayerHandler;
00336 
00340     QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
00341 
00342 }; // QgsProject
00343 
00344 
00347 class CORE_EXPORT QgsProjectBadLayerHandler
00348 {
00349   public:
00350     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
00351     virtual ~QgsProjectBadLayerHandler() {}
00352 };
00353 
00354 
00357 class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHandler
00358 {
00359   public:
00360     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
00361 
00362 };
00363 
00364 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines