Commit 6be112d7 authored by Lorenz Haas's avatar Lorenz Haas Committed by David Schulz

Beautifier: Avoid raw loops wherever applicable

Change-Id: I8b595ce0f7b3544466c6308457bf22826d1dafeb
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent e643383c
......@@ -119,8 +119,7 @@ QString ArtisticStyle::configurationFile() const
if (const ProjectExplorer::Project *project
= ProjectExplorer::ProjectTree::currentProject()) {
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
for (int i = 0, total = files.size(); i < total; ++i) {
const QString &file = files.at(i);
foreach (const QString &file, files) {
if (!file.endsWith(QLatin1String(".astylerc")))
continue;
const QFileInfo fi(file);
......
......@@ -180,11 +180,10 @@ void ArtisticStyleSettings::createDocumentationFile() const
// astyle writes its output to 'error'...
const QStringList lines = QString::fromUtf8(process.readAllStandardError())
.split(QLatin1Char('\n'));
const int totalLines = lines.count();
QStringList keys;
QStringList docu;
for (int i = 0; i < totalLines; ++i) {
const QString &line = lines.at(i).trimmed();
foreach (QString line, lines) {
line = line.trimmed();
if ((line.startsWith(QLatin1String("--")) && !line.startsWith(QLatin1String("---")))
|| line.startsWith(QLatin1String("OR "))) {
QStringList rawKeys = line.split(QLatin1String(" OR "), QString::SkipEmptyParts);
......
......@@ -98,12 +98,11 @@ bool BeautifierPlugin::initialize(const QStringList &arguments, QString *errorSt
menu->menu()->setTitle(QCoreApplication::translate("Beautifier", Constants::OPTION_TR_CATEGORY));
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(menu);
for (int i = 0, total = m_tools.count(); i < total; ++i) {
BeautifierAbstractTool *tool = m_tools.at(i);
foreach (BeautifierAbstractTool *tool, m_tools) {
tool->initialize();
const QList<QObject *> autoReleasedObjects = tool->autoReleaseObjects();
for (int j = 0, total = autoReleasedObjects.count(); j < total; ++j)
addAutoReleasedObject(autoReleasedObjects.at(j));
foreach (QObject *object, autoReleasedObjects)
addAutoReleasedObject(object);
}
// The single shot is needed, otherwise the menu will stay disabled even
......@@ -127,8 +126,8 @@ ExtensionSystem::IPlugin::ShutdownFlag BeautifierPlugin::aboutToShutdown()
void BeautifierPlugin::updateActions(Core::IEditor *editor)
{
for (int i = 0, total = m_tools.count(); i < total; ++i)
m_tools.at(i)->updateActions(editor);
foreach (BeautifierAbstractTool *tool, m_tools)
tool->updateActions(editor);
}
// Use pipeError() instead of calling showError() because this function may run in another thread.
......@@ -323,9 +322,7 @@ void BeautifierPlugin::formatCurrentFileContinue(QObject *watcher)
int newCursorPos = charactersInfrontOfCursor;
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
const int diffSize = diff.size();
for (int i = 0; i < diffSize; ++i) {
const DiffEditor::Diff d = diff.at(i);
foreach (const DiffEditor::Diff &d, diff) {
switch (d.command) {
case DiffEditor::Diff::Insert:
{
......@@ -396,9 +393,8 @@ void BeautifierPlugin::formatCurrentFileContinue(QObject *watcher)
+ absoluteVerticalCursorOffset / fontHeight);
// Restore folded blocks
const QTextDocument *doc = textEditor->document();
const int total = foldedBlocks.size();
for (int i = 0; i < total; ++i) {
QTextBlock block = doc->findBlockByNumber(qMax(0, foldedBlocks.at(i)));
foreach (const int blockId, foldedBlocks) {
QTextBlock block = doc->findBlockByNumber(qMax(0, blockId));
if (block.isValid())
TextDocumentLayout::doFoldOrUnfold(block, false);
}
......
......@@ -136,9 +136,7 @@ void ClangFormatSettings::createDocumentationFile() const
<< QLatin1String("TabWidth {unsigned}")
<< QLatin1String("UseTab {UseTabStyle: UT_Never, UT_ForIndentation, UT_Always}");
const int totalLines = lines.count();
for (int i = 0; i < totalLines; ++i) {
const QString& line = lines.at(i);
foreach (const QString& line, lines) {
const int firstSpace = line.indexOf(QLatin1Char(' '));
const QString keyword = line.left(firstSpace);
const QString options = line.right(line.size() - firstSpace).trimmed();
......
......@@ -156,8 +156,7 @@ QString Uncrustify::configurationFile() const
if (const ProjectExplorer::Project *project
= ProjectExplorer::ProjectTree::currentProject()) {
const QStringList files = project->files(ProjectExplorer::Project::AllFiles);
for (int i = 0, total = files.size(); i < total; ++i) {
const QString &file = files.at(i);
foreach (const QString &file, files) {
if (!file.endsWith(QLatin1String("cfg")))
continue;
const QFileInfo fi(file);
......
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