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

Commit e1b8a950 authored by Nicolas Carion's avatar Nicolas Carion

Fix deletion of AVGroup + tests

parent c44c437f
Pipeline #1805 passed with stage
in 14 minutes and 32 seconds
......@@ -1062,13 +1062,20 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
return true;
}
bool TimelineModel::requestItemDeletion(int clipId, Fun &undo, Fun &redo)
bool TimelineModel::requestItemDeletion(int itemId, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
if (m_groups->isInGroup(clipId)) {
return requestGroupDeletion(clipId, undo, redo);
if (m_groups->isInGroup(itemId)) {
return requestGroupDeletion(itemId, undo, redo);
}
if (isClip(itemId)) {
return requestClipDeletion(itemId, undo, redo);
}
if (isComposition(itemId)) {
return requestCompositionDeletion(itemId, undo, redo);
}
return requestClipDeletion(clipId, undo, redo);
Q_ASSERT(false);
return false;
}
bool TimelineModel::requestItemDeletion(int itemId, bool logUndo)
......@@ -1076,22 +1083,19 @@ bool TimelineModel::requestItemDeletion(int itemId, bool logUndo)
QWriteLocker locker(&m_lock);
TRACE(itemId, logUndo);
Q_ASSERT(isClip(itemId) || isComposition(itemId));
QString actionLabel;
if (m_groups->isInGroup(itemId)) {
bool res = requestGroupDeletion(itemId, logUndo);
TRACE_RES(res);
return res;
actionLabel = i18n("Remove group");
} else {
if (isClip(itemId)) {
actionLabel = i18n("Delete Clip");
} else {
actionLabel = i18n("Delete Composition");
}
}
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = false;
QString actionLabel;
if (isClip(itemId)) {
actionLabel = i18n("Delete Clip");
res = requestClipDeletion(itemId, undo, redo);
} else {
actionLabel = i18n("Delete Composition");
res = requestCompositionDeletion(itemId, undo, redo);
}
bool res = requestItemDeletion(itemId, undo, redo);
if (res && logUndo) {
PUSH_UNDO(undo, redo, actionLabel);
}
......@@ -1438,12 +1442,7 @@ bool TimelineModel::requestGroupDeletion(int clipId, bool logUndo)
TRACE_RES(false);
return false;
}
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = requestGroupDeletion(clipId, undo, redo);
if (res && logUndo) {
PUSH_UNDO(undo, redo, i18n("Remove group"));
}
bool res = requestItemDeletion(clipId, logUndo);
TRACE_RES(res);
return res;
}
......@@ -1479,7 +1478,8 @@ bool TimelineModel::requestGroupDeletion(int clipId, Fun &undo, Fun &redo)
}
}
if (one_child != -1) {
if (isSelection) {
if (m_groups->getType(current_group) == GroupType::Selection) {
Q_ASSERT(isSelection);
// in the case of a selection group, we delete the group but don't log it in the undo object
Fun tmp_undo = []() { return true; };
Fun tmp_redo = []() { return true; };
......
......@@ -391,14 +391,15 @@ protected:
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, double speed, Fun &undo, Fun &redo);
public:
/* @brief Deletes the given clip or composition from the timeline This
action is undoable Returns true on success. If it fails, nothing is
modified. If the clip/composition is in a group, the call is deferred to
requestGroupDeletion @param clipId is the ID of the clip/composition
/* @brief Deletes the given clip or composition from the timeline.
This action is undoable.
Returns true on success. If it fails, nothing is modified.
If the clip/composition is in a group, the call is deferred to requestGroupDeletion
@param clipId is the ID of the clip/composition
@param logUndo if set to false, no undo object is stored */
Q_INVOKABLE bool requestItemDeletion(int clipId, bool logUndo = true);
Q_INVOKABLE bool requestItemDeletion(int itemId, bool logUndo = true);
/* Same function, but accumulates undo and redo*/
bool requestItemDeletion(int clipId, Fun &undo, Fun &redo);
bool requestItemDeletion(int itemId, Fun &undo, Fun &redo);
/* @brief Move a group to a specific position
This action is undoable
......@@ -684,7 +685,7 @@ protected:
/* @brief Unplant the composition with given Id */
bool unplantComposition(int compoId);
/* Same function but accumulates undo and redo, and doesn't check for group*/
/* Internal functions to delete a clip or a composition. In general, you should call requestItemDeletion */
bool requestClipDeletion(int clipId, Fun &undo, Fun &redo);
bool requestCompositionDeletion(int compositionId, Fun &undo, Fun &redo);
......
......@@ -797,7 +797,12 @@ TEST_CASE("Clip manipulation", "[ClipModel]")
int tid6 = TrackModel::construct(timeline, -1, -1, QString(), true);
int tid5 = TrackModel::construct(timeline);
int tid5b = TrackModel::construct(timeline);
auto state0 = [&]() {
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackClipsCount(tid5) == 0);
REQUIRE(timeline->getTrackClipsCount(tid6) == 0);
};
state0();
QString binId3 = createProducerWithSound(profile_model, binModel);
int cid6 = -1;
......@@ -825,6 +830,23 @@ TEST_CASE("Clip manipulation", "[ClipModel]")
check_group();
};
state(3);
undoStack->undo();
state0();
undoStack->redo();
state(3);
// test deletion + undo after selection
REQUIRE(timeline->requestSetSelection({cid6}));
REQUIRE(timeline->getCurrentSelection() == std::unordered_set<int>{cid6, cid7});
REQUIRE(timeline->requestItemDeletion(cid6, true));
state0();
undoStack->undo();
state(3);
undoStack->redo();
state0();
undoStack->undo();
state(3);
// simple translation on the right
REQUIRE(timeline->requestClipMove(cid6, tid5, 10, true, true, true));
......@@ -1694,5 +1716,3 @@ TEST_CASE("Snapping", "[Snapping]")
pCore->m_projectManager = nullptr;
Logger::print_trace();
}
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