QGIS API Documentation  2.14.11-Essen
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  QgsProperty();
51  virtual ~QgsProperty();
52 
57  virtual void dump( int tabs = 0 ) const = 0;
58 
60  virtual bool isKey() const = 0;
61 
63  virtual bool isValue() const = 0;
64 
72  virtual bool isLeaf() const = 0;
73 
79  virtual bool readXML( QDomNode & keyNode ) = 0;
80 
90  virtual bool writeXML( const QString & nodeName,
91  QDomElement & element,
92  QDomDocument & document ) = 0;
93 
103  virtual QVariant value() const = 0;
104 
105 }; // class QgsProperty
106 
107 
108 
109 
114 class CORE_EXPORT QgsPropertyValue : public QgsProperty
115 {
116  public:
118 
119  QgsPropertyValue( const QVariant &value )
120  : value_( value )
121  {}
122 
123  virtual ~QgsPropertyValue();
124 
126  virtual bool isKey() const override { return false; }
127 
129  virtual bool isValue() const override { return true; }
130 
131  QVariant value() const override { return value_; }
132 
138  bool isLeaf() const override { return true; }
139 
140  void dump( int tabs = 0 ) const override;
141 
142  bool readXML( QDomNode & keyNode ) override;
143 
144  bool writeXML( const QString & nodeName,
145  QDomElement & element,
146  QDomDocument & document ) override;
147 
148  int count() const { return 0; }
149 
153  void entryList( QStringList & keyName, QStringList & entries ) const
154  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
155 
156  private:
157 
161  QVariant value_;
162 
163 }; // class QgsPropertyValue
164 
165 
166 
167 
184 class CORE_EXPORT QgsPropertyKey : public QgsProperty
185 {
186  public:
187  QgsPropertyKey( const QString &name = "" );
188  virtual ~QgsPropertyKey();
189 
191  // @{
192  // @note not available in python bindings
193  QString name() const { return mName; }
194 
195  QString &name() { return mName; }
196  // @}
197 
198 
202  QVariant value() const override;
203 
204 
206  QgsPropertyKey *addKey( const QString & keyName )
207  {
208  delete mProperties.take( keyName );
209  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
210 
211  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
212  }
213 
214 
216  void removeKey( const QString & keyName )
217  {
218  delete mProperties.take( keyName );
219  }
220 
226  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
227  {
228  delete mProperties.take( name );
229  mProperties.insert( name, new QgsPropertyValue( value ) );
230 
231  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
232  }
233 
239  QgsPropertyValue * setValue( const QVariant & value )
240  {
241  return setValue( name(), value );
242  }
243 
244 
245  void dump( int tabs = 0 ) const override;
246 
247  bool readXML( QDomNode & keyNode ) override;
248 
249  bool writeXML( const QString &nodeName, QDomElement & element, QDomDocument & document ) override;
250 
252  int count() const { return mProperties.count(); }
253 
255  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
256 
258  virtual bool isKey() const override { return true; }
259 
261  virtual bool isValue() const override { return false; }
262 
264  void entryList( QStringList & entries ) const;
265 
267  void subkeyList( QStringList & entries ) const;
268 
273  bool isLeaf() const override;
274 
276  virtual void clear()
277  {
278  mName = "";
279  clearKeys();
280  }
281 
283  virtual void clearKeys()
284  {
285  qDeleteAll( mProperties );
286  mProperties.clear();
287  }
288 
289  QgsProperty * find( QString & propertyName )
290  {
291  return mProperties.value( propertyName );
292  }
293 
294  private:
295 
297  QString mName;
298 
301 
302 }; // class QgsPropertyKey
303 
304 #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.
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?
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.
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
QString name() const
every key has a name
bool isEmpty() const
Does this property not have any subkeys or values?