From a50798c78f321bc3d245509cd110886a7f49bf86 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 25 Mar 2021 22:52:46 +0800 Subject: [PATCH] Sort invalid QDateTime values after valid values Closes #14607. --- src/gui/transferlistsortmodel.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/transferlistsortmodel.cpp b/src/gui/transferlistsortmodel.cpp index 66db65dc0..59b686161 100644 --- a/src/gui/transferlistsortmodel.cpp +++ b/src/gui/transferlistsortmodel.cpp @@ -47,6 +47,18 @@ namespace return (left < right) ? -1 : 1; } + int customCompare(const QDateTime &left, const QDateTime &right) + { + const bool isLeftValid = left.isValid(); + const bool isRightValid = right.isValid(); + + if (isLeftValid && isRightValid) + return threeWayCompare(left, right); + if (!isLeftValid && !isRightValid) + return 0; + return isLeftValid ? -1 : 1; + } + template int customCompare(const T left, const T right) { @@ -158,7 +170,7 @@ int TransferListSortModel::compare(const QModelIndex &left, const QModelIndex &r case TransferListModel::TR_ADD_DATE: case TransferListModel::TR_SEED_DATE: case TransferListModel::TR_SEEN_COMPLETE_DATE: - return threeWayCompare(leftValue.toDateTime(), rightValue.toDateTime()); + return customCompare(leftValue.toDateTime(), rightValue.toDateTime()); case TransferListModel::TR_DLLIMIT: case TransferListModel::TR_DLSPEED: