diff options
-rw-r--r-- | config/main.cpp | 2 | ||||
-rw-r--r-- | config/settingsdialog.cpp | 6 | ||||
-rw-r--r-- | 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<std::string>("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<T, std::string>) { - std::string r; - try { - r = vm[path].as<std::string>(); - } catch(boost::bad_any_cast &) { - // try int - try { - r = std::to_string(vm[path].as<int>()); - } catch(boost::bad_any_cast &) { - - // try bool, and crash if not that either - r = vm[path].as<bool>() ? "true" : "false"; - } + if constexpr(std::is_same_v<T, QString>) { + return std::optional<QString>(vm[path].as<const char*>()); + + } else if constexpr(std::is_same_v<T, std::string>) { + + if (vm[path].value().type() == typeid(int)) { + return std::optional<std::string>(std::to_string(vm[path].as<int>())); + } + + if (vm[path].value().type() == typeid(bool)) { + return std::optional<std::string>(vm[path].as<bool>() ? "true" : "false"); } + std::string r = vm[path].as<std::string>(); + // check if it's a path if(r.front() == '~') { r.replace(0, 1, m_homePath); } return std::optional<std::string>(r); + } else return std::optional<T>(vm[path].as<T>()); } |