Skip to content

Commit

Permalink
Port away from Q_FOREACH macro (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl authored Apr 16, 2024
1 parent 0e7a72a commit 56fdef9
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions app/configeditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ void ConfigEditorWidget::fillCodecComboBox(QComboBox *cb)
const QList<QByteArray> ca(QTextCodec::availableCodecs());
QVector<ComboItem> 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/linenumberwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/loghighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
10 changes: 5 additions & 5 deletions app/tikzcommandinserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("&#8226;"),
//QString(0x2022));
// QString(0x2022));

if (description.isEmpty()) // if both name and description are empty, setting
// the description first ensures that name is also
Expand Down Expand Up @@ -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('&')));
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -699,7 +699,7 @@ QVector<HighlightingRule> 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);
Expand All @@ -724,7 +724,7 @@ QVector<HighlightingRule> TikzCommandInserter::getHighlightingRules()
break;
case 3:
// command = command.replace(QLatin1Char('|'),
//QLatin1String("\\|"));
// QLatin1String("\\|"));
end = command.indexOf(QLatin1Char('='), 0) + 1;
if (end > 0)
command = command.left(end);
Expand Down
2 changes: 1 addition & 1 deletion app/tikzeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/tikzeditorhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void TikzHighlighter::setHighlightingRules(const QVector<HighlightingRule> &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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion common/tikzpreviewgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ static QList<qreal> 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;
Expand Down
2 changes: 1 addition & 1 deletion common/utils/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &copy) : QIcon(copy) { }
Icon() : QIcon() { }
};
Expand Down
4 changes: 3 additions & 1 deletion common/utils/tempdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 56fdef9

Please sign in to comment.