CppEditor: Introduce C++ Code Model Inspector

By default invokable via Ctrl+Shift+F12.

Change-Id: If8d61233b6d38d12131718f7c20bf40f76bc9ae4
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-11-03 02:02:36 +01:00
parent 7f829b26e5
commit c4a0f90edd
10 changed files with 2845 additions and 2 deletions

View File

@@ -808,6 +808,11 @@ Symbol **Control::lastSymbol() const
return &*d->symbols.begin() + d->symbols.size();
}
unsigned Control::symbolCount() const
{
return unsigned(d->symbols.size());
}
bool Control::hasSymbol(Symbol *symbol) const
{
return std::find(d->symbols.begin(), d->symbols.end(), symbol) != d->symbols.end();

View File

@@ -213,6 +213,7 @@ public:
Symbol **firstSymbol() const;
Symbol **lastSymbol() const;
unsigned symbolCount() const;
bool hasSymbol(Symbol *symbol) const;
void addSymbol(Symbol *symbol);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,129 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CPPCODEMODELINSPECTORDIALOG_H
#define CPPCODEMODELINSPECTORDIALOG_H
#include <cpptools/cppmodelmanagerinterface.h>
#include <cplusplus/CppDocument.h>
#include <QDialog>
#include <QList>
QT_BEGIN_NAMESPACE
class QSortFilterProxyModel;
class QModelIndex;
namespace Ui { class CppCodeModelInspectorDialog; }
QT_END_NAMESPACE
namespace CppEditor {
namespace Internal {
class FilterableView;
class SnapshotInfo;
class DiagnosticMessagesModel;
class IncludesModel;
class KeyValueModel;
class MacrosModel;
class ProjectPartsModel;
class SnapshotModel;
class SymbolsModel;
class TokensModel;
class WorkingCopyModel;
//
// This dialog is for DEBUGGING PURPOSES and thus NOT TRANSLATED.
//
class CppCodeModelInspectorDialog : public QDialog
{
Q_OBJECT
public:
explicit CppCodeModelInspectorDialog(QWidget *parent = 0);
~CppCodeModelInspectorDialog();
private slots:
void onRefreshRequested();
void onSnapshotFilterChanged(const QString &pattern);
void onSnapshotSelected(int row);
void onDocumentSelected(const QModelIndex &current, const QModelIndex &);
void onSymbolsViewExpandedOrCollapsed(const QModelIndex &);
void onProjectPartFilterChanged(const QString &pattern);
void onProjectPartSelected(const QModelIndex &current, const QModelIndex &);
void onWorkingCopyFilterChanged(const QString &pattern);
void onWorkingCopyDocumentSelected(const QModelIndex &current, const QModelIndex &);
private:
void refresh();
void clearDocumentData();
void updateDocumentData(const CPlusPlus::Document::Ptr &document);
void clearProjectPartData();
void updateProjectPartData(const CppTools::ProjectPart::Ptr &part);
bool event(QEvent *e);
private:
Ui::CppCodeModelInspectorDialog *m_ui;
// Snapshots and Documents
QList<SnapshotInfo> *m_snapshotInfos;
FilterableView *m_snapshotView;
SnapshotModel *m_snapshotModel;
QSortFilterProxyModel *m_proxySnapshotModel;
KeyValueModel *m_docGenericInfoModel;
IncludesModel *m_docIncludesModel;
DiagnosticMessagesModel *m_docDiagnosticMessagesModel;
MacrosModel *m_docMacrosModel;
SymbolsModel *m_docSymbolsModel;
TokensModel *m_docTokensModel;
// Project Parts
FilterableView *m_projectPartsView;
ProjectPartsModel *m_projectPartsModel;
QSortFilterProxyModel *m_proxyProjectPartsModel;
KeyValueModel *m_partGenericInfoModel;
// Working Copy
FilterableView *m_workingCopyView;
WorkingCopyModel *m_workingCopyModel;
QSortFilterProxyModel *m_proxyWorkingCopyModel;
};
} // namespace Internal
} // namespace CppEditor
#endif // CPPCODEMODELINSPECTORDIALOG_H

View File

@@ -0,0 +1,381 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CppCodeModelInspectorDialog</class>
<widget class="QDialog" name="CppCodeModelInspectorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>818</width>
<height>756</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">C++ Code Model Inspector</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string notr="true">&amp;Snapshots and Documents</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="snapshotSelectorAndViewLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="snapshotSelectorLabel">
<property name="text">
<string notr="true">Sn&amp;apshot:</string>
</property>
<property name="buddy">
<cstring>snapshotSelector</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="snapshotSelector">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>100</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QTabWidget" name="docTab">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_8">
<attribute name="title">
<string notr="true">&amp;General</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeView" name="docGeneralView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_7">
<attribute name="title">
<string notr="true">&amp;Includes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTreeView" name="docIncludesView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_6">
<attribute name="title">
<string notr="true">&amp;Diagnostic Messages</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QTreeView" name="docDiagnosticMessagesView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string notr="true">(Un)Defined &amp;Macros</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QTreeView" name="docDefinedMacrosView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string notr="true">P&amp;reprocessed Source</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPlainTextEdit" name="docPreprocessedSourceEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_9">
<attribute name="title">
<string notr="true">&amp;Symbols</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QTreeView" name="docSymbolsView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_10">
<attribute name="title">
<string notr="true">&amp;Tokens</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QTreeView" name="docTokensView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string notr="true">&amp;Project Parts</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QSplitter" name="projectPartsSplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTabWidget" name="projectPartTab">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_17">
<attribute name="title">
<string notr="true">&amp;General</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QTreeView" name="partGeneralView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_13">
<attribute name="title">
<string notr="true">Project &amp;Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QPlainTextEdit" name="partProjectFilesEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_14">
<attribute name="title">
<string notr="true">&amp;Defines</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_19">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string notr="true">Toolchain Defines</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QPlainTextEdit" name="partToolchainDefinesEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string notr="true">Project Defines</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QPlainTextEdit" name="partProjectDefinesEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_15">
<attribute name="title">
<string notr="true">&amp;Include Paths</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<widget class="QPlainTextEdit" name="partIncludePathsEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="definesTab_2">
<attribute name="title">
<string notr="true">F&amp;ramework Paths</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_17">
<item>
<widget class="QPlainTextEdit" name="partFrameworkPathsEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_16">
<attribute name="title">
<string notr="true">Pre&amp;compiled Headers</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_18">
<item>
<widget class="QPlainTextEdit" name="partPrecompiledHeadersEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string notr="true">&amp;Working Copy</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QSplitter" name="workingCopySplitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>true</bool>
</property>
<widget class="QPlainTextEdit" name="workingCopySourceEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="refreshButton">
<property name="text">
<string notr="true">&amp;Refresh</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="selectEditorRelevantEntriesAfterRefreshCheckBox">
<property name="text">
<string notr="true">Select &amp;editor relevant entries after refresh</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="text">
<string notr="true">Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -4,6 +4,7 @@ include(../../qtcreatorplugin.pri)
HEADERS += \
cppautocompleter.h \
cppclasswizard.h \
cppcodemodelinspectordialog.h \
cppeditor.h \
cppeditor_global.h \
cppeditorconstants.h \
@@ -33,6 +34,7 @@ HEADERS += \
SOURCES += \
cppautocompleter.cpp \
cppclasswizard.cpp \
cppcodemodelinspectordialog.cpp \
cppeditor.cpp \
cppeditorplugin.cpp \
cppelementevaluator.cpp \
@@ -57,7 +59,8 @@ SOURCES += \
cppvirtualfunctionproposalitem.cpp
FORMS += \
cpppreprocessordialog.ui
cpppreprocessordialog.ui \
cppcodemodelinspectordialog.ui
RESOURCES += \
cppeditor.qrc
@@ -74,4 +77,3 @@ equals(TEST, 1) {
followsymbol_switchmethoddecldef_test.cpp
DEFINES += SRCDIR=\\\"$$PWD\\\"
}

View File

@@ -16,6 +16,7 @@ QtcPlugin {
files: [
"cppautocompleter.cpp", "cppautocompleter.h",
"cppclasswizard.cpp", "cppclasswizard.h",
"cppcodemodelinspectordialog.cpp", "cppcodemodelinspectordialog.h", "cppcodemodelinspectordialog.ui",
"cppeditor.cpp", "cppeditor.h",
"cppeditor.qrc",
"cppeditor_global.h",

View File

@@ -44,6 +44,7 @@ const char FIND_USAGES[] = "CppEditor.FindUsages";
const char OPEN_PREPROCESSOR_DIALOG[] = "CppEditor.OpenPreprocessorDialog";
const char M_REFACTORING_MENU_INSERTION_POINT[] = "CppEditor.RefactorGroup";
const char UPDATE_CODEMODEL[] = "CppEditor.UpdateCodeModel";
const char INSPECT_CPP_CODEMODEL[] = "CppEditor.InspectCppCodeModel";
const int TYPE_HIERARCHY_PRIORITY = 700;
const char TYPE_HIERARCHY_ID[] = "CppEditor.TypeHierarchy";

View File

@@ -42,6 +42,8 @@
#include "cppquickfixes.h"
#include "cpphighlighterfactory.h"
#include "cppcodemodelinspectordialog.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
@@ -285,6 +287,11 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
connect(m_reparseExternallyChangedFiles, SIGNAL(triggered()), cppModelManager, SLOT(updateModifiedSourceFiles()));
cppToolsMenu->addAction(cmd);
QAction *inspectCppCodeModel = new QAction(tr("Debug: Inspect C++ Code Model"), this);
cmd = ActionManager::registerAction(inspectCppCodeModel, Constants::INSPECT_CPP_CODEMODEL, globalContext);
cmd->setDefaultKeySequence(QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+F12") : tr("Ctrl+Shift+F12")));
connect(inspectCppCodeModel, SIGNAL(triggered()), this, SLOT(inspectCppCodeModel()));
m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
@@ -387,6 +394,16 @@ void CppEditorPlugin::onAllTasksFinished(Core::Id type)
}
}
void CppEditorPlugin::inspectCppCodeModel()
{
if (m_cppCodeModelInspectorDialog) {
ICore::raiseWindow(m_cppCodeModelInspectorDialog);
} else {
m_cppCodeModelInspectorDialog = new CppCodeModelInspectorDialog(ICore::mainWindow());
m_cppCodeModelInspectorDialog->show();
}
}
void CppEditorPlugin::openTypeHierarchy()
{
if (currentCppEditorWidget()) {

View File

@@ -46,6 +46,7 @@ namespace CppEditor {
namespace Internal {
class CPPEditorWidget;
class CppCodeModelInspectorDialog;
class CppQuickFixCollector;
class CppQuickFixAssistProvider;
@@ -90,6 +91,7 @@ public slots:
private slots:
void onTaskStarted(Core::Id type);
void onAllTasksFinished(Core::Id type);
void inspectCppCodeModel();
#ifdef WITH_TESTS
private slots:
@@ -242,6 +244,8 @@ private:
CppQuickFixAssistProvider *m_quickFixProvider;
QPointer<CppCodeModelInspectorDialog> m_cppCodeModelInspectorDialog;
QPointer<TextEditor::ITextEditor> m_currentEditor;
};