summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemviews/qtreeview.cpp2
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp73
2 files changed, 71 insertions, 4 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index ab03fea..f6c5cf0 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -1544,7 +1544,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
? logicalIndexBeforeLeft
: logicalIndices.at(currentLogicalSection - 1);
if (columnCount == 1 || (nextLogicalSection == 0 && prevLogicalSection == -1)
- || (headerSection == 0 && nextLogicalSection == -1))
+ || (headerSection == 0 && nextLogicalSection == -1) || spanning)
opt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
else if (headerSection == 0 || (nextLogicalSection != 0 && prevLogicalSection == -1))
opt.viewItemPosition = QStyleOptionViewItemV4::Beginning;
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"