blob: 67d0c0a4e4c5d588051cc5faa4e2fd727731a6e6 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* pvsNetworkInterfaceListModel.cpp
*
* Created on: 04.08.2010
* Author: brs
*/
#include "pvsNetworkInterfaceListModel.h"
#include <QStringList>
PVSNetworkInterfaceListModel::PVSNetworkInterfaceListModel(QObject* parent) :
QAbstractListModel(parent)
{
reloadInterfaceList();
}
PVSNetworkInterfaceListModel::~PVSNetworkInterfaceListModel()
{
}
void PVSNetworkInterfaceListModel::reloadInterfaceList()
{
_interfaces = QNetworkInterface::allInterfaces();
reset();
}
QVariant PVSNetworkInterfaceListModel::data(QModelIndex const& index, int role) const
{
int i = index.row();
if(0 > i || i >= _interfaces.size())
{
return QVariant();
}
QNetworkInterface intf = _interfaces.at(i);
switch(role)
{
case Qt::DisplayRole:
{
QString name = intf.humanReadableName();
QList<QNetworkAddressEntry> addresses = intf.addressEntries();
QStringList l;
foreach(QNetworkAddressEntry addr, addresses)
{
l.append(addr.ip().toString());
}
return QString("%1 (%2)").arg(name).arg(l.join(", "));
}
case Qt::EditRole:
case Qt::UserRole:
return intf.name();
default:
return QVariant();
}
}
QVariant PVSNetworkInterfaceListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(section == 0 && orientation == Qt::Vertical && role == Qt::DisplayRole)
{
return tr("Interface");
}
else
{
return QVariant();
}
}
int PVSNetworkInterfaceListModel::rowCount(QModelIndex const& parent) const
{
if(parent.isValid())
{
return 0;
}
else
{
return _interfaces.size();
}
}
|