Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsproject.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproject.h
3 
4  Implements persistent project state.
5 
6  -------------------
7  begin : July 23, 2004
8  copyright : (C) 2004 by Mark Coletti
9  email : mcoletti at gmail.com
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 /* $Id$ */
21 
22 #ifndef QGSPROJECT_H
23 #define QGSPROJECT_H
24 
25 #include <memory>
26 #include "qgsprojectversion.h"
27 #include <QObject>
28 #include <QList>
29 #include <QPair>
30 
31 //#include <QDomDocument>
32 
33 class QFileInfo;
34 class QDomDocument;
35 class QDomNode;
36 
38 
57 class CORE_EXPORT QgsProject : public QObject
58 {
59  Q_OBJECT
60 
61  public:
62 
66  ~QgsProject();
67 
69  static QgsProject * instance();
70 
77  void title( QString const & title );
78 
80  QString const & title() const;
82 
88  bool isDirty() const;
89 
90  void dirty( bool b );
92 
93 
98  void setFileName( QString const & name );
99 
101  QString fileName() const;
103 
104 
131  bool read( QFileInfo const & file );
132  bool read( );
134 
135 
148  bool read( QDomNode & layerNode );
149 
150 
161  bool write( QFileInfo const & file );
162  bool write( );
164 
165 
167  // DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
168  // DEPRECATED typedef QValueList< PropertyValue > Properties;
169 
193  // DEPRECATED Properties & properties( QString const & scope );
194 
198  void clearProperties();
199 
200 
201  /* key value mutators
202 
203  keys would be the familiar QSettings-like '/' delimited entries, implying
204  a hierarchy of keys and corresponding values
205 
206  @note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
207  */
209  bool writeEntry( QString const & scope, const QString & key, bool value );
210  bool writeEntry( QString const & scope, const QString & key, double value );
211  bool writeEntry( QString const & scope, const QString & key, int value );
212  bool writeEntry( QString const & scope, const QString & key, const QString & value );
213  bool writeEntry( QString const & scope, const QString & key, const QStringList & value );
215 
225  QStringList readListEntry( QString const & scope, const QString & key, bool * ok = 0 ) const;
226 
227  QString readEntry( QString const & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
228  int readNumEntry( QString const & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
229  double readDoubleEntry( QString const & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
230  bool readBoolEntry( QString const & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
232 
233 
235  bool removeEntry( QString const & scope, const QString & key );
236 
237 
242  QStringList entryList( QString const & scope, QString const & key ) const;
243 
248  QStringList subkeyList( QString const & scope, QString const & key ) const;
249 
250 
256  void dumpProperties() const;
257 
258 
261  QString writePath( QString filename ) const;
262 
265  QString readPath( QString filename ) const;
266 
269  QString error() const;
270 
274  void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
275 
276  protected:
277 
280  void setError( QString errorMessage );
281 
284  void clearError();
285 
286  signals:
287 
289  void readProject( const QDomDocument & );
290 
292  void writeProject( QDomDocument & );
293 
295  void oldProjectVersionWarning( QString );
296 
298  // @param i current layer
299  // @param n number of layers
300  void layerLoaded( int i, int n );
301 
302  private:
303 
304  QgsProject(); // private 'cause it's a singleton
305 
306  QgsProject( QgsProject const & ); // private 'cause it's a singleton
307 
308  struct Imp;
309 
311  std::auto_ptr<Imp> imp_;
312 
314 
315  QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
316 
317  QString mErrorMessage;
318 
320 
321 }; // QgsProject
322 
323 
326 class CORE_EXPORT QgsProjectBadLayerHandler
327 {
328  public:
329  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
331 };
332 
333 
337 {
338  public:
339  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
340 
341 };
342 
343 #endif