Commit f79187ca authored by Leandro Melo's avatar Leandro Melo

Create type hierarchy widget; Refactor code from C++ hover into a simple reusable model.

Hierarchy information removed from tooltips now.
parent 761a9694
...@@ -1755,6 +1755,9 @@ void CPPEditor::unCommentSelection() ...@@ -1755,6 +1755,9 @@ void CPPEditor::unCommentSelection()
CPPEditor::Link CPPEditor::linkToSymbol(CPlusPlus::Symbol *symbol) CPPEditor::Link CPPEditor::linkToSymbol(CPlusPlus::Symbol *symbol)
{ {
if (!symbol)
return Link();
const QString fileName = QString::fromUtf8(symbol->fileName(), const QString fileName = QString::fromUtf8(symbol->fileName(),
symbol->fileNameLength()); symbol->fileNameLength());
unsigned line = symbol->line(); unsigned line = symbol->line();
......
...@@ -180,6 +180,10 @@ public: ...@@ -180,6 +180,10 @@ public:
void setObjCEnabled(bool onoff); void setObjCEnabled(bool onoff);
bool isObjCEnabled() const; bool isObjCEnabled() const;
bool openLink(const Link &link) { return openCppEditorAt(link); }
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
Q_SIGNALS: Q_SIGNALS:
void outlineModelIndexChanged(const QModelIndex &index); void outlineModelIndexChanged(const QModelIndex &index);
...@@ -267,13 +271,10 @@ private: ...@@ -267,13 +271,10 @@ private:
void abortRename(); void abortRename();
Link findLinkAt(const QTextCursor &, bool resolveTarget = true); Link findLinkAt(const QTextCursor &, bool resolveTarget = true);
bool openLink(const Link &link) { return openCppEditorAt(link); }
bool openCppEditorAt(const Link &); bool openCppEditorAt(const Link &);
QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()) const; QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()) const;
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
CppTools::CppModelManagerInterface *m_modelManager; CppTools::CppModelManagerInterface *m_modelManager;
QComboBox *m_outlineCombo; QComboBox *m_outlineCombo;
......
...@@ -20,8 +20,9 @@ HEADERS += cppplugin.h \ ...@@ -20,8 +20,9 @@ HEADERS += cppplugin.h \
cppsemanticinfo.h \ cppsemanticinfo.h \
cppoutline.h \ cppoutline.h \
cppdeclfromdef.h \ cppdeclfromdef.h \
cpplocalsymbols.h cpplocalsymbols.h \
cpptypehierarchy.h \
cppelementevaluator.h
SOURCES += cppplugin.cpp \ SOURCES += cppplugin.cpp \
cppeditor.cpp \ cppeditor.cpp \
cpphighlighter.cpp \ cpphighlighter.cpp \
...@@ -35,8 +36,9 @@ SOURCES += cppplugin.cpp \ ...@@ -35,8 +36,9 @@ SOURCES += cppplugin.cpp \
cppsemanticinfo.cpp \ cppsemanticinfo.cpp \
cppoutline.cpp \ cppoutline.cpp \
cppdeclfromdef.cpp \ cppdeclfromdef.cpp \
cpplocalsymbols.cpp cpplocalsymbols.cpp \
cpptypehierarchy.cpp \
cppelementevaluator.cpp
RESOURCES += cppeditor.qrc RESOURCES += cppeditor.qrc
OTHER_FILES += CppEditor.pluginspec \
OTHER_FILES += CppEditor.pluginspec CppEditor.mimetypes.xml CppEditor.mimetypes.xml
...@@ -48,6 +48,9 @@ const char * const FIND_REFERENCES = "CppEditor.FindReferences"; ...@@ -48,6 +48,9 @@ const char * const FIND_REFERENCES = "CppEditor.FindReferences";
const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition"; const char * const JUMP_TO_DEFINITION = "CppEditor.JumpToDefinition";
const char * const UPDATE_CODEMODEL = "CppEditor.UpdateCodeModel"; const char * const UPDATE_CODEMODEL = "CppEditor.UpdateCodeModel";
const char * const TYPE_HIERARCHY_ID = "CppEditor.TypeHierarchy";
const char * const OPEN_TYPE_HIERARCHY = "CppEditor.OpenTypeHierarchy";
const char * const HEADER_FILE_TYPE = "CppHeaderFiles"; const char * const HEADER_FILE_TYPE = "CppHeaderFiles";
const char * const SOURCE_FILE_TYPE = "CppSourceFiles"; const char * const SOURCE_FILE_TYPE = "CppSourceFiles";
......
This diff is collapsed.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef CPPHIGHLEVELMODEL_H
#define CPPHIGHLEVELMODEL_H
#include "cppeditor.h"
#include "cpphoverhandler.h"
#include <cplusplus/CppDocument.h>
#include <cplusplus/Overview.h>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QSharedPointer>
#include <QtGui/QTextCursor>
#include <QtGui/QIcon>
namespace CPlusPlus {
class LookupItem;
class LookupContext;
}
namespace CppTools {
class CppModelManagerInterface;
}
namespace CppEditor {
namespace Internal {
class CPPEditor;
class CppElement;
class CppElementEvaluator
{
public:
CppElementEvaluator(CPPEditor *editor);
void setTextCursor(const QTextCursor &tc);
void setLookupBaseClasses(const bool lookup);
QSharedPointer<CppElement> identifyCppElement();
private:
void evaluate();
bool matchDiagnosticMessage(const CPlusPlus::Document::Ptr &document, unsigned line);
bool matchIncludeFile(const CPlusPlus::Document::Ptr &document, unsigned line);
bool matchMacroInUse(const CPlusPlus::Document::Ptr &document, unsigned pos);
void handleLookupItemMatch(const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::LookupItem &lookupItem,
const CPlusPlus::LookupContext &lookupContext);
CPPEditor *m_editor;
CppTools::CppModelManagerInterface *m_modelManager;
QTextCursor m_tc;
bool m_lookupBaseClasses;
QSharedPointer<CppElement> m_element;
};
class CppElement
{
public:
virtual ~CppElement();
const CppHoverHandler::HelpCandidate::Category &helpCategory() const;
const QStringList &helpIdCandidates() const;
const QString &helpMark() const;
const CPPEditor::Link &link() const;
const QString &tooltip() const;
protected:
CppElement();
void setHelpCategory(const CppHoverHandler::HelpCandidate::Category &category);
void setLink(const CPPEditor::Link &link);
void setTooltip(const QString &tooltip);
void setHelpIdCandidates(const QStringList &candidates);
void addHelpIdCandidate(const QString &candidate);
void setHelpMark(const QString &mark);
private:
CppHoverHandler::HelpCandidate::Category m_helpCategory;
QStringList m_helpIdCandidates;
QString m_helpMark;
CPPEditor::Link m_link;
QString m_tooltip;
};
class Unknown : public CppElement
{
public:
Unknown(const QString &type);
virtual ~Unknown();
const QString &type() const;
private:
QString m_type;
};
class CppDiagnosis : public CppElement
{
public:
CppDiagnosis(const CPlusPlus::Document::DiagnosticMessage &message);
virtual ~CppDiagnosis();
const QString &text() const;
private:
QString m_text;
};
class CppInclude : public CppElement
{
public:
CppInclude(const CPlusPlus::Document::Include &includeFile);
virtual ~CppInclude();
const QString &path() const;
const QString &fileName() const;
private:
QString m_path;
QString m_fileName;
};
class CppMacro : public CppElement
{
public:
CppMacro(const CPlusPlus::Macro &macro);
virtual ~CppMacro();
};
class CppDeclarableElement : public CppElement
{
public:
CppDeclarableElement(CPlusPlus::Symbol *declaration);
virtual ~CppDeclarableElement();
const QString &name() const;
const QString &qualifiedName() const;
const QString &type() const;
const QIcon &icon() const;
protected:
void setName(const QString &name);
void setQualifiedName(const QString &name);
void setType(const QString &type);
void setIcon(const QIcon &icon);
private:
QString m_name;
QString m_qualifiedName;
QString m_type;
QIcon m_icon;
};
class CppNamespace : public CppDeclarableElement
{
public:
CppNamespace(CPlusPlus::Symbol *declaration);
virtual ~CppNamespace();
};
class CppClass : public CppDeclarableElement
{
public:
CppClass(CPlusPlus::Symbol *declaration);
virtual ~CppClass();
void lookupBases(CPlusPlus::Symbol *declaration, const CPlusPlus::LookupContext &context);
const QList<CppClass> &bases() const;
private:
QList<CppClass> m_bases;
};
class CppFunction : public CppDeclarableElement
{
public:
CppFunction(CPlusPlus::Symbol *declaration);
virtual ~CppFunction();
};
class CppEnum : public CppDeclarableElement
{
public:
CppEnum(CPlusPlus::Symbol *declaration);
virtual ~CppEnum();
};
class CppTypedef : public CppDeclarableElement
{
public:
CppTypedef(CPlusPlus::Symbol *declaration);
virtual ~CppTypedef();
};
class CppVariable : public CppDeclarableElement
{
public:
CppVariable(CPlusPlus::Symbol *declaration,
const CPlusPlus::LookupContext &context,
CPlusPlus::Scope *scope);
virtual ~CppVariable();
};
} // namespace Internal
} // namespace CppEditor
#endif // CPPHIGHLEVELMODEL_H
This diff is collapsed.
...@@ -30,26 +30,14 @@ ...@@ -30,26 +30,14 @@
#ifndef CPPHOVERHANDLER_H #ifndef CPPHOVERHANDLER_H
#define CPPHOVERHANDLER_H #define CPPHOVERHANDLER_H
#include <cplusplus/CppDocument.h>
#include <texteditor/basehoverhandler.h> #include <texteditor/basehoverhandler.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QList>
#include <QtCore/QStringList>
namespace CPlusPlus {
class LookupItem;
class LookupContext;
}
namespace Core { namespace Core {
class IEditor; class IEditor;
} }
namespace CppTools {
class CppModelManagerInterface;
}
namespace TextEditor { namespace TextEditor {
class ITextEditor; class ITextEditor;
} }
...@@ -62,26 +50,13 @@ class CppHoverHandler : public TextEditor::BaseHoverHandler ...@@ -62,26 +50,13 @@ class CppHoverHandler : public TextEditor::BaseHoverHandler
Q_OBJECT Q_OBJECT
public: public:
CppHoverHandler(QObject *parent = 0); CppHoverHandler(QObject *parent = 0);
virtual ~CppHoverHandler();
private: private:
virtual bool acceptEditor(Core::IEditor *editor); virtual bool acceptEditor(Core::IEditor *editor);
virtual void identifyMatch(TextEditor::ITextEditor *editor, int pos); virtual void identifyMatch(TextEditor::ITextEditor *editor, int pos);
virtual void resetExtras();
virtual void evaluateHelpCandidates(); virtual void evaluateHelpCandidates();
virtual void decorateToolTip(TextEditor::ITextEditor *editor); virtual void decorateToolTip(TextEditor::ITextEditor *editor);
bool matchDiagnosticMessage(const CPlusPlus::Document::Ptr &document, unsigned line);
bool matchIncludeFile(const CPlusPlus::Document::Ptr &document, unsigned line);
bool matchMacroInUse(const CPlusPlus::Document::Ptr &document, unsigned pos);
void handleLookupItemMatch(const CPlusPlus::LookupItem &lookupItem,
const CPlusPlus::LookupContext &lookupContext,
const bool assignTooltip);
void generateDiagramTooltip(const bool extendTooltips);
void generateNormalTooltip(const bool extendTooltips);
CppTools::CppModelManagerInterface *m_modelManager;
QList<QStringList> m_classHierarchy;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "cpphoverhandler.h" #include "cpphoverhandler.h"
#include "cppquickfix.h" #include "cppquickfix.h"
#include "cppoutline.h" #include "cppoutline.h"
#include "cpptypehierarchy.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
...@@ -46,6 +47,7 @@ ...@@ -46,6 +47,7 @@
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/navigationwidget.h>
#include <texteditor/completionsupport.h> #include <texteditor/completionsupport.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/storagesettings.h> #include <texteditor/storagesettings.h>
...@@ -60,6 +62,7 @@ ...@@ -60,6 +62,7 @@
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QStringList>
#include <QtGui/QMenu> #include <QtGui/QMenu>
...@@ -139,8 +142,8 @@ CppPlugin::CppPlugin() : ...@@ -139,8 +142,8 @@ CppPlugin::CppPlugin() :
m_sortedOutline(false), m_sortedOutline(false),
m_renameSymbolUnderCursorAction(0), m_renameSymbolUnderCursorAction(0),
m_findUsagesAction(0), m_findUsagesAction(0),
m_updateCodeModelAction(0) m_updateCodeModelAction(0),
m_openTypeHierarchyAction(0)
{ {
m_instance = this; m_instance = this;
...@@ -205,7 +208,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess ...@@ -205,7 +208,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
addAutoReleasedObject(new CppEditorFactory(this)); addAutoReleasedObject(new CppEditorFactory(this));
addAutoReleasedObject(new CppHoverHandler); addAutoReleasedObject(new CppHoverHandler);
addAutoReleasedObject(new CppOutlineWidgetFactory); addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory);
m_quickFixCollector = new CppQuickFixCollector; m_quickFixCollector = new CppQuickFixCollector;
addAutoReleasedObject(m_quickFixCollector); addAutoReleasedObject(m_quickFixCollector);
...@@ -274,6 +277,13 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess ...@@ -274,6 +277,13 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
contextMenu->addAction(cmd); contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd); cppToolsMenu->addAction(cmd);
m_openTypeHierarchyAction = new QAction(tr("Open Type Hierarchy"), this);
cmd = am->registerAction(m_openTypeHierarchyAction, Constants::OPEN_TYPE_HIERARCHY, context);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+T")));
connect(m_openTypeHierarchyAction, SIGNAL(triggered()), this, SLOT(openTypeHierarchy()));
contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd);
// Update context in global context // Update context in global context
Core::Context globalContext(Core::Constants::C_GLOBAL); Core::Context globalContext(Core::Constants::C_GLOBAL);
cppToolsMenu->addAction(createSeparator(am, this, globalContext, CppEditor::Constants::SEPARATOR2)); cppToolsMenu->addAction(createSeparator(am, this, globalContext, CppEditor::Constants::SEPARATOR2));
...@@ -391,6 +401,7 @@ void CppPlugin::onTaskStarted(const QString &type) ...@@ -391,6 +401,7 @@ void CppPlugin::onTaskStarted(const QString &type)
m_renameSymbolUnderCursorAction->setEnabled(false); m_renameSymbolUnderCursorAction->setEnabled(false);
m_findUsagesAction->setEnabled(false); m_findUsagesAction->setEnabled(false);
m_updateCodeModelAction->setEnabled(false); m_updateCodeModelAction->setEnabled(false);
m_openTypeHierarchyAction->setEnabled(false);
} }
} }
...@@ -400,6 +411,7 @@ void CppPlugin::onAllTasksFinished(const QString &type) ...@@ -400,6 +411,7 @@ void CppPlugin::onAllTasksFinished(const QString &type)
m_renameSymbolUnderCursorAction->setEnabled(true); m_renameSymbolUnderCursorAction->setEnabled(true);
m_findUsagesAction->setEnabled(true); m_findUsagesAction->setEnabled(true);
m_updateCodeModelAction->setEnabled(true); m_updateCodeModelAction->setEnabled(true);
m_openTypeHierarchyAction->setEnabled(true);
} }
} }
...@@ -413,4 +425,15 @@ void CppPlugin::currentEditorChanged(Core::IEditor *editor) ...@@ -413,4 +425,15 @@ void CppPlugin::currentEditorChanged(Core::IEditor *editor)
} }
} }
void CppPlugin::openTypeHierarchy()
{
Core::EditorManager *em = Core::EditorManager::instance();
CPPEditor *editor = qobject_cast<CPPEditor*>(em->currentEditor()->widget());
if (editor) {
Core::NavigationWidget *navigation = Core::NavigationWidget::instance();
navigation->activateSubWidget(QLatin1String(Constants::TYPE_HIERARCHY_ID));
emit typeHierarchyRequested();
}
}
Q_EXPORT_PLUGIN(CppPlugin) Q_EXPORT_PLUGIN(CppPlugin)
...@@ -71,6 +71,7 @@ public: ...@@ -71,6 +71,7 @@ public:
signals: signals:
void outlineSortingChanged(bool sort); void outlineSortingChanged(bool sort);
void typeHierarchyRequested();
public slots: public slots:
void setSortedOutline(bool sorted); void setSortedOutline(bool sorted);
...@@ -85,6 +86,7 @@ private slots: ...@@ -85,6 +86,7 @@ private slots:
void quickFix(TextEditor::ITextEditable *editable); void quickFix(TextEditor::ITextEditable *editable);
void quickFixNow(); void quickFixNow();
void currentEditorChanged(Core::IEditor *editor); void currentEditorChanged(Core::IEditor *editor);
void openTypeHierarchy();
private: private:
Core::IEditor *createEditor(QWidget *parent); Core::IEditor *createEditor(QWidget *parent);
...@@ -98,6 +100,7 @@ private: ...@@ -98,6 +100,7 @@ private:
QAction *m_renameSymbolUnderCursorAction; QAction *m_renameSymbolUnderCursorAction;
QAction *m_findUsagesAction; QAction *m_findUsagesAction;
QAction *m_updateCodeModelAction; QAction *m_updateCodeModelAction;
QAction *m_openTypeHierarchyAction;
CppQuickFixCollector *m_quickFixCollector; CppQuickFixCollector *m_quickFixCollector;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "cpptypehierarchy.h"
#include "cppeditorconstants.h"
#include "cppeditor.h"
#include "cppelementevaluator.h"
#include "cppplugin.h"
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/coreconstants.h>
#include <utils/navigationtreeview.h>
#include <QtCore/QLatin1Char>
#include <QtCore/QLatin1String>
#include <QtCore/QModelIndex>
#include <QtCore/QSettings>
#include <QtGui/QVBoxLayout>
#include <QtGui/QStandardItemModel>
#include <QtGui/QFontMetrics>
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QLabel>
using namespace CppEditor;
using namespace Internal;
// CppTypeHierarchyItem