QTableView: prevent QTableView from hanging when removing rows.

The problem was introduced in cd2afafb where we removed some code that
was meant to adjust the header's offset upon row removal.
The problem with this is that visualIndexAt() is likely to return -1 in
QHeaderView::paintEvent, which in turn will lead to calling paintSection
for each and every section.

Task-number: QTBUG-18551
Reviewed-by: Thierry
(cherry picked from commit d814e378987348ce2123d083b01ea6fb6c3e6bbf)
bb10
Pierre Rossi 2011-04-04 15:58:42 +02:00 committed by Olivier Goffart
parent 55bfa460d2
commit 5346d77e8c
2 changed files with 21 additions and 1 deletions

View File

@ -1101,6 +1101,21 @@ void QTableView::setRootIndex(const QModelIndex &index)
QAbstractItemView::setRootIndex(index);
}
/*!
\reimp
*/
void QTableView::doItemsLayout()
{
Q_D(QTableView);
QAbstractItemView::doItemsLayout();
if (verticalScrollMode() == QAbstractItemView::ScrollPerItem)
d->verticalHeader->setOffsetToSectionPosition(verticalScrollBar()->value());
else
d->verticalHeader->setOffset(verticalScrollBar()->value());
if (!d->verticalHeader->updatesEnabled())
d->verticalHeader->setUpdatesEnabled(true);
}
/*!
\reimp
*/
@ -1975,9 +1990,13 @@ QModelIndexList QTableView::selectedIndexes() const
previous number of rows is specified by \a oldCount, and the new
number of rows is specified by \a newCount.
*/
void QTableView::rowCountChanged(int /*oldCount*/, int /*newCount*/ )
void QTableView::rowCountChanged(int oldCount, int newCount )
{
Q_D(QTableView);
//when removing rows, we need to disable updates for the header until the geometries have been
//updated and the offset has been adjusted, or we risk calling paintSection for all the sections
if (newCount < oldCount)
d->verticalHeader->setUpdatesEnabled(false);
d->doDelayedItemsLayout();
}

View File

@ -71,6 +71,7 @@ public:
void setModel(QAbstractItemModel *model);
void setRootIndex(const QModelIndex &index);
void setSelectionModel(QItemSelectionModel *selectionModel);
void doItemsLayout();
QHeaderView *horizontalHeader() const;
QHeaderView *verticalHeader() const;