mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 07:27:22 -06:00
Merge pull request #9824 from thalieht/style
Convert all foreach() to range-based for()
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QTableView>
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/net/downloadhandler.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/utils/fs.h"
|
||||
@@ -110,7 +111,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
|
||||
|
||||
QStringList files;
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
foreach (const QUrl &url, event->mimeData()->urls()) {
|
||||
for (const QUrl &url : asConst(event->mimeData()->urls())) {
|
||||
if (!url.isEmpty()) {
|
||||
if (url.scheme().compare("file", Qt::CaseInsensitive) == 0)
|
||||
files << url.toLocalFile();
|
||||
@@ -125,7 +126,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
|
||||
|
||||
if (files.isEmpty()) return;
|
||||
|
||||
foreach (QString file, files) {
|
||||
for (const QString &file : asConst(files)) {
|
||||
qDebug("dropped %s", qUtf8Printable(file));
|
||||
startAsyncOp();
|
||||
m_pluginManager->installPlugin(file);
|
||||
@@ -135,8 +136,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
|
||||
// Decode if we accept drag 'n drop or not
|
||||
void PluginSelectDialog::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
QString mime;
|
||||
foreach (mime, event->mimeData()->formats()) {
|
||||
for (const QString &mime : asConst(event->mimeData()->formats())) {
|
||||
qDebug("mimeData: %s", qUtf8Printable(mime));
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ void PluginSelectDialog::on_closeButton_clicked()
|
||||
void PluginSelectDialog::on_actionUninstall_triggered()
|
||||
{
|
||||
bool error = false;
|
||||
foreach (QTreeWidgetItem *item, m_ui->pluginsTree->selectedItems()) {
|
||||
for (QTreeWidgetItem *item : asConst(m_ui->pluginsTree->selectedItems())) {
|
||||
int index = m_ui->pluginsTree->indexOfTopLevelItem(item);
|
||||
Q_ASSERT(index != -1);
|
||||
QString id = item->text(PLUGIN_ID);
|
||||
@@ -212,7 +212,7 @@ void PluginSelectDialog::on_actionUninstall_triggered()
|
||||
|
||||
void PluginSelectDialog::enableSelection(bool enable)
|
||||
{
|
||||
foreach (QTreeWidgetItem *item, m_ui->pluginsTree->selectedItems()) {
|
||||
for (QTreeWidgetItem *item : asConst(m_ui->pluginsTree->selectedItems())) {
|
||||
int index = m_ui->pluginsTree->indexOfTopLevelItem(item);
|
||||
Q_ASSERT(index != -1);
|
||||
QString id = item->text(PLUGIN_ID);
|
||||
@@ -265,7 +265,7 @@ void PluginSelectDialog::loadSupportedSearchPlugins()
|
||||
{
|
||||
// Some clean up first
|
||||
m_ui->pluginsTree->clear();
|
||||
foreach (QString name, m_pluginManager->allPlugins())
|
||||
for (const QString &name : asConst(m_pluginManager->allPlugins()))
|
||||
addNewPlugin(name);
|
||||
}
|
||||
|
||||
@@ -360,11 +360,11 @@ void PluginSelectDialog::askForPluginUrl()
|
||||
|
||||
void PluginSelectDialog::askForLocalPlugin()
|
||||
{
|
||||
QStringList pathsList = QFileDialog::getOpenFileNames(
|
||||
const QStringList pathsList = QFileDialog::getOpenFileNames(
|
||||
nullptr, tr("Select search plugins"), QDir::homePath(),
|
||||
tr("qBittorrent search plugin") + QLatin1String(" (*.py)")
|
||||
);
|
||||
foreach (QString path, pathsList) {
|
||||
for (const QString &path : pathsList) {
|
||||
startAsyncOp();
|
||||
m_pluginManager->installPlugin(path);
|
||||
}
|
||||
@@ -380,7 +380,7 @@ void PluginSelectDialog::iconDownloaded(const QString &url, QString filePath)
|
||||
QList<QSize> sizes = icon.availableSizes();
|
||||
bool invalid = (sizes.isEmpty() || icon.pixmap(sizes.first()).isNull());
|
||||
if (!invalid) {
|
||||
foreach (QTreeWidgetItem *item, findItemsWithUrl(url)) {
|
||||
for (QTreeWidgetItem *item : asConst(findItemsWithUrl(url))) {
|
||||
QString id = item->text(PLUGIN_ID);
|
||||
PluginInfo *plugin = m_pluginManager->pluginInfo(id);
|
||||
if (!plugin) continue;
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
#include "searchsortmodel.h"
|
||||
|
||||
#include "base/global.h"
|
||||
|
||||
SearchSortModel::SearchSortModel(QObject *parent)
|
||||
: base(parent)
|
||||
, m_isNameFilterEnabled(false)
|
||||
@@ -126,7 +128,7 @@ bool SearchSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceP
|
||||
const QAbstractItemModel *const sourceModel = this->sourceModel();
|
||||
if (m_isNameFilterEnabled && !m_searchTerm.isEmpty()) {
|
||||
QString name = sourceModel->data(sourceModel->index(sourceRow, NAME, sourceParent)).toString();
|
||||
for (const QString &word: m_searchTermWords) {
|
||||
for (const QString &word : asConst(m_searchTermWords)) {
|
||||
int i = name.indexOf(word, 0, Qt::CaseInsensitive);
|
||||
if (i == -1) {
|
||||
return false;
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <QTreeView>
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/global.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/search/searchpluginmanager.h"
|
||||
#include "base/search/searchhandler.h"
|
||||
@@ -166,11 +167,11 @@ void SearchWidget::fillCatCombobox()
|
||||
|
||||
using QStrPair = QPair<QString, QString>;
|
||||
QList<QStrPair> tmpList;
|
||||
foreach (const QString &cat, SearchPluginManager::instance()->getPluginCategories(selectedPlugin()))
|
||||
for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin())))
|
||||
tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||
|
||||
foreach (const QStrPair &p, tmpList) {
|
||||
for (const QStrPair &p : asConst(tmpList)) {
|
||||
qDebug("Supported category: %s", qUtf8Printable(p.second));
|
||||
m_ui->comboCategory->addItem(p.first, QVariant(p.second));
|
||||
}
|
||||
@@ -188,11 +189,11 @@ void SearchWidget::fillPluginComboBox()
|
||||
|
||||
using QStrPair = QPair<QString, QString>;
|
||||
QList<QStrPair> tmpList;
|
||||
foreach (const QString &name, SearchPluginManager::instance()->enabledPlugins())
|
||||
for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins()))
|
||||
tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
|
||||
|
||||
foreach (const QStrPair &p, tmpList)
|
||||
for (const QStrPair &p : asConst(tmpList))
|
||||
m_ui->selectPlugin->addItem(p.first, QVariant(p.second));
|
||||
|
||||
if (m_ui->selectPlugin->count() > 3)
|
||||
|
||||
Reference in New Issue
Block a user