Merge pull request #9824 from thalieht/style

Convert all foreach() to range-based for()
This commit is contained in:
Mike Tzou
2018-12-06 16:19:17 +08:00
committed by GitHub
84 changed files with 471 additions and 441 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 : asConst(categories))
if (category != defaultCategory && category != m_torrentParams.category)
m_ui->categoryComboBox->addItem(category);
@@ -398,7 +398,7 @@ void AddNewTorrentDialog::saveSavePathHistory() const
// Get current history
QStringList history = settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList();
QVector<QDir> historyDirs;
for (const QString &path : qAsConst(history))
for (const QString &path : asConst(history))
historyDirs << QDir {path};
const QDir selectedSavePath {m_ui->savePath->selectedPath()};
@@ -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 : asConst(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 : asConst(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 : asConst(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 : asConst(BitTorrent::Session::expandCategory(fullName))) {
const QString subcatName = shortName(subcat);
if (!item->hasChild(subcatName)) return nullptr;
item = item->child(subcatName);

View File

@@ -231,7 +231,7 @@ void CategoryFilterWidget::removeCategory()
void CategoryFilterWidget::removeUnusedCategories()
{
auto session = BitTorrent::Session::instance();
for (const QString &category : copyAsConst(session->categories().keys())) {
for (const QString &category : asConst(session->categories().keys())) {
if (model()->data(static_cast<CategoryFilterProxyModel *>(model())->index(category), Qt::UserRole) == 0)
session->removeCategory(category);
}

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 : asConst(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 : asConst(logger->getMessages()))
addLogMessage(msg);
foreach (const Log::Peer &peer, logger->getPeers())
for (const Log::Peer &peer : asConst(logger->getPeers()))
addPeerMessage(peer);
connect(logger, &Logger::newLogMessage, this, &ExecutionLogWidget::addLogMessage);
connect(logger, &Logger::newLogPeer, this, &ExecutionLogWidget::addPeerMessage);

View File

@@ -350,7 +350,7 @@ void FileSystemPathComboEdit::addItem(const QString &text)
editWidget<WidgetType>()->addItem(Utils::Fs::toNativePath(text));
}
void FileSystemPathComboEdit::insertItem(int index, const QString& text)
void FileSystemPathComboEdit::insertItem(int index, const QString &text)
{
editWidget<WidgetType>()->insertItem(index, Utils::Fs::toNativePath(text));
}

View File

@@ -46,7 +46,7 @@ IPSubnetWhitelistOptionsDialog::IPSubnetWhitelistOptionsDialog(QWidget *parent)
m_ui->setupUi(this);
QStringList authSubnetWhitelistStringList;
for (const Utils::Net::Subnet &subnet : copyAsConst(Preferences::instance()->getWebUiAuthSubnetWhitelist()))
for (const Utils::Net::Subnet &subnet : asConst(Preferences::instance()->getWebUiAuthSubnetWhitelist()))
authSubnetWhitelistStringList << Utils::Net::subnetToString(subnet);
m_model = new QStringListModel(authSubnetWhitelistStringList, this);
@@ -99,7 +99,7 @@ void IPSubnetWhitelistOptionsDialog::on_buttonWhitelistIPSubnet_clicked()
void IPSubnetWhitelistOptionsDialog::on_buttonDeleteIPSubnet_clicked()
{
for (const auto &i : copyAsConst(m_ui->whitelistedIPSubnetList->selectionModel()->selectedIndexes()))
for (const auto &i : asConst(m_ui->whitelistedIPSubnetList->selectionModel()->selectedIndexes()))
m_sortFilter->removeRow(i.row());
m_modified = true;

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 : asConst(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 : asConst(m_ui->toolBar->actions())) {
if (action->isSeparator()) {
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
@@ -305,7 +305,7 @@ MainWindow::MainWindow(QWidget *parent)
spacer->setMinimumWidth(8);
m_ui->toolBar->addWidget(spacer);
}
#endif
#endif // Q_OS_MAC
// Transfer list slots
connect(m_ui->actionStart, &QAction::triggered, m_transferListWidget, &TransferListWidget::startSelectedTorrents);
@@ -1110,7 +1110,7 @@ void MainWindow::toggleVisibility(const QSystemTrayIcon::ActivationReason reason
break;
}
}
#endif
#endif // Q_OS_MAC
// Display About Dialog
void MainWindow::on_actionAbout_triggered()
@@ -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 : asConst(QApplication::allWidgets())) {
if (widget->isModal()) {
hasModalWindow = true;
break;
@@ -1272,7 +1272,7 @@ bool MainWindow::event(QEvent *e)
default:
break;
}
#endif
#endif // Q_OS_MAC
return QMainWindow::event(e);
}
@@ -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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(event->mimeData()->formats()))
qDebug("mimeData: %s", mime.toLocal8Bit().data());
if (event->mimeData()->hasFormat("text/plain") || event->mimeData()->hasFormat("text/uri-list"))
event->acceptProposedAction();
@@ -1361,7 +1361,7 @@ void MainWindow::setupDockClickHandler()
MacUtils::overrideDockClickHandler(dockClickHandler);
}
#endif
#endif // Q_OS_MAC
/*****************************************************
* *
@@ -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,10 +160,10 @@ 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) {
applyButton = button;
m_applyButton = button;
break;
}
}
@@ -424,13 +424,13 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->btnEditRules, &QPushButton::clicked, this, [this]() { AutomatedRssDownloader(this).exec(); });
// Disable apply Button
applyButton->setEnabled(false);
m_applyButton->setEnabled(false);
// Tab selection mechanism
connect(m_ui->tabSelection, &QListWidget::currentItemChanged, this, &ThisType::changePage);
// Load Advanced settings
advancedSettings = new AdvancedSettings(m_ui->tabAdvancedPage);
m_ui->advPageLayout->addWidget(advancedSettings);
connect(advancedSettings, &AdvancedSettings::settingsChanged, this, &ThisType::enableApplyButton);
m_advancedSettings = new AdvancedSettings(m_ui->tabAdvancedPage);
m_ui->advPageLayout->addWidget(m_advancedSettings);
connect(m_advancedSettings, &AdvancedSettings::settingsChanged, this, &ThisType::enableApplyButton);
m_ui->textFileLogPath->setDialogCaption(tr("Choose a save directory"));
m_ui->textFileLogPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
@@ -453,9 +453,9 @@ OptionsDialog::OptionsDialog(QWidget *parent)
// disable mouse wheel event on widgets to avoid mis-selection
WheelEventEater *wheelEventEater = new WheelEventEater(this);
for (QComboBox *widget : copyAsConst(findChildren<QComboBox *>()))
for (QComboBox *widget : asConst(findChildren<QComboBox *>()))
widget->installEventFilter(wheelEventEater);
for (QSpinBox *widget : copyAsConst(findChildren<QSpinBox *>()))
for (QSpinBox *widget : asConst(findChildren<QSpinBox *>()))
widget->installEventFilter(wheelEventEater);
loadWindowState();
@@ -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, addedScanDirs)
for (const QString &path : asConst(m_addedScanDirs))
ScanFoldersModel::instance()->removePath(path);
ScanFoldersModel::instance()->configure(); // reloads "removed" paths
delete m_ui;
@@ -541,7 +541,7 @@ void OptionsDialog::saveWindowState() const
void OptionsDialog::saveOptions()
{
applyButton->setEnabled(false);
m_applyButton->setEnabled(false);
Preferences *const pref = Preferences::instance();
// Load the translation
QString locale = getLocale();
@@ -625,11 +625,11 @@ void OptionsDialog::saveOptions()
AddNewTorrentDialog::setTopLevel(m_ui->checkAdditionDialogFront->isChecked());
session->setAddTorrentPaused(addTorrentsInPause());
session->setCreateTorrentSubfolder(m_ui->checkCreateSubfolder->isChecked());
ScanFoldersModel::instance()->removeFromFSWatcher(removedScanDirs);
ScanFoldersModel::instance()->addToFSWatcher(addedScanDirs);
ScanFoldersModel::instance()->removeFromFSWatcher(m_removedScanDirs);
ScanFoldersModel::instance()->addToFSWatcher(m_addedScanDirs);
ScanFoldersModel::instance()->makePersistent();
removedScanDirs.clear();
addedScanDirs.clear();
m_removedScanDirs.clear();
m_addedScanDirs.clear();
session->setTorrentExportDirectory(getTorrentExportDir());
session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked());
@@ -748,7 +748,7 @@ void OptionsDialog::saveOptions()
// End Web UI
// End preferences
// Save advanced settings
advancedSettings->saveAdvancedSettings();
m_advancedSettings->saveAdvancedSettings();
// Assume that user changed multiple settings
// so it's best to save immediately
pref->apply();
@@ -1240,7 +1240,7 @@ int OptionsDialog::getMaxUploadsPerTorrent() const
void OptionsDialog::on_buttonBox_accepted()
{
if (applyButton->isEnabled()) {
if (m_applyButton->isEnabled()) {
if (!schedTimesOk()) {
m_ui->tabSelection->setCurrentRow(TAB_SPEED);
return;
@@ -1249,7 +1249,7 @@ void OptionsDialog::on_buttonBox_accepted()
m_ui->tabSelection->setCurrentRow(TAB_WEBUI);
return;
}
applyButton->setEnabled(false);
m_applyButton->setEnabled(false);
this->hide();
saveOptions();
}
@@ -1259,7 +1259,7 @@ void OptionsDialog::on_buttonBox_accepted()
void OptionsDialog::applySettings(QAbstractButton *button)
{
if (button == applyButton) {
if (button == m_applyButton) {
if (!schedTimesOk()) {
m_ui->tabSelection->setCurrentRow(TAB_SPEED);
return;
@@ -1291,7 +1291,7 @@ bool OptionsDialog::useAdditionDialog() const
void OptionsDialog::enableApplyButton()
{
applyButton->setEnabled(true);
m_applyButton->setEnabled(true);
}
void OptionsDialog::toggleComboRatioLimitAct()
@@ -1486,7 +1486,7 @@ void OptionsDialog::on_addScanFolderButton_clicked()
break;
default:
pref->setScanDirsLastPath(dir);
addedScanDirs << dir;
m_addedScanDirs << dir;
for (int i = 0; i < ScanFoldersModel::instance()->columnCount(); ++i)
m_ui->scanFoldersView->resizeColumnToContents(i);
enableApplyButton();
@@ -1504,9 +1504,9 @@ 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)
removedScanDirs << index.data().toString();
m_removedScanDirs << index.data().toString();
}
ScanFoldersModel::instance()->removePath(selected.first().row(), false);
}

View File

@@ -176,11 +176,10 @@ private:
QByteArray m_sslCert, m_sslKey;
Ui::OptionsDialog *m_ui;
QButtonGroup choiceLanguage;
QAbstractButton *applyButton;
AdvancedSettings *advancedSettings;
QList<QString> addedScanDirs;
QList<QString> removedScanDirs;
QAbstractButton *m_applyButton;
AdvancedSettings *m_advancedSettings;
QList<QString> m_addedScanDirs;
QList<QString> m_removedScanDirs;
};
#endif // OPTIONSDIALOG_H

View File

@@ -141,7 +141,7 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION;
QStringList remoteParts = remoteVersion.split('.');
QStringList localParts = localVersion.split('.');
for (int i = 0; i<qMin(remoteParts.size(), localParts.size()); ++i) {
for (int i = 0; i < qMin(remoteParts.size(), localParts.size()); ++i) {
if (remoteParts[i].toInt() > localParts[i].toInt())
return true;
if (remoteParts[i].toInt() < localParts[i].toInt())

View File

@@ -103,7 +103,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
hideColumn(PeerListDelegate::COUNTRY);
// Ensure that at least one column is visible at all times
bool atLeastOne = false;
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
if (!isColumnHidden(i)) {
atLeastOne = true;
break;
@@ -114,7 +114,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
// To also mitigate the above issue, we have to resize each column when
// its size is 0, because explicitly 'showing' the column isn't enough
// in the above scenario.
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i)
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i)
if ((columnWidth(i) <= 0) && !isColumnHidden(i))
resizeColumnToContents(i);
// Context menu
@@ -169,7 +169,7 @@ void PeerListWidget::displayToggleColumnsMenu(const QPoint &)
actions.append(myAct);
}
int visibleCols = 0;
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) {
if (!isColumnHidden(i))
++visibleCols;
@@ -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();
@@ -321,7 +321,7 @@ void PeerListWidget::clear()
int nbrows = m_listModel->rowCount();
if (nbrows > 0) {
qDebug("Cleared %d peers", nbrows);
m_listModel->removeRows(0, nbrows);
m_listModel->removeRows(0, nbrows);
}
}
@@ -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 : asConst(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) {
@@ -275,7 +275,7 @@ void PiecesBar::showToolTip(const QHelpEvent *e)
DetailedTooltipRenderer renderer(stream, tooltipTitle);
const bool isFileNameCorrectionNeeded = this->isFileNameCorrectionNeeded();
for (int f: files) {
for (int f : files) {
QString filePath {m_torrent->info().filePath(f)};
if (isFileNameCorrectionNeeded)
filePath.replace(QLatin1String("/.unwanted"), QString());

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 : asConst(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),
@@ -348,7 +348,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
double legendHeight = 0;
int legendWidth = 0;
for (const auto &property : qAsConst(m_properties)) {
for (const auto &property : asConst(m_properties)) {
if (!property.enable)
continue;
@@ -363,7 +363,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
painter.fillRect(legendBackgroundRect, legendBackgroundColor);
i = 0;
for (const auto &property : qAsConst(m_properties)) {
for (const auto &property : asConst(m_properties)) {
if (!property.enable)
continue;

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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {
for (const QString &token : asConst(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 : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
foreach (const QString &token, tokens) {
for (const QString &token : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : 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;

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 : asConst(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 : 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)

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 : asConst(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 : asConst(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 : asConst(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 : asConst(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"
@@ -146,7 +147,7 @@ namespace
#elif defined(Q_OS_MAC)
// There is a similar bug on macOS, to be reported to Qt
// https://github.com/qbittorrent/qBittorrent/pull/6156#issuecomment-316302615
class MacFileIconProvider final: public CachingFileIconProvider
class MacFileIconProvider final : public CachingFileIconProvider
{
QPixmap pixmapForExtension(const QString &ext) const override
{
@@ -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 : asConst(m_filesIndex))
prio.push_back(file->priority());
return prio;
}
bool TorrentContentModel::allFiltered() const
{
foreach (const TorrentContentModelFile *fileItem, m_filesIndex)
for (const TorrentContentModelFile *fileItem : asConst(m_filesIndex))
if (fileItem->priority() != prio::IGNORED)
return false;
return true;
@@ -346,7 +347,7 @@ int TorrentContentModel::getFileIndex(const QModelIndex &index)
return -1;
}
QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
@@ -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 : asConst(pathFolders)) {
if (pathPart == ".unwanted")
continue;
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);

View File

@@ -54,13 +54,13 @@ public:
QVector<int> getFilePriorities() const;
bool allFiltered() const;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool setData(const QModelIndex &index, const QVariant& value, int role = Qt::EditRole) override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
TorrentContentModelItem::ItemType itemType(const QModelIndex &index) const;
int getFileIndex(const QModelIndex &index);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void clear();

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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(m_iconPaths))
Utils::Fs::forceRemove(iconPath);
}
@@ -404,7 +405,7 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac
applyFilter(3);
}
void TrackerFiltersList::downloadFavicon(const QString& url)
void TrackerFiltersList::downloadFavicon(const QString &url)
{
if (!m_downloadTrackerFavicon) return;
Net::DownloadHandler *h = Net::DownloadManager::instance()->download(
@@ -416,7 +417,7 @@ void TrackerFiltersList::downloadFavicon(const QString& url)
, &TrackerFiltersList::handleFavicoFailure);
}
void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath)
void TrackerFiltersList::handleFavicoDownload(const QString &url, const QString &filePath)
{
QString host = url.startsWith(GOOGLE_FAVICON_URL)
? url.mid(GOOGLE_FAVICON_URL.size())
@@ -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 : asConst(Session::instance()->torrents()))
addTorrent(torrent);
// Listen for torrent changes

View File

@@ -83,7 +83,7 @@ public:
explicit TransferListModel(QObject *parent = nullptr);
int rowCount(const QModelIndex& index = QModelIndex()) const override;
int rowCount(const QModelIndex &index = QModelIndex()) const override;
int columnCount(const QModelIndex &parent=QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;

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 : asConst(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 : asConst(BitTorrent::Session::instance()->torrents()))
torrent->pause();
}
void TransferListWidget::resumeAllTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
torrent->resume();
}
void TransferListWidget::startSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->resume();
}
void TransferListWidget::forceStartSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
pathsList.insert(path);
}
MacUtils::openFiles(pathsList);
#else
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
if (!pathsList.contains(path)) {
if (torrent->filesCount() == 1)
@@ -582,12 +583,12 @@ void TransferListWidget::openSelectedTorrentsFolder() const
}
pathsList.insert(path);
}
#endif
#endif // Q_OS_MAC
}
void TransferListWidget::previewSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->hasMetadata())
new PreviewSelectDialog(this, torrent);
}
@@ -595,16 +596,16 @@ void TransferListWidget::previewSelectedTorrents()
void TransferListWidget::setDlLimitSelectedTorrents()
{
QList<BitTorrent::TorrentHandle *> TorrentsList;
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents()) {
QList<BitTorrent::TorrentHandle *> torrentsList;
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->isSeed())
continue;
TorrentsList += torrent;
torrentsList += torrent;
}
if (TorrentsList.empty()) return;
if (torrentsList.empty()) return;
int oldLimit = TorrentsList.first()->downloadLimit();
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
int oldLimit = torrentsList.first()->downloadLimit();
for (BitTorrent::TorrentHandle *const torrent : asConst(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 : asConst(torrentsList)) {
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (newLimit / 1024l), qUtf8Printable(torrent->hash()));
torrent->setDownloadLimit(newLimit);
}
@@ -625,11 +626,11 @@ void TransferListWidget::setDlLimitSelectedTorrents()
void TransferListWidget::setUpLimitSelectedTorrents()
{
QList<BitTorrent::TorrentHandle *> TorrentsList = getSelectedTorrents();
if (TorrentsList.empty()) return;
QList<BitTorrent::TorrentHandle *> torrentsList = getSelectedTorrents();
if (torrentsList.empty()) return;
int oldLimit = TorrentsList.first()->uploadLimit();
foreach (BitTorrent::TorrentHandle *const torrent, TorrentsList) {
int oldLimit = torrentsList.first()->uploadLimit();
for (BitTorrent::TorrentHandle *const torrent : asConst(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 : asConst(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 : asConst(getSelectedTorrents()))
torrent->forceRecheck();
}
void TransferListWidget::reannounceSelectedTorrents()
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(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 : asConst(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 : asConst(getSelectedTorrents()))
torrent->toggleSequentialDownload();
}
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->toggleFirstLastPiecePriority();
}
void TransferListWidget::setSelectedAutoTMMEnabled(bool enabled) const
{
foreach (BitTorrent::TorrentHandle *const torrent, getSelectedTorrents())
for (BitTorrent::TorrentHandle *const torrent : asConst(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 : asConst(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 : asConst(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 : asConst(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 : asConst(tags)) {
const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
: tagsInAny.contains(tag) ? Qt::PartiallyChecked
: Qt::Unchecked;
@@ -1144,7 +1145,7 @@ void TransferListWidget::displayListMenu(const QPoint&)
}
}
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&)
void TransferListWidget::currentChanged(const QModelIndex &current, const QModelIndex&)
{
qDebug("CURRENT CHANGED");
BitTorrent::TorrentHandle *torrent = nullptr;

View File

@@ -106,7 +106,7 @@ protected:
protected slots:
void torrentDoubleClicked();
void displayListMenu(const QPoint&);
void currentChanged(const QModelIndex& current, const QModelIndex&) override;
void currentChanged(const QModelIndex &current, const QModelIndex&) override;
void toggleSelectedTorrentsSuperSeeding() const;
void toggleSelectedTorrentsSequentialDownload() const;
void toggleSelectedFirstLastPiecePrio() const;