mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 09:39:56 +00:00
Use settings values to declare modifier settings
This commit is contained in:
parent
4dfd2b0f46
commit
11db9eec1d
@ -20,7 +20,7 @@ class QWidget;
|
||||
namespace CSMPrefs
|
||||
{
|
||||
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)
|
||||
, mButton(nullptr)
|
||||
, mEditorActive(false)
|
||||
|
@ -22,7 +22,7 @@ namespace CSMPrefs
|
||||
|
||||
public:
|
||||
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;
|
||||
|
||||
|
@ -16,7 +16,7 @@ QMutex* CSMPrefs::Setting::getMutex()
|
||||
}
|
||||
|
||||
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())
|
||||
, mParent(parent)
|
||||
, mMutex(mutex)
|
||||
|
@ -62,7 +62,7 @@ namespace CSMPrefs
|
||||
|
||||
public:
|
||||
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;
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace CSMPrefs
|
||||
return false;
|
||||
}
|
||||
|
||||
void ShortcutManager::setModifier(const std::string& name, int modifier)
|
||||
void ShortcutManager::setModifier(std::string_view name, int modifier)
|
||||
{
|
||||
// Add to map/modify
|
||||
ModifierMap::iterator item = mModifiers.find(name);
|
||||
|
@ -32,7 +32,7 @@ namespace CSMPrefs
|
||||
void setSequence(const std::string& name, const QKeySequence& sequence);
|
||||
|
||||
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(int modifier) const;
|
||||
@ -49,9 +49,9 @@ namespace CSMPrefs
|
||||
|
||||
private:
|
||||
// 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, int> ModifierMap;
|
||||
typedef std::map<std::string, int, std::less<>> ModifierMap;
|
||||
typedef std::map<int, std::string> NameMap;
|
||||
typedef std::map<std::string, int> KeyMap;
|
||||
|
||||
|
@ -396,7 +396,7 @@ void CSMPrefs::State::declare()
|
||||
"scene-select-secondary", "Secondary Select", QKeySequence(Qt::ControlModifier | (int)Qt::MiddleButton));
|
||||
declareShortcut(
|
||||
"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-instance-drop-terrain", "Drop to terrain level", QKeySequence(Qt::Key_G));
|
||||
declareShortcut("scene-instance-drop-collision", "Drop to collision", QKeySequence(Qt::Key_H));
|
||||
@ -553,7 +553,8 @@ CSMPrefs::StringSetting& CSMPrefs::State::declareString(
|
||||
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())
|
||||
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
|
||||
int modifier;
|
||||
|
||||
getShortcutManager().convertFromString(mIndex->get<std::string>(mCurrentCategory->second.getKey(), key), modifier);
|
||||
getShortcutManager().setModifier(key, modifier);
|
||||
getShortcutManager().convertFromString(value.get(), modifier);
|
||||
getShortcutManager().setModifier(value.mName, modifier);
|
||||
|
||||
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);
|
||||
|
||||
return *setting;
|
||||
|
@ -76,7 +76,7 @@ namespace CSMPrefs
|
||||
|
||||
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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user