mirror of
https://github.com/Indy970/QtHPConnect
synced 2025-01-19 10:26: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 <QtMath>
|
||||
#include <QByteArrayMatcher>
|
||||
#include <QByteArray>
|
||||
|
||||
#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()<<a1;
|
||||
|
||||
// char cstr[20];
|
||||
// in.readRawData(cstr,20);
|
||||
// str=QString(cstr);
|
||||
// qDebug()<<str;
|
||||
|
||||
// a1=getData();
|
||||
text = codec->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<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();
|
||||
void setFileCode(hp_pkt_type);
|
||||
hp_pkt_type getFileCode();
|
||||
void setData(QByteArray);
|
||||
virtual void setData(QByteArray);
|
||||
virtual QByteArray getData();
|
||||
virtual void parseData();
|
||||
virtual void parseData(QDataStream& in);
|
||||
};
|
||||
|
||||
|
||||
|
@ -129,11 +130,13 @@ class Program: public AbstractData
|
|||
{
|
||||
private:
|
||||
QString text;
|
||||
void parseData();
|
||||
|
||||
public:
|
||||
Program(QString, hp_DataType, QString);
|
||||
void setProg(QString);
|
||||
QString getProg();
|
||||
void parseData();
|
||||
virtual void parseData(QDataStream& in);
|
||||
};
|
||||
|
||||
class Notes: public AbstractData
|
||||
|
@ -174,8 +177,10 @@ private:
|
|||
QString text;
|
||||
QString format;
|
||||
void parseData();
|
||||
|
||||
public:
|
||||
Settings(QString, hp_DataType);
|
||||
virtual void setData(QByteArray);
|
||||
};
|
||||
|
||||
#endif // ABSTRACTDATA_H
|
||||
|
|
|
@ -1,20 +1,36 @@
|
|||
#include "global.h"
|
||||
#include "cntfilesystemmodel.h"
|
||||
#include <QMimeData>
|
||||
#include <QStringListModel>
|
||||
|
||||
#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<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 {
|
||||
|
||||
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 "<<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
|
||||
#include <QObject>
|
||||
#include <QFileSystemModel>
|
||||
#include <QDropEvent>
|
||||
#include <QMdiArea>
|
||||
#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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>LogWindow</string>
|
||||
</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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
void addFile(AbstractData *);
|
||||
void addChild(AbstractData * obj);
|
||||
|
||||
|
||||
public slots:
|
||||
void dataChange(hp_Change hpchange);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ private slots:
|
|||
void showMonitor();
|
||||
void dataChange(hp_Change);
|
||||
void clickedCalculator(QModelIndex);
|
||||
void clickedContent(QModelIndex);
|
||||
void exit();
|
||||
void createLogWindow();
|
||||
void testFunction();
|
||||
|
|
|
@ -18,6 +18,18 @@
|
|||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<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">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
|
@ -98,14 +110,14 @@
|
|||
</widget>
|
||||
<widget class="QDockWidget" name="dwCalculator">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>104</width>
|
||||
<width>200</width>
|
||||
<height>184</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -117,7 +129,7 @@
|
|||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<width>300</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -191,14 +203,14 @@
|
|||
</widget>
|
||||
<widget class="QDockWidget" name="dwContent">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<width>300</width>
|
||||
<height>130</height>
|
||||
</size>
|
||||
</property>
|
||||
|
@ -227,7 +239,7 @@
|
|||
</widget>
|
||||
<widget class="QDockWidget" name="dwMessenger">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
@ -257,7 +269,7 @@
|
|||
</widget>
|
||||
<widget class="QDockWidget" name="dwMonitor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
|
|
21
options.cpp
21
options.cpp
|
@ -1,11 +1,32 @@
|
|||
#include "options.h"
|
||||
#include "ui_options.h"
|
||||
#include "global.h"
|
||||
#include <QSettings>
|
||||
|
||||
|
||||
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()
|
||||
|
|
|
@ -13,6 +13,8 @@ class Options : public QDialog
|
|||
|
||||
public:
|
||||
explicit Options(QWidget *parent = 0);
|
||||
void accept();
|
||||
void reject();
|
||||
~Options();
|
||||
|
||||
private:
|
||||
|
|
78
options.ui
78
options.ui
|
@ -29,28 +29,72 @@
|
|||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>58</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>File Path:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>521</width>
|
||||
<height>32</height>
|
||||
<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">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>58</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>File Path:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>141</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Environment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
#include "treemodel.h"
|
||||
#include "hptreeitem.h"
|
||||
#include <QStringListModel>
|
||||
#include <QMimeData>
|
||||
|
||||
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<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() {
|
||||
|
||||
delete rootNode;
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue