Fix crash & non working ungroup when several groups were selected

parent ecf504bf
......@@ -1223,12 +1223,37 @@ bool TimelineModel::requestClipUngroup(int id, bool logUndo)
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = requestClipUngroup(id, undo, redo);
if (result && logUndo) {
PUSH_UNDO(undo, redo, i18n("Ungroup clips"));
}
bool result = true;
if (id == m_temporarySelectionGroup) {
// Ungrouping selection group, so get id of all children
std::unordered_set<int> leaves = m_groups->getDirectChildren(id);
// Delete selection group without undo
Fun tmp_undo = []() { return true; };
Fun tmp_redo = []() { return true; };
requestClipUngroup(id, tmp_undo, tmp_redo);
m_temporarySelectionGroup = -1;
// Parse children to find groups
std::unordered_set<int> groups;
for (int item : leaves) {
if (m_groups->getLeaves(item).size() > 0) {
if (groups.count(item) <= 0) {
leaves.insert(item);
}
}
}
// destroy groups
for (int leave : leaves) {
result = requestClipUngroup(leave, undo, redo);
if (!result) {
break;
}
}
} else {
result = requestClipUngroup(id, undo, redo);
}
if (result && logUndo) {
PUSH_UNDO(undo, redo, i18n("Ungroup clips"));
}
return result;
}
......
......@@ -540,13 +540,11 @@ void TimelineController::unGroupSelection(int cid)
pCore->displayMessage(i18n("Select at least 1 item to ungroup"), InformationMessage, 500);
return;
}
if (cid == -1) {
for (int id : m_selection.selectedItems) {
if (m_model->m_groups->isInGroup(id) && !m_model->isInSelection(id)) {
cid = id;
break;
}
}
if (cid == -1 && m_model->m_temporarySelectionGroup >= 0) {
cid = m_model->m_temporarySelectionGroup;
}
if (m_model->m_groups->isInGroup(cid)) {
cid = m_model->m_groups->getRootId(cid);
}
if (cid > -1) {
m_model->requestClipUngroup(cid);
......
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