QGIS API Documentation  master-3f58142
src/core/qgsproject.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                                   qgsproject.h
00003 
00004                       Implements persistent project state.
00005 
00006                               -------------------
00007   begin                : July 23, 2004
00008   copyright            : (C) 2004 by Mark Coletti
00009   email                : mcoletti at gmail.com
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 #ifndef QGSPROJECT_H
00022 #define QGSPROJECT_H
00023 
00024 #include <memory>
00025 #include "qgsprojectversion.h"
00026 #include <QHash>
00027 #include <QList>
00028 #include <QObject>
00029 #include <QPair>
00030 
00031 //for the snap settings
00032 #include "qgssnapper.h"
00033 #include "qgstolerance.h"
00034 
00035 //#include <QDomDocument>
00036 
00037 class QFileInfo;
00038 class QDomDocument;
00039 class QDomElement;
00040 class QDomNode;
00041 
00042 class QgsMapLayer;
00043 class QgsProjectBadLayerHandler;
00044 class QgsVectorLayer;
00045 
00064 class CORE_EXPORT QgsProject : public QObject
00065 {
00066     Q_OBJECT
00067 
00068   public:
00069 
00073     ~QgsProject();
00074 
00076     static QgsProject * instance();
00077 
00084     void title( const QString & title );
00085 
00087     const QString & title() const;
00089 
00095     bool isDirty() const;
00096 
00097     void dirty( bool b );
00099 
00100 
00105     void setFileName( const QString & name );
00106 
00108     QString fileName() const;
00110 
00111 
00138     bool read( const QFileInfo & file );
00139     bool read();
00141 
00142 
00155     bool read( QDomNode & layerNode );
00156 
00157 
00168     bool write( const QFileInfo & file );
00169     bool write();
00171 
00172 
00174     // DEPRECATED typedef QPair< QString, QVariant >  PropertyValue;
00175     // DEPRECATED typedef QValueList< PropertyValue > Properties;
00176 
00200     // DEPRECATED Properties & properties( QString const & scope );
00201 
00205     void clearProperties();
00206 
00207 
00208     /* key value mutators
00209 
00210       keys would be the familiar QSettings-like '/' delimited entries, implying
00211       a hierarchy of keys and corresponding values
00212 
00213       @note The key string <em>must</em> include '/'s.  E.g., "/foo" not "foo".
00214     */
00216 
00217     bool writeEntry( const QString & scope, const QString & key, bool value );
00219     bool writeEntry( const QString & scope, const QString & key, double value );
00220     bool writeEntry( const QString & scope, const QString & key, int value );
00221     bool writeEntry( const QString & scope, const QString & key, const QString & value );
00222     bool writeEntry( const QString & scope, const QString & key, const QStringList & value );
00224 
00234     QStringList readListEntry( const QString & scope, const QString & key, QStringList def = QStringList(), bool *ok = 0 ) const;
00235 
00236     QString readEntry( const QString & scope, const QString & key, const QString & def = QString::null, bool * ok = 0 ) const;
00237     int readNumEntry( const QString & scope, const QString & key, int def = 0, bool * ok = 0 ) const;
00238     double readDoubleEntry( const QString & scope, const QString & key, double def = 0, bool * ok = 0 ) const;
00239     bool readBoolEntry( const QString & scope, const QString & key, bool def = false, bool * ok = 0 ) const;
00241 
00242 
00244     bool removeEntry( const QString & scope, const QString & key );
00245 
00246 
00251     QStringList entryList( const QString & scope, const QString & key ) const;
00252 
00257     QStringList subkeyList( const QString & scope, const QString & key ) const;
00258 
00259 
00265     void dumpProperties() const;
00266 
00269     QString writePath( QString filename ) const;
00270 
00273     QString readPath( QString filename ) const;
00274 
00277     QString error() const;
00278 
00282     void setBadLayerHandler( QgsProjectBadLayerHandler* handler );
00283 
00285     QString layerIsEmbedded( const QString& id ) const;
00286 
00292     bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
00293                               QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );
00294 
00297     void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
00298                                   bool avoidIntersection );
00299 
00302     bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
00303                                bool& avoidIntersection ) const;
00304 
00307     void setTopologicalEditing( bool enabled );
00308 
00311     bool topologicalEditing() const;
00312 
00316     QString homePath() const;
00317 
00318   protected:
00319 
00322     void setError( QString errorMessage );
00323 
00326     void clearError();
00327 
00328     //Creates layer and adds it to maplayer registry
00330     bool addLayer( const QDomElement& layerElem, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );
00331 
00332   signals:
00334     void readProject( const QDomDocument & );
00335 
00337     void writeProject( QDomDocument & );
00338 
00347     void readMapLayer( QgsMapLayer *mapLayer, const QDomElement &layerNode );
00348 
00357     void writeMapLayer( QgsMapLayer *mapLayer, QDomElement &layerElem, QDomDocument &doc );
00358 
00360     void projectSaved();
00361 
00363     void oldProjectVersionWarning( QString );
00364 
00366     // @param i current layer
00367     // @param n number of layers
00368     void layerLoaded( int i, int n );
00369 
00370     void loadingLayer( QString );
00371 
00372     void snapSettingsChanged();
00373 
00374   private:
00375 
00376     QgsProject(); // private 'cause it's a singleton
00377 
00378     QgsProject( QgsProject const & ); // private 'cause it's a singleton
00379 
00380     struct Imp;
00381 
00383     std::auto_ptr<Imp> imp_;
00384 
00385     static QgsProject * theProject_;
00386 
00387     QPair< bool, QList<QDomNode> > _getMapLayers( QDomDocument const &doc );
00388 
00389     QString mErrorMessage;
00390 
00391     QgsProjectBadLayerHandler* mBadLayerHandler;
00392 
00396     QHash< QString, QPair< QString, bool> > mEmbeddedLayers;
00397 
00398     void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
00399                        QStringList& avoidIntersectionList ) const;
00400 
00401 }; // QgsProject
00402 
00403 
00406 class CORE_EXPORT QgsProjectBadLayerHandler
00407 {
00408   public:
00409     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom ) = 0;
00410     virtual ~QgsProjectBadLayerHandler() {}
00411 };
00412 
00413 
00416 class CORE_EXPORT QgsProjectBadLayerDefaultHandler : public QgsProjectBadLayerHandler
00417 {
00418   public:
00419     virtual void handleBadLayers( QList<QDomNode> layers, QDomDocument projectDom );
00420 
00421 };
00422 
00423 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines