diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-07 15:29:08 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-05-07 15:32:16 (GMT) |
commit | 36932e49769726a28a7ffbc3d5a11b4bffb9952f (patch) | |
tree | 447b3327d1da6864f85fabf384f783dfc1275720 /tests/auto/qtreeview | |
parent | 4b5355b0a708e9dfa00f358cc932b6c314d832e7 (diff) | |
download | Qt-36932e49769726a28a7ffbc3d5a11b4bffb9952f.zip Qt-36932e49769726a28a7ffbc3d5a11b4bffb9952f.tar.gz Qt-36932e49769726a28a7ffbc3d5a11b4bffb9952f.tar.bz2 |
spanning columns did not have ViewItemPosition QStyleOptionViewItemV4::OnlyOne set
The new autotest tests lots of the flags of the QStyleOption
Reviewed-by: Thierry
Task-number: 252616
Diffstat (limited to 'tests/auto/qtreeview')
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index 71d7b4d..c0244e6 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -208,8 +208,8 @@ private slots: void indexRowSizeHint(); void addRowsWhileSectionsAreHidden(); - void filterProxyModelCrash(); + void styleOptionViewItem(); // task-specific tests: void task174627_moveLeftToRoot(); @@ -2849,6 +2849,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 @@ -3328,7 +3397,5 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() QVERIFY(delegate.paintedIndexes.contains(sub11.index())); } - - QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" |