QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
22 #ifndef QGSPROJECTPROPERTY_H
23 #define QGSPROJECTPROPERTY_H
24 
25 #include <QHash>
26 #include <QVariant>
27 #include <QStringList>
28 
29 class QDomNode;
30 class QDomElement;
31 class QDomDocument;
32 
33 
47 class CORE_EXPORT QgsProperty
48 {
49  public:
50 
52  {}
53 
54  virtual ~ QgsProperty()
55  {}
56 
62  virtual void dump( size_t tabs = 0 ) const = 0;
63 
65  virtual bool isKey() const = 0;
66 
68  virtual bool isValue() const = 0;
69 
77  virtual bool isLeaf() const = 0;
78 
84  virtual bool readXML( QDomNode & keyNode ) = 0;
85 
95  virtual bool writeXML( const QString & nodeName,
96  QDomElement & element,
97  QDomDocument & document ) = 0;
98 
108  virtual QVariant value() const = 0;
109 
110 }; // class QgsProperty
111 
112 
113 
114 
119 class CORE_EXPORT QgsPropertyValue : public QgsProperty
120 {
121  public:
123  {}
124 
125  QgsPropertyValue( const QVariant &value )
126  : value_( value )
127  {}
128 
129  virtual ~ QgsPropertyValue()
130  {}
131 
133  virtual bool isKey() const
134  { return false; }
135 
137  virtual bool isValue() const
138  { return true; }
139 
140  QVariant value() const
141  { return value_; }
142 
148  bool isLeaf() const
149  { return true; }
150 
151  void dump( size_t tabs = 0 ) const;
152 
153  bool readXML( QDomNode & keyNode );
154 
155  bool writeXML( const QString & nodeName,
156  QDomElement & element,
157  QDomDocument & document );
158 
159  size_t count() const
160  { return 0; }
161 
162 
167  void entryList( QStringList & keyName, QStringList & entries ) const
168  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
169 
170  private:
171 
175  QVariant value_;
176 
177 }; // class QgsPropertyValue
178 
179 
180 
181 
198 class CORE_EXPORT QgsPropertyKey : public QgsProperty
199 {
200  public:
201  QgsPropertyKey( const QString name = "" );
202  virtual ~ QgsPropertyKey();
203 
205  // @{
206  const QString &name() const
207  { return mName; }
208 
209  QString & name()
210  { return mName; }
211  // @}
212 
213 
217  QVariant value() const;
218 
219 
221  QgsPropertyKey * addKey( const QString & keyName )
222  {
223  delete mProperties.take( keyName );
224  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
225 
226  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
227  }
228 
229 
231  void removeKey( const QString & keyName )
232  {
233  delete mProperties.take( keyName );
234  }
235 
241  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
242  {
243  delete mProperties.take( name );
244  mProperties.insert( name, new QgsPropertyValue( value ) );
245 
246  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
247  }
248 
254  QgsPropertyValue * setValue( const QVariant & value )
255  {
256  return setValue( name(), value );
257  }
258 
259 
260 
261  void dump( size_t tabs = 0 ) const;
262 
263  bool readXML( QDomNode & keyNode );
264 
265  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document );
266 
268  size_t count() const
269  { return mProperties.count(); }
270 
272  /* virtual */ bool isEmpty() const
273  { return mProperties.isEmpty(); }
274 
276  virtual bool isKey() const
277  { return true; }
278 
280  virtual bool isValue() const
281  { return false; }
282 
284  void entryList( QStringList & entries ) const;
285 
287  void subkeyList( QStringList & entries ) const;
288 
294  bool isLeaf() const;
295 
297  virtual void clear()
298  {
299  mName = "";
300  clearKeys();
301  }
302 
304  virtual void clearKeys()
305  {
306  qDeleteAll( mProperties );
307  mProperties.clear();
308  }
309 
310  QgsProperty * find( QString & propertyName )
311  {
312  return mProperties.value( propertyName );
313  }
314 
315  private:
316 
318  QString mName;
319 
321  QHash < QString, QgsProperty* > mProperties;
322 
323 }; // class QgsPropertyKey
324 
325 #endif
virtual bool isKey() const
returns true if is a QgsPropertyKey
virtual bool readXML(QDomNode &keyNode)=0
restores property hierarchy to given Dom node
size_t count() const
how many elements are contained within this one?
virtual bool isLeaf() const =0
returns true if a leaf node
QgsPropertyKey * addKey(const QString &keyName)
add the given property key
QgsPropertyValue * setValue(const QString &name, const QVariant &value)
set the value associated with this key
QVariant value() const
return the node's value
QHash< QString, QgsProperty * > mProperties
sub-keys
QgsPropertyValue node.
QString mName
every key has a name
bool isLeaf() const
returns true if is a leaf node
QgsPropertyValue * setValue(const QVariant &value)
set the value associated with this key
void removeKey(const QString &keyName)
remove the given key
virtual void clearKeys()
delete any sub-nodes
QgsPropertyKey node.
virtual QVariant value() const =0
return the node's value
bool isEmpty() const
Does this property not have any subkeys or values?
An Abstract Base Class for QGIS project property hierarchies.
QgsProperty * find(QString &propertyName)
virtual void clear()
reset the QgsProperty key to prestine state
virtual bool isKey() const
returns true if is a QgsPropertyKey
QgsPropertyValue(const QVariant &value)
QVariant value_
We use QVariant as it's very handy to keep multiple types and provides type conversions.
virtual bool writeXML(const QString &nodeName, QDomElement &element, QDomDocument &document)=0
adds property hierarchy to given Dom element
void entryList(QStringList &keyName, QStringList &entries) const
return keys that do not contain other keys
virtual bool isValue() const
returns true if is a QgsPropertyValue
const QString & name() const
every key has a name
virtual void dump(size_t tabs=0) const =0
dumps out the keys and values
size_t count() const
virtual bool isValue() const
returns true if is a QgsPropertyValue