diff options
-rw-r--r-- | src/gui/itemviews/qtreeview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qtreeview/tst_qtreeview.cpp | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index 1a8a686..ffd1ad0 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -1357,7 +1357,7 @@ QItemViewPaintPairs QTreeViewPrivate::draggablePaintPairs(const QModelIndexList void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItemV4 *option, const QModelIndex ¤t) const { - const int row = current.row(); + const int row = viewIndex(current); // get the index in viewItems[] option->state = option->state | (viewItems.at(row).expanded ? QStyle::State_Open : QStyle::State_None) | (viewItems.at(row).hasChildren ? QStyle::State_Children : QStyle::State_None) | (viewItems.at(row).hasMoreSiblings ? QStyle::State_Sibling : QStyle::State_None); diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index c0747a8..07a5a7d 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -245,6 +245,7 @@ private slots: void taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint(); void taskQTBUG_11466_keyboardNavigationRegression(); void taskQTBUG_13567_removeLastItemRegression(); + void taskQTBUG_25333_adjustViewOptionsForIndex(); }; class QtTestModel: public QAbstractItemModel @@ -3038,6 +3039,7 @@ void tst_QTreeView::styleOptionViewItem() // Test the rendering to pixmap before painting the widget. // The rendering to pixmap should not depend on having been // painted already yet. + delegate.count = 0; QItemSelection sel(model.index(0,0), model.index(0,modelColumns-1)); QRect rect; view.aiv_priv()->renderToPixmap(sel.indexes(), &rect); @@ -4008,5 +4010,46 @@ void tst_QTreeView::taskQTBUG_13567_removeLastItemRegression() CHECK_VISIBLE(198, 0); } +// From QTBUG-25333 (QTreeWidget drag crashes when there was a hidden item in tree) +// The test passes simply if it doesn't crash, hence there are no calls +// to QCOMPARE() or QVERIFY(). +// Note: define QT_BUILD_INTERNAL to run this test +void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex() +{ + PublicView view; + QStandardItemModel model; + QStandardItem *item1 = new QStandardItem("Item1"); + QStandardItem *item2 = new QStandardItem("Item2"); + QStandardItem *item3 = new QStandardItem("Item3"); + QStandardItem *data1 = new QStandardItem("Data1"); + QStandardItem *data2 = new QStandardItem("Data2"); + QStandardItem *data3 = new QStandardItem("Data3"); + + // Create a treeview + model.appendRow(QList<QStandardItem*>() << item1 << data1 ); + model.appendRow(QList<QStandardItem*>() << item2 << data2 ); + model.appendRow(QList<QStandardItem*>() << item3 << data3 ); + + view.setModel(&model); + + // Hide a row + view.setRowHidden(1, QModelIndex(), true); + view.expandAll(); + + view.show(); + +#ifdef QT_BUILD_INTERNAL + { + QStyleOptionViewItemV4 option; + + view.aiv_priv()->adjustViewOptionsForIndex(&option, model.indexFromItem(item1)); + + view.aiv_priv()->adjustViewOptionsForIndex(&option, model.indexFromItem(item3)); + } +#endif + +} + + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" |