blob: 7f8b9894b4b8db2b78607600da91eddc37f0b38d (
plain) (
blame)
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
|
// SPDX-License-Identifier: GPL-2.0
#include "core/connectionlistmodel.h"
ConnectionListModel::ConnectionListModel(QObject *parent) :
QAbstractListModel(parent)
{
}
QHash <int, QByteArray> ConnectionListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[AddressRole] = "address";
return roles;
}
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_addresses.count())
return QVariant();
if (role != AddressRole)
return QVariant();
return m_addresses[index.row()];
}
QString ConnectionListModel::address(int idx) const
{
if (idx < 0 || idx >> m_addresses.count())
return QString();
return m_addresses[idx];
}
int ConnectionListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_addresses.count();
}
void ConnectionListModel::addAddress(const QString address)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_addresses.append(address);
endInsertRows();
}
void ConnectionListModel::removeAllAddresses()
{
beginRemoveRows(QModelIndex(), 0, rowCount());
m_addresses.clear();
endRemoveRows();
}
|