1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the tools applications of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include "servicesproxymodel.h" |
30 | |
31 | ServicesProxyModel::ServicesProxyModel(QObject *parent) |
32 | : QSortFilterProxyModel(parent) |
33 | { |
34 | } |
35 | |
36 | QVariant ServicesProxyModel::headerData(int section, Qt::Orientation orientation, int role) const |
37 | { |
38 | if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section != 0) |
39 | return QVariant(); |
40 | |
41 | return tr(s: "Services"); |
42 | } |
43 | |
44 | |
45 | bool ServicesProxyModel::lessThan(const QModelIndex &left, |
46 | const QModelIndex &right) const |
47 | { |
48 | QString s1 = sourceModel()->data(index: left).toString(); |
49 | QString s2 = sourceModel()->data(index: right).toString(); |
50 | |
51 | const bool isNumber1 = s1.startsWith(s: QLatin1String(":1.")); |
52 | const bool isNumber2 = s2.startsWith(s: QLatin1String(":1.")); |
53 | if (isNumber1 == isNumber2) { |
54 | if (isNumber1) { |
55 | int number1 = s1.midRef(position: 3).toInt(); |
56 | int number2 = s2.midRef(position: 3).toInt(); |
57 | return number1 < number2; |
58 | } else { |
59 | return s1.compare(s: s2, cs: Qt::CaseInsensitive) < 0; |
60 | } |
61 | } else { |
62 | return isNumber2; |
63 | } |
64 | } |
65 |