forked from qt-creator/qt-creator
TypeHierarchy: Make type hierarchy independent of editor
This makes it possible to close all editors and still have the typehierarchy visible. It used to close for no apparent reason. Change-Id: I4d1500b5402905c6a04623ea60247c9d746acab8 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
committed by
David Schulz
parent
a17d7d7528
commit
599e4881c2
@@ -124,7 +124,6 @@ private:
|
||||
// CppTypeHierarchyWidget
|
||||
CppTypeHierarchyWidget::CppTypeHierarchyWidget(Core::IEditor *editor) :
|
||||
QWidget(0),
|
||||
m_cppEditor(0),
|
||||
m_treeView(0),
|
||||
m_model(0),
|
||||
m_delegate(0)
|
||||
@@ -133,9 +132,7 @@ CppTypeHierarchyWidget::CppTypeHierarchyWidget(Core::IEditor *editor) :
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
if (CPPEditor *cppEditor = qobject_cast<CPPEditor *>(editor)) {
|
||||
m_cppEditor = static_cast<CPPEditorWidget *>(cppEditor->widget());
|
||||
|
||||
if (qobject_cast<CPPEditor *>(editor)) {
|
||||
m_inspectedClass = new CppClassLabel(this);
|
||||
m_inspectedClass->setMargin(5);
|
||||
layout->addWidget(m_inspectedClass);
|
||||
@@ -165,27 +162,18 @@ CppTypeHierarchyWidget::CppTypeHierarchyWidget(Core::IEditor *editor) :
|
||||
CppTypeHierarchyWidget::~CppTypeHierarchyWidget()
|
||||
{}
|
||||
|
||||
bool CppTypeHierarchyWidget::handleEditorChange(Core::IEditor *editor)
|
||||
{
|
||||
if (CPPEditor *cppEditor = qobject_cast<CPPEditor *>(editor)) {
|
||||
if (m_cppEditor) {
|
||||
m_cppEditor = static_cast<CPPEditorWidget *>(cppEditor->widget());
|
||||
return true;
|
||||
}
|
||||
} else if (!m_cppEditor) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CppTypeHierarchyWidget::perform()
|
||||
{
|
||||
if (!m_cppEditor)
|
||||
CPPEditor *editor = qobject_cast<CPPEditor *>(Core::EditorManager::instance()->currentEditor());
|
||||
if (!editor)
|
||||
return;
|
||||
CPPEditorWidget *widget = qobject_cast<CPPEditorWidget *>(editor->widget());
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
m_model->clear();
|
||||
|
||||
CppElementEvaluator evaluator(m_cppEditor);
|
||||
CppElementEvaluator evaluator(widget);
|
||||
evaluator.setLookupBaseClasses(true);
|
||||
evaluator.setLookupDerivedClasses(true);
|
||||
evaluator.execute();
|
||||
@@ -218,7 +206,13 @@ void CppTypeHierarchyWidget::buildHierarchy(const CppClass &cppClass, QStandardI
|
||||
|
||||
void CppTypeHierarchyWidget::onItemClicked(const QModelIndex &index)
|
||||
{
|
||||
m_cppEditor->openLink(index.data(LinkRole).value<TextEditor::BaseTextEditorWidget::Link>());
|
||||
const TextEditor::BaseTextEditorWidget::Link link
|
||||
= index.data(LinkRole).value<TextEditor::BaseTextEditorWidget::Link>();
|
||||
if (!link.fileName.isEmpty())
|
||||
TextEditor::BaseTextEditorWidget::openEditorAt(link.fileName,
|
||||
link.line,
|
||||
link.column,
|
||||
Constants::CPPEDITOR_ID);
|
||||
}
|
||||
|
||||
// CppTypeHierarchyStackedWidget
|
||||
@@ -227,9 +221,6 @@ CppTypeHierarchyStackedWidget::CppTypeHierarchyStackedWidget(QWidget *parent) :
|
||||
m_typeHiearchyWidgetInstance(new CppTypeHierarchyWidget(Core::EditorManager::currentEditor()))
|
||||
{
|
||||
addWidget(m_typeHiearchyWidgetInstance);
|
||||
|
||||
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
||||
this, SLOT(editorChanged(Core::IEditor*)));
|
||||
}
|
||||
|
||||
CppTypeHierarchyStackedWidget::~CppTypeHierarchyStackedWidget()
|
||||
@@ -237,17 +228,6 @@ CppTypeHierarchyStackedWidget::~CppTypeHierarchyStackedWidget()
|
||||
delete m_typeHiearchyWidgetInstance;
|
||||
}
|
||||
|
||||
void CppTypeHierarchyStackedWidget::editorChanged(Core::IEditor *editor)
|
||||
{
|
||||
if (!m_typeHiearchyWidgetInstance->handleEditorChange(editor)) {
|
||||
CppTypeHierarchyWidget *replacement = new CppTypeHierarchyWidget(editor);
|
||||
removeWidget(m_typeHiearchyWidgetInstance);
|
||||
m_typeHiearchyWidgetInstance->deleteLater();
|
||||
m_typeHiearchyWidgetInstance = replacement;
|
||||
addWidget(m_typeHiearchyWidgetInstance);
|
||||
}
|
||||
}
|
||||
|
||||
// CppTypeHierarchyFactory
|
||||
CppTypeHierarchyFactory::CppTypeHierarchyFactory()
|
||||
{}
|
||||
|
@@ -69,8 +69,6 @@ public:
|
||||
CppTypeHierarchyWidget(Core::IEditor *editor);
|
||||
virtual ~CppTypeHierarchyWidget();
|
||||
|
||||
bool handleEditorChange(Core::IEditor *editor);
|
||||
|
||||
public slots:
|
||||
void perform();
|
||||
|
||||
@@ -97,9 +95,6 @@ public:
|
||||
CppTypeHierarchyStackedWidget(QWidget *parent = 0);
|
||||
virtual ~CppTypeHierarchyStackedWidget();
|
||||
|
||||
public slots:
|
||||
void editorChanged(Core::IEditor* editor);
|
||||
|
||||
private:
|
||||
CppTypeHierarchyWidget *m_typeHiearchyWidgetInstance;
|
||||
};
|
||||
|
Reference in New Issue
Block a user