diff options
author | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-10-15 17:22:05 -0300 |
---|---|---|
committer | Renato Araujo Oliveira Filho <renato.filho@canonical.com> | 2012-10-15 17:22:05 -0300 |
commit | 7f0972362c6969fbf306945fc76f23b716400794 (patch) | |
tree | a029356e6893515af2f8dc187d7897202df0a888 /libqmenumodel/src | |
parent | 5999e7a42962140b6479995d77a178186b6b2fcc (diff) | |
download | qmenumodel-7f0972362c6969fbf306945fc76f23b716400794.tar.gz qmenumodel-7f0972362c6969fbf306945fc76f23b716400794.tar.bz2 qmenumodel-7f0972362c6969fbf306945fc76f23b716400794.zip |
Implemented conversion for QVariantMap;
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r-- | libqmenumodel/src/converter.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 452f68c..2451d79 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -38,6 +38,19 @@ QVariant Converter::toQVariant(GVariant *value) gsize size = 0; const gchar *v = g_variant_get_string(value, &size); result.setValue(QString::fromLatin1(v, size)); + } else if (g_variant_type_equal(type, G_VARIANT_TYPE_VARDICT)) { + GVariantIter iter; + GVariant *vvalue; + gchar *key; + QVariantMap qmap; + + g_variant_iter_init (&iter, value); + while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue)) + { + qmap.insert(QString::fromLatin1(key), toQVariant(vvalue)); + } + + result.setValue(qmap); } else { qWarning() << "Unsupported GVariant value"; } @@ -109,6 +122,21 @@ GVariant* Converter::toGVariant(const QVariant &value) case QVariant::UInt: result = g_variant_new_uint32(value.toUInt()); break; + case QVariant::Map: + { + GVariantBuilder *b; + GVariant *dict; + + b = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}")); + QMapIterator<QString, QVariant> i(value.toMap()); + while (i.hasNext()) { + i.next(); + g_variant_builder_add(b, "{sv}", reinterpret_cast<const char*>(i.key().toLatin1().data()), toGVariant(i.value())); + } + result = g_variant_builder_end(b); + g_variant_builder_unref(b); + break; + } default: result = ::toGVariant(value.typeName(), value); } |