Handle conversion and comparison between qvarianthash and qvariantmap
QVariant claims to be able to QVariantHash and QVariantMap, but the actual conversion implementation is missing. Task-number: QTBUG-61471 Change-Id: I0cba74642aa77dc423effed289bc7619922a89eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
b783c03d19
commit
b3f7bea105
@ -855,6 +855,12 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
||||
if (qstrcmp(QMetaType::typeName(d->type), "QMap<QString, QVariant>") == 0) {
|
||||
*static_cast<QVariantMap *>(result) =
|
||||
*static_cast<QMap<QString, QVariant> *>(d->data.shared->ptr);
|
||||
} else if (d->type == QVariant::Hash) {
|
||||
QVariantMap *map = static_cast<QVariantMap *>(result);
|
||||
const QVariantHash *hash = v_cast<QVariantHash>(d);
|
||||
const auto end = hash->end();
|
||||
for (auto it = hash->begin(); it != end; ++it)
|
||||
map->insertMulti(it.key(), it.value());
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
} else if (d->type == QMetaType::QJsonValue) {
|
||||
if (!v_cast<QJsonValue>(d)->isObject())
|
||||
@ -871,6 +877,12 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
|
||||
if (qstrcmp(QMetaType::typeName(d->type), "QHash<QString, QVariant>") == 0) {
|
||||
*static_cast<QVariantHash *>(result) =
|
||||
*static_cast<QHash<QString, QVariant> *>(d->data.shared->ptr);
|
||||
} else if (d->type == QVariant::Map) {
|
||||
QVariantHash *hash = static_cast<QVariantHash *>(result);
|
||||
const QVariantMap *map = v_cast<QVariantMap>(d);
|
||||
const auto end = map->end();
|
||||
for (auto it = map->begin(); it != end; ++it)
|
||||
hash->insertMulti(it.key(), it.value());
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
} else if (d->type == QMetaType::QJsonValue) {
|
||||
if (!v_cast<QJsonValue>(d)->isObject())
|
||||
|
@ -2558,6 +2558,8 @@ void tst_QVariant::variantMap()
|
||||
QVariant v3 = QVariant(QMetaType::type("QMap<QString, QVariant>"), &map);
|
||||
QCOMPARE(qvariant_cast<QVariantMap>(v3).value("test").toInt(), 42);
|
||||
|
||||
QCOMPARE(v, QVariant(v.toHash()));
|
||||
|
||||
// multi-keys
|
||||
map.insertMulti("test", 47);
|
||||
v = map;
|
||||
@ -2565,6 +2567,8 @@ void tst_QVariant::variantMap()
|
||||
QCOMPARE(map2, map);
|
||||
map2 = v.toMap();
|
||||
QCOMPARE(map2, map);
|
||||
|
||||
QCOMPARE(v, QVariant(v.toHash()));
|
||||
}
|
||||
|
||||
void tst_QVariant::variantHash()
|
||||
@ -2587,6 +2591,8 @@ void tst_QVariant::variantHash()
|
||||
QVariant v3 = QVariant(QMetaType::type("QHash<QString, QVariant>"), &hash);
|
||||
QCOMPARE(qvariant_cast<QVariantHash>(v3).value("test").toInt(), 42);
|
||||
|
||||
QCOMPARE(v, QVariant(v.toMap()));
|
||||
|
||||
// multi-keys
|
||||
hash.insertMulti("test", 47);
|
||||
v = hash;
|
||||
@ -2594,6 +2600,8 @@ void tst_QVariant::variantHash()
|
||||
QCOMPARE(hash2, hash);
|
||||
hash2 = v.toHash();
|
||||
QCOMPARE(hash2, hash);
|
||||
|
||||
QCOMPARE(v, QVariant(v.toMap()));
|
||||
}
|
||||
|
||||
class CustomQObject : public QObject {
|
||||
|
Loading…
Reference in New Issue
Block a user