From ea3666cb7a2d4e4aae810b00d7cb3bd24170e5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Tue, 9 Apr 2024 16:21:48 +0200 Subject: [PATCH 1/2] refactor: Replace depracated QRegExp with QRegularExpression --- src/common.cpp | 13 +++++++------ src/gamecontroller/gamecontroller.cpp | 4 ++-- src/globalvariables.cpp | 4 ++-- src/globalvariables.h | 6 +++--- src/joystick.cpp | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 1d780afd6..58654aa2d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -24,7 +24,8 @@ #include #include #include -#include +#include + #ifdef Q_OS_WIN #include #endif @@ -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); @@ -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; } @@ -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(); diff --git a/src/gamecontroller/gamecontroller.cpp b/src/gamecontroller/gamecontroller.cpp index 3cc7877e9..27cebf8de 100644 --- a/src/gamecontroller/gamecontroller.cpp +++ b/src/gamecontroller/gamecontroller.cpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include @@ -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; diff --git a/src/globalvariables.cpp b/src/globalvariables.cpp index 76b7cd9df..fc71f60e3 100644 --- a/src/globalvariables.cpp +++ b/src/globalvariables.cpp @@ -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 ---- // diff --git a/src/globalvariables.h b/src/globalvariables.h index 23cd1779a..722c4dc66 100644 --- a/src/globalvariables.h +++ b/src/globalvariables.h @@ -21,7 +21,7 @@ #include #include -#include +#include namespace GlobalVariables { class JoyButton @@ -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 diff --git a/src/joystick.cpp b/src/joystick.cpp index d111b3176..32a69d685 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -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 From b442edd833de0edd3147133e6b0deeea7ea59eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Tue, 9 Apr 2024 16:41:25 +0200 Subject: [PATCH 2/2] refactor: Replaced some iterators based loops with range-based ones --- src/autoprofilewatcher.cpp | 65 +++++++++--------------------------- src/joybuttonmousehelper.cpp | 4 +-- src/sdleventreader.cpp | 5 +-- 3 files changed, 18 insertions(+), 56 deletions(-) diff --git a/src/autoprofilewatcher.cpp b/src/autoprofilewatcher.cpp index 6c0fe4d3d..7b311c5bb 100644 --- a/src/autoprofilewatcher.cpp +++ b/src/autoprofilewatcher.cpp @@ -26,9 +26,6 @@ #include #include #include -#include -#include -#include #if defined(Q_OS_UNIX) && defined(WITH_X11) #include "x11extras.h" @@ -213,11 +210,8 @@ void AutoProfileWatcher::runAppCheck() bool hasOnePartName = false; - QListIterator iterList(iter.value()); - while (iterList.hasNext()) + for (auto autoInfo : iter.value()) { - AutoProfileInfo *autoInfo = iterList.next(); - if (autoInfo->isPartialState()) { hasOnePartName = true; @@ -275,10 +269,8 @@ void AutoProfileWatcher::runAppCheck() QHash highestMatchCount; QHash highestMatches; - QSetIterator fullSetIter(fullSet); - while (fullSetIter.hasNext()) + for (auto &&info : fullSet) { - AutoProfileInfo *info = fullSetIter.next(); if (info->isActive()) { int numProps = 0; @@ -317,11 +309,8 @@ void AutoProfileWatcher::runAppCheck() } } - QHashIterator highIter(highestMatches); - - while (highIter.hasNext()) + for (auto &&info : highestMatches) { - AutoProfileInfo *info = highIter.next().value(); getUniqeIDSetLocal().insert(info->getUniqueID()); emit foundApplicableProfile(info); } @@ -333,13 +322,8 @@ void AutoProfileWatcher::runAppCheck() emit foundApplicableProfile(allDefaultInfo); } - QHashIterator 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); @@ -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(); @@ -529,53 +510,42 @@ void AutoProfileWatcher::syncProfileAssignment() void AutoProfileWatcher::clearProfileAssignments() { QSet terminateProfiles; - QListIterator> iterDelete(appProfileAssignments.values()); - while (iterDelete.hasNext()) + for (const auto &profileList : appProfileAssignments.values()) { - QList templist = iterDelete.next(); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - terminateProfiles.unite(QSet(templist.begin(), templist.end())); + terminateProfiles.unite(QSet(profileList.begin(), profileList.end())); #else - terminateProfiles.unite(templist.toSet()); + terminateProfiles.unite(profileList.toSet()); #endif } appProfileAssignments.clear(); - QListIterator> iterClassDelete(windowClassProfileAssignments.values()); - - while (iterClassDelete.hasNext()) + for (const auto &profileList : windowClassProfileAssignments.values()) { - QList templist = iterClassDelete.next(); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - terminateProfiles.unite(QSet(templist.begin(), templist.end())); + terminateProfiles.unite(QSet(profileList.begin(), profileList.end())); #else - terminateProfiles.unite(templist.toSet()); + terminateProfiles.unite(profileList.toSet()); #endif } windowClassProfileAssignments.clear(); - QListIterator> iterNameDelete(windowNameProfileAssignments.values()); - - while (iterNameDelete.hasNext()) + for (const auto &profileList : windowNameProfileAssignments.values()) { - QList templist = iterNameDelete.next(); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - terminateProfiles.unite(QSet(templist.begin(), templist.end())); + terminateProfiles.unite(QSet(profileList.begin(), profileList.end())); #else - terminateProfiles.unite(templist.toSet()); + terminateProfiles.unite(profileList.toSet()); #endif } windowNameProfileAssignments.clear(); - QSetIterator iterTerminate(terminateProfiles); - - while (iterTerminate.hasNext()) + for (auto *info : terminateProfiles) { - AutoProfileInfo *info = iterTerminate.next(); if (info != nullptr) { info->deleteLater(); @@ -583,11 +553,8 @@ void AutoProfileWatcher::clearProfileAssignments() } } - QListIterator iterDefaultsDelete(getDefaultProfileAssignments().values()); - - while (iterDefaultsDelete.hasNext()) + for (auto *info : getDefaultProfileAssignments().values()) { - AutoProfileInfo *info = iterDefaultsDelete.next(); if (info != nullptr) { info->deleteLater(); diff --git a/src/joybuttonmousehelper.cpp b/src/joybuttonmousehelper.cpp index c3aef2cf6..d2199df14 100644 --- a/src/joybuttonmousehelper.cpp +++ b/src/joybuttonmousehelper.cpp @@ -100,11 +100,9 @@ void JoyButtonMouseHelper::mouseEvent() void JoyButtonMouseHelper::resetButtonMouseDistances() { QList *buttonList = JoyButton::getPendingMouseButtons(); - QListIterator iter(*buttonList); - while (iter.hasNext()) + for (JoyButton *temp : *buttonList) { - JoyButton *temp = iter.next(); temp->resetAccelerationDistances(); } } diff --git a/src/sdleventreader.cpp b/src/sdleventreader.cpp index a5cb85e61..66116cd5f 100644 --- a/src/sdleventreader.cpp +++ b/src/sdleventreader.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include SDLEventReader::SDLEventReader(QMap *joysticks, AntiMicroSettings *settings, QObject *parent) @@ -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())