From 9dfdfdf5744d3bf0ffea3c380ed37f0ab9273fe5 Mon Sep 17 00:00:00 2001 From: Martin Smith <martin.smith@qt.io> Date: Thu, 22 Feb 2018 10:26:36 +0100 Subject: [PATCH] qdoc: Generate correct links to QML properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a QML type is marked \qmlabstract, the documentation for its properties is included on the reference page for each QML type that inherits the abstract QML type. This means that when using the link command to link to one of these properties in HTML, qdoc must first obtain the correct file name. It was not getting the correct file name, when the link command appeared in documentation for a QML type that didn't inherit the QML type marked abstract. This update corrects that bug. Change-Id: I91ccb34e43618b7bbc1909026cbdf0c1b719df87 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> --- src/qdoc/htmlgenerator.cpp | 11 +++++++++-- src/qdoc/node.cpp | 14 ++++++++++++++ src/qdoc/node.h | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/qdoc/htmlgenerator.cpp b/src/qdoc/htmlgenerator.cpp index 137da05ff..60ed94981 100644 --- a/src/qdoc/htmlgenerator.cpp +++ b/src/qdoc/htmlgenerator.cpp @@ -3943,8 +3943,15 @@ QString HtmlGenerator::linkForNode(const Node *node, const Node *relative) if (node && node->parent() && (node->parent()->isQmlType() || node->parent()->isJsType()) && node->parent()->isAbstract()) { - if (Generator::qmlTypeContext()) - fn = fileName(Generator::qmlTypeContext()); + if (Generator::qmlTypeContext()) { + if (Generator::qmlTypeContext()->inherits(node->parent())) { + fn = fileName(Generator::qmlTypeContext()); + } + else if (node->parent()->isInternal()) { + node->doc().location().warning(tr("Cannot link to property in internal type '%1'").arg(node->parent()->name())); + return QString(); + } + } } QString link = fn; diff --git a/src/qdoc/node.cpp b/src/qdoc/node.cpp index e2ed08032..7e3b2d96a 100644 --- a/src/qdoc/node.cpp +++ b/src/qdoc/node.cpp @@ -2668,6 +2668,20 @@ QString QmlTypeNode::logicalModuleIdentifier() const return (logicalModule_ ? logicalModule_->logicalModuleIdentifier() : QString()); } +/*! + Returns true if this QML type inherits \a type. + */ +bool QmlTypeNode::inherits(Aggregate* type) +{ + QmlTypeNode* qtn = qmlBaseNode(); + while (qtn != 0) { + if (qtn == type) + return true; + qtn = qtn->qmlBaseNode(); + } + return false; +} + /*! Constructs a Qml basic type node. The new node has the given \a parent and \a name. diff --git a/src/qdoc/node.h b/src/qdoc/node.h index faea2dcb1..38fc99f03 100644 --- a/src/qdoc/node.h +++ b/src/qdoc/node.h @@ -677,6 +677,7 @@ public: static void addInheritedBy(const Node *base, Node* sub); static void subclasses(const Node *base, NodeList& subs); static void terminate(); + bool inherits(Aggregate* type); public: static bool qmlOnly; -- GitLab