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-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-03-02 20:20:23 +01:00
|
|
|
hpcalc = dataStore;
|
|
|
|
filename=file;
|
|
|
|
type=dtype;
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
int varTableModel::rowCount(const QModelIndex & /*parent*/) const
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
if (type==HP_MATRIX) {
|
|
|
|
Matrix * matrix;
|
|
|
|
matrix = (Matrix *)dataobj;
|
|
|
|
size= matrix->getMatrixRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
|
|
|
|
QString item;
|
|
|
|
|
|
|
|
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-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();
|
|
|
|
}
|