diff --git a/src/plugins/cppeditor/cpptypehierarchy.cpp b/src/plugins/cppeditor/cpptypehierarchy.cpp index 837375b6f37..228e494a70d 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.cpp +++ b/src/plugins/cppeditor/cpptypehierarchy.cpp @@ -12,26 +12,83 @@ #include #include #include + #include + #include #include #include +#include #include #include -#include +#include +#include #include #include #include #include +#include #include +#include +#include #include -using namespace CppEditor; -using namespace CppEditor::Internal; using namespace Utils; -namespace { +namespace CppEditor::Internal { + +class CppClass; +class CppElement; + +class CppTypeHierarchyModel : public QStandardItemModel +{ +public: + CppTypeHierarchyModel(QObject *parent) + : QStandardItemModel(parent) + {} + + Qt::DropActions supportedDragActions() const override; + QStringList mimeTypes() const override; + QMimeData *mimeData(const QModelIndexList &indexes) const override; +}; + +class CppTypeHierarchyWidget : public QWidget +{ +public: + CppTypeHierarchyWidget(); + + void perform(); + +private: + void displayHierarchy(); + typedef QList CppClass::*HierarchyMember; + void performFromExpression(const QString &expression, const FilePath &filePath); + QStandardItem *buildHierarchy(const CppClass &cppClass, QStandardItem *parent, + bool isRoot, HierarchyMember member); + void showNoTypeHierarchyLabel(); + void showTypeHierarchy(); + void showProgress(); + void hideProgress(); + void clearTypeHierarchy(); + void onItemActivated(const QModelIndex &index); + void onItemDoubleClicked(const QModelIndex &index); + + CppEditorWidget *m_cppEditor = nullptr; + NavigationTreeView *m_treeView = nullptr; + QWidget *m_hierarchyWidget = nullptr; + QStackedLayout *m_stackLayout = nullptr; + QStandardItemModel *m_model = nullptr; + AnnotatedItemDelegate *m_delegate = nullptr; + TextEditor::TextEditorLinkLabel *m_inspectedClass = nullptr; + QLabel *m_infoLabel = nullptr; + QFuture> m_future; + QFutureWatcher m_futureWatcher; + FutureSynchronizer m_synchronizer; + ProgressIndicator *m_progressIndicator = nullptr; + QString m_oldClass; + bool m_showOldClass = false; +}; enum ItemRole { AnnotationRole = Qt::UserRole + 1, @@ -61,55 +118,44 @@ QList sortClasses(const QList &cppClasses) }); } -} // Anonymous - class CppTypeHierarchyTreeView : public NavigationTreeView { - Q_OBJECT public: - CppTypeHierarchyTreeView(QWidget *parent); + CppTypeHierarchyTreeView(QWidget *parent) + : NavigationTreeView(parent) + {} - void contextMenuEvent(QContextMenuEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override + { + if (!event) + return; + + QMenu contextMenu; + + QAction *action = contextMenu.addAction(Tr::tr("Open in Editor")); + connect(action, &QAction::triggered, this, [this] () { + emit activated(currentIndex()); + }); + action = contextMenu.addAction(Tr::tr("Open Type Hierarchy")); + connect(action, &QAction::triggered, this, [this] () { + emit doubleClicked(currentIndex()); + }); + + contextMenu.addSeparator(); + + action = contextMenu.addAction(Tr::tr("Expand All")); + connect(action, &QAction::triggered, this, &QTreeView::expandAll); + action = contextMenu.addAction(Tr::tr("Collapse All")); + connect(action, &QAction::triggered, this, &QTreeView::collapseAll); + + contextMenu.exec(event->globalPos()); + + event->accept(); + } }; - -CppTypeHierarchyTreeView::CppTypeHierarchyTreeView(QWidget *parent) : - NavigationTreeView(parent) -{ -} - -void CppTypeHierarchyTreeView::contextMenuEvent(QContextMenuEvent *event) -{ - if (!event) - return; - - QMenu contextMenu; - - QAction *action = contextMenu.addAction(Tr::tr("Open in Editor")); - connect(action, &QAction::triggered, this, [this] () { - emit activated(currentIndex()); - }); - action = contextMenu.addAction(Tr::tr("Open Type Hierarchy")); - connect(action, &QAction::triggered, this, [this] () { - emit doubleClicked(currentIndex()); - }); - - contextMenu.addSeparator(); - - action = contextMenu.addAction(Tr::tr("Expand All")); - connect(action, &QAction::triggered, this, &QTreeView::expandAll); - action = contextMenu.addAction(Tr::tr("Collapse All")); - connect(action, &QAction::triggered, this, &QTreeView::collapseAll); - - contextMenu.exec(event->globalPos()); - - event->accept(); -} - -namespace CppEditor { -namespace Internal { - // CppTypeHierarchyWidget + CppTypeHierarchyWidget::CppTypeHierarchyWidget() { m_inspectedClass = new TextEditor::TextEditorLinkLabel(this); @@ -323,26 +369,6 @@ void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index) performFromExpression(getExpression(index), link.targetFilePath); } -// CppTypeHierarchyFactory -CppTypeHierarchyFactory::CppTypeHierarchyFactory() -{ - setDisplayName(Tr::tr("Type Hierarchy")); - setPriority(700); - setId(Constants::TYPE_HIERARCHY_ID); -} - -Core::NavigationView CppTypeHierarchyFactory::createWidget() -{ - auto w = new CppTypeHierarchyWidget; - w->perform(); - return {w, {}}; -} - -CppTypeHierarchyModel::CppTypeHierarchyModel(QObject *parent) - : QStandardItemModel(parent) -{ -} - Qt::DropActions CppTypeHierarchyModel::supportedDragActions() const { // copy & move actions to avoid idiotic behavior of drag and drop: @@ -369,7 +395,20 @@ QMimeData *CppTypeHierarchyModel::mimeData(const QModelIndexList &indexes) const return data; } -} // namespace Internal -} // namespace CppEditor +// CppTypeHierarchyFactory -#include "cpptypehierarchy.moc" +CppTypeHierarchyFactory::CppTypeHierarchyFactory() +{ + setDisplayName(Tr::tr("Type Hierarchy")); + setPriority(700); + setId(Constants::TYPE_HIERARCHY_ID); +} + +Core::NavigationView CppTypeHierarchyFactory::createWidget() +{ + auto w = new CppTypeHierarchyWidget; + w->perform(); + return {w, {}}; +} + +} // CppEditor::Internal diff --git a/src/plugins/cppeditor/cpptypehierarchy.h b/src/plugins/cppeditor/cpptypehierarchy.h index 4e782242224..37eaec2a78e 100644 --- a/src/plugins/cppeditor/cpptypehierarchy.h +++ b/src/plugins/cppeditor/cpptypehierarchy.h @@ -4,100 +4,15 @@ #pragma once #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QLabel; -class QModelIndex; -class QStackedLayout; -class QStandardItem; -QT_END_NAMESPACE - -namespace TextEditor { class TextEditorLinkLabel; } - -namespace Utils { -class AnnotatedItemDelegate; -class NavigationTreeView; -class ProgressIndicator; -} - -namespace CppEditor { -class CppEditorWidget; - -namespace Internal { -class CppClass; -class CppElement; - -class CppTypeHierarchyModel : public QStandardItemModel -{ - Q_OBJECT - -public: - CppTypeHierarchyModel(QObject *parent); - - Qt::DropActions supportedDragActions() const override; - QStringList mimeTypes() const override; - QMimeData *mimeData(const QModelIndexList &indexes) const override; -}; - -class CppTypeHierarchyWidget : public QWidget -{ - Q_OBJECT -public: - CppTypeHierarchyWidget(); - - void perform(); - -private slots: - void displayHierarchy(); - -private: - typedef QList CppClass::*HierarchyMember; - void performFromExpression(const QString &expression, const Utils::FilePath &filePath); - QStandardItem *buildHierarchy(const CppClass &cppClass, QStandardItem *parent, - bool isRoot, HierarchyMember member); - void showNoTypeHierarchyLabel(); - void showTypeHierarchy(); - void showProgress(); - void hideProgress(); - void clearTypeHierarchy(); - void onItemActivated(const QModelIndex &index); - void onItemDoubleClicked(const QModelIndex &index); - - CppEditorWidget *m_cppEditor = nullptr; - Utils::NavigationTreeView *m_treeView = nullptr; - QWidget *m_hierarchyWidget = nullptr; - QStackedLayout *m_stackLayout = nullptr; - QStandardItemModel *m_model = nullptr; - Utils::AnnotatedItemDelegate *m_delegate = nullptr; - TextEditor::TextEditorLinkLabel *m_inspectedClass = nullptr; - QLabel *m_infoLabel = nullptr; - QFuture> m_future; - QFutureWatcher m_futureWatcher; - Utils::FutureSynchronizer m_synchronizer; - Utils::ProgressIndicator *m_progressIndicator = nullptr; - QString m_oldClass; - bool m_showOldClass = false; -}; +namespace CppEditor::Internal { class CppTypeHierarchyFactory : public Core::INavigationWidgetFactory { - Q_OBJECT - public: CppTypeHierarchyFactory(); Core::NavigationView createWidget() override; }; -} // namespace Internal -} // namespace CppEditor +} // CppEditor::Internal