forked from qt-creator/qt-creator
Class view: Add drag & drop onto editor splits
Change-Id: I35bc03d4e963500a7edf37d6f9d0ddd0a6c68529 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user