Qt: Support QActions in SettingsWidgetBinder

This commit is contained in:
Stenzek 2020-02-04 15:22:39 +09:00
parent 52fd070d3b
commit 6718f0442c

View file

@ -5,6 +5,7 @@
#include "core/settings.h"
#include "qthostinterface.h"
#include <QtWidgets/QAction>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QLineEdit>
@ -110,6 +111,28 @@ struct SettingAccessor<QSlider>
}
};
template<>
struct SettingAccessor<QAction>
{
static bool getBoolValue(const QAction* widget) { return widget->isChecked(); }
static void setBoolValue(QAction* widget, bool value) { widget->setChecked(value); }
static int getIntValue(const QAction* widget) { return widget->isChecked() ? 1 : 0; }
static void setIntValue(QAction* widget, int value) { widget->setChecked(value != 0); }
static QString getStringValue(const QAction* widget)
{
return widget->isChecked() ? QStringLiteral("1") : QStringLiteral("0");
}
static void setStringValue(QAction* widget, const QString& value) { widget->setChecked(value.toInt() != 0); }
template<typename F>
static void connectValueChanged(QAction* widget, F func)
{
widget->connect(widget, &QAction::toggled, func);
}
};
/// Binds a widget's value to a setting, updating it when the value changes.
template<typename WidgetType>