diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2014-10-17 10:22:26 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2014-10-17 14:23:33 +0200 |
commit | cc42a0872317b7b51c96bf68171993bff90bdf2c (patch) | |
tree | 9fc594146876a1c011a045d40f1fd4f92e9f5b42 /src/plugins/classview | |
parent | 216b9501247c45f561694e15978dfc6c2a098609 (diff) | |
download | qt-creator-cc42a0872317b7b51c96bf68171993bff90bdf2c.tar.gz |
Class view: Add drag & drop onto editor splits
Change-Id: I35bc03d4e963500a7edf37d6f9d0ddd0a6c68529
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/plugins/classview')
-rw-r--r-- | src/plugins/classview/classviewnavigationwidget.cpp | 3 | ||||
-rw-r--r-- | src/plugins/classview/classviewparsertreeitem.cpp | 4 | ||||
-rw-r--r-- | src/plugins/classview/classviewtreeitemmodel.cpp | 30 | ||||
-rw-r--r-- | src/plugins/classview/classviewtreeitemmodel.h | 16 |
4 files changed, 44 insertions, 9 deletions
diff --git a/src/plugins/classview/classviewnavigationwidget.cpp b/src/plugins/classview/classviewnavigationwidget.cpp index 9243fae81d..49ab4ab0e8 100644 --- a/src/plugins/classview/classviewnavigationwidget.cpp +++ b/src/plugins/classview/classviewnavigationwidget.cpp @@ -99,6 +99,9 @@ NavigationWidget::NavigationWidget(QWidget *parent) : verticalLayout->setContentsMargins(0, 0, 0, 0); treeView = new ::Utils::NavigationTreeView(this); treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); + treeView->setDragEnabled(true); + treeView->setDragDropMode(QAbstractItemView::DragOnly); + treeView->setDefaultDropAction(Qt::MoveAction); verticalLayout->addWidget(Core::ItemViewFind::createSearchableWrapper( treeView, Core::ItemViewFind::DarkColored, Core::ItemViewFind::FetchMoreWhileSearching)); diff --git a/src/plugins/classview/classviewparsertreeitem.cpp b/src/plugins/classview/classviewparsertreeitem.cpp index a054339c34..89e33d9de0 100644 --- a/src/plugins/classview/classviewparsertreeitem.cpp +++ b/src/plugins/classview/classviewparsertreeitem.cpp @@ -316,6 +316,10 @@ void ParserTreeItem::convertTo(QStandardItem *item) const // icon add->setIcon(ptr->icon()); + // draggable + if (!ptr->symbolLocations().isEmpty()) + add->setFlags(add->flags() | Qt::ItemIsDragEnabled); + // locations add->setData(Utils::locationsToRole(ptr->symbolLocations()), Constants::SymbolLocationsRole); diff --git a/src/plugins/classview/classviewtreeitemmodel.cpp b/src/plugins/classview/classviewtreeitemmodel.cpp index f719b3378c..8f7b033aba 100644 --- a/src/plugins/classview/classviewtreeitemmodel.cpp +++ b/src/plugins/classview/classviewtreeitemmodel.cpp @@ -34,6 +34,7 @@ #include "classviewutils.h" #include <cplusplus/Icons.h> +#include <utils/fileutils.h> namespace ClassView { namespace Internal { @@ -133,6 +134,35 @@ bool TreeItemModel::hasChildren(const QModelIndex &parent) const return Manager::instance()->hasChildren(itemFromIndex(parent)); } +Qt::DropActions TreeItemModel::supportedDragActions() const +{ + return Qt::MoveAction | Qt::CopyAction; +} + +QStringList TreeItemModel::mimeTypes() const +{ + return ::Utils::FileDropSupport::mimeTypesForFilePaths(); +} + +QMimeData *TreeItemModel::mimeData(const QModelIndexList &indexes) const +{ + auto mimeData = new ::Utils::FileDropMimeData; + mimeData->setOverrideFileDropAction(Qt::CopyAction); + foreach (const QModelIndex &index, indexes) { + const QSet<SymbolLocation> locations = Utils::roleToLocations( + data(index, Constants::SymbolLocationsRole).toList()); + if (locations.isEmpty()) + continue; + const SymbolLocation loc = *locations.constBegin(); + mimeData->addFile(loc.fileName(), loc.line(), loc.column()); + } + if (mimeData->files().isEmpty()) { + delete mimeData; + return 0; + } + return mimeData; +} + /*! Moves the root item to the \a target item. */ diff --git a/src/plugins/classview/classviewtreeitemmodel.h b/src/plugins/classview/classviewtreeitemmodel.h index 0a793f3785..55d1ec387c 100644 --- a/src/plugins/classview/classviewtreeitemmodel.h +++ b/src/plugins/classview/classviewtreeitemmodel.h @@ -43,21 +43,19 @@ class TreeItemModel : public QStandardItemModel Q_OBJECT public: - explicit TreeItemModel(QObject *parent=0); + explicit TreeItemModel(QObject *parent = 0); virtual ~TreeItemModel(); void moveRootToTarget(const QStandardItem *target); - //! \implements QStandardItemModel::data QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool canFetchMore(const QModelIndex &parent) const; + void fetchMore(const QModelIndex &parent); + bool hasChildren(const QModelIndex &parent = QModelIndex()) const; - //! \implements QStandardItemModel::canFetchMore - virtual bool canFetchMore(const QModelIndex &parent) const; - - //! \implements QStandardItemModel::fetchMore - virtual void fetchMore(const QModelIndex &parent); - - virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; + Qt::DropActions supportedDragActions() const; + QStringList mimeTypes() const; + QMimeData *mimeData(const QModelIndexList &indexes) const; private: //! private class data pointer |