QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
115 class CORE_EXPORT QgsPropertyValue : public QgsProperty
116 {
117  public:
119 
120  QgsPropertyValue( const QVariant &value )
121  : value_( value )
122  {}
123 
124  virtual ~QgsPropertyValue();
125 
127  virtual bool isKey() const override { return false; }
128 
130  virtual bool isValue() const override { return true; }
131 
132  QVariant value() const override { return value_; }
133 
139  bool isLeaf() const override { return true; }
140 
141  void dump( int tabs = 0 ) const override;
142 
143  bool readXML( QDomNode & keyNode ) override;
144 
145  bool writeXML( const QString & nodeName,
146  QDomElement & element,
147  QDomDocument & document ) override;
148 
149  int count() const { return 0; }
150 
154  void entryList( QStringList & keyName, QStringList & entries ) const
155  { Q_UNUSED( keyName ); Q_UNUSED( entries ); /* NOP */ }
156 
157  private:
158 
162  QVariant value_;
163 
164 }; // class QgsPropertyValue
165 
166 
167 
168 
185 class CORE_EXPORT QgsPropertyKey : public QgsProperty
186 {
187  public:
188  QgsPropertyKey( const QString &name = "" );
189  virtual ~QgsPropertyKey();
190 
192  // @{
193  // @note not available in python bindings
194  QString name() const { return mName; }
195 
196  QString &name() { return mName; }
197  // @}
198 
199 
203  QVariant value() const override;
204 
205 
207  QgsPropertyKey *addKey( const QString & keyName )
208  {
209  delete mProperties.take( keyName );
210  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
211 
212  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
213  }
214 
215 
217  void removeKey( const QString & keyName )
218  {
219  delete mProperties.take( keyName );
220  }
221 
227  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
228  {
229  delete mProperties.take( name );
230  mProperties.insert( name, new QgsPropertyValue( value ) );
231 
232  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
233  }
234 
240  QgsPropertyValue * setValue( const QVariant & value )
241  {
242  return setValue( name(), value );
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?