File: syncthingsortfiltermodel.cpp

package info (click to toggle)
syncthingtray 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 34,081; xml: 1,705; java: 1,258; sh: 97; javascript: 54; makefile: 25
file content (34 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "./syncthingsortfiltermodel.h"
#include "./syncthingmodel.h"

#include <QSortFilterProxyModel>

namespace Data {

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);
}

bool SyncthingSortFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
    // keep order within nested structures
    if (m_behavior == SyncthingSortBehavior::KeepRawOrder || left.parent().isValid() || right.parent().isValid()) {
        return left.row() < right.row();
    }
    // 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;
    }
    // use the default sorting for the top-level
    return QSortFilterProxyModel::lessThan(left, right);
}

} // namespace Data