Commit f672bff3 authored by Friedemann Kleint's avatar Friedemann Kleint

Fix some code scanning issues.

foreach()-Loops.
parent 0f6551c4
......@@ -83,8 +83,12 @@ void PluginDetailsView::update(PluginSpec *spec)
m_ui->copyright->setText(spec->copyright());
m_ui->license->setText(spec->license());
QStringList depStrings;
foreach (PluginDependency dep, spec->dependencies()) {
depStrings << QString("%1 (%2)").arg(dep.name).arg(dep.version);
foreach (const PluginDependency &dep, spec->dependencies()) {
QString depString = dep.name;
depString += QLatin1String(" (");
depString += dep.version;
depString += QLatin1Char(')');
depStrings.append(depString);
}
m_ui->dependencies->addItems(depStrings);
}
......@@ -95,7 +95,7 @@ void runFileSearch(QFutureInterface<FileSearchResult> &future,
QFile file;
QBuffer buffer;
foreach (QString s, files) {
foreach (const QString &s, files) {
if (future.isPaused())
future.waitForResume();
if (future.isCanceled()) {
......
......@@ -180,7 +180,7 @@ bool CMakeProject::parseCMakeLists()
QSet<QString> projectFiles;
if (cbpparser.hasCMakeFiles()) {
fileList.append(cbpparser.cmakeFileList());
foreach(ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
foreach(const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
projectFiles.insert(node->path());
} else {
// Manually add the CMakeLists.txt file
......@@ -219,7 +219,7 @@ bool CMakeProject::parseCMakeLists()
QStringList allIncludePaths;
QStringList allFrameworkPaths;
QList<ProjectExplorer::HeaderPath> allHeaderPaths = activeBC->toolChain()->systemHeaderPaths();
foreach (ProjectExplorer::HeaderPath headerPath, allHeaderPaths) {
foreach (const ProjectExplorer::HeaderPath &headerPath, allHeaderPaths) {
if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath)
allFrameworkPaths.append(headerPath.path());
else
......
......@@ -1550,7 +1550,7 @@ QByteArray EditorManager::saveState() const
QList<OpenEditorsModel::Entry> entries = m_d->m_editorModel->entries();
stream << entries.count();
foreach (OpenEditorsModel::Entry entry, entries) {
foreach (const OpenEditorsModel::Entry &entry, entries) {
stream << entry.fileName() << entry.displayName() << entry.id().toUtf8();
}
......
......@@ -67,7 +67,7 @@ int OpenEditorsModel::rowCount(const QModelIndex &parent) const
QList<IEditor *> OpenEditorsModel::editors() const
{
QList<IEditor *> result;
foreach (Entry entry, m_editors)
foreach (const Entry &entry, m_editors)
if (entry.editor)
result += entry.editor;
return result;
......@@ -207,7 +207,7 @@ bool OpenEditorsModel::isDuplicate(IEditor *editor) const
IEditor *OpenEditorsModel::originalForDuplicate(IEditor *duplicate) const
{
IFile *file = duplicate->file();
foreach(Entry e, m_editors)
foreach(const Entry &e, m_editors)
if (e.editor && e.editor->file() == file)
return e.editor;
return 0;
......
......@@ -245,7 +245,7 @@ void OpenEditorsWindow::setEditors(EditorView *mainView, EditorView *view, OpenE
}
// add purely restored editors which are not initialised yet
foreach (OpenEditorsModel::Entry entry, model->entries()) {
foreach (const OpenEditorsModel::Entry &entry, model->entries()) {
if (entry.editor)
continue;
QTreeWidgetItem *item = new QTreeWidgetItem();
......
......@@ -96,7 +96,7 @@ void GeneralSettings::fillLanguageBox() const
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("*.qm")));
const QString currentLocale = language();
Q_FOREACH(const QString languageFile, languageFiles)
Q_FOREACH(const QString &languageFile, languageFiles)
{
int start = languageFile.lastIndexOf(QLatin1Char('_'))+1;
int end = languageFile.lastIndexOf(QLatin1Char('.'));
......
......@@ -496,7 +496,7 @@ unsigned MimeType::matchesFile(const QFileInfo &file) const
unsigned MimeType::matchesFile(Internal::FileMatchContext &c) const
{
// check globs
foreach (QRegExp pattern, m_d->globPatterns) {
foreach (const QRegExp &pattern, m_d->globPatterns) {
if (pattern.exactMatch(c.fileName()))
return GlobMatchPriority;
}
......@@ -507,7 +507,7 @@ unsigned MimeType::matchesFile(Internal::FileMatchContext &c) const
const QByteArray data = c.data();
if (!data.isEmpty()) {
foreach (MimeTypeData::IMagicMatcherSharedPointer matcher, m_d->magicMatchers) {
foreach (const MimeTypeData::IMagicMatcherSharedPointer &matcher, m_d->magicMatchers) {
if (matcher->matches(data))
return matcher->priority();
}
......
......@@ -160,7 +160,7 @@ int PasteView::show(const QString &user, const QString &description, const QStri
QByteArray content;
m_parts = parts;
m_ui.uiPatchList->clear();
foreach (const FileData part, parts) {
foreach (const FileData &part, parts) {
QListWidgetItem *itm = new QListWidgetItem(part.filename, m_ui.uiPatchList);
itm->setCheckState(Qt::Checked);
itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
......
......@@ -289,7 +289,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
// We only want to show F1 if the tooltip matches the help id
bool showF1 = true;
foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) {
foreach (const Document::DiagnosticMessage &m, doc->diagnosticMessages()) {
if (m.line() == lineNumber) {
m_toolTip = m.text();
showF1 = false;
......
......@@ -1178,7 +1178,7 @@ bool CppCodeCompletion::completeScope(const QList<LookupItem> &results,
{
QList<Symbol *> classes, namespaces;
foreach (LookupItem result, results) {
foreach (const LookupItem &result, results) {
FullySpecifiedType ty = result.type();
if (Class *classTy = ty->asClassType())
......@@ -1489,7 +1489,7 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
} else if (m_completionOperator == T_LPAREN ||
m_completionOperator == T_SIGNAL ||
m_completionOperator == T_SLOT) {
foreach (TextEditor::CompletionItem item, m_completions) {
foreach (const TextEditor::CompletionItem &item, m_completions) {
if (item.text.startsWith(key, Qt::CaseInsensitive)) {
completions->append(item);
}
......
......@@ -847,7 +847,7 @@ QFuture<void> CppModelManager::refreshSourceFiles(const QStringList &sourceFiles
m_synchronizer.clearFutures();
foreach (QFuture<void> future, futures) {
foreach (const QFuture<void> &future, futures) {
if (! (future.isFinished() || future.isCanceled()))
m_synchronizer.addFuture(future);
}
......
......@@ -349,8 +349,10 @@ void DebuggerOutputWindow::showOutput(int channel, const QString &output)
foreach (QString line, output.split('\n')) {
// FIXME: QTextEdit asserts on really long lines...
const int n = 30000;
if (line.size() > n)
line = line.left(n) + " [...] <cut off>";
if (line.size() > n) {
line.truncate(n);
line += QLatin1String(" [...] <cut off>");
}
if (line != QLatin1String("(gdb) "))
m_combinedText->appendPlainText(charForChannel(channel) + line);
}
......
......@@ -247,7 +247,7 @@ struct Range
QDebug &operator<<(QDebug &ts, const QList<QTextEdit::ExtraSelection> &sels)
{
foreach (QTextEdit::ExtraSelection sel, sels)
foreach (const QTextEdit::ExtraSelection &sel, sels)
ts << "SEL: " << sel.cursor.anchor() << sel.cursor.position();
return ts;
}
......
......@@ -99,8 +99,8 @@ void FilterSettingsPage::updateFilterPage()
help.setupData();
m_filterMapBackup.clear();
const QStringList filters = help.customFilters();
foreach (const QString filter, filters) {
QStringList atts = help.filterAttributes(filter);
foreach (const QString &filter, filters) {
const QStringList atts = help.filterAttributes(filter);
m_filterMapBackup.insert(filter, atts);
if (!m_filterMap.contains(filter))
m_filterMap.insert(filter, atts);
......@@ -108,8 +108,8 @@ void FilterSettingsPage::updateFilterPage()
m_ui.filterWidget->addItems(m_filterMap.keys());
foreach (const QString a, help.filterAttributes())
new QTreeWidgetItem(m_ui.attributeWidget, QStringList() << a);
foreach (const QString &a, help.filterAttributes())
new QTreeWidgetItem(m_ui.attributeWidget, QStringList(a));
if (m_filterMap.keys().count())
m_ui.filterWidget->setCurrentRow(0);
......@@ -215,7 +215,7 @@ bool FilterSettingsPage::applyChanges()
}
}
if (changed) {
foreach (QString filter, m_removedFilters)
foreach (const QString &filter, m_removedFilters)
m_helpEngine->removeCustomFilter(filter);
QMapIterator<QString, QStringList> it(m_filterMap);
while (it.hasNext()) {
......
......@@ -57,7 +57,7 @@ BuildStepsPage::BuildStepsPage(Project *project, bool clean) :
BuildStepsPage::~BuildStepsPage()
{
foreach(BuildStepsWidgetStruct s, m_buildSteps) {
foreach(const BuildStepsWidgetStruct &s, m_buildSteps) {
delete s.widget;
delete s.detailsWidget;
}
......
......@@ -99,8 +99,10 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project)
QTextCodec *codec = QTextCodec::codecForMib(mib);
m_codecs += codec;
QString name = codec->name();
foreach (QByteArray alias, codec->aliases())
name += QString(QLatin1String(" / ") + alias);
foreach (const QByteArray &alias, codec->aliases()) {
name += QLatin1String(" / ");
name += QString::fromLatin1(alias);
}
m_ui.encodingComboBox->addItem(name);
if (defaultTextCodec == codec)
m_ui.encodingComboBox->setCurrentIndex(i);
......
......@@ -143,7 +143,7 @@ void PersistentSettingsWriter::writeValue(QDomElement &ps, const QVariant &varia
QDomElement values = ps.ownerDocument().createElement("valuelist");
values.setAttribute("type", QVariant::typeToName(QVariant::List));
QList<QVariant> varList = variant.toList();
foreach (QVariant var, varList) {
foreach (const QVariant &var, varList) {
writeValue(values, var);
}
ps.appendChild(values);
......
......@@ -477,7 +477,7 @@ void Qt4Project::updateCodeModel()
//foreach(const HeaderPath &hp, tc->systemHeaderPaths())
// qDebug()<<hp.path();
}
foreach (HeaderPath headerPath, allHeaderPaths) {
foreach (const HeaderPath &headerPath, allHeaderPaths) {
if (headerPath.kind() == HeaderPath::FrameworkHeaderPath)
predefinedFrameworkPaths.append(headerPath.path());
else
......@@ -531,7 +531,7 @@ void Qt4Project::updateCodeModel()
allPrecompileHeaders.append(info.precompiledHeader);
// Add custom defines
foreach (const QString def, pro->variableValue(DefinesVar)) {
foreach (const QString &def, pro->variableValue(DefinesVar)) {
definedMacros += "#define ";
info.defines += "#define ";
const int index = def.indexOf(QLatin1Char('='));
......
......@@ -327,7 +327,7 @@ void QtVersionManager::addNewVersionsFromInstaller()
QStringList newVersionsList = newVersionsValue.split(';', QString::SkipEmptyParts);
bool defaultVersionWasReset = false;
foreach (QString newVersion, newVersionsList) {
foreach (const QString &newVersion, newVersionsList) {
QStringList newVersionData = newVersion.split('=');
if (newVersionData.count() >= 2) {
if (QFile::exists(newVersionData[1])) {
......@@ -750,7 +750,7 @@ QtVersion *QtVersionManager::qtVersionForQMakeBinary(const QString &qmakePath)
void dumpQMakeAssignments(const QList<QMakeAssignment> &list)
{
foreach(QMakeAssignment qa, list) {
foreach(const QMakeAssignment &qa, list) {
qDebug()<<qa.variable<<qa.op<<qa.value;
}
}
......@@ -789,11 +789,11 @@ QPair<QtVersion::QmakeBuildConfigs, QStringList> QtVersionManager::scanMakeFile(
dumpQMakeAssignments(assignments);
result2.append(additionalArguments);
foreach(QMakeAssignment qa, assignments)
foreach(const QMakeAssignment &qa, assignments)
result2.append(qa.variable + qa.op + qa.value);
if (!afterAssignments.isEmpty()) {
result2.append("-after");
foreach(QMakeAssignment qa, afterAssignments)
foreach(const QMakeAssignment &qa, afterAssignments)
result2.append(qa.variable + qa.op + qa.value);
}
}
......@@ -918,7 +918,7 @@ QtVersion::QmakeBuildConfigs QtVersionManager::qmakeBuildConfigFromCmdArgs(QList
QtVersion::QmakeBuildConfigs result = defaultBuildConfig;
QList<QMakeAssignment> oldAssignments = *assignments;
assignments->clear();
foreach(QMakeAssignment qa, oldAssignments) {
foreach(const QMakeAssignment &qa, oldAssignments) {
if (qa.variable == "CONFIG") {
QStringList values = qa.value.split(' ');
QStringList newValues;
......@@ -1100,7 +1100,7 @@ QList<QSharedPointer<ProjectExplorer::ToolChain> > QtVersion::toolChains() const
ProjectExplorer::ToolChain *QtVersion::toolChain(ProjectExplorer::ToolChain::ToolChainType type) const
{
foreach(QSharedPointer<ProjectExplorer::ToolChain> tcptr, toolChains())
foreach(const QSharedPointer<ProjectExplorer::ToolChain> &tcptr, toolChains())
if (tcptr->type() == type)
return tcptr.data();
return 0;
......@@ -1109,7 +1109,7 @@ ProjectExplorer::ToolChain *QtVersion::toolChain(ProjectExplorer::ToolChain::Too
QList<ProjectExplorer::ToolChain::ToolChainType> QtVersion::possibleToolChainTypes() const
{
QList<ProjectExplorer::ToolChain::ToolChainType> types;
foreach(QSharedPointer<ProjectExplorer::ToolChain> tc, toolChains())
foreach(const QSharedPointer<ProjectExplorer::ToolChain> &tc, toolChains())
types << tc->type();
return types;
}
......
......@@ -4689,7 +4689,7 @@ void BaseTextEditor::_q_matchParentheses()
if (animatePosition >= 0) {
foreach (QTextEdit::ExtraSelection sel, BaseTextEditor::extraSelections(ParenthesesMatchingSelection)) {
foreach (const QTextEdit::ExtraSelection &sel, BaseTextEditor::extraSelections(ParenthesesMatchingSelection)) {
if (sel.cursor.selectionStart() == animatePosition
|| sel.cursor.selectionEnd() - 1 == animatePosition) {
animatePosition = -1;
......
......@@ -105,7 +105,7 @@ CodecSelector::CodecSelector(QWidget *parent, BaseTextDocument *doc)
continue;
}
QString names = QString::fromLatin1(c->name());
foreach (QByteArray alias, c->aliases())
foreach (const QByteArray &alias, c->aliases())
names += QLatin1String(" / ") + QString::fromLatin1(alias);
if (doc->codec() == c)
currentIndex = encodings.count();
......
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