QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
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 "qgis_core.h"
26
27#include <QCoreApplication>
28#include <QHash>
29#include <QStringList>
30#include <QVariant>
31
32class QDomNode;
33class QDomElement;
34class QDomDocument;
35
36
49class CORE_EXPORT QgsProjectProperty
50{
51 public:
53 virtual ~QgsProjectProperty() = default;
54
60 virtual void dump( int tabs = 0 ) const = 0;
61
67 virtual bool isKey() const = 0;
68
74 virtual bool isValue() const = 0;
75
84 virtual bool isLeaf() const = 0;
85
91 virtual bool readXml( const QDomNode &keyNode ) = 0;
92
102 virtual bool writeXml( const QString &nodeName, QDomElement &element, QDomDocument &document ) = 0;
103
114 virtual QVariant value() const = 0;
115};
116
117
124{
125 public:
127
132 : mValue( value )
133 {}
134
135 bool isKey() const override { return false; }
136 bool isValue() const override { return true; }
137 QVariant value() const override { return mValue; }
138
139 //value nodes can also be qualified as leaf nodes even though we only count key nodes.
140 bool isLeaf() const override { return true; }
141
142 void dump( int tabs = 0 ) const override;
143 bool readXml( const QDomNode &keyNode ) override;
144 bool writeXml( const QString &nodeName, QDomElement &element, QDomDocument &document ) override;
145
146 private:
147 // We use QVariant as it's very handy to keep multiple types and provides type conversions
148 QVariant mValue;
149};
150
151
172{
173 Q_DECLARE_TR_FUNCTIONS( QgsProjectPropertyKey )
174
175 public:
179 QgsProjectPropertyKey( const QString &name = QString() );
180 ~QgsProjectPropertyKey() override;
181
186 QString name() const { return mName; }
187
193 void setName( const QString &name );
194
199 QVariant value() const override;
200
204 QgsProjectPropertyKey *addKey( const QString &keyName )
205 {
206 if ( mProperties.contains( keyName ) )
207 delete mProperties.take( keyName );
208
210 mProperties.insert( keyName, p );
211
212 return p;
213 }
214
218 void removeKey( const QString &keyName ) { delete mProperties.take( keyName ); }
219
226 QgsProjectPropertyValue *setValue( const QString &name, const QVariant &value )
227 {
228 if ( mProperties.contains( name ) )
229 delete mProperties.take( name );
230
232 mProperties.insert( name, p );
233
234 return p;
235 }
236
243 QgsProjectPropertyValue *setValue( const QVariant &value ) { return setValue( name(), value ); }
244
245 void dump( int tabs = 0 ) const override;
246 bool readXml( const QDomNode &keyNode ) override;
247 bool writeXml( const QString &nodeName, QDomElement &element, QDomDocument &document ) override;
248
252 int count() const { return mProperties.count(); }
253
257 bool isEmpty() const { return mProperties.isEmpty(); }
258
259 bool isKey() const override { return true; }
260 bool isValue() const override { return false; }
261 bool isLeaf() const override;
262
267 void entryList( QStringList &entries ) const;
268
273 void subkeyList( QStringList &entries ) const;
274
278 virtual void clear()
279 {
280 mName.clear();
281 clearKeys();
282 }
283
287 virtual void clearKeys()
288 {
289 qDeleteAll( mProperties );
290 mProperties.clear();
291 }
292
296 QgsProjectProperty *find( const QString &propertyName ) const { return mProperties.value( propertyName ); }
297
298 private:
300 QString mName;
301
303 QHash< QString, QgsProjectProperty * > mProperties;
304};
305
306#endif
QString name() const
The name of the property is used as identifier.
QgsProjectPropertyKey(const QString &name=QString())
Create a new QgsProjectPropertyKey with the specified identifier.
QgsProjectProperty * find(const QString &propertyName) const
Attempts to find a property with a matching sub-key name.
void removeKey(const QString &keyName)
Removes the specified key.
bool isEmpty() const
Returns true if this property contains no sub-keys.
bool isKey() const override
Returns true if the property is a QgsProjectPropertyKey.
virtual void clearKeys()
Deletes any sub-nodes from the property.
virtual void clear()
Resets the property to a default, empty state.
QgsProjectPropertyKey * addKey(const QString &keyName)
Adds the specified property key as a sub-key.
bool isValue() const override
Returns true if the property is a QgsProjectPropertyValue.
QVariant value() const override
If this key has a value, it will be stored by its name in its properties.
QgsProjectPropertyValue * setValue(const QString &name, const QVariant &value)
Sets the value associated with this key.
int count() const
Returns the number of sub-keys contained by this property.
QgsProjectPropertyValue * setValue(const QVariant &value)
Set the value associated with this key.
Project property value node, contains a QgsProjectPropertyKey's value.
QgsProjectPropertyValue()=default
QVariant value() const override
Returns the node's value.
bool isValue() const override
Returns true if the property is a QgsProjectPropertyValue.
QgsProjectPropertyValue(const QVariant &value)
Constructor for QgsProjectPropertyValue, initialized to a specified value.
bool isKey() const override
Returns true if the property is a QgsProjectPropertyKey.
bool isLeaf() const override
Returns true if property is a leaf node.
virtual bool isLeaf() const =0
Returns true if property is a leaf node.
virtual void dump(int tabs=0) const =0
Dumps out the keys and values.
virtual bool readXml(const QDomNode &keyNode)=0
Restores the property hierarchy from a specified DOM node.
virtual bool isKey() const =0
Returns true if the property is a QgsProjectPropertyKey.
virtual bool writeXml(const QString &nodeName, QDomElement &element, QDomDocument &document)=0
Writes the property hierarchy to a specified DOM element.
virtual QVariant value() const =0
Returns the node's value.
virtual bool isValue() const =0
Returns true if the property is a QgsProjectPropertyValue.
virtual ~QgsProjectProperty()=default