diff options
author | Pierre Rossi <pierre.rossi@nokia.com> | 2011-04-04 13:58:42 (GMT) |
---|---|---|
committer | Pierre Rossi <pierre.rossi@nokia.com> | 2011-04-04 14:15:51 (GMT) |
commit | d814e378987348ce2123d083b01ea6fb6c3e6bbf (patch) | |
tree | 6f64d54a01e4f6f367eaec385169216a342564c4 /src | |
parent | b60d82fd56897b1a1d3cc730172f71c27a497ede (diff) | |
download | Qt-d814e378987348ce2123d083b01ea6fb6c3e6bbf.zip Qt-d814e378987348ce2123d083b01ea6fb6c3e6bbf.tar.gz Qt-d814e378987348ce2123d083b01ea6fb6c3e6bbf.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/itemviews/qtableview.cpp | 21 | ||||
-rw-r--r-- | src/gui/itemviews/qtableview.h | 1 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index e494ee5..59a3d15 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -1104,6 +1104,21 @@ void QTableView::setRootIndex(const QModelIndex &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 +*/ void QTableView::setSelectionModel(QItemSelectionModel *selectionModel) { Q_D(QTableView); @@ -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(); } diff --git a/src/gui/itemviews/qtableview.h b/src/gui/itemviews/qtableview.h index d4be086..7ab9d08 100644 --- a/src/gui/itemviews/qtableview.h +++ b/src/gui/itemviews/qtableview.h @@ -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; |