Drag Drop Development

This commit is contained in:
Ian Gebbie 2020-01-16 05:38:13 +02:00
parent 58d49f4829
commit 302fbea493
7 changed files with 117 additions and 30 deletions

View file

@ -904,7 +904,9 @@ void Program::parseData(QDataStream& in) {
// qDebug()<<str;
// a1=getData();
text = codec->toUnicode(a1);
setProg(codec->toUnicode(a1));
return;
}

View file

@ -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()<<index.data(Qt::DisplayRole);
QString data;
/* Store row id list */
QList<int> rowIdList;
int rowId;
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
rowId = index.row();
data=index.data().toString();
qDebug()<<data;
if (!rowIdList.contains(rowId)) {
rowIdList << rowId;
}
}
QFileInfo info = contentFileSystemModel::fileInfo(index);
QFile file(info.absoluteFilePath());
qDebug()<<info.absoluteFilePath();
adata=readFile(info);
if (adata!=nullptr) {
mydata = adata->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 "<<info.absoluteFilePath();
}
hp_DataStruct contentFileSystemModel::getFileType(QFileInfo info) {
AbstractData * contentFileSystemModel::readFile(QFileInfo fileinfo) const {
AbstractData * data=nullptr;
hp_DataStruct filedata;
QFile file(fileinfo.absoluteFilePath());
if (file.open(QIODevice::ReadOnly),QFileDevice::AutoCloseHandle) {
QDataStream in(&file);
filedata=getFileType(fileinfo);
switch (filedata.type) {
case HP_PROG: {
qDebug()<<"HP_PROG";
data = new Program(filedata.filename, HP_PROG, QStringLiteral(""));
data->parseData(in);
}
break;
default: ;
}
file.close();
}
return data;
}
hp_DataStruct contentFileSystemModel::getFileType(QFileInfo info) const {
hp_DataStruct filedata;
int i;
QString suffix;

View file

@ -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:

View file

@ -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)

View file

@ -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();

View file

@ -1,16 +1,22 @@
//
// Model to contain the calculator data structure
//
#include "treemodel.h"
#include "hptreeitem.h"
#include <QStringListModel>
#include <QMimeData>
//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 "<<row<<" "<<column;
if (action == Qt::IgnoreAction) {
qDebug()<<"treemodel::IgnoreAction";
return true;
}
if (column > 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<hpTreeItem *>(itemFromIndex(index));
if (item!=nullptr) {
qDebug()<<item->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()<<position;
//qDebug()<<data_in;
qDebug()<<"treemodel::dropMimeData End";
return true;
}
@ -180,6 +206,8 @@ Qt::ItemFlags treeModel::flags(const QModelIndex &index) const
treeModel::~treeModel() {
if (rootNode!=nullptr)
delete rootNode;
qDebug()<<"treeModel:: delete";
}

View file

@ -33,7 +33,7 @@ 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) override;
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &index) override;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
Qt::DropActions supportedDropActions() const override;
QMimeData* mimeData(const QModelIndexList &) const override;