Consider depth levels in path sorting (#5445) (#5573)

This commit is contained in:
Santiago Gil 2016-12-31 10:22:10 -03:00 committed by John Maguire
parent 789c4924f4
commit 00c96f7334
2 changed files with 23 additions and 0 deletions

View File

@ -1309,6 +1309,18 @@ bool Playlist::CompareItems(int column, Qt::SortOrder order,
return false;
}
bool Playlist::ComparePathDepths(Qt::SortOrder order,
shared_ptr<PlaylistItem> _a,
shared_ptr<PlaylistItem> _b) {
shared_ptr<PlaylistItem> a = order == Qt::AscendingOrder ? _a : _b;
shared_ptr<PlaylistItem> b = order == Qt::AscendingOrder ? _b : _a;
int a_dir_level = a->Url().path().count('/');
int b_dir_level = b->Url().path().count('/');
return a_dir_level < b_dir_level;
}
QString Playlist::column_name(Column column) {
switch (column) {
case Column_Title:
@ -1410,6 +1422,14 @@ void Playlist::sort(int column, Qt::SortOrder order) {
std::bind(&Playlist::CompareItems, Column_Disc, order, _1, _2));
qStableSort(begin, new_items.end(), std::bind(&Playlist::CompareItems,
Column_Album, order, _1, _2));
} else if (column == Column_Filename) {
// When sorting by full paths we also expect a hierarchical order. This
// returns a breath-first ordering of paths.
qStableSort(
begin, new_items.end(),
std::bind(&Playlist::CompareItems, Column_Filename, order, _1, _2));
qStableSort(begin, new_items.end(),
std::bind(&Playlist::ComparePathDepths, order, _1, _2));
} else {
qStableSort(begin, new_items.end(),
std::bind(&Playlist::CompareItems, column, order, _1, _2));

View File

@ -306,6 +306,9 @@ class Playlist : public QAbstractListModel {
bool removeRows(int row, int count,
const QModelIndex& parent = QModelIndex());
static bool ComparePathDepths(Qt::SortOrder, PlaylistItemPtr,
PlaylistItemPtr);
public slots:
void set_current_row(int index, bool is_stopping = false);
void Paused();