From a691b31b8ea98ab118d27a20a6db5ad2e4a60182 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sun, 10 Jan 2021 13:39:36 +0200 Subject: [PATCH] gui: Make access to hotkey actions explicit --- src/gui/src/Hotkey.h | 7 ++++--- src/gui/src/ServerConfigDialog.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/gui/src/Hotkey.h b/src/gui/src/Hotkey.h index 91e39f38..becf3739 100644 --- a/src/gui/src/Hotkey.h +++ b/src/gui/src/Hotkey.h @@ -34,7 +34,6 @@ class QSettings; class Hotkey { friend class HotkeyDialog; - friend class ServerConfigDialog; friend QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey); public: @@ -45,13 +44,15 @@ class Hotkey const KeySequence& keySequence() const { return m_KeySequence; } const ActionList& actions() const { return m_Actions; } + void appendAction(const Action& action) { m_Actions.append(action); } + void setAction(int index, const Action& action) { m_Actions[index] = action; } + void removeAction(int index) { m_Actions.removeAt(index); } + void loadSettings(QSettings& settings); void saveSettings(QSettings& settings) const; protected: void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; } - ActionList& actions() { return m_Actions; } - private: KeySequence m_KeySequence; diff --git a/src/gui/src/ServerConfigDialog.cpp b/src/gui/src/ServerConfigDialog.cpp index dfa8022c..9d789d4c 100644 --- a/src/gui/src/ServerConfigDialog.cpp +++ b/src/gui/src/ServerConfigDialog.cpp @@ -183,7 +183,7 @@ void ServerConfigDialog::on_m_pButtonNewAction_clicked() ActionDialog dlg(this, serverConfig(), hotkey, action); if (dlg.exec() == QDialog::Accepted) { - hotkey.actions().append(action); + hotkey.appendAction(action); m_pListActions->addItem(action.text()); } } @@ -196,11 +196,13 @@ void ServerConfigDialog::on_m_pButtonEditAction_clicked() int idxAction = m_pListActions->currentRow(); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); - Action& action = hotkey.actions()[idxAction]; + Action action = hotkey.actions()[idxAction]; ActionDialog dlg(this, serverConfig(), hotkey, action); - if (dlg.exec() == QDialog::Accepted) + if (dlg.exec() == QDialog::Accepted) { + hotkey.setAction(idxAction, action); m_pListActions->currentItem()->setText(action.text()); + } } void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() @@ -212,7 +214,7 @@ void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() int idxAction = m_pListActions->currentRow(); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); - hotkey.actions().removeAt(idxAction); + hotkey.removeAction(idxAction); delete m_pListActions->currentItem(); }