diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-18 15:50:17 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-18 15:50:17 +0200 |
commit | 36681ba81d33e3c1e66bef49450f4e7008154b61 (patch) | |
tree | a26d692fce762e44bd134dfad324f4deb0831d8e /libqmenumodel/src | |
parent | c42bc210a32f06b2850fbe010be9356d477330b0 (diff) | |
download | qmenumodel-36681ba81d33e3c1e66bef49450f4e7008154b61.tar.gz qmenumodel-36681ba81d33e3c1e66bef49450f4e7008154b61.tar.bz2 qmenumodel-36681ba81d33e3c1e66bef49450f4e7008154b61.zip |
Converter: use QMetaType to check integer subtypes
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r-- | libqmenumodel/src/converter.cpp | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 9fd65ed..9f89662 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -131,25 +131,6 @@ QVariant Converter::toQVariant(GVariant *value) return result; } -static GVariant* toGVariant(const QString &typeName, const QVariant &value) -{ - if (typeName == "uchar") { - return g_variant_new_byte(value.value<uchar>()); - } else if (typeName == "short") { - return g_variant_new_int16(value.value<short>()); - } else if (typeName == "ushort") { - return g_variant_new_uint16(value.value<ushort>()); - } else if (typeName == "long") { - return g_variant_new_int64(value.value<long>()); - } else if (typeName == "ulong") { - return g_variant_new_uint64(value.value<ulong>()); - } else { - qWarning() << "QVariant type not supported:" << typeName; - } - - return NULL; -} - QVariant Converter::toQVariantFromVariantString(const QString &variantString) { GVariant *gvariant; @@ -204,6 +185,21 @@ GVariant* Converter::toGVariant(const QVariant &value) case QVariant::ULongLong: result = g_variant_new_uint64(value.toULongLong()); break; + case QMetaType::UChar: + result = g_variant_new_byte(value.value<uchar>()); + break; + case QMetaType::Short: + result = g_variant_new_int16(value.value<short>()); + break; + case QMetaType::UShort: + result = g_variant_new_uint16(value.value<ushort>()); + break; + case QMetaType::Long: + result = g_variant_new_int64(value.value<long>()); + break; + case QMetaType::ULong: + result = g_variant_new_uint64(value.value<ulong>()); + break; case QVariant::Map: { GVariantBuilder *b; @@ -243,7 +239,7 @@ GVariant* Converter::toGVariant(const QVariant &value) break; } default: - result = ::toGVariant(value.typeName(), value); + qWarning() << "QVariant type not supported:" << value.type(); } return result; |