1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-24 15:11:35 +00:00

Avoid std::string to QString conversion for label

This commit is contained in:
elsid 2023-11-10 13:09:37 +01:00
parent d6220b7d03
commit 335dbffe6e
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
21 changed files with 49 additions and 61 deletions

View file

@ -11,7 +11,7 @@
#include "state.hpp" #include "state.hpp"
CSMPrefs::BoolSetting::BoolSetting( CSMPrefs::BoolSetting::BoolSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, bool default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, bool default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mDefault(default_) , mDefault(default_)
, mWidget(nullptr) , mWidget(nullptr)
@ -26,7 +26,7 @@ CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip(const std::string& tool
std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent) std::pair<QWidget*, QWidget*> CSMPrefs::BoolSetting::makeWidgets(QWidget* parent)
{ {
mWidget = new QCheckBox(QString::fromUtf8(getLabel().c_str()), parent); mWidget = new QCheckBox(getLabel(), parent);
mWidget->setCheckState(mDefault ? Qt::Checked : Qt::Unchecked); mWidget->setCheckState(mDefault ? Qt::Checked : Qt::Unchecked);
if (!mTooltip.empty()) if (!mTooltip.empty())

View file

@ -21,7 +21,7 @@ namespace CSMPrefs
QCheckBox* mWidget; QCheckBox* mWidget;
public: public:
BoolSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label, bool default_); BoolSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label, bool default_);
BoolSetting& setTooltip(const std::string& tooltip); BoolSetting& setTooltip(const std::string& tooltip);

View file

@ -14,7 +14,7 @@
#include "state.hpp" #include "state.hpp"
CSMPrefs::ColourSetting::ColourSetting( CSMPrefs::ColourSetting::ColourSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, QColor default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, QColor default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mDefault(std::move(default_)) , mDefault(std::move(default_))
, mWidget(nullptr) , mWidget(nullptr)
@ -29,7 +29,7 @@ CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip(const std::string&
std::pair<QWidget*, QWidget*> CSMPrefs::ColourSetting::makeWidgets(QWidget* parent) std::pair<QWidget*, QWidget*> CSMPrefs::ColourSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
mWidget = new CSVWidget::ColorEditor(mDefault, parent); mWidget = new CSVWidget::ColorEditor(mDefault, parent);

View file

@ -29,8 +29,7 @@ namespace CSMPrefs
CSVWidget::ColorEditor* mWidget; CSVWidget::ColorEditor* mWidget;
public: public:
ColourSetting( ColourSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label, QColor default_);
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, QColor default_);
ColourSetting& setTooltip(const std::string& tooltip); ColourSetting& setTooltip(const std::string& tooltip);

View file

@ -15,7 +15,7 @@
#include "state.hpp" #include "state.hpp"
CSMPrefs::DoubleSetting::DoubleSetting( CSMPrefs::DoubleSetting::DoubleSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, double default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, double default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mPrecision(2) , mPrecision(2)
, mMin(0) , mMin(0)
@ -58,7 +58,7 @@ CSMPrefs::DoubleSetting& CSMPrefs::DoubleSetting::setTooltip(const std::string&
std::pair<QWidget*, QWidget*> CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent) std::pair<QWidget*, QWidget*> CSMPrefs::DoubleSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
mWidget = new QDoubleSpinBox(parent); mWidget = new QDoubleSpinBox(parent);
mWidget->setDecimals(mPrecision); mWidget->setDecimals(mPrecision);

View file

@ -21,8 +21,7 @@ namespace CSMPrefs
QDoubleSpinBox* mWidget; QDoubleSpinBox* mWidget;
public: public:
DoubleSetting( DoubleSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label, double default_);
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, double default_);
DoubleSetting& setPrecision(int precision); DoubleSetting& setPrecision(int precision);

View file

@ -45,7 +45,7 @@ CSMPrefs::EnumValues& CSMPrefs::EnumValues::add(const std::string& value, const
} }
CSMPrefs::EnumSetting::EnumSetting( CSMPrefs::EnumSetting::EnumSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, const EnumValue& default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, const EnumValue& default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mDefault(default_) , mDefault(default_)
, mWidget(nullptr) , mWidget(nullptr)
@ -78,7 +78,7 @@ CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::addValue(const std::string& value,
std::pair<QWidget*, QWidget*> CSMPrefs::EnumSetting::makeWidgets(QWidget* parent) std::pair<QWidget*, QWidget*> CSMPrefs::EnumSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
mWidget = new QComboBox(parent); mWidget = new QComboBox(parent);

View file

@ -44,8 +44,8 @@ namespace CSMPrefs
QComboBox* mWidget; QComboBox* mWidget;
public: public:
EnumSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label, EnumSetting(
const EnumValue& default_); Category* parent, QMutex* mutex, const std::string& key, const QString& label, const EnumValue& default_);
EnumSetting& setTooltip(const std::string& tooltip); EnumSetting& setTooltip(const std::string& tooltip);

View file

@ -15,7 +15,7 @@
#include "state.hpp" #include "state.hpp"
CSMPrefs::IntSetting::IntSetting( CSMPrefs::IntSetting::IntSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, int default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, int default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mMin(0) , mMin(0)
, mMax(std::numeric_limits<int>::max()) , mMax(std::numeric_limits<int>::max())
@ -51,7 +51,7 @@ CSMPrefs::IntSetting& CSMPrefs::IntSetting::setTooltip(const std::string& toolti
std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent) std::pair<QWidget*, QWidget*> CSMPrefs::IntSetting::makeWidgets(QWidget* parent)
{ {
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
mWidget = new QSpinBox(parent); mWidget = new QSpinBox(parent);
mWidget->setRange(mMin, mMax); mWidget->setRange(mMin, mMax);

View file

@ -23,7 +23,7 @@ namespace CSMPrefs
QSpinBox* mWidget; QSpinBox* mWidget;
public: public:
IntSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label, int default_); IntSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label, int default_);
// defaults to [0, std::numeric_limits<int>::max()] // defaults to [0, std::numeric_limits<int>::max()]
IntSetting& setRange(int min, int max); IntSetting& setRange(int min, int max);

View file

@ -19,7 +19,7 @@ class QWidget;
namespace CSMPrefs namespace CSMPrefs
{ {
ModifierSetting::ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label) ModifierSetting::ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mButton(nullptr) , mButton(nullptr)
, mEditorActive(false) , mEditorActive(false)
@ -33,7 +33,7 @@ namespace CSMPrefs
QString text = QString::fromUtf8(State::get().getShortcutManager().convertToString(modifier).c_str()); QString text = QString::fromUtf8(State::get().getShortcutManager().convertToString(modifier).c_str());
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
QPushButton* widget = new QPushButton(text, parent); QPushButton* widget = new QPushButton(text, parent);
widget->setCheckable(true); widget->setCheckable(true);

View file

@ -20,7 +20,7 @@ namespace CSMPrefs
Q_OBJECT Q_OBJECT
public: public:
ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label); ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label);
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;

View file

@ -14,7 +14,7 @@ QMutex* CSMPrefs::Setting::getMutex()
return mMutex; return mMutex;
} }
CSMPrefs::Setting::Setting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label) CSMPrefs::Setting::Setting(Category* parent, QMutex* mutex, const std::string& key, const QString& label)
: QObject(parent->getState()) : QObject(parent->getState())
, mParent(parent) , mParent(parent)
, mMutex(mutex) , mMutex(mutex)
@ -40,11 +40,6 @@ const std::string& CSMPrefs::Setting::getKey() const
return mKey; return mKey;
} }
const std::string& CSMPrefs::Setting::getLabel() const
{
return mLabel;
}
int CSMPrefs::Setting::toInt() const int CSMPrefs::Setting::toInt() const
{ {
QMutexLocker lock(mMutex); QMutexLocker lock(mMutex);

View file

@ -21,13 +21,13 @@ namespace CSMPrefs
Category* mParent; Category* mParent;
QMutex* mMutex; QMutex* mMutex;
std::string mKey; std::string mKey;
std::string mLabel; QString mLabel;
protected: protected:
QMutex* getMutex(); QMutex* getMutex();
public: public:
Setting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label); Setting(Category* parent, QMutex* mutex, const std::string& key, const QString& label);
~Setting() override = default; ~Setting() override = default;
@ -46,7 +46,7 @@ namespace CSMPrefs
const std::string& getKey() const; const std::string& getKey() const;
const std::string& getLabel() const; const QString& getLabel() const { return mLabel; }
int toInt() const; int toInt() const;

View file

@ -18,7 +18,7 @@
namespace CSMPrefs namespace CSMPrefs
{ {
ShortcutSetting::ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label) ShortcutSetting::ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mButton(nullptr) , mButton(nullptr)
, mEditorActive(false) , mEditorActive(false)
@ -37,7 +37,7 @@ namespace CSMPrefs
QString text = QString::fromUtf8(State::get().getShortcutManager().convertToString(sequence).c_str()); QString text = QString::fromUtf8(State::get().getShortcutManager().convertToString(sequence).c_str());
QLabel* label = new QLabel(QString::fromUtf8(getLabel().c_str()), parent); QLabel* label = new QLabel(getLabel(), parent);
QPushButton* widget = new QPushButton(text, parent); QPushButton* widget = new QPushButton(text, parent);
widget->setCheckable(true); widget->setCheckable(true);

View file

@ -22,7 +22,7 @@ namespace CSMPrefs
Q_OBJECT Q_OBJECT
public: public:
ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label); ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const QString& label);
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override; std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;

View file

@ -463,7 +463,7 @@ void CSMPrefs::State::declareCategory(const std::string& key)
} }
} }
CSMPrefs::IntSetting& CSMPrefs::State::declareInt(const std::string& key, const std::string& label, int default_) CSMPrefs::IntSetting& CSMPrefs::State::declareInt(const std::string& key, const QString& label, int default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -479,8 +479,7 @@ CSMPrefs::IntSetting& CSMPrefs::State::declareInt(const std::string& key, const
return *setting; return *setting;
} }
CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble( CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble(const std::string& key, const QString& label, double default_)
const std::string& key, const std::string& label, double default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -499,7 +498,7 @@ CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble(
return *setting; return *setting;
} }
CSMPrefs::BoolSetting& CSMPrefs::State::declareBool(const std::string& key, const std::string& label, bool default_) CSMPrefs::BoolSetting& CSMPrefs::State::declareBool(const std::string& key, const QString& label, bool default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -516,8 +515,7 @@ CSMPrefs::BoolSetting& CSMPrefs::State::declareBool(const std::string& key, cons
return *setting; return *setting;
} }
CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum( CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum(const std::string& key, const QString& label, EnumValue default_)
const std::string& key, const std::string& label, EnumValue default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -534,8 +532,7 @@ CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum(
return *setting; return *setting;
} }
CSMPrefs::ColourSetting& CSMPrefs::State::declareColour( CSMPrefs::ColourSetting& CSMPrefs::State::declareColour(const std::string& key, const QString& label, QColor default_)
const std::string& key, const std::string& label, QColor default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -554,7 +551,7 @@ CSMPrefs::ColourSetting& CSMPrefs::State::declareColour(
} }
CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut( CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut(
const std::string& key, const std::string& label, const QKeySequence& default_) const std::string& key, const QString& label, const QKeySequence& default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -576,7 +573,7 @@ CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut(
} }
CSMPrefs::StringSetting& CSMPrefs::State::declareString( CSMPrefs::StringSetting& CSMPrefs::State::declareString(
const std::string& key, const std::string& label, std::string default_) const std::string& key, const QString& label, std::string default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -593,8 +590,7 @@ CSMPrefs::StringSetting& CSMPrefs::State::declareString(
return *setting; return *setting;
} }
CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier( CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& key, const QString& label, int default_)
const std::string& key, const std::string& label, int default_)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");
@ -625,7 +621,7 @@ void CSMPrefs::State::declareSeparator()
mCurrentCategory->second.addSetting(setting); mCurrentCategory->second.addSetting(setting);
} }
void CSMPrefs::State::declareSubcategory(const std::string& label) void CSMPrefs::State::declareSubcategory(const QString& label)
{ {
if (mCurrentCategory == mCategories.end()) if (mCurrentCategory == mCategories.end())
throw std::logic_error("no category for setting"); throw std::logic_error("no category for setting");

View file

@ -60,25 +60,24 @@ namespace CSMPrefs
void declareCategory(const std::string& key); void declareCategory(const std::string& key);
IntSetting& declareInt(const std::string& key, const std::string& label, int default_); IntSetting& declareInt(const std::string& key, const QString& label, int default_);
DoubleSetting& declareDouble(const std::string& key, const std::string& label, double default_); DoubleSetting& declareDouble(const std::string& key, const QString& label, double default_);
BoolSetting& declareBool(const std::string& key, const std::string& label, bool default_); BoolSetting& declareBool(const std::string& key, const QString& label, bool default_);
EnumSetting& declareEnum(const std::string& key, const std::string& label, EnumValue default_); EnumSetting& declareEnum(const std::string& key, const QString& label, EnumValue default_);
ColourSetting& declareColour(const std::string& key, const std::string& label, QColor default_); ColourSetting& declareColour(const std::string& key, const QString& label, QColor default_);
ShortcutSetting& declareShortcut( ShortcutSetting& declareShortcut(const std::string& key, const QString& label, const QKeySequence& default_);
const std::string& key, const std::string& label, const QKeySequence& default_);
StringSetting& declareString(const std::string& key, const std::string& label, std::string default_); StringSetting& declareString(const std::string& key, const QString& label, std::string default_);
ModifierSetting& declareModifier(const std::string& key, const std::string& label, int modifier_); ModifierSetting& declareModifier(const std::string& key, const QString& label, int modifier_);
void declareSeparator(); void declareSeparator();
void declareSubcategory(const std::string& label); void declareSubcategory(const QString& label);
void setDefault(const std::string& key, const std::string& default_); void setDefault(const std::string& key, const std::string& default_);

View file

@ -12,7 +12,7 @@
#include "state.hpp" #include "state.hpp"
CSMPrefs::StringSetting::StringSetting( CSMPrefs::StringSetting::StringSetting(
Category* parent, QMutex* mutex, const std::string& key, const std::string& label, std::string_view default_) Category* parent, QMutex* mutex, const std::string& key, const QString& label, std::string_view default_)
: Setting(parent, mutex, key, label) : Setting(parent, mutex, key, label)
, mDefault(default_) , mDefault(default_)
, mWidget(nullptr) , mWidget(nullptr)

View file

@ -23,8 +23,8 @@ namespace CSMPrefs
QLineEdit* mWidget; QLineEdit* mWidget;
public: public:
StringSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label, StringSetting(
std::string_view default_); Category* parent, QMutex* mutex, const std::string& key, const QString& label, std::string_view default_);
StringSetting& setTooltip(const std::string& tooltip); StringSetting& setTooltip(const std::string& tooltip);

View file

@ -82,7 +82,7 @@ namespace CSVPrefs
} }
else else
{ {
if (setting->getLabel().empty()) if (setting->getLabel().isEmpty())
{ {
// Insert empty space // Insert empty space
assert(mPageLayout); assert(mPageLayout);
@ -99,7 +99,7 @@ namespace CSVPrefs
mStackedLayout->addWidget(pageWidget); mStackedLayout->addWidget(pageWidget);
mPageSelector->addItem(QString::fromUtf8(setting->getLabel().c_str())); mPageSelector->addItem(setting->getLabel());
} }
} }
} }