From ef48b4725eb8fcafad716f86dd7a5086a4351e40 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Mon, 30 Dec 2019 21:21:06 +0100 Subject: [PATCH] tools: port foreach -> range-based for Signed-off-by: Juraj Oravec --- src/lib/tools/buttonwithmenu.cpp | 4 ++-- src/lib/tools/html5permissions/html5permissionsdialog.cpp | 6 ++++-- src/lib/tools/iconprovider.cpp | 8 +++++--- src/lib/tools/qztools.cpp | 6 +++--- src/lib/tools/treewidget.cpp | 4 ++-- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/lib/tools/buttonwithmenu.cpp b/src/lib/tools/buttonwithmenu.cpp index 5c78823b6..5cacdd201 100644 --- a/src/lib/tools/buttonwithmenu.cpp +++ b/src/lib/tools/buttonwithmenu.cpp @@ -76,7 +76,7 @@ void ButtonWithMenu::addItem(const Item &item) void ButtonWithMenu::addItems(const QVector &items) { - foreach (const Item &item, items) { + for (const Item &item : items) { addItem(item); } } @@ -158,7 +158,7 @@ void ButtonWithMenu::generateMenu() { m_menu->clear(); - foreach (const Item &item, m_items) { + for (const Item &item : qAsConst(m_items)) { QVariant variant; variant.setValue(item); m_menu->addAction(item.icon, item.text, this, SLOT(setCurrentItem()))->setData(variant); diff --git a/src/lib/tools/html5permissions/html5permissionsdialog.cpp b/src/lib/tools/html5permissions/html5permissionsdialog.cpp index f79ec974a..5464d4797 100644 --- a/src/lib/tools/html5permissions/html5permissionsdialog.cpp +++ b/src/lib/tools/html5permissions/html5permissionsdialog.cpp @@ -53,7 +53,8 @@ void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feat ui->treeWidget->clear(); - foreach (const QString &site, m_granted.value(feature)) { + const auto grantedSites = m_granted.value(feature); + for (const QString &site : grantedSites) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget); item->setText(0, site); item->setText(1, tr("Allow")); @@ -61,7 +62,8 @@ void HTML5PermissionsDialog::showFeaturePermissions(QWebEnginePage::Feature feat ui->treeWidget->addTopLevelItem(item); } - foreach (const QString &site, m_denied.value(feature)) { + const auto deniedSites = m_denied.value(feature); + for (const QString &site : deniedSites) { QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidget); item->setText(0, site); item->setText(1, tr("Deny")); diff --git a/src/lib/tools/iconprovider.cpp b/src/lib/tools/iconprovider.cpp index 9588b900f..31296cda9 100644 --- a/src/lib/tools/iconprovider.cpp +++ b/src/lib/tools/iconprovider.cpp @@ -195,7 +195,8 @@ QImage IconProvider::imageForUrl(const QUrl &url, bool allowNull) return img->isNull() && !allowNull ? IconProvider::emptyWebImage() : *img; } - foreach (const BufferedIcon &ic, instance()->m_iconBuffer) { + const auto iconBuffer = instance()->m_iconBuffer; + for (const BufferedIcon &ic : iconBuffer) { if (encodeUrl(ic.first) == encodedUrl) { return ic.second; } @@ -228,7 +229,8 @@ QImage IconProvider::imageForDomain(const QUrl &url, bool allowNull) QMutexLocker locker(&instance()->m_iconCacheMutex); - foreach (const BufferedIcon &ic, instance()->m_iconBuffer) { + const auto iconBuffer = instance()->m_iconBuffer; + for (const BufferedIcon &ic : iconBuffer) { if (ic.first.host() == url.host()) { return ic.second; } @@ -255,7 +257,7 @@ void IconProvider::saveIconsToDatabase() { QMutexLocker locker(&instance()->m_iconCacheMutex); - foreach (const BufferedIcon &ic, m_iconBuffer) { + for (const BufferedIcon &ic : qAsConst(m_iconBuffer)) { QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 661a282ca..a24f07741 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -515,9 +515,9 @@ QString QzTools::resolveFromPath(const QString &name) return QString(); } - QStringList dirs = path.split(QLatin1Char(':'), QString::SkipEmptyParts); + const QStringList dirs = path.split(QLatin1Char(':'), QString::SkipEmptyParts); - foreach (const QString &dir, dirs) { + for (const QString &dir : dirs) { QDir d(dir); if (d.exists(name)) { return d.absoluteFilePath(name); @@ -609,7 +609,7 @@ bool QzTools::isUtf8(const char* string) bool QzTools::containsSpace(const QString &str) { - Q_FOREACH (const QChar &c, str) { + for (const QChar &c : str) { if (c.isSpace()) return true; } diff --git a/src/lib/tools/treewidget.cpp b/src/lib/tools/treewidget.cpp index 59723705f..acf56878c 100644 --- a/src/lib/tools/treewidget.cpp +++ b/src/lib/tools/treewidget.cpp @@ -103,10 +103,10 @@ QList TreeWidget::allItems() void TreeWidget::filterString(const QString &string) { - QList _allItems = allItems(); + const QList _allItems = allItems(); QList parents; bool stringIsEmpty = string.isEmpty(); - foreach (QTreeWidgetItem* item, _allItems) { + for (QTreeWidgetItem* item : _allItems) { bool containsString = stringIsEmpty || item->text(0).contains(string, Qt::CaseInsensitive); if (containsString) { item->setHidden(false);