comparison main/MainWindow.cpp @ 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 e78f2c842a55
children a8f913f79bd7
comparison
equal deleted inserted replaced
672:de3d628e048e 673:90ee5448c205
811 } 811 }
812 812
813 void 813 void
814 MainWindow::resetAnalyseOptions() 814 MainWindow::resetAnalyseOptions()
815 { 815 {
816 //!!! oh no, we need to update the menu states as well...
817 QSettings settings; 816 QSettings settings;
818 settings.beginGroup("Analyser"); 817 settings.beginGroup("Analyser");
818
819 settings.setValue("auto-analysis", true); 819 settings.setValue("auto-analysis", true);
820 settings.setValue("precision-analysis", false); 820
821 settings.setValue("lowamp-analysis", true); 821 auto keyMap = Analyser::getAnalysisSettings();
822 settings.setValue("onset-analysis", true); 822 for (auto p: keyMap) {
823 settings.setValue("prune-analysis", true); 823 settings.setValue(p.first, p.second);
824 }
825
824 settings.endGroup(); 826 settings.endGroup();
825 updateAnalyseStates(); 827 updateAnalyseStates();
826 } 828 }
827 829
828 void 830 void
829 MainWindow::updateAnalyseStates() 831 MainWindow::updateAnalyseStates()
830 { 832 {
831 QSettings settings; 833 QSettings settings;
832 settings.beginGroup("Analyser"); 834 settings.beginGroup("Analyser");
835
833 bool autoAnalyse = settings.value("auto-analysis", true).toBool(); 836 bool autoAnalyse = settings.value("auto-analysis", true).toBool();
834 bool precise = settings.value("precision-analysis", false).toBool(); 837 m_autoAnalyse->setChecked(autoAnalyse);
835 bool lowamp = settings.value("lowamp-analysis", true).toBool(); 838
836 bool onset = settings.value("onset-analysis", true).toBool(); 839 std::map<QString, QAction *> actions {
837 bool prune = settings.value("prune-analysis", true).toBool(); 840 { "precision-analysis", m_precise },
841 { "lowamp-analysis", m_lowamp },
842 { "onset-analysis", m_onset },
843 { "prune-analysis", m_prune }
844 };
845
846 auto keyMap = Analyser::getAnalysisSettings();
847
848 for (auto p: actions) {
849 auto ki = keyMap.find(p.first);
850 if (ki != keyMap.end()) {
851 p.second->setChecked(settings.value
852 (ki->first, ki->second).toBool());
853 } else {
854 throw std::logic_error("Internal error: One or more analysis settings keys not found in map returned by Analyser: check updateAnalyseStates and getAnalysisSettings");
855 }
856 }
857
838 settings.endGroup(); 858 settings.endGroup();
839
840 m_autoAnalyse->setChecked(autoAnalyse);
841 m_precise->setChecked(precise);
842 m_lowamp->setChecked(lowamp);
843 m_onset->setChecked(onset);
844 m_prune->setChecked(prune);
845 } 859 }
846 860
847 void 861 void
848 MainWindow::autoAnalysisToggled() 862 MainWindow::autoAnalysisToggled()
849 { 863 {
854 868
855 QSettings settings; 869 QSettings settings;
856 settings.beginGroup("Analyser"); 870 settings.beginGroup("Analyser");
857 settings.setValue("auto-analysis", set); 871 settings.setValue("auto-analysis", set);
858 settings.endGroup(); 872 settings.endGroup();
873
874 // make result visible explicitly, in case e.g. we just set the wrong key
875 updateAnalyseStates();
859 } 876 }
860 877
861 void 878 void
862 MainWindow::precisionAnalysisToggled() 879 MainWindow::precisionAnalysisToggled()
863 { 880 {
870 settings.beginGroup("Analyser"); 887 settings.beginGroup("Analyser");
871 settings.setValue("precision-analysis", set); 888 settings.setValue("precision-analysis", set);
872 settings.endGroup(); 889 settings.endGroup();
873 890
874 // don't run analyseNow() automatically -- it's a destructive operation 891 // don't run analyseNow() automatically -- it's a destructive operation
892
893 // make result visible explicitly, in case e.g. we just set the wrong key
894 updateAnalyseStates();
875 } 895 }
876 896
877 void 897 void
878 MainWindow::lowampAnalysisToggled() 898 MainWindow::lowampAnalysisToggled()
879 { 899 {
886 settings.beginGroup("Analyser"); 906 settings.beginGroup("Analyser");
887 settings.setValue("lowamp-analysis", set); 907 settings.setValue("lowamp-analysis", set);
888 settings.endGroup(); 908 settings.endGroup();
889 909
890 // don't run analyseNow() automatically -- it's a destructive operation 910 // don't run analyseNow() automatically -- it's a destructive operation
911
912 // make result visible explicitly, in case e.g. we just set the wrong key
913 updateAnalyseStates();
891 } 914 }
892 915
893 void 916 void
894 MainWindow::onsetAnalysisToggled() 917 MainWindow::onsetAnalysisToggled()
895 { 918 {
902 settings.beginGroup("Analyser"); 925 settings.beginGroup("Analyser");
903 settings.setValue("onset-analysis", set); 926 settings.setValue("onset-analysis", set);
904 settings.endGroup(); 927 settings.endGroup();
905 928
906 // don't run analyseNow() automatically -- it's a destructive operation 929 // don't run analyseNow() automatically -- it's a destructive operation
930
931 // make result visible explicitly, in case e.g. we just set the wrong key
932 updateAnalyseStates();
907 } 933 }
908 934
909 void 935 void
910 MainWindow::pruneAnalysisToggled() 936 MainWindow::pruneAnalysisToggled()
911 { 937 {
918 settings.beginGroup("Analyser"); 944 settings.beginGroup("Analyser");
919 settings.setValue("prune-analysis", set); 945 settings.setValue("prune-analysis", set);
920 settings.endGroup(); 946 settings.endGroup();
921 947
922 // don't run analyseNow() automatically -- it's a destructive operation 948 // don't run analyseNow() automatically -- it's a destructive operation
949
950 // make result visible explicitly, in case e.g. we just set the wrong key
951 updateAnalyseStates();
923 } 952 }
924 953
925 void 954 void
926 MainWindow::setupHelpMenu() 955 MainWindow::setupHelpMenu()
927 { 956 {