Utils: Key/Store fix for Qt < 6.5

Change-Id: Ibf11f01a9502ab7da052db7630b5df2fdeda09ab
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-25 15:11:45 +02:00
parent d9a8eba35d
commit 5839a09e72

View File

@@ -357,6 +357,12 @@ FilePath PersistentSettingsReader::filePath()
\sa Utils::PersistentSettingsReader
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
static QString xmlAttrFromKey(const Key &key) { return stringFromKey(key); }
#else
static Key xmlAttrFromKey(const Key &key) { return key; }
#endif
static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
const QVariant &variant, const Key &key = {})
{
@@ -367,7 +373,7 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
w.writeStartElement(ctx.valueListElement);
w.writeAttribute(ctx.typeAttribute, "QVariantList");
if (!key.isEmpty())
w.writeAttribute(ctx.keyAttribute, key);
w.writeAttribute(ctx.keyAttribute, xmlAttrFromKey(key));
const QList<QVariant> list = variant.toList();
for (const QVariant &var : list)
writeVariantValue(w, ctx, var);
@@ -376,7 +382,7 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
w.writeStartElement(ctx.valueMapElement);
w.writeAttribute(ctx.typeAttribute, "QVariantMap");
if (!key.isEmpty())
w.writeAttribute(ctx.keyAttribute, key);
w.writeAttribute(ctx.keyAttribute, xmlAttrFromKey(key));
const Store varMap = storeFromVariant(variant);
const Store::const_iterator cend = varMap.constEnd();
for (Store::const_iterator i = varMap.constBegin(); i != cend; ++i)
@@ -390,7 +396,7 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
w.writeStartElement(ctx.valueElement);
w.writeAttribute(ctx.typeAttribute, QLatin1String(variant.typeName()));
if (!key.isEmpty())
w.writeAttribute(ctx.keyAttribute, key);
w.writeAttribute(ctx.keyAttribute, xmlAttrFromKey(key));
switch (variant.type()) {
case QVariant::Rect:
w.writeCharacters(rectangleToString(variant.toRect()));