From 9ea4905b450b6c4f7eb275e8e58f255288ee84e3 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 5 Jun 2018 17:17:52 +0200 Subject: Add QString cast to Configuration::value --- config/main.cpp | 2 +- config/settingsdialog.cpp | 6 +----- lib/configuration/configuration.h | 29 +++++++++++++++-------------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/config/main.cpp b/config/main.cpp index 569249c..2597e35 100644 --- a/config/main.cpp +++ b/config/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char **argv) SettingsDialog dlg(&config); dlg.configPath = QString::fromStdString(config.value("config").value()); - dlg.setWindowTitle("poi-config: " + dlg.configPath); + dlg.setWindowTitle(dlg.configPath); dlg.show(); return app.exec(); diff --git a/config/settingsdialog.cpp b/config/settingsdialog.cpp index cc8cb8e..5ff4328 100644 --- a/config/settingsdialog.cpp +++ b/config/settingsdialog.cpp @@ -94,9 +94,5 @@ void SettingsDialog::write(const QString &path) output.close(); unsavedChanges = false; - if(windowTitle().endsWith('*')) { - QString title = windowTitle(); - title.chop(1); - setWindowTitle(title); - } + setWindowTitle(configPath); } diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index 1d0fb54..1df6bb5 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -43,32 +43,33 @@ public: if(vm.count(path) == 0) { #ifdef QT_DEBUG - qWarning("value(%s) does not exist, probably crashing now", path); + qWarning("value(%s) does not exist", path); #endif return std::nullopt; } - if constexpr(std::is_same_v) { - std::string r; - try { - r = vm[path].as(); - } catch(boost::bad_any_cast &) { - // try int - try { - r = std::to_string(vm[path].as()); - } catch(boost::bad_any_cast &) { - - // try bool, and crash if not that either - r = vm[path].as() ? "true" : "false"; - } + if constexpr(std::is_same_v) { + return std::optional(vm[path].as()); + + } else if constexpr(std::is_same_v) { + + if (vm[path].value().type() == typeid(int)) { + return std::optional(std::to_string(vm[path].as())); + } + + if (vm[path].value().type() == typeid(bool)) { + return std::optional(vm[path].as() ? "true" : "false"); } + std::string r = vm[path].as(); + // check if it's a path if(r.front() == '~') { r.replace(0, 1, m_homePath); } return std::optional(r); + } else return std::optional(vm[path].as()); } -- cgit v1.2.1