From fa74f28bca86cc32c00a2b438d3da32b4d578ff0 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Mon, 24 Sep 2018 11:55:39 +0200 Subject: [PATCH] Add deviceName attribute to CJoystickButton ref T254 --- src/blackmisc/input/joystickbutton.cpp | 9 +++++++-- src/blackmisc/input/joystickbutton.h | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/blackmisc/input/joystickbutton.cpp b/src/blackmisc/input/joystickbutton.cpp index 166ec04df..b6e170d31 100644 --- a/src/blackmisc/input/joystickbutton.cpp +++ b/src/blackmisc/input/joystickbutton.cpp @@ -15,8 +15,8 @@ namespace BlackMisc { namespace Input { - CJoystickButton::CJoystickButton(int buttonIndex) : - m_buttonIndex(buttonIndex) + CJoystickButton::CJoystickButton(const QString deviceName, int index) : + m_deviceName(deviceName), m_buttonIndex(index) {} void CJoystickButton::setButtonIndex(int buttonIndex) @@ -35,6 +35,9 @@ namespace BlackMisc ColumnIndex i = index.frontCasted(); switch (i) { + case IndexDeviceName: + this->setDeviceName(variant.value()); + break; case IndexButton: case IndexButtonAsString: this->setButtonIndex(buttonIndexFromString(variant.value())); @@ -54,6 +57,8 @@ namespace BlackMisc ColumnIndex i = index.frontCasted(); switch (i) { + case IndexDeviceName: + return CVariant::from(this->getDeviceName()); case IndexButton: return CVariant::from(this->getButtonIndex()); case IndexButtonAsString: diff --git a/src/blackmisc/input/joystickbutton.h b/src/blackmisc/input/joystickbutton.h index 602c1927a..aaddfd4df 100644 --- a/src/blackmisc/input/joystickbutton.h +++ b/src/blackmisc/input/joystickbutton.h @@ -33,7 +33,8 @@ namespace BlackMisc //! Properties by index enum ColumnIndex { - IndexButton = 0, + IndexDeviceName = 0, + IndexButton, IndexButtonAsString, IndeButtonObject, // just for updates }; @@ -42,7 +43,10 @@ namespace BlackMisc CJoystickButton() = default; //! Constructor - CJoystickButton(int buttonIndex); + CJoystickButton(const QString deviceName, int index); + + //! Get device name + QString getDeviceName() const { return m_deviceName; } //! Get button index int getButtonIndex() const { return m_buttonIndex; } @@ -50,11 +54,14 @@ namespace BlackMisc //! Get button as String QString getButtonAsString() const { return buttonIndexToString(m_buttonIndex); } + //! Set owning device name + void setDeviceName(const QString &deviceName) { m_deviceName = deviceName; } + //! Set button index void setButtonIndex(int buttonIndex); //! Is valid? - bool isValid() const { return m_buttonIndex >= 0 ? true : false; } + bool isValid() const { return !m_deviceName.isEmpty() && m_buttonIndex >= 0 ? true : false; } //! Set button object void setButtonObject(CJoystickButton button); @@ -78,12 +85,14 @@ namespace BlackMisc QString convertToQString(bool i18n = false) const; private: + QString m_deviceName; int m_buttonIndex = m_invalidIndex; static constexpr int m_invalidIndex = -1; BLACK_METACLASS( CJoystickButton, + BLACK_METAMEMBER(deviceName), BLACK_METAMEMBER(buttonIndex) ); };