Fix spacer crash regression introduced in recent commit

parent 1e365f42
......@@ -148,7 +148,6 @@ Fun GroupsModel::destructGroupItem_lambda(int id)
removeFromGroup(id);
auto ptr = m_parent.lock();
if (!ptr) Q_ASSERT(false);
ptr->clearGroupSelectionOnDelete(id);
for (int child : m_downLink[id]) {
m_upLink[child] = -1;
QModelIndex ix;
......@@ -540,6 +539,7 @@ bool GroupsModel::split(int id, const std::function<bool(int)> &criterion, Fun &
// At each iteration, we create a new node by grouping together elements that are either leaves or already created nodes.
std::unordered_map<int, int> created_id; // to keep track of node that we create
std::vector<int> newGroups;
while (!new_groups.empty()) {
int selected = INT_MAX;
for (const auto &group : new_groups) {
......@@ -563,6 +563,7 @@ bool GroupsModel::split(int id, const std::function<bool(int)> &criterion, Fun &
}
Q_ASSERT(new_types.count(selected) != 0);
int gid = groupItems(group, undo, redo, new_types[selected], true);
newGroups.push_back(gid);
created_id[selected] = gid;
new_groups.erase(selected);
}
......@@ -575,6 +576,14 @@ bool GroupsModel::split(int id, const std::function<bool(int)> &criterion, Fun &
mergeSingleGroups(created_id[corresp[id]], undo, redo);
}
}
Fun clear_group_selection = [this, newGroups]() {
if (auto ptr = m_parent.lock()) {
// Ensure one of the deleted group was not selected
ptr->clearGroupSelectionOnDelete(newGroups);
}
return true;
};
PUSH_FRONT_LAMBDA(clear_group_selection, undo);
return res;
}
......
......@@ -4878,10 +4878,10 @@ void TimelineModel::requestClearSelection(bool onDeletion, Fun &undo, Fun &redo)
}
}
void TimelineModel::clearGroupSelectionOnDelete(int gid)
void TimelineModel::clearGroupSelectionOnDelete(std::vector<int>groups)
{
READ_LOCK();
if (gid == m_currentSelection) {
if (std::find(groups.begin(), groups.end(), m_currentSelection) != groups.end()) {
requestClearSelection(true);
}
}
......
......@@ -690,10 +690,10 @@ public:
*/
Q_INVOKABLE bool requestClearSelection(bool onDeletion = false);
/** @brief On group deletion, ensure the group was not selected, clear selection otherwise
@param gid The group id
/** @brief On groups deletion, ensure the groups were not selected, clear selection otherwise
@param groups The group ids
*/
void clearGroupSelectionOnDelete(int gid);
void clearGroupSelectionOnDelete(std::vector<int>groups);
// same function with undo/redo accumulation
void requestClearSelection(bool onDeletion, Fun &undo, Fun &redo);
......
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