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 selection

parent 0abbe17e
......@@ -40,7 +40,6 @@ ClipModel::ClipModel(std::shared_ptr<TimelineModel> parent, std::shared_ptr<Mlt:
, m_producer(std::move(prod))
, m_effectStack(EffectStackModel::construct(m_producer, {ObjectType::TimelineClip, m_id}, parent->m_undoStack))
, m_binClipId(binClipId)
, isInGroupDrag(false)
{
m_producer->set("kdenlive:id", binClipId.toUtf8().constData());
m_producer->set("_kdenlive_cid", m_id);
......
......@@ -106,7 +106,6 @@ public:
int fadeIn() const;
int fadeOut() const;
bool isInGroupDrag;
friend class TrackModel;
friend class TimelineModel;
......
......@@ -77,6 +77,10 @@ public:
*/
virtual const QString getProperty(const QString &name) const = 0;
/* @brief true if the item is in current selection and should be moved within a group
*/
bool isInGroupDrag;
protected:
/* @brief Returns a pointer to the service. It may be used but do NOT store it*/
virtual Service *service() const = 0;
......
......@@ -27,6 +27,7 @@ MoveableItem<Service>::MoveableItem(std::weak_ptr<TimelineModel> parent, int id)
, m_position(-1)
, m_currentTrackId(-1)
, m_lock(QReadWriteLock::Recursive)
, isInGroupDrag(false)
{
}
......
......@@ -336,7 +336,9 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
case DurationRole:
return compo->getPlaytime();
case GroupedRole:
return false; // m_groups->isInGroup(id);
return m_groups->isInGroup(id);
case GroupDragRole:
return compo->isInGroupDrag;
case InPointRole:
return 0;
case OutPointRole:
......
......@@ -115,18 +115,30 @@ void TimelineController::addSelection(int newSelection)
// new items were selected, inform model to prepare for group drag
newIds = m_model->getGroupElements(m_selection.selectedClips.constFirst());
for (int i : newIds) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
}
// Make sure to remove items from previous selection
for (int i : previousSelection) {
if (newIds.find(i) == newIds.end()) {
// item not in selection anymore
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
}
emit selectionChanged();
......@@ -238,9 +250,15 @@ void TimelineController::setSelection(const QList<int> &newSelection, int trackI
if (m_model->m_temporarySelectionGroup >= 0 || (!m_selection.selectedClips.isEmpty() && m_model->m_groups->isInGroup(m_selection.selectedClips.constFirst()))) {
newIds = m_model->getGroupElements(m_selection.selectedClips.constFirst());
for (int i : newIds) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
} else {
qDebug()<<"// NON GROUPED SELCTUIIN: "<<m_selection.selectedClips<<" !!!!!!";
......@@ -255,9 +273,15 @@ void TimelineController::setSelection(const QList<int> &newSelection, int trackI
// Clear previously selcted items
if (newIds.find(i) == newIds.end()) {
// item not in selection anymore
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
}
emit selectionChanged();
......@@ -694,24 +718,34 @@ void TimelineController::selectItems(QVariantList arg, int startFrame, int endFr
m_model->requestClipUngroup(m_model->m_temporarySelectionGroup, false);
}
std::unordered_set<int> newIds;
QVector<int> roles;
roles.push_back(TimelineModel::GroupDragRole);
if (m_model->m_temporarySelectionGroup >= 0) {
newIds = m_model->getGroupElements(m_selection.selectedClips.constFirst());
QVector<int> roles;
roles.push_back(TimelineModel::GroupDragRole);
for (int i : newIds) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = true;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
}
for (int i : previousSelection) {
if (newIds.find(i) == newIds.end()) {
// item not in selection anymore
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
QVector<int> roles;
roles.push_back(TimelineModel::GroupDragRole);
m_model->notifyChange(modelIndex, modelIndex, roles);
if (m_model->isClip(i)) {
m_model->m_allClips[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeClipIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
} else if (m_model->isComposition(i)) {
m_model->m_allCompositions[i]->isInGroupDrag = false;
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(i);
m_model->notifyChange(modelIndex, modelIndex, roles);
}
}
}
emit selectionChanged();
......
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