QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
21 #ifndef QGSPROJECT_H
22 #define QGSPROJECT_H
23 
24 #include <memory>
25 #include "qgsprojectversion.h"
26 #include <QHash>
27 #include <QList>
28 #include <QObject>
29 #include <QPair>
30 
31 //for the snap settings
32 #include "qgssnapper.h"
33 #include "qgstolerance.h"
34 
35 //#include <QDomDocument>
36 
37 class QFileInfo;
38 class QDomDocument;
39 class QDomElement;
40 class QDomNode;
41 
42 class QgsMapLayer;
44 class QgsVectorLayer;
45 
64 class CORE_EXPORT QgsProject : public QObject
65 {
66  Q_OBJECT
67 
68  public:
69 
73  ~QgsProject();
74 
76  static QgsProject * instance();
77 
84  void title( const QString & title );
85 
87  const QString & title() const;
89 
95  bool isDirty() const;
96 
97  void dirty( bool b );
99 
100 
105  void setFileName( const QString & name );
106 
108  QString fileName() const;
110 
111 
138  bool read( const QFileInfo & file );
139  bool read();
141 
142 
155  bool read( QDomNode & layerNode );
156 
157 
168  bool write( const QFileInfo & file );
169  bool write();
171 
172 
174  // DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
175  // DEPRECATED typedef QValueList< PropertyValue > Properties;
176 
200  // DEPRECATED Properties & properties( QString const & scope );
201 
205  void clearProperties();
206 
207 
208  /* key value mutators
209 
210  keys would be the familiar QSettings-like '/' delimited entries, implying
211  a hierarchy of keys and corresponding values
212 
213  @note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
214  */
216 
217  bool writeEntry( const QString & scope, const QString & key, bool value );
219  bool writeEntry( const QString & scope, const QString & key, double value );
220  bool writeEntry( const QString & scope, const QString & key, int value );
221  bool writeEntry( const QString & scope, const QString & key, const QString & value );
222  bool writeEntry( const QString & scope, const QString & key, const QStringList & value );
224 
234  QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool *ok = 0 ) const;
235 
236  QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
237  int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
238  double readDoubleEntry( const QString & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
239  bool readBoolEntry( const QString & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
241 
242 
244  bool removeEntry( const QString & scope, const QString & key );
245 
246 
251  QStringList entryList( const QString & scope, const QString & key ) const;
252 
257  QStringList subkeyList( const QString & scope, const QString & key ) const;
258 
259 
265  void dumpProperties() const;
266 
269  QString writePath( QString filename ) const;
270 
273  QString readPath( QString filename ) const;
274 
277  QString error() const;
278 
282  void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
283 
285  QString layerIsEmbedded( const QString& id ) const;
286 
292  bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
293  QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
294 
297  void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
298  bool avoidIntersection );
299 
302  bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
303  bool& avoidIntersection ) const;
304 
307  void setTopologicalEditing( bool enabled );
308 
311  bool topologicalEditing() const;
312 
316  QString homePath() const;
317 
318  protected:
319 
322  void setError( QString errorMessage );
323 
326  void clearError();
327 
328  //Creates layer and adds it to maplayer registry
330  bool addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
331 
332  signals:
334  void readProject( const QDomDocument & );
335 
337  void writeProject( QDomDocument & );
338 
347  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
348 
357  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
358 
360  void projectSaved();
361 
363  void oldProjectVersionWarning( QString );
364 
366  // @param i current layer
367  // @param n number of layers
368  void layerLoaded( int i, int n );
369 
370  void loadingLayer( QString );
371 
372  void snapSettingsChanged();
373 
374  private:
375 
376  QgsProject(); // private 'cause it's a singleton
377 
378  QgsProject( QgsProject const & ); // private 'cause it's a singleton
379 
380  struct Imp;
381 
383  std::auto_ptr<Imp> imp_;
384 
386 
387  QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
388 
389  QString mErrorMessage;
390 
392 
396  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
397 
398  void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
399  QStringList& avoidIntersectionList ) const;
400 
401 }; // QgsProject
402 
403 
406 class CORE_EXPORT QgsProjectBadLayerHandler
407 {
408  public:
409  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
411 };
412 
413 
417 {
418  public:
419  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
420 
421 };
422 
423 #endif