Combine qAsConst() with copyAsConst() to asConst()

This commit is contained in:
thalieht
2018-11-27 22:15:04 +02:00
parent 6b1d26d555
commit 1f36b8b89f
57 changed files with 199 additions and 202 deletions

View File

@@ -143,7 +143,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
m_ui->categoryComboBox->addItem(defaultCategory);
m_ui->categoryComboBox->addItem("");
for (const QString &category : qAsConst(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()};

View File

@@ -287,7 +287,7 @@ void AdvancedSettings::updateInterfaceAddressCombo()
};
if (ifaceName.isEmpty()) {
for (const QHostAddress &ip : copyAsConst(QNetworkInterface::allAddresses()))
for (const QHostAddress &ip : asConst(QNetworkInterface::allAddresses()))
populateCombo(ip.toString(), ip.protocol());
}
else {
@@ -426,7 +426,7 @@ void AdvancedSettings::loadAdvancedSettings()
const QString currentInterface = session->networkInterface();
bool interfaceExists = currentInterface.isEmpty();
int i = 1;
for (const QNetworkInterface &iface : copyAsConst(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

@@ -408,7 +408,7 @@ void CategoryFilterModel::populate()
const QString &category = i.key();
if (m_isSubcategoriesEnabled) {
CategoryModelItem *parent = m_rootItem;
for (const QString &subcat : copyAsConst(session->expandCategory(category))) {
for (const QString &subcat : asConst(session->expandCategory(category))) {
const QString subcatName = shortName(subcat);
if (!parent->hasChild(subcatName)) {
new CategoryModelItem(
@@ -437,7 +437,7 @@ CategoryModelItem *CategoryFilterModel::findItem(const QString &fullName) const
return m_rootItem->child(fullName);
CategoryModelItem *item = m_rootItem;
for (const QString &subcat : copyAsConst(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

@@ -101,6 +101,6 @@ void CookiesDialog::onButtonDeleteClicked()
}
);
for (const QModelIndex &idx : qAsConst(idxs))
for (const QModelIndex &idx : asConst(idxs))
m_cookiesModel->removeRow(idx.row());
}

View File

@@ -53,9 +53,9 @@ ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &typ
m_ui->tabBan->layout()->addWidget(m_peerList);
const Logger *const logger = Logger::instance();
for (const Log::Msg &msg : copyAsConst(logger->getMessages()))
for (const Log::Msg &msg : asConst(logger->getMessages()))
addLogMessage(msg);
for (const Log::Peer &peer : copyAsConst(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

@@ -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

@@ -98,7 +98,7 @@ void LogListWidget::copySelection()
{
static const QRegularExpression htmlTag("<[^>]+>");
QStringList strings;
for (QListWidgetItem* it : copyAsConst(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
for (QAction *action : copyAsConst(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);
@@ -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;
for (QWidget *widget : copyAsConst(QApplication::allWidgets())) {
for (QWidget *widget : asConst(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()) {
for (const QUrl &url : copyAsConst(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;
for (const QString &file : qAsConst(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();
for (const QString &file : qAsConst(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
for (const QString &file : qAsConst(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)
{
for (const QString &mime : copyAsConst(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();

View File

@@ -439,9 +439,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();
@@ -479,7 +479,7 @@ OptionsDialog::~OptionsDialog()
saveWindowState();
for (const QString &path : qAsConst(m_addedScanDirs))
for (const QString &path : asConst(m_addedScanDirs))
ScanFoldersModel::instance()->removePath(path);
ScanFoldersModel::instance()->configure(); // reloads "removed" paths
delete m_ui;

View File

@@ -62,7 +62,7 @@ void PeersAdditionDialog::validateInput()
QMessageBox::Ok);
return;
}
for (const QString &peer : copyAsConst(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

@@ -103,7 +103,7 @@ PropTabBar::PropTabBar(QWidget *parent)
connect(m_btnGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked)
, this, &PropTabBar::setCurrentIndex);
// Disable buttons focus
for (QAbstractButton *btn : copyAsConst(m_btnGroup->buttons()))
for (QAbstractButton *btn : asConst(m_btnGroup->buttons()))
btn->setFocusPolicy(Qt::NoFocus);
}

View File

@@ -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

@@ -290,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;
for (const BitTorrent::PeerInfo &peer : copyAsConst(torrent->peers())) {
for (const BitTorrent::PeerInfo &peer : asConst(torrent->peers())) {
if (peer.isConnecting()) continue;
if (peer.fromDHT()) {
@@ -332,7 +332,7 @@ void TrackerListWidget::loadTrackers()
// Load actual trackers information
QHash<QString, BitTorrent::TrackerInfo> trackerData = torrent->trackerInfos();
QStringList oldTrackerURLs = m_trackerItems.keys();
for (const BitTorrent::TrackerEntry &entry : copyAsConst(torrent->trackers())) {
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers())) {
QString trackerURL = entry.url();
QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr);
if (!item) {
@@ -384,7 +384,7 @@ void TrackerListWidget::loadTrackers()
item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
}
// Remove old trackers
for (const QString &tracker : qAsConst(oldTrackerURLs))
for (const QString &tracker : asConst(oldTrackerURLs))
delete m_trackerItems.take(tracker);
}
@@ -395,7 +395,7 @@ void TrackerListWidget::askForTrackers()
if (!torrent) return;
QList<BitTorrent::TrackerEntry> trackers;
for (const QString &tracker : copyAsConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
trackers << tracker;
torrent->addTrackers(trackers);

View File

@@ -60,7 +60,7 @@ TrackersAdditionDialog::~TrackersAdditionDialog()
QStringList TrackersAdditionDialog::newTrackers() const
{
QStringList cleanTrackers;
for (QString url : copyAsConst(m_ui->textEditTrackersList->toPlainText().split('\n'))) {
for (QString url : asConst(m_ui->textEditTrackersList->toPlainText().split('\n'))) {
url = url.trimmed();
if (!url.isEmpty())
cleanTrackers << url;

View File

@@ -69,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);
for (const auto article : copyAsConst(rssItem->articles())) {
for (const auto article : asConst(rssItem->articles())) {
if (!(m_unreadOnly && article->isRead())) {
auto item = createItem(article);
addItem(item);

View File

@@ -132,7 +132,7 @@ AutomatedRssDownloader::AutomatedRssDownloader(QWidget *parent)
loadFeedList();
m_ui->listRules->blockSignals(true);
for (const RSS::AutoDownloadRule &rule : copyAsConst(RSS::AutoDownloader::instance()->rules()))
for (const RSS::AutoDownloadRule &rule : asConst(RSS::AutoDownloader::instance()->rules()))
createRuleItem(rule);
m_ui->listRules->blockSignals(false);
@@ -182,7 +182,7 @@ void AutomatedRssDownloader::loadFeedList()
{
const QSignalBlocker feedListSignalBlocker(m_ui->listFeeds);
for (const auto feed : copyAsConst(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);
@@ -212,7 +212,7 @@ void AutomatedRssDownloader::updateFeedList()
bool allEnabled = true;
bool anyEnabled = false;
for (const QListWidgetItem *ruleItem : qAsConst(selection)) {
for (const QListWidgetItem *ruleItem : asConst(selection)) {
auto rule = RSS::AutoDownloader::instance()->ruleByName(ruleItem->text());
if (rule.feedURLs().contains(feedURL))
anyEnabled = true;
@@ -549,7 +549,7 @@ void AutomatedRssDownloader::clearSelectedRuleDownloadedEpisodeList()
void AutomatedRssDownloader::handleFeedCheckStateChange(QListWidgetItem *feedItem)
{
const QString feedURL = feedItem->data(Qt::UserRole).toString();
for (QListWidgetItem *ruleItem : copyAsConst(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()));
@@ -573,16 +573,16 @@ void AutomatedRssDownloader::updateMatchingArticles()
{
m_ui->treeMatchingArticles->clear();
for (const QListWidgetItem *ruleItem : copyAsConst(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()));
for (const QString &feedURL : copyAsConst(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;
for (const auto article : copyAsConst(feed->articles()))
for (const auto article : asConst(feed->articles()))
if (rule.matches(article->data()))
matchingArticles << article->title();
if (!matchingArticles.isEmpty())
@@ -676,10 +676,10 @@ void AutomatedRssDownloader::updateMustLineValidity()
if (isRegex)
tokens << text;
else
for (const QString &token : copyAsConst(text.split('|')))
for (const QString &token : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
for (const QString &token : qAsConst(tokens)) {
for (const QString &token : asConst(tokens)) {
QRegularExpression reg(token, QRegularExpression::CaseInsensitiveOption);
if (!reg.isValid()) {
if (isRegex)
@@ -714,10 +714,10 @@ void AutomatedRssDownloader::updateMustNotLineValidity()
if (isRegex)
tokens << text;
else
for (const QString &token : copyAsConst(text.split('|')))
for (const QString &token : asConst(text.split('|')))
tokens << Utils::String::wildcardToRegex(token);
for (const QString &token : qAsConst(tokens)) {
for (const QString &token : asConst(tokens)) {
QRegularExpression reg(token, QRegularExpression::CaseInsensitiveOption);
if (!reg.isValid()) {
if (isRegex)

View File

@@ -220,7 +220,7 @@ void FeedListWidget::dropEvent(QDropEvent *event)
: RSS::Session::instance()->rootFolder());
// move as much items as possible
for (QTreeWidgetItem *srcItem : copyAsConst(selectedItems())) {
for (QTreeWidgetItem *srcItem : asConst(selectedItems())) {
auto rssItem = getRSSItem(srcItem);
RSS::Session::instance()->moveItem(rssItem, RSS::Item::joinPath(destFolder->path(), rssItem->name()));
}
@@ -265,7 +265,7 @@ QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem
void FeedListWidget::fill(QTreeWidgetItem *parent, RSS::Folder *rssParent)
{
for (const auto rssItem : copyAsConst(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

@@ -187,7 +187,7 @@ void RSSWidget::displayItemsListMenu(const QPoint &)
{
bool hasTorrent = false;
bool hasLink = false;
for (const QListWidgetItem *item : copyAsConst(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);
@@ -309,7 +309,7 @@ void RSSWidget::loadFoldersOpenState()
const QStringList openedFolders = Preferences::instance()->getRssOpenFolders();
for (const QString &varPath : openedFolders) {
QTreeWidgetItem *parent = nullptr;
for (const QString &name : copyAsConst(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));
@@ -326,7 +326,7 @@ void RSSWidget::loadFoldersOpenState()
void RSSWidget::saveFoldersOpenState()
{
QStringList openedFolders;
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->getAllOpenedFolders()))
for (QTreeWidgetItem *item : asConst(m_feedListWidget->getAllOpenedFolders()))
openedFolders << m_feedListWidget->itemPath(item);
Preferences::instance()->setRssOpenFolders(openedFolders);
}
@@ -338,7 +338,7 @@ void RSSWidget::refreshAllFeeds()
void RSSWidget::downloadSelectedTorrents()
{
for (QListWidgetItem *item : copyAsConst(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);
@@ -357,7 +357,7 @@ void RSSWidget::downloadSelectedTorrents()
// open the url of the selected RSS articles in the Web browser
void RSSWidget::openSelectedArticlesUrls()
{
for (QListWidgetItem *item : copyAsConst(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);
@@ -398,7 +398,7 @@ void RSSWidget::renameSelectedRSSItem()
void RSSWidget::refreshSelectedItems()
{
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->selectedItems())) {
for (QTreeWidgetItem *item : asConst(m_feedListWidget->selectedItems())) {
if (item == m_feedListWidget->stickyUnreadItem()) {
refreshAllFeeds();
return;
@@ -411,7 +411,7 @@ void RSSWidget::refreshSelectedItems()
void RSSWidget::copySelectedFeedsURL()
{
QStringList URLs;
for (QTreeWidgetItem *item : copyAsConst(m_feedListWidget->selectedItems())) {
for (QTreeWidgetItem *item : asConst(m_feedListWidget->selectedItems())) {
if (auto feed = qobject_cast<RSS::Feed *>(m_feedListWidget->getRSSItem(item)))
URLs << feed->url();
}
@@ -426,7 +426,7 @@ void RSSWidget::handleCurrentFeedItemChanged(QTreeWidgetItem *currentItem)
void RSSWidget::on_markReadButton_clicked()
{
for (QTreeWidgetItem *item : copyAsConst(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

@@ -111,7 +111,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
QStringList files;
if (event->mimeData()->hasUrls()) {
for (const QUrl &url : copyAsConst(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();
@@ -126,7 +126,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
if (files.isEmpty()) return;
for (const QString &file : qAsConst(files)) {
for (const QString &file : asConst(files)) {
qDebug("dropped %s", qUtf8Printable(file));
startAsyncOp();
m_pluginManager->installPlugin(file);
@@ -136,7 +136,7 @@ void PluginSelectDialog::dropEvent(QDropEvent *event)
// Decode if we accept drag 'n drop or not
void PluginSelectDialog::dragEnterEvent(QDragEnterEvent *event)
{
for (const QString &mime : copyAsConst(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;
for (QTreeWidgetItem *item : copyAsConst(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)
{
for (QTreeWidgetItem *item : copyAsConst(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();
for (const QString &name : copyAsConst(m_pluginManager->allPlugins()))
for (const QString &name : asConst(m_pluginManager->allPlugins()))
addNewPlugin(name);
}
@@ -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) {
for (QTreeWidgetItem *item : copyAsConst(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

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

View File

@@ -167,11 +167,11 @@ void SearchWidget::fillCatCombobox()
using QStrPair = QPair<QString, QString>;
QList<QStrPair> tmpList;
for (const QString &cat : copyAsConst(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); });
for (const QStrPair &p : qAsConst(tmpList)) {
for (const QStrPair &p : asConst(tmpList)) {
qDebug("Supported category: %s", qUtf8Printable(p.second));
m_ui->comboCategory->addItem(p.first, QVariant(p.second));
}
@@ -189,11 +189,11 @@ void SearchWidget::fillPluginComboBox()
using QStrPair = QPair<QString, QString>;
QList<QStrPair> tmpList;
for (const QString &name : copyAsConst(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); } );
for (const QStrPair &p : qAsConst(tmpList))
for (const QStrPair &p : asConst(tmpList))
m_ui->selectPlugin->addItem(p.first, QVariant(p.second));
if (m_ui->selectPlugin->count() > 3)

View File

@@ -90,7 +90,7 @@ void StatsDialog::update()
// num_peers is not reliable (adds up peers, which didn't even overcome tcp handshake)
quint32 peers = 0;
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(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

@@ -248,7 +248,7 @@ void TagFilterModel::torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const to
if (torrent->tags().isEmpty())
untaggedItem()->decreaseTorrentsCount();
for (TagModelItem *item : copyAsConst(findItems(torrent->tags())))
for (TagModelItem *item : asConst(findItems(torrent->tags())))
item->decreaseTorrentsCount();
}
@@ -275,7 +275,7 @@ void TagFilterModel::populate()
[](Torrent *torrent) { return torrent->tags().isEmpty(); });
addToModel(getSpecialUntaggedTag(), untaggedCount);
for (const QString &tag : copyAsConst(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);

View File

@@ -223,7 +223,7 @@ void TagFilterWidget::removeTag()
void TagFilterWidget::removeUnusedTags()
{
auto session = BitTorrent::Session::instance();
for (const QString &tag : copyAsConst(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

@@ -267,14 +267,14 @@ QVector<int> TorrentContentModel::getFilePriorities() const
{
QVector<int> prio;
prio.reserve(m_filesIndex.size());
for (const TorrentContentModelFile *file : qAsConst(m_filesIndex))
for (const TorrentContentModelFile *file : asConst(m_filesIndex))
prio.push_back(file->priority());
return prio;
}
bool TorrentContentModel::allFiltered() const
{
for (const TorrentContentModelFile *fileItem : qAsConst(m_filesIndex))
for (const TorrentContentModelFile *fileItem : asConst(m_filesIndex))
if (fileItem->priority() != prio::IGNORED)
return false;
return true;
@@ -477,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();
for (const QString &pathPart : qAsConst(pathFolders)) {
for (const QString &pathPart : asConst(pathFolders)) {
if (pathPart == ".unwanted")
continue;
TorrentContentModelFolder* newParent = currentParent->childFolderWithName(pathPart);

View File

@@ -86,7 +86,7 @@ TorrentContentModelItem *TorrentContentModelFolder::child(int row) const
TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
{
for (TorrentContentModelItem *child : qAsConst(m_childItems))
for (TorrentContentModelItem *child : asConst(m_childItems))
if ((child->itemType() == FolderType) && (child->name() == name))
return static_cast<TorrentContentModelFolder *>(child);
return nullptr;
@@ -133,7 +133,7 @@ void TorrentContentModelFolder::setPriority(int newPriority, bool updateParent)
// Update children
if (m_priority != prio::MIXED)
for (TorrentContentModelItem *child : qAsConst(m_childItems))
for (TorrentContentModelItem *child : asConst(m_childItems))
child->setPriority(m_priority, false);
}
@@ -142,7 +142,7 @@ void TorrentContentModelFolder::recalculateProgress()
qreal tProgress = 0;
qulonglong tSize = 0;
qulonglong tRemaining = 0;
for (TorrentContentModelItem *child : qAsConst(m_childItems)) {
for (TorrentContentModelItem *child : asConst(m_childItems)) {
if (child->priority() == prio::IGNORED)
continue;
@@ -165,7 +165,7 @@ void TorrentContentModelFolder::recalculateAvailability()
qreal tAvailability = 0;
qulonglong tSize = 0;
bool foundAnyData = false;
for (TorrentContentModelItem *child : qAsConst(m_childItems)) {
for (TorrentContentModelItem *child : asConst(m_childItems)) {
if (child->priority() == prio::IGNORED)
continue;

View File

@@ -220,7 +220,7 @@ TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *tran
TrackerFiltersList::~TrackerFiltersList()
{
for (const QString &iconPath : qAsConst(m_iconPaths))
for (const QString &iconPath : asConst(m_iconPaths))
Utils::Fs::forceRemove(iconPath);
}

View File

@@ -62,7 +62,7 @@ TransferListModel::TransferListModel(QObject *parent)
{
// Load the torrents
using namespace BitTorrent;
for (TorrentHandle *const torrent : copyAsConst(Session::instance()->torrents()))
for (TorrentHandle *const torrent : asConst(Session::instance()->torrents()))
addTorrent(torrent);
// Listen for torrent changes

View File

@@ -382,7 +382,7 @@ void TransferListWidget::torrentDoubleClicked()
QList<BitTorrent::TorrentHandle *> TransferListWidget::getSelectedTorrents() const
{
QList<BitTorrent::TorrentHandle *> torrents;
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows()))
for (const QModelIndex &index : asConst(selectionModel()->selectedRows()))
torrents << m_listModel->torrentHandle(mapToSource(index));
return torrents;
@@ -413,25 +413,25 @@ void TransferListWidget::setSelectedTorrentsLocation()
void TransferListWidget::pauseAllTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
torrent->pause();
}
void TransferListWidget::resumeAllTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(BitTorrent::Session::instance()->torrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(BitTorrent::Session::instance()->torrents()))
torrent->resume();
}
void TransferListWidget::startSelectedTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->resume();
}
void TransferListWidget::forceStartSelectedTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->resume(true);
}
@@ -446,7 +446,7 @@ void TransferListWidget::startVisibleTorrents()
void TransferListWidget::pauseSelectedTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->pause();
}
@@ -496,7 +496,7 @@ void TransferListWidget::deleteVisibleTorrents()
&& !DeletionConfirmationDialog::askForDeletionConfirmation(this, deleteLocalFiles, torrents.size(), torrents[0]->name()))
return;
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrents))
for (BitTorrent::TorrentHandle *const torrent : asConst(torrents))
BitTorrent::Session::instance()->deleteTorrent(torrent->hash(), deleteLocalFiles);
}
@@ -529,7 +529,7 @@ void TransferListWidget::bottomPrioSelectedTorrents()
void TransferListWidget::copySelectedMagnetURIs() const
{
QStringList magnetUris;
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
magnetUris << torrent->toMagnetUri();
qApp->clipboard()->setText(magnetUris.join('\n'));
@@ -538,7 +538,7 @@ void TransferListWidget::copySelectedMagnetURIs() const
void TransferListWidget::copySelectedNames() const
{
QStringList torrentNames;
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrentNames << torrent->name();
qApp->clipboard()->setText(torrentNames.join('\n'));
@@ -547,7 +547,7 @@ void TransferListWidget::copySelectedNames() const
void TransferListWidget::copySelectedHashes() const
{
QStringList torrentHashes;
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrentHashes << torrent->hash();
qApp->clipboard()->setText(torrentHashes.join('\n'));
@@ -567,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.
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
pathsList.insert(path);
}
MacUtils::openFiles(pathsList);
#else
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
QString path = torrent->contentPath(true);
if (!pathsList.contains(path)) {
if (torrent->filesCount() == 1)
@@ -588,7 +588,7 @@ void TransferListWidget::openSelectedTorrentsFolder() const
void TransferListWidget::previewSelectedTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->hasMetadata())
new PreviewSelectDialog(this, torrent);
}
@@ -597,7 +597,7 @@ void TransferListWidget::previewSelectedTorrents()
void TransferListWidget::setDlLimitSelectedTorrents()
{
QList<BitTorrent::TorrentHandle *> torrentsList;
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->isSeed())
continue;
torrentsList += torrent;
@@ -605,7 +605,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->downloadLimit();
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList)) {
if (torrent->downloadLimit() != oldLimit) {
oldLimit = -1;
break;
@@ -618,7 +618,7 @@ void TransferListWidget::setDlLimitSelectedTorrents()
, BitTorrent::Session::instance()->globalDownloadSpeedLimit());
if (!ok) return;
for (BitTorrent::TorrentHandle *const torrent : qAsConst(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);
}
@@ -630,7 +630,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
if (torrentsList.empty()) return;
int oldLimit = torrentsList.first()->uploadLimit();
for (BitTorrent::TorrentHandle *const torrent : qAsConst(torrentsList)) {
for (BitTorrent::TorrentHandle *const torrent : asConst(torrentsList)) {
if (torrent->uploadLimit() != oldLimit) {
oldLimit = -1;
break;
@@ -643,7 +643,7 @@ void TransferListWidget::setUpLimitSelectedTorrents()
, BitTorrent::Session::instance()->globalUploadSpeedLimit());
if (!ok) return;
for (BitTorrent::TorrentHandle *const torrent : qAsConst(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);
}
@@ -687,13 +687,13 @@ void TransferListWidget::recheckSelectedTorrents()
if (ret != QMessageBox::Yes) return;
}
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->forceRecheck();
}
void TransferListWidget::reannounceSelectedTorrents()
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->forceReannounce();
}
@@ -739,7 +739,7 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&)
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents())) {
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents())) {
if (torrent->hasMetadata())
torrent->setSuperSeeding(!torrent->superSeeding());
}
@@ -747,19 +747,19 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->toggleSequentialDownload();
}
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->toggleFirstLastPiecePriority();
}
void TransferListWidget::setSelectedAutoTMMEnabled(bool enabled) const
{
for (BitTorrent::TorrentHandle *const torrent : copyAsConst(getSelectedTorrents()))
for (BitTorrent::TorrentHandle *const torrent : asConst(getSelectedTorrents()))
torrent->setAutoTMMEnabled(enabled);
}
@@ -812,7 +812,7 @@ QStringList TransferListWidget::askTagsForSelection(const QString &dialogTitle)
void TransferListWidget::applyToSelectedTorrents(const std::function<void (BitTorrent::TorrentHandle *const)> &fn)
{
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows())) {
for (const QModelIndex &index : asConst(selectionModel()->selectedRows())) {
BitTorrent::TorrentHandle *const torrent = m_listModel->torrentHandle(mapToSource(index));
Q_ASSERT(torrent);
fn(torrent);
@@ -840,7 +840,7 @@ void TransferListWidget::renameSelectedTorrent()
void TransferListWidget::setSelectionCategory(QString category)
{
for (const QModelIndex &index : copyAsConst(selectionModel()->selectedRows()))
for (const QModelIndex &index : asConst(selectionModel()->selectedRows()))
m_listModel->setData(m_listModel->index(mapToSource(index).row(), TransferListModel::TR_CATEGORY), category, Qt::DisplayRole);
}
@@ -1023,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();
for (QString category : qAsConst(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)) {
@@ -1042,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();
for (const QString &tag : qAsConst(tags)) {
for (const QString &tag : asConst(tags)) {
const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
: tagsInAny.contains(tag) ? Qt::PartiallyChecked
: Qt::Unchecked;