diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-08-27 05:51:46 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-08-27 05:51:46 (GMT) |
commit | 09c662b1c3440d7ff0b151d1fd10fc19ef75725f (patch) | |
tree | dd7d64120aaa4d0ca0caba7bd76e5c4eacabd80c /tests/auto/declarative/qmlengine | |
parent | 59511a43beb04cd4341b2f99c0385daef120c122 (diff) | |
download | Qt-09c662b1c3440d7ff0b151d1fd10fc19ef75725f.zip Qt-09c662b1c3440d7ff0b151d1fd10fc19ef75725f.tar.gz Qt-09c662b1c3440d7ff0b151d1fd10fc19ef75725f.tar.bz2 |
Start adding convenience functions for value types.
Allows you to write things like "geometry: Qt.rect(0,0,100,100)" and
"color: Qt.hsla(.7,.5,.2)"
Diffstat (limited to 'tests/auto/declarative/qmlengine')
-rw-r--r-- | tests/auto/declarative/qmlengine/functions.qml | 6 | ||||
-rw-r--r-- | tests/auto/declarative/qmlengine/tst_qmlengine.cpp | 87 |
2 files changed, 77 insertions, 16 deletions
diff --git a/tests/auto/declarative/qmlengine/functions.qml b/tests/auto/declarative/qmlengine/functions.qml new file mode 100644 index 0000000..28e8ed4 --- /dev/null +++ b/tests/auto/declarative/qmlengine/functions.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyTypeObject { + rectProperty: Qt.rect(0,0,100,100) + rectFProperty: Qt.rect(0,0.5,100,99.5) +} diff --git a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp index 9a04c61..8c050cb 100644 --- a/tests/auto/declarative/qmlengine/tst_qmlengine.cpp +++ b/tests/auto/declarative/qmlengine/tst_qmlengine.cpp @@ -1,4 +1,6 @@ #include <qtest.h> +#include <QtDeclarative/qml.h> +#include <QtDeclarative/QmlComponent> #include <QtDeclarative/QmlEngine> #include <QtCore/QDebug> @@ -12,30 +14,83 @@ public: tst_qmlengine() {} private slots: - void componentSearchPath(); -}; + void valueTypeFunctions(); +private: + QmlEngine engine; +}; -void tst_qmlengine::componentSearchPath() +class MyTypeObject : public QObject { - QFile file(SRCDIR "/imports.qml"); - QVERIFY(file.open(QIODevice::ReadOnly)); + Q_OBJECT + Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty); + Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty); + Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty); + Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty); + Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged); + Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty); + +public: + MyTypeObject() {} - QmlEngine engine; + QPoint pointPropertyValue; + QPoint pointProperty() const { + return pointPropertyValue; + } + void setPointProperty(const QPoint &v) { + pointPropertyValue = v; + } - QList<QUrl> searchPath = engine.componentSearchPath(file.readAll(), - QUrl::fromLocalFile(file.fileName())); + QPointF pointFPropertyValue; + QPointF pointFProperty() const { + return pointFPropertyValue; + } + void setPointFProperty(const QPointF &v) { + pointFPropertyValue = v; + } - QList<QUrl> expected; - expected << QUrl::fromLocalFile(SRCDIR); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import1")); - expected << QUrl::fromLocalFile(file.fileName()).resolved(QUrl("import2")); + QSize sizePropertyValue; + QSize sizeProperty() const { + return sizePropertyValue; + } + void setSizeProperty(const QSize &v) { + sizePropertyValue = v; + } - QCOMPARE(searchPath.size(), expected.size()); - for (int i = 0; i < expected.size(); ++i) { - QCOMPARE(searchPath.at(i).toString(QUrl::StripTrailingSlash), - expected.at(i).toString(QUrl::StripTrailingSlash)); + QSizeF sizeFPropertyValue; + QSizeF sizeFProperty() const { + return sizeFPropertyValue; } + void setSizeFProperty(const QSizeF &v) { + sizeFPropertyValue = v; + } + + QRect rectPropertyValue; + QRect rectProperty() const { + return rectPropertyValue; + } + void setRectProperty(const QRect &v) { + rectPropertyValue = v; + } + + QRectF rectFPropertyValue; + QRectF rectFProperty() const { + return rectFPropertyValue; + } + void setRectFProperty(const QRectF &v) { + rectFPropertyValue = v; + } + +}; +QML_DECLARE_TYPE(MyTypeObject); +QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject); + +void tst_qmlengine::valueTypeFunctions() +{ + QmlComponent component(&engine, SRCDIR "/functions.qml"); + MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create()); + QCOMPARE(obj->rectProperty(), QRect(0,0,100,100)); + QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5)); } QTEST_MAIN(tst_qmlengine) |