2019-03-02 20:20:23 +01:00
|
|
|
#include "global.h"
|
2019-02-10 14:43:00 +01:00
|
|
|
#include "vartablemodel.h"
|
2019-03-02 20:20:23 +01:00
|
|
|
#include "abstractdata.h"
|
2019-02-10 14:32:15 +01:00
|
|
|
|
2019-03-16 20:34:09 +01:00
|
|
|
const QStringList varTableModel::real_header={ "A",
|
|
|
|
"B",
|
|
|
|
"C",
|
|
|
|
"D",
|
|
|
|
"E",
|
|
|
|
"F",
|
|
|
|
"G",
|
|
|
|
"H",
|
|
|
|
"I",
|
|
|
|
"J",
|
|
|
|
"K",
|
|
|
|
"L",
|
|
|
|
"M",
|
|
|
|
"N",
|
|
|
|
"o",
|
|
|
|
"P",
|
|
|
|
"Q",
|
|
|
|
"R",
|
|
|
|
"S",
|
|
|
|
"T",
|
|
|
|
"U",
|
|
|
|
"V",
|
|
|
|
"W",
|
|
|
|
"X",
|
|
|
|
"Y",
|
|
|
|
"Z",
|
|
|
|
"THETA"
|
|
|
|
};
|
|
|
|
|
|
|
|
const QStringList varTableModel::complex_header={ "Z0",
|
|
|
|
"Z1",
|
|
|
|
"Z2",
|
|
|
|
"Z3",
|
|
|
|
"Z4",
|
|
|
|
"Z5",
|
|
|
|
"Z6",
|
|
|
|
"Z7",
|
|
|
|
"Z8",
|
|
|
|
"Z9"
|
|
|
|
};
|
|
|
|
|
2019-03-02 20:20:23 +01:00
|
|
|
varTableModel::varTableModel(QObject *parent,
|
|
|
|
hpCalcData * dataStore,
|
|
|
|
QString file,
|
|
|
|
hp_DataType dtype)
|
2019-02-10 14:43:00 +01:00
|
|
|
:QAbstractTableModel(parent)
|
2019-02-10 14:32:15 +01:00
|
|
|
{
|
2019-04-02 21:14:31 +02:00
|
|
|
q_parent=parent;
|
2019-03-02 20:20:23 +01:00
|
|
|
hpcalc = dataStore;
|
|
|
|
filename=file;
|
|
|
|
type=dtype;
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
2019-04-02 21:14:31 +02:00
|
|
|
//REWORK!
|
|
|
|
QModelIndex varTableModel::parent(const QModelIndex &index) const {
|
|
|
|
|
|
|
|
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
//rework!
|
|
|
|
QModelIndex varTableModel::index(int row, int column, const QModelIndex &parent) const {
|
|
|
|
|
|
|
|
return createIndex(row,column);
|
|
|
|
}
|
|
|
|
|
2019-03-02 20:20:23 +01:00
|
|
|
void varTableModel::setup()
|
|
|
|
{
|
|
|
|
if (hpcalc) {
|
|
|
|
|
|
|
|
dataobj=hpcalc->getData(filename,type);
|
|
|
|
|
|
|
|
// qDebug()<<"varTableModel: type"<<dataobj->getType();
|
|
|
|
}
|
2019-02-10 14:32:15 +01:00
|
|
|
|
2019-03-02 20:20:23 +01:00
|
|
|
return;
|
2019-02-10 14:32:15 +01:00
|
|
|
}
|
2019-02-10 14:43:00 +01:00
|
|
|
|
2019-04-02 21:14:31 +02:00
|
|
|
int varTableModel::rowCount(const QModelIndex & parent) const
|
2019-02-10 14:43:00 +01:00
|
|
|
{
|
2019-03-02 20:20:23 +01:00
|
|
|
int size=16; //should be zero
|
|
|
|
if (type==HP_LIST) {
|
|
|
|
List * list;
|
|
|
|
list = (List *)dataobj;
|
|
|
|
size= list->getListSize();
|
|
|
|
}
|
2019-03-09 21:11:43 +01:00
|
|
|
if (type==HP_REAL) {
|
|
|
|
Real * real;
|
|
|
|
real = (Real *)dataobj;
|
|
|
|
size= real->getListSize();
|
|
|
|
}
|
2019-03-16 20:34:09 +01:00
|
|
|
if (type==HP_COMPLEX) {
|
|
|
|
Complex * complex;
|
|
|
|
complex = (Complex *)dataobj;
|
|
|
|
size= complex->getListSize();
|
|
|
|
}
|
2019-03-02 20:20:23 +01:00
|
|
|
if (type==HP_MATRIX) {
|
|
|
|
Matrix * matrix;
|
|
|
|
matrix = (Matrix *)dataobj;
|
|
|
|
size= matrix->getMatrixRows();
|
2019-03-09 15:39:38 +01:00
|
|
|
// qDebug()<<matrix->getName()<<" row"<<size;
|
2019-03-02 20:20:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2019-02-10 14:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int varTableModel::columnCount(const QModelIndex & /*parent*/) const
|
|
|
|
{
|
2019-03-02 20:20:23 +01:00
|
|
|
int size=1;
|
|
|
|
if (type==HP_MATRIX) {
|
|
|
|
Matrix * matrix;
|
|
|
|
matrix = (Matrix *)dataobj;
|
|
|
|
size= matrix->getMatrixColumns();
|
2019-03-09 15:39:38 +01:00
|
|
|
// qDebug()<<matrix->getName()<<" column"<<size;
|
|
|
|
|
2019-03-02 20:20:23 +01:00
|
|
|
}
|
2019-03-16 20:34:09 +01:00
|
|
|
if (type==HP_COMPLEX) {
|
|
|
|
Complex * complex;
|
|
|
|
complex = (Complex *)dataobj;
|
|
|
|
// size= matrix->getMatrixColumns();
|
|
|
|
// qDebug()<<matrix->getName()<<" column"<<size;
|
|
|
|
return 1;
|
|
|
|
}
|
2019-03-02 20:20:23 +01:00
|
|
|
return size;
|
2019-02-10 14:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant varTableModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
2019-03-02 20:20:23 +01:00
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
2019-03-09 15:39:38 +01:00
|
|
|
QString item=QStringLiteral("-");
|
2019-03-02 20:20:23 +01:00
|
|
|
|
|
|
|
if (type==HP_LIST) {
|
|
|
|
List * list;
|
|
|
|
list = (List *)dataobj;
|
|
|
|
item = list->getItem(index.row());
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
if (type==HP_MATRIX) {
|
|
|
|
Matrix * matrix;
|
|
|
|
matrix = (Matrix *)dataobj;
|
|
|
|
item = matrix->getItem(index.row(),index.column());
|
|
|
|
return item;
|
|
|
|
}
|
2019-03-09 21:11:43 +01:00
|
|
|
if (type==HP_REAL) {
|
2019-03-16 20:34:09 +01:00
|
|
|
Real * real;
|
|
|
|
real = (Real *)dataobj;
|
|
|
|
item = real->getItem(index.row());
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
if (type==HP_COMPLEX) {
|
|
|
|
Complex * complex;
|
|
|
|
complex = (Complex *)dataobj;
|
|
|
|
item = complex->getItem(index.row());
|
2019-03-09 21:11:43 +01:00
|
|
|
return item;
|
|
|
|
}
|
2019-03-02 20:20:23 +01:00
|
|
|
|
2019-02-10 14:43:00 +01:00
|
|
|
return QString("Row%1, Column%2")
|
|
|
|
.arg(index.row() + 1)
|
|
|
|
.arg(index.column() +1);
|
2019-03-02 20:20:23 +01:00
|
|
|
}
|
2019-02-10 14:43:00 +01:00
|
|
|
return QVariant();
|
|
|
|
}
|
2019-03-16 20:34:09 +01:00
|
|
|
|
|
|
|
QVariant varTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (role != Qt::DisplayRole) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
if (type==HP_REAL) {
|
|
|
|
return QString("%1").arg(section+1);
|
|
|
|
}
|
|
|
|
return QString("%1").arg(section+1);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (orientation == Qt::Vertical) {
|
|
|
|
if (type==HP_REAL) {
|
|
|
|
if (section < real_header.size()) {
|
|
|
|
return real_header.at(section);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return QString("%1").arg(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type==HP_COMPLEX) {
|
|
|
|
if (section < complex_header.size()) {
|
|
|
|
return complex_header.at(section);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return QString("%1").arg(section);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString("%1").arg(section);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
2019-09-15 17:23:44 +02:00
|
|
|
|
|
|
|
varTableModel::~varTableModel() {
|
|
|
|
qDebug()<<"Entering ~varTableModel()";
|
|
|
|
}
|