Fix view corruption with spacer tool

parent 93b93d34
......@@ -180,7 +180,7 @@ int TimelineFunctions::requestSpacerStartOperation(std::shared_ptr<TimelineItemM
{
std::unordered_set<int> clips = timeline->getItemsAfterPosition(trackId, position, -1);
if (clips.size() > 0) {
timeline->requestClipsGroup(clips, false);
timeline->requestClipsGroup(clips, false, GroupType::Selection);
return (*clips.cbegin());
}
return -1;
......@@ -193,7 +193,7 @@ bool TimelineFunctions::requestSpacerEndOperation(std::shared_ptr<TimelineItemMo
timeline->requestClipMove(clipId, track, startPosition, false, false);
std::unordered_set<int> clips = timeline->getGroupElements(clipId);
// break group
timeline->requestClipUngroup(clipId, false);
pCore->clearSelection();
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
......
......@@ -385,6 +385,37 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool
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)
{
#ifdef LOGGING
......@@ -422,7 +453,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
}
}
// 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);
if (possible) {
return position;
......@@ -441,7 +472,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
} else {
return false;
}
possible = requestClipMove(clipId, trackId, position, false, false, false);
possible = requestClipMoveAttempt(clipId, trackId, position);
return possible ? position : currentPos;
}
// find best pos for groups
......@@ -495,7 +526,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int sn
}
if (blank_length != 0) {
int updatedPos = currentPos + (after ? blank_length : -blank_length);
possible = requestClipMove(clipId, trackId, updatedPos, false, false, false);
possible = requestClipMoveAttempt(clipId, trackId, updatedPos);
if (possible) {
return updatedPos;
}
......@@ -838,9 +869,8 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
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
m_logFile << "timeline->requestGroupMove(" << clipId << "," << groupId << " ," << delta_track << ", " << delta_pos << ", "
<< (updateView ? "true" : "false") << " ); " << std::endl;
......@@ -894,7 +924,7 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
int current_track_position = getTrackPosition(current_track_id);
int d = getTrackById(current_track_id)->isAudioTrack() ? audio_delta : video_delta;
int target_track_position = current_track_position + d;
bool updateThisView = true;
bool updateThisView = allowViewRefresh;
if (clip == clipId) {
updateThisView = updateView;
}
......
......@@ -344,9 +344,10 @@ public:
@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 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, 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.
This action is undoable
......@@ -592,6 +593,9 @@ protected:
/** @brief Get a track tag (A1, V1, V2,...) through its id */
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:
/* @brief Debugging function that checks consistency with Mlt objects */
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