QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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( int 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  QgsPropertyValue( const QVariant &value )
125  : value_( value )
126  {}
127 
128  virtual ~QgsPropertyValue() {}
129 
131  virtual bool isKey() const { return false; }
132 
134  virtual bool isValue() const { return true; }
135 
136  QVariant value() const { return value_; }
137 
143  bool isLeaf() const { return true; }
144 
145  void dump( int tabs = 0 ) const;
146 
147  bool readXML( QDomNode & keyNode );
148 
149  bool writeXML( const QString & nodeName,
150  QDomElement & element,
151  QDomDocument & document );
152 
153  int count() const { return 0; }
154 
159  void entryList( QStringList & keyName, QStringList & entries ) const
160  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
161 
162  private:
163 
167  QVariant value_;
168 
169 }; // class QgsPropertyValue
170 
171 
172 
173 
190 class CORE_EXPORT QgsPropertyKey : public QgsProperty
191 {
192  public:
193  QgsPropertyKey( const QString &name = "" );
194  virtual ~ QgsPropertyKey();
195 
197  // @{
198  const QString &name() const { return mName; }
199 
200  QString &name() { return mName; }
201  // @}
202 
203 
207  QVariant value() const;
208 
209 
211  QgsPropertyKey * addKey( const QString & keyName )
212  {
213  delete mProperties.take( keyName );
214  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
215 
216  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
217  }
218 
219 
221  void removeKey( const QString & keyName )
222  {
223  delete mProperties.take( keyName );
224  }
225 
231  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
232  {
233  delete mProperties.take( name );
234  mProperties.insert( name, new QgsPropertyValue( value ) );
235 
236  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
237  }
238 
244  QgsPropertyValue * setValue( const QVariant & value )
245  {
246  return setValue( name(), value );
247  }
248 
249 
250 
251  void dump( int tabs = 0 ) const;
252 
253  bool readXML( QDomNode & keyNode );
254 
255  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document );
256 
258  int count() const { return mProperties.count(); }
259 
261  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
262 
264  virtual bool isKey() const { return true; }
265 
267  virtual bool isValue() const { return false; }
268 
270  void entryList( QStringList & entries ) const;
271 
273  void subkeyList( QStringList & entries ) const;
274 
280  bool isLeaf() const;
281 
283  virtual void clear()
284  {
285  mName = "";
286  clearKeys();
287  }
288 
290  virtual void clearKeys()
291  {
292  qDeleteAll( mProperties );
293  mProperties.clear();
294  }
295 
296  QgsProperty * find( QString & propertyName )
297  {
298  return mProperties.value( propertyName );
299  }
300 
301  private:
302 
304  QString mName;
305 
307  QHash < QString, QgsProperty* > mProperties;
308 
309 }; // class QgsPropertyKey
310 
311 #endif
virtual bool isKey() const
returns true if is a QgsPropertyKey
Definition: qgsprojectproperty.h:131
virtual bool readXML(QDomNode &keyNode)=0
restores property hierarchy to given Dom node
virtual bool isLeaf() const =0
returns true if a leaf node
virtual void dump(int tabs=0) const =0
dumps out the keys and values
QgsPropertyKey * addKey(const QString &keyName)
add the given property key
Definition: qgsprojectproperty.h:211
QgsPropertyValue * setValue(const QString &name, const QVariant &value)
set the value associated with this key
Definition: qgsprojectproperty.h:231
QVariant value() const
return the node's value
Definition: qgsprojectproperty.h:136
QgsPropertyValue node.
Definition: qgsprojectproperty.h:119
QgsProperty()
Definition: qgsprojectproperty.h:51
QgsPropertyValue()
Definition: qgsprojectproperty.h:122
bool isLeaf() const
returns true if is a leaf node
Definition: qgsprojectproperty.h:143
QgsPropertyValue * setValue(const QVariant &value)
set the value associated with this key
Definition: qgsprojectproperty.h:244
void removeKey(const QString &keyName)
remove the given key
Definition: qgsprojectproperty.h:221
virtual void clearKeys()
delete any sub-nodes
Definition: qgsprojectproperty.h:290
QgsPropertyKey node.
Definition: qgsprojectproperty.h:190
virtual QVariant value() const =0
return the node's value
bool isEmpty() const
Does this property not have any subkeys or values?
Definition: qgsprojectproperty.h:261
virtual ~QgsPropertyValue()
Definition: qgsprojectproperty.h:128
int count() const
Definition: qgsprojectproperty.h:153
An Abstract Base Class for QGIS project property hierarchies.
Definition: qgsprojectproperty.h:47
QgsProperty * find(QString &propertyName)
Definition: qgsprojectproperty.h:296
virtual void clear()
reset the QgsProperty key to prestine state
Definition: qgsprojectproperty.h:283
virtual bool isKey() const
returns true if is a QgsPropertyKey
Definition: qgsprojectproperty.h:264
QgsPropertyValue(const QVariant &value)
Definition: qgsprojectproperty.h:124
QString & name()
Definition: qgsprojectproperty.h:200
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
Definition: qgsprojectproperty.h:159
virtual bool isValue() const
returns true if is a QgsPropertyValue
Definition: qgsprojectproperty.h:267
const QString & name() const
every key has a name
Definition: qgsprojectproperty.h:198
virtual bool isValue() const
returns true if is a QgsPropertyValue
Definition: qgsprojectproperty.h:134
int count() const
how many elements are contained within this one?
Definition: qgsprojectproperty.h:258