QGIS API Documentation  2.8.2-Wien
 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( 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 override { return false; }
132 
134  virtual bool isValue() const override { return true; }
135 
136  QVariant value() const override { return value_; }
137 
143  bool isLeaf() const override { return true; }
144 
145  void dump( int tabs = 0 ) const override;
146 
147  bool readXML( QDomNode & keyNode ) override;
148 
149  bool writeXML( const QString & nodeName,
150  QDomElement & element,
151  QDomDocument & document ) override;
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 override;
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 override;
252 
253  bool readXML( QDomNode & keyNode ) override;
254 
255  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document ) override;
256 
258  int count() const { return mProperties.count(); }
259 
261  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
262 
264  virtual bool isKey() const override { return true; }
265 
267  virtual bool isValue() const override { return false; }
268 
270  void entryList( QStringList & entries ) const;
271 
273  void subkeyList( QStringList & entries ) const;
274 
280  bool isLeaf() const override;
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