diff options
author | Stephen D'Angelo <stephen.m.dangelo@gmail.com> | 2017-11-30 12:14:16 -0500 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-10-09 19:23:31 +0000 |
commit | 3fde977a817498817e98ce350d493658b0ed4458 (patch) | |
tree | db4d1c465fb3e7886b188d7bcf3c21fd581d1286 /tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp | |
parent | 6b6ef3a8417e628ca01a1c2cad81af69ea5c9d3a (diff) |
QQuickWindow: Higher z-order items now steal drop target
Previously, an active drop target would remain the drop target until the
drag left it's area, or entered a child item that accepted a
DragEnterEvent, even if the drag entered a drop target with a globally
higher z-order from a different subtree.
When moving to an item with a higher z-order, the DragEnterEvent is
now sent to the new drop target before DragLeaveEvent is sent to the old
drop target. There can now only be one drop target. If an item is the
current drop target and a higher z-order child accepts the DragEnterEvent,
the parent is no longer a drop target.
Fixes: QTBUG-30305
Change-Id: I7b985d6317be70867e7727222a4cd44ace7559e6
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp')
-rw-r--r-- | tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp | 88 |
1 files changed, 74 insertions, 14 deletions
diff --git a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp index cf01cc927b..dcba4c872e 100644 --- a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp +++ b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp @@ -28,6 +28,7 @@ #include <QtTest/QtTest> #include <QtTest/QSignalSpy> +#include <QtGui/qstylehints.h> #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> #include <QtQml/qqmlcontext.h> @@ -36,6 +37,8 @@ #include <qpa/qplatformdrag.h> #include <qpa/qwindowsysteminterface.h> +#include "../../shared/util.h" +#include "../shared/viewtestutil.h" template <typename T> static T evaluate(QObject *scope, const QString &expression) { @@ -54,13 +57,10 @@ template <> void evaluate<void>(QObject *scope, const QString &expression) qWarning() << expr.error().toString(); } -class tst_QQuickDropArea: public QObject +class tst_QQuickDropArea: public QQmlDataTest { Q_OBJECT private slots: - void initTestCase(); - void cleanupTestCase(); - void containsDrag_internal(); void containsDrag_external(); void keys_internal(); @@ -74,21 +74,13 @@ private slots: void competingDrags(); void simultaneousDrags(); void dropStuff(); + void nestedDropAreas_data(); + void nestedDropAreas(); private: QQmlEngine engine; }; -void tst_QQuickDropArea::initTestCase() -{ - -} - -void tst_QQuickDropArea::cleanupTestCase() -{ - -} - void tst_QQuickDropArea::containsDrag_internal() { QQuickWindow window; @@ -1224,6 +1216,74 @@ void tst_QQuickDropArea::dropStuff() QCOMPARE(evaluate<QByteArray>(dropArea, "array"), QByteArray("red")); } +void tst_QQuickDropArea::nestedDropAreas_data() +{ + QTest::addColumn<QString>("qmlFile"); + + QTest::newRow("dropRectDropRect") << "nested1.qml"; + QTest::newRow("rectDropRectDrop") << "nested2.qml"; +} + +void tst_QQuickDropArea::nestedDropAreas() +{ + QFETCH(QString, qmlFile); + + const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(QQuickTest::initView(window, testFileUrl(qmlFile.toLatin1().data()), true, &errorMessage), errorMessage.constData()); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != nullptr); + + QQuickItem *dragArea = window.rootObject()->findChild<QQuickItem*>("dragArea"); + QVERIFY(dragArea); + QQuickItem *outerDropArea = window.rootObject()->findChild<QQuickItem*>("outerDropArea"); + QVERIFY(outerDropArea); + QQuickItem *innerDropArea = window.rootObject()->findChild<QQuickItem*>("innerDropArea"); + QVERIFY(innerDropArea); + + QPoint p = QPoint(10,10); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p); + + // move the minimum distance to activate drag + p += QPoint(dragThreshold + 1, dragThreshold + 1); + QTest::mouseMove(&window, p); + + // drag the red rectangle into the inner DropArea + p += QPoint(100, 100); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 0); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 0); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 0); + + // drag the red rectangle into the outer DropArea + p += QPoint(0, 50); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 0); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 1); + + // drag the red rectangle into the inner DropArea + p -= QPoint(0, 50); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 1); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 1); + + // drag the red rectangle back out of both + p -= QPoint(100, 100); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 1); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 2); +} + QTEST_MAIN(tst_QQuickDropArea) #include "tst_qquickdroparea.moc" |