From 9cf3895f4dbb5d0678e2030316c1693581f754c9 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Tue, 12 Apr 2016 23:14:46 +0300 Subject: QQuickDragAttached: fix updating of "active" property The d->active member variable should be changed regardless of the value of Drag.dragType. Task-number: QTBUG-52540 Change-Id: I7fa39ccf11b1200e9c2f6fe57cba58657b6cff74 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickdrag.cpp | 11 +++--- tests/auto/quick/qquickdrag/tst_qquickdrag.cpp | 46 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 7e1ffb6b7e..e1b7ef47d8 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -300,13 +300,14 @@ void QQuickDragAttached::setActive(bool active) else if (active) { if (d->dragType == QQuickDrag::Internal) { d->start(d->supportedActions); - } - else if (d->dragType == QQuickDrag::Automatic) { - // There are different semantics than start() since startDrag() - // may be called after an internal drag is already started. + } else { d->active = true; emit activeChanged(); - d->startDrag(d->supportedActions); + if (d->dragType == QQuickDrag::Automatic) { + // There are different semantics than start() since startDrag() + // may be called after an internal drag is already started. + d->startDrag(d->supportedActions); + } } } else diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp index e232341a06..3615f56e5b 100644 --- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp +++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp @@ -144,6 +144,8 @@ private slots: void cleanupTestCase(); void active(); + void setActive_data(); + void setActive(); void drop(); void move(); void parentChange(); @@ -379,6 +381,50 @@ void tst_QQuickDrag::active() QCOMPARE(dropTarget.enterEvents, 0); QCOMPARE(dropTarget.leaveEvents, 0); QCOMPARE(dropTarget.moveEvents, 0); } +void tst_QQuickDrag::setActive_data() +{ + QTest::addColumn("dragType"); + + QTest::newRow("default") << ""; + QTest::newRow("internal") << "Drag.dragType: Drag.Internal"; + QTest::newRow("none") << "Drag.dragType: Drag.None"; + /* We don't test Drag.Automatic, because that causes QDrag::exec() to be + * invoked, and on some platforms tha's implemented by running a main loop + * until the drag has finished -- and at that point, the Drag.active will + * be false again. */ +} + +// QTBUG-52540 +void tst_QQuickDrag::setActive() +{ + QFETCH(QString, dragType); + + QQuickWindow window; + TestDropTarget dropTarget(window.contentItem()); + dropTarget.setSize(QSizeF(100, 100)); + QQmlComponent component(&engine); + component.setData( + "import QtQuick 2.0\n" + "Item {\n" + "property bool dragActive: Drag.active\n" + "property Item dragTarget: Drag.target\n" + + dragType.toUtf8() + "\n" + "x: 50; y: 50\n" + "width: 10; height: 10\n" + "}", QUrl()); + QScopedPointer object(component.create()); + QQuickItem *item = qobject_cast(object.data()); + QVERIFY(item); + item->setParentItem(&dropTarget); + + QCOMPARE(evaluate(item, "Drag.active"), false); + QCOMPARE(evaluate(item, "dragActive"), false); + + evaluate(item, "Drag.active = true"); + QCOMPARE(evaluate(item, "Drag.active"), true); + QCOMPARE(evaluate(item, "dragActive"), true); +} + void tst_QQuickDrag::drop() { QQuickWindow window; -- cgit v1.2.3