diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,7 +94,7 @@ endif() remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) - +add_definitions(-DQT_NO_FOREACH) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() diff --git a/src/knotificationmanager.cpp b/src/knotificationmanager.cpp --- a/src/knotificationmanager.cpp +++ b/src/knotificationmanager.cpp @@ -207,7 +207,7 @@ }, this); - Q_FOREACH (QObject *pluginObj, plugins) { + for (QObject *pluginObj : qAsConst(plugins)) { KNotificationPlugin *notifyPlugin = qobject_cast(pluginObj); if (notifyPlugin) { @@ -280,7 +280,8 @@ KNotifyConfig notifyConfig(n->appName(), n->contexts(), n->eventId()); QString notifyActions = notifyConfig.readEntry(QStringLiteral("Action")); - Q_FOREACH (const QString &action, notifyActions.split(QLatin1Char('|'))) { + const auto listActions = notifyActions.split(QLatin1Char('|')); + for (const QString &action : listActions) { if (!d->notifyPlugins.contains(action)) { qCDebug(LOG_KNOTIFICATIONS) << "No plugin for action" << action; continue; @@ -311,7 +312,8 @@ d->notifications.insert(d->notifyIdCounter, n); - Q_FOREACH (const QString &action, notifyActions.split(QLatin1Char('|'))) { + const auto actionsList = notifyActions.split(QLatin1Char('|')); + for (const QString &action : actionsList) { KNotificationPlugin *notifyPlugin = pluginForAction(action); if (!notifyPlugin) { @@ -332,7 +334,7 @@ { KNotifyConfig notifyConfig(n->appName(), n->contexts(), n->eventId()); - Q_FOREACH (KNotificationPlugin *p, d->notifyPlugins) { + for (KNotificationPlugin *p : qAsConst(d->notifyPlugins)) { p->update(n, ¬ifyConfig); } } diff --git a/src/knotifyconfig.cpp b/src/knotifyconfig.cpp --- a/src/knotifyconfig.cpp +++ b/src/knotifyconfig.cpp @@ -50,7 +50,8 @@ void KNotifyConfig::reparseConfiguration() { QCache &cache = *static_cache; - Q_FOREACH (const QString &filename, cache.keys()) { + const auto listFiles = cache.keys(); + for (const QString &filename : listFiles) { (*cache[filename])->reparseConfiguration(); } } @@ -95,9 +96,7 @@ QString KNotifyConfig::readEntry(const QString &entry, bool path) { - QPair context; - - Q_FOREACH (context, contexts) { + for (const QPair &context : qAsConst(contexts)) { const QString group = QStringLiteral("Event/") + eventid + QLatin1Char('/') + context.first + QLatin1Char('/') + context.second; if (configfile->hasGroup(group)) { diff --git a/src/kpassivepopup.cpp b/src/kpassivepopup.cpp --- a/src/kpassivepopup.cpp +++ b/src/kpassivepopup.cpp @@ -235,8 +235,8 @@ QRect desktopRectForPoint(const QPoint &point) { - QList screens = QGuiApplication::screens(); - Q_FOREACH(const QScreen *screen, screens) { + const QList screens = QGuiApplication::screens(); + for(const QScreen *screen : screens) { if (screen->geometry().contains(point)) { return screen->geometry(); } diff --git a/src/kstatusnotifieritem.cpp b/src/kstatusnotifieritem.cpp --- a/src/kstatusnotifieritem.cpp +++ b/src/kstatusnotifieritem.cpp @@ -1134,7 +1134,8 @@ QPixmap iconPixmap; //if an icon exactly that size wasn't found don't add it to the vector - foreach (QSize size, icon.availableSizes()) { + const auto lstSizes = icon.availableSizes(); + for (QSize size : lstSizes) { iconPixmap = icon.pixmap(size); iconVector.append(imageToStruct(iconPixmap.toImage())); } diff --git a/src/notifybypopup.cpp b/src/notifybypopup.cpp --- a/src/notifybypopup.cpp +++ b/src/notifybypopup.cpp @@ -203,7 +203,7 @@ NotifyByPopup::~NotifyByPopup() { - Q_FOREACH (KPassivePopup *p, d->passivePopups) { + for (KPassivePopup *p : qAsConst(d->passivePopups)) { p->deleteLater(); } @@ -333,7 +333,7 @@ QRect screen = QGuiApplication::primaryScreen()->availableGeometry(); d->nextPosition = screen.top(); - Q_FOREACH (KPassivePopup *popup, d->passivePopups) + for (KPassivePopup *popup : qAsConst(d->passivePopups)) { int y = popup->pos().y(); if (y > d->nextPosition) { @@ -420,8 +420,10 @@ emit finished(n); } } - Q_FOREACH (KNotification *n, d->passivePopups.keys()) { - emit finished(n); + QMap::const_iterator i = d->passivePopups.constBegin(); + while (i != d->passivePopups.constEnd()) { + emit finished(i.key()); + ++i; } d->galagoNotifications.clear(); d->passivePopups.clear(); @@ -595,7 +597,8 @@ if (!notification->actions().isEmpty()) { QString linkCode = QStringLiteral("

"); int i = 0; - Q_FOREACH (const QString &it, notification->actions()) { + const auto actionList = notification->actions(); + for (const QString &it : actionList) { i++; linkCode += QStringLiteral(" %3").arg(QString::number(notification->id()), QString::number(i), it.toHtmlEscaped()); } @@ -671,7 +674,8 @@ actionList.append(defaultAction); } int actId = 0; - Q_FOREACH (const QString &actionName, notification->actions()) { + const auto listActions = notification->actions(); + for (const QString &actionName : listActions) { actId++; actionList.append(QString::number(actId)); actionList.append(actionName); diff --git a/src/notifybyportal.cpp b/src/notifybyportal.cpp --- a/src/notifybyportal.cpp +++ b/src/notifybyportal.cpp @@ -178,7 +178,7 @@ { Q_UNUSED(serviceName); // close all notifications we currently hold reference to - Q_FOREACH (KNotification *n, d->portalNotifications) { + for (KNotification *n : qAsConst(d->portalNotifications)) { if (n) { emit finished(n); } @@ -268,7 +268,8 @@ buttons.reserve(notification->actions().count()); int actId = 0; - Q_FOREACH (const QString &actionName, notification->actions()) { + const auto listActions = notification->actions(); + for (const QString &actionName : listActions) { actId++; QVariantMap button = { {QStringLiteral("action"), QString::number(actId)}, diff --git a/tests/knotificationdbustest.cpp b/tests/knotificationdbustest.cpp --- a/tests/knotificationdbustest.cpp +++ b/tests/knotificationdbustest.cpp @@ -40,7 +40,7 @@ QStringList actionList; int actId = 0; - Q_FOREACH (const QString &actionName, actions) { + for (const QString &actionName : actions) { actId++; actionList.append(QString::number(actId)); actionList.append(actionName);