gui: Make access to hotkey actions explicit

This commit is contained in:
Povilas Kanapickas 2021-01-10 13:39:36 +02:00
parent 016393fb67
commit a691b31b8e
2 changed files with 10 additions and 7 deletions

View File

@ -34,7 +34,6 @@ class QSettings;
class Hotkey class Hotkey
{ {
friend class HotkeyDialog; friend class HotkeyDialog;
friend class ServerConfigDialog;
friend QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey); friend QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey);
public: public:
@ -45,13 +44,15 @@ class Hotkey
const KeySequence& keySequence() const { return m_KeySequence; } const KeySequence& keySequence() const { return m_KeySequence; }
const ActionList& actions() const { return m_Actions; } 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 loadSettings(QSettings& settings);
void saveSettings(QSettings& settings) const; void saveSettings(QSettings& settings) const;
protected: protected:
void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; } void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; }
ActionList& actions() { return m_Actions; }
private: private:
KeySequence m_KeySequence; KeySequence m_KeySequence;

View File

@ -183,7 +183,7 @@ void ServerConfigDialog::on_m_pButtonNewAction_clicked()
ActionDialog dlg(this, serverConfig(), hotkey, action); ActionDialog dlg(this, serverConfig(), hotkey, action);
if (dlg.exec() == QDialog::Accepted) if (dlg.exec() == QDialog::Accepted)
{ {
hotkey.actions().append(action); hotkey.appendAction(action);
m_pListActions->addItem(action.text()); m_pListActions->addItem(action.text());
} }
} }
@ -196,11 +196,13 @@ void ServerConfigDialog::on_m_pButtonEditAction_clicked()
int idxAction = m_pListActions->currentRow(); int idxAction = m_pListActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size());
Action& action = hotkey.actions()[idxAction]; Action action = hotkey.actions()[idxAction];
ActionDialog dlg(this, serverConfig(), hotkey, action); 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()); m_pListActions->currentItem()->setText(action.text());
}
} }
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
@ -212,7 +214,7 @@ void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
int idxAction = m_pListActions->currentRow(); int idxAction = m_pListActions->currentRow();
Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size()); Q_ASSERT(idxAction >= 0 && idxAction < hotkey.actions().size());
hotkey.actions().removeAt(idxAction); hotkey.removeAction(idxAction);
delete m_pListActions->currentItem(); delete m_pListActions->currentItem();
} }