diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) add_feature_info(QCH ${BUILD_QCH} "API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)") add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050d00) +add_definitions(-DQT_NO_FOREACH) if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ki18n_install(po) diff --git a/autotests/klocalizedstringtest.cpp b/autotests/klocalizedstringtest.cpp --- a/autotests/klocalizedstringtest.cpp +++ b/autotests/klocalizedstringtest.cpp @@ -100,7 +100,7 @@ qDebug() << "msgfmt(1) not found in path."; return false; } - foreach (const QString &testPoPath, testPoPaths) { + for (const QString &testPoPath : testPoPaths) { int pos_1 = testPoPath.lastIndexOf(QLatin1Char('/')); int pos_2 = testPoPath.lastIndexOf(QLatin1Char('.')); QString domain = testPoPath.mid(pos_1 + 1, pos_2 - pos_1 - 1); diff --git a/src/kcatalog.cpp b/src/kcatalog.cpp --- a/src/kcatalog.cpp +++ b/src/kcatalog.cpp @@ -171,10 +171,10 @@ } QSet availableLanguages; - foreach (const QString &localDirPath, localeDirPaths) { + for (const QString &localDirPath : qAsConst(localeDirPaths)) { QDir localeDir(localDirPath); - QStringList languages = localeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); - foreach (const QString &language, languages) { + const QStringList languages = localeDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + for (const QString &language : languages) { QString relPath = QStringLiteral("%1/LC_MESSAGES/%2.mo") .arg(language, domain); if (localeDir.exists(relPath)) { diff --git a/src/klocalizedstring.cpp b/src/klocalizedstring.cpp --- a/src/klocalizedstring.cpp +++ b/src/klocalizedstring.cpp @@ -131,7 +131,8 @@ if (!qenvar.isEmpty()) { QString value = QFile::decodeName(qenvar); if (isList) { - foreach(const QString &v, value.split(QLatin1Char(':'), QString::SkipEmptyParts)) { + const auto listLanguages = value.split(QLatin1Char(':'), QString::SkipEmptyParts); + for (const QString &v : listLanguages) { appendLocaleString(languages, v); } } else { @@ -155,7 +156,7 @@ static QString extractCountry(const QStringList &languages) { QString country; - foreach (const QString &language, languages) { + for (const QString &language : languages) { int pos1 = language.indexOf(QLatin1Char('_')); if (pos1 >= 0) { ++pos1; @@ -343,7 +344,7 @@ KLocalizedStringPrivateStatics::~KLocalizedStringPrivateStatics() { - foreach (const KCatalogPtrHash &languageCatalogs, catalogs) { + for (const KCatalogPtrHash &languageCatalogs : qAsConst(catalogs)) { qDeleteAll(languageCatalogs); } // ktrs is handled by QLibrary. @@ -458,7 +459,7 @@ } // Languages are ordered from highest to lowest priority. - foreach (const QString &testLanguage, languages) { + for (const QString &testLanguage : languages) { // If code language reached, no catalog lookup is needed. if (testLanguage == s->codeLanguage) { return; @@ -1434,7 +1435,7 @@ // Go through possible localized paths by priority of languages, // return first that exists. QString fileName = fileInfo.fileName(); - foreach (const QString &lang, s->languages) { + for (const QString &lang : qAsConst(s->languages)) { QString locFilePath = locDirPath + QLatin1Char('/') + lang + QLatin1Char('/') + fileName; @@ -1497,7 +1498,7 @@ // was found, otherwise the original text was returned as translation. QString translation; QString language; - foreach (const QByteArray &domain, s->qtDomains) { + for (const QByteArray &domain : qAsConst(s->qtDomains)) { if (comment && comment[0]) { // Comment given, go for context call. KLocalizedStringPrivate::translateRaw(domain, s->languages, diff --git a/src/kuitmarkup.cpp b/src/kuitmarkup.cpp --- a/src/kuitmarkup.cpp +++ b/src/kuitmarkup.cpp @@ -487,8 +487,8 @@ aggText = aggText.relaxSubs(); if (!aggText.isEmpty()) { aggText = aggText.subs(modText); - QStringList attributeOrder = attributeOrders.value(attribKey).value(format); - foreach (const QString &attribName, attributeOrder) { + const QStringList attributeOrder = attributeOrders.value(attribKey).value(format); + for (const QString &attribName : attributeOrder) { aggText = aggText.subs(attributes.value(attribName)); } formattedText = aggText.ignoreMarkup().toString(languages); @@ -561,7 +561,7 @@ } QStringList attribNames = attribNames_; attribNames.removeAll(QString()); - foreach (const QString &attribName, attribNames) { + for (const QString &attribName : qAsConst(attribNames)) { tag.knownAttribs.insert(attribName); } QString attribKey = attributeSetKey(attribNames); @@ -1405,9 +1405,9 @@ // Stream reader will automatically resolve default XML entities, // which is not desired in this case, as the entities are to be // resolved in finalizeVisualText. Convert back into entities. - QString ctext = xml.text().toString(); + const QString ctext = xml.text().toString(); QString nctext; - foreach (const QChar c, ctext) { + for (const QChar c : ctext) { if (s->xmlEntitiesInverse.contains(c)) { const QString entName = s->xmlEntitiesInverse[c]; nctext += QL1C('&') + entName + QL1C(';'); @@ -1442,7 +1442,8 @@ // Collect attribute names and values, and format attribute string. QStringList attribNames, attribValues; - foreach (const QXmlStreamAttribute &xatt, xml.attributes()) { + const auto listAttributes = xml.attributes(); + for (const QXmlStreamAttribute &xatt : listAttributes) { attribNames += xatt.name().toString().toLower(); attribValues += xatt.value().toString(); QChar qc = attribValues.last().indexOf(QL1C('\'')) < 0