Merge pull request #6175 from ligfx/qtinputupdateclear

Qt Mapping*: make logic around setting/loading settings more consistent
This commit is contained in:
Leo Lam 2017-11-11 12:11:26 +01:00 committed by GitHub
commit 41c2618b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 15 deletions

View File

@ -10,7 +10,7 @@
MappingBool::MappingBool(MappingWidget* widget, ControllerEmu::BooleanSetting* setting)
: QCheckBox(QString::fromStdString(setting->m_ui_name)), m_parent(widget), m_setting(setting)
{
setChecked(setting->GetValue());
Update();
Connect();
}
@ -18,18 +18,18 @@ void MappingBool::Connect()
{
connect(this, &QCheckBox::stateChanged, this, [this](int value) {
m_setting->SetValue(value);
Update();
m_parent->SaveSettings();
});
}
void MappingBool::Clear()
{
setChecked(false);
m_setting->SetValue(false);
m_parent->SaveSettings();
Update();
}
void MappingBool::Update()
{
setChecked(m_setting->GetValue());
m_parent->SaveSettings();
}

View File

@ -83,9 +83,8 @@ void MappingButton::OnButtonTimeout()
void MappingButton::Clear()
{
m_parent->Update();
m_reference->SetExpression("");
Update();
m_parent->SaveSettings();
}
void MappingButton::Update()
@ -93,7 +92,6 @@ void MappingButton::Update()
const auto lock = ControllerEmu::EmulatedController::GetStateLock();
m_reference->UpdateReference(g_controller_interface, m_parent->GetParent()->GetDeviceQualifier());
setText(EscapeAmpersand(QString::fromStdString(m_reference->GetExpression())));
m_parent->SaveSettings();
}
void MappingButton::mouseReleaseEvent(QMouseEvent* event)

View File

@ -11,7 +11,7 @@ MappingNumeric::MappingNumeric(MappingWidget* widget, ControllerEmu::NumericSett
: m_parent(widget), m_setting(setting), m_range(setting->m_high - setting->m_low)
{
setRange(setting->m_low, setting->m_high);
setValue(setting->m_low + setting->GetValue() * m_range);
Update();
Connect();
}
@ -20,18 +20,18 @@ void MappingNumeric::Connect()
connect(this, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
[this](int value) {
m_setting->SetValue(static_cast<double>(value - m_setting->m_low) / m_range);
Update();
m_parent->SaveSettings();
});
}
void MappingNumeric::Clear()
{
setValue(m_setting->m_low + (m_setting->m_low + m_setting->m_high) / 2);
m_setting->SetValue(m_setting->m_low + (m_setting->m_low + m_setting->m_high) / 2);
m_parent->SaveSettings();
Update();
}
void MappingNumeric::Update()
{
setValue(m_setting->m_low + m_setting->GetValue() * m_range);
m_parent->SaveSettings();
}

View File

@ -57,14 +57,15 @@ QGroupBox* MappingWidget::CreateGroupBox(const QString& name, ControllerEmu::Con
auto* control_ref = control->control_ref.get();
connect(button, &MappingButton::AdvancedPressed, [this, control_ref] {
connect(button, &MappingButton::AdvancedPressed, [this, button, control_ref] {
if (m_parent->GetDevice() == nullptr)
return;
IOWindow io(this, m_parent->GetController(), control_ref,
control_ref->IsInput() ? IOWindow::Type::Input : IOWindow::Type::Output);
io.exec();
Update();
SaveSettings();
button->Update();
});
m_buttons.push_back(button);
@ -111,8 +112,6 @@ void MappingWidget::Update()
for (auto* checkbox : m_bools)
checkbox->Update();
LoadSettings();
}
ControllerEmu::EmulatedController* MappingWidget::GetController() const