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:
parent
f45d2dc543
commit
97422abcfc
@ -3755,7 +3755,8 @@ int QTreeViewPrivate::itemDecorationAt(const QPoint &pos) const
|
|||||||
bool spanned = false;
|
bool spanned = false;
|
||||||
if (!spanningIndexes.isEmpty()) {
|
if (!spanningIndexes.isEmpty()) {
|
||||||
const QModelIndex index = q->indexAt(pos);
|
const QModelIndex index = q->indexAt(pos);
|
||||||
spanned = q->isFirstColumnSpanned(index.row(), index.parent());
|
if (index.isValid())
|
||||||
|
spanned = q->isFirstColumnSpanned(index.row(), index.parent());
|
||||||
}
|
}
|
||||||
const int column = spanned ? 0 : header->logicalIndexAt(pos.x());
|
const int column = spanned ? 0 : header->logicalIndexAt(pos.x());
|
||||||
if (!isTreePosition(column))
|
if (!isTreePosition(column))
|
||||||
|
@ -270,6 +270,12 @@ public:
|
|||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
|
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) {
|
if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) {
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
@ -378,6 +384,7 @@ public:
|
|||||||
mutable bool fetched = false;
|
mutable bool fetched = false;
|
||||||
bool decorationsEnabled = false;
|
bool decorationsEnabled = false;
|
||||||
bool statusTipsEnabled = false;
|
bool statusTipsEnabled = false;
|
||||||
|
bool onlyValidCalls = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Testing get/set functions
|
// Testing get/set functions
|
||||||
@ -2420,6 +2427,7 @@ void tst_QTreeView::hiddenItems()
|
|||||||
void tst_QTreeView::spanningItems()
|
void tst_QTreeView::spanningItems()
|
||||||
{
|
{
|
||||||
QtTestModel model(10, 10);
|
QtTestModel model(10, 10);
|
||||||
|
model.onlyValidCalls = true;
|
||||||
QTreeView view;
|
QTreeView view;
|
||||||
view.setModel(&model);
|
view.setModel(&model);
|
||||||
view.show();
|
view.show();
|
||||||
@ -2459,6 +2467,8 @@ void tst_QTreeView::spanningItems()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QCOMPARE(view.sizeHintForColumn(0), w);
|
QCOMPARE(view.sizeHintForColumn(0), w);
|
||||||
|
|
||||||
|
view.repaint(); // to check that this doesn't hit any assert
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTreeView::selectionOrderTest()
|
void tst_QTreeView::selectionOrderTest()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user