Skip to content

Commit

Permalink
Limit how often active zone string is generated when loading a profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Sep 15, 2015
1 parent f70f321 commit 8cb1ecd
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/joyaxiswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ JoyAxisWidget::JoyAxisWidget(JoyAxis *axis, bool displayNames, QWidget *parent)
connect(axis, SIGNAL(throttleChanged()), this, SLOT(refreshLabel()));
connect(axis, SIGNAL(axisNameChanged()), this, SLOT(refreshLabel()));

connect(nAxisButton, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
connect(pAxisButton, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//connect(nAxisButton, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//connect(pAxisButton, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
connect(nAxisButton, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
connect(pAxisButton, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
connect(nAxisButton, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()), Qt::QueuedConnection);
connect(pAxisButton, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()), Qt::QueuedConnection);
connect(nAxisButton, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()));
connect(pAxisButton, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()));

axis->establishPropertyUpdatedConnection();
nAxisButton->establishPropertyUpdatedConnections();
Expand Down
62 changes: 45 additions & 17 deletions src/joybutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,10 @@ void JoyButton::readConfig(QXmlStreamReader *xml)
{
xml->skipCurrentElement();
}
else
{
buildActiveZoneSummaryString();
}

xml->readNextStartElement();
}
Expand Down Expand Up @@ -1992,7 +1996,7 @@ bool JoyButton::readButtonConfig(QXmlStreamReader *xml)
bool validSlot = buttonslot->isValidSlot();
if (validSlot)
{
bool inserted = insertAssignedSlot(buttonslot);
bool inserted = insertAssignedSlot(buttonslot, false);
if (!inserted)
{
delete buttonslot;
Expand Down Expand Up @@ -2022,7 +2026,7 @@ bool JoyButton::readButtonConfig(QXmlStreamReader *xml)
int tempchoice = temptext.toInt();
if (tempchoice >= 0 && tempchoice <= InputDevice::NUMBER_JOYSETS)
{
this->setChangeSetSelection(tempchoice - 1);
this->setChangeSetSelection(tempchoice - 1, false);
}
}
}
Expand All @@ -2048,7 +2052,7 @@ bool JoyButton::readButtonConfig(QXmlStreamReader *xml)

if (tempcondition != SetChangeDisabled)
{
this->setChangeSetCondition(tempcondition);
this->setChangeSetCondition(tempcondition, false, false);
}
}
}
Expand Down Expand Up @@ -2479,6 +2483,11 @@ QString JoyButton::buildActiveZoneSummary(QList<JoyButtonSlot *> &tempList)
iter.toBack();
break;
}
case JoyButtonSlot::JoyCycle:
{
iter.toBack();
break;
}
}

if (i > 4 && iter.hasNext())
Expand All @@ -2505,21 +2514,20 @@ QList<JoyButtonSlot*> JoyButton::getActiveZoneList()

QListIterator<JoyButtonSlot*> *iter = 0;
QReadWriteLock *tempLock = 0;
//bool slotsActive = !activeSlots.isEmpty();
if (getButtonState())
{
//tempLocker = new QReadLocker(&activeZoneLock);
tempLock = &activeZoneLock;
iter = &activeSlotsIter;
}
else
{
//tempLocker = new QReadLocker(&assignmentsLock);
tempLock = &assignmentsLock;
iter = &assignmentsIter;
}

QReadLocker tempLocker(tempLock);
Q_UNUSED(tempLocker);

if (tempLock == &assignmentsLock)
{
if (previousCycle)
Expand Down Expand Up @@ -2569,13 +2577,15 @@ QList<JoyButtonSlot*> JoyButton::getActiveZoneList()
iter->toBack();
break;
}
case JoyButtonSlot::JoyCycle:
{
iter->toBack();
break;
}
}
}
}

//delete tempLocker;
//tempLocker = 0;

return tempSlotList;
}

Expand Down Expand Up @@ -2858,7 +2868,7 @@ bool JoyButton::insertAssignedSlot(int code, unsigned int alias, int index,
checkTurboCondition(slot);
assignmentsLock.unlock();

localBuildActiveZoneSummaryString();
buildActiveZoneSummaryString();

emit slotsChanged();
}
Expand All @@ -2874,7 +2884,7 @@ bool JoyButton::insertAssignedSlot(int code, unsigned int alias, int index,
return permitSlot;
}

bool JoyButton::insertAssignedSlot(JoyButtonSlot *newSlot)
bool JoyButton::insertAssignedSlot(JoyButtonSlot *newSlot, bool updateActiveString)
{
bool permitSlot = false;

Expand Down Expand Up @@ -2915,7 +2925,11 @@ bool JoyButton::insertAssignedSlot(JoyButtonSlot *newSlot)
assignments.append(newSlot);
assignmentsLock.unlock();

localBuildActiveZoneSummaryString();
if (updateActiveString)
{
buildActiveZoneSummaryString();
}


emit slotsChanged();
}
Expand Down Expand Up @@ -2985,7 +2999,7 @@ bool JoyButton::setAssignedSlot(JoyButtonSlot *otherSlot, int index)

assignmentsLock.unlock();

localBuildActiveZoneSummaryString();
buildActiveZoneSummaryString();

emit slotsChanged();
}
Expand Down Expand Up @@ -3032,11 +3046,17 @@ int JoyButton::getMouseSpeedY()
return mouseSpeedY;
}

void JoyButton::setChangeSetSelection(int index)
void JoyButton::setChangeSetSelection(int index, bool updateActiveString)
{
if (index >= -1 && index <= 7)
{
setSelection = index;

if (updateActiveString)
{
buildActiveZoneSummaryString();
}

emit propertyUpdated();
}
}
Expand All @@ -3046,7 +3066,8 @@ int JoyButton::getSetSelection()
return setSelection;
}

void JoyButton::setChangeSetCondition(SetChangeCondition condition, bool passive)
void JoyButton::setChangeSetCondition(SetChangeCondition condition,
bool passive, bool updateActiveString)
{
SetChangeCondition oldCondition = setSelectionCondition;

Expand Down Expand Up @@ -3077,6 +3098,11 @@ void JoyButton::setChangeSetCondition(SetChangeCondition condition, bool passive

if (setSelectionCondition != oldCondition)
{
if (updateActiveString)
{
buildActiveZoneSummaryString();
}

emit propertyUpdated();
}
}
Expand Down Expand Up @@ -3732,7 +3758,7 @@ void JoyButton::removeAssignedSlot(int index)

tempAssignLocker.unlock();

localBuildActiveZoneSummaryString();
buildActiveZoneSummaryString();
emit slotsChanged();
}
}
Expand Down Expand Up @@ -5144,7 +5170,7 @@ void JoyButton::copyAssignments(JoyButton *destButton)
{
JoyButtonSlot *slot = iter.next();
JoyButtonSlot *newslot = new JoyButtonSlot(slot, destButton);
destButton->insertAssignedSlot(newslot);
destButton->insertAssignedSlot(newslot, false);
}

destButton->toggle = toggle;
Expand Down Expand Up @@ -5175,6 +5201,8 @@ void JoyButton::copyAssignments(JoyButton *destButton)
destButton->startAccelMultiplier = startAccelMultiplier;
destButton->springDeadCircleMultiplier = springDeadCircleMultiplier;
destButton->extraAccelCurve = extraAccelCurve;

buildActiveZoneSummaryString();
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/joybutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ class JoyButton : public QObject
int getWheelSpeedX();
int getWheelSpeedY();

void setChangeSetSelection(int index);
void setChangeSetSelection(int index, bool updateActiveString=true);
int getSetSelection();

virtual void setChangeSetCondition(SetChangeCondition condition, bool passive=false);
virtual void setChangeSetCondition(SetChangeCondition condition,
bool passive=false, bool updateActiveString=true);
SetChangeCondition getChangeSetCondition();

bool getButtonState();
Expand Down Expand Up @@ -292,7 +293,7 @@ class JoyButton : public QObject
void findHoldEventEnd();
bool checkForDelaySequence();
void checkForPressedSetChange();
bool insertAssignedSlot(JoyButtonSlot *newSlot);
bool insertAssignedSlot(JoyButtonSlot *newSlot, bool updateActiveString=true);
unsigned int getPreferredKeyPressTime();
void checkTurboCondition(JoyButtonSlot *slot);
static bool hasFutureSpringEvents();
Expand All @@ -302,6 +303,7 @@ class JoyButton : public QObject
JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard);

QString buildActiveZoneSummary(QList<JoyButtonSlot*> &tempList);
void localBuildActiveZoneSummaryString();

virtual bool readButtonConfig(QXmlStreamReader *xml);

Expand Down Expand Up @@ -567,6 +569,7 @@ protected slots:
virtual void wheelEventHorizontal();
void createDeskEvent();
void releaseDeskEvent(bool skipsetchange=false);
void buildActiveZoneSummaryString();

private slots:
void releaseActiveSlots();
Expand All @@ -580,8 +583,6 @@ private slots:
void checkForSetChange();
void keyPressEvent();
void slotSetChange();
void buildActiveZoneSummaryString();
void localBuildActiveZoneSummaryString();
};


Expand Down
6 changes: 6 additions & 0 deletions src/joybuttontypes/joyaxisbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void JoyAxisButton::setChangeSetCondition(SetChangeCondition condition, bool pas
{
emit propertyUpdated();
}

if (setSelectionCondition != oldCondition)
{
buildActiveZoneSummaryString();
emit propertyUpdated();
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/joybuttontypes/joycontrolstickbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ double JoyControlStickButton::getMouseDistanceFromDeadZone()

void JoyControlStickButton::setChangeSetCondition(SetChangeCondition condition, bool passive)
{
SetChangeCondition oldCondition = setSelectionCondition;

if (condition != setSelectionCondition && !passive)
{
if (condition == SetChangeWhileHeld || condition == SetChangeTwoWay)
Expand All @@ -158,6 +160,12 @@ void JoyControlStickButton::setChangeSetCondition(SetChangeCondition condition,
{
setChangeSetSelection(-1);
}

if (setSelectionCondition != oldCondition)
{
buildActiveZoneSummaryString();
emit propertyUpdated();
}
}

int JoyControlStickButton::getRealJoyNumber()
Expand Down
10 changes: 8 additions & 2 deletions src/joybuttontypes/joydpadbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ void JoyDPadButton::reset(int index)

void JoyDPadButton::setChangeSetCondition(SetChangeCondition condition, bool passive)
{
SetChangeCondition oldCondition = setSelectionCondition;

if (condition != setSelectionCondition && !passive)
{
if (condition == SetChangeWhileHeld || condition == SetChangeTwoWay)
{
// Set new condition
emit setAssignmentChanged(index, this->dpad->getJoyNumber(), setSelection, condition);
//emit setAssignmentChanged(index, setSelection, condition);
}
else if (setSelectionCondition == SetChangeWhileHeld || setSelectionCondition == SetChangeTwoWay)
{
// Remove old condition
emit setAssignmentChanged(index, this->dpad->getJoyNumber(), setSelection, SetChangeDisabled);
//emit setAssignmentChanged(index, setSelection, SetChangeDisabled);
}

setSelectionCondition = condition;
Expand All @@ -145,6 +145,12 @@ void JoyDPadButton::setChangeSetCondition(SetChangeCondition condition, bool pas
{
setChangeSetSelection(-1);
}

if (setSelectionCondition != oldCondition)
{
buildActiveZoneSummaryString();
emit propertyUpdated();
}
}

JoyDPad* JoyDPadButton::getDPad()
Expand Down
4 changes: 2 additions & 2 deletions src/joybuttonwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ JoyButtonWidget::JoyButtonWidget(JoyButton *button, bool displayNames, QWidget *
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));

connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()), Qt::QueuedConnection);
connect(button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()));
}

JoyButton* JoyButtonWidget::getJoyButton()
Expand Down
8 changes: 4 additions & 4 deletions src/joycontrolstickbuttonpushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ JoyControlStickButtonPushButton::JoyControlStickButtonPushButton(JoyControlStick
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));

connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()), Qt::QueuedConnection);
connect(button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()));
connect(button->getStick()->getModifierButton(), SIGNAL(activeZoneChanged()),
this, SLOT(refreshLabel()));
}
Expand All @@ -51,15 +51,15 @@ void JoyControlStickButtonPushButton::setButton(JoyControlStickButton *button)
disableFlashes();
if (this->button)
{
disconnect(this->button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//disconnect(this->button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
disconnect(button, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
disconnect(this->button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()));
}

this->button = button;
refreshLabel();
enableFlashes();
connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
//connect(button, SIGNAL(slotsChanged()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(propertyUpdated()), this, SLOT(refreshLabel()));
connect(button, SIGNAL(activeZoneChanged()), this, SLOT(refreshLabel()), Qt::QueuedConnection);
}
Expand Down

0 comments on commit 8cb1ecd

Please sign in to comment.