23 #include <QStringList>
38 return mMap.value( key, defaultValue );
48 return mMap.contains( key );
53 const QDomNode propsNode = parentNode.namedItem( QStringLiteral(
"customproperties" ) );
54 if ( propsNode.isNull() )
57 if ( !keyStartsWith.isEmpty() )
60 QStringList keysToRemove;
61 QMap<QString, QVariant>::const_iterator pIt =
mMap.constBegin();
62 for ( ; pIt !=
mMap.constEnd(); ++pIt )
64 if ( pIt.key().startsWith( keyStartsWith ) )
66 keysToRemove.push_back( pIt.key() );
70 QStringList::const_iterator sIt = keysToRemove.constBegin();
71 for ( ; sIt != keysToRemove.constEnd(); ++sIt )
82 if ( newProps.type() == QVariant::Map )
84 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
85 const QVariantMap propsMap = newProps.toMap();
86 for (
auto it = propsMap.constBegin(); it != propsMap.constEnd(); ++it )
87 mMap.insert( it.key(), it.value() );
89 mMap.insert( newProps.toMap() );
95 const QDomNodeList nodes = propsNode.childNodes();
97 for (
int i = 0; i < nodes.size(); i++ )
99 const QDomNode propNode = nodes.at( i );
100 if ( propNode.isNull() || propNode.nodeName() != QLatin1String(
"property" ) )
102 const QDomElement propElement = propNode.toElement();
104 const QString key = propElement.attribute( QStringLiteral(
"key" ) );
105 if ( key.isEmpty() || key.startsWith( keyStartsWith ) )
107 if ( propElement.hasAttribute( QStringLiteral(
"value" ) ) )
109 const QString
value = propElement.attribute( QStringLiteral(
"value" ) );
116 for ( QDomElement itemElement = propElement.firstChildElement( QStringLiteral(
"value" ) );
117 !itemElement.isNull();
118 itemElement = itemElement.nextSiblingElement( QStringLiteral(
"value" ) ) )
120 list << itemElement.text();
123 mMap[key] = QVariant( list );
133 const QDomNodeList propertyList = parentNode.toElement().elementsByTagName( QStringLiteral(
"customproperties" ) );
134 for (
int i = 0; i < propertyList.size(); ++i )
136 parentNode.removeChild( propertyList.at( i ) );
139 QDomElement propsElement = doc.createElement( QStringLiteral(
"customproperties" ) );
141 parentNode.appendChild( propsElement );
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
QMap< QString, QVariant > mMap
QStringList keys() const
Returns a list of all stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void remove(const QString &key)
Removes a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.