QAbstractItemView::sizeHintForRow()/Column: Check for null delegate.
The delegate may be null in QHeaderView. Task-number: QTBUG-48543 Change-Id: I4d3ba104b0b57431e8765271dc2dc880be096672 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
e56938b4bb
commit
2042a091a3
@ -3020,8 +3020,8 @@ int QAbstractItemView::sizeHintForRow(int row) const
|
|||||||
const QModelIndex index = d->model->index(row, c, d->root);
|
const QModelIndex index = d->model->index(row, c, d->root);
|
||||||
if (QWidget *editor = d->editorForIndex(index).widget.data())
|
if (QWidget *editor = d->editorForIndex(index).widget.data())
|
||||||
height = qMax(height, editor->height());
|
height = qMax(height, editor->height());
|
||||||
int hint = d->delegateForIndex(index)->sizeHint(option, index).height();
|
if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index))
|
||||||
height = qMax(height, hint);
|
height = qMax(height, delegate->sizeHint(option, index).height());
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@ -3050,8 +3050,8 @@ int QAbstractItemView::sizeHintForColumn(int column) const
|
|||||||
const QModelIndex index = d->model->index(r, column, d->root);
|
const QModelIndex index = d->model->index(r, column, d->root);
|
||||||
if (QWidget *editor = d->editorForIndex(index).widget.data())
|
if (QWidget *editor = d->editorForIndex(index).widget.data())
|
||||||
width = qMax(width, editor->sizeHint().width());
|
width = qMax(width, editor->sizeHint().width());
|
||||||
int hint = d->delegateForIndex(index)->sizeHint(option, index).width();
|
if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index))
|
||||||
width = qMax(width, hint);
|
width = qMax(width, delegate->sizeHint(option, index).width());
|
||||||
}
|
}
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,8 @@ private slots:
|
|||||||
void testStreamWithHide();
|
void testStreamWithHide();
|
||||||
void testStylePosition();
|
void testStylePosition();
|
||||||
|
|
||||||
|
void sizeHintCrash();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setupTestData(bool use_reset_model = false);
|
void setupTestData(bool use_reset_model = false);
|
||||||
void additionalInit();
|
void additionalInit();
|
||||||
@ -2879,5 +2881,15 @@ void tst_QHeaderView::testStylePosition()
|
|||||||
QCOMPARE(proxy.lastPosition, QStyleOptionHeader::OnlyOneSection);
|
QCOMPARE(proxy.lastPosition, QStyleOptionHeader::OnlyOneSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QHeaderView::sizeHintCrash()
|
||||||
|
{
|
||||||
|
QTreeView treeView;
|
||||||
|
QStandardItemModel *model = new QStandardItemModel(&treeView);
|
||||||
|
model->appendRow(new QStandardItem("QTBUG-48543"));
|
||||||
|
treeView.setModel(model);
|
||||||
|
treeView.header()->sizeHintForColumn(0);
|
||||||
|
treeView.header()->sizeHintForRow(0);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QHeaderView)
|
QTEST_MAIN(tst_QHeaderView)
|
||||||
#include "tst_qheaderview.moc"
|
#include "tst_qheaderview.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user