dolphin/Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp
Martino Fontana a14c88ba67 Remove unused imports
Yellow squiggly lines begone!
Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes.
If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed.
The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports.
Not everything is removed, but the cleanup should be substantial enough.
Because this done on Linux, code that isn't used on it is mostly untouched.
(Hopefully no open PR is depending on these imports...)
2026-01-25 16:12:15 +01:00

112 lines
2.9 KiB
C++

// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
#include <limits>
#include "DolphinQt/Config/Mapping/MappingWidget.h"
MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
: QDoubleSpinBox(parent), m_setting(*setting)
{
setDecimals(2);
if (const auto ui_description = m_setting.GetUIDescription())
setToolTip(tr(ui_description));
connect(this, &QDoubleSpinBox::valueChanged, this, [this, parent](double value) {
m_setting.SetValue(value);
ConfigChanged();
parent->SaveSettings();
});
connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
connect(parent, &MappingWidget::Update, this, &MappingDouble::Update);
}
// Overriding QDoubleSpinBox's fixup to set the default value when input is cleared.
void MappingDouble::fixup(QString& input) const
{
input = QString::number(m_setting.GetDefaultValue());
}
void MappingDouble::ConfigChanged()
{
const QSignalBlocker blocker(this);
QString suffix;
if (const auto ui_suffix = m_setting.GetUISuffix())
suffix += QLatin1Char{' '} + tr(ui_suffix);
if (m_setting.IsSimpleValue())
{
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
setButtonSymbols(ButtonSymbols::UpDownArrows);
}
else
{
constexpr auto inf = std::numeric_limits<double>::infinity();
setRange(-inf, inf);
setButtonSymbols(ButtonSymbols::NoButtons);
suffix += QString::fromUtf8(" 🎮");
}
setSuffix(suffix);
setValue(m_setting.GetValue());
}
void MappingDouble::Update()
{
if (m_setting.IsSimpleValue() || hasFocus())
return;
const QSignalBlocker blocker(this);
setValue(m_setting.GetValue());
}
MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bool>* setting)
: QCheckBox(parent), m_setting(*setting)
{
if (const auto ui_description = m_setting.GetUIDescription())
setToolTip(tr(ui_description));
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(this, &QCheckBox::checkStateChanged, this, [this, parent](Qt::CheckState value) {
#else
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
#endif
m_setting.SetValue(value != 0);
ConfigChanged();
parent->SaveSettings();
});
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
connect(parent, &MappingWidget::Update, this, &MappingBool::Update);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
}
void MappingBool::ConfigChanged()
{
const QSignalBlocker blocker(this);
if (m_setting.IsSimpleValue())
setText({});
else
setText(QString::fromUtf8("🎮"));
setChecked(m_setting.GetValue());
}
void MappingBool::Update()
{
if (m_setting.IsSimpleValue())
return;
const QSignalBlocker blocker(this);
setChecked(m_setting.GetValue());
}