From bdf27451ad912c5b5f865d6a3f6ea7eeadf789f7 Mon Sep 17 00:00:00 2001 From: Gabriele Date: Sun, 19 Oct 2014 19:19:10 +0100 Subject: [PATCH] Put directories first when sorting torrent content by name Closes #1594. --- src/torrentcontentfiltermodel.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/torrentcontentfiltermodel.cpp b/src/torrentcontentfiltermodel.cpp index 24341d449..583c04cb5 100644 --- a/src/torrentcontentfiltermodel.cpp +++ b/src/torrentcontentfiltermodel.cpp @@ -90,11 +90,19 @@ bool TorrentContentFilterModel::lessThan(const QModelIndex &left, const QModelIn Q_ASSERT(vL.isValid()); Q_ASSERT(vR.isValid()); - bool res = false; - if (misc::naturalSort(vL.toString(), vR.toString(), res)) - return res; - - return QSortFilterProxyModel::lessThan(left, right); + TorrentContentModelItem::ItemType leftType, rightType; + leftType = m_model->itemType(m_model->index(left.row(), 0, left.parent())); + rightType = m_model->itemType(m_model->index(right.row(), 0, right.parent())); + if (leftType == rightType) { + bool res = false; + if (misc::naturalSort(vL.toString(), vR.toString(), res)) + return res; + return QSortFilterProxyModel::lessThan(left, right); + } + else if (leftType == TorrentContentModelItem::FolderType && sortOrder() == Qt::AscendingOrder) + return true; + else + return false; } return QSortFilterProxyModel::lessThan(left, right); }