mirror of
https://github.com/Indy970/QtHPConnect
synced 2024-12-25 21:59:15 +01:00
update
This commit is contained in:
parent
848d8af1af
commit
5bfd57be11
14 changed files with 360 additions and 140 deletions
|
@ -22,9 +22,9 @@
|
|||
#include <QByteArray>
|
||||
|
||||
#include "global.h"
|
||||
#include "abstractdata.h"
|
||||
#include "hpusb.h"
|
||||
#include "matrixdata.h"
|
||||
#include "abstractdata.h"
|
||||
|
||||
uint16_t crc16_block(const uint8_t * buffer, uint32_t len);
|
||||
|
||||
|
@ -40,7 +40,7 @@ int BCD2I(quint8 num) {
|
|||
ret=0;
|
||||
}
|
||||
|
||||
log(QString("Num= %1 Ret= %2").arg(num,1,16).arg(ret));
|
||||
errlog(QString("Num= %1 Ret= %2").arg(num,1,16).arg(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ qint32 TwosComplement2Int(quint32 rawValue)
|
|||
|
||||
qint32 ret;
|
||||
|
||||
log(QString("2C: %1").arg(rawValue& 0x80000000,1,16));
|
||||
errlog(QString("2C: %1").arg(rawValue& 0x80000000,1,16));
|
||||
|
||||
// If a positive value, return it
|
||||
if ((rawValue & 0x80000000) == 0)
|
||||
|
@ -58,12 +58,12 @@ qint32 TwosComplement2Int(quint32 rawValue)
|
|||
}
|
||||
else {
|
||||
// Otherwise perform the 2's complement math on the value
|
||||
log(QString("List 2C Negative Detected"));
|
||||
errlog(QString("List 2C Negative Detected"));
|
||||
|
||||
ret = static_cast<qint32>(~(rawValue - 0x01)) * - 1;
|
||||
// ret = ~rawValue;
|
||||
}
|
||||
log(QString("2C: %1 %2").arg(rawValue,1,16).arg(ret,1,16));
|
||||
errlog(QString("2C: %1 %2").arg(rawValue,1,16).arg(ret,1,16));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ itemData extract16(QByteArray item) {
|
|||
|
||||
exp=((((((((static_cast<qint8>(item[7])&0xFF)<<8)+(static_cast<qint8>(item[6])&0xFF))<<8)+(static_cast<qint8>(item[5])&0xFF)))<<8)
|
||||
+(static_cast<qint8>(item[4])&0xFF));
|
||||
log(QString("extract16: exp %1").arg(exp));
|
||||
errlog(QString("extract16: exp %1").arg(exp));
|
||||
// exp=TwosComplement2Int(exp);
|
||||
|
||||
m=0;
|
||||
|
@ -166,8 +166,8 @@ itemData extract16(QByteArray item) {
|
|||
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((QString("Ans: %1").arg(ret)));
|
||||
errlog(msg);
|
||||
errlog((QString("Ans: %1").arg(ret)));
|
||||
|
||||
listvalue.dReal=ret;
|
||||
listvalue.sValue=value;
|
||||
|
@ -371,10 +371,10 @@ void Real::parseData() {
|
|||
itemData listvalue;
|
||||
|
||||
QString name;
|
||||
log("Real: Parsing Vars");
|
||||
errlog("Real: Parsing Vars");
|
||||
|
||||
name=getName();
|
||||
log(name);
|
||||
errlog(name);
|
||||
a1.clear();
|
||||
a1=getData();
|
||||
|
||||
|
@ -387,7 +387,7 @@ void Real::parseData() {
|
|||
else
|
||||
len=0;
|
||||
|
||||
log(QString("Real: %1 %2 %3").arg(ind,0,10)
|
||||
errlog(QString("Real: %1 %2 %3").arg(ind,0,10)
|
||||
.arg(searchstr.size())
|
||||
.arg(len,2,10));
|
||||
// ind=a1.indexOf(searchstr,0);
|
||||
|
@ -423,7 +423,7 @@ void Real::parseData() {
|
|||
|
||||
setListItem(getListSize(),listvalue);
|
||||
}
|
||||
// log("Real Dump");
|
||||
// errlog("Real Dump");
|
||||
// main_err->dump((uint8_t *)a1.constData(),a1.size());
|
||||
}
|
||||
|
||||
|
@ -498,10 +498,10 @@ void Complex::parseData() {
|
|||
itemData value2;
|
||||
itemData listvalue;
|
||||
QString name;
|
||||
log("Complex: Parsing Vars");
|
||||
errlog("Complex: Parsing Vars");
|
||||
|
||||
name=getName();
|
||||
log(name);
|
||||
errlog(name);
|
||||
a1.clear();
|
||||
a1=getData();
|
||||
|
||||
|
@ -512,7 +512,7 @@ void Complex::parseData() {
|
|||
else
|
||||
len=0;
|
||||
|
||||
log(QString("Real: %1 %2 %3").arg(ind,0,10)
|
||||
errlog(QString("Real: %1 %2 %3").arg(ind,0,10)
|
||||
.arg(searchstr.size())
|
||||
.arg(len,2,10));
|
||||
// ind=a1.indexOf(searchstr,0);
|
||||
|
@ -678,14 +678,19 @@ itemData List::getListItem(int row) {
|
|||
void List::setListItem(int row, itemData item) {
|
||||
|
||||
//May need to pad for missing items
|
||||
|
||||
values.insert(row,item);
|
||||
|
||||
}
|
||||
|
||||
//Gets a string representation of the list item in the list at position row
|
||||
QString List::getItem(int row) {
|
||||
|
||||
if (row<values.size()) {
|
||||
return QString("%1").arg(values.at(row).dReal);
|
||||
}
|
||||
return QString("");
|
||||
}
|
||||
|
||||
//Passes a string representation of the list item in the list at position row
|
||||
void List::setItem(int row, QString string) {
|
||||
|
@ -762,31 +767,31 @@ void Matrix::parseData() {
|
|||
qDebug()<<"Matrix: Parsing a Matrix";
|
||||
|
||||
name=getName();
|
||||
log(name);
|
||||
errlog(name);
|
||||
a1=data;
|
||||
// ind=a1.indexOf(searchstr,0);
|
||||
ind=0;
|
||||
vtype=a1[ind+2];
|
||||
|
||||
log(QString("vtype=%1").arg(vtype,1,16));
|
||||
errlog(QString("vtype=%1").arg(vtype,1,16));
|
||||
if ((vtype&0x7F)==0x14) {
|
||||
log("matrix found");
|
||||
errlog("matrix found");
|
||||
flag =1;
|
||||
}
|
||||
log(QString("vtype=%1").arg(vtype&0x7F,1,16));
|
||||
errlog(QString("vtype=%1").arg(vtype&0x7F,1,16));
|
||||
if ((vtype&0x80)==0x80) {
|
||||
log("complex found");
|
||||
errlog("complex found");
|
||||
flag =2;
|
||||
}
|
||||
log(QString("vtype=%1").arg(vtype&0x80,1,16));
|
||||
errlog(QString("vtype=%1").arg(vtype&0x80,1,16));
|
||||
|
||||
//look for 00 14
|
||||
log(QString("Found string at %1").arg(ind));
|
||||
errlog(QString("Found string at %1").arg(ind));
|
||||
|
||||
mcolumns=a1[ind+12];
|
||||
mrows=a1[ind+8];
|
||||
qDebug()<<QString("Matrix: Row %1 Column %2").arg(mrows).arg(mcolumns);
|
||||
log(QString("Matrix: Row %1 Column %2").arg(mrows).arg(mcolumns));
|
||||
errlog(QString("Matrix: Row %1 Column %2").arg(mrows).arg(mcolumns));
|
||||
|
||||
start=ind+16;
|
||||
for(j=0;j<mrows;j++) {
|
||||
|
@ -845,10 +850,7 @@ QString Matrix::getItem(int row, int column) {
|
|||
//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.dReal=string.toDouble();
|
||||
item.sValue=string;
|
||||
setListItem(row,column, item);
|
||||
setItem(row,column,string,string.toDouble());
|
||||
}
|
||||
|
||||
//Passes a string representation of the list item in the matrix at position row,column
|
||||
|
@ -951,14 +953,14 @@ void Program::parseData(QDataStream& in) {
|
|||
phrase=a1.mid(ind,16*3);
|
||||
//add array to catch variable list
|
||||
str=codec->toUnicode(phrase);
|
||||
log(QString("TD...%1 %2").arg(pos,0,16).arg(ind));
|
||||
errlog(QString("TD...%1 %2").arg(pos,0,16).arg(ind));
|
||||
main_err->dump((uint8_t *)phrase.data(),3*16);
|
||||
log(str);
|
||||
errlog(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
log("Data is not a program file");
|
||||
errlog("Data is not a program file");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1086,11 +1088,11 @@ void Settings::setData(QByteArray datain) {
|
|||
|
||||
int len1=data.size();
|
||||
int len2=datain.size();
|
||||
log(QString("Settings Compare %1 %2").arg(len1).arg(len2));
|
||||
errlog(QString("Settings Compare %1 %2").arg(len1).arg(len2));
|
||||
int i=0;
|
||||
while ((i<len1)&&(i<len2)) {
|
||||
if (data[i]!=datain[i]) {
|
||||
log(QString("Settings diff at:%1").arg(i));
|
||||
errlog(QString("Settings diff at:%1").arg(i));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -1098,7 +1100,7 @@ void Settings::setData(QByteArray datain) {
|
|||
data = datain;
|
||||
len1=data.size();
|
||||
len2=datain.size();
|
||||
log(QString("Settings Compare 2 %1 %2").arg(len1).arg(len2));
|
||||
errlog(QString("Settings Compare 2 %1 %2").arg(len1).arg(len2));
|
||||
|
||||
//parseData();
|
||||
}
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QMessageBox>
|
||||
#include "hp_mdivariableedit.h"
|
||||
#include "hptreeitem.h"
|
||||
|
||||
|
||||
|
||||
hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent,
|
||||
hpTreeItem * treeItem,
|
||||
hpCalcData * dataStore)
|
||||
|
@ -85,7 +87,25 @@ void hp_mdiVariableEdit::setup() {
|
|||
varmodel = new varTableModel(this,data,filename,type);
|
||||
tableView = new QTableView(this);
|
||||
tableView->setModel(varmodel);
|
||||
setWidget(tableView);
|
||||
|
||||
QIcon save(":/icons/save_22x22.png");
|
||||
QAction * actionSave= new QAction(save,"Save",this);
|
||||
QWidget * top = new QWidget();
|
||||
QBoxLayout * layout = new QVBoxLayout();
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
top->setLayout(layout);
|
||||
QToolBar * toolbar = new QToolBar("Save");
|
||||
toolbar->addAction(actionSave);
|
||||
|
||||
QToolButton *saveButton=new QToolButton();
|
||||
QMenu * menu = new QMenu(saveButton);
|
||||
menu->addAction(actionSave);
|
||||
layout->setMenuBar(menu);
|
||||
layout->addWidget(tableView);
|
||||
setWidget(top);
|
||||
|
||||
connect(actionSave,SIGNAL(triggered()),this,SLOT(eventSave()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +118,66 @@ void hp_mdiVariableEdit::show() {
|
|||
hp_MdiWindow::show();
|
||||
}
|
||||
|
||||
void hp_mdiVariableEdit::eventSave(){
|
||||
save();
|
||||
}
|
||||
|
||||
bool hp_mdiVariableEdit::save(){
|
||||
|
||||
// if(content)
|
||||
// return textEdit->save(file);
|
||||
// else {
|
||||
// return textEdit->save(calculator);
|
||||
// }
|
||||
}
|
||||
|
||||
bool hp_mdiVariableEdit::saveAs(){
|
||||
|
||||
// if(content)
|
||||
// return textEdit->saveAs(file);
|
||||
// else {
|
||||
// return textEdit->saveAs(calculator);
|
||||
// }
|
||||
}
|
||||
|
||||
bool hp_mdiVariableEdit::maybeSave()
|
||||
{
|
||||
/*
|
||||
if (!textEdit->document()->isModified())
|
||||
return true;
|
||||
|
||||
const QMessageBox::StandardButton ret
|
||||
= QMessageBox::warning(this, tr("MDI"),
|
||||
tr("'%1' has been modified.\n"
|
||||
"Do you want to save your changes?")
|
||||
.arg(file.fileName()),
|
||||
QMessageBox::Save | QMessageBox::Discard
|
||||
| QMessageBox::Cancel);
|
||||
switch (ret) {
|
||||
case QMessageBox::Save:
|
||||
return textEdit->save(file);
|
||||
case QMessageBox::Cancel:
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void hp_mdiVariableEdit::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
|
||||
if (maybeSave()) {
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
hp_mdiVariableEdit::~hp_mdiVariableEdit() {
|
||||
|
||||
qDebug()<<"Entering ~hpmdiVariableEdit()";
|
||||
|
|
22
hpdata.cpp
22
hpdata.cpp
|
@ -162,7 +162,7 @@ void hpCalcData::readSettings() {
|
|||
hp_Handle * handle;
|
||||
hp_Settings hpset;
|
||||
|
||||
log("hpCalcData::readSettings: -Reading Settings");
|
||||
errlog("hpCalcData::readSettings: -Reading Settings");
|
||||
qDebug()<<"Reading Settings";
|
||||
api=getAPI();
|
||||
handle=getHandle();
|
||||
|
@ -175,11 +175,11 @@ void hpCalcData::readSettings() {
|
|||
}
|
||||
}
|
||||
else {
|
||||
log("hpCalcData::readSettings Handle null");
|
||||
errlog("hpCalcData::readSettings Handle null");
|
||||
}
|
||||
}
|
||||
else {
|
||||
log("hpCalcData::readSettings API null");
|
||||
errlog("hpCalcData::readSettings API null");
|
||||
}
|
||||
// hp_homesettings=hpset;
|
||||
|
||||
|
@ -195,7 +195,7 @@ void hpCalcData::readScreen() {
|
|||
hp_Handle * handle;
|
||||
hp_Settings hpset;
|
||||
|
||||
log("Reading Screen");
|
||||
errlog("Reading Screen");
|
||||
|
||||
api=getAPI();
|
||||
handle=getHandle();
|
||||
|
@ -222,7 +222,7 @@ void hpCalcData::readScreen() {
|
|||
//recieve Screenshot
|
||||
void hpCalcData::recvScreen(hp_ScreenShot shot) {
|
||||
|
||||
log("Recieving Screen");
|
||||
errlog("Recieving Screen");
|
||||
|
||||
QByteArray imageData;
|
||||
if (screenShot!=nullptr) {
|
||||
|
@ -237,7 +237,7 @@ void hpCalcData::recvScreen(hp_ScreenShot shot) {
|
|||
void hpCalcData::recvSettings(hp_Data data) {
|
||||
|
||||
QString filename;
|
||||
log("hpCalcData::recvSettings: Recieving Setting");
|
||||
errlog("hpCalcData::recvSettings: Recieving Setting");
|
||||
filename = data.name;
|
||||
qDebug()<<filename;
|
||||
|
||||
|
@ -245,14 +245,14 @@ void hpCalcData::recvSettings(hp_Data data) {
|
|||
qDebug()<<"hpCalcData::recvSetting - Setting";
|
||||
|
||||
qDebug()<<"hpCalcData::recvSetting - Real";
|
||||
log("hpCalcData::recvSetting - Real");
|
||||
errlog("hpCalcData::recvSetting - Real");
|
||||
Real * obj1 = new Real(data.name,HP_REAL);
|
||||
obj1->setData(data.data);
|
||||
addData(obj1);
|
||||
emit emitChange(HP_REAL);
|
||||
|
||||
qDebug()<<"hpCalcData::recvSetting - Complex";
|
||||
log("hpCalcData::recvSetting - Complex");
|
||||
errlog("hpCalcData::recvSetting - Complex");
|
||||
Complex * obj2 = new Complex(data.name,HP_COMPLEX);
|
||||
obj2->setData(data.data);
|
||||
addData(obj2);
|
||||
|
@ -294,7 +294,7 @@ void hpCalcData::recvSettings(hp_Data data) {
|
|||
//recieve Program
|
||||
void hpCalcData::recvProg(hp_Prog program) {
|
||||
|
||||
log("Recieving Program");
|
||||
errlog("Recieving Program");
|
||||
qDebug()<<"hpCalcData::recvProg";
|
||||
|
||||
qDebug()<<program.filename;
|
||||
|
@ -310,7 +310,7 @@ void hpCalcData::recvProg(hp_Prog program) {
|
|||
//recieve Program
|
||||
void hpCalcData::recvNote(hp_Note note) {
|
||||
|
||||
log("Recieving Note");
|
||||
errlog("Recieving Note");
|
||||
qDebug()<<"hpCalcData::recvNote";
|
||||
|
||||
qDebug()<<note.filename;
|
||||
|
@ -325,7 +325,7 @@ void hpCalcData::recvNote(hp_Note note) {
|
|||
//recieve Program
|
||||
void hpCalcData::recvData(hp_Data data) {
|
||||
|
||||
log("Recieving Data");
|
||||
errlog("Recieving Data");
|
||||
|
||||
switch (data.type) {
|
||||
case HP_APP: {
|
||||
|
|
98
hpusb.cpp
98
hpusb.cpp
|
@ -89,10 +89,10 @@ int hpusb::hp_init()
|
|||
int rc;
|
||||
|
||||
if(!lb_init) {
|
||||
log("Initialising usb interface");
|
||||
errlog("Initialising usb interface");
|
||||
|
||||
if(!(ret=libusb_init(&ctx))) {
|
||||
log("libusb init ok");
|
||||
errlog("libusb init ok");
|
||||
libusb_set_debug(ctx,LIBUSB_LOG_LEVEL_WARNING);
|
||||
|
||||
rc = libusb_hotplug_register_callback(ctx, (libusb_hotplug_event) (LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
|
||||
|
@ -101,11 +101,11 @@ int hpusb::hp_init()
|
|||
&callback_handle);
|
||||
|
||||
if (LIBUSB_SUCCESS != rc) {
|
||||
log("Error creating a hotplug callback\n");
|
||||
errlog("Error creating a hotplug callback\n");
|
||||
libusb_exit(ctx);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
log("hpusb::hp_init - hotplug registered\n");
|
||||
errlog("hpusb::hp_init - hotplug registered\n");
|
||||
hp_callback_handle=callback_handle;
|
||||
lb_init=1;
|
||||
return ret;
|
||||
|
@ -139,7 +139,7 @@ int hpusb::hp_open(hp_Handle * handle) {
|
|||
libusb_device *device = list[i];
|
||||
if (is_device(device)) {
|
||||
found = device;
|
||||
log("Device found");
|
||||
errlog("Device found");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -161,22 +161,22 @@ int hpusb::hp_open(hp_Handle * handle) {
|
|||
err(L3,0,"handle null");
|
||||
}
|
||||
|
||||
log("Device opened");
|
||||
errlog("Device opened");
|
||||
|
||||
//claim interface
|
||||
ret = libusb_kernel_driver_active ( handle->usbhandle, 0x0) ;
|
||||
if (ret==1) {
|
||||
log(QString().sprintf("Keneral active"));
|
||||
errlog(QString().sprintf("Keneral active"));
|
||||
ret = libusb_detach_kernel_driver( handle->usbhandle, 0x0) ;
|
||||
log(QString().sprintf("Keneral detach: %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Keneral detach: %s\n", libusb_error_name(ret)));
|
||||
if (ret!=0) {
|
||||
log(QString().sprintf("Keneral detach error: %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Keneral detach error: %s\n", libusb_error_name(ret)));
|
||||
goto endfunc;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (ret!=0) {
|
||||
log(QString().sprintf("Kernal error %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Kernal error %s\n", libusb_error_name(ret)));
|
||||
goto endfunc;
|
||||
}
|
||||
|
||||
|
@ -185,14 +185,14 @@ int hpusb::hp_open(hp_Handle * handle) {
|
|||
//
|
||||
// ret=libusb_set_configuration(handle->usbhandle,0x1);
|
||||
// if (ret!=0) {
|
||||
// log(QString().sprintf("Set Configuration: %s\n", libusb_error_name(ret)));
|
||||
// errlog(QString().sprintf("Set Configuration: %s\n", libusb_error_name(ret)));
|
||||
// goto endfunc;
|
||||
// }
|
||||
handle->dev_open=1;
|
||||
|
||||
ret = libusb_claim_interface(handle->usbhandle, 0x0);
|
||||
if (ret!=0) {
|
||||
log(QString().sprintf("Claim interface Error: %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Claim interface Error: %s\n", libusb_error_name(ret)));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ int hpusb::is_device(libusb_device * device) {
|
|||
err(L3,rc,QString(__FUNCTION__) + QString(" Could not get device descriptor "));
|
||||
}
|
||||
else {
|
||||
// log(QString().sprintf("Vendor:Device = %04x:%04x", desc.idVendor, desc.idProduct));
|
||||
// errlog(QString().sprintf("Vendor:Device = %04x:%04x", desc.idVendor, desc.idProduct));
|
||||
if ((desc.idVendor==USB_VID_HP)&&(desc.idProduct==USB_PID_PRIME3)) {
|
||||
dumpDevice(device);
|
||||
return 1;
|
||||
|
@ -251,7 +251,7 @@ void hpusb::dumpDevice(libusb_device * device) {
|
|||
dump+=QString().sprintf("bNumConfigurations: %d\n",desc.bNumConfigurations);
|
||||
}
|
||||
}
|
||||
log(dump);
|
||||
errlog(dump);
|
||||
qDebug()<<dump;
|
||||
}
|
||||
|
||||
|
@ -291,20 +291,20 @@ int hpusb::submit_sync_s_transfer(hp_Handle * handle, hp_pkt_out * pktout) {
|
|||
offset += PRIME_RAW_DATA_SIZE - 1;
|
||||
}
|
||||
|
||||
log("In sync send transfer");
|
||||
errlog("In sync send transfer");
|
||||
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
|
||||
|
||||
//write
|
||||
log("Send..");
|
||||
errlog("Send..");
|
||||
ret = libusb_interrupt_transfer(devh, ENDPOINT_OUT, raw.data, raw.size,
|
||||
&trans,10000);
|
||||
if (ret) {
|
||||
log(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
|
||||
r = 0;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
log(QString().sprintf("Write bytes: %d\n", trans));
|
||||
errlog(QString().sprintf("Write bytes: %d\n", trans));
|
||||
}
|
||||
// Increment packet ID, which seems to be necessary for computer -> calc packets
|
||||
pkt_id++;
|
||||
|
@ -325,16 +325,16 @@ int hpusb::submit_sync_s_transfer(hp_Handle * handle, hp_pkt_out * pktout) {
|
|||
raw.size = r;
|
||||
memcpy(raw.data, pktout->data + offset, PRIME_RAW_DATA_SIZE-1);
|
||||
}
|
||||
log("Send small packet..");
|
||||
errlog("Send small packet..");
|
||||
|
||||
ret = libusb_interrupt_transfer(devh, ENDPOINT_OUT, raw.data, raw.size,
|
||||
&trans,10000);
|
||||
|
||||
if (ret) {
|
||||
log(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
|
||||
errlog(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
|
||||
}
|
||||
else {
|
||||
log(QString().sprintf("Write bytes: %d\n", trans));
|
||||
errlog(QString().sprintf("Write bytes: %d\n", trans));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,11 +475,11 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
QByteArray in_buffer(PRIME_RAW_DATA_SIZE,0);
|
||||
libusb_device_handle * devh = handle->usbhandle;
|
||||
|
||||
log("hpusb::submit_sync_r_transfer: Receive...");
|
||||
errlog("hpusb::submit_sync_r_transfer: Receive...");
|
||||
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
|
||||
|
||||
if (!handle) {
|
||||
log("Null handle");
|
||||
errlog("Null handle");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
|
|||
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()<<QString("hpusb::submit_sync_r_transfer: Read Error %1").arg(libusb_error_name(ret));
|
||||
log(QString("Read Error: %1\n").arg( libusb_error_name(ret)));
|
||||
errlog(QString("Read Error: %1\n").arg( libusb_error_name(ret)));
|
||||
exitflag=0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
qDebug()<<"hpusb:In send info";
|
||||
if( pkt->calc!=nullptr) {
|
||||
|
||||
log("Unpacking Data");
|
||||
errlog("Unpacking Data");
|
||||
int ind=0;
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
||||
QTextCodec * codec8 = QTextCodec::codecForName("UTF-8");
|
||||
|
@ -668,7 +668,7 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
QString app;
|
||||
app = codec8->toUnicode(str1);
|
||||
hpinfo.appver=QString("v%1").arg(listnum[4]);
|
||||
log(app);
|
||||
errlog(app);
|
||||
|
||||
//find OS Version
|
||||
ind+=12;
|
||||
|
@ -678,7 +678,7 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
osv = codec8->toUnicode(str1);
|
||||
hpinfo.osver=osv;
|
||||
// qDebug()<<osv;
|
||||
log(osv);
|
||||
errlog(osv);
|
||||
|
||||
//find Serial Number
|
||||
ind+=16;
|
||||
|
@ -686,13 +686,13 @@ int hpusb::send_info(hp_pkt_in * pkt) {
|
|||
QString serial;
|
||||
serial = codec8->toUnicode(str1);
|
||||
hpinfo.serialnum=serial;
|
||||
log(serial);
|
||||
errlog(serial);
|
||||
pkt->calc->recvInfo(hpinfo);
|
||||
return 0;
|
||||
|
||||
}
|
||||
else {
|
||||
log("Passed a null pointer");
|
||||
errlog("Passed a null pointer");
|
||||
return 1;
|
||||
}
|
||||
//Error
|
||||
|
@ -752,7 +752,7 @@ int hpusb::send_file(hp_pkt_in * pkt) {
|
|||
//find file name
|
||||
QByteArray str1 =rd.mid(3,len);
|
||||
filename = codec->toUnicode(str1);
|
||||
log(QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type));
|
||||
errlog(QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type));
|
||||
|
||||
qDebug()<<"hpusb:Checking file type";
|
||||
qDebug()<<QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type);
|
||||
|
@ -862,11 +862,11 @@ int hpusb::get_screen_shot(hp_Handle * handle) {
|
|||
|
||||
pktin.cmd= CMD_PRIME_RECV_SCREEN;
|
||||
|
||||
log(QString("%1: Waiting for a reply").arg(__FUNCTION__));
|
||||
errlog(QString("%1: Waiting for a reply").arg(__FUNCTION__));
|
||||
|
||||
if (!submit_sync_r_transfer(handle,&pktin)){
|
||||
|
||||
log(QString("%1: Recieved a reply").arg(__FUNCTION__));
|
||||
errlog(QString("%1: Recieved a reply").arg(__FUNCTION__));
|
||||
//Trying to understand reply
|
||||
/* int endpos;
|
||||
QByteArray rd = pktin.array;
|
||||
|
@ -874,7 +874,7 @@ int hpusb::get_screen_shot(hp_Handle * handle) {
|
|||
qDebug()<<"End pos:"<<endpos;
|
||||
*imageData = QByteArray(rd.mid(14,endpos+4-14));
|
||||
// qDebug()<<*imageData;
|
||||
log(QString().sprintf("%d bytes received",pktin.array.size()));*/
|
||||
errlog(QString().sprintf("%d bytes received",pktin.array.size()));*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,10 +913,10 @@ int hpusb::is_ready(hp_Handle * handle) {
|
|||
pktin.cmd= CMD_PRIME_CHECK_READY;
|
||||
// pktin.data=in_buffer;
|
||||
// pktin.size=1024;
|
||||
log(QString("%1: Waiting for a reply").arg(__FUNCTION__));
|
||||
errlog(QString("%1: Waiting for a reply").arg(__FUNCTION__));
|
||||
|
||||
if (!submit_sync_r_transfer(handle,&pktin)){
|
||||
log(QString("%1: Recieved a reply").arg(__FUNCTION__));
|
||||
errlog(QString("%1: Recieved a reply").arg(__FUNCTION__));
|
||||
//Trying to understand reply
|
||||
qDebug()<<pktin.array;
|
||||
main_err-> dump((uint8_t *)pktin.array.constData(),pktin.array.size());
|
||||
|
@ -925,7 +925,7 @@ int hpusb::is_ready(hp_Handle * handle) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
log(QString("%1: Could not send ready request ").arg(__FUNCTION__));
|
||||
errlog(QString("%1: Could not send ready request ").arg(__FUNCTION__));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -971,7 +971,7 @@ int hpusb::load_info(hp_Handle * handle) {
|
|||
{
|
||||
//recieve response
|
||||
if(submit_sync_r_transfer(handle,&pktin)) {
|
||||
log("failed to read info from device");
|
||||
errlog("failed to read info from device");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -986,7 +986,7 @@ int hpusb::lookfordouble (QByteArray rd, int start) {
|
|||
QByteArray str1;
|
||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16");
|
||||
app = codec->toUnicode(str1);
|
||||
log(app);
|
||||
errlog(app);
|
||||
|
||||
int i,ind;
|
||||
ind=start;
|
||||
|
@ -1160,21 +1160,21 @@ int hpusb::hp_close(hp_Handle * handle)
|
|||
void hpusb::print_libusb_transfer(struct libusb_transfer *p_t)
|
||||
{ int i;
|
||||
if ( NULL == p_t){
|
||||
log("No libusb_transfer...\n");
|
||||
errlog("No libusb_transfer...\n");
|
||||
}
|
||||
else {
|
||||
log("libusb_transfer structure:\n");
|
||||
log(QString().sprintf("flags =%x \n", p_t->flags));
|
||||
log(QString().sprintf("endpoint=%x \n", p_t->endpoint));
|
||||
log(QString().sprintf("type =%x \n", p_t->type));
|
||||
log(QString().sprintf("timeout =%d \n", p_t->timeout));
|
||||
errlog("libusb_transfer structure:\n");
|
||||
errlog(QString().sprintf("flags =%x \n", p_t->flags));
|
||||
errlog(QString().sprintf("endpoint=%x \n", p_t->endpoint));
|
||||
errlog(QString().sprintf("type =%x \n", p_t->type));
|
||||
errlog(QString().sprintf("timeout =%d \n", p_t->timeout));
|
||||
// length, and buffer are commands sent to the device
|
||||
log(QString().sprintf("length =%d \n", p_t->length));
|
||||
log(QString().sprintf("actual_length =%d \n", p_t->actual_length));
|
||||
log(QString().sprintf("buffer =%p \n", p_t->buffer));
|
||||
errlog(QString().sprintf("length =%d \n", p_t->length));
|
||||
errlog(QString().sprintf("actual_length =%d \n", p_t->actual_length));
|
||||
errlog(QString().sprintf("buffer =%p \n", p_t->buffer));
|
||||
|
||||
for (i=0; i < p_t->length; i++){
|
||||
log(QString().sprintf("%d %x", i, p_t->buffer[i]));
|
||||
errlog(QString().sprintf("%d %x", i, p_t->buffer[i]));
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -1380,7 +1380,7 @@ int hpusb::hotplugcallback(struct libusb_context *ctx, struct libusb_device *dev
|
|||
}
|
||||
} else {
|
||||
qDebug()<<QString("hpusb::hotplug_callback Unhandled event %1\n").arg(event);
|
||||
log(QString("hpusb::hotplug_callback Unhandled event %1\n").arg(event));
|
||||
errlog(QString("hpusb::hotplug_callback Unhandled event %1\n").arg(event));
|
||||
}
|
||||
count++;
|
||||
return 0;
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include "hpusb.h"
|
||||
#include "matrixdata.h"
|
||||
|
||||
|
||||
|
||||
struct m_Size {
|
||||
int row;
|
||||
int column;
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ERRORHANDLER_H
|
||||
#define ERRORHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
@ -25,6 +22,9 @@
|
|||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
#ifndef ERRORHANDLER_H
|
||||
#define ERRORHANDLER_H
|
||||
|
||||
enum ErrLevel {
|
||||
L0, //abort
|
||||
L1, //fault
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
class errorHandler;
|
||||
extern errorHandler *main_err;
|
||||
#define log(a) main_err->error(L7,0,QString(a),QString());
|
||||
#define errlog(a) main_err->error(L7,0,QString(a),QString());
|
||||
#define err(a,b,c) main_err->error(a,b,QString(c),QString());
|
||||
|
||||
#endif // GLOBAL_H
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HP_MDIVARIABLEEDIT_H
|
||||
#define HP_MDIVARIABLEEDIT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QTableView>
|
||||
#include <QFileInfo>
|
||||
|
||||
#ifndef HP_MDIVARIABLEEDIT_H
|
||||
#define HP_MDIVARIABLEEDIT_H
|
||||
|
||||
#include "vartablemodel.h"
|
||||
#include "hpdata.h"
|
||||
#include "hp_mdiwindow.h"
|
||||
|
@ -45,6 +45,8 @@ protected:
|
|||
QString calculator;
|
||||
bool content;
|
||||
void setup();
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
|
||||
public:
|
||||
hp_mdiVariableEdit(QWidget *parent = nullptr,
|
||||
|
@ -56,12 +58,15 @@ public:
|
|||
AbstractData * data
|
||||
);
|
||||
void show();
|
||||
~hp_mdiVariableEdit();
|
||||
bool save() override;
|
||||
bool saveAs() override;
|
||||
bool maybeSave();
|
||||
~hp_mdiVariableEdit() override;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void eventSave();
|
||||
};
|
||||
|
||||
#endif // HP_MDIVARIABLEEDIT_H
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
struct itemData {
|
||||
double dReal=0.0;
|
||||
double dImaginary=0.0;
|
||||
QString sValue=QStringLiteral("NaH");
|
||||
QString sValue=QStringLiteral("");
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -15,11 +15,14 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef VARTABLEMODEL_H
|
||||
#define VARTABLEMODEL_H
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QStringList>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
#ifndef VARTABLEMODEL_H
|
||||
#define VARTABLEMODEL_H
|
||||
|
||||
#include "hpdata.h"
|
||||
#include "abstractdata.h"
|
||||
|
@ -28,7 +31,6 @@ class varTableModel: public QAbstractTableModel
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
private:
|
||||
QObject * q_parent;
|
||||
const static QStringList real_header;
|
||||
|
@ -40,18 +42,32 @@ private:
|
|||
QList<QList<double>> dataarray;
|
||||
void setup();
|
||||
|
||||
bool isUntitled;
|
||||
QDir defaultPath;
|
||||
|
||||
|
||||
public:
|
||||
varTableModel(QObject *parent = nullptr,
|
||||
AbstractData * data =nullptr,
|
||||
QString file = QStringLiteral(""),
|
||||
hp_DataType dtype = HP_MAIN);
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &index) const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
|
||||
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;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||
|
||||
bool save(QFileInfo file);
|
||||
bool saveAs(QFileInfo file);
|
||||
bool save(QString calculator);
|
||||
bool saveAs(QString calculator);
|
||||
bool saveFile(const QString &fileName);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
~varTableModel();
|
||||
~varTableModel() override;
|
||||
};
|
||||
|
||||
#endif // VARTABLEMODEL_H
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <QFileIconProvider>
|
||||
#include <QToolButton>
|
||||
|
||||
#include <global.h>
|
||||
//#include <global.h>
|
||||
#include "hpusb.h"
|
||||
#include "datamodel.h"
|
||||
#include "treemodel.h"
|
||||
|
@ -50,7 +50,7 @@
|
|||
#include "eventtimer.h"
|
||||
|
||||
errorHandler *main_err;
|
||||
#define log(a) main_err->error(L7,0,QString(a),QString());
|
||||
#define errlog(a) main_err->error(L7,0,QString(a),QString());
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
@ -154,7 +154,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(eventExit()));
|
||||
|
||||
//default data
|
||||
log("Initialising....");
|
||||
errlog("Initialising....");
|
||||
|
||||
if (hpapi->hp_init())
|
||||
err(L1,0,QString().sprintf("%s Failed to open libusb",__FUNCTION__));
|
||||
|
@ -187,11 +187,11 @@ void MainWindow::testFunction() {
|
|||
if (pH) {
|
||||
|
||||
cmd = QInputDialog::getInt(this,"Get Command","CMD:",0,0,0xFFFF);
|
||||
log("command is "+QString().sprintf("%x",cmd));
|
||||
errlog("command is "+QString().sprintf("%x",cmd));
|
||||
pH->vpkt_send_experiments(cmd);
|
||||
}
|
||||
else
|
||||
log("Could not get calculator");
|
||||
errlog("Could not get calculator");
|
||||
|
||||
}
|
||||
|
||||
|
@ -651,7 +651,7 @@ void MainWindow::monitorAddImage(hp_ScreenShot scrnshot) {
|
|||
}
|
||||
else
|
||||
{
|
||||
log("Could not load image");
|
||||
errlog("Could not load image");
|
||||
}
|
||||
ui->dwMonitor->show();
|
||||
}
|
||||
|
@ -803,7 +803,7 @@ void MainWindow::treeMenuAction(bool clicked) {
|
|||
}
|
||||
else
|
||||
{
|
||||
log(QStringLiteral("treeItem is null"));
|
||||
errlog(QStringLiteral("treeItem is null"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ void MatrixData::addRow(int row)
|
|||
int i;
|
||||
QList<itemData> * rowlist;
|
||||
|
||||
|
||||
// qDebug()<<"MatrixData::addRow" << row;
|
||||
rows=matrix.size();
|
||||
if (rows<=row)
|
||||
|
@ -147,6 +148,8 @@ void MatrixData::upsize(int newrow,int newcol) {
|
|||
qDebug()<<"MatrixData::upsize";
|
||||
|
||||
itemData item;
|
||||
item.sValue=QStringLiteral("0");
|
||||
|
||||
rows = matrix.size();
|
||||
// qDebug()<<"MatrixData::upsize - rows:"<<newrow<<" columns:"<<newcol;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ int treeModel::createRoot()
|
|||
AbstractData * treeModel::createData(hp_Data data_in) {
|
||||
|
||||
AbstractData * obj=nullptr;
|
||||
log("TreeModel::Creating Data Stucture");
|
||||
errlog("TreeModel::Creating Data Stucture");
|
||||
|
||||
switch (data_in.type) {
|
||||
case HP_APP: {
|
||||
|
|
|
@ -19,9 +19,14 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
#include "global.h"
|
||||
#include "vartablemodel.h"
|
||||
#include "abstractdata.h"
|
||||
|
||||
const QStringList varTableModel::real_header={ "A",
|
||||
"B",
|
||||
|
@ -80,16 +85,52 @@ varTableModel::varTableModel(QObject *parent,
|
|||
//REWORK!
|
||||
QModelIndex varTableModel::parent(const QModelIndex &index) const {
|
||||
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
Qt::ItemFlags varTableModel::flags(const QModelIndex &index) const {
|
||||
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
//rework!
|
||||
QModelIndex varTableModel::index(int row, int column, const QModelIndex &parent) const {
|
||||
|
||||
return createIndex(row,column);
|
||||
}
|
||||
|
||||
//alter the data table if data is edited
|
||||
bool varTableModel::setData(const QModelIndex &index, const QVariant &value, int role) {
|
||||
|
||||
qDebug()<<"Data Changed";
|
||||
|
||||
if (type==HP_LIST) {
|
||||
List * list;
|
||||
list = static_cast<List *>(dataobj);
|
||||
list->setItem(index.row(),value.toString(),value.toReal());
|
||||
return true;
|
||||
}
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = static_cast<Matrix *>(dataobj);
|
||||
matrix->setItem(index.row(),index.column(),value.toString(),value.toReal());
|
||||
return true;
|
||||
}
|
||||
if (type==HP_REAL) {
|
||||
Real * real;
|
||||
real = static_cast<Real *>(dataobj);
|
||||
// item = real->getItem(index.row());
|
||||
// return item;
|
||||
}
|
||||
if (type==HP_COMPLEX) {
|
||||
Complex * complex;
|
||||
complex = static_cast<Complex *>(dataobj);
|
||||
// item = complex->getItem(index.row());
|
||||
// return item;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void varTableModel::setup()
|
||||
{
|
||||
|
@ -108,23 +149,23 @@ int varTableModel::rowCount(const QModelIndex & parent) const
|
|||
int size=16; //should be zero
|
||||
if (type==HP_LIST) {
|
||||
List * list;
|
||||
list = (List *)dataobj;
|
||||
size= list->getListSize();
|
||||
list = static_cast<List *>(dataobj);
|
||||
size= list->getListSize()+1;
|
||||
}
|
||||
if (type==HP_REAL) {
|
||||
Real * real;
|
||||
real = (Real *)dataobj;
|
||||
real = static_cast<Real *>(dataobj);
|
||||
size= real->getListSize();
|
||||
}
|
||||
if (type==HP_COMPLEX) {
|
||||
Complex * complex;
|
||||
complex = (Complex *)dataobj;
|
||||
complex = static_cast<Complex *>(dataobj);
|
||||
size= complex->getListSize();
|
||||
}
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
size= matrix->getMatrixRows();
|
||||
matrix = static_cast<Matrix *>(dataobj);
|
||||
size= matrix->getMatrixRows()+1;
|
||||
// qDebug()<<matrix->getName()<<" row"<<size;
|
||||
}
|
||||
|
||||
|
@ -136,14 +177,14 @@ int varTableModel::columnCount(const QModelIndex & /*parent*/) const
|
|||
int size=1;
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
size= matrix->getMatrixColumns();
|
||||
matrix = static_cast<Matrix *>(dataobj);
|
||||
size= matrix->getMatrixColumns()+1;
|
||||
// qDebug()<<matrix->getName()<<" column"<<size;
|
||||
|
||||
}
|
||||
if (type==HP_COMPLEX) {
|
||||
Complex * complex;
|
||||
complex = (Complex *)dataobj;
|
||||
complex = static_cast<Complex *>(dataobj);
|
||||
// size= matrix->getMatrixColumns();
|
||||
// qDebug()<<matrix->getName()<<" column"<<size;
|
||||
return 1;
|
||||
|
@ -151,6 +192,15 @@ int varTableModel::columnCount(const QModelIndex & /*parent*/) const
|
|||
return size;
|
||||
}
|
||||
|
||||
void varTableModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) {
|
||||
|
||||
|
||||
qDebug()<<"Data Changed";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
QVariant varTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole) {
|
||||
|
@ -159,25 +209,25 @@ QVariant varTableModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
if (type==HP_LIST) {
|
||||
List * list;
|
||||
list = (List *)dataobj;
|
||||
list = static_cast<List *>(dataobj);
|
||||
item = list->getItem(index.row());
|
||||
return item;
|
||||
}
|
||||
if (type==HP_MATRIX) {
|
||||
Matrix * matrix;
|
||||
matrix = (Matrix *)dataobj;
|
||||
matrix = static_cast<Matrix *>(dataobj);
|
||||
item = matrix->getItem(index.row(),index.column());
|
||||
return item;
|
||||
}
|
||||
if (type==HP_REAL) {
|
||||
Real * real;
|
||||
real = (Real *)dataobj;
|
||||
real = static_cast<Real *>(dataobj);
|
||||
item = real->getItem(index.row());
|
||||
return item;
|
||||
}
|
||||
if (type==HP_COMPLEX) {
|
||||
Complex * complex;
|
||||
complex = (Complex *)dataobj;
|
||||
complex = static_cast<Complex *>(dataobj);
|
||||
item = complex->getItem(index.row());
|
||||
return item;
|
||||
}
|
||||
|
@ -227,6 +277,72 @@ QVariant varTableModel::headerData(int section, Qt::Orientation orientation, in
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
bool varTableModel::save(QString Calculator)
|
||||
{
|
||||
if (isUntitled) {
|
||||
return saveAs(Calculator);
|
||||
} else {
|
||||
return saveFile("xx");
|
||||
}
|
||||
}
|
||||
|
||||
bool varTableModel::save(QFileInfo file)
|
||||
{
|
||||
if (isUntitled) {
|
||||
return saveAs(file);
|
||||
} else {
|
||||
return saveFile("xx");
|
||||
}
|
||||
}
|
||||
|
||||
bool varTableModel::saveAs(QFileInfo fileinfo)
|
||||
{
|
||||
|
||||
// QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
|
||||
// fileinfo.absoluteFilePath());
|
||||
// if (fileName.isEmpty())
|
||||
// return false;
|
||||
|
||||
//return saveFile(fileName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool varTableModel::saveAs(QString calculaor)
|
||||
{
|
||||
|
||||
// QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
|
||||
// fileinfo.absoluteFilePath());
|
||||
QString fileName="";
|
||||
if (fileName.isEmpty())
|
||||
return false;
|
||||
|
||||
return saveFile(fileName);
|
||||
}
|
||||
|
||||
bool varTableModel::saveFile(const QString &fileName)
|
||||
{
|
||||
QFileInfo fileinfo(defaultPath,fileName);
|
||||
QFile file(fileinfo.absoluteFilePath());
|
||||
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
// QMessageBox::warning(this, tr("MDI"),
|
||||
// tr("Cannot write file %1:\n%2.")
|
||||
// .arg(QDir::toNativeSeparators(fileName), file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
// out << toPlainText();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
// setCurrentFile(fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
varTableModel::~varTableModel() {
|
||||
qDebug()<<"Entering ~varTableModel()";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue