Utils: Introduce variantFromStore and storeFromVariant

These are functional replacements for
  QVariant::fromValue(QVariantMap) (or QVariant::fromValue(Store)) and
  QVariant::toMap() (or QVariant::toValue<Store>())

We will have a few code paths in the end that need to explicitly
operarate on both QVariantMap and Store (e.g. actual reading/writing
to keep format compatibility etc), so these can't in the end be
simple to/fromValue(OneType) but need an internal 'if' or such.

Change-Id: I954f3cb24fa8fe123162b72bbd25d891dd19b768
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-28 10:55:31 +02:00
parent bb59dfd636
commit 23149b27ab
39 changed files with 149 additions and 136 deletions

View File

@@ -135,7 +135,7 @@ QVariant ParseValueStackEntry::value() const
case QVariant::Invalid:
return QVariant();
case QVariant::Map:
return QVariant::fromValue(mapValue);
return variantFromStore(mapValue);
case QVariant::List:
return QVariant(listValue);
default:
@@ -378,7 +378,7 @@ static void writeVariantValue(QXmlStreamWriter &w, const Context &ctx,
w.writeAttribute(ctx.typeAttribute, QLatin1String(QVariant::typeToName(QVariant::Map)));
if (!key.isEmpty())
w.writeAttribute(ctx.keyAttribute, key);
const Store varMap = variant.value<Store>();
const Store varMap = storeFromVariant(variant);
const Store::const_iterator cend = varMap.constEnd();
for (Store::const_iterator i = varMap.constBegin(); i != cend; ++i)
writeVariantValue(w, ctx, i.value(), i.key());