1
/***************************************************************************
4
Implements persistent project state.
7
begin : February 24, 2005
8
copyright : (C) 2005 by Mark Coletti
9
email : mcoletti at gmail.com
10
***************************************************************************/
12
/***************************************************************************
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. *
19
***************************************************************************/
21
/* $Id: qgsprojectproperty.h 4502 2006-01-08 01:18:20Z timlinux $ */
23
#ifndef QGSPROJECTPROPERTY_H
24
#define QGSPROJECTPROPERTY_H
37
ABC for property hierarchies
39
Each sub-class is either a QgsPropertyKey or QgsPropertyValue. QgsPropertyKeys can
40
contain either QgsPropertyKeys or QgsPropertyValues, thus describing an
41
hierarchy. QgsPropertyValues are always graph leaves.
45
This is really a hidden QgsProject implementation class. It was getting
46
too large and unwieldy, so it's broken out here into separate files.
56
virtual ~ QgsProperty()
59
/** dumps out the keys and values
61
@param tabs is number of tabs to print; used for pretty-printing
64
virtual void dump( size_t tabs = 0 ) const = 0;
66
/** returns true if is a QgsPropertyKey */
67
virtual bool isKey() const = 0;
69
/** returns true if is a QgsPropertyValue */
70
virtual bool isValue() const = 0;
72
/** returns true if a leaf node
74
A leaf node is a key node that has either no value or a single value.
75
A non-leaf node would be a key node with key sub-nodes.
77
This is used for entryList() and subkeyList() implementation.
79
virtual bool isLeaf() const = 0;
82
restores property hierarchy to given DOM node
84
Used for restoring properties from project file
86
virtual bool readXML(QDomNode & keyNode) = 0;
89
adds property hierarchy to given DOM node
91
Used for saving properties to project file.
93
@param nodeName the tag name associated with this element
94
@param node the parent (or encompassing) property node
95
@param documetn the overall project file DOM document
97
virtual bool writeXML(QString const & nodeName,
98
QDomElement & element,
99
QDomDocument & document) = 0;
101
/** return the node's value
103
For QgsPropertyValue nodes, this is straightforward -- just return the
104
embedded QVariant, _value. For QgsPropertyKey, this means returning
105
the QgsPropertyValue _value that is keyed by its name, if it exists;
106
i.e., QgsPropertyKey "foo" will return the property value mapped to its
107
name, "foo", in its QDict of QProperties.
110
virtual QVariant value() const = 0;
112
}; // class QgsProperty
117
/** QgsPropertyValue node
119
Contains a QgsPropertyKey's value
121
class QgsPropertyValue : public QgsProperty
127
QgsPropertyValue(QVariant const &value)
131
virtual ~ QgsPropertyValue()
134
/** returns true if is a QgsPropertyKey */
135
virtual bool isKey() const
138
/** returns true if is a QgsPropertyValue */
139
virtual bool isValue() const
142
QVariant value() const
145
/** returns true if is a leaf node
147
@note I suppose, in a way, value nodes can also be qualified as leaf
148
nodes even though we're only counting key nodes.
153
void dump( size_t tabs = 0) const;
155
bool readXML(QDomNode & keyNode);
157
bool writeXML( QString const & nodeName,
158
QDomElement & element,
159
QDomDocument & document );
165
/** return keys that do not contain other keys
167
Since QgsPropertyValue isn't a key, don't do anything.
169
void entryList( QStringList & keyName, QStringList & entries ) const
174
/** We use QVariant as it's very handy to keep multiple types and provides
179
}; // class QgsPropertyValue
187
Can, itself, contain QgsPropertyKeys and QgsPropertyValues.
189
The internal QDict, properties_, maps key names to their respective
190
QgsPropertyValue or next QgsPropertyKey in the key name sequence. The key with
191
the current name should contain its QgsPropertyValue.
193
E.g., given the key sequence "/foo/bar", "foo" will have a corresponding
194
QgsPropertyKey with a name "foo". It will contain an element in its
195
properties_ that maps to "bar", which is another QgsPropertyKey. The "bar"
196
QgsPropertyKey will, in turn, have an element that maps to itself, i.e. "bar",
197
that will contain a QgsPropertyValue.
200
class QgsPropertyKey : public QgsProperty
204
QgsPropertyKey( QString const name = "" );
206
virtual ~ QgsPropertyKey()
209
/// every key has a name
211
QString const & name() const
219
/** if this key has a value, it will be stored by its name in its
222
QVariant value() const;
225
/// add the given property key
226
QgsPropertyKey * addKey( QString const & keyName )
228
properties_.replace( keyName, new QgsPropertyKey(keyName) );
230
return dynamic_cast<QgsPropertyKey*>(properties_.find( keyName ));
234
/// remove the given key
235
bool removeKey( QString const & keyName )
237
return properties_.remove( keyName );
240
/** set the value associated with this key
241
@param name is the key name
243
QgsPropertyValue * setValue( QString const & name, QVariant const & value )
245
properties_.replace( name, new QgsPropertyValue( value ) );
247
return dynamic_cast<QgsPropertyValue*>(properties_.find( name ));
250
/** set the value associated with this key
252
@note that the single value node associated with each key is always
253
stored keyed by the current key name
255
QgsPropertyValue * setValue( QVariant const & value )
257
return setValue( name(), value );
262
void dump( size_t tabs = 0 ) const;
264
bool readXML(QDomNode & keyNode);
266
bool writeXML(QString const &nodeName, QDomElement & element, QDomDocument & document);
268
/// how many elements are contained within this one?
270
{ return properties_.count(); }
272
/// Does this property not have any subkeys or values?
273
/* virtual */ bool isEmpty() const
274
{ return properties_.isEmpty(); }
276
/** returns true if is a QgsPropertyKey */
277
virtual bool isKey() const
280
/** returns true if is a QgsPropertyValue */
281
virtual bool isValue() const
284
/// return keys that do not contain other keys
285
void entryList( QStringList & entries ) const;
287
/// return keys that contain other keys
288
void subkeyList(QStringList & entries) const;
290
/** returns true if a leaf node
292
A leaf node is a key node that has either no value or a single value. A
293
non-leaf node would be a key node with key sub-nodes.
297
/// reset the QgsProperty key to prestine state
304
/// delete any sub-nodes
305
virtual void clearKeys()
310
QgsProperty * find( QString & propertyName )
312
return properties_.find( propertyName );
317
/// every key has a name
321
Q3Dict < QgsProperty > properties_;
323
}; // class QgsPropertyKey