diff --git a/src/kaboutapplicationpersonmodel_p.cpp b/src/kaboutapplicationpersonmodel_p.cpp --- a/src/kaboutapplicationpersonmodel_p.cpp +++ b/src/kaboutapplicationpersonmodel_p.cpp @@ -44,9 +44,7 @@ } bool hasOcsUsernames = false; - for (QList< KAboutPerson >::const_iterator it = personList.constBegin(); it != personList.constEnd(); ++it) { - KAboutPerson person = *it; - + for (auto& person : qAsConst(m_personList)) { if (!person.ocsUsername().isEmpty()) { hasOcsUsernames = true; } @@ -120,9 +118,7 @@ m_providerName = m_provider.name(); int i = 0; - for (QList< KAboutApplicationPersonProfile >::const_iterator it = m_profileList.constBegin(); - it != m_profileList.constEnd(); ++it) { - KAboutApplicationPersonProfile profile = *it; + for (auto& profile : qAsConst(m_profileList)) { if (!profile.ocsUsername().isEmpty()) { Attica::ItemJob< Attica::Person > *job = m_provider.requestPerson(profile.ocsUsername()); connect(job, SIGNAL(finished(Attica::BaseJob*)), @@ -363,13 +359,12 @@ void KAboutApplicationPersonIconsJob::getIcons(int i) { - for (QList< KAboutApplicationPersonProfileOcsLink >::iterator it = m_ocsLinks.begin() + i; - it != m_ocsLinks.end(); ++it) { - if (m_model->m_ocsLinkIcons.contains(it->type())) { - it->setIcon(m_model->m_ocsLinkIcons.value(it->type())); - } else if (m_model->m_ocsLinkIconUrls.contains(it->type())) { + for (auto& ocsLink : m_ocsLinks) { + if (m_model->m_ocsLinkIcons.contains(ocsLink.type())) { + ocsLink.setIcon(m_model->m_ocsLinkIcons.value(ocsLink.type())); + } else if (m_model->m_ocsLinkIconUrls.contains(ocsLink.type())) { QNetworkReply *reply = - m_manager->get(QNetworkRequest(QUrl(m_model->m_ocsLinkIconUrls.value(it->type())))); + m_manager->get(QNetworkRequest(QUrl(m_model->m_ocsLinkIconUrls.value(ocsLink.type())))); reply->setProperty("linkIndex", i); return; } diff --git a/src/kedittoolbar.cpp b/src/kedittoolbar.cpp --- a/src/kedittoolbar.cpp +++ b/src/kedittoolbar.cpp @@ -507,9 +507,8 @@ #ifndef NDEBUG void dump() const { - XmlDataList::const_iterator xit = m_xmlFiles.begin(); - for (; xit != m_xmlFiles.end(); ++xit) { - (*xit).dump(); + for (auto& xmlFile : m_xmlFiles) { + xmlFile.dump(); } } #endif @@ -910,20 +909,19 @@ void KEditToolBarWidget::save() { //qDebug(240) << "KEditToolBarWidget::save"; - XmlDataList::Iterator it = d->m_xmlFiles.begin(); - for (; it != d->m_xmlFiles.end(); ++it) { + for (auto& xmlFile : qAsConst(d->m_xmlFiles)) { // let's not save non-modified files - if (!((*it).m_isModified)) { + if (!xmlFile.m_isModified) { continue; } // let's also skip (non-existent) merged files - if ((*it).type() == XmlData::Merged) { + if (xmlFile.type() == XmlData::Merged) { continue; } // Add noMerge="1" to all the menus since we are saving the merged data - QDomNodeList menuNodes = (*it).domDocument().elementsByTagName(QStringLiteral("Menu")); + QDomNodeList menuNodes = xmlFile.domDocument().elementsByTagName(QStringLiteral("Menu")); for (int i = 0; i < menuNodes.length(); ++i) { QDomNode menuNode = menuNodes.item(i); QDomElement menuElement = menuNode.toElement(); @@ -937,7 +935,7 @@ //qDebug(240) << "Saving " << (*it).xmlFile(); // if we got this far, we might as well just save it - KXMLGUIFactory::saveConfigFile((*it).domDocument(), (*it).xmlFile()); + KXMLGUIFactory::saveConfigFile(xmlFile.domDocument(), xmlFile.xmlFile()); } if (!d->m_factory) { @@ -1156,21 +1154,19 @@ int defaultToolBarId = -1; int count = 0; // load in all of the toolbar names into this combo box - XmlDataList::const_iterator xit = m_xmlFiles.constBegin(); - for (; xit != m_xmlFiles.constEnd(); ++xit) { + for (auto& xmlFile : qAsConst(m_xmlFiles)) { // skip the merged one in favor of the local one, // so that we can change icons // This also makes the app-defined named for "mainToolBar" appear rather than the ui_standards-defined name. - if ((*xit).type() == XmlData::Merged) { + if (xmlFile.type() == XmlData::Merged) { continue; } // each xml file may have any number of toolbars - ToolBarList::const_iterator it = (*xit).barList().begin(); - for (; it != (*xit).barList().constEnd(); ++it) { - const QString text = (*xit).toolBarText(*it); + for (auto& bar : qAsConst(xmlFile.barList())) { + const QString text = xmlFile.toolBarText(bar); m_toolbarCombo->addItem(text); - const QString name = (*it).attribute(attrName); + const QString name = bar.attribute(attrName); if (defaultToolBarId == -1 && name == defaultToolBar) { defaultToolBarId = count; } @@ -1317,25 +1313,21 @@ // To do that, we do the same iteration as the one which filled in the combobox. int toolbarNumber = 0; - XmlDataList::iterator xit = m_xmlFiles.begin(); - for (; xit != m_xmlFiles.end(); ++xit) { - + for (auto& xmlFile : m_xmlFiles) { // skip the merged one in favor of the local one, // so that we can change icons - if ((*xit).type() == XmlData::Merged) { + if (xmlFile.type() == XmlData::Merged) { continue; } // each xml file may have any number of toolbars - ToolBarList::Iterator it = (*xit).barList().begin(); - for (; it != (*xit).barList().end(); ++it) { - + for (auto& bar : xmlFile.barList()) { // is this our toolbar? if (toolbarNumber == index) { // save our current settings - m_currentXmlData = & (*xit); - m_currentToolBarElem = *it; + m_currentXmlData = &xmlFile; + m_currentToolBarElem = bar; //qCDebug(DEBUG_KXMLGUI) << "found toolbar" << m_currentXmlData->toolBarText(*it) << "m_currentXmlData set to"; m_currentXmlData->dump(); @@ -1346,8 +1338,8 @@ // load in our values loadActions(m_currentToolBarElem); - if ((*xit).type() == XmlData::Part || (*xit).type() == XmlData::Shell) { - m_widget->setDOMDocument((*xit).domDocument()); + if (xmlFile.type() == XmlData::Part || xmlFile.type() == XmlData::Shell) { + m_widget->setDOMDocument(xmlFile.domDocument()); } return; } @@ -1571,39 +1563,37 @@ void KEditToolBarWidgetPrivate::updateLocal(QDomElement &elem) { - XmlDataList::Iterator xit = m_xmlFiles.begin(); - for (; xit != m_xmlFiles.end(); ++xit) { - if ((*xit).type() == XmlData::Merged) { + for (auto& xmlFile : m_xmlFiles) { + if (xmlFile.type() == XmlData::Merged) { continue; } - if ((*xit).type() == XmlData::Shell || - (*xit).type() == XmlData::Part) { - if (m_currentXmlData->xmlFile() == (*xit).xmlFile()) { - (*xit).m_isModified = true; + if (xmlFile.type() == XmlData::Shell || + xmlFile.type() == XmlData::Part) { + if (m_currentXmlData->xmlFile() == xmlFile.xmlFile()) { + xmlFile.m_isModified = true; return; } continue; } - (*xit).m_isModified = true; + xmlFile.m_isModified = true; const QLatin1String attrName("name"); - ToolBarList::Iterator it = (*xit).barList().begin(); - for (; it != (*xit).barList().end(); ++it) { - QString name((*it).attribute(attrName)); - QString tag((*it).tagName()); + for (auto& bar : qAsConst(xmlFile.barList())) { + const QString name(bar.attribute(attrName)); + const QString tag(bar.tagName()); if ((tag != elem.tagName()) || (name != elem.attribute(attrName))) { continue; } - QDomElement toolbar = (*xit).domDocument().documentElement().toElement(); - toolbar.replaceChild(elem, (*it)); + QDomElement toolbar = xmlFile.domDocument().documentElement().toElement(); + toolbar.replaceChild(elem, bar); return; } // just append it - QDomElement toolbar = (*xit).domDocument().documentElement().toElement(); + QDomElement toolbar = xmlFile.domDocument().documentElement().toElement(); Q_ASSERT(!toolbar.isNull()); toolbar.appendChild(elem); } diff --git a/src/kgesture.cpp b/src/kgesture.cpp --- a/src/kgesture.cpp +++ b/src/kgesture.cpp @@ -114,9 +114,9 @@ float xScale = bounding.width() ? 100.0 / bounding.width() : 1.0; float yScale = bounding.height() ? 100.0 / bounding.height() : 1.0; d->m_shape.translate(-bounding.left(), -bounding.top()); - for (int i = 0; i < d->m_shape.size(); i++) { - d->m_shape[i].setX((int)(xScale * (float)d->m_shape[i].x())); - d->m_shape[i].setY((int)(yScale * (float)d->m_shape[i].y())); + for (QPoint& shape : d->m_shape) { + shape.setX((int)(xScale * (float)shape.x())); + shape.setY((int)(yScale * (float)shape.y())); } //calculate accumulated lengths of lines making up the polygon @@ -162,10 +162,9 @@ //TODO: what if the name contains a "," or ";"? Limit the name to letters? QString ret = d->m_friendlyName; - int i; - for (i = 0; i < d->m_shape.size(); i++) { - ret += QLatin1Char(',') + QString::number(d->m_shape[i].x()) + - QLatin1Char(',') + QString::number(d->m_shape[i].y()); + for (const QPoint shape : qAsConst(d->m_shape)) { + ret += QLatin1Char(',') + QString::number(shape.x()) + + QLatin1Char(',') + QString::number(shape.y()); } return ret; diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp --- a/src/kmainwindow.cpp +++ b/src/kmainwindow.cpp @@ -346,10 +346,9 @@ dbusName = QLatin1Char('/') + QCoreApplication::applicationName() + QLatin1Char('/'); dbusName += q->objectName().replace(QLatin1Char('/'), QLatin1Char('_')); // Clean up for dbus usage: any non-alphanumeric char should be turned into '_' - const int len = dbusName.length(); - for (int i = 0; i < len; ++i) { - if (!isValidDBusObjectPathCharacter(dbusName[i])) { - dbusName[i] = QLatin1Char('_'); + for (QChar& c : dbusName) { + if (!isValidDBusObjectPathCharacter(c)) { + c = QLatin1Char('_'); } } diff --git a/src/kshortcutseditor.cpp b/src/kshortcutseditor.cpp --- a/src/kshortcutseditor.cpp +++ b/src/kshortcutseditor.cpp @@ -712,11 +712,12 @@ tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid); tableformat.setBorder(0.5); - QList > shortcutTitleToColumn; - shortcutTitleToColumn << qMakePair(i18n("Main:"), LocalPrimary); - shortcutTitleToColumn << qMakePair(i18n("Alternate:"), LocalAlternate); - shortcutTitleToColumn << qMakePair(i18n("Global:"), GlobalPrimary); - shortcutTitleToColumn << qMakePair(i18n("Global alternate:"), GlobalAlternate); + const QPair shortcutTitleToColumnMap[] = { + qMakePair(i18n("Main:"), LocalPrimary), + qMakePair(i18n("Alternate:"), LocalAlternate), + qMakePair(i18n("Global:"), GlobalPrimary), + qMakePair(i18n("Global alternate:"), GlobalAlternate), + }; for (int i = 0; i < root->childCount(); i++) { QTreeWidgetItem *item = root->child(i); @@ -753,8 +754,8 @@ table->cellAt(currow, 0).firstCursorPosition().insertText(data.toString()); QTextTable *shortcutTable = nullptr; - for (int k = 0; k < shortcutTitleToColumn.count(); k++) { - data = editoritem->data(shortcutTitleToColumn.at(k).second, Qt::DisplayRole); + for (auto& shortcutTitleToColumn : shortcutTitleToColumnMap) { + data = editoritem->data(shortcutTitleToColumn.second, Qt::DisplayRole); QString key = data.value().toString(); if (!key.isEmpty()) { @@ -768,7 +769,7 @@ } else { shortcutTable->insertRows(shortcutTable->rows(), 1); } - shortcutTable->cellAt(shortcutTable->rows() - 1, 0).firstCursorPosition().insertText(shortcutTitleToColumn.at(k).first); + shortcutTable->cellAt(shortcutTable->rows() - 1, 0).firstCursorPosition().insertText(shortcutTitleToColumn.first); shortcutTable->cellAt(shortcutTable->rows() - 1, 1).firstCursorPosition().insertText(key); } } diff --git a/src/kswitchlanguagedialog_p.cpp b/src/kswitchlanguagedialog_p.cpp --- a/src/kswitchlanguagedialog_p.cpp +++ b/src/kswitchlanguagedialog_p.cpp @@ -274,8 +274,7 @@ { QStringList languages; - for (int i = 0, count = d->languageButtons.count(); i < count; ++i) { - KLanguageButton *languageButton = d->languageButtons[i]; + for (auto* languageButton : qAsConst(d->languageButtons)) { languages << languageButton->current(); } @@ -371,8 +370,8 @@ languagesList = l.uiLanguages(); // We get en-US here but we use en_US - for (int i = 0; i < languagesList.count(); ++i) { - languagesList[i].replace(QLatin1Char('-'), QLatin1Char('_')); + for (auto& language : languagesList) { + language.replace(QLatin1Char('-'), QLatin1Char('_')); } } diff --git a/src/ktoolbar.cpp b/src/ktoolbar.cpp --- a/src/ktoolbar.cpp +++ b/src/ktoolbar.cpp @@ -184,16 +184,16 @@ public: IntSetting() { - for (int level = 0; level < NSettingLevels; ++level) { - values[level] = Unset; + for (int& value : values) { + value = Unset; } } int currentValue() const { int val = Unset; - for (int level = 0; level < NSettingLevels; ++level) { - if (values[level] != Unset) { - val = values[level]; + for (int value : values) { + if (value != Unset) { + val = value; } } return val; @@ -213,8 +213,8 @@ QString toString() const { QString str; - for (int level = 0; level < NSettingLevels; ++level) { - str += QString::number(values[level]) + QLatin1Char(' '); + for (int value : values) { + str += QString::number(value) + QLatin1Char(' '); } return str; } @@ -375,9 +375,9 @@ // Scalable icons. const int progression[] = { 16, 22, 32, 48, 64, 96, 128, 192, 256 }; - for (uint i = 0; i < 9; i++) { + for (int p : progression) { for (int it : qAsConst(avSizes)) { - if (it >= progression[ i ]) { + if (it >= p) { QString text; if (it < 19) { text = i18n("Small (%1x%2)", it, it); diff --git a/src/ktoolbarhandler.cpp b/src/ktoolbarhandler.cpp --- a/src/ktoolbarhandler.cpp +++ b/src/ktoolbarhandler.cpp @@ -192,10 +192,10 @@ void ToolBarHandler::Private::connectToActionContainer(QAction *action) { - int containerCount = action->associatedWidgets().count(); + const auto associatedWidgets = action->associatedWidgets(); - for (int i = 0; i < containerCount; ++i) { - connectToActionContainer(action->associatedWidgets().value(i)); + for (auto* widget : associatedWidgets) { + connectToActionContainer(widget); } } diff --git a/src/kxmlguiclient.cpp b/src/kxmlguiclient.cpp --- a/src/kxmlguiclient.cpp +++ b/src/kxmlguiclient.cpp @@ -754,28 +754,24 @@ void KXMLGUIClient::stateChanged(const QString &newstate, KXMLGUIClient::ReverseStateChange reverse) { - StateChange stateChange = getActionsToChangeForState(newstate); + const StateChange stateChange = getActionsToChangeForState(newstate); bool setTrue = (reverse == StateNoReverse); bool setFalse = !setTrue; // Enable actions which need to be enabled... // - for (QStringList::const_iterator it = stateChange.actionsToEnable.constBegin(); - it != stateChange.actionsToEnable.constEnd(); ++it) { - - QAction *action = actionCollection()->action(*it); + for (auto& actionId : stateChange.actionsToEnable) { + QAction *action = actionCollection()->action(actionId); if (action) { action->setEnabled(setTrue); } } // and disable actions which need to be disabled... // - for (QStringList::const_iterator it = stateChange.actionsToDisable.constBegin(); - it != stateChange.actionsToDisable.constEnd(); ++it) { - - QAction *action = actionCollection()->action(*it); + for (auto& actionId : stateChange.actionsToDisable) { + QAction *action = actionCollection()->action(actionId); if (action) { action->setEnabled(setFalse); } diff --git a/src/kxmlguifactory_p.cpp b/src/kxmlguifactory_p.cpp --- a/src/kxmlguifactory_p.cpp +++ b/src/kxmlguifactory_p.cpp @@ -418,10 +418,8 @@ // unplug all actionslists - ActionListMap::ConstIterator alIt = client->actionLists.constBegin(); - ActionListMap::ConstIterator alEnd = client->actionLists.constEnd(); - for (; alIt != alEnd; ++alIt) { - removeActions(alIt.value()); + for (auto& actionList : qAsConst(client->actionLists)) { + removeActions(actionList); } }