From 5d52d73c4b2781fd99260534c17e35640ab17589 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:31:26 -0400 Subject: [PATCH] shared_widget: Use default literals more --- src/yuzu/configuration/shared_widget.cpp | 26 +++++++++++------------- src/yuzu/configuration/shared_widget.h | 17 +++++++++------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index e5e071386b..ea8d7add42 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -63,7 +63,7 @@ static QString DefaultSuffix(QWidget* parent, Settings::BasicSetting& setting) { return tr("%", context.c_str()); } - return QStringLiteral(""); + return default_suffix; } QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) { @@ -71,7 +71,7 @@ QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* paren QStyle* style = parent->style(); QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_LineEditClearButton)); - QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); + QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(), parent); restore_button->setObjectName(QStringLiteral("RestoreButton%1").arg(restore_button_count)); restore_button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -259,7 +259,7 @@ static void CreateIntSlider(Settings::BasicSetting& setting, bool reversed, floa QLabel* feedback, const QString& use_format, QSlider* slider, std::function& serializer, std::function& restore_func) { - int max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); + const int max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); const auto update_feedback = [=](int value) { int present = (reversed ? max_val - value : value) * multiplier + 0.5f; @@ -283,9 +283,10 @@ static void CreateFloatSlider(Settings::BasicSetting& setting, bool reversed, fl QLabel* feedback, const QString& use_format, QSlider* slider, std::function& serializer, std::function& restore_func) { - float max_val = std::strtof(setting.MaxVal().c_str(), nullptr); - float min_val = std::strtof(setting.MinVal().c_str(), nullptr); - float use_multiplier = multiplier == default_multiplier ? default_float_multiplier : multiplier; + const float max_val = std::strtof(setting.MaxVal().c_str(), nullptr); + const float min_val = std::strtof(setting.MinVal().c_str(), nullptr); + const float use_multiplier = + multiplier == default_multiplier ? default_float_multiplier : multiplier; const auto update_feedback = [=](float value) { int present = (reversed ? max_val - value : value) + 0.5f; @@ -330,8 +331,7 @@ QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& gi layout->setContentsMargins(0, 0, 0, 0); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; const QString use_format = QStringLiteral("%1").append(suffix); @@ -360,8 +360,7 @@ QWidget* Widget::CreateSpinBox(const QString& given_suffix, const auto max_val = std::strtol(setting.MaxVal().c_str(), nullptr, 0); const auto default_val = std::strtol(setting.ToString().c_str(), nullptr, 0); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; spinbox = new QSpinBox(this); spinbox->setRange(min_val, max_val); @@ -395,8 +394,7 @@ QWidget* Widget::CreateDoubleSpinBox(const QString& given_suffix, const auto max_val = std::strtod(setting.MaxVal().c_str(), nullptr); const auto default_val = std::strtod(setting.ToString().c_str(), nullptr); - QString suffix = - given_suffix == QStringLiteral("") ? DefaultSuffix(this, setting) : given_suffix; + QString suffix = given_suffix == default_suffix ? DefaultSuffix(this, setting) : given_suffix; double_spinbox = new QDoubleSpinBox(this); double_spinbox->setRange(min_val, max_val); @@ -733,10 +731,10 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati return std::pair{translations.at(id).first, translations.at(id).second}; } LOG_WARNING(Frontend, "Translation table lacks entry for \"{}\"", setting_label); - return std::pair{QString::fromStdString(setting_label), QStringLiteral("")}; + return std::pair{QString::fromStdString(setting_label), QStringLiteral()}; }(); - if (label == QStringLiteral("")) { + if (label == QStringLiteral()) { LOG_DEBUG(Frontend, "Translation table has empty entry for \"{}\", skipping...", setting.GetLabel()); return; diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 86edaacc88..226284cf36 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -44,8 +44,9 @@ enum class RequestType { MaxEnum, }; -constexpr const float default_multiplier{1.f}; -constexpr const float default_float_multiplier{100.f}; +constexpr float default_multiplier{1.f}; +constexpr float default_float_multiplier{100.f}; +static const QString default_suffix = QStringLiteral(); class Widget : public QWidget { Q_OBJECT @@ -70,8 +71,9 @@ public: const ComboboxTranslationMap& combobox_translations, QWidget* parent, bool runtime_lock, std::vector>& apply_funcs_, RequestType request = RequestType::Default, bool managed = true, - float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, - const QString& suffix = QStringLiteral("")); + float multiplier = default_multiplier, + Settings::BasicSetting* other_setting = nullptr, + const QString& suffix = default_suffix); virtual ~Widget(); /** @@ -153,14 +155,15 @@ public: Widget* BuildWidget(Settings::BasicSetting* setting, std::vector>& apply_funcs, RequestType request = RequestType::Default, bool managed = true, - float multiplier = 1.0f, Settings::BasicSetting* other_setting = nullptr, - const QString& suffix = QStringLiteral("")) const; + float multiplier = default_multiplier, + Settings::BasicSetting* other_setting = nullptr, + const QString& suffix = default_suffix) const; Widget* BuildWidget(Settings::BasicSetting* setting, std::vector>& apply_funcs, Settings::BasicSetting* other_setting, RequestType request = RequestType::Default, - const QString& suffix = QStringLiteral("")) const; + const QString& suffix = default_suffix) const; const ComboboxTranslationMap& ComboboxTranslations() const;