Changeset View
Changeset View
Standalone View
Standalone View
src/timeline2/model/modelupdater.cpp
Context not available. | |||||
116 | int sourcePos = -1; | 116 | int sourcePos = -1; | ||
---|---|---|---|---|---|
117 | bool isClip = true; | 117 | bool isClip = true; | ||
118 | std::weak_ptr<TimelineModel> sourceTimeline; | 118 | std::weak_ptr<TimelineModel> sourceTimeline; | ||
119 | | ||||
120 | for (const auto &update : list) { | 119 | for (const auto &update : list) { | ||
121 | Q_ASSERT(update->getItemId() == itemId); | 120 | Q_ASSERT(update->getItemId() == itemId); | ||
122 | Q_ASSERT(!update->isMove()); | 121 | Q_ASSERT(!update->isMove()); | ||
Context not available. | |||||
129 | Q_ASSERT(sourceTrackId != -1); | 128 | Q_ASSERT(sourceTrackId != -1); | ||
130 | } else if (sourceTrackId != -1 && update->isInsert()) { | 129 | } else if (sourceTrackId != -1 && update->isInsert()) { | ||
131 | auto insert = std::static_pointer_cast<InsertUpdate>(update); | 130 | auto insert = std::static_pointer_cast<InsertUpdate>(update); | ||
132 | result.emplace_back( | 131 | if (insert->getTrackId() == sourceTrackId) { | ||
132 | // Same track move, convert to change only | ||||
133 | result.emplace_back(new ChangeUpdate(itemId, sourceTimeline, {TimelineModel::StartRole})); | ||||
134 | } else { | ||||
135 | result.emplace_back( | ||||
133 | new MoveUpdate(itemId, sourceTimeline, sourceTrackId, sourcePos, insert->getTimeline(), insert->getTrackId(), insert->getPos())); | 136 | new MoveUpdate(itemId, sourceTimeline, sourceTrackId, sourcePos, insert->getTimeline(), insert->getTrackId(), insert->getPos())); | ||
137 | } | ||||
134 | sourceTrackId = -1; | 138 | sourceTrackId = -1; | ||
135 | sourcePos = -1; | 139 | sourcePos = -1; | ||
136 | isClip = insert->isClip(); | 140 | isClip = insert->isClip(); | ||
Context not available. | |||||
158 | } | 162 | } | ||
159 | if (!isFirstOperationInsert) { | 163 | if (!isFirstOperationInsert) { | ||
160 | result_clean.emplace_back(new DeleteUpdate(itemId, sourceTimeline, sourceTrackId, sourcePos, isClip)); | 164 | result_clean.emplace_back(new DeleteUpdate(itemId, sourceTimeline, sourceTrackId, sourcePos, isClip)); | ||
165 | return result_clean; | ||||
166 | } else { | ||||
167 | // We insert clip then delete it, so do nothing | ||||
168 | return result_clean; | ||||
161 | } | 169 | } | ||
162 | } | 170 | } | ||
163 | return result; | 171 | return result; | ||
Context not available. | |||||
236 | } | 244 | } | ||
237 | 245 | | |||
238 | // Then, we simplify updates element by element | 246 | // Then, we simplify updates element by element | ||
239 | | ||||
240 | std::vector<std::shared_ptr<AbstractUpdate>> res; | 247 | std::vector<std::shared_ptr<AbstractUpdate>> res; | ||
241 | for (const auto &u : updatesByItem) { | 248 | for (const auto &u : updatesByItem) { | ||
242 | auto curated = mergeChanges(mergeMoves(mergeDeleteInsert(u.second))); | 249 | auto curated = mergeChanges(mergeMoves(mergeDeleteInsert(u.second))); | ||
Context not available. | |||||
309 | }; | 316 | }; | ||
310 | return [ list, getCurrentRow = std::move(getCurrentRow), getTentativeRow = std::move(getTentativeRow) ]() | 317 | return [ list, getCurrentRow = std::move(getCurrentRow), getTentativeRow = std::move(getTentativeRow) ]() | ||
311 | { | 318 | { | ||
319 | QMap <int,int> trackRowOffset; | ||||
320 | for (const auto &u : list) { | ||||
321 | if (u->isInsert()) { | ||||
322 | auto ins = std::static_pointer_cast<InsertUpdate>(u); | ||||
323 | int trackId = ins->getTrackId(); | ||||
324 | if (trackRowOffset.contains(trackId)) { | ||||
325 | int offset = trackRowOffset.value(trackId); | ||||
326 | trackRowOffset[trackId] = offset + 1; | ||||
327 | } else { | ||||
328 | trackRowOffset[trackId] = 0; | ||||
329 | } | ||||
330 | } | ||||
331 | } | ||||
312 | for (const auto &u : list) { | 332 | for (const auto &u : list) { | ||
313 | if (u->isDelete()) { | 333 | if (u->isDelete()) { | ||
314 | auto del = std::static_pointer_cast<DeleteUpdate>(u); | 334 | auto del = std::static_pointer_cast<DeleteUpdate>(u); | ||
Context not available. | |||||
325 | if (auto timeline = ins->getTimeline().lock()) { | 345 | if (auto timeline = ins->getTimeline().lock()) { | ||
326 | int trackId = ins->getTrackId(), itemId = ins->getItemId(); | 346 | int trackId = ins->getTrackId(), itemId = ins->getItemId(); | ||
327 | int row = getTentativeRow(timeline, trackId, itemId, ins->isClip()); | 347 | int row = getTentativeRow(timeline, trackId, itemId, ins->isClip()); | ||
328 | timeline->_beginInsertRows(timeline->makeTrackIndexFromID(trackId), row, row); | 348 | //HACK: workaround for the getTentativeRow that does not work in case of multiple insert in one track | ||
349 | int offset = trackRowOffset.value(trackId); | ||||
350 | if (offset >= 0) { | ||||
351 | timeline->_beginInsertRows(timeline->makeTrackIndexFromID(trackId), row, row + offset); | ||||
352 | trackRowOffset[trackId] = -1; | ||||
353 | } | ||||
329 | } else { | 354 | } else { | ||
330 | qDebug() << "ERROR: impossible to lock timeline"; | 355 | qDebug() << "ERROR: impossible to lock timeline"; | ||
331 | Q_ASSERT(false); | 356 | Q_ASSERT(false); | ||
Context not available. | |||||
334 | auto move = std::static_pointer_cast<MoveUpdate>(u); | 359 | auto move = std::static_pointer_cast<MoveUpdate>(u); | ||
335 | if (auto sTimeline = move->getSourceTimeline().lock()) { | 360 | if (auto sTimeline = move->getSourceTimeline().lock()) { | ||
336 | if (auto tTimeline = move->getTargetTimeline().lock()) { | 361 | if (auto tTimeline = move->getTargetTimeline().lock()) { | ||
337 | int sTrackId = move->getSourceTrackId(), itemId = move->getItemId(); | 362 | int sTrackId = move->getSourceTrackId(); | ||
363 | int itemId = move->getItemId(); | ||||
338 | int tTrackId = move->getTargetTrackId(); | 364 | int tTrackId = move->getTargetTrackId(); | ||
339 | int sRow = getCurrentRow(sTimeline, sTrackId, itemId); | 365 | int sRow = getCurrentRow(sTimeline, sTrackId, itemId); | ||
340 | int tRow = getTentativeRow(tTimeline, tTrackId, itemId, sTimeline->isClip(itemId)); | 366 | int tRow = getTentativeRow(tTimeline, tTrackId, itemId, sTimeline->isClip(itemId)); | ||
Context not available. | |||||
369 | Fun ModelUpdater::postApply_lambda(const std::vector<std::shared_ptr<AbstractUpdate>> &list) | 395 | Fun ModelUpdater::postApply_lambda(const std::vector<std::shared_ptr<AbstractUpdate>> &list) | ||
370 | { | 396 | { | ||
371 | return [list]() { | 397 | return [list]() { | ||
398 | bool insertSent = false; | ||||
372 | for (const auto &u : list) { | 399 | for (const auto &u : list) { | ||
373 | if (u->isDelete()) { | 400 | if (u->isDelete()) { | ||
374 | auto del = std::static_pointer_cast<DeleteUpdate>(u); | 401 | auto del = std::static_pointer_cast<DeleteUpdate>(u); | ||
Context not available. | |||||
379 | Q_ASSERT(false); | 406 | Q_ASSERT(false); | ||
380 | } | 407 | } | ||
381 | } else if (u->isInsert()) { | 408 | } else if (u->isInsert()) { | ||
409 | if (insertSent) { | ||||
410 | continue; | ||||
411 | } | ||||
382 | auto ins = std::static_pointer_cast<InsertUpdate>(u); | 412 | auto ins = std::static_pointer_cast<InsertUpdate>(u); | ||
383 | if (auto timeline = ins->getTimeline().lock()) { | 413 | if (auto timeline = ins->getTimeline().lock()) { | ||
384 | timeline->_endInsertRows(); | 414 | timeline->_endInsertRows(); | ||
415 | insertSent = true; | ||||
385 | } else { | 416 | } else { | ||
386 | qDebug() << "ERROR: impossible to lock timeline"; | 417 | qDebug() << "ERROR: impossible to lock timeline"; | ||
387 | Q_ASSERT(false); | 418 | Q_ASSERT(false); | ||
Context not available. | |||||
434 | } | 465 | } | ||
435 | auto updates = simplify(list); | 466 | auto updates = simplify(list); | ||
436 | auto rev_updates = reverse(updates); | 467 | auto rev_updates = reverse(updates); | ||
437 | | ||||
438 | // firstly, we need to undo the action | 468 | // firstly, we need to undo the action | ||
439 | bool undone = undo(); | 469 | bool undone = undo(); | ||
440 | Q_ASSERT(undone); | 470 | Q_ASSERT(undone); | ||
Context not available. | |||||
588 | 618 | | |||
589 | std::shared_ptr<AbstractUpdate> MoveUpdate::reverse() | 619 | std::shared_ptr<AbstractUpdate> MoveUpdate::reverse() | ||
590 | { | 620 | { | ||
591 | return std::make_shared<MoveUpdate>(m_itemId, m_targetTimeline, m_targetTrackId, m_targetPos, m_targetTimeline, m_targetTrackId, m_targetPos); | 621 | return std::make_shared<MoveUpdate>(m_itemId, m_targetTimeline, m_targetTrackId, m_targetPos, m_sourceTimeline, m_sourceTrackId, m_sourcePos); | ||
592 | } | 622 | } | ||
593 | 623 | | |||
594 | void MoveUpdate::print() const | 624 | void MoveUpdate::print() const | ||
Context not available. | |||||
633 | case TimelineModel::NameRole: | 663 | case TimelineModel::NameRole: | ||
634 | qDebug() << "NameRole"; | 664 | qDebug() << "NameRole"; | ||
635 | break; | 665 | break; | ||
666 | case TimelineModel::TrackIdRole: | ||||
667 | qDebug() << "TrackIdRole"; | ||||
668 | break; | ||||
636 | case TimelineModel::ResourceRole: | 669 | case TimelineModel::ResourceRole: | ||
637 | qDebug() << "ResourceRole"; | 670 | qDebug() << "ResourceRole"; | ||
638 | break; | 671 | break; | ||
Context not available. |