From 7746d6c283a569846a2aa8deeddd09e5c5927736 Mon Sep 17 00:00:00 2001 From: Indy970 Date: Sat, 2 Mar 2019 21:20:23 +0200 Subject: [PATCH] Lists --- QtHPConnect.pro | 6 +- TODO.md | 18 +- abstractdata.cpp | 362 +++++++++++++++++++++++++++++++++++++- abstractdata.h | 51 +++++- hp_mditexteditor.cpp | 4 - hp_mdivariableedit.cpp | 23 ++- hp_mdivariableedit.h | 17 +- hpdata.cpp | 6 +- hpdata.h | 2 + hptreeitem.cpp | 13 +- hpusb.cpp | 146 +++++++++------ hpusb.h | 2 - libhpcalcs/src/hpcables.c | 4 +- libhpcalcs/src/hpcalcs.c | 2 +- libhpcalcs/src/hpfiles.c | 4 +- libhpcalcs/src/hpopers.c | 4 +- matrixdata.cpp | 118 +++++++++++++ matrixdata.h | 28 +++ vartablemodel.cpp | 64 ++++++- vartablemodel.h | 16 +- 20 files changed, 780 insertions(+), 110 deletions(-) create mode 100644 matrixdata.cpp create mode 100644 matrixdata.h diff --git a/QtHPConnect.pro b/QtHPConnect.pro index 89d4dfd..b61db6e 100644 --- a/QtHPConnect.pro +++ b/QtHPConnect.pro @@ -77,7 +77,8 @@ SOURCES += \ hpusb.cpp \ hp_settingsdlg.cpp \ cntfilesystemmodel.cpp \ - abstractdata.cpp + abstractdata.cpp \ + matrixdata.cpp HEADERS += \ mainwindow.h \ @@ -116,7 +117,8 @@ HEADERS += \ hp_settingsdlg.h \ version.h \ cntfilesystemmodel.h \ - abstractdata.h + abstractdata.h \ + matrixdata.h FORMS += \ mainwindow.ui \ diff --git a/TODO.md b/TODO.md index 34b4198..e1e97f8 100644 --- a/TODO.md +++ b/TODO.md @@ -6,15 +6,21 @@ Content - fix resizing Create storage path if it does not exist Load and read program files - Load Screen shot and display Add options - set default paths + + Drag and drop from content window to calc + 2 Comms - Understand what the calc is doing! - CAN READ ALL DATA! - ------------------ - Tidy hpusb and start decoding + Libusb hot swap - Sections are group by function starting 00 F7 + Async transfer + + CRC checks are not working - this will be a problem on sending data. Worried that a byte is being + gained or lost on transfer + + Decoding data. Lists 90% complete + + Extract vars file 3 Backup to disk diff --git a/abstractdata.cpp b/abstractdata.cpp index abe8fa9..fa057b6 100644 --- a/abstractdata.cpp +++ b/abstractdata.cpp @@ -1,8 +1,126 @@ #include +#include +#include #include "global.h" #include "abstractdata.h" #include "hpusb.h" +#include "matrixdata.h" + +uint16_t crc16_block(const uint8_t * buffer, uint32_t len); + +int BCD2I(quint16 num) { + + int ds,ret; + if(num>0) { + ds=((num&0xF0)>>4)*10; + ds+=(num&0x0F); + ret=ds; + } + else { + ret=0; + } + +// qDebug()<0) { + m=m*0.01+(double)multi*BCD2I(item[k]); + } + } + ret=sign*m*qPow(base,exp); + + value=QString("%1E%2").arg(m).arg(exp); + +// msg=QString("multi:%1 base:%2 sign:%3 exp:%4 m:%5").arg(multi).arg(base).arg(sign).arg(exp).arg(m); + msg=QString("value: %1").arg(value); + + log(msg); + // log(value); + log((QString("Ans: %1").arg(ret))); + qDebug()<dump((uint8_t *)a1.constData(),a1.size()); +} + +//Gets a list item from the list +itemData List::getListItem(int row) { + + itemData null; + + if (rowdump((uint8_t *)a1.constData(),a1.size()); +} + +//Gets a item from the matrix +itemData Matrix::getListItem(int row, int column) { + + itemData data; + data=mdata.at(row,column); + return data; +} + +//Gets a list item in the matrix at position row,column +void Matrix::setListItem(int row, int column, itemData item) { + + mdata.insert(row,column,item); + +} + +//Gets a string representation of the list item in the matrix at position row,column +QString Matrix::getItem(int row, int column) { + + itemData data; + QString item; + + data=mdata.at(row,column); + item=data.sValue; + + return item; +} + +//Passes a string representation of the item in the matrix at position position row,column +void Matrix::setItem(int row, int column, QString string) { + + itemData item; + item.dValue=string.toDouble(); + item.sValue=string; + setListItem(row,column, item); +} + +//Passes a string representation of the list item in the matrix at position row,column +void Matrix::setItem(int row, int column, QString string, double value) { + + itemData item; + item.dValue=value; + item.sValue=string; + setListItem(row,column,item); +} + +//Passes the number of entries in the list +m_Size Matrix::getMatrixSize() { + + m_Size size; + size.row=mdata.rows(); + size.column=mdata.columns(); + + return size; +} + +//Passes the number of entries in the list +int Matrix::getMatrixRows() { + + return mdata.rows(); +} + +//Passes the number of entries in the list +int Matrix::getMatrixColumns() { + + return mdata.columns(); +} + //Program Program::Program(QString name_in, hp_DataType type_in, QString data): AbstractData(name_in, type_in) { @@ -120,23 +433,60 @@ void Program::setProg(QString data_in) { text=data_in; } +void Program::parseData() { + + int16_t len1,len2; + QTextCodec * codec = QTextCodec::codecForName("UTF-16LE"); + + QByteArray a1; + a1=getData(); + text = codec->toUnicode(a1); + } + + //Notes -Notes::Notes(QString name_in, hp_DataType type_in, QString data): +Notes::Notes(QString name_in, hp_DataType type_in, QString data_in): AbstractData(name_in, type_in) { setFileCode(HP_TP_NOTE); - setNote(data); - qDebug()<<"Taking Note"; - qDebug()<> len1; + ds >> len2; +*/ + + formatstart=a1.indexOf("C\x00S\x00W\x0D\x001\x001\x00"); + a3=a1.mid(formatstart,-1); + a1=a1.mid(0,formatstart); + + text = codec->toUnicode(a1); + format = codec->toUnicode(a3); + +} + void Notes::setNote(QString data_in) { text=data_in; } diff --git a/abstractdata.h b/abstractdata.h index f495526..0600d99 100644 --- a/abstractdata.h +++ b/abstractdata.h @@ -4,6 +4,7 @@ #include #include #include "hpusb.h" +#include "matrixdata.h" enum hp_DataType{ HP_MAIN=0, @@ -19,6 +20,11 @@ enum hp_DataType{ HP_SCREEN=10 }; +struct m_Size { + int row; + int column; +}; + class AbstractData { @@ -26,6 +32,8 @@ private: QString name; hp_DataType type; hp_pkt_type file_code; + +protected: QByteArray data; public: @@ -40,54 +48,85 @@ public: hp_pkt_type getFileCode(); void setData(QByteArray); QByteArray getData(); + virtual void parseData(); }; class Application: public AbstractData { +private: + void parseData(); public: Application(QString, hp_DataType); }; -class Real: public AbstractData +class Real: public AbstractData { +private: + void parseData(); public: Real(QString, hp_DataType); }; class Complex: public AbstractData { +private: + void parseData(); public: Complex(QString, hp_DataType); }; -class List: public AbstractData + +class List: public AbstractData { +private: + QList values; + void parseData(); public: List(QString, hp_DataType); + QByteArray getData(); + itemData getListItem(int); + void setListItem(int, itemData); + QString getItem(int); + void setItem(int, QString); + void setItem(int, QString, double); + int getListSize(); }; -class Matrix: public AbstractData +class Matrix: public AbstractData { +private: + MatrixData mdata; + void parseData(); public: Matrix(QString, hp_DataType); + itemData getListItem(int row, int column); + void setListItem(int, int, itemData); + QString getItem(int row, int column); + void setItem(int, int, QString); + void setItem(int, int, QString, double); + m_Size getMatrixSize(); + int getMatrixRows(); + int getMatrixColumns(); }; -class Program: public AbstractData +class Program: public AbstractData { private: QString text; + void parseData(); public: Program(QString, hp_DataType, QString); void setProg(QString); QString getProg(); }; -class Notes: public AbstractData +class Notes: public AbstractData { private: QString text; - + QString format; + void parseData(); public: Notes(QString, hp_DataType, QString); void setNote(QString); diff --git a/hp_mditexteditor.cpp b/hp_mditexteditor.cpp index 321fac0..f90d6c2 100644 --- a/hp_mditexteditor.cpp +++ b/hp_mditexteditor.cpp @@ -27,16 +27,12 @@ void hp_mdiTextEdit::setup() { QString text; textEdit = new textEditor(this); - qDebug()<<"hp_mdiTextEdit::setup"; - if (data) { - qDebug()<<"hp_mdiTextEdit::setup - Data not null"; qDebug()<getName(); qDebug()<getType(); if (data->getType()==HP_NOTE) { - qDebug()<<"hp_mdiTextEdit::setup - Its a Note"; Notes *note; note=(Notes *)data; text=note->getNote(); diff --git a/hp_mdivariableedit.cpp b/hp_mdivariableedit.cpp index 34314b9..850523a 100644 --- a/hp_mdivariableedit.cpp +++ b/hp_mdivariableedit.cpp @@ -2,24 +2,33 @@ #include "hptreeitem.h" -hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent, hpTreeItem * treeItem) +hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent, + hpTreeItem * treeItem, + hpCalcData * dataStore) : QMdiSubWindow(parent) { setMinimumSize(200,200); setMaximumSize(1000,1000); setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); - setup(); + hptreeitem=treeItem; + hpcalc = dataStore; + filename=treeItem->getFileName(); + type=treeItem->getType(); + + setup(); + setWindowTitle(treeItem->getFileName()); } void hp_mdiVariableEdit::setup() { - tableView = new QTableView(this); - varmodel = new varTableModel(this); - tableView->setModel(varmodel); - setWidget(tableView); - + if (hpcalc) { + varmodel = new varTableModel(this,hpcalc,filename,type); + tableView = new QTableView(this); + tableView->setModel(varmodel); + setWidget(tableView); + } } void hp_mdiVariableEdit::show() { diff --git a/hp_mdivariableedit.h b/hp_mdivariableedit.h index 282a9fe..8c02f4c 100644 --- a/hp_mdivariableedit.h +++ b/hp_mdivariableedit.h @@ -6,6 +6,7 @@ #include #include #include "vartablemodel.h" +#include "hpdata.h" class hpTreeItem; @@ -14,13 +15,19 @@ class hp_mdiVariableEdit : public QMdiSubWindow Q_OBJECT protected: - QTableView * tableView; - hpTreeItem * hptreeitem; - varTableModel * varmodel; + QTableView * tableView =nullptr; + hpTreeItem * hptreeitem =nullptr; + varTableModel * varmodel =nullptr; + hpCalcData * hpcalc =nullptr; + QString filename; + hp_DataType type; + void setup(); public: - explicit hp_mdiVariableEdit(QWidget *parent = nullptr, hpTreeItem * treeItem = nullptr); - void setup(); + explicit hp_mdiVariableEdit(QWidget *parent = nullptr, + hpTreeItem * treeItem = nullptr, + hpCalcData * dataStore =nullptr + ); void show(); ~hp_mdiVariableEdit(); diff --git a/hpdata.cpp b/hpdata.cpp index 5e6d16f..2b2fbcc 100644 --- a/hpdata.cpp +++ b/hpdata.cpp @@ -210,6 +210,7 @@ void hpCalcData::recvProg(hp_Prog program) { //qDebug()<setData(program.data); addData(obj); emit emitChange(HP_PROG); @@ -224,6 +225,7 @@ void hpCalcData::recvNote(hp_Note note) { qDebug()<setData(note.data); addData(obj); emit emitChange(HP_NOTE); @@ -238,12 +240,14 @@ void hpCalcData::recvData(hp_Data data) { case HP_APP: { qDebug()<<"hpCalcData::recvData - Application"; Application * obj = new Application(data.name,data.type); + obj->setData(data.data); addData(obj); emit emitChange(HP_APP); } break; case HP_LIST: { List * obj = new List(data.name,data.type); + obj->setData(data.data); addData(obj); emit emitChange(HP_LIST); } @@ -251,12 +255,12 @@ void hpCalcData::recvData(hp_Data data) { case HP_MATRIX: { qDebug()<<"hpCalcData::recvData - Matrix"; Matrix * obj = new Matrix(data.name,data.type); + obj->setData(data.data); addData(obj); emit emitChange(HP_MATRIX); } break; } - } diff --git a/hpdata.h b/hpdata.h index 904b21e..3e5c1a7 100644 --- a/hpdata.h +++ b/hpdata.h @@ -54,11 +54,13 @@ struct hp_Change { struct hp_Prog { QString filename; QString prog; + QByteArray data; }; struct hp_Note { QString filename; QString text; + QByteArray data; }; struct hp_Data { diff --git a/hptreeitem.cpp b/hptreeitem.cpp index 14db1ec..b32529e 100644 --- a/hptreeitem.cpp +++ b/hptreeitem.cpp @@ -117,21 +117,26 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) { hpvaredit ->show(); break; case HP_LIST: - qDebug()<getData(getFileName(),HP_LIST); } if (data) { - hpvaredit = new hp_mdiVariableEdit(mdiwin,this); + hpvaredit = new hp_mdiVariableEdit(mdiwin,this,calc); } } if (hpvaredit!=nullptr) hpvaredit ->show(); break; case HP_MATRIX: - if (hpvaredit==nullptr) - hpvaredit = new hp_mdiVariableEdit(mdiwin,this); + if (hpvaredit==nullptr) { + if (calc) { + data=calc->getData(getFileName(),HP_MATRIX); + } + if (data) { + hpvaredit = new hp_mdiVariableEdit(mdiwin,this,calc); + } + } if (hpvaredit!=nullptr) hpvaredit ->show(); break; diff --git a/hpusb.cpp b/hpusb.cpp index ab7c5a9..01d2291 100644 --- a/hpusb.cpp +++ b/hpusb.cpp @@ -17,7 +17,7 @@ #include #include -static inline uint16_t crc16_block(const uint8_t * buffer, uint32_t len) { +uint16_t crc16_block(const uint8_t * buffer, uint32_t len) { static const uint16_t ccitt_crc16_table[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, @@ -77,7 +77,7 @@ int hpusb::hp_init() if(!(ret=libusb_init(&ctx))) { log("libusb init ok"); - libusb_set_debug(ctx,LIBUSB_LOG_LEVEL_DEBUG); + libusb_set_debug(ctx,LIBUSB_LOG_LEVEL_WARNING); lb_init=1; return ret; } @@ -365,7 +365,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) { uh->pkt_size=Int32; //assume third byte is header length uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE; uh->name_length=0; - uh->embedded_crc = (((uint16_t)(raw[7])) << 8) | ((uint16_t)(raw[8])); + uh->embedded_crc = (((uint16_t)(raw[8] & 0xFF)) << 8) | ((uint16_t)(raw[7] & 0xFF)); uh->headerlen=14; memcpy(uh->header,raw,HEADER_LEN); QString msg = QString("PNG Header chunks: %1 size: %2 Items: %3") @@ -387,14 +387,12 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) { Int32=(Int32<<8)+raw[4]; Int32=(Int32<<8)+raw[5]; Int32=(Int32<<8)+raw[6]; + uh->pkt_size=Int32; //assume third byte is data length uh->pkt_type=raw[7]; //File type being read - uh->pkt_size=Int32; //assume third byte is header length uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE; uh->name_length=0; uh->headerlen=8; - // For whatever reason the CRC seems to be encoded the other way around compared to receiving files uh->embedded_crc = 0; - //(((uint16_t)(raw[7])) << 8) | ((uint16_t)(raw[8])); memcpy(uh->header,raw,HEADER_LEN); QString msg = QString("File Header chunks: %1 size: %2 items: %3") .arg(uh->num_chunks).arg(uh->pkt_size).arg(uh->items); @@ -414,7 +412,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) { Int32=(Int32<<8)+raw[4]; Int32=(Int32<<8)+raw[5]; Int32=(Int32<<8)+raw[6]; - uh->pkt_size=Int32; //assume third byte is header length + uh->pkt_size=Int32; //assume third byte is data length uh->num_chunks=uh->pkt_size/PRIME_RAW_DATA_SIZE; uh->name_length=raw[7]; uh->headerlen=11; @@ -424,8 +422,7 @@ int hpusb::extract_header(uint8_t * raw, usb_header * uh) { .arg(uh->num_chunks).arg(uh->pkt_size).arg(uh->items); qDebug()<usbhandle; - log("Receive..."); + log("hpusb::submit_sync_r_transfer: Receive..."); qDebug()<usbhandle); if (!handle) { @@ -465,17 +462,18 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) { while(exitflag) { trans_c=0; + //read memset(raw,0,PRIME_RAW_DATA_SIZE); if ((ret = libusb_interrupt_transfer(devh,ENDPOINT_IN,raw,PRIME_RAW_DATA_SIZE,&trans_c,TIME_OUT))!=0) { - qDebug()<0) { - qDebug()<=uh1.pkt_size) { - //qDebug()<type) { case HP_HDR_PNG: send_screen_shot(pktin); @@ -598,9 +595,9 @@ int hpusb::send_info(hp_pkt_in * pkt) { qDebug()<<"hpusb:In send info"; if( pkt->calc!=nullptr) { - log("unpacking data"); + log("Unpacking Data"); int ind=0; - QTextCodec * codec = QTextCodec::codecForName("UTF-16 Little Endian"); + QTextCodec * codec = QTextCodec::codecForName("UTF-16LE"); QTextCodec * codec8 = QTextCodec::codecForName("UTF-8"); QByteArray rd= pkt->array; @@ -612,17 +609,36 @@ int hpusb::send_info(hp_pkt_in * pkt) { name = codec->toUnicode(str1); hpinfo.name=name; - //unsigned char searchstr[] = {0x80,0x20,0x80,0x01,0x62}; //ind+=rd.indexOf((char *) searchstr,ind+64); ind +=64; //find Application Version - str1 =rd.mid(ind,10); + //FIX + str1 =rd.mid(ind,12); + + //test + QTime t; + QDataStream ds1(str1); + ds1.setByteOrder(QDataStream::LittleEndian); + ds1>>t; + qDebug()<> listnum[j]; + qDebug()<toUnicode(str1); - hpinfo.appver=app; + hpinfo.appver=QString("v%1").arg(listnum[4]); log(app); //find OS Version @@ -648,7 +664,6 @@ int hpusb::send_info(hp_pkt_in * pkt) { } else { log("Passed a null pointer"); - qDebug()<<"send_info - null calc pointer"; return 1; } //Error @@ -665,7 +680,7 @@ int hpusb::send_screen_shot(hp_pkt_in * pkt) { if( pkt->calc!=nullptr) { endpos = pkt->array.indexOf("IEND"); - qDebug()<<"End pos:"<array.mid(0,endpos+4)); screenShot = new QPixmap(); screenShot->loadFromData(imageData); @@ -680,16 +695,31 @@ int hpusb::send_screen_shot(hp_pkt_in * pkt) { //File Processor int hpusb::send_file(hp_pkt_in * pkt) { - qDebug()<<"hpusb:In File Processor"; + + qDebug()<<"hpusb::send_file: In File Processor"; QString filename; - QTextCodec * codec = QTextCodec::codecForName("UTF-16LE"); QByteArray rd= pkt->array; - int len; + qint8 crc; + len = rd[0]; + //TODO + + //What is byte rd[1],rd[2]? + //Check if CRC + + QByteArray temp((const char *)pkt->array,pkt->array.size()); + temp[1]=0x00; + temp[2]=0x00; + crc=crc16_block((uint8_t *)temp.constData(),temp.size()); +// crc= qChecksum(pkt.array,pkt.array.size()); +// crc=crc16_block((uint8_t *)pkt.array.constData(),pkt.array.size()); + qDebug()<toUnicode(str1); @@ -697,21 +727,27 @@ int hpusb::send_file(hp_pkt_in * pkt) { qDebug()<<"hpusb:Checking file type"; qDebug()<pkt_type); - qDebug()<pkt_type) { - case HP_TP_SETTINGS: + case HP_TP_SETTINGS: { qDebug()<<"hpusb:File type settings"; qDebug()<calc->recvData(sData); } break; @@ -720,7 +756,7 @@ int hpusb::send_file(hp_pkt_in * pkt) { hp_Data sData; sData.type=HP_LIST; sData.name=filename; - sData.data=rd.mid(len,-1); + sData.data=rd.mid(len+3,-1); pkt->calc->recvData(sData); } break; @@ -729,7 +765,7 @@ int hpusb::send_file(hp_pkt_in * pkt) { hp_Data sData; sData.type=HP_MATRIX; sData.name=filename; - sData.data=rd.mid(len,-1); + sData.data=rd.mid(len+3,-1); pkt->calc->recvData(sData); } break; @@ -742,8 +778,9 @@ int hpusb::send_file(hp_pkt_in * pkt) { qDebug()<toUnicode(str1); + note.data=str1; pkt->calc->recvNote(note); } break; @@ -756,7 +793,8 @@ int hpusb::send_file(hp_pkt_in * pkt) { qDebug()<toUnicode(str1); pkt->calc->recvProg(prog); } diff --git a/hpusb.h b/hpusb.h index ce96f43..b2ef582 100644 --- a/hpusb.h +++ b/hpusb.h @@ -141,10 +141,8 @@ struct hp_Information; class hpusb { - private: - struct timespec t1, t2; enum { diff --git a/libhpcalcs/src/hpcables.c b/libhpcalcs/src/hpcables.c index 33a8df3..d01727e 100644 --- a/libhpcalcs/src/hpcables.c +++ b/libhpcalcs/src/hpcables.c @@ -2,7 +2,7 @@ * libhpcables: hand-helds support libraries. * Copyright (C) 2013 Lionel Debroux * Code patterns and snippets borrowed from libticables & libticalcs: - * Copyright (C) 1999-2009 Romain Liévin + * Copyright (C) 1999-2009 Romain Liévin * Copyright (C) 2009-2013 Lionel Debroux * Copyright (C) 1999-2013 libti* contributors. * @@ -144,7 +144,7 @@ HPEXPORT int HPCALL hpcables_exit(void) { HPEXPORT const char* HPCALL hpcables_version_get (void) { - return VERSION; + return "Test"; } diff --git a/libhpcalcs/src/hpcalcs.c b/libhpcalcs/src/hpcalcs.c index e3519e8..34f8cfc 100644 --- a/libhpcalcs/src/hpcalcs.c +++ b/libhpcalcs/src/hpcalcs.c @@ -128,7 +128,7 @@ HPEXPORT int HPCALL hpcalcs_exit(void) { HPEXPORT const char* HPCALL hpcalcs_version_get (void) { - return VERSION; + return "Test"; } diff --git a/libhpcalcs/src/hpfiles.c b/libhpcalcs/src/hpfiles.c index 7198a4e..6208efa 100644 --- a/libhpcalcs/src/hpfiles.c +++ b/libhpcalcs/src/hpfiles.c @@ -2,7 +2,7 @@ * libhpfiles: hand-helds support libraries. * Copyright (C) 2013 Lionel Debroux * Code patterns and snippets borrowed from libticables & libticalcs: - * Copyright (C) 1999-2009 Romain Liévin + * Copyright (C) 1999-2009 Romain Liévin * Copyright (C) 2009-2013 Lionel Debroux * Copyright (C) 1999-2013 libti* contributors. * @@ -149,7 +149,7 @@ HPEXPORT int HPCALL hpfiles_exit(void) { HPEXPORT const char* HPCALL hpfiles_version_get (void) { - return VERSION; + return "TEST"; } diff --git a/libhpcalcs/src/hpopers.c b/libhpcalcs/src/hpopers.c index 19d2fd2..c7fc664 100644 --- a/libhpcalcs/src/hpopers.c +++ b/libhpcalcs/src/hpopers.c @@ -2,7 +2,7 @@ * libhpopers: hand-helds support libraries. * Copyright (C) 2013 Lionel Debroux * Code patterns and snippets borrowed from libticables & libticalcs: - * Copyright (C) 1999-2009 Romain Liévin + * Copyright (C) 1999-2009 Romain Liévin * Copyright (C) 2009-2013 Lionel Debroux * Copyright (C) 1999-2013 libti* contributors. * @@ -121,6 +121,6 @@ HPEXPORT int HPCALL hpopers_exit(void) { HPEXPORT const char* HPCALL hpopers_version_get (void) { - return VERSION; + return "VERSION"; } diff --git a/matrixdata.cpp b/matrixdata.cpp new file mode 100644 index 0000000..c70bc1e --- /dev/null +++ b/matrixdata.cpp @@ -0,0 +1,118 @@ +#include "matrixdata.h" + +MatrixData::MatrixData() +{ + clear(); +} + +//Return the item or a zero item +itemData MatrixData::at(int row, int column) +{ + QList * rowlist; + itemData item; + + if (matrix.size()size()) { + item=rowlist->at(column); + } + } + } + return item; +} + +//Insert a new item and resize the list if larger +void MatrixData::insert(int row, int column, itemData data) +{ + QList * rowlist; + + if (matrix.size()size()) { + rowlist->insert(column,data); + } + else { + resize(); + } + } + else { + QList * newrow = new QList; + newrow->insert(column,data); + matrix.insert(row,newrow); + resize(); + } +} + +//get all columns to same size by padding it zero items +void MatrixData::resize() { + + QList * row; + int rows; + int maxrows; + int columns; + int maxcolumns; + int i; + int j; + itemData item; + rows = matrix.size(); + + for(i=0;isize(); + if (maxcolumnssize(); + if (columnsinsert(j,item); + } + } + } +} + +void MatrixData::clear() +{ + int i; + int r; + QList * row; + + r=rows(); + + for(i=0; iclear(); + delete row; + } + } + matrix.clear(); +} + +int MatrixData::columns() +{ + QList * row; + + if (matrix.size()>0) { + row=matrix.at(0); + if (row) { + return row->size(); + } + } + return 0; +} + +int MatrixData::rows() +{ + matrix.size(); +} + +MatrixData::~MatrixData() +{ + clear(); +} +\ diff --git a/matrixdata.h b/matrixdata.h new file mode 100644 index 0000000..61f5e03 --- /dev/null +++ b/matrixdata.h @@ -0,0 +1,28 @@ +#ifndef MATRIXDATA_H +#define MATRIXDATA_H + +#include + +struct itemData { + double dValue=0.0; + QString sValue=QStringLiteral("NaH"); +}; + + +class MatrixData +{ +private: + QList*> matrix; + +public: + MatrixData(); + itemData at(int,int); + void insert(int,int,itemData); + void clear(); + int rows(); + int columns(); + void resize(); + ~ MatrixData(); +}; + +#endif // MATRIXDATA_H diff --git a/vartablemodel.cpp b/vartablemodel.cpp index c7562ae..7233a9c 100644 --- a/vartablemodel.cpp +++ b/vartablemodel.cpp @@ -1,27 +1,81 @@ +#include "global.h" #include "vartablemodel.h" +#include "abstractdata.h" -varTableModel::varTableModel(QObject *parent) +varTableModel::varTableModel(QObject *parent, + hpCalcData * dataStore, + QString file, + hp_DataType dtype) :QAbstractTableModel(parent) { + hpcalc = dataStore; + filename=file; + type=dtype; + setup(); +} +void varTableModel::setup() +{ + if (hpcalc) { + + dataobj=hpcalc->getData(filename,type); + + // qDebug()<<"varTableModel: type"<getType(); + } + + return; } int varTableModel::rowCount(const QModelIndex & /*parent*/) const { - return 16; + 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; } int varTableModel::columnCount(const QModelIndex & /*parent*/) const { - return 1; + int size=1; + if (type==HP_MATRIX) { + Matrix * matrix; + matrix = (Matrix *)dataobj; + size= matrix->getMatrixColumns(); + } + return size; } QVariant varTableModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) + 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; + } + return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); - + } return QVariant(); } diff --git a/vartablemodel.h b/vartablemodel.h index bc33386..c8abfc7 100644 --- a/vartablemodel.h +++ b/vartablemodel.h @@ -3,12 +3,26 @@ #include +#include "hpdata.h" +#include "abstractdata.h" + class varTableModel: public QAbstractTableModel { Q_OBJECT +private: + hpCalcData * hpcalc =nullptr; + QString filename; + hp_DataType type; + AbstractData * dataobj =nullptr; + QList> dataarray; + void setup(); + public: - varTableModel(QObject *parent = nullptr); + varTableModel(QObject *parent = nullptr, + hpCalcData * dataStore =nullptr, + QString file = QStringLiteral(""), + hp_DataType dtype = HP_MAIN); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;