mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
Merge pull request #14717 from Chocobo1/ncmp
Simplify natural sort classes interface
This commit is contained in:
@@ -48,9 +48,9 @@
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/torrentfileguard.h"
|
||||
#include "base/utils/compare.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "autoexpandabledialog.h"
|
||||
#include "properties/proplistdelegate.h"
|
||||
#include "raisedmessagebox.h"
|
||||
@@ -129,7 +129,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
|
||||
|
||||
// Load categories
|
||||
QStringList categories = session->categories().keys();
|
||||
std::sort(categories.begin(), categories.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
auto defaultCategory = settings()->loadValue<QString>(KEY_DEFAULTCATEGORY);
|
||||
|
||||
if (!m_torrentParams.category.isEmpty())
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "categoryfilterproxymodel.h"
|
||||
|
||||
#include "base/utils/string.h"
|
||||
#include "categoryfiltermodel.h"
|
||||
|
||||
CategoryFilterProxyModel::CategoryFilterProxyModel(QObject *parent)
|
||||
@@ -51,9 +50,5 @@ bool CategoryFilterProxyModel::lessThan(const QModelIndex &left, const QModelInd
|
||||
// "All" and "Uncategorized" must be left in place
|
||||
if (CategoryFilterModel::isSpecialItem(left) || CategoryFilterModel::isSpecialItem(right))
|
||||
return (left < right);
|
||||
|
||||
int result = Utils::String::naturalCompare(left.data().toString(), right.data().toString()
|
||||
, Qt::CaseInsensitive);
|
||||
|
||||
return (result < 0);
|
||||
return m_naturalLessThan(left.data().toString(), right.data().toString());
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "base/utils/compare.h"
|
||||
|
||||
class QString;
|
||||
|
||||
class CategoryFilterProxyModel final : public QSortFilterProxyModel
|
||||
@@ -47,4 +49,6 @@ protected:
|
||||
private:
|
||||
// we added another overload of index(), hence this using directive:
|
||||
using QSortFilterProxyModel::index;
|
||||
|
||||
Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> m_naturalLessThan;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "peerlistsortmodel.h"
|
||||
|
||||
#include "base/utils/string.h"
|
||||
#include "peerlistwidget.h"
|
||||
|
||||
PeerListSortModel::PeerListSortModel(QObject *parent)
|
||||
@@ -43,11 +42,10 @@ bool PeerListSortModel::lessThan(const QModelIndex &left, const QModelIndex &rig
|
||||
{
|
||||
case PeerListWidget::IP:
|
||||
case PeerListWidget::CLIENT:
|
||||
{
|
||||
{
|
||||
const QString strL = left.data(UnderlyingDataRole).toString();
|
||||
const QString strR = right.data(UnderlyingDataRole).toString();
|
||||
const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive);
|
||||
return (result < 0);
|
||||
return m_naturalLessThan(strL, strR);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "base/utils/compare.h"
|
||||
|
||||
class PeerListSortModel final : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -45,4 +47,6 @@ public:
|
||||
|
||||
private:
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
|
||||
|
||||
Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> m_naturalLessThan;
|
||||
};
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "base/rss/rss_feed.h"
|
||||
#include "base/rss/rss_folder.h"
|
||||
#include "base/rss/rss_session.h"
|
||||
#include "base/utils/compare.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "gui/autoexpandabledialog.h"
|
||||
@@ -330,7 +331,7 @@ void AutomatedRssDownloader::initCategoryCombobox()
|
||||
{
|
||||
// Load torrent categories
|
||||
QStringList categories = BitTorrent::Session::instance()->categories().keys();
|
||||
std::sort(categories.begin(), categories.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
m_ui->comboCategory->addItem("");
|
||||
m_ui->comboCategory->addItems(categories);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "searchsortmodel.h"
|
||||
|
||||
#include "base/global.h"
|
||||
#include "base/utils/string.h"
|
||||
|
||||
SearchSortModel::SearchSortModel(QObject *parent)
|
||||
: base(parent)
|
||||
@@ -118,11 +117,10 @@ bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right
|
||||
{
|
||||
case NAME:
|
||||
case ENGINE_URL:
|
||||
{
|
||||
{
|
||||
const QString strL = left.data().toString();
|
||||
const QString strR = right.data().toString();
|
||||
const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive);
|
||||
return (result < 0);
|
||||
return m_naturalLessThan(strL, strR);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStringList>
|
||||
|
||||
#include "base/utils/compare.h"
|
||||
|
||||
class SearchSortModel final : public QSortFilterProxyModel
|
||||
{
|
||||
using base = QSortFilterProxyModel;
|
||||
@@ -94,4 +96,6 @@ private:
|
||||
int m_minSeeds, m_maxSeeds;
|
||||
int m_minLeeches, m_maxLeeches;
|
||||
qint64 m_minSize, m_maxSize;
|
||||
|
||||
Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> m_naturalLessThan;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "tagfilterproxymodel.h"
|
||||
|
||||
#include "base/utils/string.h"
|
||||
#include "tagfiltermodel.h"
|
||||
|
||||
TagFilterProxyModel::TagFilterProxyModel(QObject *parent)
|
||||
@@ -51,8 +50,5 @@ bool TagFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &r
|
||||
// "All" and "Untagged" must be left in place
|
||||
if (TagFilterModel::isSpecialItem(left) || TagFilterModel::isSpecialItem(right))
|
||||
return (left < right);
|
||||
|
||||
int result = Utils::String::naturalCompare(left.data().toString(), right.data().toString()
|
||||
, Qt::CaseInsensitive);
|
||||
return (result < 0);
|
||||
return m_naturalLessThan(left.data().toString(), right.data().toString());
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "base/utils/compare.h"
|
||||
|
||||
class QString;
|
||||
|
||||
class TagFilterProxyModel final : public QSortFilterProxyModel
|
||||
@@ -47,4 +49,6 @@ protected:
|
||||
private:
|
||||
// we added another overload of index(), hence this using directive:
|
||||
using QSortFilterProxyModel::index;
|
||||
|
||||
Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> m_naturalLessThan;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "torrentcontentfiltermodel.h"
|
||||
|
||||
#include "base/utils/string.h"
|
||||
#include "torrentcontentmodel.h"
|
||||
|
||||
TorrentContentFilterModel::TorrentContentFilterModel(QObject *parent)
|
||||
@@ -94,7 +93,7 @@ bool TorrentContentFilterModel::lessThan(const QModelIndex &left, const QModelIn
|
||||
{
|
||||
const QString strL = left.data().toString();
|
||||
const QString strR = right.data().toString();
|
||||
return Utils::String::naturalLessThan<Qt::CaseInsensitive>(strL, strR);
|
||||
return m_naturalLessThan(strL, strR);
|
||||
}
|
||||
if ((leftType == TorrentContentModelItem::FolderType) && (sortOrder() == Qt::AscendingOrder))
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "base/utils/compare.h"
|
||||
#include "torrentcontentmodelitem.h"
|
||||
|
||||
class TorrentContentModel;
|
||||
@@ -61,4 +62,5 @@ private:
|
||||
bool hasFiltered(const QModelIndex &folder) const;
|
||||
|
||||
TorrentContentModel *m_model;
|
||||
Utils::Compare::NaturalLessThan<Qt::CaseInsensitive> m_naturalLessThan;
|
||||
};
|
||||
|
||||
@@ -47,8 +47,8 @@
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/torrentfilter.h"
|
||||
#include "base/utils/compare.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "categoryfilterwidget.h"
|
||||
#include "tagfilterwidget.h"
|
||||
#include "transferlistwidget.h"
|
||||
@@ -366,10 +366,11 @@ void TrackerFiltersList::addItem(const QString &tracker, const BitTorrent::Torre
|
||||
}
|
||||
|
||||
Q_ASSERT(count() >= 4);
|
||||
const Utils::Compare::NaturalLessThan<Qt::CaseSensitive> naturalLessThan {};
|
||||
int insPos = count();
|
||||
for (int i = 4; i < count(); ++i)
|
||||
{
|
||||
if (Utils::String::naturalLessThan<Qt::CaseSensitive>(host, item(i)->text()))
|
||||
if (naturalLessThan(host, item(i)->text()))
|
||||
{
|
||||
insPos = i;
|
||||
break;
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include "base/bittorrent/infohash.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "transferlistmodel.h"
|
||||
|
||||
namespace
|
||||
@@ -143,7 +142,7 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r
|
||||
case TransferListModel::TR_SAVE_PATH:
|
||||
case TransferListModel::TR_TAGS:
|
||||
case TransferListModel::TR_TRACKER:
|
||||
return Utils::String::naturalCompare(leftValue.toString(), rightValue.toString(), Qt::CaseInsensitive);
|
||||
return m_naturalCompare(leftValue.toString(), rightValue.toString());
|
||||
|
||||
case TransferListModel::TR_AMOUNT_DOWNLOADED:
|
||||
case TransferListModel::TR_AMOUNT_DOWNLOADED_SESSION:
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "base/settingvalue.h"
|
||||
#include "base/torrentfilter.h"
|
||||
#include "base/utils/compare.h"
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
@@ -64,4 +65,6 @@ private:
|
||||
TorrentFilter m_filter;
|
||||
mutable CachedSettingValue<int> m_subSortColumn;
|
||||
mutable int m_lastSortColumn = -1;
|
||||
|
||||
Utils::Compare::NaturalCompare<Qt::CaseInsensitive> m_naturalCompare;
|
||||
};
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "base/logger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/torrentfilter.h"
|
||||
#include "base/utils/compare.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/string.h"
|
||||
@@ -963,7 +964,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
|
||||
|
||||
// Category Menu
|
||||
QStringList categories = BitTorrent::Session::instance()->categories().keys();
|
||||
std::sort(categories.begin(), categories.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
|
||||
std::sort(categories.begin(), categories.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
|
||||
QMenu *categoryMenu = listMenu->addMenu(UIThemeManager::instance()->getIcon("view-categories"), tr("Category"));
|
||||
|
||||
@@ -988,7 +989,7 @@ void TransferListWidget::displayListMenu(const QPoint &)
|
||||
|
||||
// Tag Menu
|
||||
QStringList tags(BitTorrent::Session::instance()->tags().values());
|
||||
std::sort(tags.begin(), tags.end(), Utils::String::naturalLessThan<Qt::CaseInsensitive>);
|
||||
std::sort(tags.begin(), tags.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
|
||||
|
||||
QMenu *tagsMenu = listMenu->addMenu(UIThemeManager::instance()->getIcon("view-categories"), tr("Tags"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user