1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

Merge pull request #2816 from pmzqla/sortdates

Put torrents with invalid "Last Activity" value or no "Ratio Limit" at the bottom of the list
This commit is contained in:
sledgehammer999 2015-04-05 22:16:47 +03:00
commit 28eeef93f6

View File

@ -38,16 +38,19 @@ TransferListSortModel::TransferListSortModel(QObject *parent)
, filter0(TorrentFilter::ALL)
, labelFilterEnabled(false)
, trackerFilterEnabled(false)
{}
{
}
void TransferListSortModel::setStatusFilter(const TorrentFilter::TorrentFilter &filter) {
void TransferListSortModel::setStatusFilter(const TorrentFilter::TorrentFilter &filter)
{
if (filter != filter0) {
filter0 = filter;
invalidateFilter();
}
}
void TransferListSortModel::setLabelFilter(const QString &label) {
void TransferListSortModel::setLabelFilter(const QString &label)
{
if (!labelFilterEnabled || labelFilter != label) {
labelFilterEnabled = true;
labelFilter = label;
@ -55,7 +58,8 @@ void TransferListSortModel::setLabelFilter(const QString &label) {
}
}
void TransferListSortModel::disableLabelFilter() {
void TransferListSortModel::disableLabelFilter()
{
if (labelFilterEnabled) {
labelFilterEnabled = false;
labelFilter = QString();
@ -63,7 +67,8 @@ void TransferListSortModel::disableLabelFilter() {
}
}
void TransferListSortModel::setTrackerFilter(const QStringList &hashes) {
void TransferListSortModel::setTrackerFilter(const QStringList &hashes)
{
if (!trackerFilterEnabled || trackerFilter != hashes) {
trackerFilterEnabled = true;
trackerFilter = hashes;
@ -71,7 +76,8 @@ void TransferListSortModel::setTrackerFilter(const QStringList &hashes) {
}
}
void TransferListSortModel::disableTrackerFilter() {
void TransferListSortModel::disableTrackerFilter()
{
if (trackerFilterEnabled) {
trackerFilterEnabled = false;
trackerFilter = QStringList();
@ -79,7 +85,8 @@ void TransferListSortModel::disableTrackerFilter() {
}
}
bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
const int column = sortColumn();
if (column == TorrentModelItem::TR_NAME) {
@ -200,26 +207,49 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
return dateL < dateR;
}
else
else {
return prioL < prioR;
}
else if ((invalidL == false) && (invalidR == false))
}
else if ((invalidL == false) && (invalidR == false)) {
return QSortFilterProxyModel::lessThan(left, right);
else
}
else {
return !invalidL;
}
}
else if (column == TorrentModelItem::TR_LAST_ACTIVITY) {
const qlonglong vL = left.data().toLongLong();
const qlonglong vR = right.data().toLongLong();
if (vL == -1) return false;
if (vR == -1) return true;
return vL < vR;
}
else if (column == TorrentModelItem::TR_RATIO_LIMIT) {
const qreal vL = left.data().toDouble();
const qreal vR = right.data().toDouble();
if (vL == -1) return false;
if (vR == -1) return true;
return vL < vR;
}
return QSortFilterProxyModel::lessThan(left, right);
}
bool TransferListSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
bool TransferListSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
return matchStatusFilter(sourceRow, sourceParent)
&& matchLabelFilter(sourceRow, sourceParent)
&& matchTrackerFilter(sourceRow, sourceParent)
&& QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
bool TransferListSortModel::matchStatusFilter(int sourceRow, const QModelIndex &sourceParent) const {
bool TransferListSortModel::matchStatusFilter(int sourceRow, const QModelIndex &sourceParent) const
{
if (filter0 == TorrentFilter::ALL)
return true;
QAbstractItemModel *model = sourceModel();
@ -271,7 +301,8 @@ bool TransferListSortModel::matchStatusFilter(int sourceRow, const QModelIndex &
}
}
bool TransferListSortModel::matchLabelFilter(int sourceRow, const QModelIndex &sourceParent) const {
bool TransferListSortModel::matchLabelFilter(int sourceRow, const QModelIndex &sourceParent) const
{
if (!labelFilterEnabled)
return true;
@ -282,7 +313,8 @@ bool TransferListSortModel::matchLabelFilter(int sourceRow, const QModelIndex &s
return model->index(sourceRow, TorrentModelItem::TR_LABEL, sourceParent).data().toString() == labelFilter;
}
bool TransferListSortModel::matchTrackerFilter(int sourceRow, const QModelIndex &sourceParent) const {
bool TransferListSortModel::matchTrackerFilter(int sourceRow, const QModelIndex &sourceParent) const
{
if (!trackerFilterEnabled)
return true;