2020-10-20 19:16:53 +02:00
|
|
|
#include "./syncthingsortfiltermodel.h"
|
2023-09-16 23:07:00 +02:00
|
|
|
#include "./syncthingmodel.h"
|
2020-10-18 15:48:02 +02:00
|
|
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2020-10-20 19:16:53 +02:00
|
|
|
bool SyncthingSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
2020-10-18 15:48:02 +02:00
|
|
|
{
|
|
|
|
// 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
|
2020-10-18 15:48:02 +02:00
|
|
|
{
|
|
|
|
// keep order within nested structures
|
2020-10-20 19:16:53 +02:00
|
|
|
if (m_behavior == SyncthingSortBehavior::KeepRawOrder || left.parent().isValid() || right.parent().isValid()) {
|
2020-10-18 15:48:02 +02:00
|
|
|
return left.row() < right.row();
|
|
|
|
}
|
2023-09-16 23:07:00 +02:00
|
|
|
// show pinned items before all other items
|
|
|
|
const auto leftPinned = left.data(SyncthingModel::IsPinned).toBool();
|
|
|
|
const auto rightPinned = right.data(SyncthingModel::IsPinned).toBool();
|
|
|
|
if (leftPinned != rightPinned) {
|
|
|
|
return leftPinned;
|
|
|
|
}
|
2020-10-18 15:48:02 +02:00
|
|
|
// use the default sorting for the top-level
|
|
|
|
return QSortFilterProxyModel::lessThan(left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Data
|