From e3da9407ad85a65abce72f8a32230ec4f2f95369 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Wed, 24 Nov 2010 13:50:27 +1000 Subject: Allow javascript date and regexp objects in WorkerScript messages Task-number: QTBUG-14666 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativeworkerscript.cpp | 13 +++++++++++++ .../tst_qdeclarativeworkerscript.cpp | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index be7ea0e..4b78020 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include "qdeclarativenetworkaccessmanagerfactory.h" @@ -314,6 +315,12 @@ QVariant QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(const QScri return QVariant(value.toString()); } else if (value.isNumber()) { return QVariant((qreal)value.toNumber()); + } else if (value.isDate()) { + return QVariant(value.toDateTime()); +#ifndef QT_NO_REGEXP + } else if (value.isRegExp()) { + return QVariant(value.toRegExp()); +#endif } else if (value.isArray()) { QVariantList list; @@ -364,6 +371,12 @@ QScriptValue QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(const Q return QScriptValue(value.toString()); } else if (value.userType() == QMetaType::QReal) { return QScriptValue(value.toReal()); + } else if (value.userType() == QVariant::DateTime) { + return engine->newDate(value.toDateTime()); +#ifndef QT_NO_REGEXP + } else if (value.userType() == QVariant::RegExp) { + return engine->newRegExp(value.toRegExp()); +#endif } else if (value.userType() == qMetaTypeId()) { QDeclarativeListModelWorkerAgent::VariantRef vr = qvariant_cast(value); if (vr.a->scriptEngine() == 0) diff --git a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp index 3140265..5a6cf3c 100644 --- a/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp +++ b/tests/auto/declarative/qdeclarativeworkerscript/tst_qdeclarativeworkerscript.cpp @@ -137,6 +137,11 @@ void tst_QDeclarativeWorkerScript::messaging_data() QTest::newRow("real") << qVariantFromValue(10334.375); QTest::newRow("string") << qVariantFromValue(QString("More cheeeese, Gromit!")); QTest::newRow("variant list") << qVariantFromValue((QVariantList() << "a" << "b" << "c")); + QTest::newRow("date time") << qVariantFromValue(QDateTime::currentDateTime()); +#ifndef QT_NO_REGEXP + // QtScript's QScriptValue -> QRegExp uses RegExp2 pattern syntax + QTest::newRow("regexp") << qVariantFromValue(QRegExp("^\\d\\d?$", Qt::CaseInsensitive, QRegExp::RegExp2)); +#endif } void tst_QDeclarativeWorkerScript::messaging_sendQObjectList() -- cgit v0.12