aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2014-09-08 11:41:14 +0200
committerEike Ziller <[email protected]>2014-09-12 13:00:30 +0200
commit50ad2a4d99928a1cc8f1ac957ba734324a65b464 (patch)
treea519afea31f82211e8b1badb89c70f4be55971ad /src/plugins
parent0e0471d69829ee31fdd6f4d04b08d689deb2320a (diff)
Editors: Support drag and drop from open editors pane to splits
Change-Id: I6f8685319f0afe2a326a66e36a1e6b671e317614 Reviewed-by: Daniel Teske <[email protected]>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/coreplugin/editormanager/documentmodel.cpp38
-rw-r--r--src/plugins/coreplugin/editormanager/openeditorsview.cpp7
-rw-r--r--src/plugins/coreplugin/editormanager/openeditorsview.h2
3 files changed, 47 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp
index e1ecde4a6d1..1b972ca8d9e 100644
--- a/src/plugins/coreplugin/editormanager/documentmodel.cpp
+++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp
@@ -33,10 +33,13 @@
#include <coreplugin/idocument.h>
#include <utils/algorithm.h>
+#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QIcon>
+#include <QMimeData>
+#include <QUrl>
namespace Core {
@@ -50,10 +53,15 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ QMimeData *mimeData(const QModelIndexList &indexes) const;
QModelIndex parent(const QModelIndex &/*index*/) const { return QModelIndex(); }
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
+ Qt::DropActions supportedDragActions() const;
+ QStringList mimeTypes() const;
+
void addEntry(DocumentModel::Entry *entry);
void removeDocument(int idx);
@@ -341,6 +349,16 @@ QModelIndex DocumentModelPrivate::index(int row, int column, const QModelIndex &
return createIndex(row, column);
}
+Qt::DropActions DocumentModelPrivate::supportedDragActions() const
+{
+ return Qt::MoveAction;
+}
+
+QStringList DocumentModelPrivate::mimeTypes() const
+{
+ return Utils::FileDropSupport::mimeTypesForFilePaths();
+}
+
DocumentModel::Entry *DocumentModel::entryAtRow(int row)
{
int entryIndex = row - 1/*<no document>*/;
@@ -398,6 +416,26 @@ QVariant DocumentModelPrivate::data(const QModelIndex &index, int role) const
return QVariant();
}
+Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const
+{
+ const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
+ if (!e || e->fileName().isEmpty())
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+ return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+QMimeData *DocumentModelPrivate::mimeData(const QModelIndexList &indexes) const
+{
+ QStringList filePaths;
+ foreach (const QModelIndex &index, indexes) {
+ const DocumentModel::Entry *e = DocumentModel::entryAtRow(index.row());
+ if (!e || e->fileName().isEmpty())
+ continue;
+ filePaths.append(e->fileName());
+ }
+ return Utils::FileDropSupport::mimeDataForFilePaths(filePaths);
+}
+
int DocumentModel::rowOfDocument(IDocument *document)
{
if (!document)
diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp
index 18d8d1d3175..22c68c2e29d 100644
--- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp
+++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp
@@ -88,6 +88,8 @@ OpenEditorsWidget::OpenEditorsWidget()
{
setWindowTitle(tr("Open Documents"));
setWindowIcon(QIcon(QLatin1String(Constants::ICON_DIR)));
+ setDragEnabled(true);
+ setDragDropMode(QAbstractItemView::DragOnly);
setUniformRowHeights(true);
viewport()->setAttribute(Qt::WA_Hover);
setItemDelegate((m_delegate = new OpenEditorsDelegate(this)));
@@ -314,6 +316,11 @@ QModelIndex ProxyModel::sibling(int row, int column, const QModelIndex &idx) con
return QAbstractItemModel::sibling(row, column, idx);
}
+Qt::DropActions ProxyModel::supportedDragActions() const
+{
+ return sourceModel()->supportedDragActions();
+}
+
void ProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
QModelIndex topLeftIndex = mapFromSource(topLeft);
diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.h b/src/plugins/coreplugin/editormanager/openeditorsview.h
index 36e19261cf6..1d76c9459e2 100644
--- a/src/plugins/coreplugin/editormanager/openeditorsview.h
+++ b/src/plugins/coreplugin/editormanager/openeditorsview.h
@@ -59,6 +59,8 @@ public:
// QAbstractProxyModel::sibling is broken in Qt 5
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
+ // QAbstractProxyModel::supportedDragActions delegation is missing in Qt 5
+ Qt::DropActions supportedDragActions() const;
private slots:
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);