Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Refactors #948

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 16 additions & 49 deletions src/autoprofilewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QListIterator>
#include <QSetIterator>
#include <QStringListIterator>

#if defined(Q_OS_UNIX) && defined(WITH_X11)
#include "x11extras.h"
Expand Down Expand Up @@ -213,11 +210,8 @@ void AutoProfileWatcher::runAppCheck()

bool hasOnePartName = false;

QListIterator<AutoProfileInfo *> iterList(iter.value());
while (iterList.hasNext())
for (auto autoInfo : iter.value())
{
AutoProfileInfo *autoInfo = iterList.next();

if (autoInfo->isPartialState())
{
hasOnePartName = true;
Expand Down Expand Up @@ -275,10 +269,8 @@ void AutoProfileWatcher::runAppCheck()
QHash<QString, int> highestMatchCount;
QHash<QString, AutoProfileInfo *> highestMatches;

QSetIterator<AutoProfileInfo *> fullSetIter(fullSet);
while (fullSetIter.hasNext())
for (auto &&info : fullSet)
{
AutoProfileInfo *info = fullSetIter.next();
if (info->isActive())
{
int numProps = 0;
Expand Down Expand Up @@ -317,11 +309,8 @@ void AutoProfileWatcher::runAppCheck()
}
}

QHashIterator<QString, AutoProfileInfo *> highIter(highestMatches);

while (highIter.hasNext())
for (auto &&info : highestMatches)
{
AutoProfileInfo *info = highIter.next().value();
getUniqeIDSetLocal().insert(info->getUniqueID());
emit foundApplicableProfile(info);
}
Expand All @@ -333,13 +322,8 @@ void AutoProfileWatcher::runAppCheck()
emit foundApplicableProfile(allDefaultInfo);
}

QHashIterator<QString, AutoProfileInfo *> iter(getDefaultProfileAssignments());

while (iter.hasNext())
for (auto &&info : getDefaultProfileAssignments())
{
iter.next();
AutoProfileInfo *info = iter.value();

if (info->isActive() && !getUniqeIDSetLocal().contains(info->getUniqueID()))
{
emit foundApplicableProfile(info);
Expand Down Expand Up @@ -381,11 +365,8 @@ void AutoProfileWatcher::syncProfileAssignment()
}

// Handle device specific Default profile assignments
QStringListIterator iter(registeredUniques);

while (iter.hasNext())
for (auto &&tempkey : registeredUniques)
{
QString tempkey = iter.next();
QString uniqueID = QString(tempkey).replace("UniqueID", "");
QString profile = settings->value(QString("DefaultAutoProfile-%1/Profile").arg(uniqueID), "").toString();
QString active = settings->value(QString("DefaultAutoProfile-%1/Active").arg(uniqueID), "").toString();
Expand Down Expand Up @@ -529,65 +510,51 @@ void AutoProfileWatcher::syncProfileAssignment()
void AutoProfileWatcher::clearProfileAssignments()
{
QSet<AutoProfileInfo *> terminateProfiles;
QListIterator<QList<AutoProfileInfo *>> iterDelete(appProfileAssignments.values());

while (iterDelete.hasNext())
for (const auto &profileList : appProfileAssignments.values())
{
QList<AutoProfileInfo *> templist = iterDelete.next();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
terminateProfiles.unite(QSet<AutoProfileInfo *>(templist.begin(), templist.end()));
terminateProfiles.unite(QSet<AutoProfileInfo *>(profileList.begin(), profileList.end()));
#else
terminateProfiles.unite(templist.toSet());
terminateProfiles.unite(profileList.toSet());
#endif
}

appProfileAssignments.clear();

QListIterator<QList<AutoProfileInfo *>> iterClassDelete(windowClassProfileAssignments.values());

while (iterClassDelete.hasNext())
for (const auto &profileList : windowClassProfileAssignments.values())
{
QList<AutoProfileInfo *> templist = iterClassDelete.next();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
terminateProfiles.unite(QSet<AutoProfileInfo *>(templist.begin(), templist.end()));
terminateProfiles.unite(QSet<AutoProfileInfo *>(profileList.begin(), profileList.end()));
#else
terminateProfiles.unite(templist.toSet());
terminateProfiles.unite(profileList.toSet());
#endif
}

windowClassProfileAssignments.clear();

QListIterator<QList<AutoProfileInfo *>> iterNameDelete(windowNameProfileAssignments.values());

while (iterNameDelete.hasNext())
for (const auto &profileList : windowNameProfileAssignments.values())
{
QList<AutoProfileInfo *> templist = iterNameDelete.next();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
terminateProfiles.unite(QSet<AutoProfileInfo *>(templist.begin(), templist.end()));
terminateProfiles.unite(QSet<AutoProfileInfo *>(profileList.begin(), profileList.end()));
#else
terminateProfiles.unite(templist.toSet());
terminateProfiles.unite(profileList.toSet());
#endif
}

windowNameProfileAssignments.clear();

QSetIterator<AutoProfileInfo *> iterTerminate(terminateProfiles);

while (iterTerminate.hasNext())
for (auto *info : terminateProfiles)
{
AutoProfileInfo *info = iterTerminate.next();
if (info != nullptr)
{
info->deleteLater();
info = nullptr;
}
}

QListIterator<AutoProfileInfo *> iterDefaultsDelete(getDefaultProfileAssignments().values());

while (iterDefaultsDelete.hasNext())
for (auto *info : getDefaultProfileAssignments().values())
{
AutoProfileInfo *info = iterDefaultsDelete.next();
if (info != nullptr)
{
info->deleteLater();
Expand Down
13 changes: 7 additions & 6 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#include <QDirIterator>
#include <QLibraryInfo>
#include <QReadWriteLock>
#include <QRegExp>
#include <QRegularExpression>

#ifdef Q_OS_WIN
#include <QStandardPaths>
#endif
Expand Down Expand Up @@ -90,9 +91,9 @@ QStringList parseArgumentsString(QString tempString)
{
bool inside = (!tempString.isEmpty() && tempString.at(0) == QChar('"'));
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QStringList tempList = tempString.split(QRegExp("\""), Qt::SkipEmptyParts);
QStringList tempList = tempString.split(QRegularExpression("\""), Qt::SkipEmptyParts);
#else
QStringList tempList = tempString.split(QRegExp("\""), QString::SkipEmptyParts);
QStringList tempList = tempString.split(QRegularExpression("\""), QString::SkipEmptyParts);
#endif
QStringList finalList = QStringList();
QStringListIterator iter(tempList);
Expand All @@ -105,9 +106,9 @@ QStringList parseArgumentsString(QString tempString)
finalList.append(temp);
else
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
finalList.append(temp.split(QRegExp("\\s+"), Qt::SkipEmptyParts));
finalList.append(temp.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts));
#else
finalList.append(temp.split(QRegExp("\\s+"), QString::SkipEmptyParts));
finalList.append(temp.split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
#endif
inside = !inside;
}
Expand Down Expand Up @@ -179,7 +180,7 @@ QIcon loadIcon(QString name)
QDirIterator it(":images/", QDirIterator::Subdirectories);
QString fallback_location = "";
// search also for variants with underscore like document_save.png for document-save
QRegExp regex = QRegExp(".*" + name.replace(QChar('-'), "[_-]") + "\\.(svg|png)");
QRegularExpression regex = QRegularExpression(".*" + name.replace(QChar('-'), "[_-]") + "\\.(svg|png)");
while (it.hasNext())
{
QString value = it.next();
Expand Down
4 changes: 2 additions & 2 deletions src/gamecontroller/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <cmath>

#include <QDebug>
#include <QRegExp>
#include <QRegularExpression>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>

Expand Down Expand Up @@ -91,7 +91,7 @@ QString GameController::getSerialString() const
if (controller != nullptr)
{
const char *serial = SDL_GameControllerGetSerial(controller);
temp = QString(serial).remove(QRegExp("[^A-Za-z0-9]"));
temp = QString(serial).remove(QRegularExpression("[^A-Za-z0-9]"));
}
#endif
return temp;
Expand Down
4 changes: 2 additions & 2 deletions src/globalvariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ const int GlobalVariables::InputDevice::RAISEDDEADZONE = 20000;
const int GlobalVariables::InputDevice::DEFAULTKEYREPEATDELAY = 660; // 660 ms
const int GlobalVariables::InputDevice::DEFAULTKEYREPEATRATE = 40; // 40 ms. 25 times per second

// QRegExp GlobalVariables::InputDevice::emptyGUID("^[0]+$");
QRegExp GlobalVariables::InputDevice::emptyUniqueID("^[0]+$");
// QRegularExpression GlobalVariables::InputDevice::emptyGUID("^[0]+$");
QRegularExpression GlobalVariables::InputDevice::emptyUniqueID("^[0]+$");

// ---- JOYAXIS ---- //

Expand Down
6 changes: 3 additions & 3 deletions src/globalvariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <QList>
#include <QObject>
#include <QRegExp>
#include <QRegularExpression>

namespace GlobalVariables {
class JoyButton
Expand Down Expand Up @@ -107,8 +107,8 @@ class InputDevice
static const int DEFAULTKEYREPEATDELAY;
static const int DEFAULTKEYREPEATRATE;

// static QRegExp emptyGUID;
static QRegExp emptyUniqueID;
// static QRegularExpression emptyGUID;
static QRegularExpression emptyUniqueID;
};

class JoyAxis
Expand Down
4 changes: 1 addition & 3 deletions src/joybuttonmousehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ void JoyButtonMouseHelper::mouseEvent()
void JoyButtonMouseHelper::resetButtonMouseDistances()
{
QList<JoyButton *> *buttonList = JoyButton::getPendingMouseButtons();
QListIterator<JoyButton *> iter(*buttonList);

while (iter.hasNext())
for (JoyButton *temp : *buttonList)
{
JoyButton *temp = iter.next();
temp->resetAccelerationDistances();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ QString Joystick::getSerialString() const
if (m_joyhandle != nullptr)
{
const char *serial = SDL_JoystickGetSerial(m_joyhandle);
temp = QString(serial).remove(QRegExp("[^A-Za-z0-9]"));
temp = QString(serial).remove(QRegularExpression("[^A-Za-z0-9]"));
}
#endif

Expand Down
5 changes: 1 addition & 4 deletions src/sdleventreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <QDebug>
#include <QMapIterator>
#include <QSettings>
#include <QStringListIterator>
#include <QVariant>

SDLEventReader::SDLEventReader(QMap<SDL_JoystickID, InputDevice *> *joysticks, AntiMicroSettings *settings, QObject *parent)
Expand Down Expand Up @@ -77,11 +76,9 @@ void SDLEventReader::initSDL()
settings->getLock()->lock();
settings->beginGroup("Mappings");
QStringList mappings = settings->allKeys();
QStringListIterator iter(mappings);

while (iter.hasNext())
for (auto &&tempstring : mappings)
{
QString tempstring = iter.next();
QString mappingSetting = settings->value(tempstring, QString()).toString();

if (!mappingSetting.isEmpty())
Expand Down
Loading