diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-01 01:00:53 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-01 01:00:54 +0100 |
commit | 7aa204d5b30d3d55ac838b4df601feaa368412b8 (patch) | |
tree | ecc155d46985f1143845d3bd13074914149f22f3 /tests | |
parent | c47ec42f02196f387c28ab1a5ac70a23ec642a63 (diff) | |
parent | 55b464196297afc11cb9836f61f737e6fdaf04dc (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: Icec0aa703d8a13efa9f1634a1a353eb9d63685c8
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 15 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp | 155 | ||||
-rw-r--r-- | tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc | 2 | ||||
-rw-r--r-- | tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo.astc | bin | 0 -> 2512 bytes | |||
-rw-r--r-- | tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo_srgb.astc | bin | 0 -> 2512 bytes | |||
-rw-r--r-- | tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp | 70 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp | 46 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp | 54 |
8 files changed, 318 insertions, 24 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 4f173d2dfd..3ee6a656b0 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3402,6 +3402,21 @@ void tst_QUrl::effectiveTLDs_data() QTest::newRow("yes16") << QUrl::fromEncoded("http://anything.pagespeedmobilizer.com") << ".pagespeedmobilizer.com"; QTest::newRow("yes17") << QUrl::fromEncoded("http://anything.eu-central-1.compute.amazonaws.com") << ".eu-central-1.compute.amazonaws.com"; QTest::newRow("yes18") << QUrl::fromEncoded("http://anything.ltd.hk") << ".ltd.hk"; + QTest::newRow("trentino.it") + << QUrl::fromEncoded("http://any.thing.trentino.it") << ".trentino.it"; + QTest::newRow("net.ni") << QUrl::fromEncoded("http://test.net.ni") << ".net.ni"; + QTest::newRow("dyn.cosidns.de") + << QUrl::fromEncoded("http://test.dyn.cosidns.de") << ".dyn.cosidns.de"; + QTest::newRow("freeddns.org") + << QUrl::fromEncoded("http://test.freeddns.org") << ".freeddns.org"; + QTest::newRow("app.os.stg.fedoraproject.org") + << QUrl::fromEncoded("http://test.app.os.stg.fedoraproject.org") + << ".app.os.stg.fedoraproject.org"; + QTest::newRow("development.run") << QUrl::fromEncoded("http://test.development.run") << ".development.run"; + QTest::newRow("crafting.xyz") << QUrl::fromEncoded("http://test.crafting.xyz") << ".crafting.xyz"; + QTest::newRow("nym.ie") << QUrl::fromEncoded("http://shamus.nym.ie") << ".nym.ie"; + QTest::newRow("vapor.cloud") << QUrl::fromEncoded("http://test.vapor.cloud") << ".vapor.cloud"; + QTest::newRow("official.academy") << QUrl::fromEncoded("http://acredited.official.academy") << ".official.academy"; } void tst_QUrl::effectiveTLDs() 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/gui/util/qtexturefilereader/qtexturefilereader.qrc b/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc index ab882b5db2..8aab86e1ff 100644 --- a/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc +++ b/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc @@ -3,5 +3,7 @@ <file>texturefiles/car.ktx</file> <file>texturefiles/pattern.pkm</file> <file>texturefiles/car_mips.ktx</file> + <file>texturefiles/newlogo_srgb.astc</file> + <file>texturefiles/newlogo.astc</file> </qresource> </RCC> diff --git a/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo.astc b/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo.astc Binary files differnew file mode 100644 index 0000000000..39bf3f1734 --- /dev/null +++ b/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo.astc diff --git a/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo_srgb.astc b/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo_srgb.astc Binary files differnew file mode 100644 index 0000000000..38e876829b --- /dev/null +++ b/tests/auto/gui/util/qtexturefilereader/texturefiles/newlogo_srgb.astc diff --git a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp index 9ff4f0ccf2..9b78d18954 100644 --- a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp +++ b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp @@ -49,33 +49,55 @@ void tst_qtexturefilereader::checkHandlers_data() QTest::addColumn<QList<int>>("dataOffsets"); QTest::addColumn<QList<int>>("dataLengths"); - QTest::addRow("pattern.pkm") << QStringLiteral(":/texturefiles/pattern.pkm") - << QSize(64, 64) - << quint32(0x0) - << quint32(0x8d64) - << quint32(0x0) - << 1 - << (QList<int>() << 16) - << (QList<int>() << 2048); + QTest::addRow("pattern.pkm") + << QStringLiteral(":/texturefiles/pattern.pkm") + << QSize(64, 64) + << quint32(0x0) + << quint32(0x8d64) + << quint32(0x0) + << 1 + << (QList<int>() << 16) + << (QList<int>() << 2048); - QTest::addRow("car.ktx") << QStringLiteral(":/texturefiles/car.ktx") - << QSize(146, 80) - << quint32(0x0) - << quint32(0x9278) - << quint32(0x1908) - << 1 - << (QList<int>() << 68) - << (QList<int>() << 11840); + QTest::addRow("car.ktx") + << QStringLiteral(":/texturefiles/car.ktx") + << QSize(146, 80) + << quint32(0x0) + << quint32(0x9278) + << quint32(0x1908) + << 1 + << (QList<int>() << 68) + << (QList<int>() << 11840); - QTest::addRow("car_mips.ktx") << QStringLiteral(":/texturefiles/car_mips.ktx") - << QSize(146, 80) - << quint32(0x0) - << quint32(0x9274) - << quint32(0x1907) - << 8 - << (QList<int>() << 68 << 5992 << 7516 << 7880 << 8004 << 8056 << 8068 << 8080) - << (QList<int>() << 5920 << 1520 << 360 << 120 << 48 << 8 << 8 << 8); + QTest::addRow("car_mips.ktx") + << QStringLiteral(":/texturefiles/car_mips.ktx") + << QSize(146, 80) + << quint32(0x0) + << quint32(0x9274) + << quint32(0x1907) + << 8 + << (QList<int>() << 68 << 5992 << 7516 << 7880 << 8004 << 8056 << 8068 << 8080) + << (QList<int>() << 5920 << 1520 << 360 << 120 << 48 << 8 << 8 << 8); + QTest::addRow("newlogo.astc") + << QStringLiteral(":/texturefiles/newlogo.astc") + << QSize(111, 78) + << quint32(0x0) + << quint32(0x93b9) + << quint32(0x0) + << 1 + << (QList<int>() << 16) + << (QList<int>() << 2496); + + QTest::addRow("newlogo_srgb.astc") + << QStringLiteral(":/texturefiles/newlogo_srgb.astc") + << QSize(111, 78) + << quint32(0x0) + << quint32(0x93d9) + << quint32(0x0) + << 1 + << (QList<int>() << 16) + << (QList<int>() << 2496); } void tst_qtexturefilereader::checkHandlers() 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" |