-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvorPromet.cpp
64 lines (49 loc) · 1.69 KB
/
CvorPromet.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
#include "CvorPromet.h"
CvorPrometModel::CvorPrometModel(QObject *parent) : QAbstractTableModel(parent) {}
void CvorPrometModel::populateData(QList<CvorPromet> _promet){
promet.clear();
promet = _promet;
}
int CvorPrometModel::rowCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return promet.length();
}
int CvorPrometModel::columnCount(const QModelIndex &parent) const {
Q_UNUSED(parent);
return 2;
}
QVariant CvorPrometModel::data(const QModelIndex &index, int role) const{
if(!index.isValid() || role != Qt::DisplayRole)
return QVariant();
if(index.column() == 0)
return promet[index.row()].MAC;
else if(index.column() == 1)
return promet[index.row()].BrojPaketa;
return QVariant();
}
QVariant CvorPrometModel::headerData(int section, Qt::Orientation orientation, int role) const {
if(role != Qt::DisplayRole || orientation != Qt::Horizontal)
return QVariant();
if(section == 0)
return QString("Čvor (MAC)");
else if(section == 1)
return QString("Broj paketa");
return QVariant();
}
bool CvorPrometModel::dodajPromet(Okvir okvir, const QModelIndex &parent)
{
for(QString mac : okvir.macAdrese) {
auto cvor = std::find_if(std::begin(promet), std::end(promet), [&](CvorPromet &cvorInfo) { return cvorInfo.MAC == mac; });
if(cvor != promet.end()) {
cvor->BrojPaketa++;
}else{
beginInsertRows(parent, promet.count(), promet.count());
CvorPromet noviCvor;
noviCvor.BrojPaketa = 1;
noviCvor.MAC = mac;
promet.append(noviCvor);
endInsertRows();
}
}
return true;
}