diff --git a/duchain/navigation/declarationnavigationcontext.cpp b/duchain/navigation/declarationnavigationcontext.cpp index 6faa7a26..1d26c7bc 100644 --- a/duchain/navigation/declarationnavigationcontext.cpp +++ b/duchain/navigation/declarationnavigationcontext.cpp @@ -1,123 +1,123 @@ /* Copyright 2007 David Nolden Copyright 2008 Niko Sams This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "declarationnavigationcontext.h" #include #include #include #include #include #include #include #include #include "helpers.h" #include namespace Python { using namespace KDevelop; DeclarationNavigationContext::DeclarationNavigationContext(DeclarationPointer decl, KDevelop::TopDUContextPointer topContext, AbstractNavigationContext* previousContext) : AbstractDeclarationNavigationContext(decl, topContext, previousContext) { } QString DeclarationNavigationContext::getLink(const QString& name, DeclarationPointer declaration, NavigationAction::Type actionType) { NavigationAction action( declaration, actionType ); QString targetId = QString::number((quint64)declaration.data() * actionType); return createLink(name, targetId, action); }; void DeclarationNavigationContext::htmlClass() { - StructureType::Ptr klass = m_declaration->abstractType().cast(); + StructureType::Ptr klass = declaration()->abstractType().cast(); Q_ASSERT(klass); modifyHtml() += QStringLiteral("class "); eventuallyMakeTypeLinks( klass.cast() ); - auto classDecl = dynamic_cast(klass->declaration(m_topContext.data())); + auto classDecl = dynamic_cast(klass->declaration(topContext().data())); if ( classDecl && classDecl->baseClassesSize() ) { int count = 0; FOREACH_FUNCTION( const BaseClassInstance& base, classDecl->baseClasses ) { modifyHtml() += count++ ? QStringLiteral(", ") : QStringLiteral(" ("); eventuallyMakeTypeLinks(base.baseClass.abstractType()); } modifyHtml() += QStringLiteral(")"); } } QString DeclarationNavigationContext::typeLinkOrString(const AbstractType::Ptr type) { if ( type ) { if ( auto idType = dynamic_cast(type.data()) ) { return getLink(type->toString(), - DeclarationPointer(idType->declaration(m_topContext.data())), + DeclarationPointer(idType->declaration(topContext().data())), NavigationAction::NavigateDeclaration); } return type->toString().toHtmlEscaped(); } return i18nc("refers to an unknown type in programming", "unknown"); } void DeclarationNavigationContext::htmlIdentifiedType(AbstractType::Ptr type, const IdentifiedType* idType) { // TODO this code is duplicate of variablelengthcontainer::toString, resolve that somehow if ( auto listType = type.cast() ) { QString contentType; const QString containerType = getLink(listType->containerToString(), - DeclarationPointer(idType->declaration(m_topContext.data())), + DeclarationPointer(idType->declaration(topContext().data())), NavigationAction::NavigateDeclaration ); if ( auto map = listType.cast() ) { contentType.append(typeLinkOrString(map->keyType().abstractType())); contentType.append(" : "); } contentType.append(typeLinkOrString(listType->contentType().abstractType())); modifyHtml() += i18nc("as in list of int, set of string", "%1 of %2", containerType, contentType); } else if (auto indexedContainer = type.cast()) { const QString containerType = getLink(indexedContainer->containerToString(), - DeclarationPointer(idType->declaration(m_topContext.data())), + DeclarationPointer(idType->declaration(topContext().data())), NavigationAction::NavigateDeclaration ); QStringList typesArray; for ( int i = 0; i < indexedContainer->typesCount(); i++ ) { if ( i >= 5 ) { // Don't print more than five types explicitly typesArray << "..."; break; } typesArray << typeLinkOrString(indexedContainer->typeAt(i).abstractType()); } const QString contentType = QStringLiteral("(") + typesArray.join(", ") + ")"; modifyHtml() += i18nc("as in list of int, set of string", "%1 of %2", containerType, contentType); } else { KDevelop::AbstractDeclarationNavigationContext::htmlIdentifiedType(type, idType); } } void DeclarationNavigationContext::eventuallyMakeTypeLinks(AbstractType::Ptr type) { KDevelop::AbstractDeclarationNavigationContext::eventuallyMakeTypeLinks(Helper::resolveAliasType(type)); } } diff --git a/duchain/navigation/navigationwidget.cpp b/duchain/navigation/navigationwidget.cpp index 2984b940..e822ef5b 100644 --- a/duchain/navigation/navigationwidget.cpp +++ b/duchain/navigation/navigationwidget.cpp @@ -1,50 +1,49 @@ /*************************************************************************** * This file is part of KDevelop * * Copyright 2012-2014 Sven Brauch * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "navigationwidget.h" #include "declarationnavigationcontext.h" #include "helpers.h" using namespace KDevelop; namespace Python { NavigationWidget::NavigationWidget(KDevelop::DeclarationPointer declaration, KDevelop::TopDUContextPointer topContext, const QString& /* htmlPrefix */, const QString& /* htmlSuffix */, KDevelop::AbstractNavigationWidget::DisplayHints hints) : KDevelop::AbstractNavigationWidget() { - m_topContext = topContext; setDisplayHints(hints); initBrowser(400); auto realDeclaration = DeclarationPointer(Helper::resolveAliasDeclaration(declaration.data())); - m_startContext = new DeclarationNavigationContext(realDeclaration, m_topContext); - setContext(m_startContext); + auto context = new DeclarationNavigationContext(realDeclaration, topContext); + setContext(NavigationContextPointer(context)); } NavigationWidget::NavigationWidget(const IncludeItem &/*includeItem*/, TopDUContextPointer /*topContext*/, const QString &/*htmlPrefix*/, const QString &/*htmlSuffix*/, KDevelop::AbstractNavigationWidget::DisplayHints hints) : KDevelop::AbstractNavigationWidget() { setDisplayHints(hints); // not supported } }