QGIS API Documentation  2.4.0-Chugiak
 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 QgsLayerTreeGroup;
43 class QgsLayerTreeRegistryBridge;
44 class QgsMapLayer;
46 class QgsRelationManager;
47 class QgsVectorLayer;
48 
67 class CORE_EXPORT QgsProject : public QObject
68 {
69  Q_OBJECT
70 
71  public:
72 
76  ~QgsProject();
77 
79  static QgsProject * instance();
80 
87  void title( const QString & title );
88 
91  void setTitle( const QString& title );
92 
94  const QString & title() const;
96 
102  bool isDirty() const;
103 
104  // ### QGIS 3: remove in favor of setDirty(...)
105  void dirty( bool b );
106 
109  void setDirty( bool b );
111 
112 
117  void setFileName( const QString & name );
118 
120  QString fileName() const;
122 
126  void clear();
127 
128 
146  bool read( const QFileInfo & file );
147  bool read();
149 
150 
163  bool read( QDomNode & layerNode );
164 
165 
176  bool write( const QFileInfo & file );
177  bool write();
179 
180 
182  // DEPRECATED typedef QPair< QString, QVariant > PropertyValue;
183  // DEPRECATED typedef QValueList< PropertyValue > Properties;
184 
208  // DEPRECATED Properties & properties( QString const & scope );
209 
215  void clearProperties();
216 
217 
218  /* key value mutators
219 
220  keys would be the familiar QSettings-like '/' delimited entries, implying
221  a hierarchy of keys and corresponding values
222 
223  @note The key string <em>must</em> include '/'s. E.g., "/foo" not "foo".
224  */
226  bool writeEntry( const QString & scope, const QString & key, bool value );
229  bool writeEntry( const QString & scope, const QString & key, double value );
230  bool writeEntry( const QString & scope, const QString & key, int value );
231  bool writeEntry( const QString & scope, const QString & key, const QString & value );
232  bool writeEntry( const QString & scope, const QString & key, const QStringList & value );
234 
244  QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool *ok = 0 ) const;
245 
246  QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
247  int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
248  double readDoubleEntry( const QString & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
249  bool readBoolEntry( const QString & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
251 
252 
254  bool removeEntry( const QString & scope, const QString & key );
255 
256 
261  QStringList entryList( const QString & scope, const QString & key ) const;
262 
267  QStringList subkeyList( const QString & scope, const QString & key ) const;
268 
269 
275  void dumpProperties() const;
276 
279  QString writePath( QString filename ) const;
280 
283  QString readPath( QString filename ) const;
284 
287  QString error() const;
288 
292  void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
293 
295  QString layerIsEmbedded( const QString& id ) const;
296 
301  bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
302  QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
303 
307  QgsLayerTreeGroup* createEmbeddedGroup( const QString& groupName, const QString& projectFilePath );
308 
311  void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
312  bool avoidIntersection );
313 
316  bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
317  bool& avoidIntersection ) const;
318 
321  void setTopologicalEditing( bool enabled );
322 
325  bool topologicalEditing() const;
326 
330  QString homePath() const;
331 
332  QgsRelationManager* relationManager() const;
333 
337  QgsLayerTreeGroup* layerTreeRoot() const;
338 
342  QgsLayerTreeRegistryBridge* layerTreeRegistryBridge() const { return mLayerTreeRegistryBridge; }
343 
344  protected:
345 
348  void setError( QString errorMessage );
349 
352  void clearError();
353 
354  //Creates layer and adds it to maplayer registry
356  bool addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
357 
359  void initializeEmbeddedSubtree( const QString& projectFilePath, QgsLayerTreeGroup* group );
360 
362  void loadEmbeddedNodes( QgsLayerTreeGroup* group );
363 
365  void updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup* group );
366 
367  signals:
369  void readProject( const QDomDocument & );
370 
372  void writeProject( QDomDocument & );
373 
382  void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
383 
392  void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
393 
395  void projectSaved();
396 
398  void oldProjectVersionWarning( QString );
399 
401  // @param i current layer
402  // @param n number of layers
403  void layerLoaded( int i, int n );
404 
405  void loadingLayer( QString );
406 
407  void snapSettingsChanged();
408 
409  private:
410 
411  QgsProject(); // private 'cause it's a singleton
412 
413  QgsProject( QgsProject const & ); // private 'cause it's a singleton
414 
415  struct Imp;
416 
418  std::auto_ptr<Imp> imp_;
419 
421 
422  QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
423 
424  QString mErrorMessage;
425 
427 
431  QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
432 
433  void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
434  QStringList& avoidIntersectionList ) const;
435 
437 
438  QgsLayerTreeGroup* mRootGroup;
439 
440  QgsLayerTreeRegistryBridge* mLayerTreeRegistryBridge;
441 
442 }; // QgsProject
443 
444 
447 class CORE_EXPORT QgsProjectBadLayerHandler
448 {
449  public:
450  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
452 };
453 
454 
458 {
459  public:
460  virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
461 
462 };
463 
464 #endif
QString mErrorMessage
Definition: qgsproject.h:424
Base class for all map layer types.
Definition: qgsmaplayer.h:47
QgsLayerTreeRegistryBridge * layerTreeRegistryBridge() const
Return pointer to the helper class that synchronizes map layer registry with layer tree...
Definition: qgsproject.h:342
QHash< QString, QPair< QString, bool > > mEmbeddedLayers
Embeded layers which are defined in other projects.
Definition: qgsproject.h:431
QgsLayerTreeRegistryBridge * mLayerTreeRegistryBridge
Definition: qgsproject.h:440
UnitType
Type of unit of tolerance value from settings.
Definition: qgstolerance.h:33
QgsLayerTreeGroup * mRootGroup
Definition: qgsproject.h:438
SnappingType
Snap to vertex, to segment or both.
Definition: qgssnapper.h:66
Reads and writes project states.
Definition: qgsproject.h:67
QgsProjectBadLayerHandler * mBadLayerHandler
Definition: qgsproject.h:426
virtual ~QgsProjectBadLayerHandler()
Definition: qgsproject.h:451
QString file
Definition: qgssvgcache.cpp:76
This class manages a set of relations between layers.
static QgsProject * theProject_
Definition: qgsproject.h:420
std::auto_ptr< Imp > imp_
implementation handle
Definition: qgsproject.h:415
QgsRelationManager * mRelationManager
Definition: qgsproject.h:436
Default bad layer handler which ignores any missing layers.
Definition: qgsproject.h:457
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:447
virtual void handleBadLayers(QList< QDomNode > layers, QDomDocument projectDom)=0