Commit 8390f9e8 authored by hjk's avatar hjk
Browse files

TreeView: Announce sorting tree items

This is likely to be overkill but seems to fix a regression introduced
by e73a9c1b

: Persistent model indices owned by the selection
model of the watch view lose their model pointer and consequently
cause error messages to be emitted and potentially cause crashes.

Change-Id: I3334ca25bb5e2facf51d03c50647f95f55786498
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent cbc5f22b
......@@ -713,9 +713,21 @@ void TreeItem::removeChildren()
void TreeItem::sortChildren(const std::function<bool(const TreeItem *, const TreeItem *)> &cmp)
{
if (m_model) {
m_model->layoutAboutToBeChanged();
std::sort(m_children.begin(), m_children.end(), cmp);
m_model->layoutChanged();
if (const int n = rowCount()) {
QVector<TreeItem *> tmp = m_children;
std::sort(tmp.begin(), tmp.end(), cmp);
if (tmp == m_children) {
// Nothing changed.
} else {
QModelIndex idx = index();
m_model->beginRemoveRows(idx, 0, n - 1);
m_children.clear();
m_model->endRemoveRows();
m_model->beginInsertRows(idx, 0, n - 1);
tmp.swap(m_children);
m_model->endInsertRows();
}
}
} else {
std::sort(m_children.begin(), m_children.end(), cmp);
}
......
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