Mercurial > hg > tony
changeset 673:90ee5448c205
Fix inconsistency between MainWindow and Analyser in the default value of the lowampsuppression option, and enforce default values in a single place. As it stood, the menu option was showing "checked" (on first run) but the parameter was actually unset until you toggled it or used the reset-to-default function.
author | Chris Cannam |
---|---|
date | Mon, 18 Nov 2019 15:07:19 +0000 |
parents | de3d628e048e |
children | 1d97a86274f1 |
files | main/Analyser.cpp main/Analyser.h main/MainWindow.cpp |
diffstat | 3 files changed, 82 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/main/Analyser.cpp Mon Nov 18 15:05:26 2019 +0000 +++ b/main/Analyser.cpp Mon Nov 18 15:07:19 2019 +0000 @@ -67,6 +67,16 @@ { } +std::map<QString, QVariant> +Analyser::getAnalysisSettings() +{ + return { { "precision-analysis", false }, + { "lowamp-analysis", true }, + { "onset-analysis", true }, + { "prune-analysis", true } + }; +} + QString Analyser::newFileLoaded(Document *doc, ModelId model, PaneStack *paneStack, Pane *pane) @@ -398,10 +408,27 @@ QSettings settings; settings.beginGroup("Analyser"); - bool precise = settings.value("precision-analysis", false).toBool(); - bool lowamp = settings.value("lowamp-analysis", false).toBool(); - bool onset = settings.value("onset-analysis", true).toBool(); // should these be the same as in MainWindow.cpp? - bool prune = settings.value("prune-analysis", true).toBool(); + + bool precise = false, lowamp = true, onset = true, prune = true; + + std::map<QString, bool &> flags { + { "precision-analysis", precise }, + { "lowamp-analysis", lowamp }, + { "onset-analysis", onset }, + { "prune-analysis", prune } + }; + + auto keyMap = getAnalysisSettings(); + + for (auto p: flags) { + auto ki = keyMap.find(p.first); + if (ki != keyMap.end()) { + p.second = settings.value(ki->first, ki->second).toBool(); + } else { + throw std::logic_error("Internal error: One or more analysis settings keys not found in map: check addAnalyses and getAnalysisSettings"); + } + } + settings.endGroup(); Transform t = tf->getDefaultTransformFor
--- a/main/Analyser.h Mon Nov 18 15:05:26 2019 +0000 +++ b/main/Analyser.h Mon Nov 18 15:07:19 2019 +0000 @@ -121,6 +121,13 @@ }; /** + * Return the QSettings keys, and their default values, that + * affect analysis behaviour. These all live within the Analyser + * group in QSettings. + */ + static std::map<QString, QVariant> getAnalysisSettings(); + + /** * Analyse the selection and schedule asynchronous adds of * candidate layers for the region it contains. Returns "" on * success or a user-readable error string on failure. If the
--- a/main/MainWindow.cpp Mon Nov 18 15:05:26 2019 +0000 +++ b/main/MainWindow.cpp Mon Nov 18 15:07:19 2019 +0000 @@ -813,14 +813,16 @@ void MainWindow::resetAnalyseOptions() { - //!!! oh no, we need to update the menu states as well... QSettings settings; settings.beginGroup("Analyser"); + settings.setValue("auto-analysis", true); - settings.setValue("precision-analysis", false); - settings.setValue("lowamp-analysis", true); - settings.setValue("onset-analysis", true); - settings.setValue("prune-analysis", true); + + auto keyMap = Analyser::getAnalysisSettings(); + for (auto p: keyMap) { + settings.setValue(p.first, p.second); + } + settings.endGroup(); updateAnalyseStates(); } @@ -830,18 +832,30 @@ { QSettings settings; settings.beginGroup("Analyser"); + bool autoAnalyse = settings.value("auto-analysis", true).toBool(); - bool precise = settings.value("precision-analysis", false).toBool(); - bool lowamp = settings.value("lowamp-analysis", true).toBool(); - bool onset = settings.value("onset-analysis", true).toBool(); - bool prune = settings.value("prune-analysis", true).toBool(); + m_autoAnalyse->setChecked(autoAnalyse); + + std::map<QString, QAction *> actions { + { "precision-analysis", m_precise }, + { "lowamp-analysis", m_lowamp }, + { "onset-analysis", m_onset }, + { "prune-analysis", m_prune } + }; + + auto keyMap = Analyser::getAnalysisSettings(); + + for (auto p: actions) { + auto ki = keyMap.find(p.first); + if (ki != keyMap.end()) { + p.second->setChecked(settings.value + (ki->first, ki->second).toBool()); + } else { + throw std::logic_error("Internal error: One or more analysis settings keys not found in map returned by Analyser: check updateAnalyseStates and getAnalysisSettings"); + } + } + settings.endGroup(); - - m_autoAnalyse->setChecked(autoAnalyse); - m_precise->setChecked(precise); - m_lowamp->setChecked(lowamp); - m_onset->setChecked(onset); - m_prune->setChecked(prune); } void @@ -856,6 +870,9 @@ settings.beginGroup("Analyser"); settings.setValue("auto-analysis", set); settings.endGroup(); + + // make result visible explicitly, in case e.g. we just set the wrong key + updateAnalyseStates(); } void @@ -872,6 +889,9 @@ settings.endGroup(); // don't run analyseNow() automatically -- it's a destructive operation + + // make result visible explicitly, in case e.g. we just set the wrong key + updateAnalyseStates(); } void @@ -888,6 +908,9 @@ settings.endGroup(); // don't run analyseNow() automatically -- it's a destructive operation + + // make result visible explicitly, in case e.g. we just set the wrong key + updateAnalyseStates(); } void @@ -904,6 +927,9 @@ settings.endGroup(); // don't run analyseNow() automatically -- it's a destructive operation + + // make result visible explicitly, in case e.g. we just set the wrong key + updateAnalyseStates(); } void @@ -920,6 +946,9 @@ settings.endGroup(); // don't run analyseNow() automatically -- it's a destructive operation + + // make result visible explicitly, in case e.g. we just set the wrong key + updateAnalyseStates(); } void