QTreeView: don't call model.index(-1, 0) when using spanning items

drawTree() does
    QPoint hoverPos = d->viewport->mapFromGlobal(QCursor::pos());
    d->hoverBranch = d->itemDecorationAt(hoverPos);
and itemDecorationAt does
    const QModelIndex index = q->indexAt(pos);
which might very well be an invalid index.

Change-Id: I7db98871543bd7e1c57fcc475d2646757bf2bb42
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
David Faure 2020-03-05 17:56:32 +01:00
parent f45d2dc543
commit 97422abcfc
2 changed files with 12 additions and 1 deletions

View File

@ -3755,6 +3755,7 @@ int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const
bool spanned = false;
if (!spanningIndexes.isEmpty()) {
const QModelIndex index = q->indexAt(pos);
if (index.isValid())
spanned = q->isFirstColumnSpanned(index.row(), index.parent());
}
const int column = spanned ? 0 : header->logicalIndexAt(pos.x());

View File

@ -270,6 +270,12 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
{
if (onlyValidCalls) {
Q_ASSERT(row >= 0);
Q_ASSERT(column >= 0);
Q_ASSERT(row < rows);
Q_ASSERT(column < cols);
}
if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) {
return QModelIndex();
}
@ -378,6 +384,7 @@ public:
mutable bool fetched = false;
bool decorationsEnabled = false;
bool statusTipsEnabled = false;
bool onlyValidCalls = false;
};
// Testing get/set functions
@ -2420,6 +2427,7 @@ void tst_QTreeView::hiddenItems()
void tst_QTreeView::spanningItems()
{
QtTestModel model(10, 10);
model.onlyValidCalls = true;
QTreeView view;
view.setModel(&model);
view.show();
@ -2459,6 +2467,8 @@ void tst_QTreeView::spanningItems()
}
}
QCOMPARE(view.sizeHintForColumn(0), w);
view.repaint(); // to check that this doesn't hit any assert
}
void tst_QTreeView::selectionOrderTest()