Skip to content

Commit

Permalink
chore: Rename index variable to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Nov 18, 2022
1 parent dc4b2fc commit 18b1915
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 55 deletions.
38 changes: 19 additions & 19 deletions src/joybutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ QList<JoyButton *> 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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2591,7 +2591,7 @@ void JoyButton::restartAllForSetChange()
isButtonPressedQueue.clear();
ignoreSetQueue.clear();

emit released(m_index);
emit released(m_index_sdl);
emit setChangeActivated(setSelection);
}

Expand Down
4 changes: 2 additions & 2 deletions src/joybutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/joybuttontypes/joyaccelerometerbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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"));
Expand Down
3 changes: 2 additions & 1 deletion src/joybuttontypes/joyaccelerometerbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
6 changes: 3 additions & 3 deletions src/joybuttontypes/joyaxisbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions src/joybuttontypes/joycontrolstickbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QString JoyControlStickButton::getDirectionName() const
{
QString label = QString();

switch (m_index)
switch (m_index_sdl)
{
case 1:
label.append(tr("Up"));
Expand Down Expand 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;
Expand All @@ -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<JoyStickDirectionsType::JoyStickDirections>(m_index);
return static_cast<JoyStickDirectionsType::JoyStickDirections>(m_index_sdl);
}

/**
Expand Down Expand Up @@ -249,18 +249,18 @@ double JoyControlStickButton::getCurrentSpringDeadCircle()
{
double result = (springDeadCircleMultiplier * 0.01);

if ((m_index == static_cast<int>(JoyControlStick::StickLeft)) ||
(m_index == static_cast<int>(JoyControlStick::StickRight)))
if ((m_index_sdl == static_cast<int>(JoyControlStick::StickLeft)) ||
(m_index_sdl == static_cast<int>(JoyControlStick::StickRight)))
{
result = stick->getSpringDeadCircleX() * (springDeadCircleMultiplier * 0.01);
} else if ((m_index == static_cast<int>(JoyControlStick::StickUp)) ||
(m_index == static_cast<int>(JoyControlStick::StickDown)))
} else if ((m_index_sdl == static_cast<int>(JoyControlStick::StickUp)) ||
(m_index_sdl == static_cast<int>(JoyControlStick::StickDown)))
{
result = stick->getSpringDeadCircleY() * (springDeadCircleMultiplier * 0.01);
} else if ((m_index == static_cast<int>(JoyControlStick::StickRightUp)) ||
(m_index == static_cast<int>(JoyControlStick::StickRightDown)) ||
(m_index == static_cast<int>(JoyControlStick::StickLeftDown)) ||
(m_index == static_cast<int>(JoyControlStick::StickLeftUp)))
} else if ((m_index_sdl == static_cast<int>(JoyControlStick::StickRightUp)) ||
(m_index_sdl == static_cast<int>(JoyControlStick::StickRightDown)) ||
(m_index_sdl == static_cast<int>(JoyControlStick::StickLeftDown)) ||
(m_index_sdl == static_cast<int>(JoyControlStick::StickLeftUp)))
{
result = 0.0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/joybuttontypes/joydpadbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/joybuttontypes/joygradientbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

#include <QDebug>

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)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/joybuttontypes/joygradientbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/joybuttontypes/joygyroscopebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
12 changes: 6 additions & 6 deletions src/joybuttontypes/joysensorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -82,7 +82,7 @@ QString JoySensorButton::getXmlName() { return GlobalVariables::JoySensorButton:
*/
double JoySensorButton::getDistanceFromDeadZone()
{
return m_sensor->calculateDirectionalDistance(static_cast<JoySensorDirection>(m_index));
return m_sensor->calculateDirectionalDistance(static_cast<JoySensorDirection>(m_index_sdl));
}

/**
Expand All @@ -91,7 +91,7 @@ double JoySensorButton::getDistanceFromDeadZone()
*/
double JoySensorButton::getMouseDistanceFromDeadZone()
{
return m_sensor->calculateDirectionalDistance(static_cast<JoySensorDirection>(m_index));
return m_sensor->calculateDirectionalDistance(static_cast<JoySensorDirection>(m_index_sdl));
}

void JoySensorButton::setChangeSetCondition(SetChangeCondition condition, bool passive, bool updateActiveString)
Expand All @@ -104,12 +104,12 @@ void JoySensorButton::setChangeSetCondition(SetChangeCondition condition, bool p
if ((condition == SetChangeWhileHeld) || (condition == SetChangeTwoWay))
{
// Set new condition
emit setAssignmentChanged(static_cast<JoySensorDirection>(m_index), m_sensor->getType(), setSelection,
emit setAssignmentChanged(static_cast<JoySensorDirection>(m_index_sdl), m_sensor->getType(), setSelection,
condition);
} else if ((setSelectionCondition == SetChangeWhileHeld) || (setSelectionCondition == SetChangeTwoWay))
{
// Remove old condition
emit setAssignmentChanged(static_cast<JoySensorDirection>(m_index), m_sensor->getType(), setSelection,
emit setAssignmentChanged(static_cast<JoySensorDirection>(m_index_sdl), m_sensor->getType(), setSelection,
SetChangeDisabled);
}

Expand Down Expand Up @@ -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<JoySensorDirection>(m_index); }
JoySensorDirection JoySensorButton::getDirection() const { return static_cast<JoySensorDirection>(m_index_sdl); }

0 comments on commit 18b1915

Please sign in to comment.