Commit 52a69185 authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2][Model] AllowClipMove no longer necessary

parent c6c3ea1f
......@@ -67,9 +67,9 @@ std::shared_ptr<TimelineModel> TimelineModel::construct(std::weak_ptr<DocUndoSta
int clipId = ClipModel::construct(ptr, prod);
int clipId2 = ClipModel::construct(ptr, prod);
int clipId3 = ClipModel::construct(ptr, prod);
ptr->requestClipMove(clipId, ix, 100, false);
ptr->requestClipMove(clipId2, ix, 50, false);
ptr->requestClipMove(clipId3, ix, 250, false);
ptr->requestClipMove(clipId, ix, 100, true);
ptr->requestClipMove(clipId2, ix, 50, true);
ptr->requestClipMove(clipId3, ix, 250, true);
ptr->getTrackById(ix)->setProperty("kdenlive:trackheight", "60");
ptr->getTrackById(ix2)->setProperty("kdenlive:trackheight", "140");
}
......@@ -307,18 +307,7 @@ int TimelineModel::getClipPosition(int cid) const
return clip->getPosition();
}
bool TimelineModel::allowClipMove(int cid, int tid, int position)
{
qDebug()<<"Checking clip move"<<cid<<tid<<position;
if (!isClip(cid) || !isTrack(tid)) {
qDebug() << "ERROR : Invalid clip or track";
return false;
}
int length = m_allClips[cid]->getPlaytime();
return getTrackById(tid)->allowClipMove(cid, position, length);
}
bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, Fun &redo)
bool TimelineModel::requestClipMove(int cid, int tid, int position, bool test_only, Fun &undo, Fun &redo)
{
std::function<bool (void)> local_undo = [](){return true;};
std::function<bool (void)> local_redo = [](){return true;};
......@@ -341,19 +330,21 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
return false;
}
int new_clip_index = getTrackById(tid)->getRowfromClip(cid);
auto operation = [cid, tid, old_tid, old_clip_index, new_clip_index, this]() {
auto operation = [cid, tid, old_tid, old_clip_index, new_clip_index, test_only, this]() {
m_allClips[cid]->setCurrentTrackId(tid);
if (tid == old_tid) {
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
} else {
if (old_tid != -1){
qDebug() << "Removed row "<<old_clip_index;
beginRemoveRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
endRemoveRows();
if (!test_only) {
if (tid == old_tid) {
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
} else {
if (old_tid != -1){
qDebug() << "Removed row "<<old_clip_index;
beginRemoveRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
endRemoveRows();
}
beginInsertRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
endInsertRows();
}
beginInsertRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
endInsertRows();
}
return true;
};
......@@ -364,21 +355,21 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
//push the operation and its reverse in the undo/redo
UPDATE_UNDO_REDO(operation, reverse, local_undo, local_redo);
//We have to expend the local undo with the data modification signals. They have to be sent after the real operations occured in the model so that the GUI can query the correct new values
local_undo = [local_undo, tid, old_tid, cid, old_clip_index, new_clip_index, this]() {
local_undo = [local_undo, tid, old_tid, cid, old_clip_index, new_clip_index, test_only, this]() {
bool v = local_undo();
//qDebug()<<"DATA CHANGED SIGNAL";
if (tid == old_tid) {
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
} else {
beginRemoveRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
endRemoveRows();
if (old_tid != -1) {
beginInsertRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
endInsertRows();
if (!test_only) {
if (tid == old_tid) {
QModelIndex modelIndex = makeClipIndexFromID(cid);
emit dataChanged(modelIndex, modelIndex, {StartRole});
} else {
beginRemoveRows(makeTrackIndexFromID(tid), new_clip_index, new_clip_index);
endRemoveRows();
if (old_tid != -1) {
beginInsertRows(makeTrackIndexFromID(old_tid), old_clip_index, old_clip_index);
endInsertRows();
}
}
}
//qDebug()<<"Moved back"<<cid<<"to position"<<m_allClips[cid]->getPosition();
return v;
};
bool result = operation();
......@@ -388,7 +379,7 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, Fun &undo, F
return result;
}
bool TimelineModel::requestClipMove(int cid, int tid, int position, bool logUndo)
bool TimelineModel::requestClipMove(int cid, int tid, int position, bool test_only)
{
Q_ASSERT(m_allClips.count(cid) > 0);
if (m_allClips[cid]->getPosition() == position && m_allClips[cid]->getCurrentTrackId() == tid) {
......@@ -401,11 +392,11 @@ bool TimelineModel::requestClipMove(int cid, int tid, int position, bool logUndo
int delta_pos = position - m_allClips[cid]->getPosition();
return requestGroupMove(gid, delta_track, delta_pos);
}
qDebug()<<"clip move in model"<<cid<<tid<<position;
std::function<bool (void)> undo = [](){return true;};
std::function<bool (void)> redo = [](){return true;};
bool res = requestClipMove(cid, tid, position, undo, redo);
if (res && logUndo) {
bool res = requestClipMove(cid, tid, position, test_only, undo, redo);
qDebug()<<"clip move in model"<<cid<<tid<<position<<res<<test_only;
if (res && !test_only) {
PUSH_UNDO(undo, redo, i18n("Move clip"));
}
return res;
......@@ -424,7 +415,7 @@ bool TimelineModel::requestClipInsert(std::shared_ptr<Mlt::Producer> prod, int t
return true;
};
redo();
bool res = requestClipMove(clipId, trackId, position, undo, redo);
bool res = requestClipMove(clipId, trackId, position, false, undo, redo);
if (!res) {
undo();
id = -1;
......@@ -458,7 +449,7 @@ bool TimelineModel::requestGroupMove(int gid, int delta_track, int delta_pos, bo
for (int clip : sorted_clips) {
int target_track = m_allClips[clip]->getCurrentTrackId() + delta_track;
int target_position = m_allClips[clip]->getPosition() + delta_pos;
ok = requestClipMove(clip, target_track, target_position, undo, redo);
ok = requestClipMove(clip, target_track, target_position, false, undo, redo);
if (!ok) {
bool undone = undo();
Q_ASSERT(undone);
......
......@@ -150,9 +150,13 @@ public:
@param cid is the ID of the clip
@param tid is the ID of the target track
@param position is the position where we want to move
@param logUndo if set to true, an undo object is created
@param test_only if set to false, the undo is not created and no signal is sent to qml
*/
bool requestClipMove(int cid, int tid, int position, bool logUndo = true);
bool requestClipMove(int cid, int tid, int position, bool test_only = false);
protected:
/* Same function, but accumulates undo and redo, and doesn't check for group*/
bool requestClipMove(int cid, int tid, int position, bool test_only, Fun &undo, Fun &redo);
public:
bool trimClip(int cid, int delta, bool right, bool ripple = false);
......@@ -165,17 +169,6 @@ public:
@param ID return parameter of the id of the inserted clip
*/
bool requestClipInsert(std::shared_ptr<Mlt::Producer> prod, int trackId, int position, int &id);
protected:
/* Same function, but accumulates undo and redo, and doesn't check for group*/
bool requestClipMove(int cid, int tid, int position, Fun &undo, Fun &redo);
public:
/* @brief This function is similar as requestClipMove except that it just checks for move validity, and does not perform anything
@param cid is the ID of the clip
@param tid is the ID of the target track
@param position is the position where we want to move
*/
bool allowClipMove(int cid, int tid, int position);
/* @brief Move a group to a specific position
Returns true on success. If it fails, nothing is modified.
......
......@@ -318,23 +318,3 @@ bool TrackModel::checkConsistency()
}
return true;
}
bool TrackModel::allowClipMove(int cid, int position, int length)
{
// Check position is blank or is in cid
int ix = m_playlist.get_clip_index_at(position);
int blankEnd = 0;
int target_clip = -1;
if (m_allClips.count(cid) > 0) { //check if the clip is in the track
int clip_position = m_allClips[cid]->getPosition();
target_clip = m_playlist.get_clip_index_at(clip_position);
}
while (blankEnd < position + length && ix < m_playlist.count()) {
if (m_playlist.is_blank(ix) || target_clip == ix) {
blankEnd = m_playlist.clip_start(++ix) - 1;
} else break;
}
// Return true if we are at playlist end or if there is enough space for the move
return (ix == m_playlist.count() || blankEnd >= position + length);
}
......@@ -66,8 +66,6 @@ public:
*/
operator Mlt::Producer&(){ return m_playlist;}
bool allowClipMove(int cid, int position, int length);
// TODO make protected
QVariant getProperty(const QString &name);
void setProperty(const QString &name, const QString &value);
......
......@@ -94,9 +94,11 @@ Column{
var toTrack = clip.trackId
var cIndex = clip.clipId
var frame = Math.round(clip.x / timeScale)
var origFrame = Math.round(clip.originalX / timeScale)
console.log("Asking move ",toTrack, cIndex, frame)
var val = timeline.moveClip(toTrack, cIndex, frame, true)
timeline.moveClip(clip.originalTrackId, cIndex, origFrame, true)
var val = timeline.moveClip(toTrack, cIndex, frame, false)
console.log("RESULT", val)
}
onDragged: {
......
......@@ -135,14 +135,14 @@ bool TimelineWidget::scrub()
return false;
}
bool TimelineWidget::moveClip(int toTrack, int clipIndex, int position, bool logUndo)
bool TimelineWidget::moveClip(int toTrack, int clipIndex, int position, bool test_only)
{
return m_model->requestClipMove(clipIndex, toTrack, position, logUndo);
return m_model->requestClipMove(clipIndex, toTrack, position, test_only);
}
bool TimelineWidget::allowMoveClip(int toTrack, int clipIndex, int position)
{
return m_model->allowClipMove(clipIndex, toTrack, position);
return m_model->requestClipMove(clipIndex, toTrack, position, true);
}
bool TimelineWidget::trimClip(int clipIndex, int delta, bool right)
......
......@@ -47,7 +47,7 @@ public:
Q_INVOKABLE int selectedTrack() const { return m_selection.selectedTrack; }
Q_INVOKABLE double scaleFactor() const;
Q_INVOKABLE void setScaleFactor(double scale);
Q_INVOKABLE bool moveClip(int toTrack, int clipIndex, int position, bool logUndo = true);
Q_INVOKABLE bool moveClip(int toTrack, int clipIndex, int position, bool test_only = false);
Q_INVOKABLE bool allowMoveClip(int toTrack, int clipIndex, int position);
Q_INVOKABLE bool trimClip(int clipIndex, int delta, bool right);
Q_INVOKABLE int duration() const;
......
This diff is collapsed.
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