-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_item.cpp
65 lines (51 loc) · 1.63 KB
/
scan_item.cpp
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
#include "scan_item.h"
ScanItemModel::ScanItemModel(QObject *parent) : QAbstractTableModel(parent) {}
// Create a method to populate the model with data:
void ScanItemModel::populateData(const QList<QString> &IPs_, const QList<QString> &ports_, const QList<QString> &description_) {
IPs.clear();
IPs = IPs_;
ports.clear();
ports = ports_;
descriptions.clear();
descriptions = description_;
return;
}
void ScanItemModel::appendItem(const QString IP, const QString port, const QString description) {
IPs.append(IP);
ports.append(port);
descriptions.append(description);
}
int ScanItemModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return IPs.length();
}
int ScanItemModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return 3;
}
QVariant ScanItemModel::data(const QModelIndex &index, int role) const {
if (!index.isValid() || role != Qt::DisplayRole) {
return QVariant();
}
if (index.column() == 0) {
return IPs[index.row()];
} else if (index.column() == 1) {
return ports[index.row()];
} else if (index.column() == 2) {
return descriptions[index.row()];
}
return QVariant();
}
QVariant ScanItemModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (!(role == Qt::DisplayRole && orientation == Qt::Horizontal)) {
return QVariant();
}
if (section == 0) {
return QString("IP");
} else if (section == 1) {
return QString("Port");
} else if (section == 2) {
return QString("Description");
}
return QVariant();
}