Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsprojectproperty.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproject.h
3 
4  Implements persistent project state.
5 
6  -------------------
7  begin : February 24, 2005
8  copyright : (C) 2005 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 /* $Id$ */
22 
23 #ifndef QGSPROJECTPROPERTY_H
24 #define QGSPROJECTPROPERTY_H
25 
26 #include <QHash>
27 #include <QVariant>
28 
29 class QDomNode;
30 class QDomElement;
31 class QDomDocument;
32 class QStringList;
33 
34 
48 class CORE_EXPORT QgsProperty
49 {
50  public:
51 
53  {}
54 
55  virtual ~ QgsProperty()
56  {}
57 
63  virtual void dump( size_t tabs = 0 ) const = 0;
64 
66  virtual bool isKey() const = 0;
67 
69  virtual bool isValue() const = 0;
70 
78  virtual bool isLeaf() const = 0;
79 
85  virtual bool readXML( QDomNode & keyNode ) = 0;
86 
96  virtual bool writeXML( QString const & nodeName,
97  QDomElement & element,
98  QDomDocument & document ) = 0;
99 
109  virtual QVariant value() const = 0;
110 
111 }; // class QgsProperty
112 
113 
114 
115 
120 class CORE_EXPORT QgsPropertyValue : public QgsProperty
121 {
122  public:
124  {}
125 
126  QgsPropertyValue( QVariant const &value )
127  : value_( value )
128  {}
129 
130  virtual ~ QgsPropertyValue()
131  {}
132 
134  virtual bool isKey() const
135  { return false; }
136 
138  virtual bool isValue() const
139  { return true; }
140 
141  QVariant value() const
142  { return value_; }
143 
149  bool isLeaf() const
150  { return true; }
151 
152  void dump( size_t tabs = 0 ) const;
153 
154  bool readXML( QDomNode & keyNode );
155 
156  bool writeXML( QString const & nodeName,
157  QDomElement & element,
158  QDomDocument & document );
159 
160  size_t count() const
161  { return 0; }
162 
163 
168  void entryList( QStringList & keyName, QStringList & entries ) const
169  { /* NOP */ }
170 
171  private:
172 
176  QVariant value_;
177 
178 }; // class QgsPropertyValue
179 
180 
181 
182 
199 class CORE_EXPORT QgsPropertyKey : public QgsProperty
200 {
201  public:
202 
203  QgsPropertyKey( QString const name = "" );
204 
205  virtual ~ QgsPropertyKey();
206 
208  // @{
209  QString const & name() const
210  { return mName; }
211 
212  QString & name()
213  { return mName; }
214  // @}
215 
216 
220  QVariant value() const;
221 
222 
224  QgsPropertyKey * addKey( QString const & keyName )
225  {
226  delete mProperties.take( keyName );
227  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
228 
229  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
230  }
231 
232 
234  void removeKey( QString const & keyName )
235  {
236  delete mProperties.take( keyName );
237  }
238 
244  QgsPropertyValue * setValue( QString const & name, QVariant const & value )
245  {
246  delete mProperties.take( name );
247  mProperties.insert( name, new QgsPropertyValue( value ) );
248 
249  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
250  }
251 
257  QgsPropertyValue * setValue( QVariant const & value )
258  {
259  return setValue( name(), value );
260  }
261 
262 
263 
264  void dump( size_t tabs = 0 ) const;
265 
266  bool readXML( QDomNode & keyNode );
267 
268  bool writeXML( QString const &nodeName, QDomElement & element, QDomDocument & document );
269 
271  size_t count() const
272  { return mProperties.count(); }
273 
275  /* virtual */ bool isEmpty() const
276  { return mProperties.isEmpty(); }
277 
279  virtual bool isKey() const
280  { return true; }
281 
283  virtual bool isValue() const
284  { return false; }
285 
287  void entryList( QStringList & entries ) const;
288 
290  void subkeyList( QStringList & entries ) const;
291 
297  bool isLeaf() const;
298 
300  virtual void clear()
301  {
302  mName = "";
303  clearKeys();
304  }
305 
307  virtual void clearKeys()
308  {
309  qDeleteAll( mProperties );
310  mProperties.clear();
311  }
312 
313  QgsProperty * find( QString & propertyName )
314  {
315  return mProperties.value( propertyName );
316  }
317 
318  private:
319 
321  QString mName;
322 
324  QHash < QString, QgsProperty* > mProperties;
325 
326 }; // class QgsPropertyKey
327 
328 
329 
330 
331 
332 #endif