diff --git a/src/client/utils/customshortcutmodel.cpp b/src/client/utils/customshortcutmodel.cpp index 923e84516..ca1c42a6e 100644 --- a/src/client/utils/customshortcutmodel.cpp +++ b/src/client/utils/customshortcutmodel.cpp @@ -1,7 +1,7 @@ /* Drawpile - a collaborative drawing program. - Copyright (C) 2015-2018 Calle Laakkonen + Copyright (C) 2015-2019 Calle Laakkonen Drawpile is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -98,7 +98,7 @@ QVariant CustomShortcutModel::headerData(int section, Qt::Orientation orientatio void CustomShortcutModel::loadShortcuts() { - QList actions; + QVector actions; actions.reserve(m_customizableActions.size()); QSettings cfg; @@ -114,9 +114,7 @@ void CustomShortcutModel::loadShortcuts() actions.append(a); } - std::sort(actions.begin(), actions.end(), - [](const CustomShortcut &a1, const CustomShortcut &a2) { return a1.title.compare(a2.title) < 0; } - ); + std::sort(actions.begin(), actions.end()); beginResetModel(); m_shortcuts = actions; @@ -128,7 +126,7 @@ void CustomShortcutModel::saveShortcuts() QSettings cfg; cfg.beginGroup("settings/shortcuts"); - cfg.remove(""); + cfg.remove(QString()); for(const CustomShortcut &cs : m_shortcuts) { if(cs.currentShortcut != cs.defaultShortcut) @@ -141,26 +139,17 @@ void CustomShortcutModel::registerCustomizableAction(const QString &name, const if(m_customizableActions.contains(name)) return; - m_customizableActions[name] = CustomShortcut(name, title, defaultShortcut); -} - -bool CustomShortcutModel::hasDefaultShortcut(const QString &name) -{ - return m_customizableActions.contains(name); + m_customizableActions[name] = CustomShortcut { + name, + title, + defaultShortcut, + QKeySequence() + }; } QKeySequence CustomShortcutModel::getDefaultShortcut(const QString &name) { - return m_customizableActions[name].defaultShortcut; -} - -QKeySequence CustomShortcutModel::getShorcut(const QString &name) -{ - QSettings cfg; - cfg.beginGroup("settings/shortcuts"); - if(cfg.contains(name)) - return cfg.value(name).value(); - else if(m_customizableActions.contains(name)) + if(m_customizableActions.contains(name)) return m_customizableActions[name].defaultShortcut; else return QKeySequence(); diff --git a/src/client/utils/customshortcutmodel.h b/src/client/utils/customshortcutmodel.h index 691b91a95..eefd45774 100644 --- a/src/client/utils/customshortcutmodel.h +++ b/src/client/utils/customshortcutmodel.h @@ -1,7 +1,7 @@ /* Drawpile - a collaborative drawing program. - Copyright (C) 2015-2018 Calle Laakkonen + Copyright (C) 2015-2019 Calle Laakkonen Drawpile is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -30,10 +30,7 @@ struct CustomShortcut { QKeySequence defaultShortcut; QKeySequence currentShortcut; - CustomShortcut() { } - CustomShortcut(const QString &n, const QString &t, const QKeySequence &s) - : name(n), title(t), defaultShortcut(s), currentShortcut(QKeySequence()) - { } + bool operator<(const CustomShortcut &other) const { return title.compare(other.title) < 0; } }; class CustomShortcutModel : public QAbstractTableModel @@ -52,14 +49,11 @@ class CustomShortcutModel : public QAbstractTableModel void loadShortcuts(); void saveShortcuts(); - static bool hasDefaultShortcut(const QString &name); static QKeySequence getDefaultShortcut(const QString &name); - static QKeySequence getShorcut(const QString &name); - static void registerCustomizableAction(const QString &name, const QString &title, const QKeySequence &defaultShortcut); -private: - QList m_shortcuts; +private: + QVector m_shortcuts; static QMap m_customizableActions; }; diff --git a/src/desktop/mainwindow.cpp b/src/desktop/mainwindow.cpp index 70fd1bf04..c8c5ca62f 100644 --- a/src/desktop/mainwindow.cpp +++ b/src/desktop/mainwindow.cpp @@ -685,7 +685,7 @@ void MainWindow::loadShortcuts() if(!name.isEmpty()) { if(cfg.contains(name)) a->setShortcut(cfg.value(name).value()); - else if(CustomShortcutModel::hasDefaultShortcut(name)) + else a->setShortcut(CustomShortcutModel::getDefaultShortcut(name)); // If an action has a shortcut, show it in the tooltip