diff --git a/abstractdata.cpp b/abstractdata.cpp index 0ff20a9..ed9fb6b 100644 --- a/abstractdata.cpp +++ b/abstractdata.cpp @@ -22,9 +22,9 @@ #include #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(~(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(item[7])&0xFF)<<8)+(static_cast(item[6])&0xFF))<<8)+(static_cast(item[5])&0xFF)))<<8) +(static_cast(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,13 +678,18 @@ 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) { - return QString("%1").arg(values.at(row).dReal); + + if (rowtoUnicode(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. */ +#include +#include +#include +#include #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()"; diff --git a/hpdata.cpp b/hpdata.cpp index 834e295..9c77270 100644 --- a/hpdata.cpp +++ b/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()<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()<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()<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()<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()<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()<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()<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:"< 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()<. */ -#ifndef ERRORHANDLER_H -#define ERRORHANDLER_H - #include #include #include @@ -25,6 +22,9 @@ #include #include +#ifndef ERRORHANDLER_H +#define ERRORHANDLER_H + enum ErrLevel { L0, //abort L1, //fault diff --git a/include/global.h b/include/global.h index 4796db8..37d41b9 100644 --- a/include/global.h +++ b/include/global.h @@ -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 diff --git a/include/hp_mdivariableedit.h b/include/hp_mdivariableedit.h index 8ed01b0..d6600d8 100644 --- a/include/hp_mdivariableedit.h +++ b/include/hp_mdivariableedit.h @@ -15,14 +15,14 @@ * along with this program. If not, see . */ -#ifndef HP_MDIVARIABLEEDIT_H -#define HP_MDIVARIABLEEDIT_H - -#include #include #include #include #include + +#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 diff --git a/include/matrixdata.h b/include/matrixdata.h index ef36049..f630410 100644 --- a/include/matrixdata.h +++ b/include/matrixdata.h @@ -23,7 +23,7 @@ struct itemData { double dReal=0.0; double dImaginary=0.0; - QString sValue=QStringLiteral("NaH"); + QString sValue=QStringLiteral(""); }; diff --git a/include/vartablemodel.h b/include/vartablemodel.h index 72d511c..6cbdd91 100644 --- a/include/vartablemodel.h +++ b/include/vartablemodel.h @@ -15,11 +15,14 @@ * along with this program. If not, see . */ -#ifndef VARTABLEMODEL_H -#define VARTABLEMODEL_H - +#include #include #include +#include +#include + +#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> 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 &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 diff --git a/mainwindow.cpp b/mainwindow.cpp index 8d30266..6c6b388 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,7 +34,7 @@ #include #include -#include +//#include #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")); } } } diff --git a/matrixdata.cpp b/matrixdata.cpp index 9505164..53de3d5 100644 --- a/matrixdata.cpp +++ b/matrixdata.cpp @@ -66,6 +66,7 @@ void MatrixData::addRow(int row) int i; QList * 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:"< +#include +#include +#include +#include + #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(dataobj); + list->setItem(index.row(),value.toString(),value.toReal()); + return true; + } + if (type==HP_MATRIX) { + Matrix * matrix; + matrix = static_cast(dataobj); + matrix->setItem(index.row(),index.column(),value.toString(),value.toReal()); + return true; + } + if (type==HP_REAL) { + Real * real; + real = static_cast(dataobj); + // item = real->getItem(index.row()); + // return item; + } + if (type==HP_COMPLEX) { + Complex * complex; + complex = static_cast(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(dataobj); + size= list->getListSize()+1; } if (type==HP_REAL) { Real * real; - real = (Real *)dataobj; + real = static_cast(dataobj); size= real->getListSize(); } if (type==HP_COMPLEX) { Complex * complex; - complex = (Complex *)dataobj; + complex = static_cast(dataobj); size= complex->getListSize(); } if (type==HP_MATRIX) { Matrix * matrix; - matrix = (Matrix *)dataobj; - size= matrix->getMatrixRows(); + matrix = static_cast(dataobj); + size= matrix->getMatrixRows()+1; // qDebug()<getName()<<" row"<getMatrixColumns(); + matrix = static_cast(dataobj); + size= matrix->getMatrixColumns()+1; // qDebug()<getName()<<" column"<(dataobj); // size= matrix->getMatrixColumns(); // qDebug()<getName()<<" column"< &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(dataobj); item = list->getItem(index.row()); return item; } if (type==HP_MATRIX) { Matrix * matrix; - matrix = (Matrix *)dataobj; + matrix = static_cast(dataobj); item = matrix->getItem(index.row(),index.column()); return item; } if (type==HP_REAL) { Real * real; - real = (Real *)dataobj; + real = static_cast(dataobj); item = real->getItem(index.row()); return item; } if (type==HP_COMPLEX) { Complex * complex; - complex = (Complex *)dataobj; + complex = static_cast(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()"; }