diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-06-22 17:01:41 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-06-23 16:24:27 +0200 |
commit | a0bcad39033bddd9b9d14a524b829513105913d3 (patch) | |
tree | 633ebeaa2f8cc4df6ebcf5d69505f934117496b9 /src/corelib/itemmodels | |
parent | 5546f2df538c06f5e7cc3e218f03a9a0ef2d830e (diff) |
QAbstractProxyModel: delay headerDataChanged emissions when inserting/removing rows/columns
33c88f86b5b8714977719a8ccff0f7c15c9cbd44 added some logic to QAPM in
order to have it automatically emit headerDataChanged when rows/columns
were added or removed in the model. This was done as a stopgap measure
to prevent QAPM from asking for illegal indices in order to implement
automatic remapping of the section headings (since there's no
mapSectionToSource).
The commit seems to have introduced a regression in QHeaderView, which
isn't prepared to receive headerDataChanged while a row/column count
change is in progress. When receiving headerDataChanged, QHeaderView
will try to read the row/column count and will store it internally.
When it will then receive the signals for insertion/removal of
rows/columns, it will interpret it as a modification of the previously
stored value -- even if the value it stored was already correct.
Fix this by avoiding to have two signals in flight at the same time;
emit headerDataChanged as a queued invocation.
Task-number: QTBUG-114225
Change-Id: I521465a852b8c7135f22f730ead41dca760ba428
Pick-to: 6.5 6.6
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractproxymodel.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index c0321ee282..12974b5aaa 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -55,6 +55,13 @@ void QAbstractProxyModelPrivate::_q_sourceModelDestroyed() model = QAbstractItemModelPrivate::staticEmptyModel(); } +static auto emitHeaderDataChanged(QAbstractItemModel *model, + Qt::Orientation orientation, + int count) +{ + return [=](){ emit model->headerDataChanged(orientation, 0, count); }; +} + void QAbstractProxyModelPrivate::_q_sourceModelRowsAboutToBeInserted(const QModelIndex &parent, int, int) { if (parent.isValid()) @@ -70,7 +77,7 @@ void QAbstractProxyModelPrivate::_q_sourceModelRowsInserted(const QModelIndex &p Q_Q(QAbstractProxyModel); const int columnCount = q->columnCount(); if (columnCount > 0) - emit q->headerDataChanged(Qt::Horizontal, 0, columnCount - 1); + QMetaObject::invokeMethod(q, emitHeaderDataChanged(q, Qt::Horizontal, columnCount - 1), Qt::QueuedConnection); } } @@ -83,7 +90,7 @@ void QAbstractProxyModelPrivate::_q_sourceModelRowsRemoved(const QModelIndex &pa Q_Q(QAbstractProxyModel); const int columnCount = q->columnCount(); if (columnCount > 0) - emit q->headerDataChanged(Qt::Horizontal, 0, columnCount - 1); + QMetaObject::invokeMethod(q, emitHeaderDataChanged(q, Qt::Horizontal, columnCount - 1), Qt::QueuedConnection); } } @@ -102,7 +109,7 @@ void QAbstractProxyModelPrivate::_q_sourceModelColumnsInserted(const QModelIndex Q_Q(QAbstractProxyModel); const int rowCount = q->rowCount(); if (rowCount > 0) - emit q->headerDataChanged(Qt::Vertical, 0, rowCount - 1); + QMetaObject::invokeMethod(q, emitHeaderDataChanged(q, Qt::Vertical, rowCount - 1), Qt::QueuedConnection); } } @@ -114,7 +121,7 @@ void QAbstractProxyModelPrivate::_q_sourceModelColumnsRemoved(const QModelIndex Q_Q(QAbstractProxyModel); const int rowCount = q->rowCount(); if (rowCount > 0) - emit q->headerDataChanged(Qt::Vertical, 0, rowCount - 1); + QMetaObject::invokeMethod(q, emitHeaderDataChanged(q, Qt::Vertical, rowCount - 1), Qt::QueuedConnection); } } |