diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-05-10 14:01:15 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-06 08:00:12 +0200 |
commit | de4997ed4c08c63e54454629e9d78385330b4094 (patch) | |
tree | 2ffb980cdc395200f8055f86900846fe49e009ff /tests | |
parent | 7b181d599f87f628f7e019aa451ff670fdb29d9f (diff) |
Restart a drag when the item canvas changes.
Likewise when a property that affects whether a drag event is likely to
be accepted. Properties were locked in when a drag was started, but
this means that if a drag was started by setting the active property
in a state change or similar bulk change the properties that are
locked in is undefined. And if an item changed canvases during a drag
or the active property was set before a parent enter and leave events
weren't sent as they should have been.
Change-Id: Iefd22dcab4c5469904d8d8c5eaf91ec339540d9c
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickapplication/qquickapplication.pro | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquickdrag/tst_qquickdrag.cpp | 136 | ||||
-rw-r--r-- | tests/auto/quick/quick.pro | 1 |
3 files changed, 135 insertions, 4 deletions
diff --git a/tests/auto/quick/qquickapplication/qquickapplication.pro b/tests/auto/quick/qquickapplication/qquickapplication.pro index 454591272d..b59e69dbd0 100644 --- a/tests/auto/quick/qquickapplication/qquickapplication.pro +++ b/tests/auto/quick/qquickapplication/qquickapplication.pro @@ -4,5 +4,5 @@ TARGET = tst_qquickapplication macx:CONFIG -= app_bundle SOURCES += tst_qquickapplication.cpp -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml quick qml-private quick-private testlib diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp index 0f8449fff5..0ebfa81201 100644 --- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp +++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp @@ -154,6 +154,7 @@ private slots: void active(); void drop(); void move(); + void parentChange(); void hotSpot(); void supportedActions(); void proposedAction(); @@ -676,6 +677,93 @@ void tst_QQuickDrag::move() QCOMPARE(outerTarget.position.x(), qreal(25)); QCOMPARE(outerTarget.position.y(), qreal(50)); } +void tst_QQuickDrag::parentChange() +{ + QQuickCanvas canvas1; + TestDropTarget dropTarget1(canvas1.rootItem()); + dropTarget1.setSize(QSizeF(100, 100)); + + QQuickCanvas canvas2; + TestDropTarget dropTarget2(canvas2.rootItem()); + dropTarget2.setSize(QSizeF(100, 100)); + + QQmlComponent component(&engine); + component.setData( + "import QtQuick 2.0\n" + "Item {\n" + "property real hotSpotX: Drag.hotSpot.x\n" + "property real hotSpotY: Drag.hotSpot.y\n" + "x: 50; y: 50\n" + "width: 10; height: 10\n" + "Drag.active: true\n" + "}", QUrl()); + QScopedPointer<QObject> object(component.create()); + QQuickItem *item = qobject_cast<QQuickItem *>(object.data()); + QVERIFY(item); + + QCOMPARE(evaluate<bool>(item, "Drag.active"), true); + + // Verify setting a parent item for an item with an active drag sends an enter event. + item->setParentItem(canvas1.rootItem()); + QCOMPARE(dropTarget1.enterEvents, 0); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget1.enterEvents, 1); + + // Changing the parent within the same canvas should send a move event. + item->setParentItem(&dropTarget1); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 0); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + + // Changing the parent to an item in another canvas sends a leave event in the old canvas + // and an enter on the new canvas. + item->setParentItem(canvas2.rootItem()); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + QCOMPARE(dropTarget1.leaveEvents, 0); + QCOMPARE(dropTarget2.enterEvents, 0); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + QCOMPARE(dropTarget1.leaveEvents, 1); + QCOMPARE(dropTarget2.enterEvents, 1); + + // Removing then parent item sends a leave event. + item->setParentItem(0); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + QCOMPARE(dropTarget1.leaveEvents, 1); + QCOMPARE(dropTarget2.enterEvents, 1); + QCOMPARE(dropTarget2.leaveEvents, 0); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + QCOMPARE(dropTarget1.leaveEvents, 1); + QCOMPARE(dropTarget2.enterEvents, 1); + QCOMPARE(dropTarget2.leaveEvents, 1); + + // Go around again and verify no events if active is false. + evaluate<void>(item, "Drag.active = false"); + item->setParentItem(canvas1.rootItem()); + QCoreApplication::processEvents(); + + item->setParentItem(&dropTarget1); + QCoreApplication::processEvents(); + + item->setParentItem(canvas2.rootItem()); + QCoreApplication::processEvents(); + + item->setParentItem(0); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget1.enterEvents, 1); + QCOMPARE(dropTarget1.moveEvents, 1); + QCOMPARE(dropTarget1.leaveEvents, 1); + QCOMPARE(dropTarget2.enterEvents, 1); + QCOMPARE(dropTarget2.leaveEvents, 1); +} + void tst_QQuickDrag::hotSpot() { QQuickCanvas canvas; @@ -763,18 +851,28 @@ void tst_QQuickDrag::supportedActions() evaluate<void>(item, "{ Drag.start(); Drag.cancel() }"); QCOMPARE(dropTarget.supportedActions, Qt::CopyAction | Qt::MoveAction | Qt::LinkAction); + dropTarget.reset(); evaluate<void>(item, "Drag.supportedActions = Qt.CopyAction | Qt.MoveAction"); QCOMPARE(evaluate<bool>(item, "Drag.supportedActions == Qt.CopyAction | Qt.MoveAction"), true); QCOMPARE(evaluate<bool>(item, "supportedActions == Qt.CopyAction | Qt.MoveAction"), true); evaluate<void>(item, "Drag.start()"); QCOMPARE(dropTarget.supportedActions, Qt::CopyAction | Qt::MoveAction); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); - // Once a drag is started the proposed actions are locked in for future events. + // Changing the supported actions will restart the drag, after a delay to avoid any + // recursion. evaluate<void>(item, "Drag.supportedActions = Qt.MoveAction"); QCOMPARE(evaluate<bool>(item, "Drag.supportedActions == Qt.MoveAction"), true); QCOMPARE(evaluate<bool>(item, "supportedActions == Qt.MoveAction"), true); item->setPos(QPointF(60, 60)); QCOMPARE(dropTarget.supportedActions, Qt::CopyAction | Qt::MoveAction); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget.supportedActions, Qt::MoveAction); + QCOMPARE(dropTarget.leaveEvents, 1); + QCOMPARE(dropTarget.enterEvents, 2); // Calling start with proposed actions will override the current actions for the next sequence. evaluate<void>(item, "Drag.start(Qt.CopyAction)"); @@ -806,7 +904,6 @@ void tst_QQuickDrag::proposedAction() QVERIFY(item); item->setParentItem(&dropTarget); - QCOMPARE(evaluate<bool>(item, "Drag.proposedAction == Qt.MoveAction"), true); QCOMPARE(evaluate<bool>(item, "proposedAction == Qt.MoveAction"), true); evaluate<void>(item, "{ Drag.start(); Drag.cancel() }"); @@ -824,7 +921,6 @@ void tst_QQuickDrag::proposedAction() evaluate<void>(item, "Drag.proposedAction = Qt.MoveAction"); QCOMPARE(evaluate<bool>(item, "Drag.proposedAction == Qt.MoveAction"), true); QCOMPARE(evaluate<bool>(item, "proposedAction == Qt.MoveAction"), true); - item->setPos(QPointF(60, 60)); QCoreApplication::processEvents(); QCOMPARE(dropTarget.defaultAction, Qt::MoveAction); QCOMPARE(dropTarget.proposedAction, Qt::MoveAction); @@ -859,6 +955,23 @@ void tst_QQuickDrag::keys() QCOMPARE(evaluate<QStringList>(item, "Drag.keys"), QStringList() << "red" << "blue"); QCOMPARE(evaluate<QStringList>(item, "keys"), QStringList() << "red" << "blue"); QCOMPARE(item->property("keys").toStringList(), QStringList() << "red" << "blue"); + + // Test changing the keys restarts a drag. + QQuickCanvas canvas; + item->setParentItem(canvas.rootItem()); + TestDropTarget dropTarget(canvas.rootItem()); + dropTarget.setSize(QSizeF(100, 100)); + + evaluate<void>(item, "Drag.start()"); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); + + evaluate<void>(item, "Drag.keys = [\"green\"]"); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget.leaveEvents, 1); + QCOMPARE(dropTarget.enterEvents, 2); } void tst_QQuickDrag::source() @@ -890,6 +1003,23 @@ void tst_QQuickDrag::source() evaluate<void>(item, "Drag.source = undefined"); QCOMPARE(evaluate<QObject *>(item, "Drag.source"), static_cast<QObject *>(item)); QCOMPARE(evaluate<QObject *>(item, "source"), static_cast<QObject *>(item)); + + // Test changing the source restarts a drag. + QQuickCanvas canvas; + item->setParentItem(canvas.rootItem()); + TestDropTarget dropTarget(canvas.rootItem()); + dropTarget.setSize(QSizeF(100, 100)); + + evaluate<void>(item, "Drag.start()"); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); + + evaluate<void>(item, "Drag.source = proxySource"); + QCOMPARE(dropTarget.leaveEvents, 0); + QCOMPARE(dropTarget.enterEvents, 1); + QCoreApplication::processEvents(); + QCOMPARE(dropTarget.leaveEvents, 1); + QCOMPARE(dropTarget.enterEvents, 2); } class RecursingDropTarget : public TestDropTarget diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index 1c73a3b7d6..2ef6dc0357 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -44,6 +44,7 @@ QUICKTESTS = \ qquickborderimage \ qquickcanvas \ qquickdrag \ + qquickdroparea \ qquickflickable \ qquickflipable \ qquickfocusscope \ |