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

David Edmundson <k...@davidedmundson.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Latest Commit|https://commits.kde.org/pla |https://commits.kde.org/pla
                   |sma-workspace/3990ec2358106 |sma-workspace/d2f722a82ebeb
                   |875bd1d58ad65bd2a55ff4f1d73 |213a89efc209ec726a8188de6f0

--- Comment #18 from David Edmundson <k...@davidedmundson.co.uk> ---
Git commit d2f722a82ebeb213a89efc209ec726a8188de6f0 by David Edmundson, on
behalf of Eike Hein.
Committed on 22/08/2017 at 16:36.
Pushed by davidedmundson into branch 'Plasma/5.8'.

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/d2f722a82ebeb213a89efc209ec726a8188de6f0

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

Reply via email to