Commit 3d4640be authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Fix crash with sortAllByName/Description

Summary:
Calling QTreeWidgetItem::takeChildren() on invisibleRootItem() results
in a crash because it calls QTreeModel::beginRemoveItems() which calls
QTreeModel::index() on that item which returns an invalid QModelIndex.

Instead iterate over topLevelItem's and sort them.

Test Plan:
- Sort all by name/description causes a crash
- Apply the patch then try again, it should work

Reviewers: mlaurent

Reviewed By: mlaurent

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24615
parent 3784ba13
......@@ -1371,16 +1371,20 @@ void TreeView::sort(const int sortCmd)
TreeItem *itemToSort;
if (sortType == SortByName || sortType == SortByDescription) {
itemToSort = static_cast<TreeItem *>(selectedItem());
sortItem(itemToSort, sortType);
} else if (sortType == SortAllByDescription) {
sortType = SortByDescription;
itemToSort = static_cast<TreeItem *>(invisibleRootItem());
for (int i = 0; i < topLevelItemCount(); ++i) {
itemToSort = static_cast<TreeItem *>(topLevelItem(i));
sortItem(itemToSort, sortType);
}
} else { /* if (sortType == SortAllByName) */
sortType = SortByName;
itemToSort = static_cast<TreeItem *>(invisibleRootItem());
for (int i = 0; i < topLevelItemCount(); ++i) {
itemToSort = static_cast<TreeItem *>(topLevelItem(i));
sortItem(itemToSort, sortType);
}
}
// proceed to the sorting
sortItem(itemToSort, sortType);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment