22 #include <QStringList>
37 return mMap.value( key, defaultValue );
47 return mMap.contains( key );
52 QDomNode propsNode = parentNode.namedItem( QStringLiteral(
"customproperties" ) );
53 if ( propsNode.isNull() )
56 if ( !keyStartsWith.isEmpty() )
59 QStringList keysToRemove;
60 QMap<QString, QVariant>::const_iterator pIt =
mMap.constBegin();
61 for ( ; pIt !=
mMap.constEnd(); ++pIt )
63 if ( pIt.key().startsWith( keyStartsWith ) )
65 keysToRemove.push_back( pIt.key() );
69 QStringList::const_iterator sIt = keysToRemove.constBegin();
70 for ( ; sIt != keysToRemove.constEnd(); ++sIt )
80 QDomNodeList nodes = propsNode.childNodes();
82 for (
int i = 0; i < nodes.size(); i++ )
84 QDomNode propNode = nodes.at( i );
85 if ( propNode.isNull() || propNode.nodeName() != QLatin1String(
"property" ) )
87 QDomElement propElement = propNode.toElement();
89 QString key = propElement.attribute( QStringLiteral(
"key" ) );
90 if ( key.isEmpty() || key.startsWith( keyStartsWith ) )
92 if ( propElement.hasAttribute( QStringLiteral(
"value" ) ) )
94 QString
value = propElement.attribute( QStringLiteral(
"value" ) );
101 for ( QDomElement itemElement = propElement.firstChildElement( QStringLiteral(
"value" ) );
102 !itemElement.isNull();
103 itemElement = itemElement.nextSiblingElement( QStringLiteral(
"value" ) ) )
105 list << itemElement.text();
108 mMap[key] = QVariant( list );
118 QDomNodeList propertyList = parentNode.toElement().elementsByTagName( QStringLiteral(
"customproperties" ) );
119 for (
int i = 0; i < propertyList.size(); ++i )
121 parentNode.removeChild( propertyList.at( i ) );
124 QDomElement propsElement = doc.createElement( QStringLiteral(
"customproperties" ) );
128 std::sort(
keys.begin(),
keys.end() );
130 for (
const auto &key : qgis::as_const(
keys ) )
132 QDomElement propElement = doc.createElement( QStringLiteral(
"property" ) );
133 propElement.setAttribute( QStringLiteral(
"key" ), key );
134 const QVariant
value =
mMap.value( key );
135 if (
value.canConvert<QString>() )
137 propElement.setAttribute( QStringLiteral(
"value" ),
value.toString() );
139 else if (
value.canConvert<QStringList>() )
141 const auto constToStringList =
value.toStringList();
142 for (
const QString &valueStr : constToStringList )
144 QDomElement itemElement = doc.createElement( QStringLiteral(
"value" ) );
145 itemElement.appendChild( doc.createTextNode( valueStr ) );
146 propElement.appendChild( itemElement );
149 propsElement.appendChild( propElement );
152 parentNode.appendChild( propsElement );