Matrix Update

This commit is contained in:
Ian Gebbie 2020-02-08 21:29:59 +02:00
parent e773148a2b
commit 848d8af1af
9 changed files with 224 additions and 51 deletions

View file

@ -22,6 +22,8 @@
#include <QStringListModel> #include <QStringListModel>
#include <hp_mditexteditor.h> #include <hp_mditexteditor.h>
#include <hp_infodialog.h>
#include <hp_mdivariableedit.h>
#include <QSettings> #include <QSettings>
#include <QTextCodec> #include <QTextCodec>
#include <utility> #include <utility>
@ -301,14 +303,42 @@ bool contentFileSystemModel::openFile(QMdiArea * mdiwin,QFileInfo info) {
hp_mdiTextEdit * hptextedit = nullptr; hp_mdiTextEdit * hptextedit = nullptr;
AbstractData * data=nullptr; AbstractData * data=nullptr;
QString calc;
QString name;
hp_DataType type;
hp_Information hpinfo;
// hp_infoDialog * hpinfodlg;
hp_mdiVariableEdit * hpvaredit=nullptr;
data = readFile(info); data = readFile(info);
if (data!=nullptr) { if (data!=nullptr) {
type=data->getType();
switch (type) {
case HP_NOTE:
case HP_PROG: {
if (hptextedit==nullptr) if (hptextedit==nullptr)
hptextedit = new hp_mdiTextEdit(mdiwin,info, data); hptextedit = new hp_mdiTextEdit(mdiwin,info, data);
if (hptextedit!=nullptr) { if (hptextedit!=nullptr)
hptextedit ->show(); hptextedit ->show();
return true; }
break;
case HP_CAS:
case HP_REAL:
case HP_COMPLEX:
case HP_LIST:
case HP_MATRIX: {
if (hpvaredit==nullptr) {
if (data!=nullptr) {
qDebug()<<"Opening Varedit";
hpvaredit = new hp_mdiVariableEdit(mdiwin,info,data);
}
}
if (hpvaredit!=nullptr)
hpvaredit ->show();
}
break;
} }
} }
else { else {
@ -376,6 +406,18 @@ AbstractData * contentFileSystemModel::readFile(QFileInfo fileinfo) const {
data->parseData(in); data->parseData(in);
} }
break; break;
case HP_LIST: {
qDebug()<<"HP_LIST";
data = new List(filedata.filename, HP_LIST);
data->parseData(in);
}
break;
case HP_MATRIX: {
qDebug()<<"HP_MATRIX";
data = new Matrix(filedata.filename, HP_MATRIX);
data->parseData(in);
}
break;
default: ; default: ;
} }

View file

@ -31,18 +31,58 @@ hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent,
hptreeitem=treeItem; hptreeitem=treeItem;
hpcalc = dataStore; hpcalc = dataStore;
filename = QStringLiteral("NULL");
if (hpcalc!=nullptr) {
calculator=hpcalc->getCalculatorName();
if (treeItem!=nullptr) {
filename=treeItem->getFileName(); filename=treeItem->getFileName();
type=treeItem->getType(); type=treeItem->getType();
}
else {
qWarning()<<"hpcalc is null";
}
data=hpcalc->getData(filename,type);
}
else {
qWarning()<<"hpcalc is null";
}
content=false;
setup();
setWindowTitle(calculator+": "+filename);
}
hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent,
QFileInfo file,
AbstractData * data_in)
: hp_MdiWindow(parent)
{
setMinimumSize(200,200);
setMaximumSize(1000,1000);
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
calculator=QStringLiteral("Content: ");
content=true;
hptreeitem=nullptr;
hpcalc = nullptr;
filename=file.fileName();
data = data_in;
if (data!=nullptr)
type=data->getType();
setup(); setup();
setWindowTitle(filename); setWindowTitle(calculator+filename);
} }
void hp_mdiVariableEdit::setup() { void hp_mdiVariableEdit::setup() {
if (hpcalc) { if (data!=nullptr) {
varmodel = new varTableModel(this,hpcalc,filename,type); varmodel = new varTableModel(this,data,filename,type);
tableView = new QTableView(this); tableView = new QTableView(this);
tableView->setModel(varmodel); tableView->setModel(varmodel);
setWidget(tableView); setWidget(tableView);
@ -50,8 +90,11 @@ void hp_mdiVariableEdit::setup() {
} }
void hp_mdiVariableEdit::show() { void hp_mdiVariableEdit::show() {
if(tableView) if(tableView!=nullptr)
tableView->show(); tableView->show();
else {
qWarning()<<"hp_mdiVariableEdit::show tableView null";
}
hp_MdiWindow::show(); hp_MdiWindow::show();
} }

View file

@ -22,6 +22,7 @@
#include <QWidget> #include <QWidget>
#include <QMdiSubWindow> #include <QMdiSubWindow>
#include <QTableView> #include <QTableView>
#include <QFileInfo>
#include "vartablemodel.h" #include "vartablemodel.h"
#include "hpdata.h" #include "hpdata.h"
#include "hp_mdiwindow.h" #include "hp_mdiwindow.h"
@ -37,19 +38,23 @@ protected:
hpTreeItem * hptreeitem =nullptr; hpTreeItem * hptreeitem =nullptr;
varTableModel * varmodel =nullptr; varTableModel * varmodel =nullptr;
hpCalcData * hpcalc =nullptr; hpCalcData * hpcalc =nullptr;
AbstractData * data = nullptr;
QString filename; QString filename;
hp_DataType type; hp_DataType type=HP_MAIN;
QFileInfo file;
QString calculator;
bool content;
void setup(); void setup();
public: public:
explicit hp_mdiVariableEdit(QWidget *parent = nullptr, hp_mdiVariableEdit(QWidget *parent = nullptr,
hpTreeItem * treeItem = nullptr, hpTreeItem * treeItem = nullptr,
hpCalcData * dataStore =nullptr hpCalcData * dataStore =nullptr
); );
// explicit hp_mdiVariableEdit(QWidget *parent, hp_mdiVariableEdit(QWidget *parent,
// hp_DataStruct filedata, QFileInfo file,
// hpCalcData * dataStore AbstractData * data
// ); );
void show(); void show();
~hp_mdiVariableEdit(); ~hp_mdiVariableEdit();

View file

@ -57,7 +57,6 @@ public:
void writeStatus(QString); void writeStatus(QString);
void writeChatter(QString); void writeChatter(QString);
void addDummy(); void addDummy();
void createActions();
hpusb * getAPI(); hpusb * getAPI();
signals: signals:
@ -84,12 +83,21 @@ private slots:
void readSettings(); void readSettings();
void setTimerStopped(); void setTimerStopped();
void eventTileWindow();
void eventCascadeWindow();
void eventCloseWindow();
void eventCloseAllWindow();
void eventPrevious();
void eventNext();
void eventSave(); void eventSave();
void eventSaveAs(); void eventSaveAs();
void eventCreateFolder(); void eventCreateFolder();
void eventCreateNote(); void eventCreateNote();
void eventCreateProgram(); void eventCreateProgram();
void eventExit();
treeModel * getTreeModel(); treeModel * getTreeModel();
void treeMenuAction(bool); void treeMenuAction(bool);

View file

@ -42,7 +42,7 @@ private:
public: public:
varTableModel(QObject *parent = nullptr, varTableModel(QObject *parent = nullptr,
hpCalcData * dataStore =nullptr, AbstractData * data =nullptr,
QString file = QStringLiteral(""), QString file = QStringLiteral(""),
hp_DataType dtype = HP_MAIN); hp_DataType dtype = HP_MAIN);
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex &index) const;

View file

@ -81,14 +81,11 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
setWindowIcon(QIcon::fromTheme("accessories-calculator", setWindowIcon(QIcon::fromTheme("accessories-calculator",
QIcon(":/icons/monitor_32x32.png"))); QIcon(":/icons/monitor_32x32.png")));
createActions();
createLogWindow(); createLogWindow();
setTreeMenu(); setTreeMenu();
setContentWindow(); setContentWindow();
//create some sub menus //create some sub menus
QToolButton *createNewButton= QToolButton *createNewButton=
dynamic_cast<QToolButton*>(ui->toolBar->widgetForAction(ui->actionCreateNew)); dynamic_cast<QToolButton*>(ui->toolBar->widgetForAction(ui->actionCreateNew));
createNewButton->setPopupMode(QToolButton::InstantPopup); createNewButton->setPopupMode(QToolButton::InstantPopup);
@ -109,7 +106,6 @@ MainWindow::MainWindow(QWidget *parent) :
createNewButton->setMenu(createMenu); createNewButton->setMenu(createMenu);
//Hack to fix QT resizing bug //Hack to fix QT resizing bug
resizeDocks({ui->dwCalculator,ui->dwContent},{0,0}, Qt::Horizontal); resizeDocks({ui->dwCalculator,ui->dwContent},{0,0}, Qt::Horizontal);
@ -121,10 +117,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tvCalculators->setDropIndicatorShown(true); ui->tvCalculators->setDropIndicatorShown(true);
ui->tvCalculators->show(); ui->tvCalculators->show();
//setup actions
connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(onOpen())); connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(onOpen()));
connect(ui->actionAbout_HP_Connect,SIGNAL(triggered()),this,SLOT(about())); connect(ui->actionAbout_HP_Connect,SIGNAL(triggered()),this,SLOT(about()));
// connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(exit())); // connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(exit()));
@ -151,6 +144,15 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->tvContent, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_tvContent_customContextMenuRequested(const QPoint &))); connect(ui->tvContent, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(on_tvContent_customContextMenuRequested(const QPoint &)));
connect(hpapi, SIGNAL(hotplug(int)), this, SLOT(hotplug_handler(int))); connect(hpapi, SIGNAL(hotplug(int)), this, SLOT(hotplug_handler(int)));
connect(ui->actionTile,SIGNAL(triggered()),this,SLOT(eventTileWindow()));
connect(ui->actionCascade,SIGNAL(triggered()),this,SLOT(eventCascadeWindow()));
connect(ui->actionClose,SIGNAL(triggered()),this,SLOT(eventCloseWindow()));
connect(ui->actionClose_all,SIGNAL(triggered()),this,SLOT(eventCloseAllWindow()));
connect(ui->actionNext,SIGNAL(triggered()),this,SLOT(eventNext()));
connect(ui->actionPrevious,SIGNAL(triggered()),this,SLOT(eventPrevious()));
connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(eventExit()));
//default data //default data
log("Initialising...."); log("Initialising....");
@ -410,6 +412,48 @@ void MainWindow::eventSaveAs() {
qDebug()<<"Save As Pressed"; qDebug()<<"Save As Pressed";
} }
void MainWindow::eventTileWindow() {
QMdiArea * mdi=getMdi();
mdi->tileSubWindows();
}
void MainWindow::eventCascadeWindow() {
QMdiArea * mdi=getMdi();
mdi->cascadeSubWindows();
}
void MainWindow::eventCloseWindow() {
QMdiArea * mdi=getMdi();
mdi->closeActiveSubWindow();
}
void MainWindow::eventCloseAllWindow() {
QMdiArea * mdi=getMdi();
mdi->closeAllSubWindows();
}
void MainWindow::eventPrevious() {
QMdiArea * mdi=getMdi();
mdi->activatePreviousSubWindow();
}
void MainWindow::eventNext() {
QMdiArea * mdi=getMdi();
mdi->activateNextSubWindow();
}
void MainWindow::eventExit() {
QMdiArea * mdi=getMdi();
mdi->closeAllSubWindows();
close();
}
void MainWindow::eventCreateFolder() { void MainWindow::eventCreateFolder() {
QString newName= QStringLiteral("New Folder"); QString newName= QStringLiteral("New Folder");
@ -469,16 +513,6 @@ void MainWindow::onOptions(bool clicked)
optiondlg->show(); optiondlg->show();
} }
//Dummy from examples -- edit
void MainWindow::createActions()
{
// ui->toolBar->addWidget(QPushButton(QIcon(":/icons/about_32x32.png"),"test"));
// const QIcon newIcon = QIcon::fromTheme("document-new", QIcon(":/icons/new.png"));
// QAction *newAct = new QAction(newIcon, tr("&New"), this);
};
//show or hide content window //show or hide content window
void MainWindow::showContent() { void MainWindow::showContent() {

View file

@ -64,9 +64,6 @@
<property name="title"> <property name="title">
<string>Edit</string> <string>Edit</string>
</property> </property>
<addaction name="actionCut"/>
<addaction name="actionCopy"/>
<addaction name="actionPaste"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionPreferences"/> <addaction name="actionPreferences"/>
</widget> </widget>

View file

@ -26,6 +26,8 @@
#include "treemodel.h" #include "treemodel.h"
#include "hptreeitem.h" #include "hptreeitem.h"
#include <hp_infodialog.h>
#include <hp_mdivariableedit.h>
#include <hp_mditexteditor.h> #include <hp_mditexteditor.h>
#include <QStringListModel> #include <QStringListModel>
#include <QMimeData> #include <QMimeData>
@ -123,18 +125,59 @@ void treeModel::openFile(QMdiArea * mdiwin, QModelIndex &index) {
hp_mdiTextEdit * hptextedit = nullptr; hp_mdiTextEdit * hptextedit = nullptr;
AbstractData * data=nullptr; AbstractData * data=nullptr;
hpTreeItem * item=nullptr; hpTreeItem * item=nullptr;
QString calc;
QString name;
hp_DataType type;
hp_Information hpinfo;
hp_infoDialog * hpinfodlg=nullptr;
hpCalcData * hpdata=nullptr;
hp_mdiVariableEdit * hpvaredit=nullptr;
item = static_cast<hpTreeItem *>(itemFromIndex(index)); item = static_cast<hpTreeItem *>(itemFromIndex(index));
data=getData(index); data=getData(index);
if ((data!=nullptr)&&(item!=nullptr)) { if ((data!=nullptr)&&(item!=nullptr)) {
calc=item->getCalculatorName();
name=item->getFileName();
type=data->getType();
hpdata=getHpCalcData(calc);
switch (type) {
case HP_MAIN: {
hpinfo=hpdata->getInfo();
hpinfodlg = new hp_infoDialog(mdiwin,hpinfo);
hpinfodlg->show();
}
break;
case HP_NOTE:
case HP_PROG: {
if (hptextedit==nullptr) if (hptextedit==nullptr)
hptextedit = new hp_mdiTextEdit(mdiwin,item, data); hptextedit = new hp_mdiTextEdit(mdiwin,item, data);
if (hptextedit!=nullptr) if (hptextedit!=nullptr)
hptextedit ->show(); hptextedit ->show();
} }
break;
case HP_CAS:
case HP_REAL:
case HP_COMPLEX:
case HP_LIST:
case HP_MATRIX: {
if (hpvaredit==nullptr) {
if (data!=nullptr) {
hpvaredit = new hp_mdiVariableEdit(mdiwin,item,hpdata);
}
}
if (hpvaredit!=nullptr)
hpvaredit ->show();
}
break;
}
}
else { else {
qDebug()<<"Null data"; qDebug()<<"Null data";
} }
return;
} }
void treeModel::renameFile(QModelIndex &index,QString newName) { void treeModel::renameFile(QModelIndex &index,QString newName) {

View file

@ -65,13 +65,13 @@ const QStringList varTableModel::complex_header={ "Z0",
}; };
varTableModel::varTableModel(QObject *parent, varTableModel::varTableModel(QObject *parent,
hpCalcData * dataStore, AbstractData * data,
QString file, QString file,
hp_DataType dtype) hp_DataType dtype)
:QAbstractTableModel(parent) :QAbstractTableModel(parent)
{ {
q_parent=parent; q_parent=parent;
hpcalc = dataStore; dataobj = data;
filename=file; filename=file;
type=dtype; type=dtype;
setup(); setup();
@ -90,14 +90,15 @@ QModelIndex varTableModel::index(int row, int column, const QModelIndex &parent)
return createIndex(row,column); return createIndex(row,column);
} }
void varTableModel::setup() void varTableModel::setup()
{ {
if (hpcalc) { // if (hpcalc) {
dataobj=hpcalc->getData(filename,type); // dataobj=hpcalc->getData(filename,type);
// qDebug()<<"varTableModel: type"<<dataobj->getType(); // qDebug()<<"varTableModel: type"<<dataobj->getType();
} // }
return; return;
} }