Fix last > rowCount() assert in ClassModel Node dtor

Authored by buschinski on Aug 14 2018, 6:44 PM.

Description

Fix last > rowCount() assert in ClassModel Node dtor

Summary:
This patch fixes another assert in the classmodel.
This time it is the assert triggered from
Node::~Node -> ClassModel::nodesAboutToBeRemoved -> QAbstractItemModel::beginRemoveRows(index, first, last)

last > rowCount(), last was greater than the rowCount.

This is because in Node::removeNode the child was first removed from the childrenlist and then deleted.
But createIndex() & rowCount() rely on the item to still be in the model/list. Node::row() would simply return -1 which would result in an invalid index.

rowCount for invalid index < last Item

The solution is simple, like in Node::clear(), first delete the item and then remove it from the list.

Test Plan:

  • compile Qt 5.11.1 with debug&asserts enabled
  • compile kdevelop against this version of Qt
  • start kdevelop and open a project
  • open the Classes toolview
  • expand & collapse some items

-> assert/crash

Reviewers: KDevelop, brauch

Reviewed By: KDevelop, brauch

Subscribers: brauch, kdevelop-devel

Tags: KDevelop

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

Details

Committed
buschinskiAug 14 2018, 6:50 PM
Reviewer
KDevelop
Differential Revision
D14840: Fix last > rowCount() assert in ClassModel Node dtor
Parents
R32:f30ef7c6f137: Fix assert in ClassModel::nodesRemoved
Branches
Unknown
Tags
Unknown