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 if ( propElement.hasAttribute(
"value" ) )
93 QString
value = propElement.attribute(
"value" );
94 mMap[key] = QVariant( value );
100 for ( QDomElement itemElement = propElement.firstChildElement(
"value" );
101 !itemElement.isNull();
102 itemElement = itemElement.nextSiblingElement(
"value" ) )
104 list << itemElement.text();
107 mMap[key] = QVariant( list );
117 QDomNodeList propertyList = parentNode.toElement().elementsByTagName(
"customproperties" );
118 for (
int i = 0; i < propertyList.size(); ++i )
120 parentNode.removeChild( propertyList.at( i ) );
123 QDomElement propsElement = doc.createElement(
"customproperties" );
125 for ( QMap<QString, QVariant>::const_iterator it =
mMap.constBegin(); it !=
mMap.constEnd(); ++it )
127 QDomElement propElement = doc.createElement(
"property" );
128 propElement.setAttribute(
"key", it.key() );
129 if ( it.value().canConvert<QString>() )
131 propElement.setAttribute(
"value", it.value().toString() );
133 else if ( it.value().canConvert<QStringList>() )
135 foreach ( QString
value, it.value().toStringList() )
137 QDomElement itemElement = doc.createElement(
"value" );
138 itemElement.appendChild( doc.createTextNode( value ) );
139 propElement.appendChild( itemElement );
142 propsElement.appendChild( propElement );
145 parentNode.appendChild( propsElement );