Fix view corruption with spacer tool

parent 93b93d34
...@@ -180,7 +180,7 @@ int TimelineFunctions::requestSpacerStartOperation(std::shared_ptr<TimelineItemM ...@@ -180,7 +180,7 @@ int TimelineFunctions::requestSpacerStartOperation(std::shared_ptr<TimelineItemM
{ {
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, position, -1); std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, position, -1);
if (clips.size() > 0) { if (clips.size() > 0) {
timeline->requestClipsGroup(clips, false); timeline->requestClipsGroup(clips, false, GroupType::Selection);
return (*clips.cbegin()); return (*clips.cbegin());
} }
return -1; return -1;
...@@ -193,7 +193,7 @@ bool TimelineFunctions::requestSpacerEndOperation(std::shared_ptr<TimelineItemMo ...@@ -193,7 +193,7 @@ bool TimelineFunctions::requestSpacerEndOperation(std::shared_ptr<TimelineItemMo
timeline->requestClipMove(clipId, track, startPosition, false, false); timeline->requestClipMove(clipId, track, startPosition, false, false);
std::unordered_set<int> clips = timeline->getGroupElements(clipId); std::unordered_set<int> clips = timeline->getGroupElements(clipId);
// break group // break group
timeline->requestClipUngroup(clipId, false); pCore->clearSelection();
// Start undoable command // Start undoable command
std::function<bool(void)> undo = []() { return true; }; std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; }; std::function<bool(void)> redo = []() { return true; };
......
...@@ -385,6 +385,37 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool ...@@ -385,6 +385,37 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool
return res; return res;
} }
bool TimelineModel::requestClipMoveAttempt(int clipId, int trackId, int position)
{
#ifdef LOGGING
m_logFile << "timeline->requestClipMove(" << clipId << "," << trackId << " ," << position << std::endl;
#endif
QWriteLocker locker(&m_lock);
Q_ASSERT(m_allClips.count(clipId) > 0);
if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) {
return true;
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool res = true;
if (m_groups->isInGroup(clipId)) {
// element is in a group.
int groupId = m_groups->getRootId(clipId);
int current_trackId = getClipTrackId(clipId);
int track_pos1 = getTrackPosition(trackId);
int track_pos2 = getTrackPosition(current_trackId);
int delta_track = track_pos1 - track_pos2;
int delta_pos = position - m_allClips[clipId]->getPosition();
res = requestGroupMove(clipId, groupId, delta_track, delta_pos, false, false, undo, redo, false);
} else {
res = requestClipMove(clipId, trackId, position, false, false, undo, redo);
}
if (res) {
undo();
}
return res;
}
int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance) int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int snapDistance)
{ {
#ifdef LOGGING #ifdef LOGGING
...@@ -422,7 +453,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn ...@@ -422,7 +453,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
} }
} }
// we check if move is possible // we check if move is possible
bool possible = requestClipMove(clipId, trackId, position, false, false, false); bool possible = requestClipMoveAttempt(clipId, trackId, position);
// bool possible = requestClipMove(clipId, trackId, position, false, false, undo, redo); // bool possible = requestClipMove(clipId, trackId, position, false, false, undo, redo);
if (possible) { if (possible) {
return position; return position;
...@@ -441,7 +472,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn ...@@ -441,7 +472,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
} else { } else {
return false; return false;
} }
possible = requestClipMove(clipId, trackId, position, false, false, false); possible = requestClipMoveAttempt(clipId, trackId, position);
return possible ? position : currentPos; return possible ? position : currentPos;
} }
// find best pos for groups // find best pos for groups
...@@ -495,7 +526,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn ...@@ -495,7 +526,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
} }
if (blank_length != 0) { if (blank_length != 0) {
int updatedPos = currentPos + (after ? blank_length : -blank_length); int updatedPos = currentPos + (after ? blank_length : -blank_length);
possible = requestClipMove(clipId, trackId, updatedPos, false, false, false); possible = requestClipMoveAttempt(clipId, trackId, updatedPos);
if (possible) { if (possible) {
return updatedPos; return updatedPos;
} }
...@@ -838,9 +869,8 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i ...@@ -838,9 +869,8 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
return res; return res;
} }
bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo) bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo, bool allowViewRefresh)
{ {
Q_UNUSED(clipId)
#ifdef LOGGING #ifdef LOGGING
m_logFile << "timeline->requestGroupMove(" << clipId << "," << groupId << " ," << delta_track << ", " << delta_pos << ", " m_logFile << "timeline->requestGroupMove(" << clipId << "," << groupId << " ," << delta_track << ", " << delta_pos << ", "
<< (updateView ? "true" : "false") << " ); " << std::endl; << (updateView ? "true" : "false") << " ); " << std::endl;
...@@ -894,7 +924,7 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i ...@@ -894,7 +924,7 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
int current_track_position = getTrackPosition(current_track_id); int current_track_position = getTrackPosition(current_track_id);
int d = getTrackById(current_track_id)->isAudioTrack() ? audio_delta : video_delta; int d = getTrackById(current_track_id)->isAudioTrack() ? audio_delta : video_delta;
int target_track_position = current_track_position + d; int target_track_position = current_track_position + d;
bool updateThisView = true; bool updateThisView = allowViewRefresh;
if (clip == clipId) { if (clip == clipId) {
updateThisView = updateView; updateThisView = updateView;
} }
......
...@@ -344,9 +344,10 @@ public: ...@@ -344,9 +344,10 @@ public:
@param delta_pos is the requested position change @param delta_pos is the requested position change
@param updateView if set to false, no signal is sent to qml for the clip clipId @param updateView if set to false, no signal is sent to qml for the clip clipId
@param logUndo if set to true, an undo object is created @param logUndo if set to true, an undo object is created
@param allowViewRefresh if false, the view will never get updated (useful for suggestMove)
*/ */
bool requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView = true, bool logUndo = true); bool requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView = true, bool logUndo = true);
bool requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo); bool requestGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo, bool allowViewRefresh = true);
/* @brief Deletes all clips inside the group that contains the given clip. /* @brief Deletes all clips inside the group that contains the given clip.
This action is undoable This action is undoable
...@@ -592,6 +593,9 @@ protected: ...@@ -592,6 +593,9 @@ protected:
/** @brief Get a track tag (A1, V1, V2,...) through its id */ /** @brief Get a track tag (A1, V1, V2,...) through its id */
const QString getTrackTagById(int trackId) const; const QString getTrackTagById(int trackId) const;
/** @brief Attempt to make a clip move without ever updating the view */
bool requestClipMoveAttempt(int clipId, int trackId, int position);
public: public:
/* @brief Debugging function that checks consistency with Mlt objects */ /* @brief Debugging function that checks consistency with Mlt objects */
bool checkConsistency(); bool checkConsistency();
......
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