Browse Source

Merge pull request #15911 from Chocobo1/pair

Replace Qt functions with std counterparts
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
dd76525372
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/base/bittorrent/session.cpp
  2. 2
      src/base/bittorrent/torrentimpl.cpp
  3. 7
      src/base/rss/rss_feed.cpp
  4. 4
      src/gui/addnewtorrentdialog.cpp
  5. 3
      src/gui/properties/downloadedpiecesbar.cpp
  6. 7
      src/gui/properties/pieceavailabilitybar.cpp
  7. 3
      src/gui/rss/automatedrssdownloader.cpp
  8. 5
      src/gui/rss/automatedrssdownloader.h
  9. 10
      src/gui/search/searchwidget.cpp
  10. 18
      src/gui/speedlimitdialog.cpp
  11. 14
      src/gui/torrentoptionsdialog.cpp

16
src/base/bittorrent/session.cpp

@ -3171,7 +3171,7 @@ void Session::setPeerTurnoverInterval(const int val) @@ -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) @@ -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) @@ -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) @@ -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)
{

2
src/base/bittorrent/torrentimpl.cpp

@ -1063,7 +1063,7 @@ qlonglong TorrentImpl::eta() const @@ -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;

7
src/base/rss/rss_feed.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "rss_feed.h"
#include <algorithm>
#include <utility>
#include <vector>
#include <QDir>
@ -461,19 +462,19 @@ int Feed::updateArticles(const QList<QVariantHash> &loadedArticles) @@ -461,19 +462,19 @@ int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)
if (newArticles.empty())
return 0;
using ArticleSortAdaptor = QPair<QDateTime, const QVariantHash *>;
using ArticleSortAdaptor = std::pair<QDateTime, const QVariantHash *>;
std::vector<ArticleSortAdaptor> sortData;
const QList<Article *> 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

4
src/gui/addnewtorrentdialog.cpp

@ -28,6 +28,8 @@ @@ -28,6 +28,8 @@
#include "addnewtorrentdialog.h"
#include <algorithm>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
@ -231,7 +233,7 @@ int AddNewTorrentDialog::savePathHistoryLength() @@ -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)

3
src/gui/properties/downloadedpiecesbar.cpp

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include "downloadedpiecesbar.h"
#include <algorithm>
#include <cmath>
#include <QDebug>
@ -117,7 +118,7 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin @@ -117,7 +118,7 @@ QVector<float> 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;
}

7
src/gui/properties/pieceavailabilitybar.cpp

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include "pieceavailabilitybar.h"
#include <algorithm>
#include <cmath>
#include <QDebug>
@ -46,9 +47,9 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin, @@ -46,9 +47,9 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &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<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin, @@ -115,7 +116,7 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &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;
}

3
src/gui/rss/automatedrssdownloader.cpp

@ -33,7 +33,6 @@ @@ -33,7 +33,6 @@
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
#include <QPair>
#include <QRegularExpression>
#include <QShortcut>
#include <QSignalBlocker>
@ -664,7 +663,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(RSS::Feed *feed, const QStrin @@ -664,7 +663,7 @@ void AutomatedRssDownloader::addFeedArticlesToTree(RSS::Feed *feed, const QStrin
// Insert the articles
for (const QString &article : articles)
{
QPair<QString, QString> key(feed->name(), article);
const std::pair<QString, QString> key(feed->name(), article);
if (!m_treeListEntries.contains(key))
{

5
src/gui/rss/automatedrssdownloader.h

@ -29,9 +29,10 @@ @@ -29,9 +29,10 @@
#pragma once
#include <utility>
#include <QDialog>
#include <QHash>
#include <QPair>
#include <QSet>
#include "base/rss/rss_autodownloadrule.h"
@ -101,7 +102,7 @@ private: @@ -101,7 +102,7 @@ private:
Ui::AutomatedRssDownloader *m_ui;
QListWidgetItem *m_currentRuleItem;
QSet<QPair<QString, QString>> m_treeListEntries;
QSet<std::pair<QString, QString>> m_treeListEntries;
RSS::AutoDownloadRule m_currentRule;
QHash<QString, QListWidgetItem *> m_itemsByRuleName;
QRegularExpression *m_episodeRegex;

10
src/gui/search/searchwidget.cpp

@ -32,6 +32,8 @@ @@ -32,6 +32,8 @@
#include <QtGlobal>
#include <utility>
#ifdef Q_OS_WIN
#include <cstdlib>
#endif
@ -182,10 +184,10 @@ void SearchWidget::fillCatCombobox() @@ -182,10 +184,10 @@ void SearchWidget::fillCatCombobox()
m_ui->comboCategory->clear();
m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), "all");
using QStrPair = QPair<QString, QString>;
using QStrPair = std::pair<QString, QString>;
QVector<QStrPair> 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() @@ -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<QString, QString>;
using QStrPair = std::pair<QString, QString>;
QVector<QStrPair> 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))

18
src/gui/speedlimitdialog.cpp

@ -28,6 +28,8 @@ @@ -28,6 +28,8 @@
#include "speedlimitdialog.h"
#include <algorithm>
#include <QStyle>
#include "base/bittorrent/session.h"
@ -65,17 +67,17 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) @@ -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);

14
src/gui/torrentoptionsdialog.cpp

@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
#include "torrentoptionsdialog.h"
#include <algorithm>
#include <QLineEdit>
#include <QMessageBox>
#include <QString>
@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor @@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const QString firstTorrentSavePath = torrents[0]->savePath();
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 QVector<BitTor @@ -112,12 +114,12 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
}
if (allSameUpLimit)
{
if (qMax(0, torrent->uploadLimit()) != 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 QVector<BitTor @@ -201,8 +203,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
? (session->altGlobalDownloadSpeedLimit() / 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;

Loading…
Cancel
Save