mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-11 08:39:13 +01:00
fef1b84f0a
QStringLiterals generate a buffer so that during runtime there's very little cost to constructing a QString. However, this also means that duplicated strings cannot be optimized out into a single entry that gets referenced everywhere, taking up space in the binary. Rather than use QStringLiteral(""), we can just use QString{} (the default constructor) to signify the empty string. This gets rid of an unnecessary string buffer from being created, saving a tiny bit of space. While we're at it, we can just use the character overloads of particular functions when they're available instead of using a QString overload. The characters in this case are Latin-1 to begin with, so we can just specify the characters as QLatin1Char instances to use those overloads. These will automatically convert to QChar if needed, so this is safe.
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
// Copyright 2017 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingNumeric.h"
|
|
|
|
#include "DolphinQt/Config/Mapping/MappingWidget.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
|
|
MappingDouble::MappingDouble(MappingWidget* parent, ControllerEmu::NumericSetting<double>* setting)
|
|
: QDoubleSpinBox(parent), m_setting(*setting)
|
|
{
|
|
setRange(m_setting.GetMinValue(), m_setting.GetMaxValue());
|
|
setDecimals(2);
|
|
|
|
if (const auto ui_suffix = m_setting.GetUISuffix())
|
|
setSuffix(QLatin1Char{' '} + tr(ui_suffix));
|
|
|
|
if (const auto ui_description = m_setting.GetUIDescription())
|
|
setToolTip(tr(ui_description));
|
|
|
|
connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
|
|
[this, parent](double value) {
|
|
m_setting.SetValue(value);
|
|
parent->SaveSettings();
|
|
});
|
|
|
|
connect(parent, &MappingWidget::ConfigChanged, this, &MappingDouble::ConfigChanged);
|
|
}
|
|
|
|
// 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);
|
|
setValue(m_setting.GetValue());
|
|
}
|
|
|
|
MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bool>* setting)
|
|
: QCheckBox(parent), m_setting(*setting)
|
|
{
|
|
connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
|
|
m_setting.SetValue(value != 0);
|
|
parent->SaveSettings();
|
|
});
|
|
|
|
connect(parent, &MappingWidget::ConfigChanged, this, &MappingBool::ConfigChanged);
|
|
}
|
|
|
|
void MappingBool::ConfigChanged()
|
|
{
|
|
const QSignalBlocker blocker(this);
|
|
setChecked(m_setting.GetValue());
|
|
}
|