From 1936e4973f6309ece1b83a886c6c6d9211e2155e Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Thu, 30 Oct 2014 15:22:17 +0100 Subject: [PATCH] qdoc: Generate \keyword anchors at the top of the page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, qdoc processes \keyword and \target the same way. The negative effect of this is that when either command appears at the top of a qdoc comment, the anchor it generates in the html file is just above the details section on the html page. This is usually wrong, especially for \keyword commands, where the anchor generated should always be at the top of the page/text where the \keyword appears. This update implements that. \target anchors are meant to be used when the anchor should appear somewhere in the middle of the page/text, exactly where the \target command appears. Change-Id: Ibbbf1087562a977ff74ccd98febfe9310ecba8f0 Task-number: QTBUG-42290 Reviewed-by: Topi Reiniƶ --- src/tools/qdoc/atom.cpp | 4 ++++ src/tools/qdoc/atom.h | 1 + src/tools/qdoc/doc.cpp | 9 ++++++--- src/tools/qdoc/htmlgenerator.cpp | 24 ++++++++++++++++++++++++ src/tools/qdoc/htmlgenerator.h | 1 + src/tools/qdoc/tree.cpp | 2 +- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/tools/qdoc/atom.cpp b/src/tools/qdoc/atom.cpp index e227526d90..9aaa1af319 100644 --- a/src/tools/qdoc/atom.cpp +++ b/src/tools/qdoc/atom.cpp @@ -97,6 +97,9 @@ QT_BEGIN_NAMESPACE \value ImageText \value ImportantNote \value InlineImage + \value JavaScript + \value EndJavaScript + \value Keyword \value LineBreak \value Link \value LinkNode @@ -183,6 +186,7 @@ static const struct { { "InlineImage", Atom::InlineImage }, { "JavaScript", Atom::JavaScript }, { "EndJavaScript", Atom::EndJavaScript }, + { "Keyword", Atom::Keyword }, { "LegaleseLeft", Atom::LegaleseLeft }, { "LegaleseRight", Atom::LegaleseRight }, { "LineBreak", Atom::LineBreak }, diff --git a/src/tools/qdoc/atom.h b/src/tools/qdoc/atom.h index daa94a1fb8..2eb34a042b 100644 --- a/src/tools/qdoc/atom.h +++ b/src/tools/qdoc/atom.h @@ -84,6 +84,7 @@ public: InlineImage, JavaScript, EndJavaScript, + Keyword, LegaleseLeft, LegaleseRight, LineBreak, diff --git a/src/tools/qdoc/doc.cpp b/src/tools/qdoc/doc.cpp index 53d8ea885d..ce77caec9c 100644 --- a/src/tools/qdoc/doc.cpp +++ b/src/tools/qdoc/doc.cpp @@ -1690,12 +1690,15 @@ void DocParser::insertTarget(const QString &target, bool keyword) } else { targetMap_.insert(target, location()); - append(Atom::Target, target); priv->constructExtra(); - if (keyword) + if (keyword) { + append(Atom::Keyword, target); priv->extra->keywords_.append(priv->text.lastAtom()); - else + } + else { + append(Atom::Target, target); priv->extra->targets_.append(priv->text.lastAtom()); + } } } diff --git a/src/tools/qdoc/htmlgenerator.cpp b/src/tools/qdoc/htmlgenerator.cpp index f08f84abae..a3e8dac1e8 100644 --- a/src/tools/qdoc/htmlgenerator.cpp +++ b/src/tools/qdoc/htmlgenerator.cpp @@ -270,6 +270,20 @@ QString HtmlGenerator::format() return "HTML"; } +/*! + Generate targets for any \keyword commands that were seen + in the qdoc comment for the \a node. + */ +void HtmlGenerator::generateKeywordAnchors(const Node* node) +{ + if (!node->doc().isEmpty()) { + const QList& keywords = node->doc().keywords(); + foreach (Atom* a, keywords) { + out() << "string()) << "\">"; + } + } +} + /*! Traverses the current tree generating all the HTML documentation. */ @@ -1229,6 +1243,8 @@ int HtmlGenerator::generateAtom(const Atom *atom, const Node *relative, CodeMark break; case Atom::TableOfContents: break; + case Atom::Keyword: + break; case Atom::Target: out() << "string()) << "\">"; break; @@ -1276,8 +1292,10 @@ void HtmlGenerator::generateClassLikeNode(InnerNode* inner, CodeMarker* marker) subtitleText << "(" << Atom(Atom::AutoLink, fullTitle) << ")" << Atom(Atom::LineBreak); generateHeader(title, inner, marker); + sections = marker->sections(inner, CodeMarker::Summary, CodeMarker::Okay); generateTableOfContents(inner,marker,§ions); + generateKeywordAnchors(inner); generateTitle(title, subtitleText, SmallSubTitle, inner, marker); generateBrief(inner, marker); generateRequisites(inner, marker); @@ -1450,6 +1468,7 @@ void HtmlGenerator::generateQmlTypePage(QmlClassNode* qcn, CodeMarker* marker) QList
sections = marker->qmlSections(qcn, CodeMarker::Summary); generateTableOfContents(qcn, marker, §ions); marker = CodeMarker::markerForLanguage(QLatin1String("QML")); + generateKeywordAnchors(qcn); generateTitle(htmlTitle, Text() << qcn->subTitle(), subTitleSize, qcn, marker); generateBrief(qcn, marker); generateQmlRequisites(qcn, marker); @@ -1521,6 +1540,7 @@ void HtmlGenerator::generateQmlBasicTypePage(QmlBasicTypeNode* qbtn, CodeMarker* generateHeader(htmlTitle, qbtn, marker); QList
sections = marker->sections(qbtn, CodeMarker::Summary, CodeMarker::Okay); generateTableOfContents(qbtn,marker,§ions); + generateKeywordAnchors(qbtn); generateTitle(htmlTitle, Text() << qbtn->subTitle(), subTitleSize, @@ -1567,6 +1587,7 @@ void HtmlGenerator::generateDocNode(DocNode* dn, CodeMarker* marker) (dn->name() != QString("qtexamplesandtutorials.html"))) generateTableOfContents(dn,marker,0); + generateKeywordAnchors(dn); generateTitle(fullTitle, Text() << dn->subTitle(), subTitleSize, @@ -1651,6 +1672,7 @@ void HtmlGenerator::generateCollectionNode(CollectionNode* cn, CodeMarker* marke generateHeader(fullTitle, cn, marker); generateTableOfContents(cn,marker,0); + generateKeywordAnchors(cn); generateTitle(fullTitle, Text() << cn->subTitle(), subTitleSize, cn, marker); if (cn->isModule()) { @@ -3901,6 +3923,7 @@ void HtmlGenerator::generateDetailedMember(const Node *node, generateMacRef(node, marker); #endif generateExtractionMark(node, MemberMark); + generateKeywordAnchors(node); QString nodeRef = refForNode(node); if (node->type() == Node::Enum && (enume = static_cast(node))->flagsType()) { @@ -4137,6 +4160,7 @@ void HtmlGenerator::generateDetailedQmlMember(Node *node, generateMacRef(node, marker); #endif generateExtractionMark(node, MemberMark); + generateKeywordAnchors(node); out() << "
"; QString nodeRef = refForNode(node); if (node->type() == Node::QmlPropertyGroup) { diff --git a/src/tools/qdoc/htmlgenerator.h b/src/tools/qdoc/htmlgenerator.h index b8ead2bbec..22e6aa68dd 100644 --- a/src/tools/qdoc/htmlgenerator.h +++ b/src/tools/qdoc/htmlgenerator.h @@ -105,6 +105,7 @@ protected: void generateManifestFile(QString manifest, QString element); void readManifestMetaContent(const Config &config); + void generateKeywordAnchors(const Node* node); private: enum SubTitleSize { SmallSubTitle, LargeSubTitle }; diff --git a/src/tools/qdoc/tree.cpp b/src/tools/qdoc/tree.cpp index 6610bd0db4..819951d0e0 100644 --- a/src/tools/qdoc/tree.cpp +++ b/src/tools/qdoc/tree.cpp @@ -1135,7 +1135,7 @@ QString Tree::refForAtom(const Atom* atom) if (atom) { if (atom->type() == Atom::SectionLeft) return Doc::canonicalTitle(Text::sectionHeading(atom).toString()); - if (atom->type() == Atom::Target) + if ((atom->type() == Atom::Target) || (atom->type() == Atom::Keyword)) return Doc::canonicalTitle(atom->string()); } return QString();