From e984daaf9adf6c89b62f5485abcd2d8e13414c39 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sat, 3 Sep 2022 15:16:33 +0200 Subject: [PATCH] add EffectChainPreset::isReadOnly --- src/effects/presets/effectchainpreset.cpp | 14 +++++++---- src/effects/presets/effectchainpreset.h | 7 ++++++ .../presets/effectchainpresetmanager.cpp | 24 +++++++++++++++---- src/widget/weffectchainpresetbutton.cpp | 14 +++++++---- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/effects/presets/effectchainpreset.cpp b/src/effects/presets/effectchainpreset.cpp index 69eb59a2befa..0df63a6342f1 100644 --- a/src/effects/presets/effectchainpreset.cpp +++ b/src/effects/presets/effectchainpreset.cpp @@ -7,7 +7,8 @@ EffectChainPreset::EffectChainPreset() : m_name(kNoEffectString), m_mixMode(EffectChainMixMode::DrySlashWet), - m_dSuper(0.0) { + m_dSuper(0.0), + m_readOnly(false) { } EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) { @@ -28,6 +29,8 @@ EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) { m_dSuper = XmlParse::selectNodeDouble(chainElement, EffectXml::kChainSuperParameter); + m_readOnly = false; + QDomElement effectsElement = XmlParse::selectElement(chainElement, EffectXml::kEffectsRoot); QDomNodeList effectList = effectsElement.childNodes(); @@ -47,7 +50,8 @@ EffectChainPreset::EffectChainPreset(const QDomElement& chainElement) { EffectChainPreset::EffectChainPreset(const EffectChain* chain) : m_name(chain->presetName()), m_mixMode(chain->mixMode()), - m_dSuper(chain->getSuperParameter()) { + m_dSuper(chain->getSuperParameter()), + m_readOnly(false) { for (const auto& pEffectSlot : chain->getEffectSlots()) { m_effectPresets.append(EffectPresetPointer(new EffectPreset(pEffectSlot))); } @@ -56,14 +60,16 @@ EffectChainPreset::EffectChainPreset(const EffectChain* chain) EffectChainPreset::EffectChainPreset(EffectManifestPointer pManifest) : m_name(pManifest->displayName()), m_mixMode(EffectChainMixMode::DrySlashWet), - m_dSuper(pManifest->metaknobDefault()) { + m_dSuper(pManifest->metaknobDefault()), + m_readOnly(false) { m_effectPresets.append(EffectPresetPointer(new EffectPreset(pManifest))); } EffectChainPreset::EffectChainPreset(EffectPresetPointer pEffectPreset) : m_name(pEffectPreset->id()), m_mixMode(EffectChainMixMode::DrySlashWet), - m_dSuper(pEffectPreset->metaParameter()) { + m_dSuper(pEffectPreset->metaParameter()), + m_readOnly(false) { m_effectPresets.append(pEffectPreset); } diff --git a/src/effects/presets/effectchainpreset.h b/src/effects/presets/effectchainpreset.h index 38c309550190..ad6aa9e71b6b 100644 --- a/src/effects/presets/effectchainpreset.h +++ b/src/effects/presets/effectchainpreset.h @@ -40,6 +40,12 @@ class EffectChainPreset { double superKnob() const { return m_dSuper; } + void setReadOnly(bool readOnly) { + m_readOnly = readOnly; + } + bool isReadOnly() const { + return m_readOnly; + } const QList& effectPresets() const { return m_effectPresets; @@ -50,4 +56,5 @@ class EffectChainPreset { EffectChainMixMode::Type m_mixMode; double m_dSuper; QList m_effectPresets; + bool m_readOnly; }; diff --git a/src/effects/presets/effectchainpresetmanager.cpp b/src/effects/presets/effectchainpresetmanager.cpp index ba7c2b75db66..b29f9e965293 100644 --- a/src/effects/presets/effectchainpresetmanager.cpp +++ b/src/effects/presets/effectchainpresetmanager.cpp @@ -233,8 +233,14 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) { VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(oldName)) { return; } - // Don't allow renaming the internal empty '---' preset - VERIFY_OR_DEBUG_ASSERT(oldName != kNoEffectString) { + if (m_effectChainPresets.value(oldName)->isReadOnly()) { + QMessageBox msgBox; + msgBox.setText(tr("Effect chain preset can not be renamed")); + msgBox.setInformativeText( + tr("Effect chain preset \"%1\" is read-only and can not be renamed.") + .arg(oldName)); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); return; } @@ -315,6 +321,16 @@ bool EffectChainPresetManager::deletePreset(const QString& chainPresetName) { VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(chainPresetName)) { return false; } + if (m_effectChainPresets.value(chainPresetName)->isReadOnly()) { + QMessageBox msgBox; + msgBox.setText(tr("Effect chain preset can not be deleted")); + msgBox.setInformativeText( + tr("Effect chain preset \"%1\" is read-only and can not be deleted.") + .arg(chainPresetName)); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); + return false; + } auto pressedButton = QMessageBox::question(nullptr, tr("Remove effect chain preset"), tr("Are you sure you want to delete the effect chain preset " @@ -702,11 +718,11 @@ EffectsXmlData EffectChainPresetManager::readEffectsXml( // It will not be visible in the effects preferences. EffectManifestPointer pEmptyChainManifest(new EffectManifest()); pEmptyChainManifest->setName(kNoEffectString); + // Required for the QuickEffect selector in DlgPrefEQ pEmptyChainManifest->setShortName(kNoEffectString); - auto pEmptyChainPreset = EffectChainPresetPointer(new EffectChainPreset(pEmptyChainManifest)); - pEmptyChainPreset->setName(pEmptyChainManifest->name()); + pEmptyChainPreset->setReadOnly(true); m_effectChainPresets.insert(pEmptyChainPreset->name(), pEmptyChainPreset); m_effectChainPresetsSorted.prepend(pEmptyChainPreset); diff --git a/src/widget/weffectchainpresetbutton.cpp b/src/widget/weffectchainpresetbutton.cpp index a7873955f5d6..33925af93c53 100644 --- a/src/widget/weffectchainpresetbutton.cpp +++ b/src/widget/weffectchainpresetbutton.cpp @@ -47,6 +47,7 @@ void WEffectChainPresetButton::populateMenu() { // Chain preset items bool chainIsPreset = false; + EffectChainPresetPointer pLoadedPreset; for (const auto& pChainPreset : m_pChainPresetManager->getPresetsSorted()) { // Don't show the empty '---' preset if (pChainPreset->name() == kNoEffectString) { @@ -57,13 +58,14 @@ void WEffectChainPresetButton::populateMenu() { title = QChar(0x2713) + // CHECK MARK QChar(' ') + title; chainIsPreset = true; + pLoadedPreset = pChainPreset; } m_pMenu->addAction(title, this, [this, pChainPreset]() { m_pChain->loadChainPreset(pChainPreset); }); } m_pMenu->addSeparator(); - if (chainIsPreset) { + if (chainIsPreset && !pLoadedPreset->isReadOnly()) { m_pMenu->addAction(tr("Update Preset"), this, [this]() { m_pChainPresetManager->updatePreset(m_pChain); }); @@ -134,11 +136,13 @@ void WEffectChainPresetButton::populateMenu() { pEffectMenu->addAction(pAction.get()); } } - pEffectMenu->addSeparator(); + if (!pLoadedPreset->isReadOnly()) { + pEffectMenu->addSeparator(); - pEffectMenu->addAction(tr("Save snapshot"), this, [this, pEffectSlot] { - m_pEffectsManager->getEffectPresetManager()->saveDefaultForEffect(pEffectSlot); - }); + pEffectMenu->addAction(tr("Save snapshot"), this, [this, pEffectSlot] { + m_pEffectsManager->getEffectPresetManager()->saveDefaultForEffect(pEffectSlot); + }); + } m_pMenu->addMenu(pEffectMenu); } }