<table><tr><td style="">hein created this revision.<br />Restricted Application added a project: Plasma.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D7139" rel="noreferrer">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>TaskGroupingProxyModel uses a simple QVector<QVector<int>> populated<br />
with source model row indices to represent the task group tree. To<br />
implement QAbstractItemModel::parent(), its implementation of index()<br />
encodes row indices of the top-level vector into the internal ids of<br />
child item model indices. This allows parent() to produce the parent<br />
model index by simply decoding the parent row from the passed-in child<br />
index and call index() with that row.</p>
<p>Top-level row indices shift up and down as the list of top-level items<br />
changes, invalidating those internal ids. QModelIndex is not meant to<br />
be stored, and the proxy model does take care of updating any persis-<br />
tent model indexes with new ids, so this should be fine.</p>
<p>However, where it falls apart is that as internal ids are invalidated,<br />
a QSortFilterProxyModel on top of this proxy (i.e. TasksModel) may end<br />
up with multiple indexes with identical internal ids in its mappings,<br />
causing it to mess up its mappings as it uses them (e.g. taking things<br />
from them). This causes the often-reported crash/assert there.</p>
<p>The fix is to refactor index()/parent() not to rely on row indices as<br />
internal ids, but instead use pointers to internal data structures<br />
instead.</p>
<p>This patch achieves this by changing the map to QVector<QVector<int> *>.<br />
This screams fugly, but the alternative would basically just be to<br />
create some wrapper struct to hide the fugly appeareance a little,<br />
which I don't think is worth it.</p>
<p>On the flip side, it saves a QVector::replace() call as a multable<br />
vector iterator can work directly on a vector without making a copy,<br />
and it's now no longer necessary to update the persistent model<br />
indices.</p>
<p>BUG:381006</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R120 Plasma Workspace</div></div></div><br /><div><strong>BRANCH</strong><div><div>master</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D7139" rel="noreferrer">https://phabricator.kde.org/D7139</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>libtaskmanager/taskgroupingproxymodel.cpp</div></div></div><br /><div><strong>To: </strong>hein, Plasma, davidedmundson<br /><strong>Cc: </strong>plasma-devel, ZrenBot, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol, mart, lukas<br /></div>