/
mtmodel.cpp
89 lines (80 loc) · 1.85 KB
/
mtmodel.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "mtmodel.h"
int MTModel::columnCount(const QModelIndex& parent) const
{
return list.size();
}
int MTModel::rowCount(const QModelIndex& parent) const
{
return list.size();
}
QVariant MTModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() >= list.size())
return QVariant();
if (role == Qt::DisplayRole){
return mul(
list.at(list.size() -1 - index.row()),
list.at(list.size() -1 - index.column()));
}
return QVariant();
}
QVariant MTModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role != Qt::DisplayRole)
return QVariant();
if ((orientation == Qt::Horizontal || orientation == Qt::Vertical)) {
if (base != MY_E)
return QString::number(list.at(list.size() -1 - section), base);
else
//return QString::number(toE(list.size() -1 - list.at(section)),'G',precision);
return section+1;
}
return QVariant();
}
void MTModel::setBase(int b)
{
base = b;
if (
b == 2 ||
b == 8 ||
b == 10 ||
b == 16
) {
setRange(b);
} else if (b == MY_E){
setRange(3);
} else {
return;
}
}
void MTModel::setRange(int r)
{
list.clear();
for(u_int8_t i = 1; i <= static_cast<u_int8_t>(r); i++)
list.add(i);
emit dataChanged(index(0,0),index(rowCount(),columnCount()));
emit headerDataChanged(Qt::Horizontal,0,15);
emit headerDataChanged(Qt::Vertical,0,15);
}
void MTModel::setPrecision(int p)
{
precision = p;
emit dataChanged(index(0,0),index(rowCount(),columnCount()));
emit headerDataChanged(Qt::Horizontal,0,15);
emit headerDataChanged(Qt::Vertical,0,15);
}
QString MTModel::mul(const u_int8_t& a, const u_int8_t& b) const
{
if (base != MY_E)
return QString::number(a*b,base);
else {
return QString::number(fromE(a*b),'f',precision);
}
return QString("NO DATA");
}
double MTModel::fromE(u_int8_t x) const
{
return pow(x, M_E);
}