mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
Combine qAsConst() with copyAsConst() to asConst()
This commit is contained in:
committed by
sledgehammer999
parent
e2ee928017
commit
bd4d2fa424
@@ -199,7 +199,7 @@ namespace
|
||||
|
||||
for (auto i = categories.cbegin(); i != categories.cend(); ++i) {
|
||||
const QString &category = i.key();
|
||||
for (const QString &subcat : copyAsConst(Session::expandCategory(category))) {
|
||||
for (const QString &subcat : asConst(Session::expandCategory(category))) {
|
||||
if (!expanded.contains(subcat))
|
||||
expanded[subcat] = "";
|
||||
}
|
||||
@@ -610,7 +610,7 @@ void Session::setTempPathEnabled(bool enabled)
|
||||
{
|
||||
if (enabled != isTempPathEnabled()) {
|
||||
m_isTempPathEnabled = enabled;
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents))
|
||||
torrent->handleTempPathChanged();
|
||||
}
|
||||
}
|
||||
@@ -624,7 +624,7 @@ void Session::setAppendExtensionEnabled(bool enabled)
|
||||
{
|
||||
if (isAppendExtensionEnabled() != enabled) {
|
||||
// append or remove .!qB extension for incomplete files
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents))
|
||||
torrent->handleAppendExtensionToggled();
|
||||
|
||||
m_isAppendExtensionEnabled = enabled;
|
||||
@@ -752,7 +752,7 @@ bool Session::addCategory(const QString &name, const QString &savePath)
|
||||
return false;
|
||||
|
||||
if (isSubcategoriesEnabled()) {
|
||||
for (const QString &parent : copyAsConst(expandCategory(name))) {
|
||||
for (const QString &parent : asConst(expandCategory(name))) {
|
||||
if ((parent != name) && !m_categories.contains(parent)) {
|
||||
m_categories[parent] = "";
|
||||
emit categoryAdded(parent);
|
||||
@@ -775,12 +775,12 @@ bool Session::editCategory(const QString &name, const QString &savePath)
|
||||
m_categories[name] = savePath;
|
||||
m_storedCategories = map_cast(m_categories);
|
||||
if (isDisableAutoTMMWhenCategorySavePathChanged()) {
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
if (torrent->category() == name)
|
||||
torrent->setAutoTMMEnabled(false);
|
||||
}
|
||||
else {
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
if (torrent->category() == name)
|
||||
torrent->handleCategorySavePathChanged();
|
||||
}
|
||||
@@ -790,7 +790,7 @@ bool Session::editCategory(const QString &name, const QString &savePath)
|
||||
|
||||
bool Session::removeCategory(const QString &name)
|
||||
{
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
if (torrent->belongsToCategory(name))
|
||||
torrent->setCategory("");
|
||||
|
||||
@@ -877,7 +877,7 @@ bool Session::addTag(const QString &tag)
|
||||
bool Session::removeTag(const QString &tag)
|
||||
{
|
||||
if (m_tags.remove(tag)) {
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
torrent->removeTag(tag);
|
||||
m_storedTags = m_tags.toList();
|
||||
emit tagRemoved(tag);
|
||||
@@ -1085,7 +1085,7 @@ void Session::configure()
|
||||
void Session::processBannedIPs(libt::ip_filter &filter)
|
||||
{
|
||||
// First, import current filter
|
||||
for (const QString &ip : copyAsConst(m_bannedIPs.value())) {
|
||||
for (const QString &ip : asConst(m_bannedIPs.value())) {
|
||||
boost::system::error_code ec;
|
||||
libt::address addr = libt::address::from_string(ip.toLatin1().constData(), ec);
|
||||
Q_ASSERT(!ec);
|
||||
@@ -1770,7 +1770,7 @@ void Session::enableBandwidthScheduler()
|
||||
void Session::populateAdditionalTrackers()
|
||||
{
|
||||
m_additionalTrackerList.clear();
|
||||
for (QString tracker : copyAsConst(additionalTrackers().split('\n'))) {
|
||||
for (QString tracker : asConst(additionalTrackers().split('\n'))) {
|
||||
tracker = tracker.trimmed();
|
||||
if (!tracker.isEmpty())
|
||||
m_additionalTrackerList << tracker;
|
||||
@@ -1781,7 +1781,7 @@ void Session::processShareLimits()
|
||||
{
|
||||
qDebug("Processing share limits...");
|
||||
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents())) {
|
||||
for (TorrentHandle *const torrent : asConst(torrents())) {
|
||||
if (torrent->isSeed() && !torrent->isForced()) {
|
||||
if (torrent->ratioLimit() != TorrentHandle::NO_RATIO_LIMIT) {
|
||||
const qreal ratio = torrent->realRatio();
|
||||
@@ -1934,7 +1934,7 @@ bool Session::deleteTorrent(const QString &hash, bool deleteLocalFiles)
|
||||
m_nativeSession->remove_torrent(torrent->nativeHandle(), libt::session::delete_partfile);
|
||||
#endif
|
||||
// Remove unwanted and incomplete files
|
||||
for (const QString &unwantedFile : qAsConst(unwantedFiles)) {
|
||||
for (const QString &unwantedFile : asConst(unwantedFiles)) {
|
||||
qDebug("Removing unwanted file: %s", qUtf8Printable(unwantedFile));
|
||||
Utils::Fs::forceRemove(unwantedFile);
|
||||
const QString parentFolder = Utils::Fs::branchPath(unwantedFile);
|
||||
@@ -2367,7 +2367,7 @@ void Session::exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolde
|
||||
|
||||
void Session::generateResumeData(bool final)
|
||||
{
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents)) {
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents)) {
|
||||
if (!torrent->isValid()) continue;
|
||||
if (torrent->isChecking() || torrent->isPaused()) continue;
|
||||
if (!final && !torrent->needSaveResumeData()) continue;
|
||||
@@ -2414,7 +2414,7 @@ void Session::saveResumeData()
|
||||
void Session::saveTorrentsQueue()
|
||||
{
|
||||
QMap<int, QString> queue; // Use QMap since it should be ordered by key
|
||||
for (const TorrentHandle *torrent : copyAsConst(torrents())) {
|
||||
for (const TorrentHandle *torrent : asConst(torrents())) {
|
||||
// We require actual (non-cached) queue position here!
|
||||
const int queuePos = torrent->nativeHandle().queue_position();
|
||||
if (queuePos >= 0)
|
||||
@@ -2422,7 +2422,7 @@ void Session::saveTorrentsQueue()
|
||||
}
|
||||
|
||||
QByteArray data;
|
||||
for (const QString &hash : qAsConst(queue))
|
||||
for (const QString &hash : asConst(queue))
|
||||
data += (hash.toLatin1() + '\n');
|
||||
|
||||
const QString filename = QLatin1String {"queue"};
|
||||
@@ -2444,10 +2444,10 @@ void Session::setDefaultSavePath(QString path)
|
||||
m_defaultSavePath = path;
|
||||
|
||||
if (isDisableAutoTMMWhenDefaultSavePathChanged())
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
torrent->setAutoTMMEnabled(false);
|
||||
else
|
||||
for (TorrentHandle *const torrent : copyAsConst(torrents()))
|
||||
for (TorrentHandle *const torrent : asConst(torrents()))
|
||||
torrent->handleCategorySavePathChanged();
|
||||
}
|
||||
|
||||
@@ -2458,7 +2458,7 @@ void Session::setTempPath(QString path)
|
||||
|
||||
m_tempPath = path;
|
||||
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents))
|
||||
torrent->handleTempPathChanged();
|
||||
}
|
||||
|
||||
@@ -3776,7 +3776,7 @@ void Session::handleTorrentTrackerWarning(TorrentHandle *const torrent, const QS
|
||||
|
||||
bool Session::hasPerTorrentRatioLimit() const
|
||||
{
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents))
|
||||
if (torrent->ratioLimit() >= 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -3784,7 +3784,7 @@ bool Session::hasPerTorrentRatioLimit() const
|
||||
|
||||
bool Session::hasPerTorrentSeedingTimeLimit() const
|
||||
{
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents))
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents))
|
||||
if (torrent->seedingTimeLimit() >= 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -3928,7 +3928,7 @@ void Session::startUpTorrents()
|
||||
QMap<int, TorrentResumeData> queuedResumeData;
|
||||
int nextQueuePosition = 1;
|
||||
int numOfRemappedFiles = 0;
|
||||
for (const QString &fastresumeName : qAsConst(fastresumes)) {
|
||||
for (const QString &fastresumeName : asConst(fastresumes)) {
|
||||
const QRegularExpressionMatch rxMatch = rx.match(fastresumeName);
|
||||
if (!rxMatch.hasMatch()) continue;
|
||||
|
||||
@@ -3967,7 +3967,7 @@ void Session::startUpTorrents()
|
||||
}
|
||||
|
||||
// starting up downloading torrents (queue position > 0)
|
||||
for (const TorrentResumeData &torrentResumeData : qAsConst(queuedResumeData))
|
||||
for (const TorrentResumeData &torrentResumeData : asConst(queuedResumeData))
|
||||
startupTorrent(torrentResumeData);
|
||||
|
||||
return;
|
||||
@@ -3989,7 +3989,7 @@ void Session::startUpTorrents()
|
||||
fastresumes = queue + fastresumes.toSet().subtract(queue.toSet()).toList();
|
||||
}
|
||||
|
||||
for (const QString &fastresumeName : qAsConst(fastresumes)) {
|
||||
for (const QString &fastresumeName : asConst(fastresumes)) {
|
||||
const QRegularExpressionMatch rxMatch = rx.match(fastresumeName);
|
||||
if (!rxMatch.hasMatch()) continue;
|
||||
|
||||
@@ -4554,7 +4554,7 @@ void Session::handleStateUpdateAlert(libt::state_update_alert *p)
|
||||
}
|
||||
|
||||
m_torrentStatusReport = TorrentStatusReport();
|
||||
for (TorrentHandle *const torrent : qAsConst(m_torrents)) {
|
||||
for (TorrentHandle *const torrent : asConst(m_torrents)) {
|
||||
if (torrent->isDownloading())
|
||||
++m_torrentStatusReport.nbDownloading;
|
||||
if (torrent->isUploading())
|
||||
|
||||
@@ -110,7 +110,7 @@ void TorrentCreatorThread::run()
|
||||
QStringList fileNames;
|
||||
QHash<QString, boost::int64_t> fileSizeMap;
|
||||
|
||||
for (const auto &dir : qAsConst(dirs)) {
|
||||
for (const auto &dir : asConst(dirs)) {
|
||||
QStringList tmpNames; // natural sort files within each dir
|
||||
|
||||
QDirIterator fileIter(dir, QDir::Files);
|
||||
@@ -126,7 +126,7 @@ void TorrentCreatorThread::run()
|
||||
fileNames += tmpNames;
|
||||
}
|
||||
|
||||
for (const auto &fileName : qAsConst(fileNames))
|
||||
for (const auto &fileName : asConst(fileNames))
|
||||
fs.add_file(fileName.toStdString(), fileSizeMap[fileName]);
|
||||
}
|
||||
|
||||
@@ -141,14 +141,14 @@ void TorrentCreatorThread::run()
|
||||
#endif
|
||||
|
||||
// Add url seeds
|
||||
for (QString seed : qAsConst(m_params.urlSeeds)) {
|
||||
for (QString seed : asConst(m_params.urlSeeds)) {
|
||||
seed = seed.trimmed();
|
||||
if (!seed.isEmpty())
|
||||
newTorrent.add_url_seed(seed.toStdString());
|
||||
}
|
||||
|
||||
int tier = 0;
|
||||
for (const QString &tracker : qAsConst(m_params.trackers)) {
|
||||
for (const QString &tracker : asConst(m_params.trackers)) {
|
||||
if (tracker.isEmpty())
|
||||
++tier;
|
||||
else
|
||||
|
||||
@@ -596,7 +596,7 @@ bool TorrentHandle::removeTag(const QString &tag)
|
||||
|
||||
void TorrentHandle::removeAllTags()
|
||||
{
|
||||
for (const QString &tag : copyAsConst(tags()))
|
||||
for (const QString &tag : asConst(tags()))
|
||||
removeTag(tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ void Tracker::respondToAnnounceRequest()
|
||||
QMap<QString, QByteArray> queryParams;
|
||||
// Parse GET parameters
|
||||
using namespace Utils::ByteArray;
|
||||
for (const QByteArray ¶m : copyAsConst(splitToViews(m_request.query, "&"))) {
|
||||
for (const QByteArray ¶m : asConst(splitToViews(m_request.query, "&"))) {
|
||||
const int sepPos = param.indexOf('=');
|
||||
if (sepPos <= 0) continue; // ignores params without name
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ FileSystemWatcher::FileSystemWatcher(QObject *parent)
|
||||
QStringList FileSystemWatcher::directories() const
|
||||
{
|
||||
QStringList dirs = QFileSystemWatcher::directories();
|
||||
for (const QDir &dir : qAsConst(m_watchedFolders))
|
||||
for (const QDir &dir : asConst(m_watchedFolders))
|
||||
dirs << dir.canonicalPath();
|
||||
return dirs;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ void FileSystemWatcher::scanLocalFolder(const QString &path)
|
||||
|
||||
void FileSystemWatcher::scanNetworkFolders()
|
||||
{
|
||||
for (const QDir &dir : qAsConst(m_watchedFolders))
|
||||
for (const QDir &dir : asConst(m_watchedFolders))
|
||||
processTorrentsInDir(dir);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,13 @@
|
||||
|
||||
const char C_TORRENT_FILE_EXTENSION[] = ".torrent";
|
||||
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
|
||||
template <typename T>
|
||||
constexpr typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
|
||||
constexpr typename std::add_const<T>::type &asConst(T &t) noexcept { return t; }
|
||||
|
||||
// prevent rvalue arguments:
|
||||
// Forward rvalue as const
|
||||
template <typename T>
|
||||
void qAsConst(const T &&) = delete;
|
||||
#endif
|
||||
constexpr typename std::add_const<T>::type asConst(T &&t) noexcept { return std::move(t); }
|
||||
|
||||
// returns a const object copy
|
||||
// Prevent const rvalue arguments
|
||||
template <typename T>
|
||||
constexpr typename std::add_const<T>::type copyAsConst(T &&t) noexcept { return std::move(t); }
|
||||
void asConst(const T &&) = delete;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies();
|
||||
for (const QNetworkCookie &cookie : copyAsConst(Preferences::instance()->getNetworkCookies())) {
|
||||
for (const QNetworkCookie &cookie : asConst(Preferences::instance()->getNetworkCookies())) {
|
||||
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = allCookies();
|
||||
for (const QNetworkCookie &cookie : copyAsConst(allCookies())) {
|
||||
for (const QNetworkCookie &cookie : asConst(allCookies())) {
|
||||
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url);
|
||||
for (const QNetworkCookie &cookie : copyAsConst(QNetworkCookieJar::cookiesForUrl(url))) {
|
||||
for (const QNetworkCookie &cookie : asConst(QNetworkCookieJar::cookiesForUrl(url))) {
|
||||
if (!cookie.isSessionCookie() && (cookie.expirationDate() <= now))
|
||||
cookies.removeAll(cookie);
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ QByteArray Smtp::encodeMimeHeader(const QString &key, const QString &value, QTex
|
||||
if (!prefix.isEmpty()) line += prefix;
|
||||
if (!value.contains("=?") && latin1->canEncode(value)) {
|
||||
bool firstWord = true;
|
||||
for (const QByteArray &word : copyAsConst(value.toLatin1().split(' '))) {
|
||||
for (const QByteArray &word : asConst(value.toLatin1().split(' '))) {
|
||||
if (line.size() > 78) {
|
||||
rv = rv + line + "\r\n";
|
||||
line.clear();
|
||||
|
||||
@@ -506,7 +506,7 @@ void Preferences::setWebUiAuthSubnetWhitelistEnabled(bool enabled)
|
||||
QList<Utils::Net::Subnet> Preferences::getWebUiAuthSubnetWhitelist() const
|
||||
{
|
||||
QList<Utils::Net::Subnet> subnets;
|
||||
for (const QString &rawSubnet : copyAsConst(value("Preferences/WebUI/AuthSubnetWhitelist").toStringList())) {
|
||||
for (const QString &rawSubnet : asConst(value("Preferences/WebUI/AuthSubnetWhitelist").toStringList())) {
|
||||
bool ok = false;
|
||||
const Utils::Net::Subnet subnet = Utils::Net::parseSubnet(rawSubnet.trimmed(), &ok);
|
||||
if (ok)
|
||||
|
||||
@@ -241,7 +241,7 @@ void AutoDownloader::importRules(const QByteArray &data, AutoDownloader::RulesFi
|
||||
QByteArray AutoDownloader::exportRulesToJSONFormat() const
|
||||
{
|
||||
QJsonObject jsonObj;
|
||||
for (const auto &rule : copyAsConst(rules()))
|
||||
for (const auto &rule : asConst(rules()))
|
||||
jsonObj.insert(rule.name(), rule.toJsonObject());
|
||||
|
||||
return QJsonDocument(jsonObj).toJson();
|
||||
@@ -249,14 +249,14 @@ QByteArray AutoDownloader::exportRulesToJSONFormat() const
|
||||
|
||||
void AutoDownloader::importRulesFromJSONFormat(const QByteArray &data)
|
||||
{
|
||||
for (const auto &rule : copyAsConst(rulesFromJSON(data)))
|
||||
for (const auto &rule : asConst(rulesFromJSON(data)))
|
||||
insertRule(rule);
|
||||
}
|
||||
|
||||
QByteArray AutoDownloader::exportRulesToLegacyFormat() const
|
||||
{
|
||||
QVariantHash dict;
|
||||
for (const auto &rule : copyAsConst(rules()))
|
||||
for (const auto &rule : asConst(rules()))
|
||||
dict[rule.name()] = rule.toLegacyDict();
|
||||
|
||||
QByteArray data;
|
||||
@@ -276,7 +276,7 @@ void AutoDownloader::importRulesFromLegacyFormat(const QByteArray &data)
|
||||
if (in.status() != QDataStream::Ok)
|
||||
throw ParsingError(tr("Invalid data format"));
|
||||
|
||||
for (const QVariant &val : qAsConst(dict))
|
||||
for (const QVariant &val : asConst(dict))
|
||||
insertRule(AutoDownloadRule::fromLegacyDict(val.toHash()));
|
||||
}
|
||||
|
||||
@@ -451,7 +451,7 @@ void AutoDownloader::store()
|
||||
m_savingTimer.stop();
|
||||
|
||||
QJsonObject jsonObj;
|
||||
for (const auto &rule : qAsConst(m_rules))
|
||||
for (const auto &rule : asConst(m_rules))
|
||||
jsonObj.insert(rule.name(), rule.toJsonObject());
|
||||
|
||||
m_fileStorage->store(RulesFileName, QJsonDocument(jsonObj).toJson());
|
||||
@@ -473,7 +473,7 @@ void AutoDownloader::resetProcessingQueue()
|
||||
m_processingQueue.clear();
|
||||
if (!m_processingEnabled) return;
|
||||
|
||||
for (Article *article : copyAsConst(Session::instance()->rootFolder()->articles())) {
|
||||
for (Article *article : asConst(Session::instance()->rootFolder()->articles())) {
|
||||
if (!article->isRead() && !article->torrentUrl().isEmpty())
|
||||
addJobForArticle(article);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ bool AutoDownloadRule::matchesMustContainExpression(const QString &articleTitle)
|
||||
|
||||
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
||||
// Accept if any complete expression matches.
|
||||
for (const QString &expression : qAsConst(m_dataPtr->mustContain)) {
|
||||
for (const QString &expression : asConst(m_dataPtr->mustContain)) {
|
||||
// A regex of the form "expr|" will always match, so do the same for wildcards
|
||||
if (matchesExpression(articleTitle, expression))
|
||||
return true;
|
||||
@@ -253,7 +253,7 @@ bool AutoDownloadRule::matchesMustNotContainExpression(const QString &articleTit
|
||||
|
||||
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
||||
// Reject if any complete expression matches.
|
||||
for (const QString &expression : qAsConst(m_dataPtr->mustNotContain)) {
|
||||
for (const QString &expression : asConst(m_dataPtr->mustNotContain)) {
|
||||
// A regex of the form "expr|" will always match, so do the same for wildcards
|
||||
if (matchesExpression(articleTitle, expression))
|
||||
return false;
|
||||
@@ -442,7 +442,7 @@ AutoDownloadRule AutoDownloadRule::fromJsonObject(const QJsonObject &jsonObj, co
|
||||
QStringList feedURLs;
|
||||
if (feedsVal.isString())
|
||||
feedURLs << feedsVal.toString();
|
||||
else for (const QJsonValue &urlVal : copyAsConst(feedsVal.toArray()))
|
||||
else for (const QJsonValue &urlVal : asConst(feedsVal.toArray()))
|
||||
feedURLs << urlVal.toString();
|
||||
rule.setFeedURLs(feedURLs);
|
||||
|
||||
@@ -452,7 +452,7 @@ AutoDownloadRule AutoDownloadRule::fromJsonObject(const QJsonObject &jsonObj, co
|
||||
previouslyMatched << previouslyMatchedVal.toString();
|
||||
}
|
||||
else {
|
||||
for (const QJsonValue &val : copyAsConst(previouslyMatchedVal.toArray()))
|
||||
for (const QJsonValue &val : asConst(previouslyMatchedVal.toArray()))
|
||||
previouslyMatched << val.toString();
|
||||
}
|
||||
rule.setPreviouslyMatchedEpisodes(previouslyMatched);
|
||||
|
||||
@@ -109,7 +109,7 @@ QList<Article *> Feed::articles() const
|
||||
void Feed::markAsRead()
|
||||
{
|
||||
auto oldUnreadCount = m_unreadCount;
|
||||
for (Article *article : qAsConst(m_articles)) {
|
||||
for (Article *article : asConst(m_articles)) {
|
||||
if (!article->isRead()) {
|
||||
article->disconnect(this);
|
||||
article->markAsRead();
|
||||
@@ -306,7 +306,7 @@ void Feed::loadArticlesLegacy()
|
||||
SettingsPtr qBTRSSFeeds = Profile::instance().applicationSettings(QStringLiteral("qBittorrent-rss-feeds"));
|
||||
const QVariantHash allOldItems = qBTRSSFeeds->value("old_items").toHash();
|
||||
|
||||
for (const QVariant &var : copyAsConst(allOldItems.value(m_url).toList())) {
|
||||
for (const QVariant &var : asConst(allOldItems.value(m_url).toList())) {
|
||||
auto hash = var.toHash();
|
||||
// update legacy keys
|
||||
hash[Article::KeyLink] = hash.take(QLatin1String("news_link"));
|
||||
@@ -329,7 +329,7 @@ void Feed::store()
|
||||
m_savingTimer.stop();
|
||||
|
||||
QJsonArray jsonArr;
|
||||
for (Article *article :qAsConst(m_articles))
|
||||
for (Article *article :asConst(m_articles))
|
||||
jsonArr << article->toJsonObject();
|
||||
|
||||
m_session->dataFileStorage()->store(m_dataFileName, QJsonDocument(jsonArr).toJson());
|
||||
@@ -507,7 +507,7 @@ QJsonValue Feed::toJsonValue(bool withData) const
|
||||
jsonObj.insert(KEY_HASERROR, hasError());
|
||||
|
||||
QJsonArray jsonArr;
|
||||
for (Article *article : qAsConst(m_articles))
|
||||
for (Article *article : asConst(m_articles))
|
||||
jsonArr << article->toJsonObject();
|
||||
jsonObj.insert(KEY_ARTICLES, jsonArr);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ Folder::~Folder()
|
||||
{
|
||||
emit aboutToBeDestroyed(this);
|
||||
|
||||
for (auto item : copyAsConst(items()))
|
||||
for (auto item : asConst(items()))
|
||||
delete item;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ QList<Article *> Folder::articles() const
|
||||
{
|
||||
QList<Article *> news;
|
||||
|
||||
for (Item *item : copyAsConst(items())) {
|
||||
for (Item *item : asConst(items())) {
|
||||
int n = news.size();
|
||||
news << item->articles();
|
||||
std::inplace_merge(news.begin(), news.begin() + n, news.end()
|
||||
@@ -70,20 +70,20 @@ QList<Article *> Folder::articles() const
|
||||
int Folder::unreadCount() const
|
||||
{
|
||||
int count = 0;
|
||||
for (Item *item : copyAsConst(items()))
|
||||
for (Item *item : asConst(items()))
|
||||
count += item->unreadCount();
|
||||
return count;
|
||||
}
|
||||
|
||||
void Folder::markAsRead()
|
||||
{
|
||||
for (Item *item : copyAsConst(items()))
|
||||
for (Item *item : asConst(items()))
|
||||
item->markAsRead();
|
||||
}
|
||||
|
||||
void Folder::refresh()
|
||||
{
|
||||
for (Item *item : copyAsConst(items()))
|
||||
for (Item *item : asConst(items()))
|
||||
item->refresh();
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ QList<Item *> Folder::items() const
|
||||
QJsonValue Folder::toJsonValue(bool withData) const
|
||||
{
|
||||
QJsonObject jsonObj;
|
||||
for (Item *item : copyAsConst(items()))
|
||||
for (Item *item : asConst(items()))
|
||||
jsonObj.insert(item->name(), item->toJsonValue(withData));
|
||||
|
||||
return jsonObj;
|
||||
@@ -108,7 +108,7 @@ void Folder::handleItemUnreadCountChanged()
|
||||
|
||||
void Folder::cleanup()
|
||||
{
|
||||
for (Item *item : copyAsConst(items()))
|
||||
for (Item *item : asConst(items()))
|
||||
item->cleanup();
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ void Folder::addItem(Item *item)
|
||||
connect(item, &Item::articleAboutToBeRemoved, this, &Item::articleAboutToBeRemoved);
|
||||
connect(item, &Item::unreadCountChanged, this, &Folder::handleItemUnreadCountChanged);
|
||||
|
||||
for (auto article : copyAsConst(item->articles()))
|
||||
for (auto article : asConst(item->articles()))
|
||||
emit newArticle(article);
|
||||
|
||||
if (item->unreadCount() > 0)
|
||||
@@ -134,7 +134,7 @@ void Folder::removeItem(Item *item)
|
||||
{
|
||||
Q_ASSERT(m_items.contains(item));
|
||||
|
||||
for (auto article : copyAsConst(item->articles()))
|
||||
for (auto article : asConst(item->articles()))
|
||||
emit articleAboutToBeRemoved(article);
|
||||
|
||||
item->disconnect(this);
|
||||
|
||||
@@ -284,7 +284,7 @@ void Session::load()
|
||||
void Session::loadFolder(const QJsonObject &jsonObj, Folder *folder)
|
||||
{
|
||||
bool updated = false;
|
||||
for (const QString &key : copyAsConst(jsonObj.keys())) {
|
||||
for (const QString &key : asConst(jsonObj.keys())) {
|
||||
const QJsonValue val {jsonObj[key]};
|
||||
if (val.isString()) {
|
||||
// previous format (reduced form) doesn't contain UID
|
||||
@@ -356,7 +356,7 @@ void Session::loadLegacy()
|
||||
const QString parentFolderPath = Item::parentPath(legacyPath);
|
||||
const QString feedUrl = Item::relativeName(legacyPath);
|
||||
|
||||
for (const QString &folderPath : copyAsConst(Item::expandPath(parentFolderPath)))
|
||||
for (const QString &folderPath : asConst(Item::expandPath(parentFolderPath)))
|
||||
addFolder(folderPath);
|
||||
|
||||
const QString feedPath = feedAliases[i].isEmpty()
|
||||
|
||||
@@ -327,7 +327,7 @@ void ScanFoldersModel::makePersistent()
|
||||
{
|
||||
QVariantHash dirs;
|
||||
|
||||
for (const PathData *pathData : qAsConst(m_pathList)) {
|
||||
for (const PathData *pathData : asConst(m_pathList)) {
|
||||
if (pathData->downloadType == CUSTOM_LOCATION)
|
||||
dirs.insert(Utils::Fs::fromNativePath(pathData->watchPath), Utils::Fs::fromNativePath(pathData->downloadPath));
|
||||
else
|
||||
|
||||
@@ -139,7 +139,7 @@ void SearchHandler::readSearchOutput()
|
||||
m_searchResultLineTruncated = lines.takeLast().trimmed();
|
||||
|
||||
QList<SearchResult> searchResultList;
|
||||
for (const QByteArray &line : qAsConst(lines)) {
|
||||
for (const QByteArray &line : asConst(lines)) {
|
||||
SearchResult searchResult;
|
||||
if (parseSearchResult(QString::fromUtf8(line), searchResult))
|
||||
searchResultList << searchResult;
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace
|
||||
while (iter.hasNext())
|
||||
dirs += iter.next();
|
||||
|
||||
for (const QString &dir : qAsConst(dirs)) {
|
||||
for (const QString &dir : asConst(dirs)) {
|
||||
// python 3: remove "__pycache__" folders
|
||||
if (dir.endsWith("/__pycache__")) {
|
||||
Utils::Fs::removeDirRecursive(dir);
|
||||
@@ -120,7 +120,7 @@ QStringList SearchPluginManager::allPlugins() const
|
||||
QStringList SearchPluginManager::enabledPlugins() const
|
||||
{
|
||||
QStringList plugins;
|
||||
for (const PluginInfo *plugin : qAsConst(m_plugins)) {
|
||||
for (const PluginInfo *plugin : asConst(m_plugins)) {
|
||||
if (plugin->enabled)
|
||||
plugins << plugin->name;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ QStringList SearchPluginManager::enabledPlugins() const
|
||||
QStringList SearchPluginManager::supportedCategories() const
|
||||
{
|
||||
QStringList result;
|
||||
for (const PluginInfo *plugin : qAsConst(m_plugins)) {
|
||||
for (const PluginInfo *plugin : asConst(m_plugins)) {
|
||||
if (plugin->enabled) {
|
||||
for (const QString &cat : plugin->supportedCategories) {
|
||||
if (!result.contains(cat))
|
||||
@@ -154,7 +154,7 @@ QStringList SearchPluginManager::getPluginCategories(const QString &pluginName)
|
||||
plugins << pluginName.trimmed();
|
||||
|
||||
QSet<QString> categories;
|
||||
for (const QString &name : qAsConst(plugins)) {
|
||||
for (const QString &name : asConst(plugins)) {
|
||||
const PluginInfo *plugin = pluginInfo(name);
|
||||
if (!plugin) continue; // plugin wasn't found
|
||||
for (const QString &category : plugin->supportedCategories)
|
||||
|
||||
@@ -287,7 +287,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
|
||||
// Copy everything into memory. This means even keys inserted in the file manually
|
||||
// or that we don't touch directly in this code (eg disabled by ifdef). This ensures
|
||||
// that they will be copied over when save our settings to disk.
|
||||
for (const QString &key : copyAsConst(settings->allKeys()))
|
||||
for (const QString &key : asConst(settings->allKeys()))
|
||||
data.insert(key, settings->value(key));
|
||||
|
||||
return settings->fileName();
|
||||
|
||||
@@ -133,7 +133,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
||||
std::sort(dirList.begin(), dirList.end()
|
||||
, [](const QString &l, const QString &r) { return l.count('/') > r.count('/'); });
|
||||
|
||||
for (const QString &p : qAsConst(dirList)) {
|
||||
for (const QString &p : asConst(dirList)) {
|
||||
// remove unwanted files
|
||||
for (const QString &f : deleteFilesList) {
|
||||
forceRemove(p + f);
|
||||
|
||||
Reference in New Issue
Block a user