diff --git a/src/commands/undohelper.cpp b/src/commands/undohelper.cpp index 936cb6cb51..136ff6a7b1 100644 --- a/src/commands/undohelper.cpp +++ b/src/commands/undohelper.cpp @@ -53,13 +53,11 @@ void UndoHelper::recordBeforeState() for (int j = 0; j < playlist.count(); ++j) { QScopedPointer clip(playlist.get_clip(j)); - QUuid uid = MLT.ensureHasUuid(clip->parent()); - if (clip->is_blank()) { - uid = MLT.ensureHasUuid(*clip); - } + QUuid uid = MLT.ensureHasUuid(*clip); m_insertedOrder << uid; Info &info = m_state[uid]; - if (!(m_hints & SkipXML) || m_xmlClips.contains(uid)) + if (!(m_hints & SkipXML) || m_xmlClips.contains(uid) + || m_xmlClips.contains(MLT.uuid(clip->parent()))) info.xml = MLT.XML(&clip->parent()); Mlt::ClipInfo clipInfo; playlist.clip_info(j, &clipInfo); @@ -89,14 +87,15 @@ void UndoHelper::recordAfterState() for (int j = 0; j < playlist.count(); ++j) { QScopedPointer clip(playlist.get_clip(j)); - QUuid uid = MLT.ensureHasUuid(clip->parent()); - if (clip->is_blank()) { - uid = MLT.ensureHasUuid(*clip); + QUuid uid = MLT.uuid(*clip); + if (uid.isNull()) { + uid = MLT.uuid(clip->parent()); } /* Clips not previously in m_state are new */ if (!m_state.contains(uid)) { UNDOLOG << "New clip at" << i << j; + uid = MLT.ensureHasUuid(*clip); m_clipsAdded << uid; m_affectedTracks << i; } else { @@ -236,11 +235,7 @@ void UndoHelper::undoChanges() QScopedPointer clip(playlist.get_clip(currentIndex)); Q_ASSERT(currentIndex < playlist.count()); Q_ASSERT(!clip.isNull()); - if (info.isBlank) { - MLT.setUuid(*clip, uid); - } else { - MLT.setUuid(clip->parent(), uid); - } + MLT.setUuid(*clip, uid); if (info.group >= 0) { clip->set(kShotcutGroupProperty, info.group); } @@ -273,8 +268,7 @@ void UndoHelper::undoChanges() // Re-apply timeline-specific properties that are not encoded in the producer XML. QScopedPointer clip(playlist.get_clip(currentIndex)); if (clip && clip->is_valid()) { - // Restore UUID on the parent producer for this non-blank clip. - MLT.setUuid(clip->parent(), uid); + MLT.setUuid(*clip, uid); // Restore grouping metadata on the clip, if any was recorded. if (info.group >= 0) { clip->set(kShotcutGroupProperty, info.group); @@ -326,10 +320,7 @@ void UndoHelper::undoChanges() Mlt::Playlist playlist(*trackProducer); for (int i = playlist.count() - 1; i >= 0; --i) { QScopedPointer clip(playlist.get_clip(i)); - QUuid uid = MLT.uuid(clip->parent()); - if (clip->is_blank()) { - uid = MLT.uuid(*clip); - } + QUuid uid = MLT.uuid(*clip); if (m_clipsAdded.removeOne(uid)) { UNDOLOG << "Removing clip at" << i; m_model.beginRemoveRows(m_model.index(trackIndex), i, i); @@ -443,11 +434,7 @@ void UndoHelper::restoreAffectedTracks() QScopedPointer clip(playlist.get_clip(currentIndex)); Q_ASSERT(currentIndex < playlist.count()); Q_ASSERT(!clip.isNull()); - if (info.isBlank) { - MLT.setUuid(*clip, uid); - } else { - MLT.setUuid(clip->parent(), uid); - } + MLT.setUuid(*clip, uid); AudioLevelsTask::start(clip->parent(), &m_model, modelIndex); } } diff --git a/src/docks/timelinedock.cpp b/src/docks/timelinedock.cpp index d0ee3af8e6..810d95c019 100644 --- a/src/docks/timelinedock.cpp +++ b/src/docks/timelinedock.cpp @@ -48,6 +48,8 @@ #include "widgets/textproducerwidget.h" #include "widgets/toneproducerwidget.h" +#include + #include #include #include @@ -2671,10 +2673,14 @@ void TimelineDock::removeSelection(bool withCopy) else MAIN.undoStack()->beginMacro(tr("Remove %1 from timeline").arg(n)); } - int trackIndex, clipIndex; - for (const auto &uuid : selectionUuids()) { - m_model.findClipByUuid(uuid, trackIndex, clipIndex); - remove(trackIndex, clipIndex, n > 1); + auto clips = selection(); + std::sort(clips.begin(), clips.end(), [](const QPoint &a, const QPoint &b) { + if (a.y() != b.y()) + return a.y() > b.y(); + return a.x() > b.x(); + }); + for (const auto &clip : clips) { + remove(clip.y(), clip.x(), n > 1); } if (n > 1) MAIN.undoStack()->endMacro(); @@ -2693,10 +2699,14 @@ void TimelineDock::liftSelection() int n = selection().size(); if (n > 1) MAIN.undoStack()->beginMacro(tr("Lift %1 from timeline").arg(n)); - int trackIndex, clipIndex; - for (const auto &uuid : selectionUuids()) { - m_model.findClipByUuid(uuid, trackIndex, clipIndex); - lift(trackIndex, clipIndex, n > 1); + auto clips = selection(); + std::sort(clips.begin(), clips.end(), [](const QPoint &a, const QPoint &b) { + if (a.y() != b.y()) + return a.y() > b.y(); + return a.x() > b.x(); + }); + for (const auto &clip : clips) { + lift(clip.y(), clip.x(), n > 1); } if (n > 1) MAIN.undoStack()->endMacro();