diff options
Diffstat (limited to 'lib/settings')
-rw-r--r-- | lib/settings/configuration.cpp | 7 | ||||
-rw-r--r-- | lib/settings/configuration.h | 2 | ||||
-rw-r--r-- | lib/settings/settingsdialog.cpp | 25 |
3 files changed, 27 insertions, 7 deletions
diff --git a/lib/settings/configuration.cpp b/lib/settings/configuration.cpp index d91ae97..34d50db 100644 --- a/lib/settings/configuration.cpp +++ b/lib/settings/configuration.cpp @@ -95,6 +95,13 @@ std::vector<std::string> Configuration::childrenGroups(const char* name) return groupNames; } +void Configuration::resetValue(const char *path) +{ + if(m_userCfg->exists(path)) { + m_userCfg->getRoot().remove(path); + } +} + template<typename T> std::optional<T> Configuration::value(const char* path) const { diff --git a/lib/settings/configuration.h b/lib/settings/configuration.h index 49f92d6..1909eb8 100644 --- a/lib/settings/configuration.h +++ b/lib/settings/configuration.h @@ -32,6 +32,8 @@ public: std::vector<std::string> childrenSettings(const char *name = ""); std::vector<std::string> childrenGroups(const char *name = ""); + void resetValue(const char* path); + template<typename T> std::optional<T> value(const char* path) const; diff --git a/lib/settings/settingsdialog.cpp b/lib/settings/settingsdialog.cpp index 2b11416..6de3894 100644 --- a/lib/settings/settingsdialog.cpp +++ b/lib/settings/settingsdialog.cpp @@ -9,13 +9,14 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" #include "configuration.h" +#include <QScrollArea> #include <QFormLayout> #include <QHBoxLayout> #include <QLineEdit> #include <QToolButton> #include <QGroupBox> -inline QHBoxLayout *createEntry(const QString &value, QWidget *widget); +inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget); SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent) : QDialog(parent), @@ -24,8 +25,10 @@ SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget ui->setupUi(this); for(const std::string &group : settings->childrenGroups("")) { - QWidget *widget = widgetForGroup(settings, group, this); - ui->tabWidget->addTab(widget, QString::fromStdString(group)); + QScrollArea *area = new QScrollArea(this); + area->setWidgetResizable(true); + area->setWidget(widgetForGroup(settings, group, this)); + ui->tabWidget->addTab(area, QString::fromStdString(group)); } } @@ -43,7 +46,7 @@ QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::str // add entry for every key QFormLayout *form = new QFormLayout(); for(const std::string &key : settings->childrenSettings(group.c_str())) { - QHBoxLayout *hBox = createEntry(QString::fromStdString(settings->value<std::string>((group + '.' + key).c_str()).value()), widget); + QHBoxLayout *hBox = createEntry(settings.get(), group + '.' + key, widget); form->addRow(parent->tr(key.c_str()), hBox); } layout->addLayout(form); @@ -57,7 +60,7 @@ QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::str const std::string groupPath = group + '.' + childGroup; for(const std::string &key : settings->childrenSettings(groupPath.c_str())) { - QHBoxLayout *hBox = createEntry(QString::fromStdString(settings->value<std::string>((groupPath + '.' + key).c_str()).value()), groupBox); + QHBoxLayout *hBox = createEntry(settings.get(), groupPath + '.' + key, groupBox); boxForm->addRow(parent->tr(key.c_str()), hBox); } } @@ -65,13 +68,21 @@ QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::str return widget; } -inline QHBoxLayout *createEntry(const QString &value, QWidget *widget) +inline QHBoxLayout *createEntry(Configuration* config, const std::string &path, QWidget *widget) { QLineEdit *lineEdit = new QLineEdit(widget); - lineEdit->setText(value); + lineEdit->setText(QString::fromStdString(config->value<std::string>(path.c_str()).value())); QToolButton *resetButton = new QToolButton(widget); resetButton->setIcon(widget->style()->standardIcon(QStyle::SP_DialogResetButton)); + QObject::connect(resetButton, &QToolButton::clicked, [config, path, lineEdit]() { + config->resetValue(path.c_str()); + lineEdit->setText(QString::fromStdString(config->value<std::string>(path.c_str()).value())); + }); + QObject::connect(lineEdit, &QLineEdit::editingFinished, [config, path, lineEdit]() { + config->setValue<std::string>(path, lineEdit->text().toStdString()); + }); + QHBoxLayout *hBox = new QHBoxLayout(); hBox->addWidget(lineEdit); hBox->addWidget(resetButton); |