1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #include "servicesproxymodel.h" |
5 | |
6 | using namespace Qt::StringLiterals; |
7 | |
8 | ServicesProxyModel::ServicesProxyModel(QObject *parent) |
9 | : QSortFilterProxyModel(parent) |
10 | { |
11 | } |
12 | |
13 | QVariant ServicesProxyModel::headerData(int section, Qt::Orientation orientation, int role) const |
14 | { |
15 | if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section != 0) |
16 | return QVariant(); |
17 | |
18 | return tr(s: "Services"); |
19 | } |
20 | |
21 | |
22 | bool ServicesProxyModel::lessThan(const QModelIndex &left, |
23 | const QModelIndex &right) const |
24 | { |
25 | QString s1 = sourceModel()->data(index: left).toString(); |
26 | QString s2 = sourceModel()->data(index: right).toString(); |
27 | |
28 | const bool isNumber1 = s1.startsWith(s: ":1."_L1); |
29 | const bool isNumber2 = s2.startsWith(s: ":1."_L1); |
30 | if (isNumber1 == isNumber2) { |
31 | if (isNumber1) { |
32 | int number1 = QStringView{s1}.mid(pos: 3).toInt(); |
33 | int number2 = QStringView{s2}.mid(pos: 3).toInt(); |
34 | return number1 < number2; |
35 | } else { |
36 | return s1.compare(s: s2, cs: Qt::CaseInsensitive) < 0; |
37 | } |
38 | } else { |
39 | return isNumber2; |
40 | } |
41 | } |
42 |