QGIS API Documentation  2.3.0-Master
 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 QgsRelationManager;
45 class QgsVectorLayer;
46 
65 class CORE_EXPORT QgsProject : public QObject
66 {
67  Q_OBJECT
68 
69  public:
70 
74  ~QgsProject();
75 
77  static QgsProject * instance();
78 
85  void title( const QString & title );
86 
88  const QString & title() const;
90 
96  bool isDirty() const;
97 
98  void dirty( bool b );
100 
101 
106  void setFileName( const QString & name );
107 
109  QString fileName() const;
111 
112 
139  bool read( const QFileInfo & file );
140  bool read();
142 
143 
156  bool read( QDomNode & layerNode );
157 
158 
169  bool write( const QFileInfo & file );
170  bool write();
172 
173 
175  // DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
176  // DEPRECATED typedef QValueList< PropertyValue > Properties;
177 
201  // DEPRECATED Properties & properties( QString const & scope );
202 
206  void clearProperties();
207 
208 
209  /* key value mutators
210 
211  keys would be the familiar QSettings-like '/' delimited entries, implying
212  a hierarchy of keys and corresponding values
213 
214  @note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
215  */
217  bool writeEntry( const QString & scope, const QString & key, bool value );
220  bool writeEntry( const QString & scope, const QString & key, double value );
221  bool writeEntry( const QString & scope, const QString & key, int value );
222  bool writeEntry( const QString & scope, const QString & key, const QString & value );
223  bool writeEntry( const QString & scope, const QString & key, const QStringList & value );
225 
235  QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool *ok = 0 ) const;
236 
237  QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
238  int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
239  double readDoubleEntry( const QString & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
240  bool readBoolEntry( const QString & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
242 
243 
245  bool removeEntry( const QString & scope, const QString & key );
246 
247 
252  QStringList entryList( const QString & scope, const QString & key ) const;
253 
258  QStringList subkeyList( const QString & scope, const QString & key ) const;
259 
260 
266  void dumpProperties() const;
267 
270  QString writePath( QString filename ) const;
271 
274  QString readPath( QString filename ) const;
275 
278  QString error() const;
279 
283  void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
284 
286  QString layerIsEmbedded( const QString& id ) const;
287 
293  bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
294  QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
295 
298  void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
299  bool avoidIntersection );
300 
303  bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
304  bool& avoidIntersection ) const;
305 
308  void setTopologicalEditing( bool enabled );
309 
312  bool topologicalEditing() const;
313 
317  QString homePath() const;
318 
319  QgsRelationManager* relationManager() const;
320 
321  protected:
322 
325  void setError( QString errorMessage );
326 
329  void clearError();
330 
331  //Creates layer and adds it to maplayer registry
333  bool addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
334 
335  signals:
337  void readProject( const QDomDocument & );
338 
340  void writeProject( QDomDocument & );
341 
350  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
351 
360  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
361 
363  void projectSaved();
364 
366  void oldProjectVersionWarning( QString );
367 
369  // @param i current layer
370  // @param n number of layers
371  void layerLoaded( int i, int n );
372 
373  void loadingLayer( QString );
374 
375  void snapSettingsChanged();
376 
377  private:
378 
379  QgsProject(); // private 'cause it's a singleton
380 
381  QgsProject( QgsProject const & ); // private 'cause it's a singleton
382 
383  struct Imp;
384 
386  std::auto_ptr<Imp> imp_;
387 
389 
390  QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
391 
392  QString mErrorMessage;
393 
395 
399  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
400 
401  void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
402  QStringList& avoidIntersectionList ) const;
403 
405 
406 }; // QgsProject
407 
408 
411 class CORE_EXPORT QgsProjectBadLayerHandler
412 {
413  public:
414  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
416 };
417 
418 
422 {
423  public:
424  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
425 
426 };
427 
428 #endif
QString mErrorMessage
Definition: qgsproject.h:392
Base class for all map layer types.
Definition: qgsmaplayer.h:46
QHash< QString, QPair< QString, bool > > mEmbeddedLayers
Embeded layers which are defined in other projects.
Definition: qgsproject.h:399
UnitType
Type of unit of tolerance value from settings.
Definition: qgstolerance.h:33
SnappingType
Snap to vertex, to segment or both.
Definition: qgssnapper.h:66
Reads and writes project states.
Definition: qgsproject.h:65
QgsProjectBadLayerHandler * mBadLayerHandler
Definition: qgsproject.h:394
virtual ~QgsProjectBadLayerHandler()
Definition: qgsproject.h:415
QString file
Definition: qgssvgcache.cpp:76
This class manages a set of relations between layers.
static QgsProject * theProject_
Definition: qgsproject.h:388
std::auto_ptr< Imp > imp_
implementation handle
Definition: qgsproject.h:383
QgsRelationManager * mRelationManager
Definition: qgsproject.h:404
Default bad layer handler which ignores any missing layers.
Definition: qgsproject.h:421
Represents a vector layer which manages a vector based data sets.
Interface for classes that handle missing layer files when reading project file.
Definition: qgsproject.h:411
virtual void handleBadLayers(QList< QDomNode > layers, QDomDocument projectDom)=0