Text Editor

This commit is contained in:
Indy970 2019-02-26 21:56:39 +02:00
parent 87961927d8
commit 21b0ec99e7
9 changed files with 202 additions and 49 deletions

View file

@ -1,8 +1,13 @@
#include <QDebug>
#include "global.h"
#include "abstractdata.h" #include "abstractdata.h"
#include "hpusb.h" #include "hpusb.h"
AbstractData::AbstractData(QString name_in, hp_DataType type_in) AbstractData::AbstractData(QString name_in, hp_DataType type_in)
{ {
// qDebug()<<"base class called "<<name_in;
setName(name_in); setName(name_in);
setType(type_in); setType(type_in);
} }
@ -108,16 +113,30 @@ Program::Program(QString name_in, hp_DataType type_in, QString data):
} }
QString Program::getProg() { QString Program::getProg() {
return data; return text;
} }
void Program::setProg(QString data_in) { void Program::setProg(QString data_in) {
data=data_in; text=data_in;
} }
//Notes //Notes
Notes::Notes(QString name_in, hp_DataType type_in): Notes::Notes(QString name_in, hp_DataType type_in, QString data):
AbstractData(name_in, type_in) { AbstractData(name_in, type_in) {
setFileCode(HP_TP_SETTINGS); setFileCode(HP_TP_NOTE);
setNote(data);
qDebug()<<"Taking Note";
qDebug()<<data;
}
QString Notes::getNote() {
qDebug()<<"Getting Note";
qDebug()<<text;
return text;
}
void Notes::setNote(QString data_in) {
text=data_in;
} }

View file

@ -76,7 +76,7 @@ public:
class Program: public AbstractData class Program: public AbstractData
{ {
private: private:
QString data; QString text;
public: public:
Program(QString, hp_DataType, QString); Program(QString, hp_DataType, QString);
void setProg(QString); void setProg(QString);
@ -85,8 +85,13 @@ public:
class Notes: public AbstractData class Notes: public AbstractData
{ {
private:
QString text;
public: public:
Notes(QString, hp_DataType); Notes(QString, hp_DataType, QString);
void setNote(QString);
QString getNote();
}; };

View file

@ -1,20 +1,59 @@
#include "hp_mditexteditor.h" #include "hp_mditexteditor.h"
#include "hptreeitem.h" #include "hptreeitem.h"
#include "hpdata.h"
#include "abstractdata.h"
hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem) hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, hpCalcData * calc)
:QMdiSubWindow(parent) :QMdiSubWindow(parent)
{ {
setMinimumSize(200,200); setMinimumSize(200,200);
setMaximumSize(1000,1000); setMaximumSize(1000,1000);
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
setup();
hptreeitem=treeItem; hptreeitem=treeItem;
setWindowTitle(treeItem->getFileName()); hpcalc = calc;
filename=treeItem->getFileName();
type=treeItem->getType();
if (hpcalc) {
data=calc->getData(filename,type);
}
setup();
setWindowTitle(filename);
} }
void hp_mdiTextEdit::setup() { void hp_mdiTextEdit::setup() {
QString text;
textEdit = new textEditor(this); textEdit = new textEditor(this);
qDebug()<<"hp_mdiTextEdit::setup";
if (data) {
qDebug()<<"hp_mdiTextEdit::setup - Data not null";
qDebug()<<data->getName();
qDebug()<<data->getType();
if (data->getType()==HP_NOTE) {
qDebug()<<"hp_mdiTextEdit::setup - Its a Note";
Notes *note;
note=(Notes *)data;
text=note->getNote();
}
if (data->getType()==HP_PROG) {
Program *note;
note=(Program *)data;
text=note->getProg();
}
qDebug()<<text;
textEdit->setPlainText(text);
}
else {
qDebug()<<"hp_mdiTextEdit::setup - Data Null";
}
setWidget(textEdit); setWidget(textEdit);
} }

View file

@ -5,8 +5,10 @@
#include <QWidget> #include <QWidget>
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QTreeView> #include <QTreeView>
#include "hpdata.h"
class hpTreeItem; class hpTreeItem;
class hpCalcData;
#include "texteditor.h" #include "texteditor.h"
@ -16,11 +18,16 @@ class hp_mdiTextEdit: public QMdiSubWindow
protected: protected:
textEditor * textEdit; textEditor * textEdit =nullptr;
hpTreeItem * hptreeitem; hpTreeItem * hptreeitem =nullptr;
hpCalcData * hpcalc =nullptr;
QString filename;
hp_DataType type;
AbstractData * data =nullptr;
public: public:
hp_mdiTextEdit(QWidget * parent = nullptr, hpTreeItem * treeItem = nullptr); hp_mdiTextEdit(QWidget * parent = nullptr, hpTreeItem * treeItem = nullptr,
hpCalcData * dataStore =nullptr);
void setup(); void setup();
void show(); void show();
~hp_mdiTextEdit(); ~hp_mdiTextEdit();

View file

@ -98,6 +98,18 @@ int hpCalcData::findData(QString name, hp_DataType dataType) {
return 0; return 0;
} }
//returns position of entry in list or returns 0;
AbstractData * hpCalcData::getData(QString name, hp_DataType dataType) {
for (int i = 0; i < lData.size(); ++i) {
if (lData.at(i)->equivalent(name,dataType)) {
return lData.at(i);
}
}
return nullptr;
}
AbstractData * hpCalcData::dataAt(int i) { AbstractData * hpCalcData::dataAt(int i) {
return lData.at(i); return lData.at(i);
} }
@ -203,6 +215,20 @@ void hpCalcData::recvProg(hp_Prog program) {
emit emitChange(HP_PROG); emit emitChange(HP_PROG);
} }
//recieve Program
void hpCalcData::recvNote(hp_Note note) {
log("Recieving Note");
qDebug()<<"hpCalcData::recvNote";
qDebug()<<note.filename;
Notes * obj = new Notes(note.filename,HP_NOTE, note.text);
addData(obj);
emit emitChange(HP_NOTE);
}
//recieve Program //recieve Program
void hpCalcData::recvData(hp_Data data) { void hpCalcData::recvData(hp_Data data) {

View file

@ -56,6 +56,11 @@ struct hp_Prog {
QString prog; QString prog;
}; };
struct hp_Note {
QString filename;
QString text;
};
struct hp_Data { struct hp_Data {
QString name; QString name;
hp_DataType type; hp_DataType type;
@ -91,10 +96,12 @@ public:
void recvInfo(hp_Information); void recvInfo(hp_Information);
void recvData(hp_Data); void recvData(hp_Data);
void recvProg(hp_Prog); void recvProg(hp_Prog);
void recvNote(hp_Note);
void addData(AbstractData *); void addData(AbstractData *);
void deleteData(AbstractData *); void deleteData(AbstractData *);
int findData(QString name, hp_DataType dataType); int findData(QString name, hp_DataType dataType);
AbstractData * getData(QString name, hp_DataType dataType);
AbstractData * dataAt(int i); AbstractData * dataAt(int i);
int dataCount(); int dataCount();

View file

@ -85,6 +85,10 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
hp_infoDialog * hpinfodlg; hp_infoDialog * hpinfodlg;
hp_Information hpinfo; hp_Information hpinfo;
hpCalcData * calc;
calc=getDataStore();
AbstractData * data;
// QString test; // QString test;
// test=data(Qt::DisplayRole).toString(); // test=data(Qt::DisplayRole).toString();
@ -94,7 +98,6 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
dataStore = getDataStore(); dataStore = getDataStore();
hpinfo=dataStore->getInfo(); hpinfo=dataStore->getInfo();
hpinfodlg = new hp_infoDialog(mdiwin,hpinfo); hpinfodlg = new hp_infoDialog(mdiwin,hpinfo);
//hpinfodlg->move(700,400);
hpinfodlg->show(); hpinfodlg->show();
} }
break; break;
@ -114,8 +117,15 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
hpvaredit ->show(); hpvaredit ->show();
break; break;
case HP_LIST: case HP_LIST:
if (hpvaredit==nullptr) qDebug()<<column();
hpvaredit = new hp_mdiVariableEdit(mdiwin,this); if (hpvaredit==nullptr) {
if (calc) {
data=calc->getData(getFileName(),HP_LIST);
}
if (data) {
hpvaredit = new hp_mdiVariableEdit(mdiwin,this);
}
}
if (hpvaredit!=nullptr) if (hpvaredit!=nullptr)
hpvaredit ->show(); hpvaredit ->show();
break; break;
@ -125,13 +135,24 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
if (hpvaredit!=nullptr) if (hpvaredit!=nullptr)
hpvaredit ->show(); hpvaredit ->show();
break; break;
case HP_NOTE: case HP_NOTE: {
hpCalcData * dataStore;
dataStore = getDataStore();
if (hptextedit==nullptr) if (hptextedit==nullptr)
hptextedit = new hp_mdiTextEdit(mdiwin,this); hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore);
if (hptextedit!=nullptr) if (hptextedit!=nullptr)
hptextedit ->show(); hptextedit ->show();
}
break; break;
case HP_PROG: case HP_PROG: {
hpCalcData * dataStore;
dataStore = getDataStore();
if (hptextedit==nullptr)
hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore);
if (hptextedit!=nullptr)
hptextedit ->show();
}
break; break;
case HP_REAL: case HP_REAL:
if (hpvaredit==nullptr) if (hpvaredit==nullptr)
@ -144,9 +165,6 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
break; break;
default: ; default: ;
} }
// log(test+getDataStore()->getInfo().serialnum);
} }
void hpTreeItem::contextAction(QMdiArea * mdiwin, contextActionType cta) { void hpTreeItem::contextAction(QMdiArea * mdiwin, contextActionType cta) {
@ -251,6 +269,9 @@ void hpTreeItem::dataChange(hp_Change hpchange) {
case HP_LIST: { case HP_LIST: {
refresh(); refresh();
} }
case HP_NOTE: {
refresh();
}
case HP_PROG: { case HP_PROG: {
refresh(); refresh();
} }
@ -268,12 +289,12 @@ void hpTreeItem::addChild(AbstractData *obj) {
QString name; QString name;
//create fixed variable list //create fixed variable list
qDebug()<<"hpTreeItem:getting object data"; // qDebug()<<"hpTreeItem:getting object data";
type= obj->getType(); type= obj->getType();
name=obj->getName(); name=obj->getName();
qDebug()<<"hpTreeItem:Object not null "<<name<<"type:"<<type; // qDebug()<<"hpTreeItem:Object not null "<<name<<"type:"<<type;
qDebug()<<"hpTreeItem:this is "<<getFileName()<<" of type:"<<getType() qDebug()<<"hpTreeItem:this is "<<getFileName()<<" of type:"<<getType()
<<"Column:"<<columnCount(); <<"Column:"<<columnCount();
@ -300,6 +321,12 @@ void hpTreeItem::addChild(AbstractData *obj) {
break; break;
case HP_LIST: { case HP_LIST: {
subItem->setIcon(QIcon(func_list[HP_LIST][1])); subItem->setIcon(QIcon(func_list[HP_LIST][1]));
}
break;
case HP_NOTE: {
subItem->setIcon(QIcon(func_list[HP_NOTE][1]));
qDebug()<<"hpTreeItem: Creating Note type:"<<type;
} }
break; break;
case HP_PROG: { case HP_PROG: {
@ -307,12 +334,10 @@ void hpTreeItem::addChild(AbstractData *obj) {
} }
break; break;
} }
qDebug()<<"Append Row";
appendRow(subItem); appendRow(subItem);
} }
else { else {
qDebug()<<"hpTreeItem:No Object added"; qDebug()<<"hpTreeItem:No Object added";
} }
} }
@ -333,8 +358,6 @@ void hpTreeItem::refresh() {
calc=getDataStore(); calc=getDataStore();
qDebug()<<"hpTreeItem: In refresh";
if (calc) { if (calc) {
if (columnCount()==1) { if (columnCount()==1) {
AbstractData * obj; AbstractData * obj;
@ -416,7 +439,7 @@ void hpTreeItem::addFile(AbstractData * obj) {
QString name; QString name;
hp_DataType type; hp_DataType type;
qDebug()<<"hpTreeItem::addFile"; // qDebug()<<"hpTreeItem::addFile";
rows=rowCount(); rows=rowCount();
flag=0; flag=0;

View file

@ -561,7 +561,7 @@ int hpusb::submit_sync_r_transfer(hp_Handle * handle, hp_pkt_in * pktin) {
//request to recieve a file transfer //request to recieve a file transfer
int hpusb::data_dispatch(hp_pkt_in * pktin) { int hpusb::data_dispatch(hp_pkt_in * pktin) {
qDebug()<<"In data dispatch"; // qDebug()<<"In data dispatch";
switch(pktin->type) { switch(pktin->type) {
case HP_HDR_PNG: case HP_HDR_PNG:
@ -600,7 +600,8 @@ int hpusb::send_info(hp_pkt_in * pkt) {
log("unpacking data"); log("unpacking data");
int ind=0; int ind=0;
QTextCodec * codec = QTextCodec::codecForName("UTF-8"); QTextCodec * codec = QTextCodec::codecForName("UTF-16 Little Endian");
QTextCodec * codec8 = QTextCodec::codecForName("UTF-8");
QByteArray rd= pkt->array; QByteArray rd= pkt->array;
//find name //find name
@ -611,30 +612,36 @@ int hpusb::send_info(hp_pkt_in * pkt) {
name = codec->toUnicode(str1); name = codec->toUnicode(str1);
hpinfo.name=name; 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);
qDebug()<<str1;
QString app;
app = codec8->toUnicode(str1);
hpinfo.appver=app;
log(app);
//find OS Version //find OS Version
unsigned char searchstr[] = {0x80,0x20,0x80,0x01,0x62,0x01}; ind+=12;
ind+=rd.indexOf((char *) searchstr,ind+64)+4;
qDebug()<<ind;
//ind+=;
str1 =rd.mid(ind,16); str1 =rd.mid(ind,16);
// qDebug()<<str1;
QString osv; QString osv;
osv = codec->toUnicode(str1); osv = codec8->toUnicode(str1);
hpinfo.osver=osv; hpinfo.osver=osv;
qDebug()<<osv; // qDebug()<<osv;
log(osv); log(osv);
//find Serial Number //find Serial Number
ind+=16; ind+=16;
str1 =rd.mid(ind,16); str1 =rd.mid(ind,16);
QString serial; QString serial;
serial = codec->toUnicode(str1); serial = codec8->toUnicode(str1);
hpinfo.serialnum=serial; hpinfo.serialnum=serial;
log(serial); log(serial);
//find Application Version
ind+=16;
str1 =rd.mid(ind,16);
pkt->calc->recvInfo(hpinfo); pkt->calc->recvInfo(hpinfo);
return 0; return 0;
@ -676,13 +683,10 @@ int hpusb::send_file(hp_pkt_in * pkt) {
qDebug()<<"hpusb:In File Processor"; qDebug()<<"hpusb:In File Processor";
QString filename; QString filename;
int ind,ind2;
QTextCodec * codec = QTextCodec::codecForName("UTF-8"); QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
QByteArray rd= pkt->array; QByteArray rd= pkt->array;
QByteArray start = QByteArrayLiteral("\x02");
int len; int len;
len = rd[0]; len = rd[0];
@ -692,11 +696,15 @@ int hpusb::send_file(hp_pkt_in * pkt) {
log(QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type)); log(QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type));
qDebug()<<"hpusb:Checking file type"; qDebug()<<"hpusb:Checking file type";
qDebug()<<QString("File: %1 Type: %2").arg(filename).arg(pkt->pkt_type);
qDebug()<<QString("%1 %2 %3").arg((uint8_t)rd[0],1,16).arg((uint8_t)rd[1],1,16).arg((uint8_t)rd[2],1,16);
//handle each file type //handle each file type
switch (pkt->pkt_type) { switch (pkt->pkt_type) {
case HP_TP_SETTINGS: case HP_TP_SETTINGS:
qDebug()<<"hpusb:File type settings"; qDebug()<<"hpusb:File type settings";
qDebug()<<filename;
break; break;
case HP_TP_FUNCTIONS: { case HP_TP_FUNCTIONS: {
qDebug()<<"hpusb:File functions"; qDebug()<<"hpusb:File functions";
@ -725,12 +733,30 @@ int hpusb::send_file(hp_pkt_in * pkt) {
pkt->calc->recvData(sData); pkt->calc->recvData(sData);
} }
break; break;
case HP_TP_NOTE: {
//get a note
int size;
qDebug()<<"hpusb:File type Note";
hp_Note note;
note.filename=filename;
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,rd.size()-len-3);
note.text = codec->toUnicode(str1);
pkt->calc->recvNote(note);
}
break;
case HP_TP_PROG: { case HP_TP_PROG: {
//get a grogram //get a grogram
int size;
qDebug()<<"hpusb:File type program"; qDebug()<<"hpusb:File type program";
hp_Prog prog; hp_Prog prog;
prog.filename=filename; prog.filename=filename;
QByteArray str1 =rd.mid(len,rd.size()-len);
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];
QByteArray str1 =rd.mid(len+3,rd.size()-len-3);
prog.prog = codec->toUnicode(str1); prog.prog = codec->toUnicode(str1);
pkt->calc->recvProg(prog); pkt->calc->recvProg(prog);
} }
@ -890,7 +916,7 @@ int hpusb::lookfordouble (QByteArray rd, int start) {
long double num=0; long double num=0;
QString app; QString app;
QByteArray str1; QByteArray str1;
QTextCodec * codec = QTextCodec::codecForName("UTF-8"); QTextCodec * codec = QTextCodec::codecForName("UTF-16");
app = codec->toUnicode(str1); app = codec->toUnicode(str1);
log(app); log(app);

View file

@ -76,6 +76,7 @@ enum hp_pkt_type {
HP_TP_FUNCTIONS=02, HP_TP_FUNCTIONS=02,
HP_TP_LIST=03, HP_TP_LIST=03,
HP_TP_MATRIX=04, HP_TP_MATRIX=04,
HP_TP_NOTE=05,
HP_TP_PROG=06, HP_TP_PROG=06,
HP_TP_CUSTOM=11 HP_TP_CUSTOM=11
}; };