summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@nokia.com>2011-04-04 15:58:42 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2011-05-10 12:54:44 +0200
commit5346d77e8ccba0a7bfb0cc1f257a26865a1c9d42 (patch)
tree7a58ff299afd4caeca3c9baa560eb21b212216de /src
parent55bfa460d2974ebe5ace4def554c5f54d6103312 (diff)
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)
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qtableview.cpp21
-rw-r--r--src/gui/itemviews/qtableview.h1
2 files changed, 21 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp
index e494ee5564..59a3d15a62 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 d4be0868c0..7ab9d0817c 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;