mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: replace Q_FOREACH and foreach by range base for
Q_FOREACH and foreach are anachronisms. Range based for may cause a performance regression: it can lead to a copy of shared containers (one reason why Qt's COW containers are broken). However, as long as there is no user noticeable delay, there is no point in analyzing each case. And also no point in slapping an 'asConst' on every container that is looped over. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
41cb916060
commit
5ac64ab2cd
16 changed files with 32 additions and 35 deletions
|
@ -486,7 +486,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
|
|||
QItemSelection newSelected = selected.size() ? selected : selectionModel()->selection();
|
||||
|
||||
std::vector<dive *> addToSelection, removeFromSelection;
|
||||
Q_FOREACH (const QModelIndex &index, newDeselected.indexes()) {
|
||||
for (const QModelIndex &index: newDeselected.indexes()) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
const QAbstractItemModel *model = index.model();
|
||||
|
@ -499,7 +499,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
|
|||
removeFromSelection.push_back(trip->dives.dives[i]);
|
||||
}
|
||||
}
|
||||
Q_FOREACH (const QModelIndex &index, newSelected.indexes()) {
|
||||
for (const QModelIndex &index: newSelected.indexes()) {
|
||||
if (index.column() != 0)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -495,7 +495,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
|
|||
firstLine = f.readLine().trimmed();
|
||||
|
||||
currColumns = firstLine.split(';');
|
||||
Q_FOREACH (QString columnText, currColumns) {
|
||||
for (const QString &columnText: currColumns) {
|
||||
if (columnText == "Time") {
|
||||
headers.append("Sample time");
|
||||
} else if (columnText == "Depth") {
|
||||
|
@ -613,7 +613,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
|
|||
if (line.length() > 0)
|
||||
columns = line.split(separator);
|
||||
// now try and guess the columns
|
||||
Q_FOREACH (QString columnText, currColumns) {
|
||||
for (QString columnText: currColumns) {
|
||||
count++;
|
||||
/*
|
||||
* We have to skip the conversion of 2 to ₂ for APD Log
|
||||
|
|
|
@ -99,7 +99,7 @@ void GroupedLineEdit::addColor(QColor color)
|
|||
QStringList GroupedLineEdit::getBlockStringList()
|
||||
{
|
||||
QStringList retList;
|
||||
foreach (const Private::Block &block, d->blocks)
|
||||
for (const Private::Block &block: d->blocks)
|
||||
retList.append(block.text);
|
||||
return retList;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ void GroupedLineEdit::paintEvent(QPaintEvent *e)
|
|||
|
||||
QVectorIterator<QColor> i(d->colors);
|
||||
i.toFront();
|
||||
foreach (const Private::Block &block, d->blocks) {
|
||||
for (const Private::Block &block: d->blocks) {
|
||||
qreal start_x = line.cursorToX(block.start, QTextLine::Leading);
|
||||
qreal end_x = line.cursorToX(block.end-1, QTextLine::Trailing);
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ void KMessageWidgetPrivate::createLayout()
|
|||
qDeleteAll(buttons);
|
||||
buttons.clear();
|
||||
|
||||
Q_FOREACH (QAction *action, q->actions()) {
|
||||
for (QAction *action: q->actions()) {
|
||||
QToolButton *button = new QToolButton(content);
|
||||
button->setDefaultAction(action);
|
||||
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
|
@ -131,7 +131,7 @@ void KMessageWidgetPrivate::createLayout()
|
|||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
Q_FOREACH (QToolButton *button, buttons) {
|
||||
for (QToolButton *button: buttons) {
|
||||
// For some reason, calling show() is necessary if wordwrap is true,
|
||||
// otherwise the buttons do not show up. It is not needed if
|
||||
// wordwrap is false.
|
||||
|
@ -145,9 +145,8 @@ void KMessageWidgetPrivate::createLayout()
|
|||
layout->addWidget(iconLabel);
|
||||
layout->addWidget(textLabel);
|
||||
|
||||
Q_FOREACH (QToolButton *button, buttons) {
|
||||
for (QToolButton *button: buttons)
|
||||
layout->addWidget(button);
|
||||
}
|
||||
|
||||
layout->addWidget(closeButton);
|
||||
};
|
||||
|
|
|
@ -379,7 +379,7 @@ void MainWindow::on_actionOpen_triggered()
|
|||
QStringList cleanFilenames;
|
||||
QRegularExpression reg(".*\\[[^]]+]\\.ssrf", QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
Q_FOREACH (QString filename, filenames) {
|
||||
for (QString filename: filenames) {
|
||||
if (reg.match(filename).hasMatch())
|
||||
filename.remove(QRegularExpression("\\.ssrf$", QRegularExpression::CaseInsensitiveOption));
|
||||
cleanFilenames << filename;
|
||||
|
@ -1071,7 +1071,7 @@ void MainWindow::loadRecentFiles()
|
|||
recentFiles.clear();
|
||||
QSettings s;
|
||||
s.beginGroup("Recent_Files");
|
||||
foreach (const QString &key, s.childKeys()) {
|
||||
for (const QString &key: s.childKeys()) {
|
||||
// TODO Sorting only correct up to 9 entries. Currently, only 4 used, so no problem.
|
||||
if (!key.startsWith("File_"))
|
||||
continue;
|
||||
|
|
|
@ -27,7 +27,7 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu
|
|||
dateFormatShortMap.insert("MM/dd/yyyy", "M/d/yy");
|
||||
dateFormatShortMap.insert("dd.MM.yyyy", "d.M.yy");
|
||||
dateFormatShortMap.insert("yyyy-MM-dd", "yy-M-d");
|
||||
foreach (QString format, dateFormatShortMap.keys())
|
||||
for (const QString &format: dateFormatShortMap.keys())
|
||||
ui->dateFormatEntry->addItem(format);
|
||||
ui->dateFormatEntry->completer()->setCaseSensitivity(Qt::CaseSensitive);
|
||||
connect(ui->dateFormatEntry, &QComboBox::currentTextChanged,
|
||||
|
|
|
@ -55,7 +55,7 @@ void set_bundled_templates_as_read_only()
|
|||
listStats[i] = stats + QDir::separator() + listStats.at(i);
|
||||
list += listStats;
|
||||
|
||||
foreach (const QString& f, list)
|
||||
for (const QString &f: list)
|
||||
QFile::setPermissions(pathUser + QDir::separator() + f, QFileDevice::ReadOwner | QFileDevice::ReadUser);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue