Convert all foreach() to range-based for()

This commit is contained in:
thalieht
2018-11-18 20:40:37 +02:00
committed by sledgehammer999
parent 62e71a15a4
commit e2ee928017
64 changed files with 326 additions and 292 deletions

View File

@@ -143,7 +143,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
m_ui->categoryComboBox->addItem(defaultCategory);
m_ui->categoryComboBox->addItem("");
foreach (const QString &category, categories)
for (const QString &category : qAsConst(categories))
if (category != defaultCategory && category != m_torrentParams.category)
m_ui->categoryComboBox->addItem(category);
@@ -631,7 +631,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
prio = prio::IGNORED;
qDebug("Setting files priority");
foreach (const QModelIndex &index, selectedRows) {
for (const QModelIndex &index : selectedRows) {
qDebug("Setting priority(%d) for file at row %d", prio, index.row());
m_contentModel->setData(m_contentModel->index(index.row(), PRIORITY, index.parent()), prio);
}

View File

@@ -36,6 +36,7 @@
#include <QNetworkInterface>
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "base/preferences.h"
#include "base/unicodestrings.h"
#include "app/application.h"
@@ -286,13 +287,13 @@ void AdvancedSettings::updateInterfaceAddressCombo()
};
if (ifaceName.isEmpty()) {
foreach (const QHostAddress &ip, QNetworkInterface::allAddresses())
for (const QHostAddress &ip : copyAsConst(QNetworkInterface::allAddresses()))
populateCombo(ip.toString(), ip.protocol());
}
else {
const QNetworkInterface iface = QNetworkInterface::interfaceFromName(ifaceName);
const QList<QNetworkAddressEntry> addresses = iface.addressEntries();
foreach (const QNetworkAddressEntry &entry, addresses) {
for (const QNetworkAddressEntry &entry : addresses) {
const QHostAddress ip = entry.ip();
populateCombo(ip.toString(), ip.protocol());
}
@@ -425,7 +426,7 @@ void AdvancedSettings::loadAdvancedSettings()
const QString currentInterface = session->networkInterface();
bool interfaceExists = currentInterface.isEmpty();
int i = 1;
foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) {
for (const QNetworkInterface &iface : copyAsConst(QNetworkInterface::allInterfaces())) {
// This line fixes a Qt bug => https://bugreports.qt.io/browse/QTBUG-52633
// Tested in Qt 5.6.0. For more info see:
// https://github.com/qbittorrent/qBittorrent/issues/5131

View File

@@ -107,8 +107,8 @@ void BanListOptionsDialog::on_buttonBanIP_clicked()
void BanListOptionsDialog::on_buttonDeleteIP_clicked()
{
QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes();
for (auto &i : selection)
const QModelIndexList selection = m_ui->bannedIPList->selectionModel()->selectedIndexes();
for (const auto &i : selection)
m_sortFilter->removeRow(i.row());
m_modified = true;

View File

@@ -33,6 +33,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "guiiconprovider.h"
class CategoryModelItem
@@ -407,7 +408,7 @@ void CategoryFilterModel::populate()
const QString &category = i.key();
if (m_isSubcategoriesEnabled) {
CategoryModelItem *parent = m_rootItem;
foreach (const QString &subcat, session->expandCategory(category)) {
for (const QString &subcat : copyAsConst(session->expandCategory(category))) {
const QString subcatName = shortName(subcat);
if (!parent->hasChild(subcatName)) {
new CategoryModelItem(
@@ -436,7 +437,7 @@ CategoryModelItem *CategoryFilterModel::findItem(const QString &fullName) const
return m_rootItem->child(fullName);
CategoryModelItem *item = m_rootItem;
foreach (const QString &subcat, BitTorrent::Session::expandCategory(fullName)) {
for (const QString &subcat : copyAsConst(BitTorrent::Session::expandCategory(fullName))) {
const QString subcatName = shortName(subcat);
if (!item->hasChild(subcatName)) return nullptr;
item = item->child(subcatName);

View File

@@ -30,6 +30,7 @@
#include <algorithm>
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/settingsstorage.h"
#include "cookiesmodel.h"
@@ -100,6 +101,6 @@ void CookiesDialog::onButtonDeleteClicked()
}
);
for (const QModelIndex &idx : idxs)
for (const QModelIndex &idx : qAsConst(idxs))
m_cookiesModel->removeRow(idx.row());
}

View File

@@ -32,6 +32,7 @@
#include <QDateTime>
#include <QPalette>
#include "base/global.h"
#include "guiiconprovider.h"
#include "loglistwidget.h"
#include "ui_executionlogwidget.h"
@@ -52,9 +53,9 @@ ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &typ
m_ui->tabBan->layout()->addWidget(m_peerList);
const Logger *const logger = Logger::instance();
foreach (const Log::Msg &msg, logger->getMessages())
for (const Log::Msg &msg : copyAsConst(logger->getMessages()))
addLogMessage(msg);
foreach (const Log::Peer &peer, logger->getPeers())
for (const Log::Peer &peer : copyAsConst(logger->getPeers()))
addPeerMessage(peer);
connect(logger, &Logger::newLogMessage, this, &ExecutionLogWidget::addLogMessage);
connect(logger, &Logger::newLogPeer, this, &ExecutionLogWidget::addPeerMessage);

View File

@@ -36,6 +36,7 @@
#include <QListWidgetItem>
#include <QRegularExpression>
#include "base/global.h"
#include "guiiconprovider.h"
LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent)
@@ -97,7 +98,7 @@ void LogListWidget::copySelection()
{
static const QRegularExpression htmlTag("<[^>]+>");
QStringList strings;
foreach (QListWidgetItem* it, selectedItems())
for (QListWidgetItem* it : copyAsConst(selectedItems()))
strings << static_cast<QLabel*>(itemWidget(it))->text().remove(htmlTag);
QApplication::clipboard()->setText(strings.join('\n'));

View File

@@ -284,7 +284,7 @@ MainWindow::MainWindow(QWidget *parent)
m_prioSeparatorMenu = m_ui->menuEdit->insertSeparator(m_ui->actionTopPriority);
#ifdef Q_OS_MAC
foreach (QAction *action, m_ui->toolBar->actions()) {
for (QAction *action : copyAsConst(m_ui->toolBar->actions())) {
if (action->isSeparator()) {
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -1239,7 +1239,7 @@ bool MainWindow::event(QEvent *e)
qDebug() << "Has active window:" << (qApp->activeWindow() != nullptr);
// Check if there is a modal window
bool hasModalWindow = false;
foreach (QWidget *widget, QApplication::allWidgets()) {
for (QWidget *widget : copyAsConst(QApplication::allWidgets())) {
if (widget->isModal()) {
hasModalWindow = true;
break;
@@ -1285,7 +1285,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// remove scheme
QStringList files;
if (event->mimeData()->hasUrls()) {
foreach (const QUrl &url, event->mimeData()->urls()) {
for (const QUrl &url : copyAsConst(event->mimeData()->urls())) {
if (url.isEmpty())
continue;
@@ -1300,7 +1300,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// differentiate ".torrent" files/links & magnet links from others
QStringList torrentFiles, otherFiles;
foreach (const QString &file, files) {
for (const QString &file : qAsConst(files)) {
const bool isTorrentLink = (file.startsWith("magnet:", Qt::CaseInsensitive)
|| file.endsWith(C_TORRENT_FILE_EXTENSION, Qt::CaseInsensitive)
|| Utils::Misc::isUrl(file));
@@ -1312,7 +1312,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// Download torrents
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
foreach (const QString &file, torrentFiles) {
for (const QString &file : qAsConst(torrentFiles)) {
if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this);
else
@@ -1321,7 +1321,7 @@ void MainWindow::dropEvent(QDropEvent *event)
if (!torrentFiles.isEmpty()) return;
// Create torrent
foreach (const QString &file, otherFiles) {
for (const QString &file : qAsConst(otherFiles)) {
createTorrentTriggered(file);
// currently only hande the first entry
@@ -1333,7 +1333,7 @@ void MainWindow::dropEvent(QDropEvent *event)
// Decode if we accept drag 'n drop or not
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
foreach (const QString &mime, event->mimeData()->formats())
for (const QString &mime : copyAsConst(event->mimeData()->formats()))
qDebug("mimeData: %s", mime.toLocal8Bit().data());
if (event->mimeData()->hasFormat("text/plain") || event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
@@ -1382,7 +1382,7 @@ void MainWindow::on_actionOpen_triggered()
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
if (!pathsList.isEmpty()) {
foreach (QString file, pathsList) {
for (const QString &file : pathsList) {
qDebug("Dropped file %s on download list", qUtf8Printable(file));
if (useTorrentAdditionDialog)
AddNewTorrentDialog::show(file, this);
@@ -1635,7 +1635,7 @@ void MainWindow::showNotificationBaloon(QString title, QString msg) const
void MainWindow::downloadFromURLList(const QStringList &urlList)
{
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
foreach (QString url, urlList) {
for (QString url : urlList) {
if (((url.size() == 40) && !url.contains(QRegularExpression("[^0-9A-Fa-f]")))
|| ((url.size() == 32) && !url.contains(QRegularExpression("[^2-7A-Za-z]"))))
url = "magnet:?xt=urn:btih:" + url;

View File

@@ -160,8 +160,8 @@ OptionsDialog::OptionsDialog(QWidget *parent)
m_ui->hsplitter->setCollapsible(0, false);
m_ui->hsplitter->setCollapsible(1, false);
// Get apply button in button box
QList<QAbstractButton *> buttons = m_ui->buttonBox->buttons();
foreach (QAbstractButton *button, buttons) {
const QList<QAbstractButton *> buttons = m_ui->buttonBox->buttons();
for (QAbstractButton *button : buttons) {
if (m_ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
m_applyButton = button;
break;
@@ -469,7 +469,7 @@ void OptionsDialog::initializeLanguageCombo()
// List language files
const QDir langDir(":/lang");
const QStringList langFiles = langDir.entryList(QStringList("qbittorrent_*.qm"), QDir::Files);
foreach (const QString langFile, langFiles) {
for (const QString &langFile : langFiles) {
QString localeStr = langFile.mid(12); // remove "qbittorrent_"
localeStr.chop(3); // Remove ".qm"
QString languageName;
@@ -493,7 +493,7 @@ OptionsDialog::~OptionsDialog()
saveWindowState();
foreach (const QString &path, m_addedScanDirs)
for (const QString &path : qAsConst(m_addedScanDirs))
ScanFoldersModel::instance()->removePath(path);
ScanFoldersModel::instance()->configure(); // reloads "removed" paths
delete m_ui;
@@ -1504,7 +1504,7 @@ void OptionsDialog::on_removeScanFolderButton_clicked()
if (selected.isEmpty())
return;
Q_ASSERT(selected.count() == ScanFoldersModel::instance()->columnCount());
foreach (const QModelIndex &index, selected) {
for (const QModelIndex &index : selected) {
if (index.column() == ScanFoldersModel::WATCH)
m_removedScanDirs << index.data().toString();
}

View File

@@ -248,9 +248,9 @@ void PeerListWidget::showPeerListMenu(const QPoint &)
if (!act) return;
if (act == addPeerAct) {
QList<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
const QList<BitTorrent::PeerAddress> peersList = PeersAdditionDialog::askForPeers(this);
int peerCount = 0;
foreach (const BitTorrent::PeerAddress &addr, peersList) {
for (const BitTorrent::PeerAddress &addr : peersList) {
if (torrent->connectPeer(addr)) {
qDebug("Adding peer %s...", qUtf8Printable(addr.ip.toString()));
Logger::instance()->addMessage(tr("Manually adding peer '%1'...").arg(addr.ip.toString()));
@@ -284,8 +284,8 @@ void PeerListWidget::banSelectedPeers()
QString(), 0, 1);
if (ret) return;
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach (const QModelIndex &index, selectedIndexes) {
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
for (const QModelIndex &index : selectedIndexes) {
int row = m_proxyModel->mapToSource(index).row();
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Banning peer %s...", ip.toLocal8Bit().data());
@@ -298,9 +298,9 @@ void PeerListWidget::banSelectedPeers()
void PeerListWidget::copySelectedPeers()
{
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeers;
foreach (const QModelIndex &index, selectedIndexes) {
for (const QModelIndex &index : selectedIndexes) {
int row = m_proxyModel->mapToSource(index).row();
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
@@ -339,10 +339,10 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo
{
if (!torrent) return;
QList<BitTorrent::PeerInfo> peers = torrent->peers();
const QList<BitTorrent::PeerInfo> peers = torrent->peers();
QSet<QString> oldPeersSet = m_peerItems.keys().toSet();
foreach (const BitTorrent::PeerInfo &peer, peers) {
for (const BitTorrent::PeerInfo &peer : peers) {
BitTorrent::PeerAddress addr = peer.address();
if (addr.ip.isNull()) continue;

View File

@@ -31,6 +31,7 @@
#include <QHostAddress>
#include <QMessageBox>
#include "base/global.h"
#include "ui_peersadditiondialog.h"
PeersAdditionDialog::PeersAdditionDialog(QWidget *parent)
@@ -61,7 +62,7 @@ void PeersAdditionDialog::validateInput()
QMessageBox::Ok);
return;
}
foreach (const QString &peer, m_ui->textEditPeers->toPlainText().trimmed().split('\n')) {
for (const QString &peer : copyAsConst(m_ui->textEditPeers->toPlainText().trimmed().split('\n'))) {
BitTorrent::PeerAddress addr = parsePeer(peer);
if (!addr.ip.isNull()) {
m_peersList.append(addr);

View File

@@ -259,7 +259,7 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
stream << "<html><body>";
PieceIndexToImagePos transform {m_torrent->info(), m_image};
int pieceIndex = transform.pieceIndex(imagePos);
QVector<int> files {m_torrent->info().fileIndicesForPiece(pieceIndex)};
const QVector<int> files {m_torrent->info().fileIndicesForPiece(pieceIndex)};
QString tooltipTitle;
if (files.count() > 1) {

View File

@@ -511,7 +511,7 @@ void PropertiesWidget::loadUrlSeeds()
qDebug("Loading URL seeds");
const QList<QUrl> hcSeeds = m_torrent->urlSeeds();
// Add url seeds
foreach (const QUrl &hcSeed, hcSeeds) {
for (const QUrl &hcSeed : hcSeeds) {
qDebug("Loading URL seed: %s", qUtf8Printable(hcSeed.toString()));
new QListWidgetItem(hcSeed.toString(), m_ui->listWebSeeds);
}
@@ -582,7 +582,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
{
if (!m_torrent) return;
QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
const QModelIndexList selectedRows = m_ui->filesList->selectionModel()->selectedRows(0);
if (selectedRows.empty()) return;
QMenu myFilesLlistMenu;
@@ -630,7 +630,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
prio = prio::IGNORED;
qDebug("Setting files priority");
foreach (QModelIndex index, selectedRows) {
for (const QModelIndex &index : selectedRows) {
qDebug("Setting priority(%d) for file at row %d", prio, index.row());
m_propListModel->setData(m_propListModel->index(index.row(), PRIORITY, index.parent()), prio);
}
@@ -847,7 +847,7 @@ void PropertiesWidget::deleteSelectedUrlSeeds()
if (selectedItems.isEmpty()) return;
QList<QUrl> urlSeeds;
foreach (const QListWidgetItem *item, selectedItems)
for (const QListWidgetItem *item : selectedItems)
urlSeeds << item->text();
m_torrent->removeUrlSeeds(urlSeeds);
@@ -861,7 +861,7 @@ void PropertiesWidget::copySelectedWebSeedsToClipboard() const
if (selectedItems.isEmpty()) return;
QStringList urlsToCopy;
foreach (QListWidgetItem *item, selectedItems)
for (const QListWidgetItem *item : selectedItems)
urlsToCopy << item->text();
QApplication::clipboard()->setText(urlsToCopy.join('\n'));

View File

@@ -33,6 +33,7 @@
#include <QPushButton>
#include <QSpacerItem>
#include "base/global.h"
#include "guiiconprovider.h"
PropTabBar::PropTabBar(QWidget *parent)
@@ -102,7 +103,7 @@ PropTabBar::PropTabBar(QWidget *parent)
connect(m_btnGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked)
, this, &PropTabBar::setCurrentIndex);
// Disable buttons focus
foreach (QAbstractButton *btn, m_btnGroup->buttons())
for (QAbstractButton *btn : copyAsConst(m_btnGroup->buttons()))
btn->setFocusPolicy(Qt::NoFocus);
}

View File

@@ -274,7 +274,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
rect.adjust(0, fontMetrics.height(), 0, 0); // Add top padding for top speed text
// draw Y axis speed labels
QVector<QString> speedLabels = {
const QVector<QString> speedLabels = {
formatLabel(niceScale.arg, niceScale.unit),
formatLabel((0.75 * niceScale.arg), niceScale.unit),
formatLabel((0.50 * niceScale.arg), niceScale.unit),

View File

@@ -45,6 +45,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h"
#include "base/global.h"
#include "base/preferences.h"
#include "base/utils/misc.h"
#include "autoexpandabledialog.h"
@@ -140,7 +141,7 @@ QList<QTreeWidgetItem*> TrackerListWidget::getSelectedTrackerItems() const
{
const QList<QTreeWidgetItem *> selectedTrackerItems = selectedItems();
QList<QTreeWidgetItem *> selectedTrackers;
foreach (QTreeWidgetItem *item, selectedTrackerItems) {
for (QTreeWidgetItem *item : selectedTrackerItems) {
if (indexOfTopLevelItem(item) >= NB_STICKY_ITEM) // Ignore STICKY ITEMS
selectedTrackers << item;
}
@@ -163,11 +164,11 @@ void TrackerListWidget::moveSelectionUp()
clear();
return;
}
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
const QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
if (selectedTrackerItems.isEmpty()) return;
bool change = false;
foreach (QTreeWidgetItem *item, selectedTrackerItems) {
for (QTreeWidgetItem *item : selectedTrackerItems) {
int index = indexOfTopLevelItem(item);
if (index > NB_STICKY_ITEM) {
insertTopLevelItem(index - 1, takeTopLevelItem(index));
@@ -178,7 +179,7 @@ void TrackerListWidget::moveSelectionUp()
// Restore selection
QItemSelectionModel *selection = selectionModel();
foreach (QTreeWidgetItem *item, selectedTrackerItems)
for (QTreeWidgetItem *item : selectedTrackerItems)
selection->select(indexFromItem(item), (QItemSelectionModel::Rows | QItemSelectionModel::Select));
setSelectionModel(selection);
@@ -204,7 +205,7 @@ void TrackerListWidget::moveSelectionDown()
clear();
return;
}
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
const QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
if (selectedTrackerItems.isEmpty()) return;
bool change = false;
@@ -219,7 +220,7 @@ void TrackerListWidget::moveSelectionDown()
// Restore selection
QItemSelectionModel *selection = selectionModel();
foreach (QTreeWidgetItem *item, selectedTrackerItems)
for (QTreeWidgetItem *item : selectedTrackerItems)
selection->select(indexFromItem(item), (QItemSelectionModel::Rows | QItemSelectionModel::Select));
setSelectionModel(selection);
@@ -289,7 +290,7 @@ void TrackerListWidget::loadStickyItems(BitTorrent::TorrentHandle *const torrent
// XXX: libtorrent should provide this info...
// Count peers from DHT, PeX, LSD
uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;
foreach (const BitTorrent::PeerInfo &peer, torrent->peers()) {
for (const BitTorrent::PeerInfo &peer : copyAsConst(torrent->peers())) {
if (peer.isConnecting()) continue;
if (peer.fromDHT()) {
@@ -331,7 +332,7 @@ void TrackerListWidget::loadTrackers()
// Load actual trackers information
QHash<QString, BitTorrent::TrackerInfo> trackerData = torrent->trackerInfos();
QStringList oldTrackerURLs = m_trackerItems.keys();
foreach (const BitTorrent::TrackerEntry &entry, torrent->trackers()) {
for (const BitTorrent::TrackerEntry &entry : copyAsConst(torrent->trackers())) {
QString trackerURL = entry.url();
QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr);
if (!item) {
@@ -383,7 +384,7 @@ void TrackerListWidget::loadTrackers()
item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
}
// Remove old trackers
foreach (const QString &tracker, oldTrackerURLs)
for (const QString &tracker : qAsConst(oldTrackerURLs))
delete m_trackerItems.take(tracker);
}
@@ -394,7 +395,7 @@ void TrackerListWidget::askForTrackers()
if (!torrent) return;
QList<BitTorrent::TrackerEntry> trackers;
foreach (const QString &tracker, TrackersAdditionDialog::askForTrackers(this, torrent))
for (const QString &tracker : copyAsConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
trackers << tracker;
torrent->addTrackers(trackers);
@@ -402,11 +403,11 @@ void TrackerListWidget::askForTrackers()
void TrackerListWidget::copyTrackerUrl()
{
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
const QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
if (selectedTrackerItems.isEmpty()) return;
QStringList urlsToCopy;
foreach (QTreeWidgetItem *item, selectedTrackerItems) {
for (const QTreeWidgetItem *item : selectedTrackerItems) {
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString();
qDebug() << QString("Copy: ") + trackerURL;
urlsToCopy << trackerURL;
@@ -423,11 +424,11 @@ void TrackerListWidget::deleteSelectedTrackers()
return;
}
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
const QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems();
if (selectedTrackerItems.isEmpty()) return;
QStringList urlsToRemove;
foreach (QTreeWidgetItem *item, selectedTrackerItems) {
for (const QTreeWidgetItem *item : selectedTrackerItems) {
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString();
urlsToRemove << trackerURL;
m_trackerItems.remove(trackerURL);
@@ -436,8 +437,8 @@ void TrackerListWidget::deleteSelectedTrackers()
// Iterate over the trackers and remove the selected ones
QList<BitTorrent::TrackerEntry> remainingTrackers;
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
foreach (const BitTorrent::TrackerEntry &entry, trackers) {
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
for (const BitTorrent::TrackerEntry &entry : trackers) {
if (!urlsToRemove.contains(entry.url()))
remainingTrackers.push_back(entry);
}
@@ -493,7 +494,7 @@ void TrackerListWidget::editSelectedTracker()
void TrackerListWidget::reannounceSelected()
{
QList<QTreeWidgetItem *> selItems = selectedItems();
const QList<QTreeWidgetItem *> selItems = selectedItems();
if (selItems.isEmpty()) return;
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
@@ -501,7 +502,7 @@ void TrackerListWidget::reannounceSelected()
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
foreach (QTreeWidgetItem* item, selItems) {
for (const QTreeWidgetItem *item : selItems) {
// DHT case
if (item == m_DHTItem) {
torrent->forceDHTAnnounce();

View File

@@ -34,6 +34,7 @@
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h"
#include "base/global.h"
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "base/utils/fs.h"
@@ -59,7 +60,7 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
QStringList TrackersAdditionDialog::newTrackers() const
{
QStringList cleanTrackers;
foreach (QString url, m_ui->textEditTrackersList->toPlainText().split('\n')) {
for (QString url : copyAsConst(m_ui->textEditTrackersList->toPlainText().split('\n'))) {
url = url.trimmed();
if (!url.isEmpty())
cleanTrackers << url;
@@ -83,8 +84,8 @@ void TrackersAdditionDialog::parseUTorrentList(const QString &, const QByteArray
// Load from torrent handle
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
// Load from current user list
QStringList tmp = m_ui->textEditTrackersList->toPlainText().split('\n');
foreach (const QString &userURL, tmp) {
const QStringList tmp = m_ui->textEditTrackersList->toPlainText().split('\n');
for (const QString &userURL : tmp) {
BitTorrent::TrackerEntry userTracker(userURL);
if (!existingTrackers.contains(userTracker))
existingTrackers << userTracker;

View File

@@ -30,6 +30,7 @@
#include <QListWidgetItem>
#include "base/global.h"
#include "base/rss/rss_article.h"
#include "base/rss/rss_item.h"
@@ -68,7 +69,7 @@ void ArticleListWidget::setRSSItem(RSS::Item *rssItem, bool unreadOnly)
connect(m_rssItem, &RSS::Item::articleRead, this, &ArticleListWidget::handleArticleRead);
connect(m_rssItem, &RSS::Item::articleAboutToBeRemoved, this, &ArticleListWidget::handleArticleAboutToBeRemoved);
foreach (auto article, rssItem->articles()) {
for (const auto article : copyAsConst(rssItem->articles())) {
if (!(m_unreadOnly && article->isRead())) {
auto item = createItem(article);
addItem(item);

View File

@@ -41,6 +41,7 @@
#include <QString>
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "base/preferences.h"
#include "base/rss/rss_article.h"
#include "base/rss/rss_autodownloader.h"
@@ -131,7 +132,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent)
loadFeedList();
m_ui->listRules->blockSignals(true);
foreach (const RSS::AutoDownloadRule &rule, RSS::AutoDownloader::instance()->rules())
for (const RSS::AutoDownloadRule &rule : copyAsConst(RSS::AutoDownloader::instance()->rules()))
createRuleItem(rule);
m_ui->listRules->blockSignals(false);
@@ -181,7 +182,7 @@ void AutomatedRssDownloader::loadFeedList()
{
const QSignalBlocker feedListSignalBlocker(m_ui->listFeeds);
foreach (auto feed, RSS::Session::instance()->feeds()) {
for (const auto feed : copyAsConst(RSS::Session::instance()->feeds())) {
QListWidgetItem *item = new QListWidgetItem(feed->name(), m_ui->listFeeds);
item->setData(Qt::UserRole, feed->url());
item->setFlags(item->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsTristate);
@@ -211,7 +212,7 @@ void AutomatedRssDownloader::updateFeedList()
bool allEnabled = true;
bool anyEnabled = false;
foreach (const QListWidgetItem *ruleItem, selection) {
for (const QListWidgetItem *ruleItem : qAsConst(selection)) {
auto rule = RSS::AutoDownloader::instance()->ruleByName(ruleItem->text());
if (rule.feedURLs().contains(feedURL))
anyEnabled = true;
@@ -384,7 +385,7 @@ void AutomatedRssDownloader::on_removeRuleBtn_clicked()
if (QMessageBox::question(this, tr("Rule deletion confirmation"), confirmText, QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes)
return;
foreach (QListWidgetItem *item, selection)
for (const QListWidgetItem *item : selection)
RSS::AutoDownloader::instance()->removeRule(item->text());
}
@@ -548,7 +549,7 @@ void AutomatedRssDownloader::clearSelectedRuleDownloadedEpisodeList()
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feedItem)
{
const QString feedURL = feedItem->data(Qt::UserRole).toString();
foreach (QListWidgetItem *ruleItem, m_ui->listRules->selectedItems()) {
for (QListWidgetItem *ruleItem : copyAsConst(m_ui->listRules->selectedItems())) {
RSS::AutoDownloadRule rule = (ruleItem == m_currentRuleItem
? m_currentRule
: RSS::AutoDownloader::instance()->ruleByName(ruleItem->text()));
@@ -572,16 +573,16 @@ void AutomatedRssDownloader::updateMatchingArticles()
{
m_ui->treeMatchingArticles->clear();
foreach (const QListWidgetItem *ruleItem, m_ui->listRules->selectedItems()) {
for (const QListWidgetItem *ruleItem : copyAsConst(m_ui->listRules->selectedItems())) {
RSS::AutoDownloadRule rule = (ruleItem == m_currentRuleItem
? m_currentRule
: RSS::AutoDownloader::instance()->ruleByName(ruleItem->text()));
foreach (const QString &feedURL, rule.feedURLs()) {
for (const QString &feedURL : copyAsConst(rule.feedURLs())) {
auto feed = RSS::Session::instance()->feedByURL(feedURL);
if (!feed) continue; // feed doesn't exist
QStringList matchingArticles;
foreach (auto article, feed->articles())
for (const auto article : copyAsConst(feed->articles()))
if (rule.matches(article->data()))
matchingArticles << article->title();
if (!matchingArticles.isEmpty())
@@ -620,7 +621,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(RSS::Feed *feed, const QStrin
}
// Insert the articles
foreach (const QString &article, articles) {
for (const QString &article : articles) {
QPair<QString, QString> key(feed->name(), article);
if (!m_treeListEntries.contains(key)) {
@@ -675,10 +676,10 @@ void AutomatedRssDownloader::updateMustLineValidity()
if (isRegex)
tokens << text;
else
foreach (const QString &token, text.split('|'))
for (const QString &token : copyAsConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {
for (const QString &token : qAsConst(tokens)) {
QRegularExpression reg(token, QRegularExpression::CaseInsensitiveOption);
if (!reg.isValid()) {
if (isRegex)
@@ -713,10 +714,10 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if (isRegex)
tokens << text;
else
foreach (const QString &token, text.split('|'))
for (const QString &token : copyAsConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {
for (const QString &token : qAsConst(tokens)) {
QRegularExpression reg(token, QRegularExpression::CaseInsensitiveOption);
if (!reg.isValid()) {
if (isRegex)

View File

@@ -33,6 +33,7 @@
#include <QDropEvent>
#include <QTreeWidgetItem>
#include "base/global.h"
#include "base/rss/rss_article.h"
#include "base/rss/rss_feed.h"
#include "base/rss/rss_folder.h"
@@ -219,7 +220,7 @@ void FeedListWidget::dropEvent(QDropEvent *event)
: RSS::Session::instance()->rootFolder());
// move as much items as possible
foreach (QTreeWidgetItem *srcItem, selectedItems()) {
for (QTreeWidgetItem *srcItem : copyAsConst(selectedItems())) {
auto rssItem = getRSSItem(srcItem);
RSS::Session::instance()->moveItem(rssItem, RSS::Item::joinPath(destFolder->path(), rssItem->name()));
}
@@ -264,7 +265,7 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem
void FeedListWidget::fill(QTreeWidgetItem *parent, RSS::Folder *rssParent)
{
foreach (auto rssItem, rssParent->items()) {
for (const auto rssItem : copyAsConst(rssParent->items())) {
QTreeWidgetItem *item = createItem(rssItem, parent);
// Recursive call if this is a folder.
if (auto folder = qobject_cast<RSS::Folder *>(rssItem))

View File

@@ -41,6 +41,7 @@
#include <QString>
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "base/net/downloadmanager.h"
#include "base/preferences.h"
#include "base/rss/rss_article.h"
@@ -186,7 +187,7 @@ void RSSWidget::displayItemsListMenu(const QPoint &)
{
bool hasTorrent = false;
bool hasLink = false;
foreach (const QListWidgetItem *item, m_articleListWidget->selectedItems()) {
for (const QListWidgetItem *item : copyAsConst(m_articleListWidget->selectedItems())) {
auto article = reinterpret_cast<RSS::Article *>(item->data(Qt::UserRole).value<quintptr>());
Q_ASSERT(article);
@@ -286,7 +287,7 @@ void RSSWidget::on_newFeedButton_clicked()
void RSSWidget::deleteSelectedItems()
{
QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems();
const QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems();
if (selectedItems.isEmpty())
return;
if ((selectedItems.size() == 1) && (selectedItems.first() == m_feedListWidget->stickyUnreadItem()))
@@ -298,7 +299,7 @@ void RSSWidget::deleteSelectedItems()
if (answer == QMessageBox::No)
return;
foreach (QTreeWidgetItem *item, selectedItems)
for (QTreeWidgetItem *item : selectedItems)
if (item != m_feedListWidget->stickyUnreadItem())
RSS::Session::instance()->removeItem(m_feedListWidget->itemPath(item));
}
@@ -306,9 +307,9 @@ void RSSWidget::deleteSelectedItems()
void RSSWidget::loadFoldersOpenState()
{
const QStringList openedFolders = Preferences::instance()->getRssOpenFolders();
foreach (const QString &varPath, openedFolders) {
for (const QString &varPath : openedFolders) {
QTreeWidgetItem *parent = nullptr;
foreach (const QString &name, varPath.split('\\')) {
for (const QString &name : copyAsConst(varPath.split('\\'))) {
int nbChildren = (parent ? parent->childCount() : m_feedListWidget->topLevelItemCount());
for (int i = 0; i < nbChildren; ++i) {
QTreeWidgetItem *child = (parent ? parent->child(i) : m_feedListWidget->topLevelItem(i));
@@ -325,7 +326,7 @@ void RSSWidget::loadFoldersOpenState()
void RSSWidget::saveFoldersOpenState()
{
QStringList openedFolders;
foreach (QTreeWidgetItem *item, m_feedListWidget->getAllOpenedFolders())
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->getAllOpenedFolders()))
openedFolders << m_feedListWidget->itemPath(item);
Preferences::instance()->setRssOpenFolders(openedFolders);
}
@@ -337,7 +338,7 @@ void RSSWidget::refreshAllFeeds()
void RSSWidget::downloadSelectedTorrents()
{
foreach (QListWidgetItem *item, m_articleListWidget->selectedItems()) {
for (QListWidgetItem *item : copyAsConst(m_articleListWidget->selectedItems())) {
auto article = reinterpret_cast<RSS::Article *>(item->data(Qt::UserRole).value<quintptr>());
Q_ASSERT(article);
@@ -356,7 +357,7 @@ void RSSWidget::downloadSelectedTorrents()
// open the url of the selected RSS articles in the Web browser
void RSSWidget::openSelectedArticlesUrls()
{
foreach (QListWidgetItem *item, m_articleListWidget->selectedItems()) {
for (QListWidgetItem *item : copyAsConst(m_articleListWidget->selectedItems())) {
auto article = reinterpret_cast<RSS::Article *>(item->data(Qt::UserRole).value<quintptr>());
Q_ASSERT(article);
@@ -397,7 +398,7 @@ void RSSWidget::renameSelectedRSSItem()
void RSSWidget::refreshSelectedItems()
{
foreach (QTreeWidgetItem *item, m_feedListWidget->selectedItems()) {
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->selectedItems())) {
if (item == m_feedListWidget->stickyUnreadItem()) {
refreshAllFeeds();
return;
@@ -410,7 +411,7 @@ void RSSWidget::refreshSelectedItems()
void RSSWidget::copySelectedFeedsURL()
{
QStringList URLs;
foreach (QTreeWidgetItem *item, m_feedListWidget->selectedItems()) {
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->selectedItems())) {
if (auto feed = qobject_cast<RSS::Feed *>(m_feedListWidget->getRSSItem(item)))
URLs << feed->url();
}
@@ -425,7 +426,7 @@ void RSSWidget::handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem)
void RSSWidget::on_markReadButton_clicked()
{
foreach (QTreeWidgetItem *item, m_feedListWidget->selectedItems()) {
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->selectedItems())) {
m_feedListWidget->getRSSItem(item)->markAsRead();
if (item == m_feedListWidget->stickyUnreadItem())
break; // all items was read

View File

@@ -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 : copyAsConst(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 : qAsConst(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 : copyAsConst(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 : copyAsConst(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 : copyAsConst(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 : copyAsConst(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 : copyAsConst(findItemsWithUrl(url))) {
QString id = item->text(PLUGIN_ID);
PluginInfo *plugin = m_pluginManager->pluginInfo(id);
if (!plugin) continue;

View File

@@ -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 : qAsConst(m_searchTermWords)) {
int i = name.indexOf(word, 0, Qt::CaseInsensitive);
if (i == -1) {
return false;

View File

@@ -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 : copyAsConst(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 : qAsConst(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 : copyAsConst(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 : qAsConst(tmpList))
m_ui->selectPlugin->addItem(p.first, QVariant(p.second));
if (m_ui->selectPlugin->count() > 3)

View File

@@ -32,6 +32,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "ui_statsdialog.h"
@@ -89,7 +90,7 @@ void StatsDialog::update()
// num_peers is not reliable (adds up peers, which didn't even overcome tcp handshake)
quint32 peers = 0;
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
peers += torrent->peersCount();
m_ui->labelWriteStarve->setText(QString("%1%")

View File

@@ -33,6 +33,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "guiiconprovider.h"
namespace
@@ -236,7 +237,7 @@ void TagFilterModel::torrentAdded(BitTorrent::TorrentHandle *const torrent)
if (items.isEmpty())
untaggedItem()->increaseTorrentsCount();
foreach (TagModelItem *item, items)
for (TagModelItem *item : items)
item->increaseTorrentsCount();
}
@@ -247,7 +248,7 @@ void TagFilterModel::torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const to
if (torrent->tags().isEmpty())
untaggedItem()->decreaseTorrentsCount();
foreach (TagModelItem *item, findItems(torrent->tags()))
for (TagModelItem *item : copyAsConst(findItems(torrent->tags())))
item->decreaseTorrentsCount();
}
@@ -274,7 +275,7 @@ void TagFilterModel::populate()
[](Torrent *torrent) { return torrent->tags().isEmpty(); });
addToModel(getSpecialUntaggedTag(), untaggedCount);
foreach (const QString &tag, session->tags()) {
for (const QString &tag : copyAsConst(session->tags())) {
const int count = std::count_if(torrents.begin(), torrents.end(),
[tag](Torrent *torrent) { return torrent->hasTag(tag); });
addToModel(tag, count);
@@ -313,7 +314,7 @@ QVector<TagModelItem *> TagFilterModel::findItems(const QSet<QString> &tags)
{
QVector<TagModelItem *> items;
items.reserve(tags.size());
foreach (const QString &tag, tags) {
for (const QString &tag : tags) {
TagModelItem *item = findItem(tag);
if (item)
items.push_back(item);

View File

@@ -35,6 +35,7 @@
#include <QMessageBox>
#include "base/bittorrent/session.h"
#include "base/global.h"
#include "autoexpandabledialog.h"
#include "guiiconprovider.h"
#include "tagfiltermodel.h"
@@ -222,7 +223,7 @@ void TagFilterWidget::removeTag()
void TagFilterWidget::removeUnusedTags()
{
auto session = BitTorrent::Session::instance();
foreach (const QString &tag, session->tags())
for (const QString &tag : copyAsConst(session->tags()))
if (model()->data(static_cast<TagFilterProxyModel *>(model())->index(tag), Qt::UserRole) == 0)
session->removeTag(tag);
updateGeometry();

View File

@@ -48,6 +48,7 @@
#include <QPixmapCache>
#endif
#include "base/global.h"
#include "base/utils/misc.h"
#include "base/utils/fs.h"
#include "guiiconprovider.h"
@@ -266,14 +267,14 @@ QVector<int> TorrentContentModel::getFilePriorities() const
{
QVector<int> prio;
prio.reserve(m_filesIndex.size());
foreach (const TorrentContentModelFile *file, m_filesIndex)
for (const TorrentContentModelFile *file : qAsConst(m_filesIndex))
prio.push_back(file->priority());
return prio;
}
bool TorrentContentModel::allFiltered() const
{
foreach (const TorrentContentModelFile *fileItem, m_filesIndex)
for (const TorrentContentModelFile *fileItem : qAsConst(m_filesIndex))
if (fileItem->priority() != prio::IGNORED)
return false;
return true;
@@ -476,7 +477,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
// Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split('/', QString::SkipEmptyParts);
pathFolders.removeLast();
foreach (const QString &pathPart, pathFolders) {
for (const QString &pathPart : qAsConst(pathFolders)) {
if (pathPart == ".unwanted")
continue;
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);

View File

@@ -29,6 +29,7 @@
#include "torrentcontentmodelfolder.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent)
: TorrentContentModelItem(parent)
@@ -85,7 +86,7 @@ TorrentContentModelItem *TorrentContentModelFolder::child(int row) const
TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
{
foreach (TorrentContentModelItem *child, m_childItems)
for (TorrentContentModelItem *child : qAsConst(m_childItems))
if ((child->itemType() == FolderType) && (child->name() == name))
return static_cast<TorrentContentModelFolder *>(child);
return nullptr;
@@ -132,7 +133,7 @@ void TorrentContentModelFolder::setPriority(int newPriority, bool updateParent)
// Update children
if (m_priority != prio::MIXED)
foreach (TorrentContentModelItem *child, m_childItems)
for (TorrentContentModelItem *child : qAsConst(m_childItems))
child->setPriority(m_priority, false);
}
@@ -141,7 +142,7 @@ void TorrentContentModelFolder::recalculateProgress()
qreal tProgress = 0;
qulonglong tSize = 0;
qulonglong tRemaining = 0;
foreach (TorrentContentModelItem *child, m_childItems) {
for (TorrentContentModelItem *child : qAsConst(m_childItems)) {
if (child->priority() == prio::IGNORED)
continue;
@@ -164,7 +165,7 @@ void TorrentContentModelFolder::recalculateAvailability()
qreal tAvailability = 0;
qulonglong tSize = 0;
bool foundAnyData = false;
foreach (TorrentContentModelItem *child, m_childItems) {
for (TorrentContentModelItem *child : qAsConst(m_childItems)) {
if (child->priority() == prio::IGNORED)
continue;

View File

@@ -40,6 +40,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/trackerentry.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
@@ -219,7 +220,7 @@ TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *tran
TrackerFiltersList::~TrackerFiltersList()
{
foreach (const QString &iconPath, m_iconPaths)
for (const QString &iconPath : qAsConst(m_iconPaths))
Utils::Fs::forceRemove(iconPath);
}
@@ -487,8 +488,8 @@ void TrackerFiltersList::applyFilter(int row)
void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent)
{
QString hash = torrent->hash();
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
for (const BitTorrent::TrackerEntry &tracker : trackers)
addItem(tracker.url(), hash);
//Check for trackerless torrent
@@ -501,8 +502,8 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent)
{
QString hash = torrent->hash();
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
for (const BitTorrent::TrackerEntry &tracker : trackers)
removeItem(tracker.url(), hash);
//Check for trackerless torrent
@@ -662,13 +663,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value)
void TransferListFiltersWidget::addTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers)
{
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
for (const BitTorrent::TrackerEntry &tracker : trackers)
m_trackerFilters->addItem(tracker.url(), torrent->hash());
}
void TransferListFiltersWidget::removeTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers)
{
foreach (const BitTorrent::TrackerEntry &tracker, trackers)
for (const BitTorrent::TrackerEntry &tracker : trackers)
m_trackerFilters->removeItem(tracker.url(), torrent->hash());
}

View File

@@ -36,6 +36,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/torrentfilter.h"
#include "base/utils/fs.h"
@@ -61,7 +62,7 @@ TransferListModel::TransferListModel(QObject *parent)
{
// Load the torrents
using namespace BitTorrent;
foreach (TorrentHandle *const torrent, Session::instance()->torrents())
for (TorrentHandle *const torrent : copyAsConst(Session::instance()->torrents()))
addTorrent(torrent);
// Listen for torrent changes

View File

@@ -43,6 +43,7 @@
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/torrentfilter.h"
@@ -72,7 +73,7 @@ namespace
QStringList extractHashes(const QList<BitTorrent::TorrentHandle *> &torrents)
{
QStringList hashes;
foreach (BitTorrent::TorrentHandle *const torrent, torrents)
for (BitTorrent::TorrentHandle *const torrent : torrents)
hashes << torrent->hash();
return hashes;
@@ -381,7 +382,7 @@ void TransferListWidget::torrentDoubleClicked()
QList<BitTorrent::TorrentHandle *> TransferListWidget::getSelectedTorrents() const
{
QList<BitTorrent::TorrentHandle *> torrents;
foreach (const QModelIndex &index, selectionModel()->selectedRows())
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows()))
torrents << m_listModel->torrentHandle(mapToSource(index));
return torrents;
@@ -401,7 +402,7 @@ void TransferListWidget::setSelectedTorrentsLocation()
qDebug("New location is %s", qUtf8Printable(newLocation));
// Actually move storage
foreach (BitTorrent::TorrentHandle *const torrent, torrents) {
for (BitTorrent::TorrentHandle *const torrent : torrents) {
Logger::instance()->addMessage(tr("Set location: moving \"%1\", from \"%2\" to \"%3\""
, "Set location: moving \"ubuntu_16_04.iso\", from \"/home/dir1\" to \"/home/dir2\"")
.arg(torrent->name(), Utils::Fs::toNativePath(torrent->savePath())
@@ -412,25 +413,25 @@ void TransferListWidget::setSelectedTorrentsLocation()
void TransferListWidget::pauseAllTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
torrent->pause();
}
void TransferListWidget::resumeAllTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
torrent->resume();
}
void TransferListWidget::startSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->resume();
}
void TransferListWidget::forceStartSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->resume(true);
}
@@ -445,7 +446,7 @@ void TransferListWidget::startVisibleTorrents()
void TransferListWidget::pauseSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->pause();
}
@@ -478,7 +479,7 @@ void TransferListWidget::deleteSelectedTorrents(bool deleteLocalFiles)
if (Preferences::instance()->confirmTorrentDeletion()
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
return;
foreach (BitTorrent::TorrentHandle *const torrent, torrents)
for (BitTorrent::TorrentHandle *const torrent : torrents)
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
}
@@ -495,7 +496,7 @@ void TransferListWidget::deleteVisibleTorrents()
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
return;
foreach (BitTorrent::TorrentHandle *const torrent, torrents)
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrents))
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
}
@@ -528,7 +529,7 @@ void TransferListWidget::bottomPrioSelectedTorrents()
void TransferListWidget::copySelectedMagnetURIs() const
{
QStringList magnetUris;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
magnetUris << torrent->toMagnetUri();
qApp->clipboard()->setText(magnetUris.join('\n'));
@@ -537,7 +538,7 @@ void TransferListWidget::copySelectedMagnetURIs() const
void TransferListWidget::copySelectedNames() const
{
QStringList torrentNames;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrentNames << torrent->name();
qApp->clipboard()->setText(torrentNames.join('\n'));
@@ -546,7 +547,7 @@ void TransferListWidget::copySelectedNames() const
void TransferListWidget::copySelectedHashes() const
{
QStringList torrentHashes;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrentHashes << torrent->hash();
qApp->clipboard()->setText(torrentHashes.join('\n'));
@@ -566,13 +567,13 @@ void TransferListWidget::openSelectedTorrentsFolder() const
#ifdef Q_OS_MAC
// On macOS you expect both the files and folders to be opened in their parent
// folders prehilighted for opening, so we use a custom method.
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
pathsList.insert(path);
}
MacUtils::openFiles(pathsList);
#else
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
if (!pathsList.contains(path)) {
if (torrent->filesCount() == 1)
@@ -587,7 +588,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
void TransferListWidget::previewSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
if (torrent->hasMetadata())
new PreviewSelectDialog(this, torrent);
}
@@ -596,7 +597,7 @@ void TransferListWidget::previewSelectedTorrents()
void TransferListWidget::setDlLimitSelectedTorrents()
{
QList<BitTorrent::TorrentHandle *> torrentsList;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
if (torrent->isSeed())
continue;
torrentsList += torrent;
@@ -604,7 +605,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->downloadLimit();
foreach (BitTorrent::TorrentHandle *const torrent, torrentsList) {
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
if (torrent->downloadLimit() != oldLimit) {
oldLimit = -1;
break;
@@ -617,7 +618,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
, BitTorrent::Session::instance()->globalDownloadSpeedLimit());
if (!ok) return;
foreach (BitTorrent::TorrentHandle *const torrent, torrentsList) {
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setDownloadLimit(newLimit);
}
@@ -629,7 +630,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->uploadLimit();
foreach (BitTorrent::TorrentHandle *const torrent, torrentsList) {
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
if (torrent->uploadLimit() != oldLimit) {
oldLimit = -1;
break;
@@ -642,7 +643,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
, BitTorrent::Session::instance()->globalUploadSpeedLimit());
if (!ok) return;
foreach (BitTorrent::TorrentHandle *const torrent, torrentsList) {
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setUploadLimit(newLimit);
}
@@ -670,7 +671,7 @@ void TransferListWidget::setMaxRatioSelectedTorrents()
currentMaxSeedingTime, BitTorrent::TorrentHandle::MAX_SEEDING_TIME, this);
if (dlg.exec() != QDialog::Accepted) return;
foreach (BitTorrent::TorrentHandle *const torrent, torrents) {
for (BitTorrent::TorrentHandle *const torrent : torrents) {
qreal ratio = (dlg.useDefault() ? BitTorrent::TorrentHandle::USE_GLOBAL_RATIO : dlg.ratio());
torrent->setRatioLimit(ratio);
@@ -686,13 +687,13 @@ void TransferListWidget::recheckSelectedTorrents()
if (ret != QMessageBox::Yes) return;
}
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->forceRecheck();
}
void TransferListWidget::reannounceSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->forceReannounce();
}
@@ -738,7 +739,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
if (torrent->hasMetadata())
torrent->setSuperSeeding(!torrent->superSeeding());
}
@@ -746,19 +747,19 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->toggleSequentialDownload();
}
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->toggleFirstLastPiecePriority();
}
void TransferListWidget::setSelectedAutoTMMEnabled(bool enabled) const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
torrent->setAutoTMMEnabled(enabled);
}
@@ -772,7 +773,7 @@ void TransferListWidget::askNewCategoryForSelection()
void TransferListWidget::askAddTagsForSelection()
{
const QStringList tags = askTagsForSelection(tr("Add Tags"));
foreach (const QString &tag, tags)
for (const QString &tag : tags)
addSelectionTag(tag);
}
@@ -811,7 +812,7 @@ QStringList TransferListWidget::askTagsForSelection(const QString &dialogTitle)
void TransferListWidget::applyToSelectedTorrents(const std::function<void (BitTorrent::TorrentHandle *const)> &fn)
{
foreach (const QModelIndex &index, selectionModel()->selectedRows()) {
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows())) {
BitTorrent::TorrentHandle *const torrent = m_listModel->torrentHandle(mapToSource(index));
Q_ASSERT(torrent);
fn(torrent);
@@ -839,7 +840,7 @@ void TransferListWidget::renameSelectedTorrent()
void TransferListWidget::setSelectionCategory(QString category)
{
foreach (const QModelIndex &index, selectionModel()->selectedRows())
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows()))
m_listModel->setData(m_listModel->index(mapToSource(index).row(), TransferListModel::TR_CATEGORY), category, Qt::DisplayRole);
}
@@ -860,7 +861,7 @@ void TransferListWidget::clearSelectionTags()
void TransferListWidget::displayListMenu(const QPoint&)
{
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
if (selectedIndexes.size() == 0) return;
// Create actions
@@ -936,7 +937,7 @@ void TransferListWidget::displayListMenu(const QPoint&)
BitTorrent::TorrentHandle *torrent;
qDebug("Displaying menu");
foreach (const QModelIndex &index, selectedIndexes) {
for (const QModelIndex &index : selectedIndexes) {
// Get the file name
// Get handle and pause the torrent
torrent = m_listModel->torrentHandle(mapToSource(index));
@@ -1022,7 +1023,7 @@ void TransferListWidget::displayListMenu(const QPoint&)
categoryActions << categoryMenu->addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("New...", "New category..."));
categoryActions << categoryMenu->addAction(GuiIconProvider::instance()->getIcon("edit-clear"), tr("Reset", "Reset category"));
categoryMenu->addSeparator();
foreach (QString category, categories) {
for (QString category : qAsConst(categories)) {
category.replace('&', "&&"); // avoid '&' becomes accelerator key
QAction *cat = new QAction(GuiIconProvider::instance()->getIcon("inode-directory"), category, categoryMenu);
if (allSameCategory && (category == firstCategory)) {
@@ -1041,7 +1042,7 @@ void TransferListWidget::displayListMenu(const QPoint&)
tagsActions << tagsMenu->addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add...", "Add / assign multiple tags..."));
tagsActions << tagsMenu->addAction(GuiIconProvider::instance()->getIcon("edit-clear"), tr("Remove All", "Remove all tags"));
tagsMenu->addSeparator();
foreach (QString tag, tags) {
for (const QString &tag : qAsConst(tags)) {
const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
: tagsInAny.contains(tag) ? Qt::PartiallyChecked
: Qt::Unchecked;