diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,6 +69,7 @@ if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() +add_definitions(-DQT_NO_FOREACH) add_subdirectory(src) if (BUILD_TESTING) diff --git a/src/kglobalaccel.cpp b/src/kglobalaccel.cpp --- a/src/kglobalaccel.cpp +++ b/src/kglobalaccel.cpp @@ -379,7 +379,7 @@ QList KGlobalAccelPrivate::intListFromShortcut(const QList &cut) { QList ret; - Q_FOREACH (const QKeySequence &sequence, cut) { + for (const QKeySequence &sequence : cut) { ret.append(sequence[0]); } while (!ret.isEmpty() && ret.last() == 0) { @@ -391,7 +391,7 @@ QList KGlobalAccelPrivate::shortcutFromIntList(const QList &list) { QList ret; - Q_FOREACH (int i, list) { + for (int i : list) { ret.append(i); } return ret; @@ -436,8 +436,8 @@ qlonglong timestamp) { QAction *action = nullptr; - QList candidates = nameToAction.values(actionUnique); - Q_FOREACH (QAction *const a, candidates) { + const QList candidates = nameToAction.values(actionUnique); + for (QAction *const a : candidates) { if (componentUniqueForAction(a) == componentUnique) { action = a; } @@ -503,10 +503,10 @@ //shortcut was changed but the kded side died before it got the message so //autoloading will now assign an old shortcut to the action. Particularly //picky apps might assert or misbehave. - QSet allActions = actions; + const QSet allActions = actions; nameToAction.clear(); actions.clear(); - Q_FOREACH (QAction *const action, allActions) { + for (QAction *const action : allActions) { if (doRegister(action)) { updateGlobalShortcut(action, ActiveShortcut, KGlobalAccel::Autoloading); } @@ -590,7 +590,7 @@ .arg(seq.toString(), component, shortcuts[0].friendlyName()); } else { QString actionList; - Q_FOREACH (const KGlobalShortcutInfo &info, shortcuts) { + for (const KGlobalShortcutInfo &info : shortcuts) { actionList += tr("In context '%1' for action '%2'\n") .arg(info.contextFriendlyName(), info.friendlyName()); } @@ -631,7 +631,7 @@ { // protect against garbage keycode -1 that Qt sometimes produces for exotic keys; // at the moment (~mid 2008) Multimedia PlayPause is one of those keys. - Q_FOREACH (const QKeySequence &sequence, shortcut) { + for (const QKeySequence &sequence : shortcut) { for (int i = 0; i < 4; i++) { if (sequence[i] == -1) { qWarning() << "Encountered garbage keycode (keycode = -1) in input, not doing anything."; diff --git a/src/kglobalshortcutinfo_dbus.cpp b/src/kglobalshortcutinfo_dbus.cpp --- a/src/kglobalshortcutinfo_dbus.cpp +++ b/src/kglobalshortcutinfo_dbus.cpp @@ -29,12 +29,12 @@ << shortcut.contextUniqueName() << shortcut.contextFriendlyName(); argument.beginArray(qMetaTypeId()); - Q_FOREACH (const QKeySequence &key, shortcut.keys()) { + for (const QKeySequence &key : shortcut.keys()) { argument << key[0]; } argument.endArray(); argument.beginArray(qMetaTypeId()); - Q_FOREACH (const QKeySequence &key, shortcut.defaultKeys()) { + for (const QKeySequence &key : shortcut.defaultKeys()) { argument << key[0]; } argument.endArray(); diff --git a/src/runtime/component.cpp b/src/runtime/component.cpp --- a/src/runtime/component.cpp +++ b/src/runtime/component.cpp @@ -40,7 +40,7 @@ return ret; } const QStringList strList = str.split('\t'); - foreach (const QString &s, strList) { + for (const QString &s : strList) { int key = QKeySequence(s)[0]; if (key != -1) { //sanity check just in case ret.append(key); @@ -56,7 +56,7 @@ return QStringLiteral("none"); } QString ret; - foreach (int key, keys) { + for (int key : keys) { ret.append(QKeySequence(key).toString()); ret.append('\t'); } @@ -123,7 +123,7 @@ void Component::activateShortcuts() { - Q_FOREACH (GlobalShortcut *shortcut, _current->_actions) + for (GlobalShortcut *shortcut : qAsConst(_current->_actions)) { shortcut->setActive(); } @@ -160,7 +160,7 @@ { bool changed = false;; - Q_FOREACH (GlobalShortcut *shortcut, _current->_actions) + for (GlobalShortcut *shortcut : qAsConst(_current->_actions)) { qCDebug(KGLOBALACCELD) << _current->_actions.size(); if (!shortcut->isPresent()) @@ -216,7 +216,7 @@ void Component::deactivateShortcuts(bool temporarily) { - Q_FOREACH (GlobalShortcut *shortcut, _current->_actions) + for (GlobalShortcut *shortcut : qAsConst(_current->_actions)) { if (temporarily && uniqueName() == QLatin1String("kwin") @@ -281,7 +281,7 @@ QList Component::getShortcutsByKey(int key) const { QList rc; - Q_FOREACH(GlobalShortcutContext *context, _contexts) + for (GlobalShortcutContext *context : qAsConst(_contexts)) { GlobalShortcut *sc = context->getShortcutByKey(key); if (sc) rc.append(sc); @@ -311,7 +311,7 @@ { // The component is active if at least one of it's global shortcuts is // present. - Q_FOREACH (GlobalShortcut *shortcut, _current->_actions) + for (GlobalShortcut *shortcut : qAsConst(_current->_actions)) { if (shortcut->isPresent()) return true; } @@ -330,16 +330,16 @@ // context if (component==uniqueName()) { - Q_FOREACH(GlobalShortcut *sc, shortcutContext(context)->_actions) + for (GlobalShortcut *sc : qAsConst(shortcutContext(context)->_actions)) { if (sc->keys().contains(key)) return false; } } else { - Q_FOREACH(GlobalShortcutContext *ctx, _contexts) + for (GlobalShortcutContext *ctx : qAsConst(_contexts)) { - Q_FOREACH(GlobalShortcut *sc, ctx->_actions) + for (GlobalShortcut *sc : qAsConst(ctx->_actions)) { if (sc->keys().contains(key)) return false; } @@ -356,19 +356,19 @@ friendlyName, currentContext()); - QList keys = keysFromString(shortcutString); + const QList keys = keysFromString(shortcutString); shortcut->setDefaultKeys(keysFromString(defaultShortcutString)); shortcut->setIsFresh(false); - - Q_FOREACH (int key, keys) + QList newKeys = keys; + for (int key : keys) { if (key != 0) { if (GlobalShortcutsRegistry::self()->getShortcutByKey(key)) { // The shortcut is already used. The config file is // broken. Ignore the request. - keys.removeAll(key); + newKeys.removeAll(key); qCWarning(KGLOBALACCELD) << "Shortcut found twice in kglobalshortcutsrc."<_actions.value(uniqueName)) { @@ -454,7 +455,7 @@ // Now write all contexts - Q_FOREACH( GlobalShortcutContext *context, _contexts) + for( GlobalShortcutContext *context : qAsConst(_contexts)) { KConfigGroup contextGroup; @@ -473,7 +474,7 @@ // qCDebug(KGLOBALACCELD) << "writing group " << _uniqueName << ":" << context->uniqueName(); - Q_FOREACH(const GlobalShortcut *shortcut, context->_actions) + for (const GlobalShortcut *shortcut : qAsConst(context->_actions)) { // qCDebug(KGLOBALACCELD) << "writing" << shortcut->uniqueName(); diff --git a/src/runtime/globalshortcut.cpp b/src/runtime/globalshortcut.cpp --- a/src/runtime/globalshortcut.cpp +++ b/src/runtime/globalshortcut.cpp @@ -77,11 +77,11 @@ info.d->contextFriendlyName = context()->friendlyName(); info.d->componentUniqueName = context()->component()->uniqueName(); info.d->componentFriendlyName = context()->component()->friendlyName(); - Q_FOREACH (int key, _keys) + for (int key : qAsConst(_keys)) { info.d->keys.append(QKeySequence(key)); } - Q_FOREACH (int key, _defaultKeys) + for (int key : qAsConst(_defaultKeys)) { info.d->defaultKeys.append(QKeySequence(key)); } @@ -181,7 +181,7 @@ _keys = QList(); - Q_FOREACH(int key, newKeys) + for(int key : qAsConst(newKeys)) { if (key!=0 && !GlobalShortcutsRegistry::self()->getShortcutByKey(key)) { @@ -222,7 +222,7 @@ return; } - Q_FOREACH( int key, _keys) + for( int key : qAsConst(_keys)) { if (key != 0 && !GlobalShortcutsRegistry::self()->registerKey(key, this)) { @@ -242,7 +242,7 @@ return; } - Q_FOREACH( int key, _keys) + for( int key : qAsConst(_keys)) { if (key != 0 && !GlobalShortcutsRegistry::self()->unregisterKey(key, this)) { diff --git a/src/runtime/globalshortcutcontext.cpp b/src/runtime/globalshortcutcontext.cpp --- a/src/runtime/globalshortcutcontext.cpp +++ b/src/runtime/globalshortcutcontext.cpp @@ -49,7 +49,7 @@ QList GlobalShortcutContext::allShortcutInfos() const { QList rc; - Q_FOREACH (GlobalShortcut *shortcut, _actions) + for (GlobalShortcut *shortcut : qAsConst(_actions)) { rc.append(static_cast(*shortcut)); } @@ -84,16 +84,16 @@ if ((keyMod & Qt::SHIFT) && (keySym == Qt::Key_Backtab || keySym == Qt::Key_Tab)) { - Q_FOREACH(GlobalShortcut *sc, _actions) + for (GlobalShortcut *sc : qAsConst(_actions)) { if (sc->keys().contains(keyMod | Qt::Key_Tab) || sc->keys().contains(keyMod | Qt::Key_Backtab)) return sc; } } else { - Q_FOREACH(GlobalShortcut *sc, _actions) + for (GlobalShortcut *sc : qAsConst(_actions)) { if (sc->keys().contains(key)) return sc; } diff --git a/src/runtime/globalshortcutsregistry.cpp b/src/runtime/globalshortcutsregistry.cpp --- a/src/runtime/globalshortcutsregistry.cpp +++ b/src/runtime/globalshortcutsregistry.cpp @@ -44,7 +44,7 @@ if (platformName.isEmpty()) { platformName = QGuiApplication::platformName(); } - foreach (const KPluginMetaData &candidate, candidates) { + for (const KPluginMetaData &candidate : candidates) { const QJsonArray platforms = candidate.rawData().value(QStringLiteral("platforms")).toArray(); for (auto it = platforms.begin(); it != platforms.end(); ++it) { if (QString::compare(platformName, (*it).toString(), Qt::CaseInsensitive) == 0) { @@ -81,7 +81,8 @@ // Ungrab all keys. We don't go over GlobalShortcuts because // GlobalShortcutsRegistry::self() doesn't work anymore. - Q_FOREACH (const int key, _active_keys.keys()) + const auto listKeys = _active_keys.keys(); + for (const int key : listKeys) { _manager->grabKey(key, false); } @@ -111,7 +112,7 @@ void GlobalShortcutsRegistry::activateShortcuts() { - Q_FOREACH (KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { component->activateShortcuts(); } @@ -126,7 +127,7 @@ void GlobalShortcutsRegistry::clear() { - Q_FOREACH(KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { delete component; } @@ -145,7 +146,7 @@ void GlobalShortcutsRegistry::deactivateShortcuts(bool temporarily) { - Q_FOREACH (KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { component->deactivateShortcuts(temporarily); } @@ -166,7 +167,7 @@ GlobalShortcut *GlobalShortcutsRegistry::getShortcutByKey(int key) const { - Q_FOREACH (KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { GlobalShortcut *rc = component->getShortcutByKey(key); if (rc) return rc; @@ -179,7 +180,7 @@ { QList rc; - Q_FOREACH (KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { rc = component->getShortcutsByKey(key); if (!rc.isEmpty()) return rc; @@ -193,7 +194,7 @@ const QString &componentName, const QString &contextName) const { - Q_FOREACH (KdeDGlobalAccel::Component *component, _components) + for (KdeDGlobalAccel::Component *component : qAsConst(_components)) { if (!component->isShortcutAvailable(shortcut, componentName, contextName)) return false; @@ -261,7 +262,8 @@ void GlobalShortcutsRegistry::loadSettings() { - foreach (const QString &groupName, _config.groupList()) + const auto groupList = _config.groupList(); + for (const QString &groupName : groupList) { qCDebug(KGLOBALACCELD) << "Loading group " << groupName; @@ -292,7 +294,8 @@ } // Now load the contexts - Q_FOREACH(const QString& context, configGroup.groupList()) + const auto groupList = configGroup.groupList(); + for (const QString& context : groupList) { // Skip the friendly name group if (context==QLatin1String("Friendly Name")) continue; @@ -311,13 +314,14 @@ // Load the configured KServiceActions const QStringList desktopPaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kglobalaccel"), QStandardPaths::LocateDirectory); - foreach (const QString &path, desktopPaths) { + for (const QString &path : desktopPaths) { QDir dir(path); if (!dir.exists()) { continue; } const QStringList patterns = {QStringLiteral("*.desktop")}; - foreach (const QString &desktopFile, dir.entryList(patterns)) { + const auto lstDesktopFiles = dir.entryList(patterns); + for (const QString &desktopFile : lstDesktopFiles) { if (_components.contains(desktopFile)) { continue; } @@ -417,9 +421,10 @@ void GlobalShortcutsRegistry::writeSettings() const { - Q_FOREACH( - const KdeDGlobalAccel::Component *component, - GlobalShortcutsRegistry::self()->allMainComponents()) + const auto lst = GlobalShortcutsRegistry::self()->allMainComponents(); + for ( + const KdeDGlobalAccel::Component *component : lst + ) { KConfigGroup configGroup(&_config, component->uniqueName()); if (component->allShortcuts().isEmpty()) diff --git a/src/runtime/kglobalacceld.cpp b/src/runtime/kglobalacceld.cpp --- a/src/runtime/kglobalacceld.cpp +++ b/src/runtime/kglobalacceld.cpp @@ -295,7 +295,8 @@ partialId.append(component->friendlyName()); //ComponentFriendly partialId.append(QString()); //ActionFriendly - foreach (const GlobalShortcut *const shortcut, component->allShortcuts()) { + const auto listShortcuts = component->allShortcuts(); + for (const GlobalShortcut *const shortcut : listShortcuts) { if (shortcut->isFresh()) { // isFresh is only an intermediate state, not to be reported outside. continue; @@ -338,8 +339,9 @@ { QList allComp; - Q_FOREACH (const KdeDGlobalAccel::Component *component, - GlobalShortcutsRegistry::self()->allMainComponents()) + const auto lstMainComponents = GlobalShortcutsRegistry::self()->allMainComponents(); + for (const KdeDGlobalAccel::Component *component : + lstMainComponents) { allComp.append(component->dbusPath()); } @@ -435,11 +437,11 @@ #ifdef KDEDGLOBALACCEL_TRACE qCDebug(KGLOBALACCELD) << key; #endif - QList shortcuts = + const QList shortcuts = GlobalShortcutsRegistry::self()->getShortcutsByKey(key); QList rc; - Q_FOREACH(const GlobalShortcut *sc, shortcuts) + for (const GlobalShortcut *sc : shortcuts) { #ifdef KDEDGLOBALACCEL_TRACE qCDebug(KGLOBALACCELD) << sc->context()->uniqueName() << sc->uniqueName(); diff --git a/src/runtime/kserviceactioncomponent.cpp b/src/runtime/kserviceactioncomponent.cpp --- a/src/runtime/kserviceactioncomponent.cpp +++ b/src/runtime/kserviceactioncomponent.cpp @@ -75,7 +75,8 @@ } return; } - foreach (const QString &action, m_desktopFile.readActions()) { + const auto lstActions = m_desktopFile.readActions(); + for (const QString &action : lstActions) { if (action == shortcut.uniqueName()) { QStringList parts = m_desktopFile.actionGroup(action).readEntry(QStringLiteral("Exec"), QString()).split(QChar(' ')); @@ -119,8 +120,8 @@ GlobalShortcut *shortcut = registerShortcut(QStringLiteral("_launch"), m_desktopFile.readName(), shortcutString, shortcutString); shortcut->setIsPresent(true); - - foreach(const QString &action, m_desktopFile.readActions()) + const auto lstActions = m_desktopFile.readActions(); + for (const QString &action : lstActions) { shortcuts = m_desktopFile.actionGroup(action).readEntry(QStringLiteral("X-KDE-Shortcuts"), QString()).split(QChar(',')); if (!shortcuts.isEmpty()) diff --git a/src/runtime/plugins/osx/kglobalaccel_mac.cpp b/src/runtime/plugins/osx/kglobalaccel_mac.cpp --- a/src/runtime/plugins/osx/kglobalaccel_mac.cpp +++ b/src/runtime/plugins/osx/kglobalaccel_mac.cpp @@ -94,15 +94,15 @@ KKeyServer::keyQtToModMac( keyQt, mod ); qCDebug(KGLOBALACCELD) << "keyQt: " << keyQt << " mod: " << mod; - foreach (uint keyCode, keyCodes) { + for (uint keyCode : qAsConst(keyCodes)) { qCDebug(KGLOBALACCELD) << " keyCode: " << keyCode; } EventHotKeyID ehkid; ehkid.signature = 'Kgai'; ehkid.id = keyQt; QList hotkeys; - foreach (uint keyCode, keyCodes) { + for (uint keyCode : qAsConst(keyCodes)) { EventHotKeyRef ref; if (RegisterEventHotKey(keyCode, mod, ehkid, m_eventTarget, 0, &ref) != noErr) { qCWarning(KGLOBALACCELD) << "RegisterEventHotKey failed!"; @@ -113,7 +113,8 @@ } else { qCDebug(KGLOBALACCELD) << "Ungrabbing key " << keyQt; if (refs->count(keyQt) == 0) qCWarning(KGLOBALACCELD) << "Trying to ungrab a key thas is not grabbed"; - foreach (const EventHotKeyRef &ref, refs->value(keyQt)) { + const auto lstRef = refs->value(keyQt); + for (const EventHotKeyRef &ref : lstRef) { if (UnregisterEventHotKey(ref) != noErr) { qCWarning(KGLOBALACCELD) << "UnregisterEventHotKey should not fail!"; } @@ -149,7 +150,7 @@ grabKey(key, false); } // Now re-grab all the keys - foreach (int key, keys) { + for (int key : qAsConst(keys)) { grabKey(key, true); } }