Add separate setting type for subcategory

macos_ci_fix
elsid 1 year ago
parent fb6e429dad
commit e07d8f3066
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -116,7 +116,7 @@ opencs_units (view/prefs
opencs_units (model/prefs opencs_units (model/prefs
state setting intsetting doublesetting boolsetting enumsetting coloursetting shortcut state setting intsetting doublesetting boolsetting enumsetting coloursetting shortcut
shortcuteventhandler shortcutmanager shortcutsetting modifiersetting stringsetting shortcuteventhandler shortcutmanager shortcutsetting modifiersetting stringsetting subcategory
) )
opencs_units (model/prefs opencs_units (model/prefs

@ -24,7 +24,7 @@ CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tool
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
{ {
mWidget = new QCheckBox(getLabel(), parent); mWidget = new QCheckBox(getLabel(), parent);
mWidget->setCheckState(mDefault ? Qt::Checked : Qt::Unchecked); mWidget->setCheckState(mDefault ? Qt::Checked : Qt::Unchecked);
@ -37,7 +37,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent
connect(mWidget, &QCheckBox::stateChanged, this, &BoolSetting::valueChanged); connect(mWidget, &QCheckBox::stateChanged, this, &BoolSetting::valueChanged);
return std::make_pair(static_cast<QWidget*>(nullptr), mWidget); return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::BoolSetting::updateWidget() void CSMPrefs::BoolSetting::updateWidget()

@ -26,7 +26,7 @@ namespace CSMPrefs
BoolSetting& setTooltip(const std::string& tooltip); BoolSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -27,7 +27,7 @@ CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip(const std::string&
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::ColourSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::ColourSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(getLabel(), parent); QLabel* label = new QLabel(getLabel(), parent);
@ -42,7 +42,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::ColourSetting::makeWidgets(QWidget* pare
connect(mWidget, &CSVWidget::ColorEditor::pickingFinished, this, &ColourSetting::valueChanged); connect(mWidget, &CSVWidget::ColorEditor::pickingFinished, this, &ColourSetting::valueChanged);
return std::make_pair(label, mWidget); return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::ColourSetting::updateWidget() void CSMPrefs::ColourSetting::updateWidget()

@ -34,7 +34,7 @@ namespace CSMPrefs
ColourSetting& setTooltip(const std::string& tooltip); ColourSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -56,7 +56,7 @@ CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setTooltip(const std::string&
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(getLabel(), parent); QLabel* label = new QLabel(getLabel(), parent);
@ -74,7 +74,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::DoubleSetting::makeWidgets(QWidget* pare
connect(mWidget, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &DoubleSetting::valueChanged); connect(mWidget, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &DoubleSetting::valueChanged);
return std::make_pair(label, mWidget); return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::DoubleSetting::updateWidget() void CSMPrefs::DoubleSetting::updateWidget()

@ -35,7 +35,7 @@ namespace CSMPrefs
DoubleSetting& setTooltip(const std::string& tooltip); DoubleSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -76,7 +76,7 @@ CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValue(const std::string& value,
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::EnumSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::EnumSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(getLabel(), parent); QLabel* label = new QLabel(getLabel(), parent);
@ -105,7 +105,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::EnumSetting::makeWidgets(QWidget* parent
connect(mWidget, qOverload<int>(&QComboBox::currentIndexChanged), this, &EnumSetting::valueChanged); connect(mWidget, qOverload<int>(&QComboBox::currentIndexChanged), this, &EnumSetting::valueChanged);
return std::make_pair(label, mWidget); return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::EnumSetting::updateWidget() void CSMPrefs::EnumSetting::updateWidget()

@ -56,7 +56,7 @@ namespace CSMPrefs
EnumSetting& addValue(const std::string& value, const std::string& tooltip); EnumSetting& addValue(const std::string& value, const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -49,7 +49,7 @@ CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip(const std::string& toolti
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(getLabel(), parent); QLabel* label = new QLabel(getLabel(), parent);
@ -66,7 +66,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
connect(mWidget, qOverload<int>(&QSpinBox::valueChanged), this, &IntSetting::valueChanged); connect(mWidget, qOverload<int>(&QSpinBox::valueChanged), this, &IntSetting::valueChanged);
return std::make_pair(label, mWidget); return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::IntSetting::updateWidget() void CSMPrefs::IntSetting::updateWidget()

@ -35,7 +35,7 @@ namespace CSMPrefs
IntSetting& setTooltip(const std::string& tooltip); IntSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -26,7 +26,7 @@ namespace CSMPrefs
{ {
} }
std::pair<QWidget*, QWidget*> ModifierSetting::makeWidgets(QWidget* parent) SettingWidgets ModifierSetting::makeWidgets(QWidget* parent)
{ {
int modifier = 0; int modifier = 0;
State::get().getShortcutManager().getModifier(getKey(), modifier); State::get().getShortcutManager().getModifier(getKey(), modifier);
@ -46,7 +46,7 @@ namespace CSMPrefs
connect(widget, &QPushButton::toggled, this, &ModifierSetting::buttonToggled); connect(widget, &QPushButton::toggled, this, &ModifierSetting::buttonToggled);
return std::make_pair(label, widget); return SettingWidgets{ .mLabel = label, .mInput = widget, .mLayout = nullptr };
} }
void ModifierSetting::updateWidget() void ModifierSetting::updateWidget()

@ -22,7 +22,7 @@ namespace CSMPrefs
public: public:
ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label); ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label);
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -23,13 +23,6 @@ CSMPrefs::Setting::Setting(Category* parent, QMutex* mutex, const std::string& k
{ {
} }
std::pair<QWidget*, QWidget*> CSMPrefs::Setting::makeWidgets(QWidget* parent)
{
return std::pair<QWidget*, QWidget*>(0, 0);
}
void CSMPrefs::Setting::updateWidget() {}
const CSMPrefs::Category* CSMPrefs::Setting::getParent() const const CSMPrefs::Category* CSMPrefs::Setting::getParent() const
{ {
return mParent; return mParent;

@ -9,11 +9,20 @@
class QWidget; class QWidget;
class QColor; class QColor;
class QMutex; class QMutex;
class QGridLayout;
class QLabel;
namespace CSMPrefs namespace CSMPrefs
{ {
class Category; class Category;
struct SettingWidgets
{
QLabel* mLabel;
QWidget* mInput;
QGridLayout* mLayout;
};
class Setting : public QObject class Setting : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -31,16 +40,12 @@ namespace CSMPrefs
~Setting() override = default; ~Setting() override = default;
/// Return label, input widget. virtual SettingWidgets makeWidgets(QWidget* parent) = 0;
///
/// \note first can be a 0-pointer, which means that the label is part of the input
/// widget.
virtual std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent);
/// Updates the widget returned by makeWidgets() to the current setting. /// Updates the widget returned by makeWidgets() to the current setting.
/// ///
/// \note If make_widgets() has not been called yet then nothing happens. /// \note If make_widgets() has not been called yet then nothing happens.
virtual void updateWidget(); virtual void updateWidget() = 0;
const Category* getParent() const; const Category* getParent() const;

@ -30,7 +30,7 @@ namespace CSMPrefs
} }
} }
std::pair<QWidget*, QWidget*> ShortcutSetting::makeWidgets(QWidget* parent) SettingWidgets ShortcutSetting::makeWidgets(QWidget* parent)
{ {
QKeySequence sequence; QKeySequence sequence;
State::get().getShortcutManager().getSequence(getKey(), sequence); State::get().getShortcutManager().getSequence(getKey(), sequence);
@ -50,7 +50,7 @@ namespace CSMPrefs
connect(widget, &QPushButton::toggled, this, &ShortcutSetting::buttonToggled); connect(widget, &QPushButton::toggled, this, &ShortcutSetting::buttonToggled);
return std::make_pair(label, widget); return SettingWidgets{ .mLabel = label, .mInput = widget, .mLayout = nullptr };
} }
void ShortcutSetting::updateWidget() void ShortcutSetting::updateWidget()

@ -24,7 +24,7 @@ namespace CSMPrefs
public: public:
ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label); ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label);
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -13,6 +13,7 @@
#include <apps/opencs/model/prefs/enumsetting.hpp> #include <apps/opencs/model/prefs/enumsetting.hpp>
#include <apps/opencs/model/prefs/setting.hpp> #include <apps/opencs/model/prefs/setting.hpp>
#include <apps/opencs/model/prefs/shortcutmanager.hpp> #include <apps/opencs/model/prefs/shortcutmanager.hpp>
#include <apps/opencs/model/prefs/subcategory.hpp>
#include <components/settings/categories.hpp> #include <components/settings/categories.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
@ -609,9 +610,7 @@ void CSMPrefs::State::declareSubcategory(const QString& label)
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
CSMPrefs::Setting* setting = new CSMPrefs::Setting(&mCurrentCategory->second, &mMutex, "", label); mCurrentCategory->second.addSetting(new CSMPrefs::Subcategory(&mCurrentCategory->second, &mMutex, label));
mCurrentCategory->second.addSetting(setting);
} }
void CSMPrefs::State::setDefault(const std::string& key, const std::string& default_) void CSMPrefs::State::setDefault(const std::string& key, const std::string& default_)

@ -25,7 +25,7 @@ CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip(const std::string&
return *this; return *this;
} }
std::pair<QWidget*, QWidget*> CSMPrefs::StringSetting::makeWidgets(QWidget* parent) CSMPrefs::SettingWidgets CSMPrefs::StringSetting::makeWidgets(QWidget* parent)
{ {
mWidget = new QLineEdit(QString::fromUtf8(mDefault.c_str()), parent); mWidget = new QLineEdit(QString::fromUtf8(mDefault.c_str()), parent);
@ -37,7 +37,7 @@ std::pair<QWidget*, QWidget*> CSMPrefs::StringSetting::makeWidgets(QWidget* pare
connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged); connect(mWidget, &QLineEdit::textChanged, this, &StringSetting::textChanged);
return std::make_pair(static_cast<QWidget*>(nullptr), mWidget); return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget, .mLayout = nullptr };
} }
void CSMPrefs::StringSetting::updateWidget() void CSMPrefs::StringSetting::updateWidget()

@ -29,7 +29,7 @@ namespace CSMPrefs
StringSetting& setTooltip(const std::string& tooltip); StringSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget. /// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override; void updateWidget() override;

@ -0,0 +1,21 @@
#include "subcategory.hpp"
#include <QGridLayout>
namespace CSMPrefs
{
class Category;
Subcategory::Subcategory(Category* parent, QMutex* mutex, const QString& label)
: Setting(parent, mutex, "", label)
{
}
SettingWidgets Subcategory::makeWidgets(QWidget* /*parent*/)
{
QGridLayout* const layout = new QGridLayout();
layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
return SettingWidgets{ .mLabel = nullptr, .mInput = nullptr, .mLayout = layout };
}
}

@ -0,0 +1,26 @@
#ifndef OPENMW_APPS_OPENCS_MODEL_PREFS_SUBCATEGORY_H
#define OPENMW_APPS_OPENCS_MODEL_PREFS_SUBCATEGORY_H
#include "setting.hpp"
#include <string>
#include <utility>
namespace CSMPrefs
{
class Category;
class Subcategory final : public Setting
{
Q_OBJECT
public:
explicit Subcategory(Category* parent, QMutex* mutex, const QString& label);
SettingWidgets makeWidgets(QWidget* parent) override;
void updateWidget() override {}
};
}
#endif

@ -7,6 +7,7 @@
#include <QComboBox> #include <QComboBox>
#include <QGridLayout> #include <QGridLayout>
#include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QStackedLayout> #include <QStackedLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -61,31 +62,31 @@ namespace CSVPrefs
void KeyBindingPage::addSetting(CSMPrefs::Setting* setting) void KeyBindingPage::addSetting(CSMPrefs::Setting* setting)
{ {
std::pair<QWidget*, QWidget*> widgets = setting->makeWidgets(this); const CSMPrefs::SettingWidgets widgets = setting->makeWidgets(this);
if (widgets.first) if (widgets.mLabel != nullptr && widgets.mInput != nullptr)
{ {
// Label, Option widgets // Label, Option widgets
assert(mPageLayout); assert(mPageLayout);
int next = mPageLayout->rowCount(); int next = mPageLayout->rowCount();
mPageLayout->addWidget(widgets.first, next, 0); mPageLayout->addWidget(widgets.mLabel, next, 0);
mPageLayout->addWidget(widgets.second, next, 1); mPageLayout->addWidget(widgets.mInput, next, 1);
} }
else if (widgets.second) else if (widgets.mInput != nullptr)
{ {
// Wide single widget // Wide single widget
assert(mPageLayout); assert(mPageLayout);
int next = mPageLayout->rowCount(); int next = mPageLayout->rowCount();
mPageLayout->addWidget(widgets.second, next, 0, 1, 2); mPageLayout->addWidget(widgets.mInput, next, 0, 1, 2);
} }
else if (!setting->getLabel().isEmpty()) else if (widgets.mLayout != nullptr)
{ {
// Create new page // Create new page
QWidget* pageWidget = new QWidget(); QWidget* pageWidget = new QWidget();
mPageLayout = new QGridLayout(pageWidget); mPageLayout = widgets.mLayout;
mPageLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); mPageLayout->setParent(pageWidget);
mStackedLayout->addWidget(pageWidget); mStackedLayout->addWidget(pageWidget);

@ -6,6 +6,7 @@
#include <apps/opencs/view/prefs/pagebase.hpp> #include <apps/opencs/view/prefs/pagebase.hpp>
#include <QGridLayout> #include <QGridLayout>
#include <QLabel>
#include "../../model/prefs/category.hpp" #include "../../model/prefs/category.hpp"
#include "../../model/prefs/setting.hpp" #include "../../model/prefs/setting.hpp"
@ -24,17 +25,17 @@ CSVPrefs::Page::Page(CSMPrefs::Category& category, QWidget* parent)
void CSVPrefs::Page::addSetting(CSMPrefs::Setting* setting) void CSVPrefs::Page::addSetting(CSMPrefs::Setting* setting)
{ {
std::pair<QWidget*, QWidget*> widgets = setting->makeWidgets(this); const CSMPrefs::SettingWidgets widgets = setting->makeWidgets(this);
int next = mGrid->rowCount(); int next = mGrid->rowCount();
if (widgets.first) if (widgets.mLabel != nullptr && widgets.mInput != nullptr)
{ {
mGrid->addWidget(widgets.first, next, 0); mGrid->addWidget(widgets.mLabel, next, 0);
mGrid->addWidget(widgets.second, next, 1); mGrid->addWidget(widgets.mInput, next, 1);
} }
else if (widgets.second) else if (widgets.mInput != nullptr)
{ {
mGrid->addWidget(widgets.second, next, 0, 1, 2); mGrid->addWidget(widgets.mInput, next, 0, 1, 2);
} }
} }

Loading…
Cancel
Save