diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-03-05 15:35:32 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-03-05 15:35:32 +0100 |
commit | 40de7d18bb5e91c049947344b8c632c40989ad10 (patch) | |
tree | 33c0a3a6500ea0c2d7b62f192f685bb93d7b99e0 /lib/settings | |
parent | Fixed pkgbuild again (diff) | |
download | smolbote-40de7d18bb5e91c049947344b8c632c40989ad10.tar.xz |
Added poi-config
- view default configuration
Diffstat (limited to 'lib/settings')
-rw-r--r-- | lib/settings/settingsdialog.cpp | 83 | ||||
-rw-r--r-- | lib/settings/settingsdialog.h | 35 | ||||
-rw-r--r-- | lib/settings/settingsdialog.ui | 67 |
3 files changed, 0 insertions, 185 deletions
diff --git a/lib/settings/settingsdialog.cpp b/lib/settings/settingsdialog.cpp deleted file mode 100644 index bd0aa49..0000000 --- a/lib/settings/settingsdialog.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/smolbote.hg - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "settingsdialog.h" -#include "../../src/configuration.h" -#include "ui_settingsdialog.h" -#include <QFormLayout> -#include <QGroupBox> -#include <QLineEdit> -#include <QScrollArea> -#include <QToolButton> - -inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget); - -SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent) - : QDialog(parent) - , ui(new Ui::SettingsDialog) -{ - ui->setupUi(this); - - for(const std::string &group : settings->childrenGroups("")) { - QScrollArea *area = new QScrollArea(this); - area->setWidgetResizable(true); - area->setWidget(widgetForGroup(settings, group, this)); - ui->tabWidget->addTab(area, QString::fromStdString(group)); - } -} - -SettingsDialog::~SettingsDialog() -{ - delete ui; -} - -QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::string &group, QWidget *parent) -{ - QWidget *widget = new QWidget(parent); - QVBoxLayout *layout = new QVBoxLayout(); - widget->setLayout(layout); - - // add entry for every key - QFormLayout *form = new QFormLayout(); - for(const std::string &key : settings->childrenSettings(group.c_str())) { - QHBoxLayout *hBox = createEntry(settings.get(), group + '.' + key, widget); - form->addRow(parent->tr(key.c_str()), hBox); - } - layout->addLayout(form); - - // TODO: iterate through groups - for(const std::string &childGroup : settings->childrenGroups(group.c_str())) { - QGroupBox *groupBox = new QGroupBox(QString::fromStdString(childGroup), widget); - layout->addWidget(groupBox); - QFormLayout *boxForm = new QFormLayout(groupBox); - groupBox->setLayout(boxForm); - - const std::string groupPath = group + '.' + childGroup; - for(const std::string &key : settings->childrenSettings(groupPath.c_str())) { - QHBoxLayout *hBox = createEntry(settings.get(), groupPath + '.' + key, groupBox); - boxForm->addRow(parent->tr(key.c_str()), hBox); - } - } - - return widget; -} - -inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget) -{ - QLineEdit *lineEdit = new QLineEdit(widget); - lineEdit->setText(QString::fromStdString(config->value<std::string>(path.c_str()).value())); - - QObject::connect(lineEdit, &QLineEdit::editingFinished, widget, [config, path, lineEdit]() { - config->setValue<std::string>(path, lineEdit->text().toStdString()); - }); - - QHBoxLayout *hBox = new QHBoxLayout(); - hBox->addWidget(lineEdit); - - return hBox; -} diff --git a/lib/settings/settingsdialog.h b/lib/settings/settingsdialog.h deleted file mode 100644 index 3d822d4..0000000 --- a/lib/settings/settingsdialog.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of smolbote. It's copyrighted by the contributors recorded - * in the version control history of the file, available from its original - * location: https://neueland.iserlohn-fortress.net/smolbote.hg - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#ifndef SETTINGSDIALOG_H -#define SETTINGSDIALOG_H - -#include <QDialog> -#include <memory> - -namespace Ui -{ -class SettingsDialog; -} - -class Configuration; -class SettingsDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent = nullptr); - ~SettingsDialog(); - -private: - Ui::SettingsDialog *ui; -}; - -[[nodiscard]] QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::string &group, QWidget *parent); - -#endif // SETTINGSDIALOG_H diff --git a/lib/settings/settingsdialog.ui b/lib/settings/settingsdialog.ui deleted file mode 100644 index 522754d..0000000 --- a/lib/settings/settingsdialog.ui +++ /dev/null @@ -1,67 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SettingsDialog</class> - <widget class="QDialog" name="SettingsDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>640</width> - <height>480</height> - </rect> - </property> - <property name="windowTitle"> - <string>Settings</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QTabWidget" name="tabWidget"/> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>SettingsDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>SettingsDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> |