-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqeigenmatrixmodel.cpp
36 lines (28 loc) · 954 Bytes
/
qeigenmatrixmodel.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
#include "qeigenmatrixmodel.h"
#include <limits>
QEigenMatrixModel::QEigenMatrixModel(Eigen::MatrixXd &matrix)
: QAbstractTableModel(), m_matrix(matrix) {}
QEigenMatrixModel::~QEigenMatrixModel() {}
int QEigenMatrixModel::rowCount(const QModelIndex &) const {
return m_matrix.rows();
}
int QEigenMatrixModel::columnCount(const QModelIndex &) const {
return m_matrix.cols();
}
QVariant QEigenMatrixModel::data(const QModelIndex &index, int role) const {
switch (role) {
case Qt::DisplayRole:
if (index.isValid() && index.column() < m_matrix.cols() &&
index.row() < m_matrix.rows())
return QString::number(m_matrix(index.row(), index.column()));
default:
break;
}
return QVariant();
}
Qt::ItemFlags QEigenMatrixModel::flags(const QModelIndex &index) const {
return QAbstractItemModel::flags(index);
}
QHash<int, QByteArray> QEigenMatrixModel::roleNames() const {
return {{Qt::DisplayRole, "display"}};
}