diff --git a/abstractdata.cpp b/abstractdata.cpp index 51e1c6e..ff492a0 100644 --- a/abstractdata.cpp +++ b/abstractdata.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "global.h" #include "abstractdata.h" @@ -283,6 +284,10 @@ void AbstractData::parseData() { qDebug()<<"AbstractData::parseData"; } +void AbstractData::parseData(QDataStream& in) { + qDebug()<<"AbstractData::parseData"; +} + //REAL // Application::Application(QString name_in, hp_DataType type_in): @@ -826,19 +831,40 @@ QString Program::getProg() { } void Program::setProg(QString data_in) { + data=data_in.toUtf8(); text=data_in; } void Program::parseData() { - int16_t len1,len2; - QTextCodec * codec = QTextCodec::codecForName("UTF-16LE"); - + QTextCodec * codec = QTextCodec::codecForName("UTF8"); QByteArray a1; a1=getData(); text = codec->toUnicode(a1); - } +} +void Program::parseData(QDataStream& in) { + + QTextCodec * codec = QTextCodec::codecForName("UTF8"); + QString str; + in.setByteOrder(QDataStream::LittleEndian); + quint8 c; + QByteArray a1; + + while(!in.atEnd()) { + in>>c; + a1.append(c); + } + qDebug()<toUnicode(a1); +} //Notes Notes::Notes(QString name_in, hp_DataType type_in, QString data_in): @@ -980,3 +1006,27 @@ void Settings::parseData() { */ } + +void Settings::setData(QByteArray datain) { + + qDebug()<<"Settings Compare:"; + + int len1=data.size(); + int len2=datain.size(); + log(QString("Settings Compare %1 %2").arg(len1).arg(len2)); + int i=0; + while ((i +#include + +#include "hp_mditexteditor.h" #define FILE_NUM 9 - +#define FILE_TYPE 5 //Todo fix for all file types -const QString contentFileSystemModel::filetype_list[FILE_NUM][2]={{".hpprgm",":/icons/apps_32x32.png"}, - {"CAS Vars",":/icons/casFolder_32x32.png"}, - {"Complex",":/icons/complex_32x32.png"}, +const QString contentFileSystemModel::filetype_list[FILE_NUM][2]={{"hpprgm",":/icons/apps_16x16.png"}, + {"CAS Vars",":/icons/casFolder_16x16.png"}, + {"Complex",":/icons/complex_16x16.png"}, {"hplist",":/icons/list_16x16.png"}, - {"Matrices",":/icons/table_32x32.png"}, - {"Notes",":/icons/note_32x32.png"}, + {"Matrices",":/icons/table_16x16.png"}, + {"Notes",":/icons/note_16x16.png"}, {"hpprgm",":/icons/program_16x16.png"}, - {"Real",":/icons/real_32x32.png"}, - {"Variables",":/icons/varFolder_32x32.png"} + {"Real",":/icons/real_16x16.png"}, + {"Variables",":/icons/varFolder_16x16.png"} }; +const hp_DataType contentFileSystemModel::func_type[FILE_TYPE]={ + HP_PROG, + HP_LIST, + HP_MATRIX, + HP_NOTE, + HP_MAIN}; + +const QString contentFileSystemModel::file_type[FILE_TYPE]={"hpprgm", + "hplist", + "hpmat", + "hpnote", + ""}; contentFileSystemModel::contentFileSystemModel(QObject * parent) :QFileSystemModel(parent) @@ -22,6 +38,98 @@ contentFileSystemModel::contentFileSystemModel(QObject * parent) } +//Get and pass on the data to be dragged +QMimeData* contentFileSystemModel::mimeData(const QModelIndexList &indexes) const +{ + + QMimeData *mimeDataPtr = new QMimeData(); + QByteArray mydata; + + qDebug()<<"contentFileSystemModel::mimeData"; + + mimeDataPtr->setData("application/x-qstandarditemmodeldatalist",mydata); + + /* Store row id list */ + QList rowIdList; + int rowId; + foreach (QModelIndex index, indexes) { + if (index.isValid()) { + rowId = index.row(); + + if (!rowIdList.contains(rowId)) { + rowIdList << rowId; + } + } + } + + return mimeDataPtr; +} + +//Set drop actions supported +Qt::DropActions contentFileSystemModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction| Qt::TargetMoveAction; +} + +//Not sure that this is neccesary. Item should control this +Qt::ItemFlags contentFileSystemModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags defaultFlags = QFileSystemModel::flags(index); + + if (index.isValid()) + return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; + else + return Qt::ItemIsDropEnabled | defaultFlags; +} + +//Allow drop in location +bool contentFileSystemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + return true; +} + +//Process the drop action +bool contentFileSystemModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, + int column, const QModelIndex &parent) +{ + qDebug()<<"contentFileSystemModel::DropMineData"; + if (action == Qt::IgnoreAction) { + return true; + } + + if (column > 1) { + return false; + } + + int position; + + if (row != -1) { + position = row; + } else if (parent.isValid()) { + position = parent.row(); + } else { + position = rowCount(QModelIndex()); + } + +// QByteArray encodedData = data->data("application/text.list"); +// QDataStream stream(&encodedData, QIODevice::ReadOnly); + + /* Retrieve row id */ + QList rowIdList; +// while (!stream.atEnd()) { +// QString text; +// stream >> text; +// rowIdList << text.toInt(); +// } + + /* Insert rows (one by one) */ +// foreach(int rowId, rowIdList) { +// insertRow(position, parent, rowId); +// } + + return true; +} + QVariant contentFileSystemModel::data( const QModelIndex &index, int role ) const { if( role == Qt::DecorationRole ) @@ -42,3 +150,56 @@ QVariant contentFileSystemModel::data( const QModelIndex &index, int role ) cons } return QFileSystemModel::data(index, role); } + +void contentFileSystemModel::clickAction(QMdiArea * mdiwin, QModelIndex &index) { + + hp_mdiTextEdit * hptextedit = nullptr; + hp_DataStruct filedata; + AbstractData * data=nullptr; + + QFileInfo info = contentFileSystemModel::fileInfo(index); + QFile file(info.absoluteFilePath()); + if (file.open(QIODevice::ReadOnly),QFileDevice::AutoCloseHandle) { + QDataStream in(&file); + + filedata=getFileType(info); + + switch (filedata.type) { + + case HP_PROG: { + + data = new Program(filedata.filename, HP_PROG, QStringLiteral("")); + data->parseData(in); + } + break; + default: ; + } + + if (hptextedit==nullptr) + hptextedit = new hp_mdiTextEdit(mdiwin,filedata, data); + if (hptextedit!=nullptr) + hptextedit ->show(); + + file.close(); + } + qDebug()<<"ClickAction "< #include +#include +#include +#include "hpdata.h" class contentFileSystemModel : public QFileSystemModel { @@ -9,9 +12,20 @@ class contentFileSystemModel : public QFileSystemModel public: contentFileSystemModel(QObject * parent=nullptr); virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, + int column, const QModelIndex &parent); + QMimeData* mimeData(const QModelIndexList &indexes) const; + Qt::DropActions supportedDropActions() const; + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + + Qt::ItemFlags flags(const QModelIndex &index) const; + void clickAction(QMdiArea * mdiwin,QModelIndex &index); + hp_DataStruct getFileType(QFileInfo info); private: const static QString filetype_list[][2]; + const static hp_DataType func_type[]; + const static QString file_type[]; }; #endif // CONTENTFILESYSTEMMODEL_H diff --git a/hp_mditexteditor.cpp b/hp_mditexteditor.cpp index f90d6c2..3822ec6 100644 --- a/hp_mditexteditor.cpp +++ b/hp_mditexteditor.cpp @@ -3,7 +3,7 @@ #include "hpdata.h" #include "abstractdata.h" -hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, hpCalcData * calc) +hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, AbstractData * calcData) :QMdiSubWindow(parent) { setMinimumSize(200,200); @@ -11,17 +11,29 @@ hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, hpCalcDat setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); hptreeitem=treeItem; - hpcalc = calc; + data = calcData; filename=treeItem->getFileName(); type=treeItem->getType(); - if (hpcalc) { - data=calc->getData(filename,type); - } setup(); setWindowTitle(filename); } +hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hp_DataStruct filedata, AbstractData * calcData) + :QMdiSubWindow(parent) +{ + setMinimumSize(200,200); + setMaximumSize(1000,1000); + setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); + + hptreeitem=nullptr; + data = calcData; + filename=filedata.filename; + type=filedata.type; + setup(); + setWindowTitle(filename); +} + void hp_mdiTextEdit::setup() { QString text; diff --git a/hp_mditexteditor.h b/hp_mditexteditor.h index 4680713..19816af 100644 --- a/hp_mditexteditor.h +++ b/hp_mditexteditor.h @@ -20,14 +20,16 @@ protected: textEditor * textEdit =nullptr; hpTreeItem * hptreeitem =nullptr; - hpCalcData * hpcalc =nullptr; +// hpCalcData * hpcalc =nullptr; QString filename; hp_DataType type; AbstractData * data =nullptr; public: hp_mdiTextEdit(QWidget * parent = nullptr, hpTreeItem * treeItem = nullptr, - hpCalcData * dataStore =nullptr); + AbstractData * calcData =nullptr); + hp_mdiTextEdit(QWidget * parent, hp_DataStruct filename, + AbstractData * calcData); void setup(); void show(); ~hp_mdiTextEdit(); diff --git a/hp_mdivariableedit.cpp b/hp_mdivariableedit.cpp index 850523a..36b1ddf 100644 --- a/hp_mdivariableedit.cpp +++ b/hp_mdivariableedit.cpp @@ -18,7 +18,7 @@ hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent, setup(); - setWindowTitle(treeItem->getFileName()); + setWindowTitle(filename); } void hp_mdiVariableEdit::setup() { @@ -37,8 +37,6 @@ void hp_mdiVariableEdit::show() { QMdiSubWindow::show(); } - - hp_mdiVariableEdit::~hp_mdiVariableEdit() { if (tableView) diff --git a/hp_mdivariableedit.h b/hp_mdivariableedit.h index 8c02f4c..ef29cc1 100644 --- a/hp_mdivariableedit.h +++ b/hp_mdivariableedit.h @@ -28,6 +28,10 @@ public: hpTreeItem * treeItem = nullptr, hpCalcData * dataStore =nullptr ); +// explicit hp_mdiVariableEdit(QWidget *parent, +// hp_DataStruct filedata, +// hpCalcData * dataStore +// ); void show(); ~hp_mdiVariableEdit(); diff --git a/hp_mdiwindow.cpp b/hp_mdiwindow.cpp index a345482..40d542f 100644 --- a/hp_mdiwindow.cpp +++ b/hp_mdiwindow.cpp @@ -3,7 +3,7 @@ hp_MdiWindow::hp_MdiWindow(QWidget * parent) :QMdiSubWindow(parent) { - setMinimumSize(400,400); + setMinimumSize(500,400); setMaximumSize(1000,1000); setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); setup(); diff --git a/hp_mdiwindow.ui b/hp_mdiwindow.ui index 741e015..2589d97 100644 --- a/hp_mdiwindow.ui +++ b/hp_mdiwindow.ui @@ -10,6 +10,12 @@ 320 + + + 400 + 200 + + LogWindow diff --git a/hpdata.h b/hpdata.h index 0e143f8..d359f63 100644 --- a/hpdata.h +++ b/hpdata.h @@ -34,8 +34,9 @@ struct hp_Settings { }; -struct hpDataStruct { - +struct hp_DataStruct { + QString filename; + hp_DataType type; }; class hpCalcData; diff --git a/hptreeitem.cpp b/hptreeitem.cpp index 909868f..370d5a2 100644 --- a/hptreeitem.cpp +++ b/hptreeitem.cpp @@ -52,6 +52,9 @@ hpTreeItem::hpTreeItem(const QString & name,hpCalcData * hpDataStore,int flag) setEditable(0); setDataStore(hpDataStore); + setDragEnabled(true); + setDropEnabled(true); + filename=name; if (flag==0) @@ -86,6 +89,7 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) { hp_infoDialog * hpinfodlg; hp_Information hpinfo; hpCalcData * calc; + hp_DataStruct hpdata; calc=getDataStore(); AbstractData * data; @@ -156,17 +160,27 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) { hpCalcData * dataStore; dataStore = getDataStore(); + AbstractData * data =nullptr; + dataStore = getDataStore(); + if (dataStore) { + data=dataStore->getData(getFileName(),getType()); + } + if (hptextedit==nullptr) - hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore); + hptextedit = new hp_mdiTextEdit(mdiwin,this, data); if (hptextedit!=nullptr) hptextedit ->show(); } break; case HP_PROG: { hpCalcData * dataStore; + AbstractData * data =nullptr; dataStore = getDataStore(); + if (dataStore) { + data=dataStore->getData(getFileName(),getType()); + } if (hptextedit==nullptr) - hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore); + hptextedit = new hp_mdiTextEdit(mdiwin,this, data); if (hptextedit!=nullptr) hptextedit ->show(); } @@ -536,3 +550,4 @@ int hpTreeItem::findFile(QString dataname) { return 0; } + diff --git a/hptreeitem.h b/hptreeitem.h index 2021f40..069236a 100644 --- a/hptreeitem.h +++ b/hptreeitem.h @@ -42,6 +42,7 @@ public: void addFile(AbstractData *); void addChild(AbstractData * obj); + public slots: void dataChange(hp_Change hpchange); diff --git a/mainwindow.cpp b/mainwindow.cpp index b9cc6cb..b3ba828 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -60,9 +60,9 @@ MainWindow::MainWindow(QWidget *parent) : QSettings appSettings("IRGP","QtHPconnect"); //Set config file location (default used) - // appSettings->setPath(QSettings::NativeFormat,QSettings::UserScope,""); - - appSettings.setValue("contentPath",QDir::homePath()+"/.local/share/qthpconnect/contents/"); + if(!appSettings.contains("contentPath")) { + appSettings.setValue("contentPath",QDir::homePath()+"/.local/share/qthpconnect/contents/"); + } //error handler main_err = new errorHandler(this); @@ -83,10 +83,15 @@ MainWindow::MainWindow(QWidget *parent) : setTreeMenu(); setContentWindow(); - + //Hack to fix QT resizing bug + resizeDocks({ui->dwCalculator,ui->dwContent},{0,0}, Qt::Horizontal); //setup trees ui->tvCalculators->setModel(hpTreeModel); + ui->tvCalculators->setAcceptDrops(true); + ui->tvCalculators->setDragEnabled(true); + ui->tvCalculators->setDragDropMode(QAbstractItemView::DragDrop); + ui->tvCalculators->setDropIndicatorShown(true); ui->tvCalculators->show(); QItemSelectionModel *selectionModel= ui->tvCalculators->selectionModel(); @@ -98,6 +103,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionMessages,SIGNAL(triggered()),this,SLOT(showMessage())); connect(ui->actionMonitor,SIGNAL(triggered()),this,SLOT(showMonitor())); connect(ui->tvCalculators,SIGNAL(clicked(QModelIndex)),this,SLOT(clickedCalculator(QModelIndex))); + connect(ui->tvContent,SIGNAL(clicked(QModelIndex)),this,SLOT(clickedContent(QModelIndex))); connect(ui->actionLog,SIGNAL(triggered()),this,SLOT(createLogWindow())); connect(ui->actionTest,SIGNAL(triggered()),this,SLOT(testFunction())); connect(ui->actionTestSettings,SIGNAL(triggered()),this,SLOT(onTestSettings())); @@ -245,12 +251,13 @@ void MainWindow::openHP() { hpCalcData * data; - qDebug()<<"openHP"; + qDebug()<<"openHP"; QString name1 = QString("IAN"); data=hpTreeModel->getCalculator(name1); if(data) { - qDebug()<<"Read Info"; + qDebug()<<"Read Info"; data->readInfo(); + data->readSettings(); } else { qDebug()<<"In open Func"; @@ -327,6 +334,12 @@ void MainWindow::clickedCalculator(QModelIndex index) { log(item->data(Qt::DisplayRole).toString()); } +void MainWindow::clickedContent(QModelIndex index) { + + contentModel.clickAction(getMdi(),index); +} + + void MainWindow::about() { QMessageBox::about(this, tr("About QtHP Connect"), @@ -380,6 +393,11 @@ void MainWindow::setContentWindow() { const QModelIndex rootIndex = contentModel.index(QDir::cleanPath(path)); if (rootIndex.isValid()) { ui->tvContent->setRootIndex(rootIndex); + ui->tvContent->setAcceptDrops(true); + ui->tvContent->setDragEnabled(true); + ui->tvContent->setDragDropMode(QAbstractItemView::DragDrop); + ui->tvContent->setDropIndicatorShown(true); + } } } diff --git a/mainwindow.h b/mainwindow.h index 2fdd006..52ece5c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -55,6 +55,7 @@ private slots: void showMonitor(); void dataChange(hp_Change); void clickedCalculator(QModelIndex); + void clickedContent(QModelIndex); void exit(); void createLogWindow(); void testFunction(); diff --git a/mainwindow.ui b/mainwindow.ui index b1d071a..d550eed 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -18,6 +18,18 @@ + + + 0 + 0 + + + + + 500 + 0 + + Qt::ScrollBarAsNeeded @@ -98,14 +110,14 @@ - + 0 0 - 104 + 200 184 @@ -117,7 +129,7 @@ - 200 + 300 200 @@ -191,14 +203,14 @@ - + 0 0 - 200 + 300 130 @@ -227,7 +239,7 @@ - + 0 0 @@ -257,7 +269,7 @@ - + 0 0 diff --git a/options.cpp b/options.cpp index 01cb80c..655befa 100644 --- a/options.cpp +++ b/options.cpp @@ -1,11 +1,32 @@ #include "options.h" #include "ui_options.h" +#include "global.h" +#include + Options::Options(QWidget *parent) : QDialog(parent), ui(new Ui::Options) { ui->setupUi(this); + QString path; + + QSettings appSettings("IRGP","QtHPconnect"); + path=appSettings.value("contentPath").toString(); + ui->filePath->setText(path); +} + +void Options::accept() { + + QString path; + path=ui->filePath->text(); + QSettings appSettings("IRGP","QtHPconnect"); + appSettings.setValue("contentPath",path); + QDialog::accept(); +} + +void Options::reject() { + QDialog::reject(); } Options::~Options() diff --git a/options.h b/options.h index 8a07f1c..c897a4f 100644 --- a/options.h +++ b/options.h @@ -13,6 +13,8 @@ class Options : public QDialog public: explicit Options(QWidget *parent = 0); + void accept(); + void reject(); ~Options(); private: diff --git a/options.ui b/options.ui index 9c0f02b..595111b 100644 --- a/options.ui +++ b/options.ui @@ -29,28 +29,72 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + - 20 - 30 - 58 - 18 - - - - File Path: - - - - - - 90 + 10 20 - 521 - 32 + 621 + 91 + + + + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 80 + 40 + 521 + 32 + + + + + + + 10 + 30 + 58 + 51 + + + + File Path: + + + + + + 10 + 10 + 141 + 18 + + + + Environment + + diff --git a/treemodel.cpp b/treemodel.cpp index afa8ec2..ddc719a 100644 --- a/treemodel.cpp +++ b/treemodel.cpp @@ -1,12 +1,15 @@ #include "treemodel.h" #include "hptreeitem.h" +#include +#include treeModel::treeModel(QObject *parent) :QStandardItemModel(parent) { setItemPrototype(new hpTreeItem()); createRoot(); - setParent(parent); + setParent(parent); + } int treeModel::createRoot() @@ -87,6 +90,97 @@ void treeModel::setHpCalcData(QString name, hpCalcData * data, hpTreeItem * tree return; } +Qt::DropActions treeModel::supportedDropActions() const +{ + return Qt::CopyAction | Qt::MoveAction | Qt::TargetMoveAction; +} + +//Get and pass on the data to be dragged +QMimeData* treeModel::mimeData(const QModelIndexList &indexes) const +{ + + QMimeData *mimeDataPtr = new QMimeData(); + QByteArray mydata; + + qDebug()<<"treeModel::mimeData"; + + mimeDataPtr->setData("application/x-qabstractmodeldatalist",mydata); + + /* Store row id list */ + QList rowIdList; + int rowId; + foreach (QModelIndex index, indexes) { + if (index.isValid()) { + rowId = index.row(); + + if (!rowIdList.contains(rowId)) { + rowIdList << rowId; + } + } + } + + return mimeDataPtr; +} + +//Allow drop in location +bool treeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + return true; +} + +//Process the drop action +bool treeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, + int column, const QModelIndex &parent) +{ + qDebug()<<"treemodel::DropMineData"; + if (action == Qt::IgnoreAction) { + return true; + } + + if (column > 1) { + return false; + } + + int position; + + if (row != -1) { + position = row; + } else if (parent.isValid()) { + position = parent.row(); + } else { + position = rowCount(QModelIndex()); + } + +// QByteArray encodedData = data->data("application/text.list"); +// QDataStream stream(&encodedData, QIODevice::ReadOnly); + + /* Retrieve row id */ + QList rowIdList; +// while (!stream.atEnd()) { +// QString text; +// stream >> text; +// rowIdList << text.toInt(); +// } + + /* Insert rows (one by one) */ +// foreach(int rowId, rowIdList) { +// insertRow(position, parent, rowId); +// } + + return true; +} + +Qt::ItemFlags treeModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index); + + if (index.isValid()) + return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; + else + return Qt::ItemIsDropEnabled | defaultFlags; +} + + treeModel::~treeModel() { delete rootNode; diff --git a/treemodel.h b/treemodel.h index 83f8435..b17a9bc 100644 --- a/treemodel.h +++ b/treemodel.h @@ -33,6 +33,12 @@ public: hpCalcData * getHpCalcData(QString name); void setHpCalcData(QString name, hpCalcData * , hpTreeItem *); QString getLastDataKey(); + bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, + int column, const QModelIndex &parent); + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; + Qt::DropActions supportedDropActions() const; + QMimeData* mimeData(const QModelIndexList &) const; + Qt::ItemFlags flags(const QModelIndex&) const; }; diff --git a/vartablemodel.cpp b/vartablemodel.cpp index b1e5cc0..2c7b2c6 100644 --- a/vartablemodel.cpp +++ b/vartablemodel.cpp @@ -49,12 +49,26 @@ varTableModel::varTableModel(QObject *parent, hp_DataType dtype) :QAbstractTableModel(parent) { + q_parent=parent; hpcalc = dataStore; filename=file; type=dtype; setup(); } +//REWORK! +QModelIndex varTableModel::parent(const QModelIndex &index) const { + + + return QModelIndex(); +} + +//rework! +QModelIndex varTableModel::index(int row, int column, const QModelIndex &parent) const { + + return createIndex(row,column); +} + void varTableModel::setup() { if (hpcalc) { @@ -67,7 +81,7 @@ void varTableModel::setup() return; } -int varTableModel::rowCount(const QModelIndex & /*parent*/) const +int varTableModel::rowCount(const QModelIndex & parent) const { int size=16; //should be zero if (type==HP_LIST) { diff --git a/vartablemodel.h b/vartablemodel.h index 01727ef..5da53ef 100644 --- a/vartablemodel.h +++ b/vartablemodel.h @@ -11,7 +11,9 @@ class varTableModel: public QAbstractTableModel { Q_OBJECT + private: + QObject * q_parent; const static QStringList real_header; const static QStringList complex_header; hpCalcData * hpcalc =nullptr; @@ -26,6 +28,8 @@ public: hpCalcData * dataStore =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; 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;