Skip to content

Commit

Permalink
DlgPrefEffects: fix preset removed from list when canceling delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Oct 22, 2021
1 parent cfaeec9 commit d59011f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/effects/presets/effectchainpresetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,17 @@ void EffectChainPresetManager::renamePreset(const QString& oldName) {
emit effectChainPresetListUpdated();
}

void EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
bool EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
VERIFY_OR_DEBUG_ASSERT(m_effectChainPresets.contains(chainPresetName)) {
return;
return false;
}
auto pressedButton = QMessageBox::question(nullptr,
tr("Remove effect chain preset"),
tr("Are you sure you want to delete the effect chain preset "
"\"%1\"?")
.arg(chainPresetName));
if (pressedButton != QMessageBox::Yes) {
return;
return false;
}

QFile file(m_pConfig->getSettingsPath() + kEffectChainPresetDirectory +
Expand All @@ -318,7 +318,7 @@ void EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
msgBox.setDetailedText(file.errorString());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
return;
return false;
}

EffectChainPresetPointer pPreset =
Expand All @@ -327,6 +327,7 @@ void EffectChainPresetManager::deletePreset(const QString& chainPresetName) {
m_quickEffectChainPresetsSorted.removeAll(pPreset);
emit effectChainPresetListUpdated();
emit quickEffectChainPresetListUpdated();
return true;
}

void EffectChainPresetManager::setPresetOrder(
Expand Down
2 changes: 1 addition & 1 deletion src/effects/presets/effectchainpresetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EffectChainPresetManager : public QObject {
void importPreset();
void exportPreset(const QString& chainPresetName);
void renamePreset(const QString& oldName);
void deletePreset(const QString& chainPresetName);
bool deletePreset(const QString& chainPresetName);

void resetToDefaults();

Expand Down
7 changes: 5 additions & 2 deletions src/preferences/dialog/dlgprefeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ void DlgPrefEffects::slotDeletePreset() {
for (const auto& index : selectedIndices) {
QString selectedPresetName =
m_pFocusedChainList->model()->data(index).toString();
focusedChainStringList.removeAll(selectedPresetName);
if (!unfocusedChainStringList.contains(selectedPresetName)) {
m_pChainPresetManager->deletePreset(selectedPresetName);
if (m_pChainPresetManager->deletePreset(selectedPresetName)) {
focusedChainStringList.removeAll(selectedPresetName);
}
} else {
focusedChainStringList.removeAll(selectedPresetName);
}
}

Expand Down

0 comments on commit d59011f

Please sign in to comment.