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