Commit a32343b9 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Nikolai Kosjar
Browse files

CppEditor: fix showing 'Type Hierarchy'



When we open project and do not open any file, then open 'Type Hierarchy'
(from combobox) we see "No type hierarchy available"(and this is ok). Then
if we open any file and we try to see 'Type Hierarchy'(Ctrl+Shift+T) then we
still see "No type hierarchy available"(and this is not ok).
It will also happens if we save a session with opened "Type Hierarchy".

This change fixes this. Additionally when we select something for which there
is no 'Type Hierarchy' then it displays "No type hierarchy available".

Task-number: QTCREATORBUG-9819
Change-Id: Ib6a152f481057098f3d8a4335bb2d4a31fc5e1ef
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 7410e4be
......@@ -99,6 +99,12 @@ public:
m_link = cppClass->link;
}
void clear()
{
QLabel::clear();
m_link = CPPEditorWidget::Link();
}
private:
void mousePressEvent(QMouseEvent *)
{
......@@ -114,45 +120,42 @@ private:
CPPEditorWidget::Link m_link;
};
} // namespace Internal
} // namespace CppEditor
// CppTypeHierarchyWidget
CppTypeHierarchyWidget::CppTypeHierarchyWidget(Core::IEditor *editor) :
CppTypeHierarchyWidget::CppTypeHierarchyWidget() :
QWidget(0),
m_treeView(0),
m_model(0),
m_delegate(0)
m_delegate(0),
m_noTypeHierarchyAvailableLabel(0)
{
m_inspectedClass = new CppClassLabel(this);
m_inspectedClass->setMargin(5);
m_model = new QStandardItemModel(this);
m_treeView = new NavigationTreeView(this);
m_delegate = new AnnotatedItemDelegate(this);
m_delegate->setDelimiter(QLatin1String(" "));
m_delegate->setAnnotationRole(AnnotationRole);
m_treeView->setModel(m_model);
m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_treeView->setItemDelegate(m_delegate);
m_treeView->setRootIsDecorated(false);
connect(m_treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(onItemClicked(QModelIndex)));
m_noTypeHierarchyAvailableLabel = new QLabel(tr("No type hierarchy available"), this);
m_noTypeHierarchyAvailableLabel->setAlignment(Qt::AlignCenter);
m_noTypeHierarchyAvailableLabel->setAutoFillBackground(true);
m_noTypeHierarchyAvailableLabel->setBackgroundRole(QPalette::Base);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
layout->setSpacing(0);
layout->addWidget(m_inspectedClass);
layout->addWidget(m_treeView);
layout->addWidget(m_noTypeHierarchyAvailableLabel);
if (qobject_cast<CPPEditor *>(editor)) {
m_inspectedClass = new CppClassLabel(this);
m_inspectedClass->setMargin(5);
layout->addWidget(m_inspectedClass);
m_model = new QStandardItemModel(this);
m_treeView = new NavigationTreeView(this);
m_delegate = new AnnotatedItemDelegate(this);
m_delegate->setDelimiter(QLatin1String(" "));
m_delegate->setAnnotationRole(AnnotationRole);
m_treeView->setModel(m_model);
m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_treeView->setItemDelegate(m_delegate);
m_treeView->setRootIsDecorated(false);
layout->addWidget(m_treeView);
connect(m_treeView, SIGNAL(clicked(QModelIndex)), this, SLOT(onItemClicked(QModelIndex)));
connect(CppEditorPlugin::instance(), SIGNAL(typeHierarchyRequested()), this, SLOT(perform()));
} else {
QLabel *label = new QLabel(tr("No type hierarchy available"), this);
label->setAlignment(Qt::AlignCenter);
label->setAutoFillBackground(true);
label->setBackgroundRole(QPalette::Base);
layout->addWidget(label);
}
setLayout(layout);
connect(CppEditorPlugin::instance(), SIGNAL(typeHierarchyRequested()), SLOT(perform()));
}
CppTypeHierarchyWidget::~CppTypeHierarchyWidget()
......@@ -160,14 +163,17 @@ CppTypeHierarchyWidget::~CppTypeHierarchyWidget()
void CppTypeHierarchyWidget::perform()
{
showNoTypeHierarchyLabel();
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();
clearTypeHierarchy();
CppElementEvaluator evaluator(widget);
evaluator.setLookupBaseClasses(true);
......@@ -185,11 +191,14 @@ void CppTypeHierarchyWidget::perform()
m_model->invisibleRootItem()->appendRow(derived);
buildHierarchy(*cppClass, derived, true, &CppClass::derived);
m_treeView->expandAll();
showTypeHierarchy();
}
}
}
void CppTypeHierarchyWidget::buildHierarchy(const CppClass &cppClass, QStandardItem *parent, bool isRoot, const HierarchyMember member)
void CppTypeHierarchyWidget::buildHierarchy(const CppClass &cppClass, QStandardItem *parent,
bool isRoot, const HierarchyMember member)
{
if (!isRoot) {
QStandardItem *item = itemForClass(cppClass);
......@@ -200,6 +209,26 @@ void CppTypeHierarchyWidget::buildHierarchy(const CppClass &cppClass, QStandardI
buildHierarchy(klass, parent, false, member);
}
void CppTypeHierarchyWidget::showNoTypeHierarchyLabel()
{
m_inspectedClass->hide();
m_treeView->hide();
m_noTypeHierarchyAvailableLabel->show();
}
void CppTypeHierarchyWidget::showTypeHierarchy()
{
m_inspectedClass->show();
m_treeView->show();
m_noTypeHierarchyAvailableLabel->hide();
}
void CppTypeHierarchyWidget::clearTypeHierarchy()
{
m_inspectedClass->clear();
m_model->clear();
}
void CppTypeHierarchyWidget::onItemClicked(const QModelIndex &index)
{
const TextEditor::BaseTextEditorWidget::Link link
......@@ -214,7 +243,7 @@ void CppTypeHierarchyWidget::onItemClicked(const QModelIndex &index)
// CppTypeHierarchyStackedWidget
CppTypeHierarchyStackedWidget::CppTypeHierarchyStackedWidget(QWidget *parent) :
QStackedWidget(parent),
m_typeHiearchyWidgetInstance(new CppTypeHierarchyWidget(Core::EditorManager::currentEditor()))
m_typeHiearchyWidgetInstance(new CppTypeHierarchyWidget)
{
addWidget(m_typeHiearchyWidgetInstance);
}
......@@ -259,3 +288,7 @@ Core::NavigationView CppTypeHierarchyFactory::createWidget()
navigationView.widget = w;
return navigationView;
}
} // namespace Internal
} // namespace CppEditor
......@@ -65,7 +65,7 @@ class CppTypeHierarchyWidget : public QWidget
{
Q_OBJECT
public:
CppTypeHierarchyWidget(Core::IEditor *editor);
CppTypeHierarchyWidget();
virtual ~CppTypeHierarchyWidget();
public slots:
......@@ -76,13 +76,18 @@ private slots:
private:
typedef QList<CppClass> CppClass::*HierarchyMember;
void buildHierarchy(const CppClass &cppClass, QStandardItem *parent, bool isRoot, HierarchyMember member);
void buildHierarchy(const CppClass &cppClass, QStandardItem *parent,
bool isRoot, HierarchyMember member);
void showNoTypeHierarchyLabel();
void showTypeHierarchy();
void clearTypeHierarchy();
CPPEditorWidget *m_cppEditor;
Utils::NavigationTreeView *m_treeView;
QStandardItemModel *m_model;
Utils::AnnotatedItemDelegate *m_delegate;
CppClassLabel *m_inspectedClass;
QLabel *m_noTypeHierarchyAvailableLabel;
};
// @todo: Pretty much the same design as the OutlineWidgetStack. Maybe we can generalize the
......
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