summaryrefslogtreecommitdiffstats
path: root/network/abstractnetworkmodel.cpp
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2019-06-05 12:37:33 +0200
committerraquel medina <raquel.medina@konsulko.com>2019-06-10 10:55:23 +0000
commitd3632244d611435f48f5aeb653f9031ace9a3b20 (patch)
treedff535ea26de1483df29d5e52f91799645562d63 /network/abstractnetworkmodel.cpp
parent0b4be8897b1d041db9931f4726d0dbd9d03a0c58 (diff)
network: add network model abstraction
- AbstractNetworkModel : abstract class which provides common functionality and data to all network models. -ConnectionProfile : super class which aglomerates connection property information, independently of the technology type (e.g. wired or wifi). A network model contains a list of available connection profiles pertinent to the model. Bug-AGL: SPEC-2293 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: Ic7b9d59802d13067e057948d1fb109852f35c2fd
Diffstat (limited to 'network/abstractnetworkmodel.cpp')
-rw-r--r--network/abstractnetworkmodel.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/network/abstractnetworkmodel.cpp b/network/abstractnetworkmodel.cpp
new file mode 100644
index 0000000..6eada6a
--- /dev/null
+++ b/network/abstractnetworkmodel.cpp
@@ -0,0 +1,56 @@
+#include "abstractnetworkmodel.h"
+#include "connectionprofile.h"
+#include <QDebug>
+
+
+AbstractNetworkModel::AbstractNetworkModel(QObject *parent)
+ : QAbstractListModel(parent)
+{
+}
+
+void AbstractNetworkModel::addNetwork(ConnectionProfile *network)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ m_networks << network;
+ endInsertRows();
+}
+
+void AbstractNetworkModel::removeNetwork(ConnectionProfile *network)
+{
+ int row = m_networks.indexOf(network);
+ beginRemoveRows(QModelIndex(), row, row);
+ m_networks.removeAt(row);
+ endRemoveRows();
+ delete network;
+}
+
+void AbstractNetworkModel::removeAllNetworks()
+{
+ beginRemoveRows(QModelIndex(), 0, m_networks.count() - 1);
+ qDeleteAll(m_networks.begin(), m_networks.end());
+ m_networks.clear();
+ endRemoveRows();
+}
+
+ConnectionProfile *AbstractNetworkModel::getNetwork(QString service)
+{
+ for (auto network : m_networks) {
+ if (network->service() == service)
+ return network;
+ }
+
+ return nullptr;
+}
+
+int AbstractNetworkModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return m_networks.count();
+}
+
+QModelIndex AbstractNetworkModel::indexOf(ConnectionProfile *network)
+{
+ int row = m_networks.indexOf(network);
+
+ return index(row);
+}