21 #include <QStringList>
40 return mMap.value( key, defaultValue );
51 QDomNode propsNode = parentNode.namedItem(
"customproperties" );
52 if ( propsNode.isNull() )
55 if ( !keyStartsWith.isEmpty() )
58 QStringList keysToRemove;
59 QMap<QString, QVariant>::const_iterator pIt =
mMap.constBegin();
60 for ( ; pIt !=
mMap.constEnd(); ++pIt )
62 if ( pIt.key().startsWith( keyStartsWith ) )
64 keysToRemove.push_back( pIt.key() );
68 QStringList::const_iterator sIt = keysToRemove.constBegin();
69 for ( ; sIt != keysToRemove.constEnd(); ++sIt )
79 QDomNodeList nodes = propsNode.childNodes();
81 for (
int i = 0; i < nodes.size(); i++ )
83 QDomNode propNode = nodes.at( i );
84 if ( propNode.isNull() || propNode.nodeName() !=
"property" )
86 QDomElement propElement = propNode.toElement();
88 QString key = propElement.attribute(
"key" );
89 if ( key.isEmpty() || key.startsWith( keyStartsWith ) )
91 QString
value = propElement.attribute(
"value" );
92 mMap[key] = QVariant( value );
101 QDomNodeList propertyList = parentNode.toElement().elementsByTagName(
"customproperties" );
102 for (
int i = 0; i < propertyList.size(); ++i )
104 parentNode.removeChild( propertyList.at( i ) );
107 QDomElement propsElement = doc.createElement(
"customproperties" );
109 for ( QMap<QString, QVariant>::const_iterator it =
mMap.constBegin(); it !=
mMap.constEnd(); ++it )
111 QDomElement propElement = doc.createElement(
"property" );
112 propElement.setAttribute(
"key", it.key() );
113 propElement.setAttribute(
"value", it.value().toString() );
114 propsElement.appendChild( propElement );
117 parentNode.appendChild( propsElement );
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from XML.
void remove(const QString &key)
Remove a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Return value for the given key. If the key is not stored, default value will be used.
QMap< QString, QVariant > mMap
void setValue(const QString &key, const QVariant &value)
Add an entry to the store. If the entry with the keys exists already, it will be overwritten.
QStringList keys() const
Return list of stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Write store contents to XML.
QgsObjectCustomProperties()