configuration_shared: Make CheckState strongly typed

Also gets rid of unnecessary explicit namespace usage.
This commit is contained in:
lat9nq 2020-07-14 15:40:02 -04:00
parent d26e1a1839
commit 7df8f2b760
2 changed files with 23 additions and 24 deletions

View file

@ -95,42 +95,42 @@ void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name,
void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name,
const Settings::Setting<bool>& setting,
ConfigurationShared::CheckState& tracker) {
CheckState& tracker) {
if (setting.UsingGlobal()) {
tracker = CheckState::Global;
} else {
tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
QObject::connect(
checkbox, &QCheckBox::clicked, checkbox, [checkbox, name, setting, &tracker]() {
tracker =
static_cast<ConfigurationShared::CheckState>((tracker + 1) % CheckState::Count);
if (tracker == CheckState::Global) {
checkbox->setChecked(setting.GetValue(true));
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
});
QObject::connect(checkbox, &QCheckBox::clicked, checkbox,
[checkbox, name, setting, &tracker]() {
tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
static_cast<int>(CheckState::Count));
if (tracker == CheckState::Global) {
checkbox->setChecked(setting.GetValue(true));
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
});
}
void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name,
bool global, bool state, bool global_state,
ConfigurationShared::CheckState& tracker) {
CheckState& tracker) {
if (global) {
tracker = CheckState::Global;
} else {
tracker = (state == global_state) ? CheckState::On : CheckState::Off;
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
QObject::connect(
checkbox, &QCheckBox::clicked, checkbox, [checkbox, name, global_state, &tracker]() {
tracker =
static_cast<ConfigurationShared::CheckState>((tracker + 1) % CheckState::Count);
if (tracker == CheckState::Global) {
checkbox->setChecked(global_state);
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
});
QObject::connect(checkbox, &QCheckBox::clicked, checkbox,
[checkbox, name, global_state, &tracker]() {
tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
static_cast<int>(CheckState::Count));
if (tracker == CheckState::Global) {
checkbox->setChecked(global_state);
}
SetHighlight(checkbox, name, tracker != CheckState::Global);
});
}
void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target,