Skip to content
Permalink
Browse files
Merge pull request #6175 from ligfx/qtinputupdateclear
Qt Mapping*: make logic around setting/loading settings more consistent
  • Loading branch information
leoetlino committed Nov 11, 2017
2 parents e5d1e2a + 14f22ad commit 41c2618
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
@@ -10,26 +10,26 @@
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();
}

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();
}
@@ -83,17 +83,15 @@ void MappingButton::OnButtonTimeout()

void MappingButton::Clear()
{
m_parent->Update();
m_reference->SetExpression("");
Update();
m_parent->SaveSettings();
}

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)
@@ -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();
}
@@ -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

0 comments on commit 41c2618

Please sign in to comment.