]> git.sesse.net Git - kdenlive/blobdiff - src/effectslist.cpp
Merge branch 'master' of git://anongit.kde.org/kdenlive
[kdenlive] / src / effectslist.cpp
index 77c1f41e1f235a335182480d7e813364e46009f9..407c51b858f50ba8d1da6d9a7d9c97702758d1a6 100644 (file)
@@ -90,8 +90,8 @@ int EffectsList::hasEffect(const QString & tag, const QString & id) const
     for (int i = 0; i < effects.count(); i++) {
         QDomElement effect =  effects.at(i).toElement();
         if (!id.isEmpty()) {
-            if (effect.attribute("id") == id) return i;
-        } else if (!tag.isEmpty() && effect.attribute("tag") == tag) return i;
+            if (effect.attribute("id") == id) return effect.attribute("kdenlive_ix").toInt();
+        } else if (!tag.isEmpty() && effect.attribute("tag") == tag) return effect.attribute("kdenlive_ix").toInt();
     }
     return -1;
 }
@@ -100,8 +100,14 @@ QStringList EffectsList::effectIdInfo(const int ix) const
 {
     QStringList info;
     QDomElement effect = m_baseElement.childNodes().at(ix).toElement();
-    QDomElement namenode = effect.firstChildElement("name");
-    info << i18n(namenode.text().toUtf8().data()) << effect.attribute("tag") << effect.attribute("id");
+    if (effect.tagName() == "effectgroup") {
+       QString groupName = effect.attribute("name");
+       info << groupName << groupName << groupName << QString::number(Kdenlive::groupEffect);
+    }
+    else {
+       QDomElement namenode = effect.firstChildElement("name");
+       info << i18n(namenode.text().toUtf8().data()) << effect.attribute("tag") << effect.attribute("id");
+    }
     return info;
 }
 
@@ -297,12 +303,16 @@ void EffectsList::removeMetaProperties(QDomElement producer)
     }
 }
 
-void EffectsList::append(QDomElement e)
+QDomElement EffectsList::append(QDomElement e)
 {
+    QDomElement result;
     if (!e.isNull()) {
-       m_baseElement.appendChild(importNode(e, true));
-       if (m_useIndex) updateIndexes(m_baseElement.childNodes());
+       result = m_baseElement.appendChild(importNode(e, true)).toElement();
+       if (m_useIndex) {
+           updateIndexes(m_baseElement.childNodes(), m_baseElement.childNodes().count() - 1);
+       }
     }
+    return result;
 }
 
 int EffectsList::count() const
@@ -327,7 +337,7 @@ void EffectsList::removeAt(int ix)
     QDomNodeList effects = m_baseElement.childNodes();
     if (ix <= 0 || ix > effects.count()) return;
     m_baseElement.removeChild(effects.at(ix - 1));
-    if (m_useIndex) updateIndexes(effects);
+    if (m_useIndex) updateIndexes(effects, ix - 1);
 }
 
 QDomElement EffectsList::itemFromIndex(int ix) const
@@ -337,23 +347,29 @@ QDomElement EffectsList::itemFromIndex(int ix) const
     return effects.at(ix - 1).toElement();
 }
 
-void EffectsList::insert(QDomElement effect)
+QDomElement EffectsList::insert(QDomElement effect)
 {
     QDomNodeList effects = m_baseElement.childNodes();
     int ix = effect.attribute("kdenlive_ix").toInt();
-    if (ix > effects.count()) m_baseElement.appendChild(importNode(effect, true));
+    QDomElement result;
+    if (ix <= 0 || ix > effects.count()) {
+        ix = effects.count();
+        result = m_baseElement.appendChild(importNode(effect, true)).toElement();
+    }
     else {
         QDomElement listeffect =  effects.at(ix - 1).toElement();
-       m_baseElement.insertBefore(importNode(effect, true), listeffect);
+        result = m_baseElement.insertBefore(importNode(effect, true), listeffect).toElement();
     }
-    if (m_useIndex) updateIndexes(effects);
+    if (m_useIndex && ix > 0)
+        updateIndexes(effects, ix - 1);
+    return result;
 }
 
-void EffectsList::updateIndexes(QDomNodeList effects)
+void EffectsList::updateIndexes(QDomNodeList effects, int startIndex)
 {
-    for (int i = 0; i < effects.count(); i++) {
+    for (int i = startIndex; i < effects.count(); i++) {
         QDomElement listeffect =  effects.at(i).toElement();
-       listeffect.setAttribute("kdenlive_ix", i + 1);
+        listeffect.setAttribute("kdenlive_ix", i + 1);
     }
 }
 
@@ -369,8 +385,8 @@ void EffectsList::updateEffect(QDomElement effect)
     int ix = effect.attribute("kdenlive_ix").toInt();
     QDomElement current = effectFromIndex(effects, ix);
     if (!current.isNull()) {
-       m_baseElement.insertBefore(importNode(effect, true), current);
-       m_baseElement.removeChild(current);
+        m_baseElement.insertBefore(importNode(effect, true), current);
+        m_baseElement.removeChild(current);
     }
     else m_baseElement.appendChild(importNode(effect, true));
 }