forked from qt-creator/qt-creator
CppEditor: Hide part of CppTypeHierarchy implementation
Change-Id: I5635f320e7d746702e6e86bd5f4e8cc749c804f5 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -12,26 +12,83 @@
|
|||||||
#include <coreplugin/find/itemviewfind.h>
|
#include <coreplugin/find/itemviewfind.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
|
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/delegates.h>
|
#include <utils/delegates.h>
|
||||||
#include <utils/dropsupport.h>
|
#include <utils/dropsupport.h>
|
||||||
|
#include <utils/futuresynchronizer.h>
|
||||||
#include <utils/navigationtreeview.h>
|
#include <utils/navigationtreeview.h>
|
||||||
#include <utils/progressindicator.h>
|
#include <utils/progressindicator.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLatin1String>
|
#include <QLatin1String>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
|
#include <QSharedPointer>
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
using namespace CppEditor;
|
|
||||||
using namespace CppEditor::Internal;
|
|
||||||
using namespace Utils;
|
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> 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<QSharedPointer<CppElement>> m_future;
|
||||||
|
QFutureWatcher<void> m_futureWatcher;
|
||||||
|
FutureSynchronizer m_synchronizer;
|
||||||
|
ProgressIndicator *m_progressIndicator = nullptr;
|
||||||
|
QString m_oldClass;
|
||||||
|
bool m_showOldClass = false;
|
||||||
|
};
|
||||||
|
|
||||||
enum ItemRole {
|
enum ItemRole {
|
||||||
AnnotationRole = Qt::UserRole + 1,
|
AnnotationRole = Qt::UserRole + 1,
|
||||||
@@ -61,55 +118,44 @@ QList<CppClass> sortClasses(const QList<CppClass> &cppClasses)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Anonymous
|
|
||||||
|
|
||||||
class CppTypeHierarchyTreeView : public NavigationTreeView
|
class CppTypeHierarchyTreeView : public NavigationTreeView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
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::CppTypeHierarchyWidget()
|
CppTypeHierarchyWidget::CppTypeHierarchyWidget()
|
||||||
{
|
{
|
||||||
m_inspectedClass = new TextEditor::TextEditorLinkLabel(this);
|
m_inspectedClass = new TextEditor::TextEditorLinkLabel(this);
|
||||||
@@ -323,26 +369,6 @@ void CppTypeHierarchyWidget::onItemDoubleClicked(const QModelIndex &index)
|
|||||||
performFromExpression(getExpression(index), link.targetFilePath);
|
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
|
Qt::DropActions CppTypeHierarchyModel::supportedDragActions() const
|
||||||
{
|
{
|
||||||
// copy & move actions to avoid idiotic behavior of drag and drop:
|
// copy & move actions to avoid idiotic behavior of drag and drop:
|
||||||
@@ -369,7 +395,20 @@ QMimeData *CppTypeHierarchyModel::mimeData(const QModelIndexList &indexes) const
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
// CppTypeHierarchyFactory
|
||||||
} // namespace CppEditor
|
|
||||||
|
|
||||||
#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
|
||||||
|
@@ -4,100 +4,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <coreplugin/inavigationwidgetfactory.h>
|
#include <coreplugin/inavigationwidgetfactory.h>
|
||||||
#include <utils/futuresynchronizer.h>
|
|
||||||
|
|
||||||
#include <QFuture>
|
namespace CppEditor::Internal {
|
||||||
#include <QFutureWatcher>
|
|
||||||
#include <QList>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QStackedWidget>
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
#include <QString>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
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> 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<QSharedPointer<CppElement>> m_future;
|
|
||||||
QFutureWatcher<void> m_futureWatcher;
|
|
||||||
Utils::FutureSynchronizer m_synchronizer;
|
|
||||||
Utils::ProgressIndicator *m_progressIndicator = nullptr;
|
|
||||||
QString m_oldClass;
|
|
||||||
bool m_showOldClass = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CppTypeHierarchyFactory : public Core::INavigationWidgetFactory
|
class CppTypeHierarchyFactory : public Core::INavigationWidgetFactory
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppTypeHierarchyFactory();
|
CppTypeHierarchyFactory();
|
||||||
|
|
||||||
Core::NavigationView createWidget() override;
|
Core::NavigationView createWidget() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // CppEditor::Internal
|
||||||
} // namespace CppEditor
|
|
||||||
|
Reference in New Issue
Block a user