|
QGIS API Documentation
master-6227475
|
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( const QString & 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( const QVariant &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( const QString & 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 QgsPropertyKey( const QString name = "" ); 00202 virtual ~ QgsPropertyKey(); 00203 00205 // @{ 00206 const QString &name() const 00207 { return mName; } 00208 00209 QString & name() 00210 { return mName; } 00211 // @} 00212 00213 00217 QVariant value() const; 00218 00219 00221 QgsPropertyKey * addKey( const QString & keyName ) 00222 { 00223 delete mProperties.take( keyName ); 00224 mProperties.insert( keyName, new QgsPropertyKey( keyName ) ); 00225 00226 return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) ); 00227 } 00228 00229 00231 void removeKey( const QString & keyName ) 00232 { 00233 delete mProperties.take( keyName ); 00234 } 00235 00241 QgsPropertyValue * setValue( const QString & name, const QVariant & value ) 00242 { 00243 delete mProperties.take( name ); 00244 mProperties.insert( name, new QgsPropertyValue( value ) ); 00245 00246 return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) ); 00247 } 00248 00254 QgsPropertyValue * setValue( const QVariant & value ) 00255 { 00256 return setValue( name(), value ); 00257 } 00258 00259 00260 00261 void dump( size_t tabs = 0 ) const; 00262 00263 bool readXML( QDomNode & keyNode ); 00264 00265 bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document ); 00266 00268 size_t count() const 00269 { return mProperties.count(); } 00270 00272 /* virtual */ bool isEmpty() const 00273 { return mProperties.isEmpty(); } 00274 00276 virtual bool isKey() const 00277 { return true; } 00278 00280 virtual bool isValue() const 00281 { return false; } 00282 00284 void entryList( QStringList & entries ) const; 00285 00287 void subkeyList( QStringList & entries ) const; 00288 00294 bool isLeaf() const; 00295 00297 virtual void clear() 00298 { 00299 mName = ""; 00300 clearKeys(); 00301 } 00302 00304 virtual void clearKeys() 00305 { 00306 qDeleteAll( mProperties ); 00307 mProperties.clear(); 00308 } 00309 00310 QgsProperty * find( QString & propertyName ) 00311 { 00312 return mProperties.value( propertyName ); 00313 } 00314 00315 private: 00316 00318 QString mName; 00319 00321 QHash < QString, QgsProperty* > mProperties; 00322 00323 }; // class QgsPropertyKey 00324 00325 #endif