Commit 166828e8 authored by Christoph Cullmann's avatar Christoph Cullmann

Use range loop if possible

Summary: It (should) simplify code a bit. It some cases prevents copying strings, shared_ptrs.

Reviewers: #kate, cullmann

Reviewed By: #kate, cullmann

Subscribers: cullmann, kwrite-devel, #kate

Tags: #kate

Differential Revision: https://phabricator.kde.org/D23010
parent 09427e8c
......@@ -82,9 +82,9 @@ CloseConfirmDialog::CloseConfirmDialog(
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);
......
......@@ -149,24 +149,36 @@ void KateFileBrowserConfigPage::init()
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 @@ void KateFileBrowserConfigPage::init()
// 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 );
}
}
}
......
......@@ -295,10 +295,9 @@ void KateFileTree::slotFixOpenWithMenu()
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;
}
......
......@@ -120,8 +120,8 @@ bool DebugView::debuggerBusy() const
bool DebugView::hasBreakpoint(const QUrl& url, int line)
{
for (int i = 0; i<m_breakPointList.size(); i++) {
if ((url == m_breakPointList[i].file) && (line == m_breakPointList[i].line)) {
for (const auto& breakpoint : qAsConst(m_breakPointList)) {
if ((url == breakpoint.file) && (line == breakpoint.line)) {
return true;
}
}
......
......@@ -343,14 +343,14 @@ void KateCTagsView::displayHits(const Tags::TagList &list)
}
m_ctagsUi.tagTreeWidget->setSortingEnabled(false);
for (int i=0; i<list.size(); i++) {
for (const auto& tag : list) {
QTreeWidgetItem* item = new QTreeWidgetItem(m_ctagsUi.tagTreeWidget);
item->setText(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();
......
......@@ -116,14 +116,14 @@ bool PluginKateOpenHeader::tryOpenInternal( const QUrl& url, const QStringList&
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 @@ void PluginKateOpenHeader::tryOpen( const QUrl& url, const QStringList& extensio
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;
......
......@@ -91,10 +91,9 @@ void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint
*/
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
}
......
......@@ -125,21 +125,21 @@ void FolderFilesList::checkNextItem(const QFileInfo &item)
const QFileInfoList currentItems = currentDir.entryInfoList(m_types, filter, QDir::Name | QDir::LocaleAware);
bool skip;
for (int i = 0; i<currentItems.size(); ++i) {
for (const auto& currentItem : currentItems) {
skip = false;
for (int j=0; j<m_excludeList.size(); j++) {
for (const auto& regex : qAsConst(m_excludeList)) {
QString matchString = currentItems[i].filePath();
if (currentItems[i].filePath().startsWith(m_folder)) {
matchString = currentItems[i].filePath().mid(m_folder.size());
QString matchString = currentItem.filePath();
if (currentItem.filePath().startsWith(m_folder)) {
matchString = currentItem.filePath().mid(m_folder.size());
}
if (m_excludeList[j].exactMatch(matchString)) {
if (regex.exactMatch(matchString)) {
skip = true;
break;
}
}
if (!skip) {
checkNextItem(currentItems[i]);
checkNextItem(currentItem);
}
}
}
......
......@@ -549,7 +549,7 @@ QStringList KatePluginSearchView::filterFiles(const QStringList& files) const
}
QStringList tmpTypes = types.split(QLatin1Char(','));
QVector<QRegExp> typeList;
QVector<QRegExp> typeList(tmpTypes.size());
for (int i=0; i<tmpTypes.size(); i++) {
QRegExp rx(tmpTypes[i].trimmed());
rx.setPatternSyntax(QRegExp::Wildcard);
......@@ -557,7 +557,7 @@ QStringList KatePluginSearchView::filterFiles(const QStringList& files) const
}
QStringList tmpExcludes = excludes.split(QLatin1Char(','));
QVector<QRegExp> excludeList;
QVector<QRegExp> excludeList(tmpExcludes.size());
for (int i=0; i<tmpExcludes.size(); i++) {
QRegExp rx(tmpExcludes[i].trimmed());
rx.setPatternSyntax(QRegExp::Wildcard);
......@@ -573,8 +573,8 @@ QStringList KatePluginSearchView::filterFiles(const QStringList& files) const
}
bool skip = false;
for (int i=0; i<excludeList.size(); i++) {
if (excludeList[i].exactMatch(nameToCheck)) {
for (const auto& regex : qAsConst(excludeList)) {
if (regex.exactMatch(nameToCheck)) {
skip = true;
break;
}
......@@ -584,8 +584,8 @@ QStringList KatePluginSearchView::filterFiles(const QStringList& files) const
}
for (int i=0; i<typeList.size(); i++) {
if (typeList[i].exactMatch(nameToCheck)) {
for (const auto& regex : qAsConst(typeList)) {
if (regex.exactMatch(nameToCheck)) {
filteredFiles << fileName;
break;
}
......
......@@ -176,8 +176,8 @@ bool SnippetCompletionModel::shouldAbortCompletion(KTextEditor::View* view, cons
return true; //Always abort when the completion-range has been left
}
for ( int i = 0; i < currentCompletion.length(); ++i ) {
if ( currentCompletion.at(i).isSpace() ) {
for (const auto token : currentCompletion) {
if ( token.isSpace() ) {
return true;
}
}
......
......@@ -1033,8 +1033,7 @@ QStringList PluginKateXMLToolsCompletionModel::sortQStringList(QStringList list)
// Sort list case-insensitive. This looks complicated but using a QMap
// is even suggested by the Qt documentation.
QMap<QString, QString> 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.
......
......@@ -232,8 +232,10 @@ public Q_SLOTS:
QList<KTextEditor::MainWindow *> mainWindows() {
// assemble right list
QList<KTextEditor::MainWindow *> 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;
}
......
......@@ -80,10 +80,10 @@ KateConfigPluginPage::KateConfigPluginPage(QWidget *parent, KateConfigDialog *di
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);
}
......
......@@ -70,10 +70,10 @@ KateDocManager::~KateDocManager()
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);
}
}
}
......
......@@ -909,10 +909,9 @@ void KateMainWindow::mSlotFixOpenWithMenu()
//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;
}
......
......@@ -669,9 +669,7 @@ void Sidebar::restoreSession(KConfigGroup &config)
// 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 @@ MainWindow::MainWindow(QWidget *parentWidget)
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 @@ MainWindow::~MainWindow()
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 @@ void MainWindow::finishRestore()
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 @@ void MainWindow::saveSession(KConfigGroup &config)
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);
}
}
......
......@@ -96,8 +96,8 @@ KateMwModOnHdDialog::KateMwModOnHdDialog(DocVector docs, QWidget *parent, const
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);
......
......@@ -101,8 +101,8 @@ void KatePluginManager::setupPluginList()
// 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 @@ void KatePluginManager::loadConfig(KConfig *config)
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<KTextEditor::SessionConfigInterface *> (it->plugin)) {
KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(it->saveName()));
if (auto interface = qobject_cast<KTextEditor::SessionConfigInterface *> (pluginInfo.plugin)) {
KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(pluginInfo.saveName()));
interface->readSessionConfig(group);
}
}
......@@ -163,27 +163,27 @@ void KatePluginManager::writeConfig(KConfig *config)
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);
}
}
}
......
......@@ -1140,10 +1140,10 @@ void KateViewManager::restoreSplitter(const KConfigBase *configBase, const QStri
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
......@@ -1151,7 +1151,7 @@ void KateViewManager::restoreSplitter(const KConfigBase *configBase, const QStri
setActiveSpace(vs);
parent->addWidget(vs);
vs->restoreConfig(this, configBase, *it);
vs->restoreConfig(this, configBase, str);
vs->show();
} else {
// for a splitter, recurse
......@@ -1160,7 +1160,7 @@ void KateViewManager::restoreSplitter(const KConfigBase *configBase, const QStri
// we don't allow full collapse, see bug 366014
newContainer->setChildrenCollapsible(false);
restoreSplitter(configBase, *it, newContainer, viewConfGrp);
restoreSplitter(configBase, str, newContainer, viewConfGrp);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment