Commit d9b4c14c authored by Milian Wolff's avatar Milian Wolff

tie DUContext::createNavigationWidget to AbstractNavigationWidget

We always return instances of this type anyways, so enforce it in
the API and simplify the usage code accordingly.
parent f633da0d
...@@ -292,10 +292,9 @@ BasicRefactoring::NameAndCollector BasicRefactoring::newNameForDeclaration( ...@@ -292,10 +292,9 @@ BasicRefactoring::NameAndCollector BasicRefactoring::newNameForDeclaration(
UsesWidget uses(declaration.data(), collector); UsesWidget uses(declaration.data(), collector);
//So the context-links work //So the context-links work
QWidget* navigationWidget = declaration->context()->createNavigationWidget(declaration.data()); auto* navigationWidget = declaration->context()->createNavigationWidget(declaration.data());
auto* abstractNavigationWidget = dynamic_cast<AbstractNavigationWidget*>(navigationWidget); if (navigationWidget)
if (abstractNavigationWidget) connect(&uses, &UsesWidget::navigateDeclaration, navigationWidget,
connect(&uses, &UsesWidget::navigateDeclaration, abstractNavigationWidget,
&AbstractNavigationWidget::navigateDeclaration); &AbstractNavigationWidget::navigateDeclaration);
QString declarationName = declaration->toString(); QString declarationName = declaration->toString();
......
...@@ -1495,8 +1495,8 @@ TopDUContext* DUContext::topContext() const ...@@ -1495,8 +1495,8 @@ TopDUContext* DUContext::topContext() const
return m_dynamicData->m_topContext; return m_dynamicData->m_topContext;
} }
QWidget* DUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, AbstractNavigationWidget* DUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
AbstractNavigationWidget::DisplayHints hints) const AbstractNavigationWidget::DisplayHints hints) const
{ {
if (decl) { if (decl) {
auto* widget = new AbstractNavigationWidget; auto* widget = new AbstractNavigationWidget;
......
...@@ -666,9 +666,6 @@ private: ...@@ -666,9 +666,6 @@ private:
/** /**
* Can be specialized by languages to create a navigation/information-widget. * Can be specialized by languages to create a navigation/information-widget.
* *
* Ideally, the widget would be based on @c KDevelop::QuickOpenEmbeddedWidgetInterface
* for user-interaction within the quickopen list.
*
* The returned widget will be owned by the caller. * The returned widget will be owned by the caller.
* *
* @param decl A member-declaration of this context the navigation-widget should be created for. * @param decl A member-declaration of this context the navigation-widget should be created for.
...@@ -682,9 +679,9 @@ private: ...@@ -682,9 +679,9 @@ private:
* then the widget will not close when the cursor moves in the document, which * then the widget will not close when the cursor moves in the document, which
* enables you to change the document contents from the widget without immediately closing the widget. * enables you to change the document contents from the widget without immediately closing the widget.
*/ */
virtual QWidget* createNavigationWidget(Declaration* decl = nullptr, TopDUContext* topContext = nullptr, virtual AbstractNavigationWidget*
AbstractNavigationWidget::DisplayHints hints = createNavigationWidget(Declaration* decl = nullptr, TopDUContext* topContext = nullptr,
AbstractNavigationWidget::NoHints) const; AbstractNavigationWidget::DisplayHints hints = AbstractNavigationWidget::NoHints) const;
enum { enum {
Identity = 2 Identity = 2
......
...@@ -257,10 +257,10 @@ NavigationContextPointer AbstractNavigationContext::registerChild(AbstractNaviga ...@@ -257,10 +257,10 @@ NavigationContextPointer AbstractNavigationContext::registerChild(AbstractNaviga
NavigationContextPointer AbstractNavigationContext::registerChild(const DeclarationPointer& declaration) NavigationContextPointer AbstractNavigationContext::registerChild(const DeclarationPointer& declaration)
{ {
//We create a navigation-widget here, and steal its context.. evil ;) //We create a navigation-widget here, and steal its context.. evil ;)
QScopedPointer<QWidget> navigationWidget(declaration->context()->createNavigationWidget(declaration.data())); QScopedPointer<AbstractNavigationWidget> navigationWidget(
if (auto* abstractNavigationWidget = declaration->context()->createNavigationWidget(declaration.data()));
dynamic_cast<AbstractNavigationWidget*>(navigationWidget.data())) { if (navigationWidget) {
NavigationContextPointer ret = abstractNavigationWidget->context(); NavigationContextPointer ret = navigationWidget->context();
ret->setPreviousContext(this); ret->setPreviousContext(this);
d->m_children << ret; d->m_children << ret;
return ret; return ret;
......
...@@ -404,7 +404,7 @@ void MainWindowPrivate::tabToolTipRequested(Sublime::View* view, Sublime::Contai ...@@ -404,7 +404,7 @@ void MainWindowPrivate::tabToolTipRequested(Sublime::View* view, Sublime::Contai
TopDUContext* top = DUChainUtils::standardContextForUrl(urlDoc->url()); TopDUContext* top = DUChainUtils::standardContextForUrl(urlDoc->url());
if (top) { if (top) {
if ( QWidget* navigationWidget = top->createNavigationWidget() ) { if (auto* navigationWidget = top->createNavigationWidget()) {
NavigationToolTip* tooltip = new KDevelop::NavigationToolTip(m_mainWindow, QCursor::pos() + QPoint(20, 20), navigationWidget); NavigationToolTip* tooltip = new KDevelop::NavigationToolTip(m_mainWindow, QCursor::pos() + QPoint(20, 20), navigationWidget);
tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10)); tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10));
tooltip->setHandleRect(container->tabRect(tab)); tooltip->setHandleRect(container->tabRect(tab));
......
...@@ -28,9 +28,10 @@ ...@@ -28,9 +28,10 @@
using namespace KDevelop; using namespace KDevelop;
template<> template <>
QWidget* ClangTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, KDevelop::AbstractNavigationWidget*
KDevelop::AbstractNavigationWidget::DisplayHints hints) const ClangTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
KDevelop::AbstractNavigationWidget::DisplayHints hints) const
{ {
if (!decl) { if (!decl) {
const QUrl u = url().toUrl(); const QUrl u = url().toUrl();
...@@ -45,9 +46,10 @@ QWidget* ClangTopDUContext::createNavigationWidget(Declaration* decl, TopDUConte ...@@ -45,9 +46,10 @@ QWidget* ClangTopDUContext::createNavigationWidget(Declaration* decl, TopDUConte
return new ClangNavigationWidget(DeclarationPointer(decl), hints); return new ClangNavigationWidget(DeclarationPointer(decl), hints);
} }
template<> template <>
QWidget* ClangNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* /*topContext*/, KDevelop::AbstractNavigationWidget*
KDevelop::AbstractNavigationWidget::DisplayHints hints) const ClangNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* /*topContext*/,
KDevelop::AbstractNavigationWidget::DisplayHints hints) const
{ {
if (!decl) { if (!decl) {
clangDebug() << "no declaration, not returning navigationwidget"; clangDebug() << "no declaration, not returning navigationwidget";
......
...@@ -39,9 +39,10 @@ public: ...@@ -39,9 +39,10 @@ public:
static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this); static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this);
} }
QWidget* createNavigationWidget(KDevelop::Declaration* decl = nullptr, KDevelop::AbstractNavigationWidget*
KDevelop::TopDUContext* topContext = nullptr, createNavigationWidget(KDevelop::Declaration* decl = nullptr, KDevelop::TopDUContext* topContext = nullptr,
KDevelop::AbstractNavigationWidget::DisplayHints hints = KDevelop::AbstractNavigationWidget::NoHints) const override; KDevelop::AbstractNavigationWidget::DisplayHints hints
= KDevelop::AbstractNavigationWidget::NoHints) const override;
enum { enum {
Identity = IdentityT Identity = IdentityT
......
...@@ -111,8 +111,7 @@ bool ClassTree::event(QEvent* event) ...@@ -111,8 +111,7 @@ bool ClassTree::event(QEvent* event)
if (m_tooltip) { if (m_tooltip) {
m_tooltip->close(); m_tooltip->close();
} }
QWidget* navigationWidget = decl->topContext()->createNavigationWidget(decl); if (auto* navigationWidget = decl->topContext()->createNavigationWidget(decl)) {
if (navigationWidget) {
m_tooltip = new KDevelop::NavigationToolTip(this, helpEvent->globalPos() + QPoint(40, m_tooltip = new KDevelop::NavigationToolTip(this, helpEvent->globalPos() + QPoint(40,
0), navigationWidget); 0), navigationWidget);
m_tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10)); m_tooltip->resize(navigationWidget->sizeHint() + QSize(10, 10));
......
...@@ -131,7 +131,7 @@ void selectUse(ContextBrowserView* view, Direction direction) ...@@ -131,7 +131,7 @@ void selectUse(ContextBrowserView* view, Direction direction)
} }
} }
QWidget* ContextBrowserView::createWidget(KDevelop::DUContext* context) AbstractNavigationWidget* ContextBrowserView::createWidget(KDevelop::DUContext* context)
{ {
m_context = IndexedDUContext(context); m_context = IndexedDUContext(context);
if (m_context.data()) { if (m_context.data()) {
...@@ -145,7 +145,7 @@ KDevelop::IndexedDeclaration ContextBrowserView::declaration() const ...@@ -145,7 +145,7 @@ KDevelop::IndexedDeclaration ContextBrowserView::declaration() const
return m_declaration; return m_declaration;
} }
QWidget* ContextBrowserView::createWidget(Declaration* decl, TopDUContext* topContext) AbstractNavigationWidget* ContextBrowserView::createWidget(Declaration* decl, TopDUContext* topContext)
{ {
m_declaration = IndexedDeclaration(decl); m_declaration = IndexedDeclaration(decl);
return decl->context()->createNavigationWidget(decl, topContext, AbstractNavigationWidget::EmbeddableWidget); return decl->context()->createNavigationWidget(decl, topContext, AbstractNavigationWidget::EmbeddableWidget);
...@@ -354,8 +354,7 @@ void ContextBrowserView::setDeclaration(KDevelop::Declaration* decl, KDevelop::T ...@@ -354,8 +354,7 @@ void ContextBrowserView::setDeclaration(KDevelop::Declaration* decl, KDevelop::T
m_navigationWidgetDeclaration = decl->id(); m_navigationWidgetDeclaration = decl->id();
if (!isLocked() && (isVisible() || force)) { // NO-OP if tool view is hidden, for performance reasons if (!isLocked() && (isVisible() || force)) { // NO-OP if tool view is hidden, for performance reasons
QWidget* w = createWidget(decl, topContext); updateMainWidget(createWidget(decl, topContext));
updateMainWidget(w);
} }
} }
...@@ -393,8 +392,7 @@ void ContextBrowserView::setContext(KDevelop::DUContext* context) ...@@ -393,8 +392,7 @@ void ContextBrowserView::setContext(KDevelop::DUContext* context)
} }
if (!isLocked() && isVisible()) { // NO-OP if tool view is hidden, for performance reasons if (!isLocked() && isVisible()) { // NO-OP if tool view is hidden, for performance reasons
QWidget* w = createWidget(context); updateMainWidget(createWidget(context));
updateMainWidget(w);
} }
} }
......
...@@ -70,10 +70,10 @@ public: ...@@ -70,10 +70,10 @@ public:
} }
//duchain must be locked //duchain must be locked
QWidget* createWidget(KDevelop::DUContext* context); KDevelop::AbstractNavigationWidget* createWidget(KDevelop::DUContext* context);
//duchain must be locked //duchain must be locked
QWidget* createWidget(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext); KDevelop::AbstractNavigationWidget* createWidget(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext);
KDevelop::IndexedDeclaration declaration() const; KDevelop::IndexedDeclaration declaration() const;
......
...@@ -199,8 +199,7 @@ bool ProjectModelItemDelegate::helpEvent(QHelpEvent* event, ...@@ -199,8 +199,7 @@ bool ProjectModelItemDelegate::helpEvent(QHelpEvent* event,
const TopDUContext* top = DUChainUtils::standardContextForUrl(it->file()->path().toUrl()); const TopDUContext* top = DUChainUtils::standardContextForUrl(it->file()->path().toUrl());
if (top) { if (top) {
QWidget* navigationWidget = top->createNavigationWidget(); if (auto* navigationWidget = top->createNavigationWidget()) {
if (navigationWidget) {
// force possible existing normal tooltip for other list item to hide // force possible existing normal tooltip for other list item to hide
// Seems that is still only done with a small delay though, // Seems that is still only done with a small delay though,
// but the API seems not to allow more control. // but the API seems not to allow more control.
......
...@@ -35,9 +35,9 @@ using namespace KDevelop; ...@@ -35,9 +35,9 @@ using namespace KDevelop;
namespace QmlJS { namespace QmlJS {
template<> template <>
QWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, AbstractNavigationWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
AbstractNavigationWidget::DisplayHints hints) const AbstractNavigationWidget::DisplayHints hints) const
{ {
if (!decl) { if (!decl) {
const QUrl u = url().toUrl(); const QUrl u = url().toUrl();
...@@ -52,15 +52,17 @@ QWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUConte ...@@ -52,15 +52,17 @@ QWidget* QmlJSTopDUContext::createNavigationWidget(Declaration* decl, TopDUConte
return new NavigationWidget(decl, topContext, hints); return new NavigationWidget(decl, topContext, hints);
} }
template<> template <>
QWidget* QmlJSNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext, AbstractNavigationWidget::DisplayHints hints) const { AbstractNavigationWidget*
QmlJSNormalDUContext::createNavigationWidget(Declaration* decl, TopDUContext* topContext,
AbstractNavigationWidget::DisplayHints hints) const
{
if (!decl) { if (!decl) {
qCDebug(KDEV_QMLJS_DUCHAIN) << "no declaration, not returning navigationwidget"; qCDebug(KDEV_QMLJS_DUCHAIN) << "no declaration, not returning navigationwidget";
return nullptr; return nullptr;
} }
return new NavigationWidget(decl, topContext, hints); return new NavigationWidget(decl, topContext, hints);
} }
} }
DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSNormalDUContext, DUContextData) DUCHAIN_DEFINE_TYPE_WITH_DATA(QmlJS::QmlJSNormalDUContext, DUContextData)
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include <language/duchain/duchainregister.h> #include <language/duchain/duchainregister.h>
#include <language/duchain/ducontext.h> #include <language/duchain/ducontext.h>
class QWidget;
namespace KDevelop namespace KDevelop
{ {
class Declaration; class Declaration;
...@@ -61,9 +59,9 @@ public: ...@@ -61,9 +59,9 @@ public:
static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this); static_cast<KDevelop::DUChainBase*>(this)->d_func_dynamic()->setClassId(this);
} }
QWidget* createNavigationWidget(KDevelop::Declaration* decl, KDevelop::AbstractNavigationWidget*
KDevelop::TopDUContext* topContext, createNavigationWidget(KDevelop::Declaration* decl, KDevelop::TopDUContext* topContext,
KDevelop::AbstractNavigationWidget::DisplayHints hints) const override; KDevelop::AbstractNavigationWidget::DisplayHints hints) const override;
enum { enum {
Identity = IdentityT Identity = IdentityT
......
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