From 3ea4c66d4146f01d7fbfc5e7517c8a9b036719cc Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 Dec 2021 17:20:26 +0800 Subject: [PATCH 1/2] Replace QPair with std::pair --- src/base/rss/rss_feed.cpp | 7 ++++--- src/gui/rss/automatedrssdownloader.cpp | 3 +-- src/gui/rss/automatedrssdownloader.h | 5 +++-- src/gui/search/searchwidget.cpp | 10 ++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/base/rss/rss_feed.cpp b/src/base/rss/rss_feed.cpp index 0de21e5d7..7563c7b02 100644 --- a/src/base/rss/rss_feed.cpp +++ b/src/base/rss/rss_feed.cpp @@ -31,6 +31,7 @@ #include "rss_feed.h" #include +#include #include #include @@ -461,19 +462,19 @@ int Feed::updateArticles(const QList &loadedArticles) if (newArticles.empty()) return 0; - using ArticleSortAdaptor = QPair; + using ArticleSortAdaptor = std::pair; std::vector sortData; const QList
existingArticles = articles(); sortData.reserve(existingArticles.size() + newArticles.size()); std::transform(existingArticles.begin(), existingArticles.end(), std::back_inserter(sortData) , [](const Article *article) { - return qMakePair(article->date(), nullptr); + return std::make_pair(article->date(), nullptr); }); std::transform(newArticles.begin(), newArticles.end(), std::back_inserter(sortData) , [](const QVariantHash &article) { - return qMakePair(article[Article::KeyDate].toDateTime(), &article); + return std::make_pair(article[Article::KeyDate].toDateTime(), &article); }); // Sort article list in reverse chronological order diff --git a/src/gui/rss/automatedrssdownloader.cpp b/src/gui/rss/automatedrssdownloader.cpp index c8e1f2125..86a12c18c 100644 --- a/src/gui/rss/automatedrssdownloader.cpp +++ b/src/gui/rss/automatedrssdownloader.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -664,7 +663,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(RSS::Feed *feed, const QStrin // Insert the articles for (const QString &article : articles) { - QPair key(feed->name(), article); + const std::pair key(feed->name(), article); if (!m_treeListEntries.contains(key)) { diff --git a/src/gui/rss/automatedrssdownloader.h b/src/gui/rss/automatedrssdownloader.h index 8b40e9c61..3a5eadce0 100644 --- a/src/gui/rss/automatedrssdownloader.h +++ b/src/gui/rss/automatedrssdownloader.h @@ -29,9 +29,10 @@ #pragma once +#include + #include #include -#include #include #include "base/rss/rss_autodownloadrule.h" @@ -101,7 +102,7 @@ private: Ui::AutomatedRssDownloader *m_ui; QListWidgetItem *m_currentRuleItem; - QSet> m_treeListEntries; + QSet> m_treeListEntries; RSS::AutoDownloadRule m_currentRule; QHash m_itemsByRuleName; QRegularExpression *m_episodeRegex; diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 5c0dcc5a1..6e4b84ef9 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -32,6 +32,8 @@ #include +#include + #ifdef Q_OS_WIN #include #endif @@ -182,10 +184,10 @@ void SearchWidget::fillCatCombobox() m_ui->comboCategory->clear(); m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), "all"); - using QStrPair = QPair; + using QStrPair = std::pair; QVector tmpList; for (const QString &cat : asConst(SearchPluginManager::instance()->getPluginCategories(selectedPlugin()))) - tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat); + tmpList << std::make_pair(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 : asConst(tmpList)) @@ -205,10 +207,10 @@ void SearchWidget::fillPluginComboBox() m_ui->selectPlugin->addItem(tr("All plugins"), "all"); m_ui->selectPlugin->addItem(tr("Select..."), "multi"); - using QStrPair = QPair; + using QStrPair = std::pair; QVector tmpList; for (const QString &name : asConst(SearchPluginManager::instance()->enabledPlugins())) - tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name); + tmpList << std::make_pair(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 : asConst(tmpList)) From 63043b49277631ea58eb929566fbb6bfbed18a6c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 Dec 2021 20:31:57 +0800 Subject: [PATCH 2/2] Replace min, max, clamp functions with std counterparts --- src/base/bittorrent/session.cpp | 16 ++++++++-------- src/base/bittorrent/torrentimpl.cpp | 2 +- src/gui/addnewtorrentdialog.cpp | 4 +++- src/gui/properties/downloadedpiecesbar.cpp | 3 ++- src/gui/properties/pieceavailabilitybar.cpp | 7 ++++--- src/gui/speedlimitdialog.cpp | 18 ++++++++++-------- src/gui/torrentoptionsdialog.cpp | 14 ++++++++------ 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 4d5d0638f..097e554b0 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3171,7 +3171,7 @@ void Session::setPeerTurnoverInterval(const int val) int Session::asyncIOThreads() const { - return qBound(1, m_asyncIOThreads.get(), 1024); + return std::clamp(m_asyncIOThreads.get(), 1, 1024); } void Session::setAsyncIOThreads(const int num) @@ -3185,7 +3185,7 @@ void Session::setAsyncIOThreads(const int num) int Session::hashingThreads() const { - return qBound(1, m_hashingThreads.get(), 1024); + return std::clamp(m_hashingThreads.get(), 1, 1024); } void Session::setHashingThreads(const int num) @@ -3213,12 +3213,12 @@ void Session::setFilePoolSize(const int size) int Session::checkingMemUsage() const { - return qMax(1, m_checkingMemUsage.get()); + return std::max(1, m_checkingMemUsage.get()); } void Session::setCheckingMemUsage(int size) { - size = qMax(size, 1); + size = std::max(size, 1); if (size == m_checkingMemUsage) return; @@ -3230,21 +3230,21 @@ void Session::setCheckingMemUsage(int size) int Session::diskCacheSize() const { #ifdef QBT_APP_64BIT - return qMin(m_diskCacheSize.get(), 33554431); // 32768GiB + return std::min(m_diskCacheSize.get(), 33554431); // 32768GiB #else // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - return qMin(m_diskCacheSize.get(), 1536); + return std::min(m_diskCacheSize.get(), 1536); #endif } void Session::setDiskCacheSize(int size) { #ifdef QBT_APP_64BIT - size = qMin(size, 33554431); // 32768GiB + size = std::min(size, 33554431); // 32768GiB #else // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - size = qMin(size, 1536); + size = std::min(size, 1536); #endif if (size != m_diskCacheSize) { diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 83f133591..807b93363 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1063,7 +1063,7 @@ qlonglong TorrentImpl::eta() const seedingTimeEta = 0; } - return qMin(ratioEta, seedingTimeEta); + return std::min(ratioEta, seedingTimeEta); } if (!speedAverage.download) return MAX_ETA; diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index e97fa0180..f9a8a0a0b 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -28,6 +28,8 @@ #include "addnewtorrentdialog.h" +#include + #include #include #include @@ -231,7 +233,7 @@ int AddNewTorrentDialog::savePathHistoryLength() { const int defaultHistoryLength = 8; const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength); - return qBound(minPathHistoryLength, value, maxPathHistoryLength); + return std::clamp(value, minPathHistoryLength, maxPathHistoryLength); } void AddNewTorrentDialog::setSavePathHistoryLength(const int value) diff --git a/src/gui/properties/downloadedpiecesbar.cpp b/src/gui/properties/downloadedpiecesbar.cpp index 12a69cd3b..322432120 100644 --- a/src/gui/properties/downloadedpiecesbar.cpp +++ b/src/gui/properties/downloadedpiecesbar.cpp @@ -28,6 +28,7 @@ #include "downloadedpiecesbar.h" +#include #include #include @@ -117,7 +118,7 @@ QVector DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin value /= ratio; // float precision sometimes gives > 1, because it's not possible to store irrational numbers - value = qMin(value, 1.0f); + value = std::min(value, 1.0f); result[x] = value; } diff --git a/src/gui/properties/pieceavailabilitybar.cpp b/src/gui/properties/pieceavailabilitybar.cpp index 3eba18020..4156dfd1a 100644 --- a/src/gui/properties/pieceavailabilitybar.cpp +++ b/src/gui/properties/pieceavailabilitybar.cpp @@ -28,6 +28,7 @@ #include "pieceavailabilitybar.h" +#include #include #include @@ -46,9 +47,9 @@ QVector PieceAvailabilityBar::intToFloatVector(const QVector &vecin, const int maxElement = *std::max_element(vecin.begin(), vecin.end()); - // qMax because in normalization we don't want divide by 0 + // std::max because in normalization we don't want divide by 0 // if maxElement == 0 check will be disabled please enable this line: - // const int maxElement = qMax(*std::max_element(avail.begin(), avail.end()), 1); + // const int maxElement = std::max(*std::max_element(avail.begin(), avail.end()), 1); if (maxElement == 0) return result; @@ -115,7 +116,7 @@ QVector PieceAvailabilityBar::intToFloatVector(const QVector &vecin, value /= ratio * maxElement; // float precision sometimes gives > 1, because it's not possible to store irrational numbers - value = qMin(value, 1.0f); + value = std::min(value, 1.0f); result[x] = value; } diff --git a/src/gui/speedlimitdialog.cpp b/src/gui/speedlimitdialog.cpp index adae8f56c..93435a66b 100644 --- a/src/gui/speedlimitdialog.cpp +++ b/src/gui/speedlimitdialog.cpp @@ -28,6 +28,8 @@ #include "speedlimitdialog.h" +#include + #include #include "base/bittorrent/session.h" @@ -65,17 +67,17 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) slider->setValue(value); }; const auto *session = BitTorrent::Session::instance(); - const int uploadVal = qMax(0, (session->globalUploadSpeedLimit() / 1024)); - const int downloadVal = qMax(0, (session->globalDownloadSpeedLimit() / 1024)); - const int maxUpload = qMax(10000, (session->globalUploadSpeedLimit() / 1024)); - const int maxDownload = qMax(10000, (session->globalDownloadSpeedLimit() / 1024)); + const int uploadVal = std::max(0, (session->globalUploadSpeedLimit() / 1024)); + const int downloadVal = std::max(0, (session->globalDownloadSpeedLimit() / 1024)); + const int maxUpload = std::max(10000, (session->globalUploadSpeedLimit() / 1024)); + const int maxDownload = std::max(10000, (session->globalDownloadSpeedLimit() / 1024)); initSlider(m_ui->sliderUploadLimit, uploadVal, maxUpload); initSlider(m_ui->sliderDownloadLimit, downloadVal, maxDownload); - const int altUploadVal = qMax(0, (session->altGlobalUploadSpeedLimit() / 1024)); - const int altDownloadVal = qMax(0, (session->altGlobalDownloadSpeedLimit() / 1024)); - const int altMaxUpload = qMax(10000, (session->altGlobalUploadSpeedLimit() / 1024)); - const int altMaxDownload = qMax(10000, (session->altGlobalDownloadSpeedLimit() / 1024)); + const int altUploadVal = std::max(0, (session->altGlobalUploadSpeedLimit() / 1024)); + const int altDownloadVal = std::max(0, (session->altGlobalDownloadSpeedLimit() / 1024)); + const int altMaxUpload = std::max(10000, (session->altGlobalUploadSpeedLimit() / 1024)); + const int altMaxDownload = std::max(10000, (session->altGlobalDownloadSpeedLimit() / 1024)); initSlider(m_ui->sliderAltUploadLimit, altUploadVal, altMaxUpload); initSlider(m_ui->sliderAltDownloadLimit, altDownloadVal, altMaxDownload); diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index b348e1a00..823ad1939 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -30,6 +30,8 @@ #include "torrentoptionsdialog.h" +#include + #include #include #include @@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectorsavePath(); const QString firstTorrentCategory = torrents[0]->category(); - const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit()); - const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit()); + const int firstTorrentUpLimit = std::max(0, torrents[0]->uploadLimit()); + const int firstTorrentDownLimit = std::max(0, torrents[0]->downloadLimit()); const qreal firstTorrentRatio = torrents[0]->ratioLimit(); const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit(); @@ -112,12 +114,12 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectoruploadLimit()) != firstTorrentUpLimit) + if (std::max(0, torrent->uploadLimit()) != firstTorrentUpLimit) allSameUpLimit = false; } if (allSameDownLimit) { - if (qMax(0, torrent->downloadLimit()) != firstTorrentDownLimit) + if (std::max(0, torrent->downloadLimit()) != firstTorrentDownLimit) allSameDownLimit = false; } if (allSameRatio) @@ -201,8 +203,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectoraltGlobalDownloadSpeedLimit() / 1024) : (session->globalDownloadSpeedLimit() / 1024); - const int uploadVal = qMax(0, (firstTorrentUpLimit / 1024)); - const int downloadVal = qMax(0, (firstTorrentDownLimit / 1024)); + const int uploadVal = std::max(0, (firstTorrentUpLimit / 1024)); + const int downloadVal = std::max(0, (firstTorrentDownLimit / 1024)); int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit; int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit;