From 18b19158d2982cc94754bc3889c3406792fb1863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Fri, 18 Nov 2022 17:02:25 +0100 Subject: [PATCH] chore: Rename index variable to improve readability --- src/joybutton.cpp | 38 +++++++++---------- src/joybutton.h | 4 +- src/joybuttontypes/joyaccelerometerbutton.cpp | 8 ++-- src/joybuttontypes/joyaccelerometerbutton.h | 3 +- src/joybuttontypes/joyaxisbutton.cpp | 6 +-- src/joybuttontypes/joycontrolstickbutton.cpp | 26 ++++++------- src/joybuttontypes/joydpadbutton.cpp | 6 +-- src/joybuttontypes/joygradientbutton.cpp | 4 +- src/joybuttontypes/joygradientbutton.h | 2 +- src/joybuttontypes/joygyroscopebutton.cpp | 2 +- src/joybuttontypes/joysensorbutton.cpp | 12 +++--- 11 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/joybutton.cpp b/src/joybutton.cpp index 66a20d823..08048e263 100644 --- a/src/joybutton.cpp +++ b/src/joybutton.cpp @@ -73,7 +73,7 @@ QList JoyButton::pendingMouseButtons; // IT CAN BE HERE // LOOK FOR JoyCycle and put JoyMix next to the slots types -JoyButton::JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent) +JoyButton::JoyButton(int sdl_button_index, int originset, SetJoystick *parentSet, QObject *parent) : QObject(parent) { m_vdpad = nullptr; @@ -115,10 +115,10 @@ JoyButton::JoyButton(int index, int originset, SetJoystick *parentSet, QObject * // Make sure to call before calling reset resetAllProperties(); - m_index = index; + m_index_sdl = sdl_button_index; m_originset = originset; quitEvent = true; - VERBOSE() << "Created button with ID: " << m_index << " For set: " << originset << " Name: " << getName(); + VERBOSE() << "Created button with ID: " << m_index_sdl << " For set: " << originset << " Name: " << getName(); } JoyButton::~JoyButton() @@ -158,9 +158,9 @@ void JoyButton::vdpadPassEvent(bool pressed, bool ignoresets) isButtonPressed = pressed; if (isButtonPressed) - emit clicked(m_index); + emit clicked(m_index_sdl); else - emit released(m_index); + emit released(m_index_sdl); if (!ignoresets) m_vdpad->queueJoyEvent(ignoresets); @@ -176,7 +176,7 @@ void JoyButton::vdpadPassEvent(bool pressed, bool ignoresets) void JoyButton::joyEvent(bool pressed, bool ignoresets) { if (Logger::isDebugEnabled()) - DEBUG() << "Processing JoyButton::joyEvent for: " << getName() << " SDL index: " << m_index + DEBUG() << "Processing JoyButton::joyEvent for: " << getName() << " SDL index: " << m_index_sdl << " className: " << metaObject()->className(); if ((m_vdpad != nullptr) && !pendingEvent) @@ -186,21 +186,21 @@ void JoyButton::joyEvent(bool pressed, bool ignoresets) { isButtonPressed = pressed; if (isButtonPressed) - emit clicked(m_index); + emit clicked(m_index_sdl); else - emit released(m_index); + emit released(m_index_sdl); } else { if (pressed != isDown) { if (pressed) { - emit clicked(m_index); + emit clicked(m_index_sdl); if (updateInitAccelValues) oldAccelMulti = updateOldAccelMulti = accelTravel = 0.0; } else { - emit released(m_index); + emit released(m_index_sdl); } bool activePress = pressed; @@ -352,18 +352,18 @@ void JoyButton::startSequenceOfPressActive(bool isTurbo, QString debugText) } /** - * @brief Get 0 indexed number of button + * @brief Get 0 indexed number of SDL button index * @return 0 indexed button index number */ -int JoyButton::getJoyNumber() { return m_index; } +int JoyButton::getJoyNumber() { return m_index_sdl; } /** * @brief Get a 1 indexed number of button * @return 1 indexed button index number */ -int JoyButton::getRealJoyNumber() const { return m_index + 1; } +int JoyButton::getRealJoyNumber() const { return m_index_sdl + 1; } -void JoyButton::setJoyNumber(int index) { m_index = index; } +void JoyButton::setJoyNumber(int index) { m_index_sdl = index; } void JoyButton::setToggle(bool toggle) { @@ -403,7 +403,7 @@ void JoyButton::resetPrivVars() void JoyButton::reset(int index) { JoyButton::reset(); - m_index = index; + m_index_sdl = index; } bool JoyButton::getToggleState() { return m_toggle; } @@ -980,7 +980,7 @@ void JoyButton::slotSetChange() // Ensure that a change to the current set is not attempted. if (setChangeIndex != m_originset) { - emit released(m_index); + emit released(m_index_sdl); emit setChangeActivated(setChangeIndex); } } @@ -2437,11 +2437,11 @@ void JoyButton::setChangeSetCondition(SetChangeCondition condition, bool passive if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay)) { // Set new condition - emit setAssignmentChanged(m_index, setSelection, condition); + emit setAssignmentChanged(m_index_sdl, setSelection, condition); } else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay)) { // Remove old condition - emit setAssignmentChanged(m_index, setSelection, SetChangeDisabled); + emit setAssignmentChanged(m_index_sdl, setSelection, SetChangeDisabled); } setSelectionCondition = condition; @@ -2591,7 +2591,7 @@ void JoyButton::restartAllForSetChange() isButtonPressedQueue.clear(); ignoreSetQueue.clear(); - emit released(m_index); + emit released(m_index_sdl); emit setChangeActivated(setSelection); } diff --git a/src/joybutton.h b/src/joybutton.h index f78ca4d2e..b9c051d91 100644 --- a/src/joybutton.h +++ b/src/joybutton.h @@ -48,7 +48,7 @@ class JoyButton : public QObject Q_OBJECT public: - explicit JoyButton(int index, int originset, SetJoystick *parentSet, QObject *parent); + explicit JoyButton(int sdl_button_index, int originset, SetJoystick *parentSet, QObject *parent); ~JoyButton(); enum SetChangeCondition @@ -300,7 +300,7 @@ class JoyButton : public QObject static JoyButtonSlot *lastActiveKey; // JoyButtonSlots class static JoyButtonMouseHelper mouseHelper; - int m_index; // Used to denote the SDL index of the actual joypad button + int m_index_sdl; // Used to denote the SDL index of the actual joypad button int turboInterval; int wheelSpeedX; int wheelSpeedY; diff --git a/src/joybuttontypes/joyaccelerometerbutton.cpp b/src/joybuttontypes/joyaccelerometerbutton.cpp index 21bd2da50..36f60bb6b 100644 --- a/src/joybuttontypes/joyaccelerometerbutton.cpp +++ b/src/joybuttontypes/joyaccelerometerbutton.cpp @@ -18,9 +18,9 @@ #include "joyaccelerometerbutton.h" #include "joysensordirection.h" -JoyAccelerometerButton::JoyAccelerometerButton(JoySensor *sensor, int index, int originset, SetJoystick *parentSet, - QObject *parent) - : JoySensorButton(sensor, index, originset, parentSet, parent) +JoyAccelerometerButton::JoyAccelerometerButton(JoySensor *sensor, int sdl_button_index, int originset, + SetJoystick *parentSet, QObject *parent) + : JoySensorButton(sensor, sdl_button_index, originset, parentSet, parent) { } @@ -32,7 +32,7 @@ QString JoyAccelerometerButton::getDirectionName() const { QString label = QString(); - switch (m_index) + switch (m_index_sdl) { case JoySensorDirection::SENSOR_UP: label.append(tr("Up")); diff --git a/src/joybuttontypes/joyaccelerometerbutton.h b/src/joybuttontypes/joyaccelerometerbutton.h index d77b0a071..6a7ced9ae 100644 --- a/src/joybuttontypes/joyaccelerometerbutton.h +++ b/src/joybuttontypes/joyaccelerometerbutton.h @@ -26,7 +26,8 @@ class JoyAccelerometerButton : public JoySensorButton Q_OBJECT public: - explicit JoyAccelerometerButton(JoySensor *sensor, int index, int originset, SetJoystick *parentSet, QObject *parent); + explicit JoyAccelerometerButton(JoySensor *sensor, int sdl_button_index, int originset, SetJoystick *parentSet, + QObject *parent); virtual QString getDirectionName() const override; }; diff --git a/src/joybuttontypes/joyaxisbutton.cpp b/src/joybuttontypes/joyaxisbutton.cpp index 7499977d5..9d045cb61 100644 --- a/src/joybuttontypes/joyaxisbutton.cpp +++ b/src/joybuttontypes/joyaxisbutton.cpp @@ -60,7 +60,7 @@ QString JoyAxisButton::getPartialName(bool forceFullFormat, bool displayNames) c { QString buttontype = QString(); - switch (m_index) + switch (m_index_sdl) { case 0: buttontype = tr("Negative"); @@ -92,11 +92,11 @@ void JoyAxisButton::setChangeSetCondition(SetChangeCondition condition, bool pas if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay)) { // Set new condition - emit setAssignmentChanged(m_index, m_axis->getIndex(), setSelection, condition); + emit setAssignmentChanged(m_index_sdl, m_axis->getIndex(), setSelection, condition); } else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay)) { // Remove old condition - emit setAssignmentChanged(m_index, m_axis->getIndex(), setSelection, SetChangeDisabled); + emit setAssignmentChanged(m_index_sdl, m_axis->getIndex(), setSelection, SetChangeDisabled); } setSelectionCondition = condition; diff --git a/src/joybuttontypes/joycontrolstickbutton.cpp b/src/joybuttontypes/joycontrolstickbutton.cpp index 0940987a8..7d4bc89f0 100644 --- a/src/joybuttontypes/joycontrolstickbutton.cpp +++ b/src/joybuttontypes/joycontrolstickbutton.cpp @@ -47,7 +47,7 @@ QString JoyControlStickButton::getDirectionName() const { QString label = QString(); - switch (m_index) + switch (m_index_sdl) { case 1: label.append(tr("Up")); @@ -141,11 +141,11 @@ void JoyControlStickButton::setChangeSetCondition(SetChangeCondition condition, if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay)) { // Set new condition - emit setAssignmentChanged(m_index, this->stick->getIndex(), setSelection, condition); + emit setAssignmentChanged(m_index_sdl, this->stick->getIndex(), setSelection, condition); } else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay)) { // Remove old condition - emit setAssignmentChanged(m_index, this->stick->getIndex(), setSelection, SetChangeDisabled); + emit setAssignmentChanged(m_index_sdl, this->stick->getIndex(), setSelection, SetChangeDisabled); } setSelectionCondition = condition; @@ -166,11 +166,11 @@ void JoyControlStickButton::setChangeSetCondition(SetChangeCondition condition, } } -int JoyControlStickButton::getRealJoyNumber() const { return m_index; } +int JoyControlStickButton::getRealJoyNumber() const { return m_index_sdl; } JoyStickDirectionsType::JoyStickDirections JoyControlStickButton::getDirection() const { - return static_cast(m_index); + return static_cast(m_index_sdl); } /** @@ -249,18 +249,18 @@ double JoyControlStickButton::getCurrentSpringDeadCircle() { double result = (springDeadCircleMultiplier * 0.01); - if ((m_index == static_cast(JoyControlStick::StickLeft)) || - (m_index == static_cast(JoyControlStick::StickRight))) + if ((m_index_sdl == static_cast(JoyControlStick::StickLeft)) || + (m_index_sdl == static_cast(JoyControlStick::StickRight))) { result = stick->getSpringDeadCircleX() * (springDeadCircleMultiplier * 0.01); - } else if ((m_index == static_cast(JoyControlStick::StickUp)) || - (m_index == static_cast(JoyControlStick::StickDown))) + } else if ((m_index_sdl == static_cast(JoyControlStick::StickUp)) || + (m_index_sdl == static_cast(JoyControlStick::StickDown))) { result = stick->getSpringDeadCircleY() * (springDeadCircleMultiplier * 0.01); - } else if ((m_index == static_cast(JoyControlStick::StickRightUp)) || - (m_index == static_cast(JoyControlStick::StickRightDown)) || - (m_index == static_cast(JoyControlStick::StickLeftDown)) || - (m_index == static_cast(JoyControlStick::StickLeftUp))) + } else if ((m_index_sdl == static_cast(JoyControlStick::StickRightUp)) || + (m_index_sdl == static_cast(JoyControlStick::StickRightDown)) || + (m_index_sdl == static_cast(JoyControlStick::StickLeftDown)) || + (m_index_sdl == static_cast(JoyControlStick::StickLeftUp))) { result = 0.0; } diff --git a/src/joybuttontypes/joydpadbutton.cpp b/src/joybuttontypes/joydpadbutton.cpp index 7df79b16f..514e930ee 100644 --- a/src/joybuttontypes/joydpadbutton.cpp +++ b/src/joybuttontypes/joydpadbutton.cpp @@ -77,7 +77,7 @@ QString JoyDPadButton::getDirectionName() const QString JoyDPadButton::getXmlName() { return GlobalVariables::JoyDPadButton::xmlName; } -int JoyDPadButton::getRealJoyNumber() const { return m_index; } +int JoyDPadButton::getRealJoyNumber() const { return m_index_sdl; } QString JoyDPadButton::getPartialName(bool forceFullFormat, bool displayNames) const { @@ -126,11 +126,11 @@ void JoyDPadButton::setChangeSetCondition(SetChangeCondition condition, bool pas if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay)) { // Set new condition - emit setAssignmentChanged(m_index, m_dpad->getJoyNumber(), setSelection, condition); + emit setAssignmentChanged(m_index_sdl, m_dpad->getJoyNumber(), setSelection, condition); } else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay)) { // Remove old condition - emit setAssignmentChanged(m_index, m_dpad->getJoyNumber(), setSelection, SetChangeDisabled); + emit setAssignmentChanged(m_index_sdl, m_dpad->getJoyNumber(), setSelection, SetChangeDisabled); } setSelectionCondition = condition; diff --git a/src/joybuttontypes/joygradientbutton.cpp b/src/joybuttontypes/joygradientbutton.cpp index ba506e977..48d66d343 100644 --- a/src/joybuttontypes/joygradientbutton.cpp +++ b/src/joybuttontypes/joygradientbutton.cpp @@ -25,8 +25,8 @@ #include -JoyGradientButton::JoyGradientButton(int index, int originset, SetJoystick *parentSet, QObject *parent) - : JoyButton(index, originset, parentSet, parent) +JoyGradientButton::JoyGradientButton(int sdl_button_index, int originset, SetJoystick *parentSet, QObject *parent) + : JoyButton(sdl_button_index, originset, parentSet, parent) { } diff --git a/src/joybuttontypes/joygradientbutton.h b/src/joybuttontypes/joygradientbutton.h index 480f1502d..882817e88 100644 --- a/src/joybuttontypes/joygradientbutton.h +++ b/src/joybuttontypes/joygradientbutton.h @@ -28,7 +28,7 @@ class JoyGradientButton : public JoyButton Q_OBJECT public: - explicit JoyGradientButton(int index, int originset, SetJoystick *parentSet, QObject *parent); + explicit JoyGradientButton(int sdl_button_index, int originset, SetJoystick *parentSet, QObject *parent); using JoyButton::getPartialName; using JoyButton::setChangeSetCondition; diff --git a/src/joybuttontypes/joygyroscopebutton.cpp b/src/joybuttontypes/joygyroscopebutton.cpp index b058c0180..68a5527eb 100644 --- a/src/joybuttontypes/joygyroscopebutton.cpp +++ b/src/joybuttontypes/joygyroscopebutton.cpp @@ -31,7 +31,7 @@ QString JoyGyroscopeButton::getDirectionName() const { QString label = QString(); - switch (m_index) + switch (m_index_sdl) { case JoySensorDirection::SENSOR_UP: label.append(tr("Pitch Up")); diff --git a/src/joybuttontypes/joysensorbutton.cpp b/src/joybuttontypes/joysensorbutton.cpp index 5625b569d..bca23269f 100644 --- a/src/joybuttontypes/joysensorbutton.cpp +++ b/src/joybuttontypes/joysensorbutton.cpp @@ -40,7 +40,7 @@ JoySensorButton::JoySensorButton(JoySensor *sensor, int index, int originset, Se * @brief Get a 0 indexed number of button * @return 0 indexed button index number */ -int JoySensorButton::getRealJoyNumber() const { return m_index; } +int JoySensorButton::getRealJoyNumber() const { return m_index_sdl; } /** * @brief Get the name of the button. @@ -82,7 +82,7 @@ QString JoySensorButton::getXmlName() { return GlobalVariables::JoySensorButton: */ double JoySensorButton::getDistanceFromDeadZone() { - return m_sensor->calculateDirectionalDistance(static_cast(m_index)); + return m_sensor->calculateDirectionalDistance(static_cast(m_index_sdl)); } /** @@ -91,7 +91,7 @@ double JoySensorButton::getDistanceFromDeadZone() */ double JoySensorButton::getMouseDistanceFromDeadZone() { - return m_sensor->calculateDirectionalDistance(static_cast(m_index)); + return m_sensor->calculateDirectionalDistance(static_cast(m_index_sdl)); } void JoySensorButton::setChangeSetCondition(SetChangeCondition condition, bool passive, bool updateActiveString) @@ -104,12 +104,12 @@ void JoySensorButton::setChangeSetCondition(SetChangeCondition condition, bool p if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay)) { // Set new condition - emit setAssignmentChanged(static_cast(m_index), m_sensor->getType(), setSelection, + emit setAssignmentChanged(static_cast(m_index_sdl), m_sensor->getType(), setSelection, condition); } else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay)) { // Remove old condition - emit setAssignmentChanged(static_cast(m_index), m_sensor->getType(), setSelection, + emit setAssignmentChanged(static_cast(m_index_sdl), m_sensor->getType(), setSelection, SetChangeDisabled); } @@ -154,4 +154,4 @@ JoySensor *JoySensorButton::getSensor() const { return m_sensor; } /** * @brief returns the direction of this button. */ -JoySensorDirection JoySensorButton::getDirection() const { return static_cast(m_index); } +JoySensorDirection JoySensorButton::getDirection() const { return static_cast(m_index_sdl); }