summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlgraphicspathview
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-02-10 00:08:02 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-02-10 00:08:02 (GMT)
commit397595d93ca667f5ef9597974c405e339f538d4e (patch)
treef7c9ac166094b35a44cc5471bf93e6f018fcf798 /tests/auto/declarative/qmlgraphicspathview
parentb47306a53e7467ca5baf5bf49fa9da9229acd4c3 (diff)
downloadQt-397595d93ca667f5ef9597974c405e339f538d4e.zip
Qt-397595d93ca667f5ef9597974c405e339f538d4e.tar.gz
Qt-397595d93ca667f5ef9597974c405e339f538d4e.tar.bz2
Consolidate the two pathview tests and fix them all.
Diffstat (limited to 'tests/auto/declarative/qmlgraphicspathview')
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml2
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/data/pathview.qml66
-rw-r--r--tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp93
3 files changed, 155 insertions, 6 deletions
diff --git a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
index 9d08e5d..8d07db2 100644
--- a/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
+++ b/tests/auto/declarative/qmlgraphicspathview/data/datamodel.qml
@@ -8,7 +8,7 @@ PathView {
function checkProperties() {
testObject.error = false;
- if (testObject.useModel && view.model != itemModel) {
+ if (testObject.useModel && pathview.model != testData) {
console.log("model property incorrect");
testObject.error = true;
}
diff --git a/tests/auto/declarative/qmlgraphicspathview/data/pathview.qml b/tests/auto/declarative/qmlgraphicspathview/data/pathview.qml
new file mode 100644
index 0000000..8fa8d59
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicspathview/data/pathview.qml
@@ -0,0 +1,66 @@
+import Qt 4.6
+
+Rectangle {
+ width: 240
+ height: 320
+ color: "#ffffff"
+ resources: [
+ Component {
+ id: delegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ height: 20
+ width: 60
+ color: "white"
+ border.color: "black"
+ Text {
+ text: index
+ }
+ Text {
+ x: 20
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ x: 40
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+ }
+ }
+ ]
+ PathView {
+ id: view
+ objectName: "view"
+ width: 240
+ height: 320
+ model: testModel
+ delegate: delegate
+ snapPosition: 0.01
+ path: Path {
+ startY: 120
+ startX: 160
+ PathQuad {
+ y: 120
+ x: 80
+ controlY: 330
+ controlX: 100
+ }
+ PathLine {
+ y: 160
+ x: 20
+ }
+ PathCubic {
+ y: 120
+ x: 160
+ control1Y: 0
+ control1X: 100
+ control2Y: 000
+ control2X: 200
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
index e60ac5c..09b12b8 100644
--- a/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
+++ b/tests/auto/declarative/qmlgraphicspathview/tst_qmlgraphicspathview.cpp
@@ -47,6 +47,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qmlview.h>
#include <QtDeclarative/private/qmlgraphicstext_p.h>
+#include <QtDeclarative/private/qmlgraphicsrectangle_p.h>
#include <QAbstractListModel>
#include <QFile>
#include <private/qmlvaluetype_p.h>
@@ -60,10 +61,12 @@ public:
private slots:
void initValues();
+ void items();
void dataModel();
void pathview2();
void pathview3();
void path();
+ void pathMoved();
private:
QmlView *createView(const QString &filename);
@@ -186,6 +189,38 @@ void tst_QmlGraphicsPathView::initValues()
QCOMPARE(obj->pathItemCount(), -1);
}
+void tst_QmlGraphicsPathView::items()
+{
+ QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
+
+ TestModel model;
+ model.addItem("Fred", "12345");
+ model.addItem("John", "2345");
+ model.addItem("Bob", "54321");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
+ QVERIFY(pathview != 0);
+
+ QCOMPARE(pathview->childItems().count(), model.count()); // assumes all are visible
+
+ for (int i = 0; i < model.count(); ++i) {
+ QmlGraphicsText *name = findItem<QmlGraphicsText>(pathview, "textName", i);
+ QVERIFY(name != 0);
+ QCOMPARE(name->text(), model.name(i));
+ QmlGraphicsText *number = findItem<QmlGraphicsText>(pathview, "textNumber", i);
+ QVERIFY(number != 0);
+ QCOMPARE(number->text(), model.number(i));
+ }
+
+ delete canvas;
+}
+
void tst_QmlGraphicsPathView::pathview2()
{
QmlEngine engine;
@@ -323,6 +358,11 @@ void tst_QmlGraphicsPathView::dataModel()
itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count();
QCOMPARE(itemCount, 5);
+ QmlGraphicsRectangle *testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 4);
+ QVERIFY(testItem != 0);
+ testItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 5);
+ QVERIFY(testItem == 0);
+
model.insertItem(2, "pink", "2");
itemCount = findItems<QmlGraphicsItem>(pathview, "wrapper").count();
@@ -342,6 +382,49 @@ void tst_QmlGraphicsPathView::dataModel()
delete canvas;
}
+void tst_QmlGraphicsPathView::pathMoved()
+{
+ QmlView *canvas = createView(SRCDIR "/data/pathview.qml");
+
+ TestModel model;
+ model.addItem("Ben", "12345");
+ model.addItem("Bohn", "2345");
+ model.addItem("Bob", "54321");
+ model.addItem("Bill", "4321");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsPathView *pathview = findItem<QmlGraphicsPathView>(canvas->root(), "view");
+ QVERIFY(pathview != 0);
+
+ QmlGraphicsRectangle *firstItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", 0);
+ QVERIFY(firstItem);
+ QmlGraphicsPath *path = qobject_cast<QmlGraphicsPath*>(pathview->path());
+ QVERIFY(path);
+ QPointF start = path->pointAt(0.0);
+ QPointF offset;//Center of item is at point, but pos is from corner
+ offset.setX(firstItem->width()/2);
+ offset.setY(firstItem->height()/2);
+ QCOMPARE(firstItem->pos() + offset, start);
+ pathview->setOffset(10);
+ QTest::qWait(1000);//Moving is animated?
+
+ for(int i=0; i<model.count(); i++){
+ QmlGraphicsRectangle *curItem = findItem<QmlGraphicsRectangle>(pathview, "wrapper", i);
+ QCOMPARE(curItem->pos() + offset, path->pointAt(0.1 + i*0.25));
+ }
+
+ pathview->setOffset(100);
+ QTest::qWait(1000);//Moving is animated?
+ QCOMPARE(firstItem->pos() + offset, start);
+
+ delete canvas;
+}
+
QmlView *tst_QmlGraphicsPathView::createView(const QString &filename)
{
QmlView *canvas = new QmlView(0);
@@ -363,9 +446,9 @@ template<typename T>
T *tst_QmlGraphicsPathView::findItem(QmlGraphicsItem *parent, const QString &objectName, int index)
{
const QMetaObject &mo = T::staticMetaObject;
- //qDebug() << parent->QGraphicsObject::children().count() << "children";
- for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) {
- QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i));
+ //qDebug() << parent->childItems().count() << "children";
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->childItems().at(i));
if(!item)
continue;
//qDebug() << "try" << item;
@@ -393,8 +476,8 @@ QList<T*> tst_QmlGraphicsPathView::findItems(QmlGraphicsItem *parent, const QStr
QList<T*> items;
const QMetaObject &mo = T::staticMetaObject;
//qDebug() << parent->QGraphicsObject::children().count() << "children";
- for (int i = 0; i < parent->QGraphicsObject::children().count(); ++i) {
- QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->QGraphicsObject::children().at(i));
+ for (int i = 0; i < parent->childItems().count(); ++i) {
+ QmlGraphicsItem *item = qobject_cast<QmlGraphicsItem*>(parent->childItems().at(i));
if(!item)
continue;
//qDebug() << "try" << item;