diff options
Diffstat (limited to 'tests/auto/qtreeview')
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 129 |
1 files changed, 128 insertions, 1 deletions
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index e7d548f..3d4e45e 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -212,8 +212,8 @@ private slots: void indexRowSizeHint(); void addRowsWhileSectionsAreHidden(); - void filterProxyModelCrash(); + void styleOptionViewItem(); // task-specific tests: void task174627_moveLeftToRoot(); @@ -229,6 +229,8 @@ private slots: void task238873_avoidAutoReopening(); void task244304_clickOnDecoration(); void task246536_scrollbarsNotWorking(); + void task250683_wrongSectionSize(); + void task239271_addRowsWithFirstColumnHidden(); void task254234_proxySort(); }; @@ -2037,6 +2039,8 @@ void tst_QTreeView::scrollTo() // view.show(); + view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); //some styles change that in Polish + view.resize(300, 200); //view.verticalScrollBar()->setValue(0); @@ -2049,6 +2053,7 @@ void tst_QTreeView::scrollTo() QCOMPARE(view.verticalScrollBar()->value(), 5); view.scrollTo(model.index(60, 60, QModelIndex())); + CHECK_VISIBLE(60,60); view.scrollTo(model.index(60, 30, QModelIndex())); CHECK_VISIBLE(60,30); @@ -2857,6 +2862,75 @@ void tst_QTreeView::filterProxyModelCrash() view.repaint(); //used to crash } +void tst_QTreeView::styleOptionViewItem() +{ + class MyDelegate : public QStyledItemDelegate + { + public: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const + { + QVERIFY(qstyleoption_cast<const QStyleOptionViewItemV4 *>(&option)); + QStyleOptionViewItemV4 opt(option); + initStyleOption(&opt, index); + + QVERIFY(!opt.text.isEmpty()); + QCOMPARE(opt.index, index); + QCOMPARE(!(opt.features & QStyleOptionViewItemV2::Alternate), !(index.row() % 2)); + QCOMPARE(!(opt.features & QStyleOptionViewItemV2::HasCheckIndicator), !opt.text.contains("Checkable")); + + if (opt.text.contains("Beginning")) + QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Beginning); + + if (opt.text.contains("Middle")) + QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::Middle); + + if (opt.text.contains("End")) + QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::End); + + if (opt.text.contains("OnlyOne")) + QCOMPARE(opt.viewItemPosition, QStyleOptionViewItemV4::OnlyOne); + + if (opt.text.contains("Checked")) + QCOMPARE(opt.checkState, Qt::Checked); + else + QCOMPARE(opt.checkState, Qt::Unchecked); + + QVERIFY(!opt.text.contains("Assert")); + + QStyledItemDelegate::paint(painter, option, index); + count++; + } + mutable int count; + }; + + QTreeView view; + QStandardItemModel model; + view.setModel(&model); + MyDelegate delegate; + view.setItemDelegate(&delegate); + model.appendRow(QList<QStandardItem*>() + << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + model.appendRow(QList<QStandardItem*>() + << new QStandardItem("Beginning") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + model.appendRow(QList<QStandardItem*>() + << new QStandardItem("OnlyOne") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") ); + QStandardItem *checkable = new QStandardItem("Checkable"); + checkable->setCheckable(true); + QStandardItem *checked = new QStandardItem("Checkable Checked"); + checkable->setCheckable(true); + checked->setCheckState(Qt::Checked); + model.appendRow(QList<QStandardItem*>() + << new QStandardItem("Beginning") << checkable << checked << new QStandardItem("End") ); + + view.setFirstColumnSpanned(2, QModelIndex(), true); + view.setAlternatingRowColors(true); + + delegate.count = 0; + view.showMaximized(); + QTest::qWait(30); + QVERIFY(delegate.count >= 13); +} + class task174627_TreeView : public QTreeView { Q_OBJECT @@ -3282,6 +3356,59 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() QVERIFY(o.count > 0); } +void tst_QTreeView::task250683_wrongSectionSize() +{ + QDirModel model; + QTreeView treeView; + treeView.header()->setResizeMode(QHeaderView::ResizeToContents); + treeView.setModel(&model); + treeView.setColumnHidden(2, true); + treeView.setColumnHidden(3, true); + + treeView.show(); + QTest::qWait(100); + + QCOMPARE(treeView.header()->sectionSize(0) + treeView.header()->sectionSize(1), treeView.viewport()->width()); +} + +void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() +{ + class MyDelegate : public QStyledItemDelegate + { + public: + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const + { + paintedIndexes << index; + QStyledItemDelegate::paint(painter, option, index); + } + + mutable QSet<QModelIndex> paintedIndexes; + }; + + QTreeView view; + QStandardItemModel model; + view.setModel(&model); + MyDelegate delegate; + view.setItemDelegate(&delegate); + QStandardItem root0("root0"), root1("root1"); + model.invisibleRootItem()->appendRow(QList<QStandardItem*>() << &root0 << &root1); + QStandardItem sub0("sub0"), sub00("sub00"); + root0.appendRow(QList<QStandardItem*>() << &sub0 << &sub00); + view.expand(root0.index()); + + view.hideColumn(0); + view.show(); + QTest::qWait(200); + delegate.paintedIndexes.clear(); + QStandardItem sub1("sub1"), sub11("sub11"); + root0.appendRow(QList<QStandardItem*>() << &sub1 << &sub11); + + QTest::qWait(200); + //items in the 2nd column should have been painted + QVERIFY(delegate.paintedIndexes.contains(sub00.index())); + QVERIFY(delegate.paintedIndexes.contains(sub11.index())); +} + void tst_QTreeView::task254234_proxySort() { //based on tst_QTreeView::sortByColumn |