syncthingtray/model/syncthingsortfiltermodel.cpp

28 lines
849 B
C++
Raw Normal View History

2020-10-20 19:16:53 +02:00
#include "./syncthingsortfiltermodel.h"
#include <QSortFilterProxyModel>
namespace Data {
2020-10-20 19:16:53 +02:00
bool SyncthingSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
// show all nested structures
if (sourceParent.isValid()) {
return true;
}
// use default filtering for top-level
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}
2020-10-20 19:16:53 +02:00
bool SyncthingSortFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
// keep order within nested structures
2020-10-20 19:16:53 +02:00
if (m_behavior == SyncthingSortBehavior::KeepRawOrder || left.parent().isValid() || right.parent().isValid()) {
return left.row() < right.row();
}
// use the default sorting for the top-level
return QSortFilterProxyModel::lessThan(left, right);
}
} // namespace Data