]> git.sesse.net Git - kdenlive/blobdiff - src/effectslist.cpp
Use const'ref.
[kdenlive] / src / effectslist.cpp
index 2ceb03050a1fc63e1797a24a403b418e81b9926c..d6777eb73503e0602e928c7e8aa05569db80dcb6 100644 (file)
@@ -54,6 +54,17 @@ QDomElement EffectsList::getEffectByName(const QString & name) const
     return QDomElement();
 }
 
+
+void EffectsList::initEffect(QDomElement effect) const
+{
+    QDomNodeList params = effect.elementsByTagName("parameter");
+    for (int i = 0; i < params.count(); i++) {
+       QDomElement e = params.item(i).toElement();
+       if (!e.hasAttribute("value"))
+           e.setAttribute("value", e.attribute("default"));
+    }
+}
+
 QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id) const
 {
     QDomNodeList effects = m_baseElement.childNodes();
@@ -61,22 +72,20 @@ QDomElement EffectsList::getEffectByTag(const QString & tag, const QString & id)
         QDomElement effect =  effects.at(i).toElement();
         if (!id.isEmpty()) {
             if (effect.attribute("id") == id) {
-                QDomNodeList params = effect.elementsByTagName("parameter");
-                for (int i = 0; i < params.count(); i++) {
-                    QDomElement e = params.item(i).toElement();
-                    if (!e.hasAttribute("value"))
-                        e.setAttribute("value", e.attribute("default"));
-                }
+               if (effect.tagName() == "effectgroup") {
+                   // Effect group
+                   QDomNodeList subeffects = effect.elementsByTagName("effect");
+                   for (int j = 0; j < subeffects.count(); j++) {
+                       QDomElement sub = subeffects.at(j).toElement();
+                       initEffect(sub);
+                   }
+               }
+               else initEffect(effect);
                 return effect;
             }
         } else if (!tag.isEmpty()) {
             if (effect.attribute("tag") == tag) {
-                QDomNodeList params = effect.elementsByTagName("parameter");
-                for (int i = 0; i < params.count(); i++) {
-                    QDomElement e = params.item(i).toElement();
-                    if (!e.hasAttribute("value"))
-                        e.setAttribute("value", e.attribute("default"));
-                }
+                initEffect(effect);
                 return effect;
             }
         }
@@ -102,7 +111,7 @@ QStringList EffectsList::effectIdInfo(const int ix) const
     QDomElement effect = m_baseElement.childNodes().at(ix).toElement();
     if (effect.tagName() == "effectgroup") {
        QString groupName = effect.attribute("name");
-       info << groupName << groupName << groupName << QString::number(Kdenlive::groupEffect);
+       info << groupName << groupName << effect.attribute("id") << QString::number(Kdenlive::groupEffect);
     }
     else {
        QDomElement namenode = effect.firstChildElement("name");
@@ -203,13 +212,24 @@ void EffectsList::clearList()
 void EffectsList::setParameter(QDomElement effect, const QString &name, const QString &value)
 {
     QDomNodeList params = effect.elementsByTagName("parameter");
+    bool found = false;
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
         if (e.attribute("name") == name) {
             e.setAttribute("value", value);
+           found = true;
             break;
         }
     }
+    if (!found) {
+       // create property
+       QDomDocument doc = effect.ownerDocument();
+       QDomElement e = doc.createElement("parameter");
+       e.setAttribute("name", name);
+       QDomText val = doc.createTextNode(value);
+       e.appendChild(val);
+       effect.appendChild(e);
+    }
 }
 
 // static
@@ -352,15 +372,16 @@ QDomElement EffectsList::insert(QDomElement effect)
     QDomNodeList effects = m_baseElement.childNodes();
     int ix = effect.attribute("kdenlive_ix").toInt();
     QDomElement result;
-    if (effect.hasAttribute("kdenlive_ix") && ix > effects.count()) {
-       ix = effects.count();
-       result = m_baseElement.appendChild(importNode(effect, true)).toElement();
+    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();
-       result = m_baseElement.insertBefore(importNode(effect, true), listeffect).toElement();
+        result = m_baseElement.insertBefore(importNode(effect, true), listeffect).toElement();
     }
-    if (m_useIndex) updateIndexes(effects, ix - 1);
+    if (m_useIndex && ix > 0)
+        updateIndexes(effects, ix - 1);
     return result;
 }
 
@@ -368,7 +389,17 @@ void EffectsList::updateIndexes(QDomNodeList effects, int startIndex)
 {
     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);
+    }
+}
+
+void EffectsList::enableEffects(QList <int> indexes, bool disable)
+{
+    QDomNodeList effects = m_baseElement.childNodes();
+    QDomElement effect;
+    for (int i = 0; i < indexes.count(); i++) {
+        effect =  effectFromIndex(effects, indexes.at(i));
+        effect.setAttribute("disable", (int) disable);
     }
 }
 
@@ -384,8 +415,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));
 }