refs #247 CVariant uses our new metadata system to provide access to CValueObject operations in a safe manner.

This commit is contained in:
Mathew Sutcliffe
2014-11-13 22:29:15 +00:00
parent f52cdd596e
commit f68fc32f3d
3 changed files with 121 additions and 42 deletions

View File

@@ -337,27 +337,25 @@ QVariant BlackMisc::fixQVariantFromDbusArgument(const QVariant &variant, int loc
// complex, user type
// it has to be made sure, that the cast works
const QDBusArgument arg = variant.value<QDBusArgument>();
QVariant fixedVariant;
if (localUserType < static_cast<int>(QVariant::UserType))
{
// complex Qt type, e.g. QDateTime
fixedVariant = BlackMisc::complexQtTypeFromDbusArgument(arg, localUserType);
return BlackMisc::complexQtTypeFromDbusArgument(arg, localUserType);
}
else
{
// http://qt-project.org/doc/qt-5.0/qtcore/qmetatype.html#create
void *obByMetaId = QMetaType::create(localUserType);
// own types, send as QDBusArgument
CValueObject *streamable = static_cast<CValueObject *>(obByMetaId);
arg >> (*streamable);
fixedVariant = streamable->toQVariant();
QMetaType::destroy(localUserType, obByMetaId);
QVariant valueVariant(localUserType, nullptr);
auto *meta = Private::getValueObjectMetaInfo(valueVariant);
if (meta)
{
meta->unmarshall(arg, valueVariant.data());
return valueVariant;
}
}
return fixedVariant;
}
else
{
qWarning() << "fixQVariantFromDbusArgument called with unsupported type";
return variant;
}
}