Commit a81709ae authored by Jan Grulich's avatar Jan Grulich

Make mobile proxy model to inherit QSortFilterProxyModel

We need it to be combination of both the applet and editor proxy models so we
cannot inherit any of them
parent 1bfff897
......@@ -5,10 +5,10 @@ set(plasmanm_internal_SRCS
models/creatableconnectionsmodel.cpp
models/editorproxymodel.cpp
models/kcmidentitymodel.cpp
models/mobileproxymodel.cpp
models/networkitemslist.cpp
models/networkmodel.cpp
models/networkmodelitem.cpp
models/mobileappletproxymodel.cpp
configuration.cpp
debug.cpp
......
......@@ -33,7 +33,7 @@
#include "editorproxymodel.h"
#include "kcmidentitymodel.h"
#include "networkmodel.h"
#include "mobileappletproxymodel.h"
#include "mobileproxymodel.h"
#include "handler.h"
#include "enums.h"
......@@ -64,6 +64,6 @@ void QmlPlugins::registerTypes(const char* uri)
qmlRegisterType<KcmIdentityModel>(uri, 0, 2, "KcmIdentityModel");
// @uri org.kde.plasma.networkmanagement.CreatableConnectionsModel
qmlRegisterType<CreatableConnectionsModel>(uri, 0, 2, "CreatableConnectionsModel");
// @uri org.kde.plasma.networkmanagement.MobileAppletProxyModel
qmlRegisterType<MobileAppletProxymodel>(uri, 0, 2, "MobileAppletProxyModel");
// @uri org.kde.plasma.networkmanagement.MobileProxyModel
qmlRegisterType<MobileProxyModel>(uri, 0, 2, "MobileProxyModel");
}
......@@ -28,7 +28,7 @@
class Q_DECL_EXPORT AppletProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
public:
explicit AppletProxyModel(QObject* parent = 0);
virtual ~AppletProxyModel();
......
/*
* <one line to give the library's name and an idea of what it does.>
* Mobile proxy model - model for displaying netwoks in mobile kcm
* Copyright 2017 Martin Kacej <m.kacej@atlas.sk>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
......@@ -9,53 +9,106 @@
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
*
*/
#include "mobileappletproxymodel.h"
#include "mobileproxymodel.h"
#include "networkmodel.h"
#include "networkmodelitem.h"
#include "uiutils.h"
MobileAppletProxymodel::MobileAppletProxymodel(QObject* parent):AppletProxyModel(parent)
MobileProxyModel::MobileProxyModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
setDynamicSortFilter(true);
sort(0, Qt::DescendingOrder);
}
MobileAppletProxymodel::~MobileAppletProxymodel()
MobileProxyModel::~MobileProxyModel()
{
}
bool MobileAppletProxymodel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
bool MobileProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
const QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
// slaves are always filtered-out
const bool isSlave = sourceModel()->data(index, NetworkModel::SlaveRole).toBool();
if (isSlave) {
return false;
}
const NetworkManager::ConnectionSettings::ConnectionType type = (NetworkManager::ConnectionSettings::ConnectionType) sourceModel()->data(index, NetworkModel::TypeRole).toUInt();
if(type == NetworkManager::ConnectionSettings::Wireless){
if (!UiUtils::isConnectionTypeSupported(type)) {
return false;
}
NetworkModelItem::ItemType itemType = (NetworkModelItem::ItemType)sourceModel()->data(index, NetworkModel::ItemTypeRole).toUInt();
if (itemType == NetworkModelItem::AvailableConnection ||
itemType == NetworkModelItem::AvailableAccessPoint ||
itemType == NetworkModelItem::AvailableNsp) {
return true;
}
}
return false;
return type == NetworkManager::ConnectionSettings::Wireless;
}
bool MobileProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
const bool leftAvailable = (NetworkModelItem::ItemType)sourceModel()->data(left, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection;
const bool leftConnected = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated;
const int leftConnectionState = sourceModel()->data(left, NetworkModel::ConnectionStateRole).toUInt();
const QString leftName = sourceModel()->data(left, NetworkModel::NameRole).toString();
const QString leftUuid = sourceModel()->data(left, NetworkModel::UuidRole).toString();
const int leftSignal = sourceModel()->data(left, NetworkModel::SignalRole).toInt();
const QDateTime leftDate = sourceModel()->data(left, NetworkModel::TimeStampRole).toDateTime();
const bool rightAvailable = (NetworkModelItem::ItemType)sourceModel()->data(right, NetworkModel::ItemTypeRole).toUInt() != NetworkModelItem::UnavailableConnection;
const bool rightConnected = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt() == NetworkManager::ActiveConnection::Activated;
const int rightConnectionState = sourceModel()->data(right, NetworkModel::ConnectionStateRole).toUInt();
const QString rightName = sourceModel()->data(right, NetworkModel::NameRole).toString();
const QString rightUuid = sourceModel()->data(right, NetworkModel::UuidRole).toString();
const int rightSignal = sourceModel()->data(right, NetworkModel::SignalRole).toInt();
const QDateTime rightDate = sourceModel()->data(right, NetworkModel::TimeStampRole).toDateTime();
if (leftAvailable < rightAvailable) {
return true;
} else if (leftAvailable > rightAvailable) {
return false;
}
if (leftConnected < rightConnected) {
return true;
} else if (leftConnected > rightConnected) {
return false;
}
if (leftConnectionState > rightConnectionState) {
return true;
} else if (leftConnectionState < rightConnectionState) {
return false;
}
if (leftUuid.isEmpty() && !rightUuid.isEmpty()) {
return true;
} else if (!leftUuid.isEmpty() && rightUuid.isEmpty()) {
return false;
}
if (leftDate > rightDate) {
return false;
} else if (leftDate < rightDate) {
return true;
}
if (leftSignal < rightSignal) {
return true;
} else if (leftSignal > rightSignal) {
return false;
}
if (QString::localeAwareCompare(leftName, rightName) > 0) {
return true;
} else {
return false;
}
}
/*
* Mobile applet proxy model - model for displaying netwoks in mobile applet
* Mobile applet proxy model - model for displaying netwoks in mobile kcm
* Copyright 2017 Martin Kacej <m.kacej@atlas.sk>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
......@@ -9,33 +9,34 @@
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
*
*/
#ifndef MOBILEAPPLETPROXYMODEL_H
#define MOBILEAPPLETPROXYMODEL_H
#ifndef PLASMA_NM_MOBILE_PROXY_MODEL_H
#define PLASMA_NM_MOBILE_PROXY_MODEL_H
#include "appletproxymodel.h"
#include <QSortFilterProxyModel>
class Q_DECL_EXPORT MobileAppletProxymodel : public AppletProxyModel
class Q_DECL_EXPORT MobileProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
Q_PROPERTY(QAbstractItemModel * sourceModel READ sourceModel WRITE setSourceModel)
public:
explicit MobileAppletProxymodel(QObject* parent = 0);
virtual ~MobileAppletProxymodel();
explicit MobileProxyModel(QObject* parent = 0);
virtual ~MobileProxyModel();
protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const Q_DECL_OVERRIDE;
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const Q_DECL_OVERRIDE;
bool lessThan(const QModelIndex& left, const QModelIndex& right) const Q_DECL_OVERRIDE;
};
#endif // MOBILEAPPLETPROXYMODEL_H
#endif // PLASMA_NM_MOBILE_PROXY_MODEL_H
......@@ -47,8 +47,8 @@ Item {
id: connectionModel
}
PlasmaNM.MobileAppletProxyModel {
id: mobileappletProxyModel
PlasmaNM.MobileProxyModel {
id: mobileProxyModel
sourceModel: connectionModel
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment