diff --git a/addons/close-except-like/close_confirm_dialog.cpp b/addons/close-except-like/close_confirm_dialog.cpp --- a/addons/close-except-like/close_confirm_dialog.cpp +++ b/addons/close-except-like/close_confirm_dialog.cpp @@ -82,9 +82,9 @@ m_docs_tree->setSelectionMode(QAbstractItemView::SingleSelection); m_docs_tree->setRootIsDecorated(false); - for (int i = 0; i < m_docs.size(); i++) + for (auto& doc : qAsConst(m_docs)) { - new KateDocItem(m_docs[i], m_docs_tree); + new KateDocItem(doc, m_docs_tree); } m_docs_tree->header()->setStretchLastSection(false); m_docs_tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); diff --git a/addons/filebrowser/katefilebrowserconfig.cpp b/addons/filebrowser/katefilebrowserconfig.cpp --- a/addons/filebrowser/katefilebrowserconfig.cpp +++ b/addons/filebrowser/katefilebrowserconfig.cpp @@ -149,24 +149,36 @@ l << QStringLiteral("back") << QStringLiteral("forward") << QStringLiteral("bookmarks") << QStringLiteral("sync_dir") << QStringLiteral("configure"); // actions from diroperator + two of our own - QStringList allActions; - allActions << QStringLiteral("up") << QStringLiteral("back") << QStringLiteral("forward") << QStringLiteral("home") - << QStringLiteral("reload") << QStringLiteral("mkdir") << QStringLiteral("delete") - << QStringLiteral("short view") << QStringLiteral("detailed view") - << QStringLiteral("tree view") << QStringLiteral("detailed tree view") - << QStringLiteral("show hidden") /*<< QStringLiteral("view menu") << QStringLiteral("properties")*/ - << QStringLiteral("bookmarks") << QStringLiteral("sync_dir") << QStringLiteral("configure"); + const QStringList allActions{ + QStringLiteral("up"), + QStringLiteral("back"), + QStringLiteral("forward"), + QStringLiteral("home"), + QStringLiteral("reload"), + QStringLiteral("mkdir"), + QStringLiteral("delete"), + QStringLiteral("short view"), + QStringLiteral("detailed view"), + QStringLiteral("tree view"), + QStringLiteral("detailed tree view"), + QStringLiteral("show hidden"), + //QStringLiteral("view menu"), + //QStringLiteral("properties"), + QStringLiteral("bookmarks"), + QStringLiteral("sync_dir"), + QStringLiteral("configure")}; + QRegularExpression re(QStringLiteral("&(?=[^&])")); QAction *ac = nullptr; QListWidget *lb; - for ( QStringList::Iterator it = allActions.begin(); it != allActions.end(); ++it ) + for (const auto& actionName : allActions) { - lb = l.contains( *it ) ? acSel->selectedListWidget() : acSel->availableListWidget(); + lb = l.contains( actionName ) ? acSel->selectedListWidget() : acSel->availableListWidget(); - if ( *it == QStringLiteral ("bookmarks") || *it == QStringLiteral ("sync_dir") || *it == QStringLiteral ("configure") ) - ac = fileBrowser->actionCollection()->action( *it ); + if ( actionName == QStringLiteral ("bookmarks") || actionName == QStringLiteral ("sync_dir") || actionName == QStringLiteral ("configure") ) + ac = fileBrowser->actionCollection()->action( actionName ); else - ac = fileBrowser->dirOperator()->actionCollection()->action( *it ); + ac = fileBrowser->dirOperator()->actionCollection()->action( actionName ); if ( ac ) { @@ -177,7 +189,7 @@ // avoid extraction here and let it be sourced from kdelibs. #define i18ncX i18nc text = i18ncX( "@item:intable Action name in toolbar editor", "%1", text ); - new ActionLBItem( lb, ac->icon(), text, *it ); + new ActionLBItem( lb, ac->icon(), text, actionName ); } } } diff --git a/addons/filetree/katefiletree.cpp b/addons/filetree/katefiletree.cpp --- a/addons/filetree/katefiletree.cpp +++ b/addons/filetree/katefiletree.cpp @@ -295,10 +295,9 @@ QMimeType mime = db.mimeTypeForName(doc->mimeType()); QAction *a = nullptr; - KService::List offers = KMimeTypeTrader::self()->query(mime.name(), QStringLiteral("Application")); + const KService::List offers = KMimeTypeTrader::self()->query(mime.name(), QStringLiteral("Application")); // for each one, insert a menu item... - for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) { - KService::Ptr service = *it; + for (const auto& service : offers) { if (service->name() == QLatin1String("Kate")) { continue; } diff --git a/addons/gdbplugin/debugview.cpp b/addons/gdbplugin/debugview.cpp --- a/addons/gdbplugin/debugview.cpp +++ b/addons/gdbplugin/debugview.cpp @@ -120,8 +120,8 @@ bool DebugView::hasBreakpoint(const QUrl& url, int line) { - for (int i = 0; isetSortingEnabled(false); - for (int i=0; isetText(0, list[i].tag); - item->setText(1, list[i].type); - item->setText(2, list[i].file); - item->setData(0, Qt::UserRole, list[i].pattern); + item->setText(0, tag.tag); + item->setText(1, tag.type); + item->setText(2, tag.file); + item->setData(0, Qt::UserRole, tag.pattern); - QString pattern = list[i].pattern; + QString pattern = tag.pattern; pattern.replace( QStringLiteral("\\/"), QStringLiteral("/")); pattern = pattern.mid(2, pattern.length() - 4); pattern = pattern.trimmed(); diff --git a/addons/openheader/plugin_kateopenheader.cpp b/addons/openheader/plugin_kateopenheader.cpp --- a/addons/openheader/plugin_kateopenheader.cpp +++ b/addons/openheader/plugin_kateopenheader.cpp @@ -116,14 +116,14 @@ QString basename = QFileInfo( url.path() ).baseName(); QUrl newURL( url ); - for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) { - setFileName( &newURL,basename + QStringLiteral(".") + *it ); + for(const auto& extension : extensions) { + setFileName( &newURL,basename + QStringLiteral(".") + extension ); KTextEditor::Document *doc= application->findUrl(newURL); if (doc) { application->activeMainWindow()->openUrl(newURL); return true; } - setFileName(&newURL, basename + QStringLiteral(".") + (*it).toUpper() ); + setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper() ); doc= application->findUrl(newURL); if (doc) { application->activeMainWindow()->openUrl(newURL); @@ -145,13 +145,13 @@ QUrl newURL( url ); - for( QStringList::ConstIterator it = extensions.begin(); it != extensions.end(); ++it ) { - setFileName( &newURL,basename + QStringLiteral(".") + *it ); + for(const auto& extension : extensions) { + setFileName( &newURL,basename + QStringLiteral(".") + extension ); if( fileExists( newURL) ) { application->activeMainWindow()->openUrl( newURL ); return; } - setFileName(&newURL, basename + QStringLiteral(".") + (*it).toUpper() ); + setFileName(&newURL, basename + QStringLiteral(".") + extension.toUpper() ); if( fileExists( newURL) ) { application->activeMainWindow()->openUrl( newURL ); return; diff --git a/addons/project/kateprojecttreeviewcontextmenu.cpp b/addons/project/kateprojecttreeviewcontextmenu.cpp --- a/addons/project/kateprojecttreeviewcontextmenu.cpp +++ b/addons/project/kateprojecttreeviewcontextmenu.cpp @@ -91,10 +91,9 @@ */ QMenu *openWithMenu = menu.addMenu(i18n("Open With")); QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename); - KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("Application")); + const KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("Application")); // For each one, insert a menu item... - for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) { - KService::Ptr service = *it; + for (const auto& service : offers) { if (service->name() == QStringLiteral("Kate")) { continue; // omit Kate } diff --git a/addons/search/FolderFilesList.cpp b/addons/search/FolderFilesList.cpp --- a/addons/search/FolderFilesList.cpp +++ b/addons/search/FolderFilesList.cpp @@ -125,21 +125,21 @@ const QFileInfoList currentItems = currentDir.entryInfoList(m_types, filter, QDir::Name | QDir::LocaleAware); bool skip; - for (int i = 0; i typeList; + QVector typeList(tmpTypes.size()); for (int i=0; i excludeList; + QVector excludeList(tmpExcludes.size()); for (int i=0; i mapList; - for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { - QString str = *it; + for (const auto& str : qAsConst(list)) { if (mapList.contains(str.toLower())) { // do not override a previous value, e.g. "Auml" and "auml" are two different // entities, but they should be sorted next to each other. diff --git a/kate/kateapp.h b/kate/kateapp.h --- a/kate/kateapp.h +++ b/kate/kateapp.h @@ -232,8 +232,10 @@ QList mainWindows() { // assemble right list QList windows; - for (int i = 0; i < m_mainWindows.size(); ++i) { - windows.push_back(m_mainWindows[i]->wrapper()); + windows.reserve(m_mainWindows.size()); + + for (const auto mainWindow : qAsConst(m_mainWindows)) { + windows.push_back(mainWindow->wrapper()); } return windows; } diff --git a/kate/kateconfigplugindialogpage.cpp b/kate/kateconfigplugindialogpage.cpp --- a/kate/kateconfigplugindialogpage.cpp +++ b/kate/kateconfigplugindialogpage.cpp @@ -80,10 +80,10 @@ listView->setWhatsThis(i18n("Here you can see all available Kate plugins. Those with a check mark are loaded, and will be loaded again the next time Kate is started.")); KatePluginList &pluginList(KateApp::self()->pluginManager()->pluginList()); - for (KatePluginList::iterator it = pluginList.begin(); it != pluginList.end(); ++it) { - QTreeWidgetItem *item = new KatePluginListItem(it->load, &(*it)); - item->setText(0, it->metaData.name()); - item->setText(1, it->metaData.description()); + for (auto& pluginInfo : pluginList) { + QTreeWidgetItem *item = new KatePluginListItem(pluginInfo.load, &pluginInfo); + item->setText(0, pluginInfo.metaData.name()); + item->setText(1, pluginInfo.metaData.description()); listView->addTopLevelItem(item); } diff --git a/kate/katedocmanager.cpp b/kate/katedocmanager.cpp --- a/kate/katedocmanager.cpp +++ b/kate/katedocmanager.cpp @@ -70,10 +70,10 @@ if (m_daysMetaInfos > 0) { const QStringList groups = m_metaInfos.groupList(); QDateTime def(QDate(1970, 1, 1)); - for (QStringList::const_iterator it = groups.begin(); it != groups.end(); ++it) { - QDateTime last = m_metaInfos.group(*it).readEntry("Time", def); + for (const auto& group : groups) { + QDateTime last = m_metaInfos.group(group).readEntry("Time", def); if (last.daysTo(QDateTime::currentDateTimeUtc()) > m_daysMetaInfos) { - m_metaInfos.deleteGroup(*it); + m_metaInfos.deleteGroup(group); } } } diff --git a/kate/katemainwindow.cpp b/kate/katemainwindow.cpp --- a/kate/katemainwindow.cpp +++ b/kate/katemainwindow.cpp @@ -909,10 +909,9 @@ //qCDebug(LOG_KATE) << "mime type: " << mime.name(); QAction *a = nullptr; - KService::List offers = KMimeTypeTrader::self()->query(mime.name(), QStringLiteral("Application")); + const KService::List offers = KMimeTypeTrader::self()->query(mime.name(), QStringLiteral("Application")); // add all default open-with-actions except "Kate" - for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) { - KService::Ptr service = *it; + for (const auto& service : offers) { if (service->name() == QStringLiteral("Kate")) { continue; } diff --git a/kate/katemdi.cpp b/kate/katemdi.cpp --- a/kate/katemdi.cpp +++ b/kate/katemdi.cpp @@ -669,9 +669,7 @@ // show only correct toolviews, remember persistent values ;) bool anyVis = false; - for (int i = 0; i < m_toolviews.size(); ++i) { - ToolView *tv = m_toolviews[i]; - + for (auto tv : qAsConst(m_toolviews)) { tv->persistent = config.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Persistent").arg(tv->id), false); tv->setToolVisible(config.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Visible").arg(tv->id), false)); @@ -770,8 +768,8 @@ hlayout->addWidget(m_sidebars[KMultiTabBar::Right]); m_sidebars[KMultiTabBar::Right]->setSplitter(m_hSplitter); - for (int i = 0; i < 4; i++) { - connect(m_sidebars[i], &Sidebar::sigShowPluginConfigPage, this, &MainWindow::sigShowPluginConfigPage); + for (const auto sidebar : qAsConst(m_sidebars)) { + connect(sidebar, &Sidebar::sigShowPluginConfigPage, this, &MainWindow::sigShowPluginConfigPage); } } @@ -785,8 +783,8 @@ delete m_centralWidget; // cleanup the sidebars - for (unsigned int i = 0; i < 4; ++i) { - delete m_sidebars[i]; + for (auto sidebar : qAsConst(m_sidebars)) { + delete sidebar; } } @@ -982,17 +980,17 @@ applyMainWindowSettings(cg); // reshuffle toolviews only if needed - for (int i = 0; i < m_toolviews.size(); ++i) { - KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) cg.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Position").arg(m_toolviews[i]->id), int(m_toolviews[i]->sidebar()->position())); + for (const auto tv : qAsConst(m_toolviews)) { + KMultiTabBar::KMultiTabBarPosition newPos = (KMultiTabBar::KMultiTabBarPosition) cg.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Position").arg(tv->id), int(tv->sidebar()->position())); - if (m_toolviews[i]->sidebar()->position() != newPos) { - moveToolView(m_toolviews[i], newPos); + if (tv->sidebar()->position() != newPos) { + moveToolView(tv, newPos); } } // restore the sidebars - for (unsigned int i = 0; i < 4; ++i) { - m_sidebars[i]->restoreSession(cg); + for (auto sidebar : qAsConst(m_sidebars)) { + sidebar->restoreSession(cg); } // restore splitter sizes @@ -1046,8 +1044,8 @@ config.writeEntry("Kate-MDI-Sidebar-Visible", m_sidebarsVisible); // save the sidebars - for (unsigned int i = 0; i < 4; ++i) { - m_sidebars[i]->saveSession(config); + for (auto sidebar : qAsConst(m_sidebars)) { + sidebar->saveSession(config); } } diff --git a/kate/katemwmodonhddialog.cpp b/kate/katemwmodonhddialog.cpp --- a/kate/katemwmodonhddialog.cpp +++ b/kate/katemwmodonhddialog.cpp @@ -96,8 +96,8 @@ twDocuments->setRootIsDecorated(false); m_stateTexts << QString() << i18n("Modified") << i18n("Created") << i18n("Deleted"); - for (int i = 0; i < docs.size(); i++) { - new KateDocItem(docs[i], m_stateTexts[(uint)KateApp::self()->documentManager()->documentInfo(docs[i])->modifiedOnDiscReason ], twDocuments); + for (auto& doc : qAsConst(docs)) { + new KateDocItem(doc, m_stateTexts[(uint)KateApp::self()->documentManager()->documentInfo(doc)->modifiedOnDiscReason ], twDocuments); } twDocuments->header()->setStretchLastSection(false); twDocuments->header()->setSectionResizeMode(0, QHeaderView::Stretch); diff --git a/kate/katepluginmanager.cpp b/kate/katepluginmanager.cpp --- a/kate/katepluginmanager.cpp +++ b/kate/katepluginmanager.cpp @@ -101,8 +101,8 @@ // construct fast lookup map, do this after vector has final size, resize will invalidate the pointers! m_name2Plugin.clear(); - for (int i = 0; i < m_pluginList.size(); ++i) { - m_name2Plugin[m_pluginList[i].saveName()] = &(m_pluginList[i]); + for (auto& pluginInfo : m_pluginList) { + m_name2Plugin[pluginInfo.saveName()] = &pluginInfo; } } @@ -118,25 +118,25 @@ KConfigGroup cg = KConfigGroup(config, QStringLiteral("Kate Plugins")); // disable all plugin if no config, beside the ones marked as default load - for (int i = 0; i < m_pluginList.size(); ++i) { - m_pluginList[i].load = cg.readEntry(m_pluginList[i].saveName(), m_pluginList[i].defaultLoad); + for (auto& pluginInfo: m_pluginList) { + pluginInfo.load = cg.readEntry(pluginInfo.saveName(), pluginInfo.defaultLoad); } } /** * load plugins */ - for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { - if (it->load) { + for (auto& pluginInfo : m_pluginList) { + if (pluginInfo.load) { /** * load plugin + trigger update of GUI for already existing main windows */ - loadPlugin(&(*it)); - enablePluginGUI(&(*it)); + loadPlugin(&pluginInfo); + enablePluginGUI(&pluginInfo); // restore config - if (auto interface = qobject_cast (it->plugin)) { - KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(it->saveName())); + if (auto interface = qobject_cast (pluginInfo.plugin)) { + KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(pluginInfo.saveName())); interface->readSessionConfig(group); } } @@ -163,27 +163,27 @@ void KatePluginManager::unloadAllPlugins() { - for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { - if (it->plugin) { - unloadPlugin(&(*it)); + for (auto& pluginInfo : m_pluginList) { + if (pluginInfo.plugin) { + unloadPlugin(&pluginInfo); } } } void KatePluginManager::enableAllPluginsGUI(KateMainWindow *win, KConfigBase *config) { - for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { - if (it->plugin) { - enablePluginGUI(&(*it), win, config); + for (auto& pluginInfo : m_pluginList) { + if (pluginInfo.plugin) { + enablePluginGUI(&pluginInfo, win, config); } } } void KatePluginManager::disableAllPluginsGUI(KateMainWindow *win) { - for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { - if (it->plugin) { - disablePluginGUI(&(*it), win); + for (auto& pluginInfo : m_pluginList) { + if (pluginInfo.plugin) { + disablePluginGUI(&pluginInfo, win); } } } diff --git a/kate/kateviewmanager.cpp b/kate/kateviewmanager.cpp --- a/kate/kateviewmanager.cpp +++ b/kate/kateviewmanager.cpp @@ -1140,27 +1140,27 @@ parent->setOrientation((Qt::Orientation)config.readEntry("Orientation", int(Qt::Horizontal))); - QStringList children = config.readEntry("Children", QStringList()); - for (QStringList::Iterator it = children.begin(); it != children.end(); ++it) { + const QStringList children = config.readEntry("Children", QStringList()); + for (const auto& str : children) { // for a viewspace, create it and open all documents therein. - if ((*it).startsWith(viewConfGrp + QStringLiteral("-ViewSpace"))) { + if (str.startsWith(viewConfGrp + QStringLiteral("-ViewSpace"))) { KateViewSpace *vs = new KateViewSpace(this, nullptr); m_viewSpaceList.append(vs); // make active so that the view created in restoreConfig has this // new view space as parent. setActiveSpace(vs); parent->addWidget(vs); - vs->restoreConfig(this, configBase, *it); + vs->restoreConfig(this, configBase, str); vs->show(); } else { // for a splitter, recurse auto newContainer = new QSplitter(parent); // we don't allow full collapse, see bug 366014 newContainer->setChildrenCollapsible(false); - restoreSplitter(configBase, *it, newContainer, viewConfGrp); + restoreSplitter(configBase, str, newContainer, viewConfGrp); } }