From: Jean-Baptiste Mardelle Date: Thu, 12 Apr 2012 22:09:05 +0000 (+0200) Subject: Saved effect groups should not be merged when added to a clip with existing group: X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=591f0d54f02448b81d88d91179b17197b203deb7;p=kdenlive Saved effect groups should not be merged when added to a clip with existing group: http://kdenlive.org/mantis/view.php?id=2576 --- diff --git a/src/clipitem.cpp b/src/clipitem.cpp index d5c03901..d6be7a43 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -1629,6 +1629,20 @@ const ItemInfo ClipItem::speedIndependantInfo() const return m_speedIndependantInfo; } +int ClipItem::nextFreeEffectGroupIndex() const +{ + int freeGroupIndex = 0; + for (int i = 0; i < m_effectList.count(); i++) { + QDomElement effect = m_effectList.at(i); + EffectInfo effectInfo; + effectInfo.fromString(effect.attribute("kdenlive_info")); + if (effectInfo.groupIndex >= freeGroupIndex) { + freeGroupIndex = effectInfo.groupIndex + 1; + } + } + return freeGroupIndex; +} + //virtual void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) { @@ -1641,8 +1655,14 @@ void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event) if (e.tagName() == "effectgroup") { // dropped an effect group QDomNodeList effectlist = e.elementsByTagName("effect"); + int freeGroupIndex = nextFreeEffectGroupIndex(); + EffectInfo effectInfo; for (int i = 0; i < effectlist.count(); i++) { - effectlist.at(i).toElement().removeAttribute("kdenlive_ix"); + QDomElement effect = effectlist.at(i).toElement(); + effectInfo.fromString(effect.attribute("kdenlive_info")); + effectInfo.groupIndex = freeGroupIndex; + effect.setAttribute("kdenlive_info", effectInfo.toString()); + effect.removeAttribute("kdenlive_ix"); } } else { // single effect dropped diff --git a/src/clipitem.h b/src/clipitem.h index 682bb9fc..978585c6 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -176,6 +176,9 @@ public: void resetFrameWidth(int width); /** @brief Clip is about to be deleted, block thumbs. */ void stopThumbs(); + + /** @brief Get a free index value for effect group. */ + int nextFreeEffectGroupIndex() const; protected: //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 4651997e..2712dff7 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1734,7 +1734,18 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * if (effect.tagName() == "effectgroup") { QDomNodeList effectlist = effect.elementsByTagName("effect"); for (int j = 0; j < effectlist.count(); j++) { - processEffect(item, effectlist.at(j).toElement(), effectCommand); + QDomElement subeffect = effectlist.at(j).toElement(); + if (subeffect.hasAttribute("kdenlive_info")) { + // effect is in a group + EffectInfo effectInfo; + effectInfo.fromString(subeffect.attribute("kdenlive_info")); + if (effectInfo.groupIndex < 0) { + // group needs to be appended + effectInfo.groupIndex = item->nextFreeEffectGroupIndex(); + subeffect.setAttribute("kdenlive_info", effectInfo.toString()); + } + } + processEffect(item, subeffect, effectCommand); } } else { @@ -1790,7 +1801,18 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) if (effect.tagName() == "effectgroup") { QDomNodeList effectlist = effect.elementsByTagName("effect"); for (int j = 0; j < effectlist.count(); j++) { - processEffect(item, effectlist.at(j).toElement(), effectCommand); + QDomElement subeffect = effectlist.at(j).toElement(); + if (subeffect.hasAttribute("kdenlive_info")) { + // effect is in a group + EffectInfo effectInfo; + effectInfo.fromString(subeffect.attribute("kdenlive_info")); + if (effectInfo.groupIndex < 0) { + // group needs to be appended + effectInfo.groupIndex = item->nextFreeEffectGroupIndex(); + subeffect.setAttribute("kdenlive_info", effectInfo.toString()); + } + } + processEffect(item, subeffect, effectCommand); } } else processEffect(item, effect, effectCommand); diff --git a/src/effectstack/collapsiblegroup.cpp b/src/effectstack/collapsiblegroup.cpp index cb1ad1d5..7f89038f 100644 --- a/src/effectstack/collapsiblegroup.cpp +++ b/src/effectstack/collapsiblegroup.cpp @@ -167,11 +167,14 @@ void CollapsibleGroup::slotSaveGroup() for (int i = 0; i < effects.count(); i++) { QDomElement eff = effects.at(i).toElement(); eff.removeAttribute("kdenlive_ix"); - QString kdenliveInfo = eff.attribute("kdenlive_info"); + EffectInfo info; + info.fromString(eff.attribute("kdenlive_info")); // Make sure all effects have the correct new group name - if (kdenliveInfo.count('/') >= 2) { - eff.setAttribute("kdenlive_info", kdenliveInfo.section('/', 0, 1) + "/" + name); - } + info.groupName = name; + // Saved effect group should have a group index of -1 + info.groupIndex = -1; + eff.setAttribute("kdenlive_info", info.toString()); + } base.setAttribute("name", name);