00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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
00171
00172
00196
00197
00201 void clearProperties();
00202
00203
00204
00205
00206
00207
00208
00209
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
00279 protected:
00280
00283 void setError( QString errorMessage );
00284
00287 void clearError();
00288
00289 signals:
00290
00292 void readProject( const QDomDocument & );
00293
00295 void writeProject( QDomDocument & );
00296
00298 void oldProjectVersionWarning( QString );
00299
00301
00302
00303 void layerLoaded( int i, int n );
00304
00305 private:
00306
00307 QgsProject();
00308
00309 QgsProject( QgsProject const & );
00310
00311 struct Imp;
00312
00314 std::auto_ptr<Imp> imp_;
00315
00316 static QgsProject * theProject_;
00317
00318 QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
00319
00320 QString mErrorMessage;
00321
00322 QgsProjectBadLayerHandler* mBadLayerHandler;
00323
00324 };
00325
00326
00329 class CORE_EXPORT QgsProjectBadLayerHandler
00330 {
00331 public:
00332 virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
00333 virtual ~QgsProjectBadLayerHandler() {}
00334 };
00335
00336
00339 class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHandler
00340 {
00341 public:
00342 virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
00343
00344 };
00345
00346 #endif