mirror of
https://github.com/Indy970/QtHPConnect
synced 2025-02-07 08:46:28 +01:00
File Read
This commit is contained in:
parent
fc18ff768d
commit
780e808e5a
23 changed files with 546 additions and 61 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QByteArrayMatcher>
|
#include <QByteArrayMatcher>
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "abstractdata.h"
|
#include "abstractdata.h"
|
||||||
|
@ -283,6 +284,10 @@ void AbstractData::parseData() {
|
||||||
qDebug()<<"AbstractData::parseData";
|
qDebug()<<"AbstractData::parseData";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AbstractData::parseData(QDataStream& in) {
|
||||||
|
qDebug()<<"AbstractData::parseData";
|
||||||
|
}
|
||||||
|
|
||||||
//REAL
|
//REAL
|
||||||
//
|
//
|
||||||
Application::Application(QString name_in, hp_DataType type_in):
|
Application::Application(QString name_in, hp_DataType type_in):
|
||||||
|
@ -826,19 +831,40 @@ QString Program::getProg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::setProg(QString data_in) {
|
void Program::setProg(QString data_in) {
|
||||||
|
data=data_in.toUtf8();
|
||||||
text=data_in;
|
text=data_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Program::parseData() {
|
void Program::parseData() {
|
||||||
|
|
||||||
int16_t len1,len2;
|
QTextCodec * codec = QTextCodec::codecForName("UTF8");
|
||||||
QTextCodec * codec = QTextCodec::codecForName("UTF-16LE");
|
|
||||||
|
|
||||||
QByteArray a1;
|
QByteArray a1;
|
||||||
a1=getData();
|
a1=getData();
|
||||||
text = codec->toUnicode(a1);
|
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()<<a1;
|
||||||
|
|
||||||
|
// char cstr[20];
|
||||||
|
// in.readRawData(cstr,20);
|
||||||
|
// str=QString(cstr);
|
||||||
|
// qDebug()<<str;
|
||||||
|
|
||||||
|
// a1=getData();
|
||||||
|
text = codec->toUnicode(a1);
|
||||||
|
}
|
||||||
|
|
||||||
//Notes
|
//Notes
|
||||||
Notes::Notes(QString name_in, hp_DataType type_in, QString data_in):
|
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<len1)&&(i<len2)) {
|
||||||
|
if (data[i]!=datain[i]) {
|
||||||
|
log(QString("Settings diff at:%1").arg(i));
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data = datain;
|
||||||
|
len1=data.size();
|
||||||
|
len2=datain.size();
|
||||||
|
log(QString("Settings Compare 2 %1 %2").arg(len1).arg(len2));
|
||||||
|
|
||||||
|
//parseData();
|
||||||
|
}
|
||||||
|
|
|
@ -47,9 +47,10 @@ public:
|
||||||
hp_DataType getType();
|
hp_DataType getType();
|
||||||
void setFileCode(hp_pkt_type);
|
void setFileCode(hp_pkt_type);
|
||||||
hp_pkt_type getFileCode();
|
hp_pkt_type getFileCode();
|
||||||
void setData(QByteArray);
|
virtual void setData(QByteArray);
|
||||||
virtual QByteArray getData();
|
virtual QByteArray getData();
|
||||||
virtual void parseData();
|
virtual void parseData();
|
||||||
|
virtual void parseData(QDataStream& in);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,11 +130,13 @@ class Program: public AbstractData
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
QString text;
|
QString text;
|
||||||
void parseData();
|
|
||||||
public:
|
public:
|
||||||
Program(QString, hp_DataType, QString);
|
Program(QString, hp_DataType, QString);
|
||||||
void setProg(QString);
|
void setProg(QString);
|
||||||
QString getProg();
|
QString getProg();
|
||||||
|
void parseData();
|
||||||
|
virtual void parseData(QDataStream& in);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Notes: public AbstractData
|
class Notes: public AbstractData
|
||||||
|
@ -174,8 +177,10 @@ private:
|
||||||
QString text;
|
QString text;
|
||||||
QString format;
|
QString format;
|
||||||
void parseData();
|
void parseData();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Settings(QString, hp_DataType);
|
Settings(QString, hp_DataType);
|
||||||
|
virtual void setData(QByteArray);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ABSTRACTDATA_H
|
#endif // ABSTRACTDATA_H
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "cntfilesystemmodel.h"
|
#include "cntfilesystemmodel.h"
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
#include "hp_mditexteditor.h"
|
||||||
|
|
||||||
#define FILE_NUM 9
|
#define FILE_NUM 9
|
||||||
|
#define FILE_TYPE 5
|
||||||
//Todo fix for all file types
|
//Todo fix for all file types
|
||||||
const QString contentFileSystemModel::filetype_list[FILE_NUM][2]={{".hpprgm",":/icons/apps_32x32.png"},
|
const QString contentFileSystemModel::filetype_list[FILE_NUM][2]={{"hpprgm",":/icons/apps_16x16.png"},
|
||||||
{"CAS Vars",":/icons/casFolder_32x32.png"},
|
{"CAS Vars",":/icons/casFolder_16x16.png"},
|
||||||
{"Complex",":/icons/complex_32x32.png"},
|
{"Complex",":/icons/complex_16x16.png"},
|
||||||
{"hplist",":/icons/list_16x16.png"},
|
{"hplist",":/icons/list_16x16.png"},
|
||||||
{"Matrices",":/icons/table_32x32.png"},
|
{"Matrices",":/icons/table_16x16.png"},
|
||||||
{"Notes",":/icons/note_32x32.png"},
|
{"Notes",":/icons/note_16x16.png"},
|
||||||
{"hpprgm",":/icons/program_16x16.png"},
|
{"hpprgm",":/icons/program_16x16.png"},
|
||||||
{"Real",":/icons/real_32x32.png"},
|
{"Real",":/icons/real_16x16.png"},
|
||||||
{"Variables",":/icons/varFolder_32x32.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)
|
contentFileSystemModel::contentFileSystemModel(QObject * parent)
|
||||||
:QFileSystemModel(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<int> 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<int> 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 {
|
QVariant contentFileSystemModel::data( const QModelIndex &index, int role ) const {
|
||||||
|
|
||||||
if( role == Qt::DecorationRole )
|
if( role == Qt::DecorationRole )
|
||||||
|
@ -42,3 +150,56 @@ QVariant contentFileSystemModel::data( const QModelIndex &index, int role ) cons
|
||||||
}
|
}
|
||||||
return QFileSystemModel::data(index, role);
|
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 "<<info.absoluteFilePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
hp_DataStruct contentFileSystemModel::getFileType(QFileInfo info) {
|
||||||
|
hp_DataStruct filedata;
|
||||||
|
int i;
|
||||||
|
QString suffix;
|
||||||
|
hp_DataType type=HP_MAIN;
|
||||||
|
suffix=info.completeSuffix();
|
||||||
|
for (i=0;i<FILE_TYPE;i++) {
|
||||||
|
if (suffix==file_type[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
type=func_type[i];
|
||||||
|
if (type!=HP_MAIN) {
|
||||||
|
filedata.filename=info.completeBaseName();
|
||||||
|
filedata.type=type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filedata;
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define CONTENTFILESYSTEMMODEL_H
|
#define CONTENTFILESYSTEMMODEL_H
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QFileSystemModel>
|
#include <QFileSystemModel>
|
||||||
|
#include <QDropEvent>
|
||||||
|
#include <QMdiArea>
|
||||||
|
#include "hpdata.h"
|
||||||
|
|
||||||
class contentFileSystemModel : public QFileSystemModel
|
class contentFileSystemModel : public QFileSystemModel
|
||||||
{
|
{
|
||||||
|
@ -9,9 +12,20 @@ class contentFileSystemModel : public QFileSystemModel
|
||||||
public:
|
public:
|
||||||
contentFileSystemModel(QObject * parent=nullptr);
|
contentFileSystemModel(QObject * parent=nullptr);
|
||||||
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
|
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:
|
private:
|
||||||
const static QString filetype_list[][2];
|
const static QString filetype_list[][2];
|
||||||
|
const static hp_DataType func_type[];
|
||||||
|
const static QString file_type[];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTENTFILESYSTEMMODEL_H
|
#endif // CONTENTFILESYSTEMMODEL_H
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "hpdata.h"
|
#include "hpdata.h"
|
||||||
#include "abstractdata.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)
|
:QMdiSubWindow(parent)
|
||||||
{
|
{
|
||||||
setMinimumSize(200,200);
|
setMinimumSize(200,200);
|
||||||
|
@ -11,13 +11,25 @@ hp_mdiTextEdit::hp_mdiTextEdit(QWidget * parent,hpTreeItem * treeItem, hpCalcDat
|
||||||
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
|
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
|
||||||
|
|
||||||
hptreeitem=treeItem;
|
hptreeitem=treeItem;
|
||||||
hpcalc = calc;
|
data = calcData;
|
||||||
filename=treeItem->getFileName();
|
filename=treeItem->getFileName();
|
||||||
type=treeItem->getType();
|
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();
|
setup();
|
||||||
setWindowTitle(filename);
|
setWindowTitle(filename);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,16 @@ protected:
|
||||||
|
|
||||||
textEditor * textEdit =nullptr;
|
textEditor * textEdit =nullptr;
|
||||||
hpTreeItem * hptreeitem =nullptr;
|
hpTreeItem * hptreeitem =nullptr;
|
||||||
hpCalcData * hpcalc =nullptr;
|
// hpCalcData * hpcalc =nullptr;
|
||||||
QString filename;
|
QString filename;
|
||||||
hp_DataType type;
|
hp_DataType type;
|
||||||
AbstractData * data =nullptr;
|
AbstractData * data =nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
hp_mdiTextEdit(QWidget * parent = nullptr, hpTreeItem * treeItem = nullptr,
|
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 setup();
|
||||||
void show();
|
void show();
|
||||||
~hp_mdiTextEdit();
|
~hp_mdiTextEdit();
|
||||||
|
|
|
@ -18,7 +18,7 @@ hp_mdiVariableEdit::hp_mdiVariableEdit(QWidget *parent,
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
setWindowTitle(treeItem->getFileName());
|
setWindowTitle(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hp_mdiVariableEdit::setup() {
|
void hp_mdiVariableEdit::setup() {
|
||||||
|
@ -37,8 +37,6 @@ void hp_mdiVariableEdit::show() {
|
||||||
QMdiSubWindow::show();
|
QMdiSubWindow::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hp_mdiVariableEdit::~hp_mdiVariableEdit() {
|
hp_mdiVariableEdit::~hp_mdiVariableEdit() {
|
||||||
|
|
||||||
if (tableView)
|
if (tableView)
|
||||||
|
|
|
@ -28,6 +28,10 @@ public:
|
||||||
hpTreeItem * treeItem = nullptr,
|
hpTreeItem * treeItem = nullptr,
|
||||||
hpCalcData * dataStore =nullptr
|
hpCalcData * dataStore =nullptr
|
||||||
);
|
);
|
||||||
|
// explicit hp_mdiVariableEdit(QWidget *parent,
|
||||||
|
// hp_DataStruct filedata,
|
||||||
|
// hpCalcData * dataStore
|
||||||
|
// );
|
||||||
void show();
|
void show();
|
||||||
~hp_mdiVariableEdit();
|
~hp_mdiVariableEdit();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
hp_MdiWindow::hp_MdiWindow(QWidget * parent)
|
hp_MdiWindow::hp_MdiWindow(QWidget * parent)
|
||||||
:QMdiSubWindow(parent)
|
:QMdiSubWindow(parent)
|
||||||
{
|
{
|
||||||
setMinimumSize(400,400);
|
setMinimumSize(500,400);
|
||||||
setMaximumSize(1000,1000);
|
setMaximumSize(1000,1000);
|
||||||
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
|
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
|
||||||
setup();
|
setup();
|
||||||
|
|
|
@ -10,6 +10,12 @@
|
||||||
<height>320</height>
|
<height>320</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>200</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>LogWindow</string>
|
<string>LogWindow</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
5
hpdata.h
5
hpdata.h
|
@ -34,8 +34,9 @@ struct hp_Settings {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct hpDataStruct {
|
struct hp_DataStruct {
|
||||||
|
QString filename;
|
||||||
|
hp_DataType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class hpCalcData;
|
class hpCalcData;
|
||||||
|
|
|
@ -52,6 +52,9 @@ hpTreeItem::hpTreeItem(const QString & name,hpCalcData * hpDataStore,int flag)
|
||||||
setEditable(0);
|
setEditable(0);
|
||||||
setDataStore(hpDataStore);
|
setDataStore(hpDataStore);
|
||||||
|
|
||||||
|
setDragEnabled(true);
|
||||||
|
setDropEnabled(true);
|
||||||
|
|
||||||
filename=name;
|
filename=name;
|
||||||
|
|
||||||
if (flag==0)
|
if (flag==0)
|
||||||
|
@ -86,6 +89,7 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
|
||||||
hp_infoDialog * hpinfodlg;
|
hp_infoDialog * hpinfodlg;
|
||||||
hp_Information hpinfo;
|
hp_Information hpinfo;
|
||||||
hpCalcData * calc;
|
hpCalcData * calc;
|
||||||
|
hp_DataStruct hpdata;
|
||||||
calc=getDataStore();
|
calc=getDataStore();
|
||||||
AbstractData * data;
|
AbstractData * data;
|
||||||
|
|
||||||
|
@ -156,17 +160,27 @@ void hpTreeItem::clickAction(QMdiArea * mdiwin) {
|
||||||
hpCalcData * dataStore;
|
hpCalcData * dataStore;
|
||||||
dataStore = getDataStore();
|
dataStore = getDataStore();
|
||||||
|
|
||||||
|
AbstractData * data =nullptr;
|
||||||
|
dataStore = getDataStore();
|
||||||
|
if (dataStore) {
|
||||||
|
data=dataStore->getData(getFileName(),getType());
|
||||||
|
}
|
||||||
|
|
||||||
if (hptextedit==nullptr)
|
if (hptextedit==nullptr)
|
||||||
hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore);
|
hptextedit = new hp_mdiTextEdit(mdiwin,this, data);
|
||||||
if (hptextedit!=nullptr)
|
if (hptextedit!=nullptr)
|
||||||
hptextedit ->show();
|
hptextedit ->show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HP_PROG: {
|
case HP_PROG: {
|
||||||
hpCalcData * dataStore;
|
hpCalcData * dataStore;
|
||||||
|
AbstractData * data =nullptr;
|
||||||
dataStore = getDataStore();
|
dataStore = getDataStore();
|
||||||
|
if (dataStore) {
|
||||||
|
data=dataStore->getData(getFileName(),getType());
|
||||||
|
}
|
||||||
if (hptextedit==nullptr)
|
if (hptextedit==nullptr)
|
||||||
hptextedit = new hp_mdiTextEdit(mdiwin,this, dataStore);
|
hptextedit = new hp_mdiTextEdit(mdiwin,this, data);
|
||||||
if (hptextedit!=nullptr)
|
if (hptextedit!=nullptr)
|
||||||
hptextedit ->show();
|
hptextedit ->show();
|
||||||
}
|
}
|
||||||
|
@ -536,3 +550,4 @@ int hpTreeItem::findFile(QString dataname) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
void addFile(AbstractData *);
|
void addFile(AbstractData *);
|
||||||
void addChild(AbstractData * obj);
|
void addChild(AbstractData * obj);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void dataChange(hp_Change hpchange);
|
void dataChange(hp_Change hpchange);
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
QSettings appSettings("IRGP","QtHPconnect");
|
QSettings appSettings("IRGP","QtHPconnect");
|
||||||
|
|
||||||
//Set config file location (default used)
|
//Set config file location (default used)
|
||||||
// appSettings->setPath(QSettings::NativeFormat,QSettings::UserScope,"");
|
if(!appSettings.contains("contentPath")) {
|
||||||
|
|
||||||
appSettings.setValue("contentPath",QDir::homePath()+"/.local/share/qthpconnect/contents/");
|
appSettings.setValue("contentPath",QDir::homePath()+"/.local/share/qthpconnect/contents/");
|
||||||
|
}
|
||||||
|
|
||||||
//error handler
|
//error handler
|
||||||
main_err = new errorHandler(this);
|
main_err = new errorHandler(this);
|
||||||
|
@ -83,10 +83,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
setTreeMenu();
|
setTreeMenu();
|
||||||
setContentWindow();
|
setContentWindow();
|
||||||
|
|
||||||
|
//Hack to fix QT resizing bug
|
||||||
|
resizeDocks({ui->dwCalculator,ui->dwContent},{0,0}, Qt::Horizontal);
|
||||||
|
|
||||||
//setup trees
|
//setup trees
|
||||||
ui->tvCalculators->setModel(hpTreeModel);
|
ui->tvCalculators->setModel(hpTreeModel);
|
||||||
|
ui->tvCalculators->setAcceptDrops(true);
|
||||||
|
ui->tvCalculators->setDragEnabled(true);
|
||||||
|
ui->tvCalculators->setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
|
ui->tvCalculators->setDropIndicatorShown(true);
|
||||||
ui->tvCalculators->show();
|
ui->tvCalculators->show();
|
||||||
QItemSelectionModel *selectionModel= ui->tvCalculators->selectionModel();
|
QItemSelectionModel *selectionModel= ui->tvCalculators->selectionModel();
|
||||||
|
|
||||||
|
@ -98,6 +103,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
connect(ui->actionMessages,SIGNAL(triggered()),this,SLOT(showMessage()));
|
connect(ui->actionMessages,SIGNAL(triggered()),this,SLOT(showMessage()));
|
||||||
connect(ui->actionMonitor,SIGNAL(triggered()),this,SLOT(showMonitor()));
|
connect(ui->actionMonitor,SIGNAL(triggered()),this,SLOT(showMonitor()));
|
||||||
connect(ui->tvCalculators,SIGNAL(clicked(QModelIndex)),this,SLOT(clickedCalculator(QModelIndex)));
|
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->actionLog,SIGNAL(triggered()),this,SLOT(createLogWindow()));
|
||||||
connect(ui->actionTest,SIGNAL(triggered()),this,SLOT(testFunction()));
|
connect(ui->actionTest,SIGNAL(triggered()),this,SLOT(testFunction()));
|
||||||
connect(ui->actionTestSettings,SIGNAL(triggered()),this,SLOT(onTestSettings()));
|
connect(ui->actionTestSettings,SIGNAL(triggered()),this,SLOT(onTestSettings()));
|
||||||
|
@ -251,6 +257,7 @@ void MainWindow::openHP()
|
||||||
if(data) {
|
if(data) {
|
||||||
qDebug()<<"Read Info";
|
qDebug()<<"Read Info";
|
||||||
data->readInfo();
|
data->readInfo();
|
||||||
|
data->readSettings();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug()<<"In open Func";
|
qDebug()<<"In open Func";
|
||||||
|
@ -327,6 +334,12 @@ void MainWindow::clickedCalculator(QModelIndex index) {
|
||||||
log(item->data(Qt::DisplayRole).toString());
|
log(item->data(Qt::DisplayRole).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::clickedContent(QModelIndex index) {
|
||||||
|
|
||||||
|
contentModel.clickAction(getMdi(),index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::about()
|
void MainWindow::about()
|
||||||
{
|
{
|
||||||
QMessageBox::about(this, tr("About QtHP Connect"),
|
QMessageBox::about(this, tr("About QtHP Connect"),
|
||||||
|
@ -380,6 +393,11 @@ void MainWindow::setContentWindow() {
|
||||||
const QModelIndex rootIndex = contentModel.index(QDir::cleanPath(path));
|
const QModelIndex rootIndex = contentModel.index(QDir::cleanPath(path));
|
||||||
if (rootIndex.isValid()) {
|
if (rootIndex.isValid()) {
|
||||||
ui->tvContent->setRootIndex(rootIndex);
|
ui->tvContent->setRootIndex(rootIndex);
|
||||||
|
ui->tvContent->setAcceptDrops(true);
|
||||||
|
ui->tvContent->setDragEnabled(true);
|
||||||
|
ui->tvContent->setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
|
ui->tvContent->setDropIndicatorShown(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ private slots:
|
||||||
void showMonitor();
|
void showMonitor();
|
||||||
void dataChange(hp_Change);
|
void dataChange(hp_Change);
|
||||||
void clickedCalculator(QModelIndex);
|
void clickedCalculator(QModelIndex);
|
||||||
|
void clickedContent(QModelIndex);
|
||||||
void exit();
|
void exit();
|
||||||
void createLogWindow();
|
void createLogWindow();
|
||||||
void testFunction();
|
void testFunction();
|
||||||
|
|
|
@ -18,6 +18,18 @@
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QMdiArea" name="mdiArea">
|
<widget class="QMdiArea" name="mdiArea">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>500</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="verticalScrollBarPolicy">
|
<property name="verticalScrollBarPolicy">
|
||||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -98,14 +110,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDockWidget" name="dwCalculator">
|
<widget class="QDockWidget" name="dwCalculator">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>104</width>
|
<width>200</width>
|
||||||
<height>184</height>
|
<height>184</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -117,7 +129,7 @@
|
||||||
</property>
|
</property>
|
||||||
<property name="baseSize">
|
<property name="baseSize">
|
||||||
<size>
|
<size>
|
||||||
<width>200</width>
|
<width>300</width>
|
||||||
<height>200</height>
|
<height>200</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -191,14 +203,14 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDockWidget" name="dwContent">
|
<widget class="QDockWidget" name="dwContent">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>200</width>
|
<width>300</width>
|
||||||
<height>130</height>
|
<height>130</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
@ -227,7 +239,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDockWidget" name="dwMessenger">
|
<widget class="QDockWidget" name="dwMessenger">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -257,7 +269,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QDockWidget" name="dwMonitor">
|
<widget class="QDockWidget" name="dwMonitor">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
|
21
options.cpp
21
options.cpp
|
@ -1,11 +1,32 @@
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "ui_options.h"
|
#include "ui_options.h"
|
||||||
|
#include "global.h"
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
|
||||||
Options::Options(QWidget *parent) :
|
Options::Options(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::Options)
|
ui(new Ui::Options)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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()
|
Options::~Options()
|
||||||
|
|
|
@ -13,6 +13,8 @@ class Options : public QDialog
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Options(QWidget *parent = 0);
|
explicit Options(QWidget *parent = 0);
|
||||||
|
void accept();
|
||||||
|
void reject();
|
||||||
~Options();
|
~Options();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
58
options.ui
58
options.ui
|
@ -29,28 +29,72 @@
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QFrame" name="frame">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>20</y>
|
||||||
|
<width>621</width>
|
||||||
|
<height>91</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string extracomment="Set Global Settings"/>
|
||||||
|
</property>
|
||||||
|
<property name="statusTip">
|
||||||
|
<string extracomment="Set Global Settings"/>
|
||||||
|
</property>
|
||||||
|
<property name="whatsThis">
|
||||||
|
<string extracomment="Set Global Settings"/>
|
||||||
|
</property>
|
||||||
|
<property name="accessibleName">
|
||||||
|
<string extracomment="Settings"/>
|
||||||
|
</property>
|
||||||
|
<property name="accessibleDescription">
|
||||||
|
<string extracomment="Global Settings"/>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<widget class="QLineEdit" name="filePath">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>80</x>
|
||||||
|
<y>40</y>
|
||||||
|
<width>521</width>
|
||||||
|
<height>32</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>20</x>
|
<x>10</x>
|
||||||
<y>30</y>
|
<y>30</y>
|
||||||
<width>58</width>
|
<width>58</width>
|
||||||
<height>18</height>
|
<height>51</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>File Path:</string>
|
<string>File Path:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QLineEdit" name="lineEdit">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>90</x>
|
<x>10</x>
|
||||||
<y>20</y>
|
<y>10</y>
|
||||||
<width>521</width>
|
<width>141</width>
|
||||||
<height>32</height>
|
<height>18</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Environment</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "treemodel.h"
|
#include "treemodel.h"
|
||||||
#include "hptreeitem.h"
|
#include "hptreeitem.h"
|
||||||
|
#include <QStringListModel>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
treeModel::treeModel(QObject *parent)
|
treeModel::treeModel(QObject *parent)
|
||||||
:QStandardItemModel(parent)
|
:QStandardItemModel(parent)
|
||||||
|
@ -7,6 +9,7 @@ treeModel::treeModel(QObject *parent)
|
||||||
setItemPrototype(new hpTreeItem());
|
setItemPrototype(new hpTreeItem());
|
||||||
createRoot();
|
createRoot();
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int treeModel::createRoot()
|
int treeModel::createRoot()
|
||||||
|
@ -87,6 +90,97 @@ void treeModel::setHpCalcData(QString name, hpCalcData * data, hpTreeItem * tree
|
||||||
return;
|
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<int> 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<int> 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() {
|
treeModel::~treeModel() {
|
||||||
|
|
||||||
delete rootNode;
|
delete rootNode;
|
||||||
|
|
|
@ -33,6 +33,12 @@ public:
|
||||||
hpCalcData * getHpCalcData(QString name);
|
hpCalcData * getHpCalcData(QString name);
|
||||||
void setHpCalcData(QString name, hpCalcData * , hpTreeItem *);
|
void setHpCalcData(QString name, hpCalcData * , hpTreeItem *);
|
||||||
QString getLastDataKey();
|
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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,26 @@ varTableModel::varTableModel(QObject *parent,
|
||||||
hp_DataType dtype)
|
hp_DataType dtype)
|
||||||
:QAbstractTableModel(parent)
|
:QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
|
q_parent=parent;
|
||||||
hpcalc = dataStore;
|
hpcalc = dataStore;
|
||||||
filename=file;
|
filename=file;
|
||||||
type=dtype;
|
type=dtype;
|
||||||
setup();
|
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()
|
void varTableModel::setup()
|
||||||
{
|
{
|
||||||
if (hpcalc) {
|
if (hpcalc) {
|
||||||
|
@ -67,7 +81,7 @@ void varTableModel::setup()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int varTableModel::rowCount(const QModelIndex & /*parent*/) const
|
int varTableModel::rowCount(const QModelIndex & parent) const
|
||||||
{
|
{
|
||||||
int size=16; //should be zero
|
int size=16; //should be zero
|
||||||
if (type==HP_LIST) {
|
if (type==HP_LIST) {
|
||||||
|
|
|
@ -11,7 +11,9 @@ class varTableModel: public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QObject * q_parent;
|
||||||
const static QStringList real_header;
|
const static QStringList real_header;
|
||||||
const static QStringList complex_header;
|
const static QStringList complex_header;
|
||||||
hpCalcData * hpcalc =nullptr;
|
hpCalcData * hpcalc =nullptr;
|
||||||
|
@ -26,6 +28,8 @@ public:
|
||||||
hpCalcData * dataStore =nullptr,
|
hpCalcData * dataStore =nullptr,
|
||||||
QString file = QStringLiteral(""),
|
QString file = QStringLiteral(""),
|
||||||
hp_DataType dtype = HP_MAIN);
|
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 rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(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;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue