Commit cc42a087 authored by Eike Ziller's avatar Eike Ziller

Class view: Add drag & drop onto editor splits

Change-Id: I35bc03d4e963500a7edf37d6f9d0ddd0a6c68529
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 216b9501
...@@ -99,6 +99,9 @@ NavigationWidget::NavigationWidget(QWidget *parent) : ...@@ -99,6 +99,9 @@ NavigationWidget::NavigationWidget(QWidget *parent) :
verticalLayout->setContentsMargins(0, 0, 0, 0); verticalLayout->setContentsMargins(0, 0, 0, 0);
treeView = new ::Utils::NavigationTreeView(this); treeView = new ::Utils::NavigationTreeView(this);
treeView->setEditTriggers(QAbstractItemView::NoEditTriggers); treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
treeView->setDragEnabled(true);
treeView->setDragDropMode(QAbstractItemView::DragOnly);
treeView->setDefaultDropAction(Qt::MoveAction);
verticalLayout->addWidget(Core::ItemViewFind::createSearchableWrapper( verticalLayout->addWidget(Core::ItemViewFind::createSearchableWrapper(
treeView, Core::ItemViewFind::DarkColored, treeView, Core::ItemViewFind::DarkColored,
Core::ItemViewFind::FetchMoreWhileSearching)); Core::ItemViewFind::FetchMoreWhileSearching));
......
...@@ -316,6 +316,10 @@ void ParserTreeItem::convertTo(QStandardItem *item) const ...@@ -316,6 +316,10 @@ void ParserTreeItem::convertTo(QStandardItem *item) const
// icon // icon
add->setIcon(ptr->icon()); add->setIcon(ptr->icon());
// draggable
if (!ptr->symbolLocations().isEmpty())
add->setFlags(add->flags() | Qt::ItemIsDragEnabled);
// locations // locations
add->setData(Utils::locationsToRole(ptr->symbolLocations()), add->setData(Utils::locationsToRole(ptr->symbolLocations()),
Constants::SymbolLocationsRole); Constants::SymbolLocationsRole);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "classviewutils.h" #include "classviewutils.h"
#include <cplusplus/Icons.h> #include <cplusplus/Icons.h>
#include <utils/fileutils.h>
namespace ClassView { namespace ClassView {
namespace Internal { namespace Internal {
...@@ -133,6 +134,35 @@ bool TreeItemModel::hasChildren(const QModelIndex &parent) const ...@@ -133,6 +134,35 @@ bool TreeItemModel::hasChildren(const QModelIndex &parent) const
return Manager::instance()->hasChildren(itemFromIndex(parent)); 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. Moves the root item to the \a target item.
*/ */
......
...@@ -43,21 +43,19 @@ class TreeItemModel : public QStandardItemModel ...@@ -43,21 +43,19 @@ class TreeItemModel : public QStandardItemModel
Q_OBJECT Q_OBJECT
public: public:
explicit TreeItemModel(QObject *parent=0); explicit TreeItemModel(QObject *parent = 0);
virtual ~TreeItemModel(); virtual ~TreeItemModel();
void moveRootToTarget(const QStandardItem *target); void moveRootToTarget(const QStandardItem *target);
//! \implements QStandardItemModel::data
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 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 Qt::DropActions supportedDragActions() const;
virtual bool canFetchMore(const QModelIndex &parent) const; QStringList mimeTypes() const;
QMimeData *mimeData(const QModelIndexList &indexes) const;
//! \implements QStandardItemModel::fetchMore
virtual void fetchMore(const QModelIndex &parent);
virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
private: private:
//! private class data pointer //! private class data pointer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment