1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-05 01:06:40 +00:00

Merge branch 'editor_modifier_settings' into 'master'

Use settings values to declare modifier settings ()

See merge request 
This commit is contained in:
Alexei Kotov 2023-12-18 00:37:55 +00:00
commit 7922f0e7f8
8 changed files with 15 additions and 14 deletions

View file

@ -20,7 +20,7 @@ class QWidget;
namespace CSMPrefs namespace CSMPrefs
{ {
ModifierSetting::ModifierSetting( ModifierSetting::ModifierSetting(
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index) Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
: TypedSetting(parent, mutex, key, label, index) : TypedSetting(parent, mutex, key, label, index)
, mButton(nullptr) , mButton(nullptr)
, mEditorActive(false) , mEditorActive(false)

View file

@ -22,7 +22,7 @@ namespace CSMPrefs
public: public:
explicit ModifierSetting( explicit ModifierSetting(
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index); Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index);
SettingWidgets makeWidgets(QWidget* parent) override; SettingWidgets makeWidgets(QWidget* parent) override;

View file

@ -16,7 +16,7 @@ QMutex* CSMPrefs::Setting::getMutex()
} }
CSMPrefs::Setting::Setting( CSMPrefs::Setting::Setting(
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index) Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index)
: QObject(parent->getState()) : QObject(parent->getState())
, mParent(parent) , mParent(parent)
, mMutex(mutex) , mMutex(mutex)

View file

@ -61,7 +61,7 @@ namespace CSMPrefs
public: public:
explicit Setting( explicit Setting(
Category* parent, QMutex* mutex, const std::string& key, const QString& label, Settings::Index& index); Category* parent, QMutex* mutex, std::string_view key, const QString& label, Settings::Index& index);
~Setting() override = default; ~Setting() override = default;

View file

@ -91,7 +91,7 @@ namespace CSMPrefs
return false; return false;
} }
void ShortcutManager::setModifier(const std::string& name, int modifier) void ShortcutManager::setModifier(std::string_view name, int modifier)
{ {
// Add to map/modify // Add to map/modify
ModifierMap::iterator item = mModifiers.find(name); ModifierMap::iterator item = mModifiers.find(name);

View file

@ -32,7 +32,7 @@ namespace CSMPrefs
void setSequence(const std::string& name, const QKeySequence& sequence); void setSequence(const std::string& name, const QKeySequence& sequence);
bool getModifier(const std::string& name, int& modifier) const; bool getModifier(const std::string& name, int& modifier) const;
void setModifier(const std::string& name, int modifier); void setModifier(std::string_view name, int modifier);
std::string convertToString(const QKeySequence& sequence) const; std::string convertToString(const QKeySequence& sequence) const;
std::string convertToString(int modifier) const; std::string convertToString(int modifier) const;
@ -49,9 +49,9 @@ namespace CSMPrefs
private: private:
// Need a multimap in case multiple shortcuts share the same name // Need a multimap in case multiple shortcuts share the same name
typedef std::multimap<std::string, Shortcut*> ShortcutMap; typedef std::multimap<std::string, Shortcut*, std::less<>> ShortcutMap;
typedef std::map<std::string, QKeySequence> SequenceMap; typedef std::map<std::string, QKeySequence> SequenceMap;
typedef std::map<std::string, int> ModifierMap; typedef std::map<std::string, int, std::less<>> ModifierMap;
typedef std::map<int, std::string> NameMap; typedef std::map<int, std::string> NameMap;
typedef std::map<std::string, int> KeyMap; typedef std::map<std::string, int> KeyMap;

View file

@ -396,7 +396,7 @@ void CSMPrefs::State::declare()
"scene-select-secondary", "Secondary Select", QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton)); "scene-select-secondary", "Secondary Select", QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton));
declareShortcut( declareShortcut(
"scene-select-tertiary", "Tertiary Select", QKeySequence(Qt::ShiftModifier | (int)Qt::MiddleButton)); "scene-select-tertiary", "Tertiary Select", QKeySequence(Qt::ShiftModifier | (int)Qt::MiddleButton));
declareModifier("scene-speed-modifier", "Speed Modifier", Qt::Key_Shift); declareModifier(mValues->mKeyBindings.mSceneSpeedModifier, "Speed Modifier");
declareShortcut("scene-delete", "Delete Instance", QKeySequence(Qt::Key_Delete)); declareShortcut("scene-delete", "Delete Instance", QKeySequence(Qt::Key_Delete));
declareShortcut("scene-instance-drop-terrain", "Drop to terrain level", QKeySequence(Qt::Key_G)); declareShortcut("scene-instance-drop-terrain", "Drop to terrain level", QKeySequence(Qt::Key_G));
declareShortcut("scene-instance-drop-collision", "Drop to collision", QKeySequence(Qt::Key_H)); declareShortcut("scene-instance-drop-collision", "Drop to collision", QKeySequence(Qt::Key_H));
@ -553,7 +553,8 @@ CSMPrefs::StringSetting& CSMPrefs::State::declareString(
return *setting; return *setting;
} }
CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& key, const QString& label, int default_) CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(
Settings::SettingValue<std::string>& value, 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");
@ -561,11 +562,11 @@ CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& k
// Setup with actual data // Setup with actual data
int modifier; int modifier;
getShortcutManager().convertFromString(mIndex->get<std::string>(mCurrentCategory->second.getKey(), key), modifier); getShortcutManager().convertFromString(value.get(), modifier);
getShortcutManager().setModifier(key, modifier); getShortcutManager().setModifier(value.mName, modifier);
CSMPrefs::ModifierSetting* setting CSMPrefs::ModifierSetting* setting
= new CSMPrefs::ModifierSetting(&mCurrentCategory->second, &mMutex, key, label, *mIndex); = new CSMPrefs::ModifierSetting(&mCurrentCategory->second, &mMutex, value.mName, label, *mIndex);
mCurrentCategory->second.addSetting(setting); mCurrentCategory->second.addSetting(setting);
return *setting; return *setting;

View file

@ -76,7 +76,7 @@ namespace CSMPrefs
StringSetting& declareString(const std::string& key, const QString& label, const std::string& default_); StringSetting& declareString(const std::string& key, const QString& label, const std::string& default_);
ModifierSetting& declareModifier(const std::string& key, const QString& label, int modifier_); ModifierSetting& declareModifier(Settings::SettingValue<std::string>& value, const QString& label);
void declareSubcategory(const QString& label); void declareSubcategory(const QString& label);