Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Improve handling of groups created by split audio in view

parent 8d729c2a
......@@ -593,3 +593,8 @@ Mlt::Profile *Core::thumbProfile()
}
return m_thumbProfile.get();
}
void Core::clearSelection()
{
m_mainWindow->getCurrentTimeline()->controller()->clearSelection();
}
......@@ -169,6 +169,7 @@ public:
/** Show / hide keyframes for a timeline clip */
void showClipKeyframes(ObjectId id, bool enable);
Mlt::Profile *thumbProfile();
void clearSelection();
private:
explicit Core();
......
......@@ -309,7 +309,19 @@ void GroupsModel::setGroup(int id, int groupId)
m_upLink[id] = groupId;
if (groupId != -1) {
m_downLink[groupId].insert(id);
if (getType(groupId) == GroupType::Leaf) {
auto ptr = m_parent.lock();
if (ptr) {
QModelIndex ix;
if (ptr->isClip(id)) {
ix = ptr->makeClipIndexFromID(id);
} else if (ptr->isComposition(id)) {
ix = ptr->makeCompositionIndexFromID(id);
}
if (ix.isValid()) {
ptr->dataChanged(ix, ix, {TimelineModel::GroupedRole});
}
}
if (getType(groupId) == GroupType::Leaf) {
promoteToGroup(groupId, GroupType::Normal);
}
}
......@@ -324,6 +336,17 @@ void GroupsModel::removeFromGroup(int id)
if (parent != -1) {
Q_ASSERT(getType(parent) != GroupType::Leaf);
m_downLink[parent].erase(id);
QModelIndex ix;
auto ptr = m_parent.lock();
if (!ptr) Q_ASSERT(false);
if (ptr->isClip(id)) {
ix = ptr->makeClipIndexFromID(id);
} else if (ptr->isComposition(id)) {
ix = ptr->makeCompositionIndexFromID(id);
}
if (ix.isValid()) {
ptr->dataChanged(ix, ix, {TimelineModel::GroupedRole});
}
if (m_downLink[parent].size() == 0) {
downgradeToLeaf(parent);
}
......@@ -371,10 +394,6 @@ bool GroupsModel::mergeSingleGroups(int id, Fun &undo, Fun &redo)
for (const auto &group : parents) {
int old = m_upLink[group.first];
setGroup(group.first, group.second);
if (old == -1 && group.second != -1 && ptr->isClip(group.first)) {
QModelIndex ix = ptr->makeClipIndexFromID(group.first);
ptr->dataChanged(ix, ix, {TimelineModel::GroupedRole});
}
}
return true;
};
......@@ -564,6 +583,7 @@ bool GroupsModel::createGroupAtSameLevel(int id, std::unordered_set<int> to_add,
int gid = TimelineModel::getNextId();
std::unordered_map<int, int> old_parents;
to_add.insert(id);
for (int g : to_add) {
Q_ASSERT(m_upLink.count(g) > 0);
old_parents[g] = m_upLink[g];
......
......@@ -458,6 +458,8 @@ bool TimelineFunctions::requestSplitAudio(std::shared_ptr<TimelineItemModel> tim
std::function<bool(void)> redo = []() { return true; };
const std::unordered_set<int> clips = timeline->getGroupElements(clipId);
bool done = false;
// Now clear selection so we don't mess with groups
pCore->clearSelection();
for (int cid : clips) {
if (!timeline->getClipPtr(cid)->hasAudio() || timeline->getClipPtr(cid)->clipState() == PlaylistState::AudioOnly) {
// clip without audio or audio only, skip
......
......@@ -1018,8 +1018,10 @@ int TimelineModel::requestClipsGroup(const std::unordered_set<int> &ids, bool lo
Fun undo = []() { return true; };
Fun redo = []() { return true; };
if (m_temporarySelectionGroup > -1) {
int firstChild = *m_groups->getDirectChildren(m_temporarySelectionGroup).begin();
requestClipUngroup(firstChild, undo, redo);
m_groups->destructGroupItem(m_temporarySelectionGroup);
// We don't log in undo the selection changes
//int firstChild = *m_groups->getDirectChildren(m_temporarySelectionGroup).begin();
//requestClipUngroup(firstChild, undo, redo);
m_temporarySelectionGroup = -1;
}
int result = requestClipsGroup(ids, undo, redo, type);
......
......@@ -1548,3 +1548,13 @@ bool TimelineController::ungroupClips(int clipId)
{
return m_model->requestClipUngroup(clipId);
}
void TimelineController::clearSelection()
{
if (m_model->m_temporarySelectionGroup >= 0) {
m_model->m_groups->destructGroupItem(m_model->m_temporarySelectionGroup);
m_model->m_temporarySelectionGroup = -1;
}
m_selection.selectedItems.clear();
emit selectionChanged();
}
......@@ -75,6 +75,9 @@ public:
/* @brief Add a clip id to current selection
*/
Q_INVOKABLE void addSelection(int newSelection);
/* @brief Clear current selection and inform the view
*/
void clearSelection();
/* @brief returns current timeline's zoom factor
*/
Q_INVOKABLE double scaleFactor() const;
......
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