Quantum GIS API Documentation  1.7.4
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 /* $Id$ */
00021 
00022 #ifndef QGSPROJECT_H
00023 #define QGSPROJECT_H
00024 
00025 #include <memory>
00026 #include "qgsprojectversion.h"
00027 #include <QObject>
00028 #include <QList>
00029 #include <QPair>
00030 
00031 //#include <QDomDocument>
00032 
00033 class QFileInfo;
00034 class QDomDocument;
00035 class QDomNode;
00036 
00037 class QgsProjectBadLayerHandler;
00038 
00057 class CORE_EXPORT QgsProject : public QObject
00058 {
00059     Q_OBJECT
00060 
00061   public:
00062 
00066     ~QgsProject();
00067 
00069     static QgsProject * instance();
00070 
00077     void title( QString const & title );
00078 
00080     QString const & title() const;
00082 
00088     bool isDirty() const;
00089 
00090     void dirty( bool b );
00092 
00093 
00098     void setFileName( QString const & name );
00099 
00101     QString fileName() const;
00103 
00104 
00131     bool read( QFileInfo const & file );
00132     bool read( );
00134 
00135 
00148     bool read( QDomNode & layerNode );
00149 
00150 
00161     bool write( QFileInfo const & file );
00162     bool write( );
00164 
00165 
00167     // DEPRECATED typedef QPair< QString, QVariant >  PropertyValue;
00168     // DEPRECATED typedef QValueList< PropertyValue > Properties;
00169 
00193     // DEPRECATED Properties & properties( QString const & scope );
00194 
00198     void clearProperties();
00199 
00200 
00201     /* key value mutators
00202 
00203       keys would be the familiar QSettings-like '/' delimited entries, implying
00204       a hierarchy of keys and corresponding values
00205 
00206       @note The key string <em>must</em> include '/'s.  E.g., "/foo" not "foo".
00207     */
00209     bool writeEntry( QString const & scope, const QString & key, bool value );
00210     bool writeEntry( QString const & scope, const QString & key, double value );
00211     bool writeEntry( QString const & scope, const QString & key, int value );
00212     bool writeEntry( QString const & scope, const QString & key, const QString & value );
00213     bool writeEntry( QString const & scope, const QString & key, const QStringList & value );
00215 
00225     QStringList readListEntry( QString const & scope, const QString & key, bool * ok = 0 ) const;
00226 
00227     QString readEntry( QString const & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
00228     int readNumEntry( QString const & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
00229     double readDoubleEntry( QString const & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
00230     bool readBoolEntry( QString const & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
00232 
00233 
00235     bool removeEntry( QString const & scope, const QString & key );
00236 
00237 
00242     QStringList entryList( QString const & scope, QString const & key ) const;
00243 
00248     QStringList subkeyList( QString const & scope, QString const & key ) const;
00249 
00250 
00256     void dumpProperties() const;
00257 
00258 
00261     QString writePath( QString filename ) const;
00262 
00265     QString readPath( QString filename ) const;
00266 
00269     QString error() const;
00270 
00274     void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
00275 
00276   protected:
00277 
00280     void setError( QString errorMessage );
00281 
00284     void clearError();
00285 
00286   signals:
00287 
00289     void readProject( const QDomDocument & );
00290 
00292     void writeProject( QDomDocument & );
00293 
00295     void oldProjectVersionWarning( QString );
00296 
00298     // @param i current layer
00299     // @param n number of layers
00300     void layerLoaded( int i, int n );
00301 
00302   private:
00303 
00304     QgsProject(); // private 'cause it's a singleton
00305 
00306     QgsProject( QgsProject const & ); // private 'cause it's a singleton
00307 
00308     struct Imp;
00309 
00311     std::auto_ptr<Imp> imp_;
00312 
00313     static QgsProject * theProject_;
00314 
00315     QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
00316 
00317     QString mErrorMessage;
00318 
00319     QgsProjectBadLayerHandler* mBadLayerHandler;
00320 
00321 }; // QgsProject
00322 
00323 
00326 class CORE_EXPORT QgsProjectBadLayerHandler
00327 {
00328   public:
00329     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
00330     virtual ~QgsProjectBadLayerHandler() {}
00331 };
00332 
00333 
00336 class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHandler
00337 {
00338   public:
00339     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
00340 
00341 };
00342 
00343 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines