Quantum GIS API Documentation  1.7.4
src/core/qgsprojectproperty.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                                   qgsproject.h
00003 
00004                       Implements persistent project state.
00005 
00006                               -------------------
00007   begin                : February 24, 2005
00008   copyright            : (C) 2005 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 /* $Id$ */
00022 
00023 #ifndef QGSPROJECTPROPERTY_H
00024 #define QGSPROJECTPROPERTY_H
00025 
00026 #include <QHash>
00027 #include <QVariant>
00028 
00029 class QDomNode;
00030 class QDomElement;
00031 class QDomDocument;
00032 class QStringList;
00033 
00034 
00048 class CORE_EXPORT QgsProperty
00049 {
00050   public:
00051 
00052     QgsProperty()
00053     {}
00054 
00055     virtual ~ QgsProperty()
00056     {}
00057 
00063     virtual void dump( size_t tabs = 0 ) const = 0;
00064 
00066     virtual bool isKey() const = 0;
00067 
00069     virtual bool isValue() const = 0;
00070 
00078     virtual bool isLeaf() const = 0;
00079 
00085     virtual bool readXML( QDomNode & keyNode ) = 0;
00086 
00096     virtual bool writeXML( QString const & nodeName,
00097                            QDomElement   & element,
00098                            QDomDocument  & document ) = 0;
00099 
00109     virtual QVariant value() const = 0;
00110 
00111 }; // class QgsProperty
00112 
00113 
00114 
00115 
00120 class CORE_EXPORT QgsPropertyValue : public QgsProperty
00121 {
00122   public:
00123     QgsPropertyValue()
00124     {}
00125 
00126     QgsPropertyValue( QVariant const &value )
00127         : value_( value )
00128     {}
00129 
00130     virtual ~ QgsPropertyValue()
00131     {}
00132 
00134     virtual bool isKey() const
00135     { return false; }
00136 
00138     virtual bool isValue() const
00139     { return true; }
00140 
00141     QVariant value() const
00142     { return value_; }
00143 
00149     bool isLeaf() const
00150     { return true; }
00151 
00152     void dump( size_t tabs = 0 ) const;
00153 
00154     bool readXML( QDomNode & keyNode );
00155 
00156     bool writeXML( QString const & nodeName,
00157                    QDomElement   & element,
00158                    QDomDocument  & document );
00159 
00160     size_t count() const
00161     { return 0; }
00162 
00163 
00168     void entryList( QStringList & keyName, QStringList & entries ) const
00169     { /* NOP */ }
00170 
00171   private:
00172 
00176     QVariant value_;
00177 
00178 }; // class QgsPropertyValue
00179 
00180 
00181 
00182 
00199 class CORE_EXPORT QgsPropertyKey : public QgsProperty
00200 {
00201   public:
00202 
00203     QgsPropertyKey( QString const name = "" );
00204 
00205     virtual ~ QgsPropertyKey();
00206 
00208     // @{
00209     QString const & name() const
00210     { return mName; }
00211 
00212     QString & name()
00213     { return mName; }
00214     // @}
00215 
00216 
00220     QVariant value() const;
00221 
00222 
00224     QgsPropertyKey * addKey( QString const & keyName )
00225     {
00226       delete mProperties.take( keyName );
00227       mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
00228 
00229       return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
00230     }
00231 
00232 
00234     void removeKey( QString const & keyName )
00235     {
00236       delete mProperties.take( keyName );
00237     }
00238 
00244     QgsPropertyValue * setValue( QString const & name, QVariant const & value )
00245     {
00246       delete mProperties.take( name );
00247       mProperties.insert( name, new QgsPropertyValue( value ) );
00248 
00249       return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
00250     }
00251 
00257     QgsPropertyValue * setValue( QVariant const & value )
00258     {
00259       return setValue( name(), value );
00260     }
00261 
00262 
00263 
00264     void dump( size_t tabs = 0 ) const;
00265 
00266     bool readXML( QDomNode & keyNode );
00267 
00268     bool writeXML( QString const &nodeName, QDomElement & element, QDomDocument & document );
00269 
00271     size_t count() const
00272     { return mProperties.count(); }
00273 
00275     /* virtual */ bool isEmpty() const
00276     { return mProperties.isEmpty(); }
00277 
00279     virtual bool isKey() const
00280     { return true; }
00281 
00283     virtual bool isValue() const
00284     { return false; }
00285 
00287     void entryList( QStringList & entries ) const;
00288 
00290     void subkeyList( QStringList & entries ) const;
00291 
00297     bool isLeaf() const;
00298 
00300     virtual void clear()
00301     {
00302       mName = "";
00303       clearKeys();
00304     }
00305 
00307     virtual void clearKeys()
00308     {
00309       qDeleteAll( mProperties );
00310       mProperties.clear();
00311     }
00312 
00313     QgsProperty * find( QString & propertyName )
00314     {
00315       return mProperties.value( propertyName );
00316     }
00317 
00318   private:
00319 
00321     QString mName;
00322 
00324     QHash < QString, QgsProperty* > mProperties;
00325 
00326 }; // class QgsPropertyKey
00327 
00328 
00329 
00330 
00331 
00332 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines