From 302fbea49377cc51d54c271d7c6c4ae7384bdd07 Mon Sep 17 00:00:00 2001 From: Ian Gebbie Date: Thu, 16 Jan 2020 05:38:13 +0200 Subject: [PATCH] Drag Drop Development --- abstractdata.cpp | 4 +- cntfilesystemmodel.cpp | 89 ++++++++++++++++++++++++++++++++---------- cntfilesystemmodel.h | 4 +- hptreeitem.cpp | 7 ++++ hptreeitem.h | 1 + treemodel.cpp | 40 ++++++++++++++++--- treemodel.h | 2 +- 7 files changed, 117 insertions(+), 30 deletions(-) diff --git a/abstractdata.cpp b/abstractdata.cpp index b9a5f3d..e346ea5 100644 --- a/abstractdata.cpp +++ b/abstractdata.cpp @@ -904,7 +904,9 @@ void Program::parseData(QDataStream& in) { // qDebug()<toUnicode(a1); + setProg(codec->toUnicode(a1)); + + return; } diff --git a/cntfilesystemmodel.cpp b/cntfilesystemmodel.cpp index 4356134..5617b6f 100644 --- a/cntfilesystemmodel.cpp +++ b/cntfilesystemmodel.cpp @@ -31,7 +31,7 @@ const QString contentFileSystemModel::file_type[FILE_TYPE]={"hpprgm", "hpmat", "hpnote", ""}; - +//condtrutor contentFileSystemModel::contentFileSystemModel(QObject * parent) :QFileSystemModel(parent) { @@ -44,24 +44,32 @@ QMimeData* contentFileSystemModel::mimeData(const QModelIndexList &indexes) cons QMimeData *mimeDataPtr = new QMimeData(); QByteArray mydata; + QModelIndex index; + AbstractData * adata = nullptr; qDebug()<<"contentFileSystemModel::mimeData"; - mimeDataPtr->setData("application/x-qstandarditemmodeldatalist",mydata); + index=indexes.first(); + qDebug()< rowIdList; - int rowId; - foreach (QModelIndex index, indexes) { - if (index.isValid()) { - rowId = index.row(); + data=index.data().toString(); + qDebug()<getData(); + mimeDataPtr->setData("application/x-qstandarditemmodeldatalist",mydata); + } + else { + mydata=data.toUtf8(); + mimeDataPtr->setData("application/x-qstandarditemmodeldatalist",mydata); } - return mimeDataPtr; } @@ -94,10 +102,12 @@ bool contentFileSystemModel::dropMimeData(const QMimeData* data, Qt::DropAction { qDebug()<<"contentFileSystemModel::DropMineData"; if (action == Qt::IgnoreAction) { + qDebug()<<"contentFileSystemModel::QT::ignoreAction"; return true; } if (column > 1) { + qDebug()<<"contentFileSystemModel::column>1"; return false; } @@ -127,6 +137,8 @@ bool contentFileSystemModel::dropMimeData(const QMimeData* data, Qt::DropAction // insertRow(position, parent, rowId); // } + + qDebug()<<"contentFileSystemModel::dropMineData end"; return true; } @@ -158,7 +170,7 @@ void contentFileSystemModel::clickAction(QMdiArea * mdiwin, QModelIndex &index) AbstractData * data=nullptr; QFileInfo info = contentFileSystemModel::fileInfo(index); - QFile file(info.absoluteFilePath()); +/* if (file.open(QIODevice::ReadOnly),QFileDevice::AutoCloseHandle) { QDataStream in(&file); @@ -174,18 +186,53 @@ void contentFileSystemModel::clickAction(QMdiArea * mdiwin, QModelIndex &index) break; default: ; } +*/ - if (hptextedit==nullptr) - hptextedit = new hp_mdiTextEdit(mdiwin,filedata, data); - if (hptextedit!=nullptr) - hptextedit ->show(); + data = readFile(info); - file.close(); - } + if (data!=nullptr) { + if (hptextedit==nullptr) + hptextedit = new hp_mdiTextEdit(mdiwin,filedata, data); + if (hptextedit!=nullptr) + hptextedit ->show(); + } + else { + qDebug()<<"Null data"; + } qDebug()<<"ClickAction "<parseData(in); + } + break; + default: ; + } + + file.close(); + } + + return data; +} + + + +hp_DataStruct contentFileSystemModel::getFileType(QFileInfo info) const { hp_DataStruct filedata; int i; QString suffix; diff --git a/cntfilesystemmodel.h b/cntfilesystemmodel.h index 81fbe0d..f0ebba7 100644 --- a/cntfilesystemmodel.h +++ b/cntfilesystemmodel.h @@ -20,7 +20,9 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; void clickAction(QMdiArea * mdiwin,QModelIndex &index); - hp_DataStruct getFileType(QFileInfo info); + hp_DataStruct getFileType(QFileInfo info) const; + AbstractData * readFile(QFileInfo fileinfo) const; + ~contentFileSystemModel(); private: diff --git a/hptreeitem.cpp b/hptreeitem.cpp index b071eb8..9c86e7d 100644 --- a/hptreeitem.cpp +++ b/hptreeitem.cpp @@ -43,7 +43,14 @@ const hp_DataType hpTreeItem::func_type[FUNC_NUM]={ hpTreeItem::hpTreeItem() :QStandardItem() { + setDropEnabled(true); + setEditable(0); +} + +bool hpTreeItem::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) { + + qDebug()<<"hpTreeItem::dropMimeData"; } hpTreeItem::hpTreeItem(const QString & name,hpCalcData * hpDataStore,int flag) diff --git a/hptreeitem.h b/hptreeitem.h index af9bd8f..e597d8d 100644 --- a/hptreeitem.h +++ b/hptreeitem.h @@ -35,6 +35,7 @@ public: hpCalcData * getDataStore(); QString getGroupName(); QString getFileName(); + bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent); void setFileName(QString); hp_DataType getType(); void refresh(); diff --git a/treemodel.cpp b/treemodel.cpp index 286c85c..dbd67c4 100644 --- a/treemodel.cpp +++ b/treemodel.cpp @@ -1,16 +1,22 @@ +// +// Model to contain the calculator data structure +// + #include "treemodel.h" #include "hptreeitem.h" #include #include +//Constructor treeModel::treeModel(QObject *parent) :QStandardItemModel(parent) { setItemPrototype(new hpTreeItem()); createRoot(); setParent(parent); -} + } +//Create the start of the tree int treeModel::createRoot() { rootNode = invisibleRootItem(); @@ -35,6 +41,7 @@ int treeModel::addCalculator(QString name, hpusb * handle){ return 0; } +//return the calculator data within the model hpCalcData * treeModel::getCalculator(QString name){ hpDataLink hplink; @@ -51,6 +58,8 @@ hpCalcData * treeModel::getCalculator(QString name){ return hpdata; } +//index system for data retrieval +//review QStandardItemModel should already have one in place QString treeModel::getLastDataKey() { if (hpCalcList.isEmpty()) return QStringLiteral(""); @@ -88,6 +97,7 @@ void treeModel::setHpCalcData(QString name, hpCalcData * data, hpTreeItem * tree return; } +//Part the the drag and drop system Qt::DropActions treeModel::supportedDropActions() const { return Qt::CopyAction | Qt::MoveAction | Qt::TargetMoveAction; @@ -127,15 +137,19 @@ bool treeModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, in } //Process the drop action -bool treeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, - int column, const QModelIndex &parent) +bool treeModel::dropMimeData(const QMimeData* md_data, Qt::DropAction action, int row, + int column, const QModelIndex &index) { - qDebug()<<"treemodel::DropMineData"; + QByteArray data_in; + + qDebug()<<"treemodel::DropMineData "< 1) { + qDebug()<<"treemodel::column>1"; return false; } @@ -143,12 +157,20 @@ bool treeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int r if (row != -1) { position = row; - } else if (parent.isValid()) { - position = parent.row(); + } else if (index.isValid()) { + position = index.row(); } else { position = rowCount(QModelIndex()); } + hpTreeItem * item=nullptr; + item = static_cast(itemFromIndex(index)); + if (item!=nullptr) { + qDebug()<getType(); + } + //item = getItem(parent); + + // QByteArray encodedData = data->data("application/text.list"); // QDataStream stream(&encodedData, QIODevice::ReadOnly); @@ -165,6 +187,10 @@ bool treeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int r // insertRow(position, parent, rowId); // } + data_in=md_data->data("application/x-qstandarditemmodeldatalist"); + qDebug()<