QGIS API Documentation  2.99.0-Master (c558d51)
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 
192  QgsPropertyKey( const QString& name = QString() );
193  virtual ~QgsPropertyKey();
194 
198  QString name() const { return mName; }
199 
205  void setName( const QString& name );
206 
211  QVariant value() const override;
212 
213 
215  QgsPropertyKey *addKey( const QString & keyName )
216  {
217  delete mProperties.take( keyName );
218  mProperties.insert( keyName, new QgsPropertyKey( keyName ) );
219 
220  return dynamic_cast<QgsPropertyKey*>( mProperties.value( keyName ) );
221  }
222 
223 
225  void removeKey( const QString & keyName )
226  {
227  delete mProperties.take( keyName );
228  }
229 
235  QgsPropertyValue * setValue( const QString & name, const QVariant & value )
236  {
237  delete mProperties.take( name );
238  mProperties.insert( name, new QgsPropertyValue( value ) );
239 
240  return dynamic_cast<QgsPropertyValue*>( mProperties.value( name ) );
241  }
242 
248  QgsPropertyValue * setValue( const QVariant & value )
249  {
250  return setValue( name(), value );
251  }
252 
253  void dump( int tabs = 0 ) const override;
254 
255  bool readXml( QDomNode & keyNode ) override;
256 
257  bool writeXml( const QString &nodeName, QDomElement & element, QDomDocument & document ) override;
258 
260  int count() const { return mProperties.count(); }
261 
263  /* virtual */ bool isEmpty() const { return mProperties.isEmpty(); }
264 
266  virtual bool isKey() const override { return true; }
267 
269  virtual bool isValue() const override { return false; }
270 
272  void entryList( QStringList & entries ) const;
273 
275  void subkeyList( QStringList & entries ) const;
276 
281  bool isLeaf() const override;
282 
284  virtual void clear()
285  {
286  mName = QLatin1String( "" );
287  clearKeys();
288  }
289 
291  virtual void clearKeys()
292  {
293  qDeleteAll( mProperties );
294  mProperties.clear();
295  }
296 
297  QgsProperty * find( QString & propertyName )
298  {
299  return mProperties.value( propertyName );
300  }
301 
302  private:
303 
305  QString mName;
306 
308  QHash < QString, QgsProperty* > mProperties;
309 
310 }; // class QgsPropertyKey
311 
312 #endif
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.
virtual bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document)=0
adds property hierarchy to given Dom element
QString name() const
The name of the property is used as identifier.
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.
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?
virtual bool readXml(QDomNode &keyNode)=0
restores property hierarchy to given Dom node