From 06f035926acb9966c95e6b725d9eb95a22f7c734 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sun, 24 Oct 2021 00:17:08 +0800 Subject: [PATCH] work save: drag & drop in project view --- RedPandaIDE/mainwindow.ui | 3 +++ RedPandaIDE/project.cpp | 30 +++++++++++++++++++++++++++++- RedPandaIDE/project.h | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 97f331be..e512cfe1 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -131,6 +131,9 @@ QAbstractItemView::SelectRows + + 500 + false diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index b028af53..bf6eb8c2 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -602,6 +602,8 @@ PFolderNode Project::pointerToNode(FolderNode *p, PFolderNode parent) if (!parent) { parent = mNode; } + if (p==mNode.get()) + return mNode; foreach (const PFolderNode& node , parent->children) { if (node.get()==p) return node; @@ -1765,6 +1767,8 @@ QModelIndex ProjectModel::index(int row, int column, const QModelIndex &parent) if (!parentNode) { return QModelIndex(); } + if (row<0 || row>=parentNode->children.count()) + return QModelIndex(); return createIndex(row,column,parentNode->children[row].get()); } @@ -1942,12 +1946,36 @@ bool ProjectModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, { if (action != Qt::MoveAction) return false; - QModelIndex idx = index(row,column,parent); + QModelIndex idx; + if (row >= rowCount(parent) || row < 0) { + qDebug()<<"above/below"; + idx = parent; + } else { + idx= index(row,column,parent); + } if (!idx.isValid()) return false; FolderNode* p = static_cast(idx.internalPointer()); PFolderNode node = mProject->pointerToNode(p); + qDebug()<text; if (node->unitIndex>=0) return false; return true; } + +QStringList ProjectModel::mimeTypes() const +{ + QStringList t=QAbstractItemModel::mimeTypes(); + return t; +} + +QMimeData *ProjectModel::mimeData(const QModelIndexList &indexes) const +{ + QMimeData * d= QAbstractItemModel::mimeData(indexes); + return d; +} + +Qt::DropActions ProjectModel::supportedDropActions() const +{ + return Qt::MoveAction; +} diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index dbca4ed4..75fd07c8 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -101,6 +101,9 @@ public: // QAbstractItemModel interface public: bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; + QStringList mimeTypes() const override; + QMimeData *mimeData(const QModelIndexList &indexes) const override; + Qt::DropActions supportedDropActions() const override; }; class ProjectTemplate;