diff options
Diffstat (limited to 'tests/auto/widgets/itemviews')
8 files changed, 272 insertions, 51 deletions
diff --git a/tests/auto/widgets/itemviews/itemviews.pro b/tests/auto/widgets/itemviews/itemviews.pro index af0b6aeef0..f2ee0e9124 100644 --- a/tests/auto/widgets/itemviews/itemviews.pro +++ b/tests/auto/widgets/itemviews/itemviews.pro @@ -20,7 +20,3 @@ SUBDIRS=\ !qtConfig(private_tests): SUBDIRS -= \ qcolumnview \ qlistwidget \ - -# This test takes too long to run on IRIX, so skip it on that platform -irix-*:SUBDIRS -= qitemview - diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 1ac66ed5cb..f6723ceba4 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -77,7 +77,7 @@ public: GeometriesTestView() : QTableView(), updateGeometriesCalled(false) {} bool updateGeometriesCalled; protected slots: - void updateGeometries() Q_DECL_OVERRIDE { updateGeometriesCalled = true; QTableView::updateGeometries(); } + void updateGeometries() override { updateGeometriesCalled = true; QTableView::updateGeometries(); } }; class tst_QAbstractItemView : public QObject @@ -1555,7 +1555,7 @@ public: QItemDelegate(parent) {} - void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE { + void setEditorData(QWidget *editor, const QModelIndex &index) const override { Q_UNUSED(index); static bool w = true; editor->setEnabled(w); @@ -1999,7 +1999,7 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model() { } - void setSelectionModel(QItemSelectionModel *model) Q_DECL_OVERRIDE + void setSelectionModel(QItemSelectionModel *model) override { m_deselectedMustBeEmpty = !selectionModel() || !model || selectionModel()->model() != model->model(); QListView::setSelectionModel(model); @@ -2009,7 +2009,7 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model() bool selectionChangedOk() const { return m_selectionChangedOk; } protected: - bool viewportEvent(QEvent *event) Q_DECL_OVERRIDE + bool viewportEvent(QEvent *event) override { if (event->type() == QEvent::Paint) ++m_paintEventsCount; @@ -2017,7 +2017,7 @@ void tst_QAbstractItemView::QTBUG50535_update_on_new_selection_model() } void selectionChanged(const QItemSelection &selected, - const QItemSelection &deselected) Q_DECL_OVERRIDE + const QItemSelection &deselected) override { if (m_deselectedMustBeEmpty && !deselected.isEmpty()) m_selectionChangedOk = false; @@ -2140,7 +2140,7 @@ signals: void setSelectionCalled(const QRect &rect); protected: - void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) Q_DECL_OVERRIDE + void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override { emit setSelectionCalled(rect); QListView::setSelection(rect, flags); diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 90019a1798..a5d131a436 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -239,13 +239,15 @@ private slots: void testStreamWithHide(); void testStylePosition(); void stretchAndRestoreLastSection(); - + void testMinMaxSectionSizeStretched(); + void testMinMaxSectionSizeNotStretched(); void sizeHintCrash(); protected: void setupTestData(bool use_reset_model = false); void additionalInit(); void calculateAndCheck(int cppline, const int precalced_comparedata[]); + void testMinMaxSectionSize(bool stretchLastSection); QWidget *topLevel; QHeaderView *view; @@ -402,6 +404,7 @@ void tst_QHeaderView::init() QCOMPARE(view->length(), 0); QCOMPARE(view->sizeHint(), QSize(0,0)); QCOMPARE(view->sectionSizeHint(0), -1); + view->setMinimumSectionSize(0); // system default min size can be to large /* model = new QStandardItemModel(1, 1); @@ -514,6 +517,12 @@ void tst_QHeaderView::movable() QCOMPARE(view->sectionsMovable(), false); view->setSectionsMovable(true); QCOMPARE(view->sectionsMovable(), true); + + QCOMPARE(view->firstSectionMovable(), true); + view->setFirstSectionMovable(false); + QCOMPARE(view->firstSectionMovable(), false); + view->setFirstSectionMovable(true); + QCOMPARE(view->firstSectionMovable(), true); } void tst_QHeaderView::clickable() @@ -1598,6 +1607,7 @@ static QByteArray savedState() QStandardItemModel m(4, 4); QHeaderView h1(Qt::Horizontal); h1.setModel(&m); + h1.setMinimumSectionSize(0); // system default min size can be to large h1.swapSections(0, 2); h1.resizeSection(1, 10); h1.setSortIndicatorShown(true); @@ -1800,7 +1810,7 @@ class TestHeaderViewStyle : public QProxyStyle { public: TestHeaderViewStyle() : horizontalSectionSize(100) {} - int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE + int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override { if (metric == QStyle::PM_HeaderDefaultSectionSizeHorizontal) return horizontalSectionSize; @@ -2188,6 +2198,7 @@ void tst_QHeaderView::task248050_hideRow() //this is the sequence of events that make the task fail protected_QHeaderView header(Qt::Vertical); QStandardItemModel model(0, 1); + header.setMinimumSectionSize(0); // system default min size can be to large header.setStretchLastSection(false); header.setDefaultSectionSize(17); header.setModel(&model); @@ -3176,5 +3187,76 @@ void tst_QHeaderView::stretchAndRestoreLastSection() QCOMPARE(header.sectionSize(9), someOtherSectionSize); } +void tst_QHeaderView::testMinMaxSectionSizeStretched() +{ + testMinMaxSectionSize(true); +} + +void tst_QHeaderView::testMinMaxSectionSizeNotStretched() +{ + testMinMaxSectionSize(false); +} + +static void waitFor(const std::function<bool()> &func) +{ + for (int i = 0; i < 100; i++) + { + if (func()) + return; + QTest::qWait(10); + } +} + +void tst_QHeaderView::testMinMaxSectionSize(bool stretchLastSection) +{ + QStandardItemModel m(5, 5); + QTableView tv; + tv.setModel(&m); + tv.show(); + + const int sectionSizeMin = 20; + const int sectionSizeMax = 40; + const int defaultSectionSize = 30; + + QVERIFY(QTest::qWaitForWindowExposed(&tv)); + + QHeaderView &header = *tv.horizontalHeader(); + header.setMinimumSectionSize(sectionSizeMin); + header.setMaximumSectionSize(sectionSizeMax); + header.setDefaultSectionSize(defaultSectionSize); + header.setStretchLastSection(stretchLastSection); + + // check defaults + QCOMPARE(header.sectionSize(0), defaultSectionSize); + QCOMPARE(header.sectionSize(3), defaultSectionSize); + + // do not go above maxSectionSize + header.resizeSection(0, sectionSizeMax + 1); + QCOMPARE(header.sectionSize(0), sectionSizeMax); + + // do not go below minSectionSize + header.resizeSection(0, sectionSizeMin - 1); + QCOMPARE(header.sectionSize(0), sectionSizeMin); + + // change section size on max change + header.setMinimumSectionSize(sectionSizeMin); + header.setMaximumSectionSize(sectionSizeMax); + header.resizeSection(0, sectionSizeMax); + QCOMPARE(header.sectionSize(0), sectionSizeMax); + header.setMaximumSectionSize(defaultSectionSize); + waitFor([this, &header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; }); + QCOMPARE(header.sectionSize(0), defaultSectionSize); + + // change section size on min change + header.setMinimumSectionSize(sectionSizeMin); + header.setMaximumSectionSize(sectionSizeMax); + header.resizeSection(0, sectionSizeMin); + QCOMPARE(header.sectionSize(0), sectionSizeMin); + header.setMinimumSectionSize(defaultSectionSize); + waitFor([this, &header, defaultSectionSize]() { return header.sectionSize(0) == defaultSectionSize; }); + QCOMPARE(header.sectionSize(0), defaultSectionSize); +} + + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 2a5895583d..2fed2e0c69 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -220,6 +220,20 @@ private slots: void QTBUG4435_keepSelectionOnCheck(); void QTBUG16469_textForRole(); + void dateTextForRole_data(); + void dateTextForRole(); + +#ifdef QT_BUILD_INTERNAL +private: + struct RoleDelegate : public QItemDelegate + { + QString textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale) + { + QAbstractItemDelegatePrivate *d = reinterpret_cast<QAbstractItemDelegatePrivate *>(qGetPtrHelper(d_ptr)); + return d->textForRole(role, value, locale); + } + }; +#endif }; @@ -474,7 +488,7 @@ void tst_QItemDelegate::doLayout_data() << QRect(0, 0, 50, 50) << QRect(0, 0, 1000, 1000) << QRect(0, 0, 400, 400) - << QRect(m, 0, 50 + 2*m, 1000) + << QRect(0, 0, 50 + 2*m, 1000) << QRect(50 + 2*m, 0, 1000 + 2*m, 1000 + m) << QRect(50 + 2*m, 1000 + m, 1000 + 2*m, 400); /* @@ -510,7 +524,7 @@ void tst_QItemDelegate::doLayout_data() << QRect(0, 0, 50, 50) << QRect(0, 0, 1000, 1000) << QRect(0, 0, 400, 400) - << QRect(m, 0, 50 + 2 * m, 1000) + << QRect(0, 0, 50 + 2 * m, 1000) << QRect(50 + 2 * m, 400 + m, 1000 + 2 * m, 1000) << QRect(50 + 2 * m, 0, 1000 + 2 * m, 400 + m); @@ -534,7 +548,7 @@ void tst_QItemDelegate::doLayout_data() << QRect(0, 0, 50, 50) << QRect(0, 0, 1000, 1000) << QRect(0, 0, 400, 400) - << QRect(m, 0, 50 + 2 * m, 1000) + << QRect(0, 0, 50 + 2 * m, 1000) << QRect(50 + 2 * m, 0, 1000 + 2 * m, 1000) << QRect(1050 + 4 * m, 0, 400 + 2 * m, 1000); @@ -558,7 +572,7 @@ void tst_QItemDelegate::doLayout_data() << QRect(0, 0, 50, 50) << QRect(0, 0, 1000, 1000) << QRect(0, 0, 400, 400) - << QRect(m, 0, 50 + 2 * m, 1000) + << QRect(0, 0, 50 + 2 * m, 1000) << QRect(450 + 4 * m, 0, 1000 + 2 * m, 1000) << QRect(50 + 2 * m, 0, 400 + 2 * m, 1000); @@ -1530,14 +1544,7 @@ void tst_QItemDelegate::QTBUG16469_textForRole() #ifndef QT_BUILD_INTERNAL QSKIP("This test requires a developer build"); #else - struct TestDelegate : public QItemDelegate - { - QString textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale) - { - QAbstractItemDelegatePrivate *d = reinterpret_cast<QAbstractItemDelegatePrivate *>(qGetPtrHelper(d_ptr)); - return d->textForRole(role, value, locale); - } - } delegate; + RoleDelegate delegate; QLocale locale; const float f = 123.456f; @@ -1559,20 +1566,6 @@ void tst_QItemDelegate::QTBUG16469_textForRole() QCOMPARE(delegate.textForRole(Qt::DisplayRole, ull, locale), locale.toString(ull)); QCOMPARE(delegate.textForRole(Qt::ToolTipRole, ull, locale), locale.toString(ull)); - const QDateTime dateTime = QDateTime::currentDateTime(); - const QDate date = dateTime.date(); - const QTime time = dateTime.time(); - const QString shortDate = locale.toString(date, QLocale::ShortFormat); - const QString longDate = locale.toString(date, QLocale::LongFormat); - const QString shortTime = locale.toString(time, QLocale::ShortFormat); - const QString longTime = locale.toString(time, QLocale::LongFormat); - QCOMPARE(delegate.textForRole(Qt::DisplayRole, date, locale), shortDate); - QCOMPARE(delegate.textForRole(Qt::ToolTipRole, date, locale), longDate); - QCOMPARE(delegate.textForRole(Qt::DisplayRole, time, locale), shortTime); - QCOMPARE(delegate.textForRole(Qt::ToolTipRole, time, locale), longTime); - QCOMPARE(delegate.textForRole(Qt::DisplayRole, dateTime, locale), shortDate + QLatin1Char(' ') + shortTime); - QCOMPARE(delegate.textForRole(Qt::ToolTipRole, dateTime, locale), longDate + QLatin1Char(' ') + longTime); - const QString text("text"); QCOMPARE(delegate.textForRole(Qt::DisplayRole, text, locale), text); QCOMPARE(delegate.textForRole(Qt::ToolTipRole, text, locale), text); @@ -1584,6 +1577,41 @@ void tst_QItemDelegate::QTBUG16469_textForRole() #endif } +void tst_QItemDelegate::dateTextForRole_data() +{ +#ifdef QT_BUILD_INTERNAL + QTest::addColumn<QDateTime>("when"); + + QTest::newRow("now") << QDateTime::currentDateTime(); // It's a local time + QDate date(2013, 12, 11); + QTime time(10, 9, 8, 765); + // Ensure we exercise every time-spec variant: + QTest::newRow("local") << QDateTime(date, time, Qt::LocalTime); + QTest::newRow("UTC") << QDateTime(date, time, Qt::UTC); + QTest::newRow("zone") << QDateTime(date, time, QTimeZone("Europe/Dublin")); + QTest::newRow("offset") << QDateTime(date, time, Qt::OffsetFromUTC, 36000); +#endif +} + +void tst_QItemDelegate::dateTextForRole() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("This test requires a developer build"); +#else + QFETCH(QDateTime, when); + RoleDelegate delegate; + QLocale locale; +# define CHECK(value) \ + QCOMPARE(delegate.textForRole(Qt::DisplayRole, value, locale), locale.toString(value, QLocale::ShortFormat)); \ + QCOMPARE(delegate.textForRole(Qt::ToolTipRole, value, locale), locale.toString(value, QLocale::LongFormat)) + + CHECK(when); + CHECK(when.date()); + CHECK(when.time()); +# undef CHECK +#endif +} + // ### _not_ covered: // editing with a custom editor factory diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 5e0d99f25e..1d8286b3cf 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -282,7 +282,7 @@ public: class ScrollPerItemListView : public QListView { public: - explicit ScrollPerItemListView(QWidget *parent = Q_NULLPTR) + explicit ScrollPerItemListView(QWidget *parent = nullptr) : QListView(parent) { // Force per item scroll mode since it comes from the style by default diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 4e401ddd86..06c80bf8d2 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -426,6 +426,9 @@ public: this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection))); + // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes. + horizontalHeader()->setMinimumSectionSize(0); + verticalHeader()->setMinimumSectionSize(0); } // enum CursorAction and moveCursor() are protected in QTableView. @@ -738,6 +741,8 @@ void tst_QTableView::headerSections() QHeaderView *vheader = view.verticalHeader(); view.setModel(&model); + hheader->setMinimumSectionSize(columnWidth); + vheader->setMinimumSectionSize(rowHeight); view.show(); hheader->doItemsLayout(); @@ -1147,6 +1152,9 @@ void tst_QTableView::moveCursor() QtTestTableView view; view.setModel(&model); + // we have to make sure that PgUp/PgDown can scroll to the bottom/top + view.resize(view.horizontalHeader()->length() + 50, + view.verticalHeader()->length() + 50); view.hideRow(hideRow); view.hideColumn(hideColumn); if (moveColumn.first != moveColumn.second) @@ -2085,6 +2093,8 @@ void tst_QTableView::visualRect() QTableView view; view.setModel(&model); + view.horizontalHeader()->setMinimumSectionSize(0); + view.verticalHeader()->setMinimumSectionSize(0); // Make sure that it has 1 pixel between each cell. view.setGridStyle(Qt::SolidLine); for (int i = 0; i < view.verticalHeader()->count(); ++i) @@ -3533,6 +3543,9 @@ void tst_QTableView::editSpanFromDirections() TableViewWithCursorExposed view; view.setModel(model.data()); + // we have to make sure that PgUp/PgDown can scroll to the bottom/top + view.resize(view.horizontalHeader()->length() + 50, + view.verticalHeader()->length() + 50); view.setSpan(row, column, rowSpan, columnSpan); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -3978,7 +3991,7 @@ void tst_QTableView::mouseWheel_data() << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines(); QTest::newRow("scroll down per pixel") << int(QAbstractItemView::ScrollPerPixel) << -120 - << 10 + qApp->wheelScrollLines() * 89 << 10 + qApp->wheelScrollLines() * 28; + << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46; } void tst_QTableView::mouseWheel() @@ -3992,16 +4005,17 @@ void tst_QTableView::mouseWheel() QWidget topLevel; QtTestTableView view(&topLevel); view.resize(500, 500); - for (int r = 0; r < 100; ++r) - view.setRowHeight(r, 50); - for (int c = 0; c < 100; ++c) - view.setColumnWidth(c, 100); topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); view.setModel(&model); + for (int r = 0; r < 100; ++r) + view.setRowHeight(r, 50); + for (int c = 0; c < 100; ++c) + view.setColumnWidth(c, 100); + view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode); view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode); view.horizontalScrollBar()->setValue(10); @@ -4270,7 +4284,7 @@ void tst_QTableView::changeHeaderData() QVERIFY(QTest::qWaitForWindowExposed(&view)); QString text = "long long long text"; - const int textWidth = view.verticalHeader()->fontMetrics().width(text); + const int textWidth = view.verticalHeader()->fontMetrics().horizontalAdvance(text); QVERIFY(view.verticalHeader()->width() < textWidth); model.setHeaderData(2, Qt::Vertical, text); @@ -4364,7 +4378,8 @@ void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection() QItemSelection selection; selection << range; QRegion region = view.visualRegionForSelection(selection); - QCOMPARE(region.rects().at(0), view.visualRect(range.topLeft()) | view.visualRect(range.bottomRight())); + QVERIFY(!region.isEmpty()); + QCOMPARE(region.begin()[0], view.visualRect(range.topLeft()) | view.visualRect(range.bottomRight())); } void tst_QTableView::taskQTBUG_8777_scrollToSpans() diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index b2e1a2d9b5..5293ba487a 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -165,6 +165,7 @@ private slots: void statusTip_data(); void statusTip(); + void fetchMoreOnScroll(); // task-specific tests: void task174627_moveLeftToRoot(); @@ -311,6 +312,12 @@ public: return QVariant(); } + void simulateMoveRows() + { + beginMoveRows(QModelIndex(), 0, 0, QModelIndex(), 2); + endMoveRows(); + } + void removeLastRow() { beginRemoveRows(QModelIndex(), rows - 1, rows - 1); @@ -1326,6 +1333,17 @@ void tst_QTreeView::columnHidden() for (int c = 0; c < model.columnCount(); ++c) QCOMPARE(view.isColumnHidden(c), true); view.update(); + + // QTBUG 54610 + // QAbstractItemViewPrivate::_q_layoutChanged() is called on + // rows/columnMoved and because this function is virtual, + // QHeaderViewPrivate::_q_layoutChanged() was called and unhided + // all sections because QHeaderViewPrivate::_q_layoutAboutToBeChanged() + // could not fill persistentHiddenSections (and is not needed) + view.hideColumn(model.cols - 1); + QCOMPARE(view.isColumnHidden(model.cols - 1), true); + model.simulateMoveRows(); + QCOMPARE(view.isColumnHidden(model.cols - 1), true); } void tst_QTreeView::rowHidden() @@ -2607,7 +2625,7 @@ class TestTreeViewStyle : public QProxyStyle { public: TestTreeViewStyle() : indentation(20) {} - int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const Q_DECL_OVERRIDE + int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override { if (metric == QStyle::PM_TreeViewIndentation) return indentation; @@ -4565,6 +4583,49 @@ void tst_QTreeView::statusTip() QTRY_COMPARE(mw.statusBar()->currentMessage(), QLatin1String("Header 0 -- Status")); } +class FetchMoreModel : public QStandardItemModel +{ +public: + FetchMoreModel() : QStandardItemModel(), canFetchReady(false) + { + for (int i = 0; i < 20; ++i) { + QStandardItem *item = new QStandardItem("Row"); + item->appendRow(new QStandardItem("Child")); + appendRow(item); + } + } + bool canFetchMore(const QModelIndex &parent) const override + { + if (!canFetchReady || !parent.isValid()) + return false; + if (!parent.parent().isValid()) + return rowCount(parent) < 20; + return false; + } + void fetchMore(const QModelIndex &parent) override + { + QStandardItem *item = itemFromIndex(parent); + for (int i = 0; i < 19; ++i) + item->appendRow(new QStandardItem(QString("New Child %1").arg(i))); + } + bool canFetchReady; +}; + +void tst_QTreeView::fetchMoreOnScroll() +{ + QTreeView tw; + FetchMoreModel im; + tw.setModel(&im); + tw.show(); + tw.expandAll(); + QVERIFY(QTest::qWaitForWindowActive(&tw)); + // Now we can allow the fetch to happen + im.canFetchReady = true; + tw.verticalScrollBar()->setValue(tw.verticalScrollBar()->maximum()); + // The item should have now fetched the other children, thus bringing the count to 20 + QCOMPARE(im.item(19)->rowCount(), 20); +} + static void fillModeltaskQTBUG_8376(QAbstractItemModel &model) { model.insertRow(0); diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index fa7f9596da..d0e6407283 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -159,6 +159,7 @@ private slots: void taskQTBUG_34717_collapseAtBottom(); void task20345_sortChildren(); void getMimeDataWithInvalidItem(); + void testVisualItemRect(); public slots: void itemSelectionChanged(); @@ -332,10 +333,19 @@ void tst_QTreeWidget::addTopLevelItem() for (int i = 0; i < 10; ++i) tops << new TreeItem(); int count = tree.topLevelItemCount(); - tree.insertTopLevelItems(100000, tops); - // ### fixme + tree.insertTopLevelItems(count, tops); QCOMPARE(tree.topLevelItemCount(), count + 10); } + + // invalid insert + { + tops.clear(); + for (int i = 0; i < 10; ++i) + tops << new TreeItem(); + int count = tree.topLevelItemCount(); + tree.insertTopLevelItems(100000, tops); // should be a no-op + QCOMPARE(tree.topLevelItemCount(), count); + } } void tst_QTreeWidget::currentItem_data() @@ -3269,7 +3279,7 @@ void tst_QTreeWidget::task239150_editorWidth() QVERIFY(tree.itemWidget(&item, 0) == 0); tree.editItem(&item); QVERIFY(tree.itemWidget(&item, 0)); - QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().width(item.text(0))); + QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().horizontalAdvance(item.text(0))); } } @@ -3449,9 +3459,38 @@ void tst_QTreeWidget::getMimeDataWithInvalidItem() { CustomTreeWidget w; QTest::ignoreMessage(QtWarningMsg, "QTreeWidget::mimeData: Null-item passed"); - QMimeData *md = w.mimeData(QList<QTreeWidgetItem*>() << Q_NULLPTR); + QMimeData *md = w.mimeData(QList<QTreeWidgetItem*>() << nullptr); QVERIFY(!md); } +// visualItemRect returned a wrong rect when the columns were moved +// (-> logical index != visual index). see QTBUG-28733 +void tst_QTreeWidget::testVisualItemRect() +{ + QTreeWidget tw; + tw.setColumnCount(2); + QTreeWidgetItem *item = new QTreeWidgetItem(&tw); + item->setText(0, "text 0"); + item->setText(1, "text 1"); + + static const int sectionSize = 30; + tw.header()->setStretchLastSection(false); + tw.header()->setMinimumSectionSize(sectionSize); + tw.header()->resizeSection(0, sectionSize); + tw.header()->resizeSection(1, sectionSize); + tw.setRootIsDecorated(false); + tw.show(); + QVERIFY(QTest::qWaitForWindowExposed(&tw)); + + QRect r = tw.visualItemRect(item); + QCOMPARE(r.width(), sectionSize * 2); // 2 columns + tw.header()->moveSection(1, 0); + r = tw.visualItemRect(item); + QCOMPARE(r.width(), sectionSize * 2); // 2 columns + tw.hideColumn(0); + r = tw.visualItemRect(item); + QCOMPARE(r.width(), sectionSize); +} + QTEST_MAIN(tst_QTreeWidget) #include "tst_qtreewidget.moc" |