QGIS API Documentation  2.15.0-Master (af20121)
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 
61  virtual void dump( int tabs = 0 ) const = 0;
62 
64  virtual bool isKey() const = 0;
65 
67  virtual bool isValue() const = 0;
68 
76  virtual bool isLeaf() const = 0;
77 
83  virtual bool readXML( QDomNode & keyNode ) = 0;
84 
94  virtual bool writeXML( const QString & nodeName,
95  QDomElement & element,
96  QDomDocument & document ) = 0;
97 
107  virtual QVariant value() const = 0;
108 
109 }; // class QgsProperty
110 
111 
112 
113 
118 class CORE_EXPORT QgsPropertyValue : public QgsProperty
119 {
120  public:
122 
123  QgsPropertyValue( const QVariant &value )
124  : value_( value )
125  {}
126 
127  virtual ~QgsPropertyValue() {}
128 
130  virtual bool isKey() const override { return false; }
131 
133  virtual bool isValue() const override { return true; }
134 
135  QVariant value() const override { return value_; }
136 
142  bool isLeaf() const override { return true; }
143 
144  void dump( int tabs = 0 ) const override;
145 
146  bool readXML( QDomNode & keyNode ) override;
147 
148  bool writeXML( const QString & nodeName,
149  QDomElement & element,
150  QDomDocument & document ) override;
151 
152  int count() const { return 0; }
153 
157  void entryList( QStringList & keyName, QStringList & entries ) const
158  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
159 
160  private:
161 
165  QVariant value_;
166 
167 }; // class QgsPropertyValue
168 
169 
170 
171 
188 class CORE_EXPORT QgsPropertyKey : public QgsProperty
189 {
190  public:
191  QgsPropertyKey( const QString &name = "" );
192  virtual ~ QgsPropertyKey();
193 
195  // @{
196  // @note not available in python bindings
197  QString name() const { return mName; }
198 
199  QString &name() { return mName; }
200  // @}
201 
202 
206  QVariant value() const override;
207 
208 
210  QgsPropertyKey * addKey( const QString & keyName )
211  {
212  delete mProperties.take( keyName );
213  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
214 
215  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
216  }
217 
218 
220  void removeKey( const QString & keyName )
221  {
222  delete mProperties.take( keyName );
223  }
224 
230  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
231  {
232  delete mProperties.take( name );
233  mProperties.insert( name, new QgsPropertyValue( value ) );
234 
235  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
236  }
237 
243  QgsPropertyValue * setValue( const QVariant & value )
244  {
245  return setValue( name(), value );
246  }
247 
248  void dump( int tabs = 0 ) const override;
249 
250  bool readXML( QDomNode & keyNode ) override;
251 
252  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document ) override;
253 
255  int count() const { return mProperties.count(); }
256 
258  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
259 
261  virtual bool isKey() const override { return true; }
262 
264  virtual bool isValue() const override { return false; }
265 
267  void entryList( QStringList & entries ) const;
268 
270  void subkeyList( QStringList & entries ) const;
271 
276  bool isLeaf() const override;
277 
279  virtual void clear()
280  {
281  mName = "";
282  clearKeys();
283  }
284 
286  virtual void clearKeys()
287  {
288  qDeleteAll( mProperties );
289  mProperties.clear();
290  }
291 
292  QgsProperty * find( QString & propertyName )
293  {
294  return mProperties.value( propertyName );
295  }
296 
297  private:
298 
300  QString mName;
301 
304 
305 }; // class QgsPropertyKey
306 
307 #endif
virtual bool readXML(QDomNode &keyNode)=0
restores property hierarchy to given Dom node
virtual bool isValue() const override
Returns true if is a QgsPropertyValue.
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
QgsPropertyValue * setValue(const QString &name, const QVariant &value)
Set the value associated with this key.
virtual bool isKey() const override
Returns true if is a QgsPropertyKey.
QgsPropertyValue node.
virtual bool isValue() const override
Returns true if is a QgsPropertyValue.
QString name() const
every key has a name
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&#39;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 bool isKey() const override
Returns true if is a QgsPropertyKey.
QVariant value() const override
Return the node&#39;s value.
virtual void clear()
reset the QgsProperty key to prestine state
QgsPropertyValue(const QVariant &value)
bool isLeaf() const override
Returns true if is a leaf node.
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 Since QgsPropertyValue isn&#39;t a key, don&#39;t do anything...
int count() const
how many elements are contained within this one?