forked from qt-creator/qt-creator
Cpp include hierarchy: Add drag & drop onto editor splits
Change-Id: If6d7acb362433814dd73819ec224249f05ab9dcd Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -57,34 +57,6 @@ using namespace Utils;
|
|||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class CppIncludeLabel : public QLabel
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CppIncludeLabel(QWidget *parent)
|
|
||||||
: QLabel(parent)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void setup(const QString &fileName, const QString &filePath)
|
|
||||||
{
|
|
||||||
setText(fileName);
|
|
||||||
m_link = CppEditorWidget::Link(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
void mousePressEvent(QMouseEvent *)
|
|
||||||
{
|
|
||||||
if (!m_link.hasValidTarget())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Core::EditorManager::openEditorAt(m_link.targetFileName,
|
|
||||||
m_link.targetLine,
|
|
||||||
m_link.targetColumn,
|
|
||||||
Constants::CPPEDITOR_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
CppEditorWidget::Link m_link;
|
|
||||||
};
|
|
||||||
|
|
||||||
// CppIncludeHierarchyWidget
|
// CppIncludeHierarchyWidget
|
||||||
CppIncludeHierarchyWidget::CppIncludeHierarchyWidget() :
|
CppIncludeHierarchyWidget::CppIncludeHierarchyWidget() :
|
||||||
QWidget(0),
|
QWidget(0),
|
||||||
@@ -94,7 +66,7 @@ CppIncludeHierarchyWidget::CppIncludeHierarchyWidget() :
|
|||||||
m_includeHierarchyInfoLabel(0),
|
m_includeHierarchyInfoLabel(0),
|
||||||
m_editor(0)
|
m_editor(0)
|
||||||
{
|
{
|
||||||
m_inspectedFile = new CppIncludeLabel(this);
|
m_inspectedFile = new TextEditorLinkLabel(this);
|
||||||
m_inspectedFile->setMargin(5);
|
m_inspectedFile->setMargin(5);
|
||||||
m_model = new CppIncludeHierarchyModel(this);
|
m_model = new CppIncludeHierarchyModel(this);
|
||||||
m_treeView = new CppIncludeHierarchyTreeView(this);
|
m_treeView = new CppIncludeHierarchyTreeView(this);
|
||||||
@@ -150,8 +122,8 @@ void CppIncludeHierarchyWidget::perform()
|
|||||||
if (m_model->isEmpty())
|
if (m_model->isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_inspectedFile->setup(widget->textDocument()->displayName(),
|
m_inspectedFile->setText(widget->textDocument()->displayName());
|
||||||
widget->textDocument()->filePath());
|
m_inspectedFile->setLink(TextEditorWidget::Link(widget->textDocument()->filePath()));
|
||||||
|
|
||||||
//expand "Includes"
|
//expand "Includes"
|
||||||
m_treeView->expand(m_model->index(0, 0));
|
m_treeView->expand(m_model->index(0, 0));
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ class QLabel;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
namespace Core { class IEditor; }
|
||||||
namespace TextEditor { class BaseTextEditor; }
|
|
||||||
|
namespace TextEditor {
|
||||||
|
class BaseTextEditor;
|
||||||
|
class TextEditorLinkLabel;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
class AnnotatedItemDelegate;
|
class AnnotatedItemDelegate;
|
||||||
@@ -58,7 +62,6 @@ namespace Internal {
|
|||||||
class CppEditor;
|
class CppEditor;
|
||||||
class CppEditorWidget;
|
class CppEditorWidget;
|
||||||
class CppInclude;
|
class CppInclude;
|
||||||
class CppIncludeLabel;
|
|
||||||
class CppIncludeHierarchyModel;
|
class CppIncludeHierarchyModel;
|
||||||
class CppIncludeHierarchyTreeView;
|
class CppIncludeHierarchyTreeView;
|
||||||
|
|
||||||
@@ -84,7 +87,7 @@ private:
|
|||||||
CppIncludeHierarchyTreeView *m_treeView;
|
CppIncludeHierarchyTreeView *m_treeView;
|
||||||
CppIncludeHierarchyModel *m_model;
|
CppIncludeHierarchyModel *m_model;
|
||||||
Utils::AnnotatedItemDelegate *m_delegate;
|
Utils::AnnotatedItemDelegate *m_delegate;
|
||||||
CppIncludeLabel *m_inspectedFile;
|
TextEditor::TextEditorLinkLabel *m_inspectedFile;
|
||||||
QLabel *m_includeHierarchyInfoLabel;
|
QLabel *m_includeHierarchyInfoLabel;
|
||||||
TextEditor::BaseTextEditor *m_editor;
|
TextEditor::BaseTextEditor *m_editor;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
@@ -241,6 +242,37 @@ bool CppIncludeHierarchyModel::hasChildren(const QModelIndex &parent) const
|
|||||||
return parentItem->hasChildren();
|
return parentItem->hasChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags CppIncludeHierarchyModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
const TextEditor::TextEditorWidget::Link link
|
||||||
|
= index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
||||||
|
if (link.hasValidTarget())
|
||||||
|
return Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::DropActions CppIncludeHierarchyModel::supportedDragActions() const
|
||||||
|
{
|
||||||
|
return Qt::MoveAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CppIncludeHierarchyModel::mimeTypes() const
|
||||||
|
{
|
||||||
|
return Utils::FileDropSupport::mimeTypesForFilePaths();
|
||||||
|
}
|
||||||
|
|
||||||
|
QMimeData *CppIncludeHierarchyModel::mimeData(const QModelIndexList &indexes) const
|
||||||
|
{
|
||||||
|
auto data = new Utils::FileDropMimeData;
|
||||||
|
foreach (const QModelIndex &index, indexes) {
|
||||||
|
const TextEditor::TextEditorWidget::Link link
|
||||||
|
= index.data(LinkRole).value<TextEditor::TextEditorWidget::Link>();
|
||||||
|
if (link.hasValidTarget())
|
||||||
|
data->addFile(link.targetFileName, link.targetLine, link.targetColumn);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
bool CppIncludeHierarchyModel::isEmpty() const
|
bool CppIncludeHierarchyModel::isEmpty() const
|
||||||
{
|
{
|
||||||
return !m_includesItem->hasChildren() && !m_includedByItem->hasChildren();
|
return !m_includesItem->hasChildren() && !m_includedByItem->hasChildren();
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ public:
|
|||||||
void fetchMore(const QModelIndex &parent);
|
void fetchMore(const QModelIndex &parent);
|
||||||
bool canFetchMore(const QModelIndex &parent) const;
|
bool canFetchMore(const QModelIndex &parent) const;
|
||||||
bool hasChildren(const QModelIndex &parent) const;
|
bool hasChildren(const QModelIndex &parent) const;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
Qt::DropActions supportedDragActions() const;
|
||||||
|
QStringList mimeTypes() const;
|
||||||
|
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
void buildHierarchy(TextEditor::BaseTextEditor *editor, const QString &filePath);
|
void buildHierarchy(TextEditor::BaseTextEditor *editor, const QString &filePath);
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ namespace Internal {
|
|||||||
CppIncludeHierarchyTreeView::CppIncludeHierarchyTreeView(QWidget *parent/* = 0*/)
|
CppIncludeHierarchyTreeView::CppIncludeHierarchyTreeView(QWidget *parent/* = 0*/)
|
||||||
: NavigationTreeView(parent)
|
: NavigationTreeView(parent)
|
||||||
{
|
{
|
||||||
|
setDragEnabled(true);
|
||||||
|
setDragDropMode(QAbstractItemView::DragOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppIncludeHierarchyTreeView::keyPressEvent(QKeyEvent *event)
|
void CppIncludeHierarchyTreeView::keyPressEvent(QKeyEvent *event)
|
||||||
|
|||||||
Reference in New Issue
Block a user