From 56fdef993f75ed8c0ee42c2d6a3fc089b0e16e8a Mon Sep 17 00:00:00 2001 From: Alex Fikl Date: Tue, 16 Apr 2024 23:44:49 +0300 Subject: [PATCH] Port away from Q_FOREACH macro (#64) --- app/configdialog.cpp | 3 ++- app/configeditorwidget.cpp | 7 ++++--- app/linenumberwidget.cpp | 2 +- app/loghighlighter.cpp | 10 +++++----- app/mainwindow.cpp | 2 +- app/tikzcommandinserter.cpp | 10 +++++----- app/tikzeditor.cpp | 2 +- app/tikzeditorhighlighter.cpp | 6 +++--- common/tikzpreviewgenerator.cpp | 3 ++- common/utils/icon.h | 2 +- common/utils/tempdir.cpp | 4 +++- 11 files changed, 28 insertions(+), 23 deletions(-) diff --git a/app/configdialog.cpp b/app/configdialog.cpp index dc2974c..6e88a4e 100644 --- a/app/configdialog.cpp +++ b/app/configdialog.cpp @@ -82,8 +82,9 @@ void ConfigDialog::writeSettings() void ConfigDialog::setTranslatedHighlightTypeNames(const QStringList &typeNames) { - Q_FOREACH (const QString &typeName, typeNames) + for (const auto &typeName : typeNames) { m_configAppearanceWidget->addItem(typeName); + } } void ConfigDialog::setHighlightTypeNames(const QStringList &typeNames) diff --git a/app/configeditorwidget.cpp b/app/configeditorwidget.cpp index ce9b39a..d52a72a 100644 --- a/app/configeditorwidget.cpp +++ b/app/configeditorwidget.cpp @@ -223,10 +223,11 @@ void ConfigEditorWidget::fillCodecComboBox(QComboBox *cb) const QList ca(QTextCodec::availableCodecs()); QVector ciList; ciList.reserve(ca.length()); - Q_FOREACH (const QByteArray &ba, ca) + for (const auto &ba : ca) { ciList.append(ComboItem(codecNameToString(ba), ba)); - qSort(ciList); - Q_FOREACH (const ComboItem &ci, ciList) { + } + std::sort(ciList.begin(), ciList.end()); + for (const auto &ci : ciList) { cb->addItem(ci.text, ci.data); } } diff --git a/app/linenumberwidget.cpp b/app/linenumberwidget.cpp index 107fa59..a845c02 100644 --- a/app/linenumberwidget.cpp +++ b/app/linenumberwidget.cpp @@ -79,7 +79,7 @@ void LineNumberWidget::paintEvent(QPaintEvent *event) QLatin1String("B")); painter.setPen(m_highlightPen); // update(0, top, width(), lineHeight); // make - //sure the bookmark is visible even when the line is wrapped + // sure the bookmark is visible even when the line is wrapped break; } } diff --git a/app/loghighlighter.cpp b/app/loghighlighter.cpp index 93f2326..a9b9dc6 100644 --- a/app/loghighlighter.cpp +++ b/app/loghighlighter.cpp @@ -37,7 +37,7 @@ LogHighlighter::LogHighlighter(QTextDocument *parent) : QSyntaxHighlighter(paren << QLatin1String("^\\[.*\\] Line \\d+: .*") // error msg created by // TikzPreviewGenerator::getParsedLogText() << tr("This program will not work!"); - Q_FOREACH (const QString &pattern, keywordPatterns) { + for (const auto &pattern : keywordPatterns) { rule.pattern = QRegExp(pattern); rule.format = keywordFormat; m_highlightingRules.append(rule); @@ -60,15 +60,15 @@ LogHighlighter::~LogHighlighter() { } void LogHighlighter::highlightBlock(const QString &text) { // Try each highlighting pattern and apply formatting if it matches - Q_FOREACH (const LogHighlightingRule &rule, m_highlightingRules) { - // const QRegExp expression(rule.pattern); - // int index = text.indexOf(expression); + for (const auto &rule : m_highlightingRules) { + // const QRegExp expression(rule.pattern); + // int index = text.indexOf(expression); QRegExp expression(rule.pattern); int index = expression.indexIn(text); while (index >= 0) { const int length = expression.matchedLength(); setFormat(index, length, rule.format); - // index = text.indexOf(expression, index + length); + // index = text.indexOf(expression, index + length); index = expression.indexIn(text, index + length); } } diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index a350561..57b2e94 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -240,7 +240,7 @@ MainWindow::MainWindow() // delayed initialization // QTimer::singleShot(0, this, SLOT(init())); // this causes flicker at startup and init() is - //not executed in a separate thread anyway :( + // not executed in a separate thread anyway :( init(); // qCritical() << "mainwindow" << t.msecsTo(QTime::currentTime()); } diff --git a/app/tikzcommandinserter.cpp b/app/tikzcommandinserter.cpp index 79f4ab6..bd597f7 100644 --- a/app/tikzcommandinserter.cpp +++ b/app/tikzcommandinserter.cpp @@ -239,7 +239,7 @@ static TikzCommandList loadChildCommandsJson(QJsonObject sectionObject, restoreNewLines(insertion); // this must be done before the next line insertion.replace(QLatin1String("\\\\"), QLatin1String("\\")); // insertion.replace(QLatin1String("•"), - //QString(0x2022)); + // QString(0x2022)); if (description.isEmpty()) // if both name and description are empty, setting // the description first ensures that name is also @@ -518,7 +518,7 @@ void TikzCommandInserter::showItemsInDockWidget() connect(tikzListWidget, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(insertTag(QListWidgetItem *))); // connect(tikzListWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, - //SLOT(insertTag(QListWidgetItem*))); + // SLOT(insertTag(QListWidgetItem*))); QString comboItemText = m_tikzSections.children.at(i).title; m_commandsCombo->addItem(comboItemText.remove(QLatin1Char('&'))); @@ -567,7 +567,7 @@ QDockWidget *TikzCommandInserter::getDockWidget(QWidget *parent) connect(tikzListWidget, SIGNAL(itemActivated(QListWidgetItem *)), this, SLOT(insertTag(QListWidgetItem *))); // connect(tikzListWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, - //SLOT(insertTag(QListWidgetItem*))); + // SLOT(insertTag(QListWidgetItem*))); m_commandsCombo->addItem(tr("General")); m_commandsStack->addWidget(tikzListWidget); @@ -699,7 +699,7 @@ QVector TikzCommandInserter::getHighlightingRules() command = command.left(end); // command = command.replace(QLatin1Char('\\'), - //QLatin1String("\\\\")); + // QLatin1String("\\\\")); rule.type = highlightTypeNames.at(0); // rule.pattern = QRegExp(command); // rule.pattern.setPattern(command); @@ -724,7 +724,7 @@ QVector TikzCommandInserter::getHighlightingRules() break; case 3: // command = command.replace(QLatin1Char('|'), - //QLatin1String("\\|")); + // QLatin1String("\\|")); end = command.indexOf(QLatin1Char('='), 0) + 1; if (end > 0) command = command.left(end); diff --git a/app/tikzeditor.cpp b/app/tikzeditor.cpp index 4c50865..2c124af 100644 --- a/app/tikzeditor.cpp +++ b/app/tikzeditor.cpp @@ -340,7 +340,7 @@ void TikzEditor::printWhiteSpaces(QPainter &painter) const QRect rect = cursorRect(cursor); // const QFontMetrics fontMetrics = - //QFontMetrics(cursor.charFormat().font()); + // QFontMetrics(cursor.charFormat().font()); if (m_showWhiteSpaces && text.at(i) == QLatin1Char(' ')) { if (painter.pen() != whiteSpacesPen) diff --git a/app/tikzeditorhighlighter.cpp b/app/tikzeditorhighlighter.cpp index 5cc58fe..7b1389f 100644 --- a/app/tikzeditorhighlighter.cpp +++ b/app/tikzeditorhighlighter.cpp @@ -41,7 +41,7 @@ void TikzHighlighter::setHighlightingRules(const QVector &high QStringList keywordPatterns; keywordPatterns << QLatin1String("\\\\begin\\{[^\\}]*\\}") << QLatin1String("\\\\end\\{[^\\}]*\\}"); - Q_FOREACH (const QString &pattern, keywordPatterns) { + for (const auto &pattern : keywordPatterns) { rule.type = highlightTypeNames.at(currentIndex); rule.pattern = QRegExp(pattern); rule.isRegExp = true; @@ -156,7 +156,7 @@ void TikzHighlighter::highlightBlock(const QString &text) // Try each highlighting pattern and apply formatting if it matches // Having the outer loop loop over the highlighting rules and the inner loop over the text is // much faster than conversely - Q_FOREACH (const HighlightingRule &rule, m_highlightingRules) { + for (const auto &rule : m_highlightingRules) { if (!rule.isRegExp) // match the insertion string { const int length = rule.matchString.length(); @@ -169,7 +169,7 @@ void TikzHighlighter::highlightBlock(const QString &text) // reality "\node" as a command is written setFormat(index, length, m_formatList[rule.type]); // index = text.indexOf(rule.matchString, index + - //length); + // length); index = indexOf(text, rule.matchString, index + length); } } else // match the pattern diff --git a/common/tikzpreviewgenerator.cpp b/common/tikzpreviewgenerator.cpp index 5b22d73..c4d747b 100644 --- a/common/tikzpreviewgenerator.cpp +++ b/common/tikzpreviewgenerator.cpp @@ -245,8 +245,9 @@ static QList tikzCoordinates(const QString &tikzFileBaseName) while (!tikzAuxFileStream.atEnd()) { QStringList tikzCoordinateStringList = tikzAuxFileStream.readLine().split(QLatin1Char(';')); - Q_FOREACH (const QString &tikzCoordinateString, tikzCoordinateStringList) + for (const auto &tikzCoordinateString : tikzCoordinateStringList) { tikzCoordinateList << tikzCoordinateString.toDouble(); + } } } return tikzCoordinateList; diff --git a/common/utils/icon.h b/common/utils/icon.h index d0581b8..f7af784 100644 --- a/common/utils/icon.h +++ b/common/utils/icon.h @@ -33,7 +33,7 @@ class Icon : public QIcon } // #else // explicit Icon(const QString &iconName) : QIcon(QLatin1String(":/icons/") + iconName + - //QLatin1String(".png")) {} // faster than the above #endif + // QLatin1String(".png")) {} // faster than the above #endif explicit Icon(const QIcon ©) : QIcon(copy) { } Icon() : QIcon() { } }; diff --git a/common/utils/tempdir.cpp b/common/utils/tempdir.cpp index d20769c..685406a 100644 --- a/common/utils/tempdir.cpp +++ b/common/utils/tempdir.cpp @@ -54,7 +54,9 @@ bool TempDir::cleanUp() bool success = true; const QStringList fileList = tempDir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries); - Q_FOREACH (const QString &fileName, fileList) + for (const auto &fileName : fileList) { success = success && tempDir.remove(fileName); + } + return success; }