From 68cfb4e58566c8019479e2c3318560cd35c31d89 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sun, 10 Jan 2021 13:39:38 +0200 Subject: [PATCH] gui: Don't use friends to limit access to Action --- src/gui/src/Action.cpp | 14 +++++++------- src/gui/src/Action.h | 31 +++++++++++++++++-------------- src/gui/src/ActionDialog.cpp | 4 ++-- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/gui/src/Action.cpp b/src/gui/src/Action.cpp index 8179b748..2882afb1 100644 --- a/src/gui/src/Action.cpp +++ b/src/gui/src/Action.cpp @@ -51,7 +51,7 @@ QString Action::text() const * in the end but now argument inside. If you need a function with no * argument, it can not have () in the end. */ - QString text = QString(m_ActionTypeNames[keySequence().isMouseButton() ? + QString text = QString(m_ActionTypeNames[m_KeySequence.isMouseButton() ? type() + int(mouseDown) : type()]); switch (type()) @@ -61,9 +61,9 @@ QString Action::text() const case keystroke: { text += "("; - text += keySequence().toString(); + text += m_KeySequence.toString(); - if (!keySequence().isMouseButton()) + if (!m_KeySequence.isMouseButton()) { const QStringList& screens = typeScreenNames(); if (haveScreens() && !screens.isEmpty()) @@ -116,15 +116,15 @@ QString Action::text() const void Action::loadSettings(QSettings& settings) { - keySequence().loadSettings(settings); + m_KeySequence.loadSettings(settings); setType(settings.value("type", keyDown).toInt()); - typeScreenNames().clear(); + m_TypeScreenNames.clear(); int numTypeScreens = settings.beginReadArray("typeScreenNames"); for (int i = 0; i < numTypeScreens; i++) { settings.setArrayIndex(i); - typeScreenNames().append(settings.value("typeScreenName").toString()); + m_TypeScreenNames.append(settings.value("typeScreenName").toString()); } settings.endArray(); @@ -137,7 +137,7 @@ void Action::loadSettings(QSettings& settings) void Action::saveSettings(QSettings& settings) const { - keySequence().saveSettings(settings); + m_KeySequence.saveSettings(settings); settings.setValue("type", type()); settings.beginWriteArray("typeScreenNames"); diff --git a/src/gui/src/Action.h b/src/gui/src/Action.h index 67e316fc..e9f4176a 100644 --- a/src/gui/src/Action.h +++ b/src/gui/src/Action.h @@ -32,9 +32,6 @@ class QTextStream; class Action { - friend class ActionDialog; - friend QTextStream& operator<<(QTextStream& outStream, const Action& action); - public: enum ActionType { keyDown, keyUp, keystroke, switchToScreen, toggleScreen, switchInDirection, @@ -48,25 +45,31 @@ class Action public: QString text() const; const KeySequence& keySequence() const { return m_KeySequence; } + void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; } + void loadSettings(QSettings& settings); void saveSettings(QSettings& settings) const; - int type() const { return m_Type; } - const QStringList& typeScreenNames() const { return m_TypeScreenNames; } - const QString& switchScreenName() const { return m_SwitchScreenName; } - int switchDirection() const { return m_SwitchDirection; } - int lockCursorMode() const { return m_LockCursorMode; } - bool activeOnRelease() const { return m_ActiveOnRelease; } - bool haveScreens() const { return m_HasScreens; } - protected: - KeySequence& keySequence() { return m_KeySequence; } - void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; } + int type() const { return m_Type; } void setType(int t) { m_Type = t; } - QStringList& typeScreenNames() { return m_TypeScreenNames; } + + const QStringList& typeScreenNames() const { return m_TypeScreenNames; } + void appendTypeScreenName(QString name) { m_TypeScreenNames.append(name); } + void clearTypeScreenNames() { m_TypeScreenNames.clear(); } + + const QString& switchScreenName() const { return m_SwitchScreenName; } void setSwitchScreenName(const QString& n) { m_SwitchScreenName = n; } + + int switchDirection() const { return m_SwitchDirection; } void setSwitchDirection(int d) { m_SwitchDirection = d; } + + int lockCursorMode() const { return m_LockCursorMode; } void setLockCursorMode(int m) { m_LockCursorMode = m; } + + bool activeOnRelease() const { return m_ActiveOnRelease; } void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; } + + bool haveScreens() const { return m_HasScreens; } void setHaveScreens(bool b) { m_HasScreens = b; } private: diff --git a/src/gui/src/ActionDialog.cpp b/src/gui/src/ActionDialog.cpp index aff46a01..bf5c6b97 100644 --- a/src/gui/src/ActionDialog.cpp +++ b/src/gui/src/ActionDialog.cpp @@ -83,9 +83,9 @@ void ActionDialog::accept() m_Action.setType(m_pButtonGroupType->checkedId()); m_Action.setHaveScreens(m_pGroupBoxScreens->isChecked()); - m_Action.typeScreenNames().clear(); + m_Action.clearTypeScreenNames(); foreach(const QListWidgetItem* pItem, m_pListScreens->selectedItems()) - m_Action.typeScreenNames().append(pItem->text()); + m_Action.appendTypeScreenName(pItem->text()); m_Action.setSwitchScreenName(m_pComboSwitchToScreen->currentText()); m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex());