-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commatrix.cpp
64 lines (53 loc) · 1.37 KB
/
Commatrix.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 "Commatrix.h"
Commatrix::Commatrix(QObject *parent)
: QAbstractTableModel(parent)
{
mat = cv::Mat(0, 0, CV_8UC1);
}
//QVariant Commatrix::headerData(int section, Qt::Orientation orientation, int role) const
//{
// // FIXME: Implement me!
// return QVariant();
//}
int Commatrix::rowCount(const QModelIndex &parent) const
{
return hei;
}
int Commatrix::columnCount(const QModelIndex &parent) const
{
return wid;
}
QHash<int, QByteArray> Commatrix::roleNames() const
{
return { {Qt::DisplayRole, "display"} };
}
QVariant Commatrix::data(const QModelIndex &index, int role) const
{
if(index.row() < 0 || index.row() >= hei || index.column() < 0 || index.column() >= wid)
return QVariant();
if (role == Qt::DisplayRole) {
// uchar u = mat.at(index.row(), index.column());
uchar ed =0;
for (const auto &p : (*elems)) {
if (p.getX() == index.column() && p.getY() == index.row())
ed = p.value;
}
return QVariant(ed);
}
else
return QVariant();
}
void Commatrix::setMatrix(cv::Mat &matrix)
{
beginInsertRows(QModelIndex(),0,matrix.rows);
this->mat = matrix;
endInsertRows();
}
void Commatrix::setElems(bc::barvector *els,const cv::Size& s)
{
this->hei = s.height;
this->wid = s.width;
beginInsertRows(QModelIndex(), 0, hei);
this->elems = els;
endInsertRows();
}