Quantum GIS API Documentation
1.8
|
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 00022 #ifndef QGSPROJECTPROPERTY_H 00023 #define QGSPROJECTPROPERTY_H 00024 00025 #include <QHash> 00026 #include <QVariant> 00027 #include <QStringList> 00028 00029 class QDomNode; 00030 class QDomElement; 00031 class QDomDocument; 00032 00033 00047 class CORE_EXPORT QgsProperty 00048 { 00049 public: 00050 00051 QgsProperty() 00052 {} 00053 00054 virtual ~ QgsProperty() 00055 {} 00056 00062 virtual void dump( size_t tabs = 0 ) const = 0; 00063 00065 virtual bool isKey() const = 0; 00066 00068 virtual bool isValue() const = 0; 00069 00077 virtual bool isLeaf() const = 0; 00078 00084 virtual bool readXML( QDomNode & keyNode ) = 0; 00085 00095 virtual bool writeXML( QString const & nodeName, 00096 QDomElement & element, 00097 QDomDocument & document ) = 0; 00098 00108 virtual QVariant value() const = 0; 00109 00110 }; // class QgsProperty 00111 00112 00113 00114 00119 class CORE_EXPORT QgsPropertyValue : public QgsProperty 00120 { 00121 public: 00122 QgsPropertyValue() 00123 {} 00124 00125 QgsPropertyValue( QVariant const &value ) 00126 : value_( value ) 00127 {} 00128 00129 virtual ~ QgsPropertyValue() 00130 {} 00131 00133 virtual bool isKey() const 00134 { return false; } 00135 00137 virtual bool isValue() const 00138 { return true; } 00139 00140 QVariant value() const 00141 { return value_; } 00142 00148 bool isLeaf() const 00149 { return true; } 00150 00151 void dump( size_t tabs = 0 ) const; 00152 00153 bool readXML( QDomNode & keyNode ); 00154 00155 bool writeXML( QString const & nodeName, 00156 QDomElement & element, 00157 QDomDocument & document ); 00158 00159 size_t count() const 00160 { return 0; } 00161 00162 00167 void entryList( QStringList & keyName, QStringList & entries ) const 00168 { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ } 00169 00170 private: 00171 00175 QVariant value_; 00176 00177 }; // class QgsPropertyValue 00178 00179 00180 00181 00198 class CORE_EXPORT QgsPropertyKey : public QgsProperty 00199 { 00200 public: 00201 00202 QgsPropertyKey( QString const name = "" ); 00203 00204 virtual ~ QgsPropertyKey(); 00205 00207 // @{ 00208 QString const & name() const 00209 { return mName; } 00210 00211 QString & name() 00212 { return mName; } 00213 // @} 00214 00215 00219 QVariant value() const; 00220 00221 00223 QgsPropertyKey * addKey( QString const & keyName ) 00224 { 00225 delete mProperties.take( keyName ); 00226 mProperties.insert( keyName, new QgsPropertyKey( keyName ) ); 00227 00228 return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) ); 00229 } 00230 00231 00233 void removeKey( QString const & keyName ) 00234 { 00235 delete mProperties.take( keyName ); 00236 } 00237 00243 QgsPropertyValue * setValue( QString const & name, QVariant const & value ) 00244 { 00245 delete mProperties.take( name ); 00246 mProperties.insert( name, new QgsPropertyValue( value ) ); 00247 00248 return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) ); 00249 } 00250 00256 QgsPropertyValue * setValue( QVariant const & value ) 00257 { 00258 return setValue( name(), value ); 00259 } 00260 00261 00262 00263 void dump( size_t tabs = 0 ) const; 00264 00265 bool readXML( QDomNode & keyNode ); 00266 00267 bool writeXML( QString const &nodeName, QDomElement & element, QDomDocument & document ); 00268 00270 size_t count() const 00271 { return mProperties.count(); } 00272 00274 /* virtual */ bool isEmpty() const 00275 { return mProperties.isEmpty(); } 00276 00278 virtual bool isKey() const 00279 { return true; } 00280 00282 virtual bool isValue() const 00283 { return false; } 00284 00286 void entryList( QStringList & entries ) const; 00287 00289 void subkeyList( QStringList & entries ) const; 00290 00296 bool isLeaf() const; 00297 00299 virtual void clear() 00300 { 00301 mName = ""; 00302 clearKeys(); 00303 } 00304 00306 virtual void clearKeys() 00307 { 00308 qDeleteAll( mProperties ); 00309 mProperties.clear(); 00310 } 00311 00312 QgsProperty * find( QString & propertyName ) 00313 { 00314 return mProperties.value( propertyName ); 00315 } 00316 00317 private: 00318 00320 QString mName; 00321 00323 QHash < QString, QgsProperty* > mProperties; 00324 00325 }; // class QgsPropertyKey 00326 00327 00328 00329 00330 00331 #endif