From 6d76e943dab0971d376cebb15fe531efc60622ac Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 5 May 2014 10:59:56 +0200 Subject: Fix visual index lookup in QTreeViewPrivate::adjustViewOptionsForIndex(). Determine the visual index by looking up the column of the QModelIndex in the logicalIndices array instead of looping. Task-number: QTBUG-37813 Change-Id: I5c3c73c67537877b03cdc2c36a52041d99f7f49d Reviewed-by: David Faure (cherry picked from qtbase/85aef2dd4b059d2ba9cba4605d9fef87f3e2c4fc) --- tests/auto/qtreeview/tst_qtreeview.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index c80d04c68e..64196f0a52 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -249,6 +249,7 @@ private slots: void taskQTBUG_11466_keyboardNavigationRegression(); void taskQTBUG_13567_removeLastItemRegression(); void taskQTBUG_25333_adjustViewOptionsForIndex(); + void taskQTBUG_37813_crash(); #ifndef QT_NO_ANIMATION void quickExpandCollapse(); @@ -4092,5 +4093,31 @@ void tst_QTreeView::quickExpandCollapse() #endif +void tst_QTreeView::taskQTBUG_37813_crash() +{ + // QTBUG_37813: Crash in visual / logical index mapping in QTreeViewPrivate::adjustViewOptionsForIndex() + // when hiding/moving columns. It is reproduceable with a QTreeWidget only. +#ifdef QT_BUILD_INTERNAL + QTreeWidget treeWidget; + treeWidget.setDragEnabled(true); + treeWidget.setColumnCount(2); + QList items; + for (int r = 0; r < 2; ++r) { + QTreeWidgetItem *item = new QTreeWidgetItem(); + for (int c = 0; c < treeWidget.columnCount(); ++c) + item->setText(c, QString::fromLatin1("Row %1 Column %2").arg(r).arg(c)); + items.append(item); + } + treeWidget.addTopLevelItems(items); + treeWidget.setColumnHidden(0, true); + treeWidget.header()->moveSection(0, 1); + QItemSelection sel(treeWidget.model()->index(0, 0), treeWidget.model()->index(0, 1)); + QRect rect; + QAbstractItemViewPrivate *av = static_cast(qt_widget_private(&treeWidget)); + const QPixmap pixmap = av->renderToPixmap(sel.indexes(), &rect); + QVERIFY(pixmap.size().isValid()); +#endif // QT_BUILD_INTERNAL +} + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" -- cgit v1.2.3