forked from qt-creator/qt-creator
Debugger: Remove foreach / Q_FOREACH usage
Task-number: QTCREATORBUG-27464 Change-Id: Ib49afb4d0283aeeffead6b31e1a3d0bcb9a7ae14 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -1611,7 +1611,8 @@ void DebuggerEnginePrivate::cleanupViews()
|
||||
const bool closeMemory = debuggerSettings()->closeMemoryBuffersOnExit.value();
|
||||
|
||||
QList<IDocument *> toClose;
|
||||
foreach (IDocument *document, DocumentModel::openedDocuments()) {
|
||||
const QList<IDocument *> documents = DocumentModel::openedDocuments();
|
||||
for (IDocument *document : documents) {
|
||||
const bool isMemory = document->property(Constants::OPENED_WITH_DISASSEMBLY).toBool();
|
||||
if (document->property(Constants::OPENED_BY_DEBUGGER).toBool()) {
|
||||
bool keepIt = true;
|
||||
@@ -2501,8 +2502,8 @@ void DebuggerEngine::handleExecRunToSelectedFunction()
|
||||
QString functionName = cursor.selectedText();
|
||||
if (functionName.isEmpty()) {
|
||||
const QTextBlock block = cursor.block();
|
||||
const QString line = block.text();
|
||||
foreach (const QString &str, line.trimmed().split('(')) {
|
||||
const QStringList lineList = block.text().trimmed().split('(');
|
||||
for (const QString &str : lineList) {
|
||||
QString a;
|
||||
for (int i = str.size(); --i >= 0; ) {
|
||||
if (!str.at(i).isLetterOrNumber())
|
||||
|
@@ -213,7 +213,7 @@ void DebuggerRunTool::setStartMode(DebuggerStartMode startMode)
|
||||
projects.removeOne(startupProject);
|
||||
projects.insert(0, startupProject);
|
||||
}
|
||||
foreach (Project *project, projects)
|
||||
for (Project *project : qAsConst(projects))
|
||||
m_runParameters.projectSourceFiles.append(project->files(Project::SourceFiles));
|
||||
if (!projects.isEmpty())
|
||||
m_runParameters.projectSourceDirectory = projects.first()->projectDirectory();
|
||||
|
@@ -1319,7 +1319,8 @@ void DebuggerToolTipManagerPrivate::leavingDebugMode()
|
||||
hideAllToolTips();
|
||||
if (QWidget *topLevel = ICore::mainWindow()->topLevelWidget())
|
||||
topLevel->removeEventFilter(this);
|
||||
foreach (IEditor *e, DocumentModel::editorsForOpenedDocuments()) {
|
||||
const QList<IEditor *> editors = DocumentModel::editorsForOpenedDocuments();
|
||||
for (IEditor *e : editors) {
|
||||
if (auto toolTipEditor = qobject_cast<BaseTextEditor *>(e)) {
|
||||
toolTipEditor->editorWidget()->verticalScrollBar()->disconnect(this);
|
||||
toolTipEditor->editorWidget()->disconnect(this);
|
||||
|
@@ -265,7 +265,8 @@ void DisassemblerAgentPrivate::configureMimeType()
|
||||
|
||||
Utils::MimeType mtype = Utils::mimeTypeForName(mimeType);
|
||||
if (mtype.isValid()) {
|
||||
foreach (IEditor *editor, DocumentModel::editorsForDocument(document))
|
||||
const QList<IEditor *> editors = DocumentModel::editorsForDocument(document);
|
||||
for (IEditor *editor : editors)
|
||||
if (auto widget = TextEditorWidget::fromEditor(editor))
|
||||
widget->configureGenericHighlighter();
|
||||
} else {
|
||||
|
@@ -818,13 +818,13 @@ void GdbEngine::commandTimeout()
|
||||
QList<int> keys = m_commandForToken.keys();
|
||||
Utils::sort(keys);
|
||||
bool killIt = false;
|
||||
foreach (int key, keys) {
|
||||
for (int key : qAsConst(keys)) {
|
||||
const DebuggerCommand &cmd = m_commandForToken.value(key);
|
||||
killIt = true;
|
||||
showMessage(QString::number(key) + ": " + cmd.function);
|
||||
}
|
||||
QStringList commands;
|
||||
foreach (const DebuggerCommand &cmd, m_commandForToken)
|
||||
for (const DebuggerCommand &cmd : qAsConst(m_commandForToken))
|
||||
commands << QString("\"%1\"").arg(cmd.function);
|
||||
if (killIt) {
|
||||
showMessage(QString("TIMED OUT WAITING FOR GDB REPLY. "
|
||||
@@ -2606,7 +2606,7 @@ void GdbEngine::insertBreakpoint(const Breakpoint &bp)
|
||||
QVariant tpCaps = bp->property(tracepointCapturePropertyName);
|
||||
if (tpCaps.isValid()) {
|
||||
QJsonArray caps;
|
||||
foreach (const auto &tpCap, tpCaps.toList()) {
|
||||
for (const QVariant &tpCap : tpCaps.toList()) {
|
||||
TracepointCaptureData data = tpCap.value<TracepointCaptureData>();
|
||||
QJsonArray cap;
|
||||
cap.append(static_cast<int>(data.type));
|
||||
@@ -2844,7 +2844,8 @@ static void handleShowModuleSymbols(const DebuggerResponse &response,
|
||||
// Object file /opt/dev/qt/lib/libQtNetworkMyns.so.4:
|
||||
// [ 0] A 0x16bd64 _DYNAMIC moc_qudpsocket.cpp
|
||||
// [12] S 0xe94680 _ZN4myns5QFileC1Ev section .plt myns::QFile::QFile()
|
||||
foreach (const QString &line, QString::fromLocal8Bit(file.readAll()).split('\n')) {
|
||||
const QStringList lines = QString::fromLocal8Bit(file.readAll()).split('\n');
|
||||
for (const QString &line : lines) {
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
if (line.at(0) != '[')
|
||||
@@ -2928,7 +2929,7 @@ void GdbEngine::handleShowModuleSections(const DebuggerResponse &response,
|
||||
const QString needle = prefix + moduleName;
|
||||
Sections sections;
|
||||
bool active = false;
|
||||
foreach (const QString &line, lines) {
|
||||
for (const QString &line : qAsConst(lines)) {
|
||||
if (line.startsWith(prefix)) {
|
||||
if (active)
|
||||
break;
|
||||
@@ -3752,7 +3753,8 @@ bool GdbEngine::handleCliDisassemblerResult(const QString &output, DisassemblerA
|
||||
// First line is something like
|
||||
// "Dump of assembler code from 0xb7ff598f to 0xb7ff5a07:"
|
||||
DisassemblerLines dlines;
|
||||
foreach (const QString &line, output.split('\n'))
|
||||
const QStringList lineList = output.split('\n');
|
||||
for (const QString &line : lineList)
|
||||
dlines.appendUnparsed(line);
|
||||
|
||||
QVector<DisassemblerLine> lines = dlines.data();
|
||||
@@ -3829,10 +3831,10 @@ void GdbEngine::setupEngine()
|
||||
gdbCommand.addArg("--tty=" + m_outputCollector.serverName());
|
||||
}
|
||||
|
||||
const QString tests = QString::fromLocal8Bit(qgetenv("QTC_DEBUGGER_TESTS"));
|
||||
foreach (const QString &test, tests.split(','))
|
||||
const QStringList testList = QString::fromLocal8Bit(qgetenv("QTC_DEBUGGER_TESTS")).split(',');
|
||||
for (const QString &test : testList)
|
||||
m_testCases.insert(test.toInt());
|
||||
foreach (int test, m_testCases)
|
||||
for (int test : qAsConst(m_testCases))
|
||||
showMessage("ENABLING TEST CASE: " + QString::number(test));
|
||||
|
||||
m_expectTerminalTrap = terminal();
|
||||
@@ -4052,7 +4054,8 @@ void GdbEngine::setEnvironmentVariables()
|
||||
|
||||
Environment sysEnv = Environment::systemEnvironment();
|
||||
Environment runEnv = runParameters().inferior.environment;
|
||||
foreach (const EnvironmentItem &item, sysEnv.diff(runEnv)) {
|
||||
const NameValueItems items = sysEnv.diff(runEnv);
|
||||
for (const EnvironmentItem &item : items) {
|
||||
// imitate the weird windows gdb behavior of setting the case of the path environment
|
||||
// variable name to an all uppercase PATH
|
||||
const QString name = isWindowsPath(item.name) ? "PATH" : item.name;
|
||||
@@ -4103,8 +4106,8 @@ void GdbEngine::abortDebuggerProcess()
|
||||
void GdbEngine::resetInferior()
|
||||
{
|
||||
if (!runParameters().commandsForReset.isEmpty()) {
|
||||
const QString commands = expand(runParameters().commandsForReset);
|
||||
foreach (QString command, commands.split('\n')) {
|
||||
const QStringList commands = expand(runParameters().commandsForReset).split('\n');
|
||||
for (QString command : commands) {
|
||||
command = command.trimmed();
|
||||
if (!command.isEmpty())
|
||||
runCommand({command, ConsoleCommand | NeedsTemporaryStop | NativeCommand});
|
||||
@@ -4185,7 +4188,7 @@ void GdbEngine::resetCommandQueue()
|
||||
QString msg;
|
||||
QTextStream ts(&msg);
|
||||
ts << "RESETING COMMAND QUEUE. LEFT OVER TOKENS: ";
|
||||
foreach (const DebuggerCommand &cmd, m_commandForToken)
|
||||
for (const DebuggerCommand &cmd : qAsConst(m_commandForToken))
|
||||
ts << "CMD:" << cmd.function;
|
||||
m_commandForToken.clear();
|
||||
m_flagsForToken.clear();
|
||||
|
@@ -472,7 +472,8 @@ void QmlEngine::gotoLocation(const Location &location)
|
||||
|
||||
QString titlePattern = tr("JS Source for %1").arg(fileName);
|
||||
//Check if there are open documents with the same title
|
||||
foreach (IDocument *document, DocumentModel::openedDocuments()) {
|
||||
const QList<IDocument *> documents = DocumentModel::openedDocuments();
|
||||
for (IDocument *document: documents) {
|
||||
if (document->displayName() == titlePattern) {
|
||||
EditorManager::activateEditorForDocument(document);
|
||||
return;
|
||||
@@ -895,7 +896,7 @@ static ConsoleItem *constructLogItemTree(const QVariant &result,
|
||||
std::sort(children.begin(), children.end(), compareConsoleItems);
|
||||
|
||||
item = new ConsoleItem(ConsoleItem::DefaultType, text);
|
||||
foreach (ConsoleItem *child, children) {
|
||||
for (ConsoleItem *child : qAsConst(children)) {
|
||||
if (child)
|
||||
item->appendChild(child);
|
||||
}
|
||||
@@ -915,7 +916,7 @@ static ConsoleItem *constructLogItemTree(const QVariant &result,
|
||||
std::sort(children.begin(), children.end(), compareConsoleItems);
|
||||
|
||||
item = new ConsoleItem(ConsoleItem::DefaultType, text);
|
||||
foreach (ConsoleItem *child, children) {
|
||||
for (ConsoleItem *child : qAsConst(children)) {
|
||||
if (child)
|
||||
item->appendChild(child);
|
||||
}
|
||||
@@ -1102,7 +1103,8 @@ void QmlEnginePrivate::updateScriptSource(const QString &fileName, int lineOffse
|
||||
//update open editors
|
||||
QString titlePattern = QCoreApplication::translate("QmlEngine", "JS Source for %1").arg(fileName);
|
||||
//Check if there are open editors with the same title
|
||||
foreach (IDocument *doc, DocumentModel::openedDocuments()) {
|
||||
const QList<IDocument *> documents = DocumentModel::openedDocuments();
|
||||
for (IDocument *doc: documents) {
|
||||
if (doc->displayName() == titlePattern) {
|
||||
updateDocument(doc, document);
|
||||
break;
|
||||
@@ -1646,7 +1648,8 @@ void QmlEnginePrivate::runDirectCommand(const QString &type, const QByteArray &m
|
||||
void QmlEnginePrivate::memorizeRefs(const QVariant &refs)
|
||||
{
|
||||
if (refs.isValid()) {
|
||||
foreach (const QVariant &ref, refs.toList()) {
|
||||
const QList<QVariant> refList = refs.toList();
|
||||
for (const QVariant &ref : refList) {
|
||||
const QVariantMap refData = ref.toMap();
|
||||
int handle = refData.value(HANDLE).toInt();
|
||||
refVals[handle] = extractData(refData);
|
||||
@@ -1811,7 +1814,7 @@ void QmlEnginePrivate::messageReceived(const QByteArray &data)
|
||||
}
|
||||
|
||||
QMap<QString,QString> files;
|
||||
foreach (const QString &file, sourceFiles) {
|
||||
for (const QString &file : qAsConst(sourceFiles)) {
|
||||
QString shortName = file;
|
||||
QString fullName = engine->toFileInProject(file);
|
||||
files.insert(shortName, fullName);
|
||||
@@ -2238,7 +2241,7 @@ void QmlEnginePrivate::constructChildLogItems(ConsoleItem *item, const QmlV8Obje
|
||||
if (debuggerSettings()->sortStructMembers.value())
|
||||
std::sort(children.begin(), children.end(), compareConsoleItems);
|
||||
|
||||
foreach (ConsoleItem *child, children)
|
||||
for (ConsoleItem *child : qAsConst(children))
|
||||
item->appendChild(child);
|
||||
}
|
||||
|
||||
@@ -2364,7 +2367,7 @@ void QmlEnginePrivate::handleExecuteDebuggerCommand(const QVariantMap &response)
|
||||
debuggerConsole()->printItem(constructLogItemTree(extractData(response.value(BODY))));
|
||||
|
||||
// Update the locals
|
||||
foreach (int index, currentFrameScopes)
|
||||
for (int index : qAsConst(currentFrameScopes))
|
||||
scope(index);
|
||||
} else {
|
||||
debuggerConsole()->printItem(new ConsoleItem(ConsoleItem::ErrorType,
|
||||
@@ -2439,7 +2442,7 @@ void QmlEnginePrivate::handleVersion(const QVariantMap &response)
|
||||
void QmlEnginePrivate::flushSendBuffer()
|
||||
{
|
||||
QTC_ASSERT(state() == Enabled, return);
|
||||
foreach (const QByteArray &msg, sendBuffer)
|
||||
for (const QByteArray &msg : qAsConst(sendBuffer))
|
||||
sendMessage(msg);
|
||||
sendBuffer.clear();
|
||||
}
|
||||
|
@@ -237,7 +237,8 @@ void clearExceptionSelection()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
|
||||
foreach (IEditor *editor, DocumentModel::editorsForOpenedDocuments()) {
|
||||
const QList<IEditor *> editors = DocumentModel::editorsForOpenedDocuments();
|
||||
for (IEditor *editor : editors) {
|
||||
if (auto ed = TextEditorWidget::fromEditor(editor))
|
||||
ed->setExtraSelections(TextEditorWidget::DebuggerExceptionSelection, selections);
|
||||
}
|
||||
|
@@ -649,7 +649,8 @@ void QmlInspectorAgent::addWatchData(const ObjectReference &obj,
|
||||
propertiesWatch->value = "list";
|
||||
propertiesWatch->wantsChildren = true;
|
||||
|
||||
foreach (const PropertyReference &property, obj.properties()) {
|
||||
const QList<PropertyReference> properties = obj.properties();
|
||||
for (const PropertyReference &property : properties) {
|
||||
const QString propertyName = property.name();
|
||||
if (propertyName.isEmpty())
|
||||
continue;
|
||||
@@ -669,7 +670,8 @@ void QmlInspectorAgent::addWatchData(const ObjectReference &obj,
|
||||
}
|
||||
|
||||
// recurse
|
||||
foreach (const ObjectReference &child, obj.children())
|
||||
const QList<ObjectReference> children = obj.children();
|
||||
for (const ObjectReference &child : children)
|
||||
addWatchData(child, objIname, append);
|
||||
}
|
||||
|
||||
|
@@ -331,7 +331,7 @@ bool ThreadsHandler::notifyGroupExited(const QString &groupId)
|
||||
if (item->threadData.groupId == groupId)
|
||||
list.append(item);
|
||||
});
|
||||
foreach (ThreadItem *item, list)
|
||||
for (ThreadItem *item : qAsConst(list))
|
||||
destroyItem(item);
|
||||
|
||||
m_pidForGroupId.remove(groupId);
|
||||
|
@@ -1172,7 +1172,8 @@ bool WatchModel::setData(const QModelIndex &idx, const QVariant &value, int role
|
||||
if (auto kev = ev.as<QKeyEvent>(QEvent::KeyPress)) {
|
||||
if (item && (kev->key() == Qt::Key_Delete || kev->key() == Qt::Key_Backspace)
|
||||
&& item->isWatcher()) {
|
||||
foreach (const QModelIndex &idx, ev.selectedRows())
|
||||
const QModelIndexList selectedRows = ev.selectedRows();
|
||||
for (const QModelIndex &idx : selectedRows)
|
||||
removeWatchItem(itemForIndex(idx));
|
||||
return true;
|
||||
}
|
||||
@@ -1544,7 +1545,7 @@ MemoryMarkupList WatchModel::variableMemoryMarkup(WatchItem *item,
|
||||
name = ranges.at(i).second;
|
||||
}
|
||||
dbg << '\n';
|
||||
foreach (const MemoryMarkup &m, result)
|
||||
for (const MemoryMarkup &m : qAsConst(result))
|
||||
dbg << m.address << ' ' << m.length << ' ' << m.toolTip << '\n';
|
||||
}
|
||||
|
||||
@@ -2180,7 +2181,7 @@ void WatchHandler::insertItems(const GdbMi &data)
|
||||
itemsToSort.insert(static_cast<WatchItem *>(item->parent()));
|
||||
}
|
||||
|
||||
foreach (WatchItem *toplevel, itemsToSort)
|
||||
for (WatchItem *toplevel : qAsConst(itemsToSort))
|
||||
toplevel->sortChildren(&sortByName);
|
||||
}
|
||||
|
||||
@@ -2219,7 +2220,7 @@ bool WatchHandler::insertItem(WatchItem *item)
|
||||
|
||||
void WatchModel::reexpandItems()
|
||||
{
|
||||
foreach (const QString &iname, m_expandedINames) {
|
||||
for (const QString &iname : qAsConst(m_expandedINames)) {
|
||||
if (WatchItem *item = findItem(iname)) {
|
||||
emit itemIsExpanded(indexForItem(item));
|
||||
emit inameIsExpanded(iname);
|
||||
@@ -2297,7 +2298,7 @@ void WatchHandler::notifyUpdateFinished()
|
||||
return true;
|
||||
});
|
||||
|
||||
foreach (auto item, toRemove)
|
||||
for (WatchItem *item : qAsConst(toRemove))
|
||||
m_model->destroyItem(item);
|
||||
|
||||
m_model->forAllItems([this](WatchItem *item) {
|
||||
@@ -2582,7 +2583,8 @@ void WatchHandler::loadSessionDataForEngine()
|
||||
theWatcherCount = 0;
|
||||
QVariant value = SessionManager::value("Watchers");
|
||||
m_model->m_watchRoot->removeChildren();
|
||||
foreach (const QString &exp, value.toStringList())
|
||||
const QStringList valueList = value.toStringList();
|
||||
for (const QString &exp : valueList)
|
||||
watchExpression(exp.trimmed());
|
||||
}
|
||||
|
||||
@@ -2765,8 +2767,8 @@ void WatchHandler::addDumpers(const GdbMi &dumpers)
|
||||
for (const GdbMi &dumper : dumpers) {
|
||||
DisplayFormats formats;
|
||||
formats.append(RawFormat);
|
||||
QString reportedFormats = dumper["formats"].data();
|
||||
foreach (const QString &format, reportedFormats.split(',')) {
|
||||
const QStringList reportedFormats = dumper["formats"].data().split(',');
|
||||
for (const QString &format : reportedFormats) {
|
||||
if (int f = format.toInt())
|
||||
formats.append(DisplayFormat(f));
|
||||
}
|
||||
|
Reference in New Issue
Block a user