| 409 | } |
| 410 | |
| 411 | bool EffectStackModel::fromXml(const QDomElement &effectsXml, Fun &undo, Fun &redo) |
| 412 | { |
| 413 | QDomNodeList nodeList = effectsXml.elementsByTagName(QStringLiteral("effect")); |
| 414 | int parentIn = effectsXml.attribute(QStringLiteral("parentIn")).toInt(); |
| 415 | int currentIn = pCore->getItemIn(m_ownerId); |
| 416 | PlaylistState::ClipState state = pCore->getItemState(m_ownerId).first; |
| 417 | bool effectAdded = false; |
| 418 | for (int i = 0; i < nodeList.count(); ++i) { |
| 419 | QDomElement node = nodeList.item(i).toElement(); |
| 420 | const QString effectId = node.attribute(QStringLiteral("id")); |
| 421 | bool isAudioEffect = EffectsRepository::get()->isAudioEffect(effectId); |
| 422 | if (state == PlaylistState::VideoOnly) { |
| 423 | if (isAudioEffect) { |
| 424 | continue; |
| 425 | } |
| 426 | } else if (state == PlaylistState::AudioOnly) { |
| 427 | if (!isAudioEffect) { |
| 428 | continue; |
| 429 | } |
| 430 | } |
| 431 | if (m_ownerId.type == KdenliveObjectType::TimelineClip && EffectsRepository::get()->isUnique(effectId) && hasFilter(effectId)) { |
| 432 | pCore->displayMessage(i18n("Effect %1 cannot be added twice.", EffectsRepository::get()->getName(effectId)), ErrorMessage); |
| 433 | return false; |
| 434 | } |
| 435 | bool effectEnabled = true; |
| 436 | if (Xml::hasXmlProperty(node, QLatin1String("disable"))) { |
| 437 | effectEnabled = Xml::getXmlProperty(node, QLatin1String("disable")).toInt() != 1; |
| 438 | } |
| 439 | if (Xml::getXmlProperty(node, QLatin1String("kdenlive:builtin")).toInt() == 1) { |
| 440 | if (!effectEnabled && !KdenliveSettings::enableBuiltInEffects()) { |
| 441 | continue; |
| 442 | } |
| 443 | // We are pasting a built in effect. Don't do a real paste, but copy the parameters to the existing effect |
| 444 | // get all properties |
| 445 | bool disableFound = Xml::hasXmlProperty(node, QLatin1String("disable")); |
| 446 | QDomNodeList props = node.elementsByTagName(QStringLiteral("property")); |
| 447 | QVector<QPair<QString, QVariant>> effectProps; |
| 448 | for (int j = 0; j < props.count(); ++j) { |
| 449 | QDomElement prop = props.item(j).toElement(); |
| 450 | const QString propName = prop.attribute(QStringLiteral("name")); |
| 451 | effectProps.append({propName, prop.firstChild().nodeValue()}); |
| 452 | } |
| 453 | // Built-in effects are disabled by default. So when pasting an effect that |
| 454 | // is enabled, ensure we overwrite the disabled state |
| 455 | if (!disableFound && effectEnabled) { |
| 456 | effectProps.append({QStringLiteral("disable"), 0}); |
| 457 | } |
| 458 | if (effectProps.isEmpty()) { |
| 459 | // Effect without params, drop |
| 460 | continue; |
| 461 | } |
| 462 | // Get current buildin effect |
| 463 | const std::shared_ptr<AssetParameterModel> model = getAssetModelById(effectId); |
| 464 | if (model) { |
| 465 | // Apply |
| 466 | QVector<QPair<QString, QVariant>> oldEffectProps = model->getAllParameters(); |
| 467 | Fun local_redo = [model, values = effectProps]() { |
| 468 | model->setParameters(values); |
no test coverage detected