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

Fix crash on composition drag

parent dec92632
......@@ -493,10 +493,10 @@ QMap<int, QString> Core::getVideoTrackNames()
return m_mainWindow->getCurrentTimeline()->controller()->getTrackNames(true);
}
int Core::getCompositionATrack(int cid) const
QPair<int,int> Core::getCompositionATrack(int cid) const
{
if (!m_guiConstructed)
return -1;
return QPair<int,int>();
return m_mainWindow->getCurrentTimeline()->controller()->getCompositionATrack(cid);
}
......
......@@ -149,7 +149,8 @@ public:
int getItemDuration(const ObjectId &id);
/** @brief Get a list of video track names with indexes */
QMap<int, QString> getVideoTrackNames();
int getCompositionATrack(int cid) const;
/** @brief Returns the composition A track (MLT index / Track id) */
QPair<int,int>getCompositionATrack(int cid) const;
void setCompositionATrack(int cid, int aTrack);
std::shared_ptr<DocUndoStack> undoStack();
double getClipSpeed(int id) const;
......
......@@ -133,13 +133,13 @@ int CompositionModel::getATrack() const
return a_track == -1 ? -1 : service()->get_int("a_track");
}
void CompositionModel::setATrack(int trackId)
void CompositionModel::setATrack(int trackMltPosition, int trackId)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(trackId != getCurrentTrackId()); // can't compose with same track
a_track = trackId;
a_track = trackMltPosition;
if (a_track >= 0) {
service()->set("a_track", trackId);
service()->set("a_track", trackMltPosition);
}
}
......
......@@ -70,7 +70,7 @@ public:
int getATrack() const;
/* @brief Sets the id of the second track involved in the composition*/
void setATrack(int trackId);
void setATrack(int trackMltPosition, int trackId);
/* @brief returns a property of the current item
*/
......
......@@ -1382,11 +1382,10 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int positio
bool TimelineModel::requestCompositionMove(int compoId, int trackId, int compositionTrack, int position, bool updateView, Fun &undo, Fun &redo)
{
qDebug() << "Requesting composition move" << trackId << "," << position;
QWriteLocker locker(&m_lock);
Q_ASSERT(isComposition(compoId));
Q_ASSERT(isTrack(trackId));
if (compositionTrack == -1) {
if (compositionTrack == -1 || (compositionTrack > 0 && trackId == getTrackIndexFromPosition(compositionTrack - 1))) {
qDebug() << "// compo track: " << trackId << ", PREVIOUS TK: " << getPreviousVideoTrackPos(trackId);
compositionTrack = getPreviousVideoTrackPos(trackId);
}
......@@ -1395,6 +1394,8 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
qDebug() << "Move failed because of last track";
return false;
}
qDebug() << "Requesting composition move" << trackId << "," << position<<" ( "<<compositionTrack<<" / "<<(compositionTrack > 0 ? getTrackIndexFromPosition(compositionTrack - 1) : 0);
Fun local_undo = []() { return true; };
Fun local_redo = []() { return true; };
bool ok = true;
......@@ -1405,12 +1406,12 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
if (old_trackId != trackId) {
delete_operation = [this, compoId]() {
bool res = unplantComposition(compoId);
if (res) m_allCompositions[compoId]->setATrack(-1);
if (res) m_allCompositions[compoId]->setATrack(-1, -1);
return res;
};
int oldAtrack = m_allCompositions[compoId]->getATrack();
delete_reverse = [this, compoId, oldAtrack]() {
m_allCompositions[compoId]->setATrack(oldAtrack);
m_allCompositions[compoId]->setATrack(oldAtrack, oldAtrack <= 0 ? -1 : getTrackIndexFromPosition(oldAtrack - 1));
return replantCompositions(compoId);
};
}
......@@ -1435,12 +1436,13 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
Fun insert_reverse = []() { return true; };
if (old_trackId != trackId) {
insert_operation = [this, compoId, trackId, compositionTrack]() {
m_allCompositions[compoId]->setATrack(compositionTrack);
qDebug()<<"-------------- ATRACK ----------------\n"<<compositionTrack<<" = "<<getTrackIndexFromPosition(compositionTrack);
m_allCompositions[compoId]->setATrack(compositionTrack, compositionTrack <= 0 ? -1 : getTrackIndexFromPosition(compositionTrack - 1));
return replantCompositions(compoId);
};
insert_reverse = [this, compoId]() {
bool res = unplantComposition(compoId);
if (res) m_allCompositions[compoId]->setATrack(-1);
if (res) m_allCompositions[compoId]->setATrack(-1, -1);
return res;
};
}
......
......@@ -766,16 +766,21 @@ void TimelineController::adjustFade(int cid, const QString &effectId, int durati
}
}
int TimelineController::getCompositionATrack(int cid) const
QPair<int,int> TimelineController::getCompositionATrack(int cid) const
{
return m_model->getCompositionPtr(cid)->getATrack();
QPair<int,int> result;
std::shared_ptr<CompositionModel> compo = m_model->getCompositionPtr(cid);
if (compo) {
result = QPair<int,int>(compo->getATrack(), m_model->getTrackMltIndex(compo->getCurrentTrackId()));
}
return result;
}
void TimelineController::setCompositionATrack(int cid, int aTrack)
{
QScopedPointer<Mlt::Field> field(m_model->m_tractor->field());
field->lock();
m_model->getCompositionPtr(cid)->setATrack(aTrack);
m_model->getCompositionPtr(cid)->setATrack(aTrack, aTrack <= 0 ? -1 : m_model->getTrackIndexFromPosition(aTrack - 1));
field->unlock();
refreshItem(cid);
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(cid);
......
......@@ -269,9 +269,9 @@ public:
/* @brief Returns a map of track ids/track names
*/
QMap<int, QString> getTrackNames(bool videoOnly);
/* @brief Returns the transition a track index for a composition
/* @brief Returns the transition a track index for a composition (MLT index / Track id)
*/
int getCompositionATrack(int cid) const;
QPair<int,int>getCompositionATrack(int cid) const;
void setCompositionATrack(int cid, int aTrack);
const QString getClipBinId(int clipId) const;
void focusItem(int itemId);
......
......@@ -42,14 +42,16 @@ void TransitionStackView::setModel(const std::shared_ptr<AssetParameterModel> &m
m_trackBox = new QComboBox(this);
m_trackBox->addItem(i18n("Background"), 0);
QMapIterator<int, QString> i(pCore->getVideoTrackNames());
QPair <int,int> aTrack = pCore->getCompositionATrack(model->getOwnerId().second);
while (i.hasNext()) {
i.next();
m_trackBox->addItem(i.value(), i.key());
if (i.key() != aTrack.second) {
m_trackBox->addItem(i.value(), i.key());
}
}
AssetParameterView::setModel(model, range, frameSize, addSpacer);
int aTrack = pCore->getCompositionATrack(m_model->getOwnerId().second);
m_trackBox->setCurrentIndex(m_trackBox->findData(aTrack));
m_trackBox->setCurrentIndex(m_trackBox->findData(aTrack.first));
QLabel *title = new QLabel(i18n("Composition track: "), this);
lay->addWidget(title);
lay->addWidget(m_trackBox);
......
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