https://bugs.kde.org/show_bug.cgi?id=381006

Eike Hein <h...@kde.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED
      Latest Commit|                            |https://commits.kde.org/pla
                   |                            |sma-workspace/3990ec2358106
                   |                            |875bd1d58ad65bd2a55ff4f1d73

--- Comment #15 from Eike Hein <h...@kde.org> ---
Git commit 3990ec2358106875bd1d58ad65bd2a55ff4f1d73 by Eike Hein.
Committed on 07/08/2017 at 10:24.
Pushed by hein into branch 'master'.

Fix QSortFilterProxyModelPrivate::updateChildrenMapping crash in libtaskmanager

Summary:
TaskGroupingProxyModel uses a simple QVector<QVector<int>> populated
with source model row indices to represent the task group tree. To
implement QAbstractItemModel::parent(), its implementation of index()
encodes row indices of the top-level vector into the internal ids of
child item model indices. This allows parent() to produce the parent
model index by simply decoding the parent row from the passed-in child
index and call index() with that row.

Top-level row indices shift up and down as the list of top-level items
changes, invalidating those internal ids. QModelIndex is not meant to
be stored, and the proxy model does take care of updating any persis-
tent model indexes with new ids, so this should be fine.

However, where it falls apart is that as internal ids are invalidated,
a QSortFilterProxyModel on top of this proxy (i.e. TasksModel) may end
up with multiple indexes with identical internal ids in its mappings,
causing it to mess up its mappings as it uses them (e.g. taking things
from them). This causes the often-reported crash/assert there.

The fix is to refactor index()/parent() not to rely on row indices as
internal ids, but instead use pointers to internal data structures
instead.

This patch achieves this by changing the map to QVector<QVector<int> *>.
This screams fugly, but the alternative would basically just be to
create some wrapper struct to hide the fugly appeareance a little,
which I don't think is worth it.

On the flip side, it saves a QVector::replace() call as a multable
vector iterator can work directly on a vector without making a copy,
and it's now no longer necessary to manually update the persistent
model indices beyond what endRemoveRows() does implicitly.

Reviewers: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7139

M  +54   -73   libtaskmanager/taskgroupingproxymodel.cpp

https://commits.kde.org/plasma-workspace/3990ec2358106875bd1d58ad65bd2a55ff4f1d73

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to