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 <david.faure@kdab.com>bb10
parent
344562aff7
commit
85aef2dd4b
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the QtWidgets module of the Qt Toolkit.
|
||||
|
|
@ -1421,15 +1421,8 @@ void QTreeViewPrivate::adjustViewOptionsForIndex(QStyleOptionViewItem *option, c
|
|||
const int right = (spanning ? header->visualIndex(0) : header->count() - 1 );
|
||||
calcLogicalIndices(&logicalIndices, &viewItemPosList, left, right);
|
||||
|
||||
int columnIndex = 0;
|
||||
for (int visualIndex = 0; visualIndex < current.column(); ++visualIndex) {
|
||||
int logicalIndex = header->logicalIndex(visualIndex);
|
||||
if (!header->isSectionHidden(logicalIndex)) {
|
||||
++columnIndex;
|
||||
}
|
||||
}
|
||||
|
||||
option->viewItemPosition = viewItemPosList.at(columnIndex);
|
||||
const int visualIndex = logicalIndices.indexOf(current.column());
|
||||
option->viewItemPosition = viewItemPosList.at(visualIndex);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
||||
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
|
|
@ -261,6 +261,7 @@ private slots:
|
|||
void taskQTBUG_18539_emitLayoutChanged();
|
||||
void taskQTBUG_8176_emitOnExpandAll();
|
||||
void taskQTBUG_34717_collapseAtBottom();
|
||||
void taskQTBUG_37813_crash();
|
||||
void testInitialFocus();
|
||||
};
|
||||
|
||||
|
|
@ -4327,5 +4328,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<QTreeWidgetItem *> 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<QAbstractItemViewPrivate*>(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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue