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
state setting intsetting doublesetting boolsetting enumsetting coloursetting shortcut
shortcuteventhandler shortcutmanager shortcutsetting modifiersetting stringsetting
shortcuteventhandler shortcutmanager shortcutsetting modifiersetting stringsetting subcategory
)
opencs_units (model/prefs

@ -24,7 +24,7 @@ CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tool
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
CSMPrefs::SettingWidgets CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
{
mWidget = new QCheckBox(getLabel(), parent);
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);
return std::make_pair(static_cast<QWidget*>(nullptr), mWidget);
return SettingWidgets{ .mLabel = nullptr, .mInput = mWidget, .mLayout = nullptr };
}
void CSMPrefs::BoolSetting::updateWidget()

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

@ -27,7 +27,7 @@ CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip(const std::string&
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::ColourSetting::makeWidgets(QWidget* parent)
CSMPrefs::SettingWidgets CSMPrefs::ColourSetting::makeWidgets(QWidget* 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);
return std::make_pair(label, mWidget);
return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
}
void CSMPrefs::ColourSetting::updateWidget()

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

@ -56,7 +56,7 @@ CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setTooltip(const std::string&
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent)
CSMPrefs::SettingWidgets CSMPrefs::DoubleSetting::makeWidgets(QWidget* 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);
return std::make_pair(label, mWidget);
return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
}
void CSMPrefs::DoubleSetting::updateWidget()

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

@ -76,7 +76,7 @@ CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValue(const std::string& value,
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::EnumSetting::makeWidgets(QWidget* parent)
CSMPrefs::SettingWidgets CSMPrefs::EnumSetting::makeWidgets(QWidget* 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);
return std::make_pair(label, mWidget);
return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
}
void CSMPrefs::EnumSetting::updateWidget()

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

@ -49,7 +49,7 @@ CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip(const std::string& toolti
return *this;
}
std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
CSMPrefs::SettingWidgets CSMPrefs::IntSetting::makeWidgets(QWidget* 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);
return std::make_pair(label, mWidget);
return SettingWidgets{ .mLabel = label, .mInput = mWidget, .mLayout = nullptr };
}
void CSMPrefs::IntSetting::updateWidget()

@ -35,7 +35,7 @@ namespace CSMPrefs
IntSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
SettingWidgets makeWidgets(QWidget* parent) 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;
State::get().getShortcutManager().getModifier(getKey(), modifier);
@ -46,7 +46,7 @@ namespace CSMPrefs
connect(widget, &QPushButton::toggled, this, &ModifierSetting::buttonToggled);
return std::make_pair(label, widget);
return SettingWidgets{ .mLabel = label, .mInput = widget, .mLayout = nullptr };
}
void ModifierSetting::updateWidget()

@ -22,7 +22,7 @@ namespace CSMPrefs
public:
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;

@ -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
{
return mParent;

@ -9,11 +9,20 @@
class QWidget;
class QColor;
class QMutex;
class QGridLayout;
class QLabel;
namespace CSMPrefs
{
class Category;
struct SettingWidgets
{
QLabel* mLabel;
QWidget* mInput;
QGridLayout* mLayout;
};
class Setting : public QObject
{
Q_OBJECT
@ -31,16 +40,12 @@ namespace CSMPrefs
~Setting() override = default;
/// Return label, input widget.
///
/// \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);
virtual SettingWidgets makeWidgets(QWidget* parent) = 0;
/// Updates the widget returned by makeWidgets() to the current setting.
///
/// \note If make_widgets() has not been called yet then nothing happens.
virtual void updateWidget();
virtual void updateWidget() = 0;
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;
State::get().getShortcutManager().getSequence(getKey(), sequence);
@ -50,7 +50,7 @@ namespace CSMPrefs
connect(widget, &QPushButton::toggled, this, &ShortcutSetting::buttonToggled);
return std::make_pair(label, widget);
return SettingWidgets{ .mLabel = label, .mInput = widget, .mLayout = nullptr };
}
void ShortcutSetting::updateWidget()

@ -24,7 +24,7 @@ namespace CSMPrefs
public:
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;

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

@ -29,7 +29,7 @@ namespace CSMPrefs
StringSetting& setTooltip(const std::string& tooltip);
/// Return label, input widget.
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
SettingWidgets makeWidgets(QWidget* parent) 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 <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QStackedLayout>
#include <QVBoxLayout>
@ -61,31 +62,31 @@ namespace CSVPrefs
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
assert(mPageLayout);
int next = mPageLayout->rowCount();
mPageLayout->addWidget(widgets.first, next, 0);
mPageLayout->addWidget(widgets.second, next, 1);
mPageLayout->addWidget(widgets.mLabel, next, 0);
mPageLayout->addWidget(widgets.mInput, next, 1);
}
else if (widgets.second)
else if (widgets.mInput != nullptr)
{
// Wide single widget
assert(mPageLayout);
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
QWidget* pageWidget = new QWidget();
mPageLayout = new QGridLayout(pageWidget);
mPageLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
mPageLayout = widgets.mLayout;
mPageLayout->setParent(pageWidget);
mStackedLayout->addWidget(pageWidget);

@ -6,6 +6,7 @@
#include <apps/opencs/view/prefs/pagebase.hpp>
#include <QGridLayout>
#include <QLabel>
#include "../../model/prefs/category.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)
{
std::pair<QWidget*, QWidget*> widgets = setting->makeWidgets(this);
const CSMPrefs::SettingWidgets widgets = setting->makeWidgets(this);
int next = mGrid->rowCount();
if (widgets.first)
if (widgets.mLabel != nullptr && widgets.mInput != nullptr)
{
mGrid->addWidget(widgets.first, next, 0);
mGrid->addWidget(widgets.second, next, 1);
mGrid->addWidget(widgets.mLabel, next, 0);
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