From 98aee81ccc17c0fe5d7e013fc40ca171dc2ebb43 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Thu, 6 Aug 2009 14:30:26 +0200 Subject: XQuery: allow usage of floats in QXmlQuery float is not a registered type in QVariant, but a QVariant can be constructed from it and then used in XQuery. Reviewed-by: Frans Englich --- src/xmlpatterns/data/qatomicvalue.cpp | 18 ++++++++++++------ tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/xmlpatterns/data/qatomicvalue.cpp b/src/xmlpatterns/data/qatomicvalue.cpp index d8186e5..3aca100 100644 --- a/src/xmlpatterns/data/qatomicvalue.cpp +++ b/src/xmlpatterns/data/qatomicvalue.cpp @@ -172,13 +172,19 @@ Item AtomicValue::toXDM(const QVariant &value) return Item(Double::fromValue(value.toDouble())); default: { - Q_ASSERT_X(false, - Q_FUNC_INFO, - qPrintable(QString::fromLatin1( - "QVariants of type %1 are not supported in " - "Patternist, see the documentation") + if (value.userType() == qMetaTypeId()) + { + return Item(Float::fromValue(value.value())); + } + else { + Q_ASSERT_X(false, + Q_FUNC_INFO, + qPrintable(QString::fromLatin1( + "QVariants of type %1 are not supported in " + "Patternist, see the documentation") .arg(QLatin1String(value.typeName())))); - return AtomicValue::Ptr(); + return AtomicValue::Ptr(); + } } } } diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index d9b5215..a2c40a8 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -1305,7 +1305,7 @@ void tst_QXmlQuery::basicQtToXQueryTypeCheck() const // TODO Do with different QDateTime time specs query.bindVariable(QLatin1String("fromQDateTime"), QXmlItem(QDateTime(QDate(2001, 9, 10), QTime(1, 2, 3)))); query.bindVariable(QLatin1String("fromDouble"), QXmlItem(double(3))); -// query.bindVariable(QLatin1String("fromFloat"), QXmlItem(float(4))); + query.bindVariable(QLatin1String("fromFloat"), QXmlItem(float(4))); query.bindVariable(QLatin1String("integer"), QXmlItem(5)); query.bindVariable(QLatin1String("fromQString"), QXmlItem(QString::fromLatin1("A QString"))); query.bindVariable(QLatin1String("fromQChar"), QXmlItem(QChar::fromLatin1('C'))); -- cgit v0.12