summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-28 01:00:14 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-02-28 01:00:15 +0100
commit043f99954faa8355c9f0d78d441099a6f7e1ad8b (patch)
tree3543e16fef20cb6f71b1374594477a4b145f9bab /tests/auto
parentf6ce77f3e4dbc67531db7eeaf271c5416b4a4934 (diff)
parentf657c7426329d3763bbf3373b986378c22020269 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp155
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp46
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp54
3 files changed, 255 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index db5e83e2c7..13dc924f93 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -204,6 +204,7 @@ private slots:
void basicRawEventTranslationOfIds();
void multiPointRawEventTranslationOnTouchScreen();
void multiPointRawEventTranslationOnTouchPad();
+ void touchOnMultipleTouchscreens();
void deleteInEventHandler();
void deleteInRawEventTranslation();
void crashInQGraphicsSceneAfterNotHandlingTouchBegin();
@@ -213,11 +214,13 @@ private slots:
private:
QTouchDevice *touchScreenDevice;
+ QTouchDevice *secondaryTouchScreenDevice;
QTouchDevice *touchPadDevice;
};
tst_QTouchEvent::tst_QTouchEvent()
: touchScreenDevice(QTest::createTouchDevice())
+ , secondaryTouchScreenDevice(QTest::createTouchDevice())
, touchPadDevice(QTest::createTouchDevice(QTouchDevice::TouchPad))
{
}
@@ -225,6 +228,7 @@ tst_QTouchEvent::tst_QTouchEvent()
void tst_QTouchEvent::cleanup()
{
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
+ QWindowSystemInterfacePrivate::clearPointIdMap();
}
void tst_QTouchEvent::qPointerUniqueId()
@@ -951,6 +955,157 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
}
}
+void tst_QTouchEvent::touchOnMultipleTouchscreens()
+{
+ tst_QTouchEventWidget touchWidget;
+ touchWidget.setWindowTitle(QTest::currentTestFunction());
+ touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
+ touchWidget.setGeometry(100, 100, 400, 300);
+ touchWidget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&touchWidget));
+ QWindow *window = touchWidget.windowHandle();
+
+ QPointF pos = touchWidget.rect().center();
+ QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint());
+ QPointF delta(10, 10);
+ QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget);
+
+ QVector<QTouchEvent::TouchPoint> rawTouchPoints(3);
+ rawTouchPoints[0].setId(0);
+ rawTouchPoints[1].setId(10);
+ rawTouchPoints[2].setId(11);
+
+ // this should be translated to a TouchBegin
+ rawTouchPoints[0].setState(Qt::TouchPointPressed);
+ rawTouchPoints[0].setScreenPos(screenPos);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ rawTouchPoints[0].setRawScreenPositions({{12, 34}, {56, 78}});
+ ulong timestamp = 1234;
+ QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[0], window);
+ QWindowSystemInterface::handleTouchEvent(window, timestamp, touchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(!touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.timestamp, timestamp);
+ QTouchEvent::TouchPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
+ const int touchPointId = (QTouchDevicePrivate::get(touchScreenDevice)->id << 24) + 1;
+ const int secTouchPointId = (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 2;
+ QCOMPARE(touchBeginPoint.id(), touchPointId);
+ QCOMPARE(touchBeginPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(touchBeginPoint.pos(), pos);
+
+ // press a point on secondaryTouchScreenDevice
+ touchWidget.seenTouchBegin = false;
+ rawTouchPoints[1].setState(Qt::TouchPointPressed);
+ rawTouchPoints[1].setScreenPos(screenPos);
+ rawTouchPoints[1].setNormalizedPos(normalized(rawTouchPoints[1].pos(), screenGeometry));
+ rawTouchPoints[1].setRawScreenPositions({{90, 100}, {110, 120}});
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[1], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.timestamp, timestamp);
+ touchBeginPoint = touchWidget.touchBeginPoints[0];
+ QCOMPARE(touchBeginPoint.id(), (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 2);
+ QCOMPARE(touchBeginPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(touchBeginPoint.pos(), pos);
+
+ // press another point on secondaryTouchScreenDevice
+ touchWidget.seenTouchBegin = false;
+ rawTouchPoints[2].setState(Qt::TouchPointPressed);
+ rawTouchPoints[2].setScreenPos(screenPos);
+ rawTouchPoints[2].setNormalizedPos(normalized(rawTouchPoints[2].pos(), screenGeometry));
+ rawTouchPoints[2].setRawScreenPositions({{130, 140}, {150, 160}});
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[2], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.timestamp, timestamp);
+ touchBeginPoint = touchWidget.touchBeginPoints[0];
+ QCOMPARE(touchBeginPoint.id(), (QTouchDevicePrivate::get(secondaryTouchScreenDevice)->id << 24) + 3);
+ QCOMPARE(touchBeginPoint.state(), rawTouchPoints[2].state());
+ QCOMPARE(touchBeginPoint.pos(), pos);
+
+ // moving the first point should translate to TouchUpdate
+ rawTouchPoints[0].setState(Qt::TouchPointMoved);
+ rawTouchPoints[0].setScreenPos(screenPos + delta);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[0], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QTouchEvent::TouchPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
+ QCOMPARE(touchUpdatePoint.id(), touchPointId);
+ QCOMPARE(touchUpdatePoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(touchUpdatePoint.pos(), pos + delta);
+
+ // releasing the first point translates to TouchEnd
+ rawTouchPoints[0].setState(Qt::TouchPointReleased);
+ rawTouchPoints[0].setScreenPos(screenPos + delta + delta);
+ rawTouchPoints[0].setNormalizedPos(normalized(rawTouchPoints[0].pos(), screenGeometry));
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[0], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QTouchEvent::TouchPoint touchEndPoint = touchWidget.touchEndPoints.first();
+ QCOMPARE(touchEndPoint.id(), touchPointId);
+ QCOMPARE(touchEndPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(touchEndPoint.pos(), pos + delta + delta);
+
+ // Widgets don't normally handle this case: if a TouchEnd was seen before, then
+ // WA_WState_AcceptedTouchBeginEvent will be false, and
+ // QApplicationPrivate::translateRawTouchEvent will ignore touch events that aren't TouchBegin.
+ // So we have to set it true. It _did_ in fact accept the touch begin from the secondary device,
+ // but it also got a TouchEnd from the primary device in the meantime.
+ touchWidget.setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, true);
+
+ // Releasing one point on the secondary touchscreen does not yet generate TouchEnd.
+ touchWidget.seenTouchEnd = false;
+ touchWidget.touchEndPoints.clear();
+ rawTouchPoints[1].setState(Qt::TouchPointReleased);
+ rawTouchPoints[2].setState(Qt::TouchPointStationary);
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[1] << rawTouchPoints[2], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(!touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints[0].id(), secTouchPointId);
+ QCOMPARE(touchWidget.touchUpdatePoints[1].id(), secTouchPointId + 1);
+
+ // releasing the last point on the secondary touchscreen translates to TouchEnd
+ touchWidget.seenTouchEnd = false;
+ rawTouchPoints[2].setState(Qt::TouchPointReleased);
+ nativeTouchPoints =
+ QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QTouchEvent::TouchPoint>() << rawTouchPoints[2], window);
+ QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
+ QCoreApplication::processEvents();
+ QVERIFY(touchWidget.seenTouchBegin);
+ QVERIFY(touchWidget.seenTouchUpdate);
+ QVERIFY(touchWidget.seenTouchEnd);
+ QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ touchEndPoint = touchWidget.touchEndPoints.first();
+ QCOMPARE(touchEndPoint.id(), secTouchPointId + 1);
+ QCOMPARE(touchEndPoint.state(), rawTouchPoints[2].state());
+}
+
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
{
tst_QTouchEventWidget touchWidget;
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index e1d527b398..0b828b8484 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -121,6 +121,7 @@ private slots:
void task254449_draggingItemToNegativeCoordinates();
void keyboardSearch();
void shiftSelectionWithNonUniformItemSizes();
+ void shiftSelectionWithItemAlignment();
void clickOnViewportClearsSelection();
void task262152_setModelColumnNavigate();
void taskQTBUG_2233_scrollHiddenItems_data();
@@ -1802,6 +1803,51 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes()
}
}
+void tst_QListView::shiftSelectionWithItemAlignment()
+{
+ QStringList items;
+ for (int c = 0; c < 2; c++) {
+ for (int i = 10; i > 0; i--)
+ items << QString(i, QLatin1Char('*'));
+
+ for (int i = 1; i < 11; i++)
+ items << QString(i, QLatin1Char('*'));
+ }
+
+ QListView view;
+ view.setFlow(QListView::TopToBottom);
+ view.setWrapping(true);
+ view.setItemAlignment(Qt::AlignLeft);
+ view.setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ QStringListModel model(items);
+ view.setModel(&model);
+
+ QFont font = view.font();
+ font.setPixelSize(10);
+ view.setFont(font);
+ view.resize(300, view.sizeHintForRow(0) * items.size() / 2 + view.horizontalScrollBar()->height());
+
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+ QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow());
+
+ QModelIndex index1 = view.model()->index(items.size() / 4, 0);
+ QPoint p = view.visualRect(index1).center();
+ QVERIFY(view.viewport()->rect().contains(p));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p);
+ QCOMPARE(view.currentIndex(), index1);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1);
+
+ QModelIndex index2 = view.model()->index(items.size() / 4 * 3, 0);
+ p = view.visualRect(index2).center();
+ QVERIFY(view.viewport()->rect().contains(p));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p);
+ QCOMPARE(view.currentIndex(), index2);
+ QCOMPARE(view.selectionModel()->selectedIndexes().size(), index2.row() - index1.row() + 1);
+}
+
void tst_QListView::clickOnViewportClearsSelection()
{
QStringList items;
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index ae968d34dd..c31de2ba22 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -200,6 +200,7 @@ private slots:
void taskQTBUG_45697_crash();
void taskQTBUG_7232_AllowUserToControlSingleStep();
void taskQTBUG_8376();
+ void taskQTBUG_61476();
void testInitialFocus();
};
@@ -4806,5 +4807,58 @@ void tst_QTreeView::taskQTBUG_8376()
QCOMPARE(rowHeightLvl1Visible, rowHeightLvl1Visible2);
}
+void tst_QTreeView::taskQTBUG_61476()
+{
+ // This checks that if a user clicks on an item to collapse it that it
+ // does not edit (in this case change the check state) the item that is
+ // now over the mouse just because it got a release event
+ QTreeView tv;
+ QStandardItemModel model;
+ QStandardItem *lastTopLevel = nullptr;
+ {
+ for (int i = 0; i < 4; ++i) {
+ QStandardItem *item = new QStandardItem(QLatin1String("Row Item"));
+ item->setCheckable(true);
+ item->setCheckState(Qt::Checked);
+ model.appendRow(item);
+ lastTopLevel = item;
+ for (int j = 0; j < 2; ++j) {
+ QStandardItem *childItem = new QStandardItem(QLatin1String("Child row Item"));
+ childItem->setCheckable(true);
+ childItem->setCheckState(Qt::Checked);
+ item->appendRow(childItem);
+ QStandardItem *grandChild = new QStandardItem(QLatin1String("Grand child row Item"));
+ grandChild->setCheckable(true);
+ grandChild->setCheckState(Qt::Checked);
+ childItem->appendRow(grandChild);
+ }
+ }
+ }
+ tv.setModel(&model);
+ tv.expandAll();
+ // We need it to be this size so that the effect of the collapsing will
+ // cause the parent item to move to be under the cursor
+ tv.resize(200, 200);
+ tv.show();
+ QVERIFY(QTest::qWaitForWindowActive(&tv));
+ tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum());
+
+ // We want to press specifically right around where a checkbox for the
+ // parent item could be when collapsing
+ QTreeViewPrivate *priv = static_cast<QTreeViewPrivate*>(qt_widget_private(&tv));
+ const QModelIndex mi = lastTopLevel->child(0)->index();
+ const QRect rect = priv->itemDecorationRect(mi);
+ const QPoint pos = rect.center();
+
+ QTest::mousePress(tv.viewport(), Qt::LeftButton, 0, pos);
+ if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, &tv) ==
+ QEvent::MouseButtonPress)
+ QTRY_VERIFY(!tv.isExpanded(mi));
+
+ QTest::mouseRelease(tv.viewport(), Qt::LeftButton, 0, pos);
+ QTRY_VERIFY(!tv.isExpanded(mi));
+ QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
+}
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"