QGIS API Documentation  2.17.0-Master (f49f7ce)
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 
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 
158  void entryList( QStringList & keyName, QStringList & entries ) const
159  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
160 
161  private:
162 
166  QVariant value_;
167 
168 }; // class QgsPropertyValue
169 
170 
171 
172 
189 class CORE_EXPORT QgsPropertyKey : public QgsProperty
190 {
191  public:
192  QgsPropertyKey( const QString &name = "" );
193  virtual ~ QgsPropertyKey();
194 
196  // @{
197  // @note not available in python bindings
198  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  void dump( int tabs = 0 ) const override;
250 
251  bool readXML( QDomNode & keyNode ) override;
252 
253  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document ) override;
254 
256  int count() const { return mProperties.count(); }
257 
259  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
260 
262  virtual bool isKey() const override { return true; }
263 
265  virtual bool isValue() const override { return false; }
266 
268  void entryList( QStringList & entries ) const;
269 
271  void subkeyList( QStringList & entries ) const;
272 
277  bool isLeaf() const override;
278 
280  virtual void clear()
281  {
282  mName = "";
283  clearKeys();
284  }
285 
287  virtual void clearKeys()
288  {
289  qDeleteAll( mProperties );
290  mProperties.clear();
291  }
292 
293  QgsProperty * find( QString & propertyName )
294  {
295  return mProperties.value( propertyName );
296  }
297 
298  private:
299 
301  QString mName;
302 
305 
306 }; // class QgsPropertyKey
307 
308 #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?