diff options
author | Jędrzej Nowacki <jedrzej.nowacki@qt.io> | 2018-09-24 15:05:13 +0200 |
---|---|---|
committer | Jędrzej Nowacki <jedrzej.nowacki@qt.io> | 2018-10-08 10:01:54 +0000 |
commit | 5f4b3fa3cade416b088fdc35f583c536269688d7 (patch) | |
tree | 0e3971e29e106d50922a42d8c321756547b5eeba /tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | |
parent | 55403f8825396b074f0785b400330033387ffdcc (diff) |
Add support for QSequentialIterable in QML
That means that now QML understand many sequential value types
and it is able to convert it to a JS array.
Fixes: QTBUG-60338
Change-Id: I46943b7c130296bb64c23008ce2e52a55d7f019d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 1ee4510e30..5cff44c3cc 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -90,6 +90,7 @@ private slots: void customValueTypeInQml(); void gadgetInheritance(); void gadgetTemplateInheritance(); + void sequences(); void toStringConversion(); void enumerableProperties(); void enumProperties(); @@ -1590,6 +1591,7 @@ struct BaseGadget Q_PROPERTY(int baseProperty READ baseProperty WRITE setBaseProperty) public: BaseGadget() : m_baseProperty(0) {} + BaseGadget(int initValue) : m_baseProperty(initValue) {} int baseProperty() const { return m_baseProperty; } void setBaseProperty(int value) { m_baseProperty = value; } @@ -1686,6 +1688,39 @@ void tst_qqmlvaluetypes::gadgetTemplateInheritance() QCOMPARE(value.property("baseProperty").toInt(), 42); } +void tst_qqmlvaluetypes::sequences() +{ + QJSEngine engine; + { + QList<BaseGadget> gadgetList{1, 4, 7, 8, 15}; + QJSValue value = engine.toScriptValue(gadgetList); + QCOMPARE(value.property("length").toInt(), gadgetList.length()); + for (int i = 0; i < gadgetList.length(); ++i) + QCOMPARE(value.property(i).property("baseProperty").toInt(), gadgetList.at(i).baseProperty()); + } + { + std::vector<BaseGadget> container{1, 4, 7, 8, 15}; + QJSValue value = engine.toScriptValue(container); + QCOMPARE(value.property("length").toInt(), int(container.size())); + for (size_t i = 0; i < container.size(); ++i) + QCOMPARE(value.property(i).property("baseProperty").toInt(), container.at(i).baseProperty()); + } + { + QVector<QChar> qcharVector{1, 4, 42, 8, 15}; + QJSValue value = engine.toScriptValue(qcharVector); + QCOMPARE(value.property("length").toInt(), qcharVector.length()); + for (int i = 0; i < qcharVector.length(); ++i) + QCOMPARE(value.property(i).toInt(), qcharVector.at(i)); + } + { + MyTypeObject a, b, c; + QSet<QObject*> objSet{&a, &b, &c}; + QJSValue value = engine.toScriptValue(objSet); + QCOMPARE(value.property("length").toInt(), objSet.size()); + for (int i = 0; i < objSet.size(); ++i) + QCOMPARE(value.property(i).property("point").property("x").toInt(), a.point().x()); + } +} struct StringLessGadget { Q_GADGET }; |