From d019f392273d4c0904abce72bcce95fc75575ec0 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 9 Dec 2009 11:32:38 +1000 Subject: Fix flicking to item boundary (snap). --- src/declarative/graphicsitems/qmlgraphicslistview.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 2084d94..a4fa07a 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -182,7 +182,7 @@ public: , snapMode(QmlGraphicsListView::NoSnap), overshootDist(0.0) , footerComponent(0), footer(0), headerComponent(0), header(0) , ownModel(false), wrap(false), autoHighlight(true), haveHighlightRange(false) - , correctFlick(true), lazyRelease(false) + , correctFlick(true), inFlickCorrection(false), lazyRelease(false) {} void init(); @@ -322,8 +322,7 @@ public: if (item->index == -1) continue; qreal itemTop = item->position(); - if ((item->index == model->count()-1 || itemTop >= pos-item->size()/2) - && (item->index == 0 || itemTop <= pos+item->size()/2)) + if (item->index == model->count()-1 || (itemTop+item->size()/2 >= pos)) return item->position(); } if (visibleItems.count()) { @@ -343,8 +342,7 @@ public: if (item->index == -1) continue; qreal itemTop = item->position(); - if ((item->index == model->count()-1 || itemTop >= pos-item->size()/2) - && (item->index == 0 || itemTop <= pos+item->size()/2)) + if (item->index == model->count()-1 || (itemTop+item->size()/2 >= pos)) return item; } if (visibleItems.count() && visibleItems.first()->position() <= pos) @@ -483,6 +481,7 @@ public: bool autoHighlight : 1; bool haveHighlightRange : 1; bool correctFlick : 1; + bool inFlickCorrection : 1; bool lazyRelease : 1; static int itemResizedIdx; @@ -1915,7 +1914,8 @@ void QmlGraphicsListView::viewportMoved() } } - if (d->flicked && d->correctFlick) { + if (d->flicked && d->correctFlick && !d->inFlickCorrection) { + d->inFlickCorrection = true; // Near an end and it seems that the extent has changed? // Recalculate the flick so that we don't end up in an odd position. if (yflick()) { @@ -1945,6 +1945,7 @@ void QmlGraphicsListView::viewportMoved() d->flickX(-d->verticalVelocity.value()); } } + d->inFlickCorrection = false; } } -- cgit v0.12 From 0150b8ffd4e12ca0f3c5197ce225d81b0f9d1537 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:03:32 +1000 Subject: Item creation benchmarks. --- .../declarative/creation/tst_creation.cpp | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index 99411d4..a73de41 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include class tst_creation : public QObject @@ -65,6 +66,12 @@ private slots: void qgraphicsitem(); void qgraphicsitem_tree(); + void itemtree_notree_cpp(); + void itemtree_objtree_cpp(); + void itemtree_cpp(); + void itemtree_data_cpp(); + void itemtree_qml(); + private: QmlEngine engine; }; @@ -241,6 +248,82 @@ void tst_creation::qgraphicsitem_tree() } } +struct QmlGraphics_DerivedObject : public QObject +{ + void setParent_noEvent(QObject *parent) { + bool sce = d_ptr->sendChildEvents; + d_ptr->sendChildEvents = false; + setParent(parent); + d_ptr->sendChildEvents = sce; + } +}; + +inline void QmlGraphics_setParent_noEvent(QObject *object, QObject *parent) +{ + static_cast(object)->setParent_noEvent(parent); +} + +void tst_creation::itemtree_notree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + } + delete item; + } +} + +void tst_creation::itemtree_objtree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + } + delete item; + } +} + +void tst_creation::itemtree_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + child->setParentItem(item); + } + delete item; + } +} + +void tst_creation::itemtree_data_cpp() +{ + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + item->data()->append(child); + } + delete item; + } +} + +void tst_creation::itemtree_qml() +{ + QmlComponent component(&engine, TEST_FILE("item.qml")); + QObject *obj = component.create(); + delete obj; + + QBENCHMARK { + QObject *obj = component.create(); + delete obj; + } +} + QTEST_MAIN(tst_creation) -- cgit v0.12 From 8c7e8e7306ad23986b55deaba3ed2c284053b6dd Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:31:23 +1000 Subject: Let anchors.centerIn honor horizontalCenterOffset and verticalCenterOffset. --- src/declarative/graphicsitems/qmlgraphicsanchors.cpp | 8 ++++---- tests/auto/declarative/anchors/data/centerin.qml | 12 ++++++++++++ tests/auto/declarative/anchors/tst_anchors.cpp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/auto/declarative/anchors/data/centerin.qml diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index c838d7d..153149e4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -183,14 +183,14 @@ void QmlGraphicsAnchorsPrivate::centerInChanged() ++updatingCenterIn; if (centerIn == item->parentItem()) { - QPointF p((item->parentItem()->width() - item->width()) / 2., - (item->parentItem()->height() - item->height()) / 2.); + QPointF p((item->parentItem()->width() - item->width()) / 2. + hCenterOffset, + (item->parentItem()->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { - QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., - centerIn->y() + (centerIn->height() - item->height()) / 2.); + QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2. + hCenterOffset, + centerIn->y() + (centerIn->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } diff --git a/tests/auto/declarative/anchors/data/centerin.qml b/tests/auto/declarative/anchors/data/centerin.qml new file mode 100644 index 0000000..09b97f6 --- /dev/null +++ b/tests/auto/declarative/anchors/data/centerin.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + objectName: "centered" + width: 50; height: 50; color: "blue" + anchors.centerIn: parent; + anchors.verticalCenterOffset: 30 + anchors.horizontalCenterOffset: 10 + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 7378d95..bbe5ef1 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -71,6 +71,7 @@ private slots: void nullItem(); void nullItem_data(); void crash1(); + void centerIn(); }; /* @@ -378,6 +379,21 @@ void tst_anchors::crash1() delete view; } +void tst_anchors::centerIn() +{ + QmlView *view = new QmlView; + + view->setUrl(QUrl("file://" SRCDIR "/data/centerin.qml")); + + view->execute(); + qApp->processEvents(); + + QCOMPARE(findItem(view->root(), QLatin1String("centered"))->x(), 85.0); + QCOMPARE(findItem(view->root(), QLatin1String("centered"))->y(), 105.0); + + delete view; +} + QTEST_MAIN(tst_anchors) #include "tst_anchors.moc" -- cgit v0.12 From 2b1aea7db5c6b8e5c31740add1dfb8dd1c9acb87 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:33:36 +1000 Subject: Fix leak. --- src/declarative/qml/qmlxmlhttprequest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 5f0fe9ce..9629d7b 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -1006,6 +1006,7 @@ QmlXMLHttpRequest::QmlXMLHttpRequest() QmlXMLHttpRequest::~QmlXMLHttpRequest() { destroyNetwork(); + delete m_nam; } QScriptValue QmlXMLHttpRequest::callback() const -- cgit v0.12 From 366abae3466f4a8d91f88caafb87f10f3031c355 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 13:43:38 +1000 Subject: Add missing file. --- .../benchmarks/declarative/creation/data/item.qml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/benchmarks/declarative/creation/data/item.qml diff --git a/tests/benchmarks/declarative/creation/data/item.qml b/tests/benchmarks/declarative/creation/data/item.qml new file mode 100644 index 0000000..74d2f27 --- /dev/null +++ b/tests/benchmarks/declarative/creation/data/item.qml @@ -0,0 +1,34 @@ +import Qt 4.6 + +Item { + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} +} -- cgit v0.12 From 4bad9d6661f6b63c6ce9b9a29e9f5cf7aa032e37 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 9 Dec 2009 14:58:11 +1000 Subject: Another creation benchmark. --- .../benchmarks/declarative/creation/tst_creation.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/benchmarks/declarative/creation/tst_creation.cpp b/tests/benchmarks/declarative/creation/tst_creation.cpp index a73de41..61033e2 100644 --- a/tests/benchmarks/declarative/creation/tst_creation.cpp +++ b/tests/benchmarks/declarative/creation/tst_creation.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ private slots: void itemtree_cpp(); void itemtree_data_cpp(); void itemtree_qml(); + void itemtree_scene_cpp(); private: QmlEngine engine; @@ -324,6 +326,24 @@ void tst_creation::itemtree_qml() } } +void tst_creation::itemtree_scene_cpp() +{ + QGraphicsScene scene; + QmlGraphicsItem *root = new QmlGraphicsItem; + scene.addItem(root); + QBENCHMARK { + QmlGraphicsItem *item = new QmlGraphicsItem; + for (int i = 0; i < 30; ++i) { + QmlGraphicsItem *child = new QmlGraphicsItem; + QmlGraphics_setParent_noEvent(child,item); + child->setParentItem(item); + } + item->setParentItem(root); + delete item; + } + delete root; +} + QTEST_MAIN(tst_creation) -- cgit v0.12