2
Copyright 2013 Jan Grulich <jgrulich@redhat.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) version 3, or any
8
later version accepted by the membership of KDE e.V. (or its
9
successor approved by the membership of KDE e.V.), which shall
10
act as a proxy defined in Section 6 of version 3 of the license.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#include "sortmodel.h"
24
SortModel::SortedConnectionType SortModel::connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type)
27
case NetworkManager::ConnectionSettings::Unknown:
28
return SortModel::SortModel::Unknown;
30
case NetworkManager::ConnectionSettings::Adsl:
31
return SortModel::SortModel::Adsl;
33
case NetworkManager::ConnectionSettings::Bluetooth:
34
return SortModel::Bluetooth;
36
case NetworkManager::ConnectionSettings::Bond:
37
return SortModel::Bond;
39
case NetworkManager::ConnectionSettings::Bridge:
40
return SortModel::Bridge;
42
case NetworkManager::ConnectionSettings::Cdma:
43
return SortModel::Cdma;
45
case NetworkManager::ConnectionSettings::Gsm:
46
return SortModel::Gsm;
48
case NetworkManager::ConnectionSettings::Infiniband:
49
return SortModel::Infiniband;
51
case NetworkManager::ConnectionSettings::OLPCMesh:
52
return SortModel::OLPCMesh;
54
case NetworkManager::ConnectionSettings::Pppoe:
55
return SortModel::Pppoe;
57
case NetworkManager::ConnectionSettings::Vlan:
58
return SortModel::Vlan;
60
case NetworkManager::ConnectionSettings::Vpn:
61
return SortModel::Vpn;
63
case NetworkManager::ConnectionSettings::Wimax:
64
return SortModel::Wimax;
66
case NetworkManager::ConnectionSettings::Wired:
67
return SortModel::Wired;
69
case NetworkManager::ConnectionSettings::Wireless:
70
return SortModel::Wireless;
73
return SortModel::Unknown;
78
SortModel::SortModel(QObject* parent):
79
QSortFilterProxyModel(parent)
81
setDynamicSortFilter(true);
82
sort(0, Qt::DescendingOrder);
85
SortModel::~SortModel()
89
void SortModel::setSourceModel(QAbstractItemModel* sourceModel)
91
QSortFilterProxyModel::setSourceModel(sourceModel);
94
QAbstractItemModel* SortModel::sourceModel() const
96
return QSortFilterProxyModel::sourceModel();
99
bool SortModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
101
const bool leftConnected = sourceModel()->data(left, Model::ConnectedRole).toBool();
102
const SortedConnectionType leftType = connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(left, Model::TypeRole).toUInt());
103
const QString leftUuid = sourceModel()->data(left, Model::UuidRole).toString();
104
const int leftSignal = sourceModel()->data(left, Model::SignalRole).toInt();
106
const bool rightConnected = sourceModel()->data(right, Model::ConnectedRole).toBool();
107
const SortedConnectionType rightType = connectionTypeToSortedType((NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(right, Model::TypeRole).toUInt());
108
const QString rightUuid = sourceModel()->data(right, Model::UuidRole).toString();
109
const int rightSignal = sourceModel()->data(right, Model::SignalRole).toInt();
111
if (leftConnected < rightConnected) {
113
} else if (leftConnected > rightConnected) {
117
if (leftUuid.isEmpty() && !rightUuid.isEmpty()) {
119
} else if (!leftUuid.isEmpty() && rightUuid.isEmpty()) {
123
if (leftType < rightType) {
125
} else if (leftType > rightType) {
129
if (leftSignal < rightSignal) {