Update to Qt6

This commit is contained in:
Ian Gebbie 2021-08-21 19:29:31 +02:00 committed by Ian Gebbie
parent e277b719da
commit 9536c97312
12 changed files with 149 additions and 97 deletions

View file

@ -108,6 +108,7 @@ private:
public:
List(QString, hp_DataType);
QByteArray getData() override;
bool getData(QDataStream &ds) override;
itemData getListItem(int);
void setListItem(int, itemData);
QString getItem(int);
@ -130,7 +131,7 @@ public:
void setItem(int, int, QString);
void setItem(int, int, QString, double);
// QByteArray getData() override;
bool getData(QDataStream &ds);
bool getData(QDataStream &ds) override;
m_Size getMatrixSize();
int getMatrixRows();
int getMatrixColumns();

View file

@ -97,7 +97,4 @@ const QString mimetypes[FUNC_NUM][2]={ {"Main","application/x-calc"},
QByteArray data;
};
#endif // HP_TYPEDEF_H

View file

@ -25,6 +25,8 @@
struct itemData {
double dReal=0.0;
double dImaginary=0.0;
QByteArray buf_real[16];
QByteArray buf_imag[16];
QString sValue=QStringLiteral("");
};

View file

@ -16,7 +16,7 @@
*/
#include <QDebug>
#include <QTextCodec>
//#include <QTextCodec>
#include <QtMath>
#include <QBuffer>
#include <math.h>
@ -146,8 +146,8 @@ QString value2Str(int sign, double m, double exp) {
QString complex2Str(QString real, QString imag) {
QString value;
if((imag[0]!="+")&&(imag[0]!="-")) {
value = real+"+"+imag+"*i";
if((imag.at(0)!=u'+')&&(imag.at(0)!=u'-')) {
value = real+u'+'+imag+"*i";
}
else
{
@ -163,8 +163,9 @@ QString complex2Str(QString real, QString imag) {
return value;
}
//Parse 16byte real
itemData extract16(QByteArray item) {
;
itemData listvalue;
QString msg;
QString value=QStringLiteral("");
@ -290,7 +291,15 @@ return out;
}
///Real to BCD
///Real to BCD List format
bool BCDL(QDataStream &ds, double real) {
qDebug()<<"BCD List from "<<real;
}
///Real to BCD for Matrix
bool BCD(QDataStream &ds, double real) {
double base=0.0;
@ -306,9 +315,6 @@ double exponent = floor(log10(F));
double mantissa = F/(pow(10,exponent));
quint8 data[8];
qDebug()<<"BCD from "<<real;
if(exponent < 0)
exponent += 0x1000;
@ -348,12 +354,12 @@ qDebug()<<"BCD from "<<real;
// ds<<(quint8)num;
data[7-i]=(quint8)num;
qDebug()<<"i= "<<i<<": "<<hex<<num;
// qDebug()<<"i= "<<i<<": "<<hex<<num;
}
expn=(quint16)exponent;
//EXP is in binary
qDebug()<<hex<<expn;
// qDebug()<<hex<<expn;
ds<<expn;
for (i=2; i<8; i++) {
@ -741,9 +747,43 @@ List::List(QString name_in, hp_DataType type_in):
}
QByteArray List::getData() {
qDebug()<<"List::getData()";
return data;
}
//resturns a datastream of the datafile
bool List::getData(QDataStream &ds) {
qDebug()<<"List::getData(ds)";
int list,i;
itemData item;
list=getListSize();
ds<<(quint16)0xfffe; //?
ds<<(quint8)0x16; //?
ds<<(quint8)0x00; //?
ds<<(quint16)list; //Size
ds<<(quint16)0x0000; //?
for (i=0;i<list;i++)
{
item=getListItem(i);
}
return true;
}
//Look for list
//Format of header
// FE
// FF
// 16
// 00
// Size
// ??
void List::parseData() {
QByteArray a1;
@ -1053,17 +1093,17 @@ void Program::setProg(QString data_in) {
void Program::parseData() {
QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1");
//QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1");
QByteArray a1;
a1=getData();
text = codec->toUnicode(a1);
//text = codec->toUnicode(a1);
text = a1;
return;
}
void Program::parseData(QDataStream& in) {
QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1");
//QTextCodec * codec = QTextCodec::codecForName("ISO 8859-1");
QByteArrayMatcher matcher;
QByteArray search;
QByteArray phrase;
@ -1099,7 +1139,8 @@ void Program::parseData(QDataStream& in) {
ind=pos+10;
phrase=a1.mid(ind,16*3);
//add array to catch variable list
str=codec->toUnicode(phrase);
//str=codec->toUnicode(phrase);
str = phrase;
errlog(QString("TD...%1 %2").arg(pos,0,16).arg(ind));
main_err->dump((uint8_t *)phrase.data(),3*16);
errlog(str);
@ -1118,8 +1159,8 @@ void Program::parseData(QDataStream& in) {
// a1=getData();
// qDebug()<<codec->toUnicode(a1);
setProg(codec->toUnicode(a1));
// setProg(codec->toUnicode(a1));
setProg(a1);
return;
}
@ -1156,7 +1197,7 @@ void Notes::parseData() {
// quint16 len1,len2;
int formatstart;
QTextCodec * codec = QTextCodec::codecForName("UTF-8");
//QTextCodec * codec = QTextCodec::codecForName("UTF-8");
QByteArray a1,a3;
@ -1166,9 +1207,10 @@ void Notes::parseData() {
a3=a1.mid(formatstart,-1);
a1=a1.mid(0,formatstart);
text = codec->toUnicode(a1);
format = codec->toUnicode(a3);
//text = codec->toUnicode(a1);
text = a1;
//format = codec->toUnicode(a3);
format=a3;
}
void Notes::setNote(QString data_in) {

View file

@ -25,7 +25,7 @@
#include <hp_infodialog.h>
#include <hp_mdivariableedit.h>
#include <QSettings>
#include <QTextCodec>
//#include <QTextCodec>
#include <utility>
#define FILE_NUM 9

View file

@ -52,7 +52,7 @@ QVariant dataModel::data(const QModelIndex &index, int role) const
.arg(row + 1)
.arg(col +1);
break;
case Qt::FontRole:
/* case Qt::FontRole:
if (row == 0 && col == 0) //change font only for cell(0,0)
{
QFont boldFont;
@ -81,7 +81,7 @@ QVariant dataModel::data(const QModelIndex &index, int role) const
{
return Qt::Checked;
}
}
*/ }
return QVariant();
}

View file

@ -18,6 +18,7 @@
#include "errorhandler.h"
#include "mainwindow.h"
#include <QTextStream>
errorHandler::errorHandler()
{
@ -59,7 +60,7 @@ int errorHandler::writeLog(QString lineToBeLogged)
QDateTime time(QDateTime::currentDateTime());
QTextStream out(&fileLog);
out << time.toString("yyyy/MM/dd hh:mm:ss") << " "<< lineToBeLogged << endl;
out << time.toString("yyyy/MM/dd hh:mm:ss") << " "<< lineToBeLogged << Qt::endl;
fileLog.close();
@ -110,7 +111,7 @@ int errorHandler::dump(uint8_t * data, int size)
QString text = QString("Dump:\n");
QString texta = QString("ASCII:\n");
j=0;
text = text + QString().sprintf("%04d | ",0);
text = text + QString().asprintf("%04d | ",0);
for (i=0; i< size; i++)
{
text = text + QString(" %1 ").arg(QChar(data[i]).unicode(),2,16,QChar('0'));
@ -118,7 +119,7 @@ int errorHandler::dump(uint8_t * data, int size)
if (j>15) {
j=0;
text=text+"\n";
text = text + QString().sprintf("%04d | ",i+1);
text = text + QString().asprintf("%04d | ",i+1);
}
texta = texta +" "+QChar(data[i]).unicode();

View file

@ -46,7 +46,7 @@ void hp_SettingsDlg::setupSettings() {
ui->cb_font->setCurrentIndex(dlgset.font_size);
ui->cb_theme->setCurrentIndex(dlgset.theme);
ui->le_integer->setText(QString().sprintf("%d",dlgset.bits));
ui->le_integer->setText(QString().asprintf("%d",dlgset.bits));
if (dlgset.textbook)
ui->ch_textbook->setCheckState(Qt::Checked);

View file

@ -169,7 +169,7 @@ void hpCalcData::readSettings() {
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
qDebug()<<QString().asprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api) {
api->get_settings(handle);
}
@ -204,7 +204,7 @@ void hpCalcData::readScreen() {
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
qDebug()<<QString().asprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api) {
api->get_screen_shot(handle);
// if (screenShot!=nullptr) {
@ -398,7 +398,7 @@ void hpCalcData::readInfo() {
if (api) {
if(handle) {
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
qDebug()<<QString().asprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (api)
api->load_info(handle);
}

View file

@ -9,7 +9,7 @@
// return 0 = success
// return <> 0 = error
#include <QTextCodec>
// #include <QTextCodec>
#include <QObject>
#include "global.h"
@ -111,7 +111,7 @@ int hpusb::hp_init()
return ret;
}
else
err(L3,ret,QString(QString().sprintf("Could not open libusb: %d",ret)));
err(L3,ret,QString(QString().asprintf("Could not open libusb: %d",ret)));
}
return ret;
}
@ -166,17 +166,17 @@ int hpusb::hp_open(hp_Handle * handle) {
//claim interface
ret = libusb_kernel_driver_active ( handle->usbhandle, 0x0) ;
if (ret==1) {
errlog(QString().sprintf("Keneral active"));
errlog(QString().asprintf("Keneral active"));
ret = libusb_detach_kernel_driver( handle->usbhandle, 0x0) ;
errlog(QString().sprintf("Keneral detach: %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Keneral detach: %s\n", libusb_error_name(ret)));
if (ret!=0) {
errlog(QString().sprintf("Keneral detach error: %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Keneral detach error: %s\n", libusb_error_name(ret)));
goto endfunc;
}
}
else
if (ret!=0) {
errlog(QString().sprintf("Kernal error %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Kernal error %s\n", libusb_error_name(ret)));
goto endfunc;
}
@ -192,7 +192,7 @@ int hpusb::hp_open(hp_Handle * handle) {
ret = libusb_claim_interface(handle->usbhandle, 0x0);
if (ret!=0) {
errlog(QString().sprintf("Claim interface Error: %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Claim interface Error: %s\n", libusb_error_name(ret)));
return -1;
}
}
@ -235,20 +235,20 @@ void hpusb::dumpDevice(libusb_device * device) {
if (device) {
rc = libusb_get_device_descriptor(device, &desc);
if (!rc) {
dump+=QString().sprintf("bLength: %d\n",(int)desc.bLength);
dump+=QString().sprintf("bDescriptor Type: %d\n",(int)desc.bDescriptorType);
dump+=QString().sprintf("bcdUSB: %d\n",(int)desc.bcdUSB);
dump+=QString().sprintf("bDeviceClass: %d\n",(int)desc.bDeviceClass);
dump+=QString().sprintf("bDeviceSubClass: %d\n",(int)desc.bDeviceSubClass);
dump+=QString().sprintf("bDeviceProtocal: %d\n",(int)desc.bDeviceProtocol);
dump+=QString().sprintf("bMaxPacketSize0: %d\n",(int)desc.bMaxPacketSize0);
dump+=QString().sprintf("idVendor: %X\n",(int)desc.idVendor);
dump+=QString().sprintf("idProduct: %d\n",(int)desc.idProduct);
dump+=QString().sprintf("bcdDevicel: %d\n",(int)desc.bcdDevice);
dump+=QString().sprintf("iManufacture: %i\n",desc.iManufacturer);
dump+=QString().sprintf("iProduct: %i\n",desc.iProduct);
dump+=QString().sprintf("iSerialNumber: %i\n",desc.iSerialNumber);
dump+=QString().sprintf("bNumConfigurations: %d\n",desc.bNumConfigurations);
dump+=QString().asprintf("bLength: %d\n",(int)desc.bLength);
dump+=QString().asprintf("bDescriptor Type: %d\n",(int)desc.bDescriptorType);
dump+=QString().asprintf("bcdUSB: %d\n",(int)desc.bcdUSB);
dump+=QString().asprintf("bDeviceClass: %d\n",(int)desc.bDeviceClass);
dump+=QString().asprintf("bDeviceSubClass: %d\n",(int)desc.bDeviceSubClass);
dump+=QString().asprintf("bDeviceProtocal: %d\n",(int)desc.bDeviceProtocol);
dump+=QString().asprintf("bMaxPacketSize0: %d\n",(int)desc.bMaxPacketSize0);
dump+=QString().asprintf("idVendor: %X\n",(int)desc.idVendor);
dump+=QString().asprintf("idProduct: %d\n",(int)desc.idProduct);
dump+=QString().asprintf("bcdDevicel: %d\n",(int)desc.bcdDevice);
dump+=QString().asprintf("iManufacture: %i\n",desc.iManufacturer);
dump+=QString().asprintf("iProduct: %i\n",desc.iProduct);
dump+=QString().asprintf("iSerialNumber: %i\n",desc.iSerialNumber);
dump+=QString().asprintf("bNumConfigurations: %d\n",desc.bNumConfigurations);
}
}
errlog(dump);
@ -292,19 +292,19 @@ int hpusb::submit_sync_s_transfer(hp_Handle * handle, hp_pkt_out * pktout) {
}
errlog("In sync send transfer");
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
qDebug()<<QString().asprintf("%s %p",__FUNCTION__,handle->usbhandle);
//write
errlog("Send..");
ret = libusb_interrupt_transfer(devh, ENDPOINT_OUT, raw.data, raw.size,
&trans,10000);
if (ret) {
errlog(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Write Error: %s\n", libusb_error_name(ret)));
r = 0;
break;
}
else {
errlog(QString().sprintf("Write bytes: %d\n", trans));
errlog(QString().asprintf("Write bytes: %d\n", trans));
}
// Increment packet ID, which seems to be necessary for computer -> calc packets
pkt_id++;
@ -331,10 +331,10 @@ int hpusb::submit_sync_s_transfer(hp_Handle * handle, hp_pkt_out * pktout) {
&trans,10000);
if (ret) {
errlog(QString().sprintf("Write Error: %s\n", libusb_error_name(ret)));
errlog(QString().asprintf("Write Error: %s\n", libusb_error_name(ret)));
}
else {
errlog(QString().sprintf("Write bytes: %d\n", trans));
errlog(QString().asprintf("Write bytes: %d\n", trans));
}
}
@ -476,7 +476,7 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
libusb_device_handle * devh = handle->usbhandle;
errlog("hpusb::submit_sync_r_transfer: Receive...");
qDebug()<<QString().sprintf("%s %p",__FUNCTION__,handle->usbhandle);
qDebug()<<QString().asprintf("%s %p",__FUNCTION__,handle->usbhandle);
if (!handle) {
errlog("Null handle");
@ -626,16 +626,17 @@ int hpusb::send_info(hp_pkt_in * pkt) {
errlog("Unpacking Data");
int ind=0;
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
QTextCodec * codec8 = QTextCodec::codecForName("UTF-8");
// QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
// QTextCodec * codec8 = QTextCodec::codecForName("UTF-8");
QByteArray rd= pkt->array;
//find name
ind=rd.indexOf(QChar(0x6c),0)+1;
ind=rd.indexOf(0x6c,0)+1;
QByteArray str1 =rd.mid(ind,64);
QString name;
name = codec->toUnicode(str1);
//name = codec->toUnicode(str1);
name = str1;
hpinfo.name=name;
//unsigned char searchstr[] = {0x80,0x20,0x80,0x01,0x62};
@ -666,7 +667,8 @@ int hpusb::send_info(hp_pkt_in * pkt) {
//end test
qDebug()<<str1;
QString app;
app = codec8->toUnicode(str1);
//app = codec8->toUnicode(str1);
app=str1;
hpinfo.appver=QString("v%1").arg(listnum[4]);
errlog(app);
@ -675,7 +677,8 @@ int hpusb::send_info(hp_pkt_in * pkt) {
str1 =rd.mid(ind,16);
// qDebug()<<str1;
QString osv;
osv = codec8->toUnicode(str1);
//osv = codec8->toUnicode(str1);
osv=str1;
hpinfo.osver=osv;
// qDebug()<<osv;
errlog(osv);
@ -684,7 +687,8 @@ int hpusb::send_info(hp_pkt_in * pkt) {
ind+=16;
str1 =rd.mid(ind,16);
QString serial;
serial = codec8->toUnicode(str1);
//serial = codec8->toUnicode(str1);
serial=str1;
hpinfo.serialnum=serial;
errlog(serial);
pkt->calc->recvInfo(hpinfo);
@ -728,7 +732,7 @@ int hpusb::send_file(hp_pkt_in * pkt) {
qDebug()<<"hpusb::send_file: In File Processor";
QString filename;
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
//QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
QByteArray rd= pkt->array;
int len;
qint8 crc;
@ -751,7 +755,8 @@ int hpusb::send_file(hp_pkt_in * pkt) {
//find file name
QByteArray str1 =rd.mid(3,len);
filename = codec->toUnicode(str1);
//filename = codec->toUnicode(str1);
filename = str1;
errlog(QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type));
qDebug()<<"hpusb:Checking file type";
@ -809,7 +814,8 @@ int hpusb::send_file(hp_pkt_in * pkt) {
qDebug()<<QString("%1 %2 %3").arg((uint8_t)rd[len],1,16).arg((uint8_t)rd[len+1],1,16).arg((uint8_t)rd[len+2],1,16);
size=rd[len+1]; //Is the byte a size?
QByteArray str1 =rd.mid(len+3,-1);
note.text = codec->toUnicode(str1);
//note.text = codec->toUnicode(str1);
note.text=str1;
note.data=str1;
pkt->calc->recvNote(note);
}
@ -825,7 +831,8 @@ int hpusb::send_file(hp_pkt_in * pkt) {
size=rd[len+1];
QByteArray str1 =rd.mid(len+3,-1);
prog.data=str1;
prog.prog = codec->toUnicode(str1);
//prog.prog = codec->toUnicode(str1);
prog.prog = str1;
pkt->calc->recvProg(prog);
}
break;
@ -984,8 +991,9 @@ int hpusb::lookfordouble (QByteArray rd, int start) {
long double num=0;
QString app;
QByteArray str1;
QTextCodec * codec = QTextCodec::codecForName("UTF-16");
app = codec->toUnicode(str1);
//QTextCodec * codec = QTextCodec::codecForName("UTF-16");
//app = codec->toUnicode(str1);
app=str1;
errlog(app);
int i,ind;
@ -995,9 +1003,10 @@ int hpusb::lookfordouble (QByteArray rd, int start) {
ind+=1;
str1 =rd.mid(ind,sizeof(num));
num= *(long double*)(str1.constData());
app = codec->toUnicode(str1);
//app = codec->toUnicode(str1);
app =str1;
// qDebug()<<num;
qDebug()<<QString().sprintf("%e",num);
qDebug()<<QString().asprintf("%e",num);
qDebug()<<app;
}
return 0;
@ -1164,17 +1173,17 @@ void hpusb::print_libusb_transfer(struct libusb_transfer *p_t)
}
else {
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));
errlog(QString().asprintf("flags =%x \n", p_t->flags));
errlog(QString().asprintf("endpoint=%x \n", p_t->endpoint));
errlog(QString().asprintf("type =%x \n", p_t->type));
errlog(QString().asprintf("timeout =%d \n", p_t->timeout));
// length, and buffer are commands sent to the device
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));
errlog(QString().asprintf("length =%d \n", p_t->length));
errlog(QString().asprintf("actual_length =%d \n", p_t->actual_length));
errlog(QString().asprintf("buffer =%p \n", p_t->buffer));
for (i=0; i < p_t->length; i++){
errlog(QString().sprintf("%d %x", i, p_t->buffer[i]));
errlog(QString().asprintf("%d %x", i, p_t->buffer[i]));
}
}
return;
@ -1325,7 +1334,7 @@ void sighandler(int signum)
// - This is called after the Out transfer has been received by libusb
void cb_out(struct libusb_transfer *transfer) {
QString().sprintf("status =%d, actual_length=%d\n",
QString().asprintf("status =%d, actual_length=%d\n",
transfer->status, transfer->actual_length);
}

View file

@ -161,7 +161,7 @@ MainWindow::MainWindow(QWidget *parent) :
errlog("Initialising....");
if (hpapi->hp_init())
err(L1,0,QString().sprintf("%s Failed to open libusb",__FUNCTION__));
err(L1,0,QString().asprintf("%s Failed to open libusb",__FUNCTION__));
//setup event handler
eventThread = new EventThread(this);
@ -191,7 +191,7 @@ void MainWindow::testFunction() {
if (pH) {
cmd = QInputDialog::getInt(this,"Get Command","CMD:",0,0,0xFFFF);
errlog("command is "+QString().sprintf("%x",cmd));
errlog("command is "+QString().asprintf("%x",cmd));
pH->vpkt_send_experiments(cmd);
}
else
@ -209,7 +209,7 @@ void MainWindow::testFunction2() {
QString out;
cmd = QInputDialog::getInt(this,"Get Command","CMD:",0,0,0xFFFF);
out=I2BCDS(cmd);
errlog("command is "+QString().sprintf("%x",cmd));
errlog("command is "+QString().asprintf("%x",cmd));
qDebug()<<out;
}

View file

@ -282,16 +282,16 @@ QVariant varTableModel::headerData(int section, Qt::Orientation orientation, in
bool varTableModel::getData(QDataStream &ds) {
// QByteArray buf;
// buf.clear();
// QDataStream ds_test(&buf, QIODevice::ReadWrite);
// ds_test.setByteOrder(QDataStream::LittleEndian);
QByteArray buf;
buf.clear();
QDataStream ds_test(&buf, QIODevice::ReadWrite);
ds_test.setByteOrder(QDataStream::LittleEndian);
if(dataobj!=nullptr) {
dataobj->getData(ds);
// dataobj->getData(ds_test);
// qDebug()<<"VarTableModel::getData";
// qDebug()<<"Out:"<<buf.toHex();
// dataobj->getData(ds);
dataobj->getData(ds_test);
qDebug()<<"VarTableModel::getData";
qDebug()<<"Out:"<<buf.toHex();
return true;
}