(Qt) Cleanups

This commit is contained in:
twinaphex 2020-05-11 17:07:37 +02:00
parent 81a623c2b6
commit dd721def41
4 changed files with 62 additions and 58 deletions

View File

@ -824,6 +824,20 @@ int setting_generic_action_ok_default(rarch_setting_t *setting, bool wraparound)
return 0; return 0;
} }
void setting_generic_handle_change(rarch_setting_t *setting)
{
settings_t *settings = config_get_ptr();
settings->modified = true;
if (setting->change_handler)
setting->change_handler(setting);
if (setting->cmd_trigger.idx && !setting->cmd_trigger.triggered)
command_event(setting->cmd_trigger.idx, NULL);
}
static void setting_get_string_representation_int_gpu_index(rarch_setting_t *setting, static void setting_get_string_representation_int_gpu_index(rarch_setting_t *setting,
char *s, size_t len) char *s, size_t len)
{ {

View File

@ -127,6 +127,8 @@ int menu_action_handle_setting(rarch_setting_t *setting,
enum setting_type menu_setting_get_browser_selection_type( enum setting_type menu_setting_get_browser_selection_type(
rarch_setting_t *setting); rarch_setting_t *setting);
void setting_generic_handle_change(rarch_setting_t *setting);
void general_write_handler(rarch_setting_t *setting); void general_write_handler(rarch_setting_t *setting);
void general_read_handler(rarch_setting_t *setting); void general_read_handler(rarch_setting_t *setting);

View File

@ -263,7 +263,7 @@ void PlaylistModel::onImageLoaded(const QImage image, const QModelIndex &index,
m_pendingImages.remove(path); m_pendingImages.remove(path);
} }
inline static bool comp_hash_name_key_lower(const QHash<QString, QString> &lhs, const QHash<QString, QString> &rhs) static inline bool comp_hash_name_key_lower(const QHash<QString, QString> &lhs, const QHash<QString, QString> &rhs)
{ {
return lhs.value("name").toLower() < rhs.value("name").toLower(); return lhs.value("name").toLower() < rhs.value("name").toLower();
} }

View File

@ -23,20 +23,8 @@ extern "C" {
static const QRegularExpression decimalsRegex("%.(\\d)f"); static const QRegularExpression decimalsRegex("%.(\\d)f");
inline void handleChange(rarch_setting_t *setting) static inline void add_sublabel_and_whats_this(
{ QWidget *widget, rarch_setting_t *setting)
settings_t *settings = config_get_ptr();
settings->modified = true;
if (setting->change_handler)
setting->change_handler(setting);
if (setting->cmd_trigger.idx && !setting->cmd_trigger.triggered)
command_event(setting->cmd_trigger.idx, NULL);
}
inline void addSublabelAndWhatsThis(QWidget *widget, rarch_setting_t *setting)
{ {
struct menu_file_list_cbs cbs = {}; struct menu_file_list_cbs cbs = {};
char tmp[512]; char tmp[512];
@ -56,14 +44,14 @@ inline void addSublabelAndWhatsThis(QWidget *widget, rarch_setting_t *setting)
widget->setWhatsThis(tmp); widget->setWhatsThis(tmp);
} }
static QString sanitizeAmpersand(QString input) static QString sanitize_ampersand(QString input)
{ {
return input.replace("&", "&&"); return input.replace("&", "&&");
} }
inline QString formLabel(rarch_setting_t *setting) static inline QString form_label(rarch_setting_t *setting)
{ {
return QString(sanitizeAmpersand(setting->short_description)) + ":"; return QString(sanitize_ampersand(setting->short_description)) + ":";
} }
FormLayout::FormLayout(QWidget *parent) : FormLayout::FormLayout(QWidget *parent) :
@ -86,61 +74,61 @@ void FormLayout::addUIntRadioButtons(rarch_setting_t *setting)
void FormLayout::addUIntComboBox(rarch_setting_t *setting) void FormLayout::addUIntComboBox(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new UIntComboBox(setting)); addRow(form_label(setting), new UIntComboBox(setting));
} }
void FormLayout::addStringComboBox(rarch_setting_t *setting) void FormLayout::addStringComboBox(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new StringComboBox(setting)); addRow(form_label(setting), new StringComboBox(setting));
} }
void FormLayout::addStringLineEdit(rarch_setting_t *setting) void FormLayout::addStringLineEdit(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new StringLineEdit(setting)); addRow(form_label(setting), new StringLineEdit(setting));
} }
void FormLayout::addPasswordLineEdit(rarch_setting_t *setting) void FormLayout::addPasswordLineEdit(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new PasswordLineEdit(setting)); addRow(form_label(setting), new PasswordLineEdit(setting));
} }
void FormLayout::addUIntSpinBox(rarch_setting_t *setting) void FormLayout::addUIntSpinBox(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new UIntSpinBox(setting)); addRow(form_label(setting), new UIntSpinBox(setting));
} }
void FormLayout::addSizeSpinBox(rarch_setting_t *setting, unsigned scale) void FormLayout::addSizeSpinBox(rarch_setting_t *setting, unsigned scale)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new SizeSpinBox(setting, scale)); addRow(form_label(setting), new SizeSpinBox(setting, scale));
} }
void FormLayout::addFloatSpinBox(rarch_setting_t *setting) void FormLayout::addFloatSpinBox(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new FloatSpinBox(setting)); addRow(form_label(setting), new FloatSpinBox(setting));
} }
void FormLayout::addDirectorySelector(rarch_setting_t *setting) void FormLayout::addDirectorySelector(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new DirectorySelector(setting)); addRow(form_label(setting), new DirectorySelector(setting));
} }
void FormLayout::addFileSelector(rarch_setting_t *setting) void FormLayout::addFileSelector(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new FileSelector(setting)); addRow(form_label(setting), new FileSelector(setting));
} }
void FormLayout::addFloatSliderAndSpinBox(rarch_setting_t *setting) void FormLayout::addFloatSliderAndSpinBox(rarch_setting_t *setting)
{ {
if (setting && setting->short_description) if (setting && setting->short_description)
addRow(formLabel(setting), new FloatSliderAndSpinBox(setting)); addRow(form_label(setting), new FloatSliderAndSpinBox(setting));
} }
void FormLayout::addUIntColorButton(const QString &title, msg_hash_enums r, msg_hash_enums g, msg_hash_enums b) void FormLayout::addUIntColorButton(const QString &title, msg_hash_enums r, msg_hash_enums g, msg_hash_enums b)
@ -266,7 +254,7 @@ void SettingsGroup::addBindButton(rarch_setting_t *setting)
} }
CheckBox::CheckBox(rarch_setting_t *setting, QWidget *parent) : CheckBox::CheckBox(rarch_setting_t *setting, QWidget *parent) :
QCheckBox(sanitizeAmpersand(setting->short_description), parent) QCheckBox(sanitize_ampersand(setting->short_description), parent)
,m_setting(setting) ,m_setting(setting)
,m_value(setting->value.target.boolean) ,m_value(setting->value.target.boolean)
{ {
@ -276,7 +264,7 @@ CheckBox::CheckBox(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(toggled(bool)), this, SLOT(onClicked(bool))); connect(this, SIGNAL(toggled(bool)), this, SLOT(onClicked(bool)));
connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
CheckBox::CheckBox(const char *setting, QWidget *parent) : CheckBox::CheckBox(const char *setting, QWidget *parent) :
@ -293,7 +281,7 @@ void CheckBox::onClicked(bool checked)
{ {
*m_value = checked; *m_value = checked;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void CheckBox::paintEvent(QPaintEvent *event) void CheckBox::paintEvent(QPaintEvent *event)
@ -325,7 +313,7 @@ CheckableSettingsGroup::CheckableSettingsGroup(rarch_setting_t *setting, QWidget
connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
} }
@ -343,7 +331,7 @@ void CheckableSettingsGroup::onClicked(bool checked)
{ {
*m_value = checked; *m_value = checked;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void CheckableSettingsGroup::paintEvent(QPaintEvent *event) void CheckableSettingsGroup::paintEvent(QPaintEvent *event)
@ -383,14 +371,14 @@ CheckableIcon::CheckableIcon(rarch_setting_t *setting, const QIcon &icon, QWidge
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool))); connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
void CheckableIcon::onToggled(bool checked) void CheckableIcon::onToggled(bool checked)
{ {
*m_value = QAbstractButton::isChecked(); *m_value = QAbstractButton::isChecked();
handleChange(m_setting); setting_generic_handle_change(m_setting);
QAbstractButton::setChecked(checked); QAbstractButton::setChecked(checked);
} }
@ -415,7 +403,7 @@ StringLineEdit::StringLineEdit(rarch_setting_t *setting, QWidget *parent) :
{ {
connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
StringLineEdit::StringLineEdit(const char *setting, QWidget *parent) : StringLineEdit::StringLineEdit(const char *setting, QWidget *parent) :
@ -427,7 +415,7 @@ void StringLineEdit::onEditingFinished()
{ {
strlcpy(m_value, text().toUtf8().data(), m_setting->size); strlcpy(m_value, text().toUtf8().data(), m_setting->size);
handleChange(m_setting); setting_generic_handle_change(m_setting);
setModified(false); setModified(false);
} }
@ -458,7 +446,7 @@ StringComboBox::StringComboBox(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(currentTextChanged(const QString&)), this, SLOT(onCurrentTextChanged(const QString&))); connect(this, SIGNAL(currentTextChanged(const QString&)), this, SLOT(onCurrentTextChanged(const QString&)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
StringComboBox::StringComboBox(const char *setting, QWidget *parent) : StringComboBox::StringComboBox(const char *setting, QWidget *parent) :
@ -470,7 +458,7 @@ void StringComboBox::onCurrentTextChanged(const QString &text)
{ {
strlcpy(m_value, text.toUtf8().data(), sizeof(m_value)); strlcpy(m_value, text.toUtf8().data(), sizeof(m_value));
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void StringComboBox::paintEvent(QPaintEvent *event) void StringComboBox::paintEvent(QPaintEvent *event)
@ -491,7 +479,7 @@ UIntComboBox::UIntComboBox(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
UIntComboBox::UIntComboBox(rarch_setting_t *setting, double min, double max, QWidget *parent) : UIntComboBox::UIntComboBox(rarch_setting_t *setting, double min, double max, QWidget *parent) :
@ -503,7 +491,7 @@ UIntComboBox::UIntComboBox(rarch_setting_t *setting, double min, double max, QWi
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int))); connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
void UIntComboBox::populate(double min, double max) void UIntComboBox::populate(double min, double max)
@ -562,7 +550,7 @@ void UIntComboBox::onCurrentIndexChanged(int index)
*m_value = currentData().toUInt(); *m_value = currentData().toUInt();
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void UIntComboBox::paintEvent(QPaintEvent *event) void UIntComboBox::paintEvent(QPaintEvent *event)
@ -583,7 +571,7 @@ UIntSpinBox::UIntSpinBox(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
UIntSpinBox::UIntSpinBox(msg_hash_enums enum_idx, QWidget *parent) : UIntSpinBox::UIntSpinBox(msg_hash_enums enum_idx, QWidget *parent) :
@ -594,7 +582,7 @@ UIntSpinBox::UIntSpinBox(msg_hash_enums enum_idx, QWidget *parent) :
void UIntSpinBox::onValueChanged(int value) void UIntSpinBox::onValueChanged(int value)
{ {
*m_value = value; *m_value = value;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void UIntSpinBox::paintEvent(QPaintEvent *event) void UIntSpinBox::paintEvent(QPaintEvent *event)
@ -626,7 +614,7 @@ SizeSpinBox::SizeSpinBox(rarch_setting_t *setting, unsigned scale, QWidget *pare
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
SizeSpinBox::SizeSpinBox(msg_hash_enums enum_idx, unsigned scale, QWidget *parent) : SizeSpinBox::SizeSpinBox(msg_hash_enums enum_idx, unsigned scale, QWidget *parent) :
@ -637,7 +625,7 @@ SizeSpinBox::SizeSpinBox(msg_hash_enums enum_idx, unsigned scale, QWidget *paren
void SizeSpinBox::onValueChanged(int value) void SizeSpinBox::onValueChanged(int value)
{ {
*m_value = value * m_scale; *m_value = value * m_scale;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void SizeSpinBox::paintEvent(QPaintEvent *event) void SizeSpinBox::paintEvent(QPaintEvent *event)
@ -689,7 +677,7 @@ UIntRadioButton::UIntRadioButton(const QString &text, rarch_setting_t *setting,
void UIntRadioButton::onClicked(bool) void UIntRadioButton::onClicked(bool)
{ {
*m_target = m_value; *m_target = m_value;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void UIntRadioButton::paintEvent(QPaintEvent *event) void UIntRadioButton::paintEvent(QPaintEvent *event)
@ -743,7 +731,7 @@ UIntRadioButtons::UIntRadioButtons(rarch_setting_t *setting, QWidget *parent) :
*setting->value.target.unsigned_integer = orig_value; *setting->value.target.unsigned_integer = orig_value;
} }
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onButtonClicked(int))); connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onButtonClicked(int)));
} }
@ -761,7 +749,7 @@ void UIntRadioButtons::onButtonClicked(int id)
{ {
*m_value = id; *m_value = id;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
IntSpinBox::IntSpinBox(rarch_setting_t *setting, QWidget *parent) : IntSpinBox::IntSpinBox(rarch_setting_t *setting, QWidget *parent) :
@ -776,13 +764,13 @@ IntSpinBox::IntSpinBox(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
void IntSpinBox::onValueChanged(int value) void IntSpinBox::onValueChanged(int value)
{ {
*m_value = value; *m_value = value;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void IntSpinBox::paintEvent(QPaintEvent *event) void IntSpinBox::paintEvent(QPaintEvent *event)
@ -826,14 +814,14 @@ FloatSpinBox::FloatSpinBox(rarch_setting_t *setting, QWidget *parent) :
setSingleStep(setting->step); setSingleStep(setting->step);
connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double))); connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
void FloatSpinBox::onValueChanged(double value) void FloatSpinBox::onValueChanged(double value)
{ {
*m_value = (float)value; *m_value = (float)value;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void FloatSpinBox::paintEvent(QPaintEvent *event) void FloatSpinBox::paintEvent(QPaintEvent *event)
@ -861,7 +849,7 @@ PathButton::PathButton(rarch_setting_t *setting, QWidget *parent) :
{ {
connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool))); connect(this, SIGNAL(clicked(bool)), this, SLOT(onClicked(bool)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
PathButton::PathButton(const char *setting, QWidget *parent) : PathButton::PathButton(const char *setting, QWidget *parent) :
@ -888,7 +876,7 @@ void DirectoryButton::onClicked(bool)
{ {
strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(dir).toUtf8().data(), m_setting->size); strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(dir).toUtf8().data(), m_setting->size);
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
emit changed(); emit changed();
@ -906,7 +894,7 @@ void FileButton::onClicked(bool)
{ {
strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(file).toUtf8().data(), m_setting->size); strlcpy(m_setting->value.target.string, QDir::toNativeSeparators(file).toUtf8().data(), m_setting->size);
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
emit changed(); emit changed();
@ -967,14 +955,14 @@ FloatSlider::FloatSlider(rarch_setting_t *setting, QWidget *parent) :
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
addSublabelAndWhatsThis(this, m_setting); add_sublabel_and_whats_this(this, m_setting);
} }
void FloatSlider::onValueChanged(int value) void FloatSlider::onValueChanged(int value)
{ {
*m_value = (float)value / m_precision; *m_value = (float)value / m_precision;
handleChange(m_setting); setting_generic_handle_change(m_setting);
} }
void FloatSlider::paintEvent(QPaintEvent *event) void FloatSlider::paintEvent(QPaintEvent *event)