summaryrefslogtreecommitdiffstats
path: root/network/abstractnetworkmodel.cpp
blob: 6eada6a8d5d7f55ff1c6fe99a3bd4135efaa3541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}