From c2a4655e6cf3a34f0e8693be0ab9961f6d5f9025 Mon Sep 17 00:00:00 2001
From: David Fairbrother <DavidFair@users.noreply.github.com>
Date: Wed, 1 Aug 2018 19:07:35 +0100
Subject: [PATCH] Re #22647 Switch getString calls to use bool getValue in
 config

---
 Framework/API/src/FileFinder.cpp              | 10 ++---
 Framework/API/src/MultipleFileProperty.cpp    |  5 +--
 .../src/CreateUserDefinedBackground.cpp       |  3 +-
 Framework/Kernel/src/ConfigService.cpp        | 14 +++----
 MantidPlot/src/ApplicationWindow.cpp          |  3 +-
 MantidPlot/src/ConfigDialog.cpp               | 38 +++++++------------
 MantidPlot/src/Mantid/MantidUI.cpp            |  5 +--
 .../instrumentview/src/InstrumentWidget.cpp   |  4 +-
 8 files changed, 31 insertions(+), 51 deletions(-)

diff --git a/Framework/API/src/FileFinder.cpp b/Framework/API/src/FileFinder.cpp
index dae90655461..67a8d923f6e 100644
--- a/Framework/API/src/FileFinder.cpp
+++ b/Framework/API/src/FileFinder.cpp
@@ -62,13 +62,9 @@ FileFinderImpl::FileFinderImpl() {
 #ifdef _WIN32
   m_globOption = Poco::Glob::GLOB_DEFAULT;
 #else
-  std::string casesensitive =
-      Mantid::Kernel::ConfigService::Instance().getString(
-          "filefinder.casesensitive");
-  if (boost::iequals("Off", casesensitive))
-    m_globOption = Poco::Glob::GLOB_CASELESS;
-  else
-    m_globOption = Poco::Glob::GLOB_DEFAULT;
+  m_globOption =
+	  Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+		  "filefinder.casesensitive").get_value_or_default(false);
 #endif
 }
 
diff --git a/Framework/API/src/MultipleFileProperty.cpp b/Framework/API/src/MultipleFileProperty.cpp
index f043f819254..9b6d6e1170f 100644
--- a/Framework/API/src/MultipleFileProperty.cpp
+++ b/Framework/API/src/MultipleFileProperty.cpp
@@ -79,10 +79,9 @@ MultipleFileProperty::MultipleFileProperty(const std::string &name,
   } else {
     m_action = action;
   }
-  std::string allowMultiFileLoading =
-      Kernel::ConfigService::Instance().getString("loading.multifile");
 
-  m_multiFileLoadingEnabled = boost::iequals(allowMultiFileLoading, "On");
+  m_multiFileLoadingEnabled =
+      Kernel::ConfigService::Instance().getValue<bool>("loading.multifile").get_value_or(false);
 
   for (const auto &ext : exts)
     if (doesNotContainWildCard(ext))
diff --git a/Framework/Algorithms/src/CreateUserDefinedBackground.cpp b/Framework/Algorithms/src/CreateUserDefinedBackground.cpp
index 6c4ad35100e..8d4f9d0e66a 100644
--- a/Framework/Algorithms/src/CreateUserDefinedBackground.cpp
+++ b/Framework/Algorithms/src/CreateUserDefinedBackground.cpp
@@ -171,8 +171,7 @@ CreateUserDefinedBackground::createBackgroundWorkspace(
     histogram.setFrequencyStandardDeviations(eBackground);
   } else {
     if (data->isHistogramData() &&
-        "On" ==
-            Kernel::ConfigService::Instance().getString(AUTODISTRIBUTIONKEY)) {
+            Kernel::ConfigService::Instance().getValue<bool>(AUTODISTRIBUTIONKEY).get_value_or(false)) {
       // Background data is actually frequencies, we put it into temporary to
       // benefit from automatic conversion in setCounts(), etc.
       histogram.setCounts(Frequencies(yBackground), xBinEdges);
diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp
index f1f3c6005ac..c024e7d4a4b 100644
--- a/Framework/Kernel/src/ConfigService.cpp
+++ b/Framework/Kernel/src/ConfigService.cpp
@@ -938,15 +938,13 @@ std::string ConfigServiceImpl::getString(const std::string &keyName,
       return (*mitr).second;
     }
   }
-  std::string retVal;
-  try {
-    retVal = m_pConf->getString(keyName);
-  } catch (Poco::NotFoundException &) {
-    g_log.debug() << "Unable to find " << keyName << " in the properties file"
-                  << '\n';
-    retVal = "";
+  if (m_pConf->hasProperty(keyName)) {
+	  return m_pConf->getString(keyName);
   }
-  return retVal;
+
+  g_log.debug() << "Unable to find " << keyName << " in the properties file"
+				<< '\n';
+  return;
 }
 
 /** Searches for keys within the currently loaded configuaration values and
diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp
index 76c35b7c351..3e004fe93b5 100644
--- a/MantidPlot/src/ApplicationWindow.cpp
+++ b/MantidPlot/src/ApplicationWindow.cpp
@@ -5014,8 +5014,7 @@ void ApplicationWindow::readSettings() {
     settings.remove("/AutoDistribution1D");
   }
   // Pull default from config service
-  const std::string propStr = cfgSvc.getString("graph1d.autodistribution");
-  autoDistribution1D = (propStr == "On");
+  const bool autoDistribution1D = cfgSvc.getValue<bool>("graph1d.autodistribution").get_value_or(false);
 
   canvasFrameWidth = settings.value("/CanvasFrameWidth", 0).toInt();
   defaultPlotMargin = settings.value("/Margin", 0).toInt();
diff --git a/MantidPlot/src/ConfigDialog.cpp b/MantidPlot/src/ConfigDialog.cpp
index 447d0f7d273..b3457451f84 100644
--- a/MantidPlot/src/ConfigDialog.cpp
+++ b/MantidPlot/src/ConfigDialog.cpp
@@ -961,14 +961,11 @@ void ConfigDialog::initMantidOptionsTab() {
       new QCheckBox("Re-use plot instances for different types of plots");
   m_reusePlotInstances->setChecked(false);
   grid->addWidget(m_reusePlotInstances, 0, 0);
-  QString setting = QString::fromStdString(
-      Mantid::Kernel::ConfigService::Instance().getString(
-          "MantidOptions.ReusePlotInstances"));
-  if (!setting.compare("On")) {
-    m_reusePlotInstances->setChecked(true);
-  } else if (!setting.compare("Off")) {
-    m_reusePlotInstances->setChecked(false);
-  }
+
+  bool setting = Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+	  "MantidOptions.ReusePlotInstances").get_value_or(false);
+
+  m_reusePlotInstance->setChecked(setting);
   m_reusePlotInstances->setToolTip("If on, the same plot instance will be "
                                    "re-used for every of the different plots "
                                    "available in the workspaces window "
@@ -979,14 +976,11 @@ void ConfigDialog::initMantidOptionsTab() {
   m_invisibleWorkspaces->setChecked(false);
   grid->addWidget(m_invisibleWorkspaces, 1, 0);
 
-  setting = QString::fromStdString(
-      Mantid::Kernel::ConfigService::Instance().getString(
-          "MantidOptions.InvisibleWorkspaces"));
-  if (!setting.compare("1")) {
-    m_invisibleWorkspaces->setChecked(true);
-  } else if (!setting.compare("0")) {
-    m_invisibleWorkspaces->setChecked(false);
-  }
+  bool invisibleWsSetting =
+      Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+          "MantidOptions.InvisibleWorkspaces").get_value_or(false);
+  
+  m_invisibleWorkspaces->setChecked(invisibleWsSetting);
 
   // categories tree widget
   treeCategories = new QTreeWidget(frame);
@@ -1004,14 +998,10 @@ void ConfigDialog::initMantidOptionsTab() {
   m_useOpenGL->setChecked(true);
   grid->addWidget(m_useOpenGL, 4, 0);
 
-  setting = QString::fromStdString(
-                Mantid::Kernel::ConfigService::Instance().getString(
-                    "MantidOptions.InstrumentView.UseOpenGL")).toUpper();
-  if (setting == "ON") {
-    m_useOpenGL->setChecked(true);
-  } else {
-    m_useOpenGL->setChecked(false);
-  }
+  bool openglSetting = Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+                    "MantidOptions.InstrumentView.UseOpenGL").get_value_or(false);
+  
+  m_useOpenGL->setChecked(openglSetting);
 }
 
 void ConfigDialog::initSendToProgramTab() {
diff --git a/MantidPlot/src/Mantid/MantidUI.cpp b/MantidPlot/src/Mantid/MantidUI.cpp
index a67ed40590c..d28cce61648 100644
--- a/MantidPlot/src/Mantid/MantidUI.cpp
+++ b/MantidPlot/src/Mantid/MantidUI.cpp
@@ -3822,9 +3822,8 @@ void MantidUI::loadWSFromFile(const std::string &wsName,
 }
 
 bool MantidUI::workspacesDockPlot1To1() {
-  return "On" ==
-         Mantid::Kernel::ConfigService::Instance().getString(
-             "MantidOptions.ReusePlotInstances");
+  return Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+             "MantidOptions.ReusePlotInstances").get_value_or(false);
 }
 
 /**
diff --git a/qt/widgets/instrumentview/src/InstrumentWidget.cpp b/qt/widgets/instrumentview/src/InstrumentWidget.cpp
index 0031049fc8c..e8904950601 100644
--- a/qt/widgets/instrumentview/src/InstrumentWidget.cpp
+++ b/qt/widgets/instrumentview/src/InstrumentWidget.cpp
@@ -264,8 +264,8 @@ void InstrumentWidget::init(bool resetGeometry, bool autoscaling,
       QString defaultView =
           QString::fromStdString(m_instrumentActor->getDefaultView());
       if (defaultView == "3D" &&
-          Mantid::Kernel::ConfigService::Instance().getString(
-              "MantidOptions.InstrumentView.UseOpenGL") != "On") {
+          Mantid::Kernel::ConfigService::Instance().getValue<bool>(
+              "MantidOptions.InstrumentView.UseOpenGL").get_value_or(false)) {
         // if OpenGL is switched off don't open the 3D view at start up
         defaultView = "CYLINDRICAL_Y";
       }
-- 
GitLab