From: Martin Smith Date: Thu, 15 Mar 2012 12:55:37 +0000 (+0100) Subject: qdoc: Structure the DITA map with a root node. X-Git-Tag: qt-v5.0.0-alpha1~252 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c0291177a1bd52b724d3a0639766ba1676a53ae4;p=profile%2Fivi%2Fqtbase.git qdoc: Structure the DITA map with a root node. The root topicref is now always index.dita, unless there is no index.dita. But there is always a root topicref that has the project name as its navtitle, even if there is no index.dita file to map it to. Task-number: Mzilla bug - 7229 Change-Id: I0c9fdf1a2e3ba847fe8975a0745667189a77a755 Reviewed-by: Casper van Donderen --- diff --git a/src/tools/qdoc/ditaxmlgenerator.cpp b/src/tools/qdoc/ditaxmlgenerator.cpp index b716863..6b0c2dc 100644 --- a/src/tools/qdoc/ditaxmlgenerator.cpp +++ b/src/tools/qdoc/ditaxmlgenerator.cpp @@ -5722,6 +5722,9 @@ bool DitaXmlGenerator::isDuplicate(NodeMultiMap* nmm, const QString& key, Node* /*! Collect all the nodes in the tree according to their type or subtype. + If a node is found that is named index.html, return that node as the + root page node. + type: Class type: Namespace @@ -5735,159 +5738,117 @@ bool DitaXmlGenerator::isDuplicate(NodeMultiMap* nmm, const QString& key, Node* subtype: QML class subtype: QML module */ -void DitaXmlGenerator::collectNodesByTypeAndSubtype(const InnerNode* parent) +Node* DitaXmlGenerator::collectNodesByTypeAndSubtype(const InnerNode* parent) { - //qDebug() << "START"; + Node* rootPageNode = 0; const NodeList& children = parent->childNodes(); if (children.size() == 0) - return; + return rootPageNode; - bool related; QString message; for (int i=0; iisInternal() || child->doc().isEmpty()) + if ((child->type() == Node::Fake) && (child->subType() == Node::Collision)) { + const FakeNode* fake = static_cast(child); + Node* n = collectNodesByTypeAndSubtype(fake); + if (n) + rootPageNode = n; continue; - if (child->relates()) { - related = true; - message = child->relates()->name(); } - else { - related = false; - message = "has documentation but no \\relates command"; + if (!child || child->isInternal() || child->doc().isEmpty()) + continue; + + if (child->name() == "index.html") { + rootPageNode = child; } + switch (child->type()) { case Node::Namespace: - //qDebug() << "NODE: Namespace" << "TITLE:" << child->name() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeTypeMaps[Node::Namespace],child->name(),child)) nodeTypeMaps[Node::Namespace]->insert(child->name(),child); break; case Node::Class: - //qDebug() << "NODE: Class" << "TITLE:" << child->name() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeTypeMaps[Node::Class],child->name(),child)) nodeTypeMaps[Node::Class]->insert(child->name(),child); break; case Node::Fake: - //qDebug() << "NODE: Fake"; switch (child->subType()) { case Node::Example: - //qDebug() << "FAKE NODE: Example" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::Example],child->title(),child)) nodeSubtypeMaps[Node::Example]->insert(child->title(),child); break; case Node::HeaderFile: - //qDebug() << "FAKE NODE: Header file" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::HeaderFile],child->title(),child)) nodeSubtypeMaps[Node::HeaderFile]->insert(child->title(),child); break; case Node::File: - //qDebug() << "FAKE NODE: File"; break; case Node::Image: - //qDebug() << "FAKE NODE: Image"; break; case Node::Group: - //qDebug() << "FAKE NODE: Group" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::Group],child->title(),child)) nodeSubtypeMaps[Node::Group]->insert(child->title(),child); break; case Node::Module: - //qDebug() << "FAKE NODE: Module" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::Module],child->title(),child)) nodeSubtypeMaps[Node::Module]->insert(child->title(),child); break; case Node::Page: - //qDebug() << "FAKE NODE: Page" << "PAGE TYPE:" << child->pageTypeString() - // << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(pageTypeMaps[child->pageType()],child->title(),child)) pageTypeMaps[child->pageType()]->insert(child->title(),child); break; case Node::ExternalPage: - //qDebug() << "FAKE NODE: External page" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::ExternalPage],child->title(),child)) nodeSubtypeMaps[Node::ExternalPage]->insert(child->title(),child); break; case Node::QmlClass: - //qDebug() << "FAKE NODE: QML class" << "TITLE:" << child->title() << "FILE:" - // << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::QmlClass],child->title(),child)) nodeSubtypeMaps[Node::QmlClass]->insert(child->title(),child); break; case Node::QmlPropertyGroup: - //qDebug() << "FAKE NODE: QML property group"; break; case Node::QmlBasicType: - //qDebug() << "FAKE NODE: QML basic type" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::QmlBasicType],child->title(),child)) nodeSubtypeMaps[Node::QmlBasicType]->insert(child->title(),child); break; case Node::QmlModule: - //qDebug() << "FAKE NODE: QML module" << "TITLE:" << child->title() - // << "FILE:" << fileName(child); if (!isDuplicate(nodeSubtypeMaps[Node::QmlModule],child->title(),child)) nodeSubtypeMaps[Node::QmlModule]->insert(child->title(),child); break; case Node::Collision: - //qDebug() << "FAKE NODE: Collision"; + qDebug() << "FAKE NODE: Collision"; + if (!isDuplicate(nodeSubtypeMaps[Node::Collision],child->title(),child)) + nodeSubtypeMaps[Node::Collision]->insert(child->title(),child); break; default: break; } break; case Node::Enum: - if (!related) - child->location().warning(tr("Global enum, %1, %2").arg(child->name()).arg(message)); break; case Node::Typedef: - if (!related) - child->location().warning(tr("Global typedef, %1, %2").arg(child->name()).arg(message)); break; case Node::Function: - if (!related) { - const FunctionNode* fn = static_cast(child); - if (fn->isMacro()) - child->location().warning(tr("Global macro, %1, %2").arg(child->name()).arg(message)); - else - child->location().warning(tr("Global function, %1(), %2").arg(child->name()).arg(message)); - } break; case Node::Property: break; case Node::Variable: - if (!related) - child->location().warning(tr("Global variable, %1, %2").arg(child->name()).arg(message)); break; case Node::Target: break; case Node::QmlProperty: - if (!related) - child->location().warning(tr("Global QML property, %1, %2").arg(child->name()).arg(message)); break; case Node::QmlSignal: - if (!related) - child->location().warning(tr("Global QML, signal, %1 %2").arg(child->name()).arg(message)); break; case Node::QmlSignalHandler: - if (!related) - child->location().warning(tr("Global QML signal handler, %1, %2").arg(child->name()).arg(message)); break; case Node::QmlMethod: - if (!related) - child->location().warning(tr("Global QML method, %1, %2").arg(child->name()).arg(message)); break; default: break; } } + return rootPageNode; } /*! @@ -5896,16 +5857,13 @@ void DitaXmlGenerator::collectNodesByTypeAndSubtype(const InnerNode* parent) */ void DitaXmlGenerator::writeDitaMap(const Tree *tree) { - beginSubPage(tree->root(),"qt.ditamap"); - QString doctype; - doctype = ""; - // doctype = ""; +#if 0 + beginSubPage(tree->root(),"qt.ditamap"); + doctype = ""; xmlWriter().writeDTD(doctype); writeStartTag(DT_map); - //xmlWriter().writeAttribute("id","Qt-DITA-Map"); - //xmlWriter().writeAttribute("title","Qt DITA Map"); writeStartTag(DT_topicmeta); writeStartTag(DT_shortdesc); xmlWriter().writeCharacters("The top level map for the Qt documentation"); @@ -5920,6 +5878,7 @@ void DitaXmlGenerator::writeDitaMap(const Tree *tree) ++i; } endSubPage(); +#endif for (unsigned i=0; iroot()); -#if 0 - for (unsigned i=0; isize() > 0) - qDebug() << "NODE TYPE:" << Node::nodeTypeString(i) << nodeTypeMaps[i]->size(); - } - for (unsigned i=1; isize() > 0) - qDebug() << "NODE SUBTYPE:" << Node::nodeSubtypeString(i) << nodeSubtypeMaps[i]->size(); - } - for (unsigned i=1; isize() > 0) - qDebug() << "PAGE TYPE:" << Node::pageTypeString(i) << pageTypeMaps[i]->size(); - } -#endif - beginSubPage(tree->root(),"test.ditamap"); + Node* rootPageNode = collectNodesByTypeAndSubtype(tree->root()); + + beginSubPage(tree->root(),"qt.ditamap"); doctype = ""; xmlWriter().writeDTD(doctype); @@ -5953,6 +5899,11 @@ void DitaXmlGenerator::writeDitaMap(const Tree *tree) writeEndTag(); // writeEndTag(); // + writeStartTag(DT_topicref); + xmlWriter().writeAttribute("navtitle",project); + if (rootPageNode) + xmlWriter().writeAttribute("href",fileName(rootPageNode)); + writeTopicrefs(pageTypeMaps[Node::OverviewPage], "overviews"); writeTopicrefs(pageTypeMaps[Node::HowToPage], "howtos"); writeTopicrefs(pageTypeMaps[Node::TutorialPage], "tutorials"); @@ -5968,6 +5919,7 @@ void DitaXmlGenerator::writeDitaMap(const Tree *tree) writeTopicrefs(nodeSubtypeMaps[Node::QmlModule], "QML modules"); writeTopicrefs(nodeSubtypeMaps[Node::QmlBasicType], "QML basic types"); + writeEndTag(); // endSubPage(); for (unsigned i=0; i"; - // doctype = ""; - xmlWriter().writeDTD(doctype); writeStartTag(DT_map); writeStartTag(DT_topicmeta); diff --git a/src/tools/qdoc/ditaxmlgenerator.h b/src/tools/qdoc/ditaxmlgenerator.h index bc3ed93..b3da02b 100644 --- a/src/tools/qdoc/ditaxmlgenerator.h +++ b/src/tools/qdoc/ditaxmlgenerator.h @@ -455,7 +455,7 @@ private: int currentSectionNestingLevel() const { return sectionNestingLevel; } QString metadataDefault(DitaTag t) const; QString stripMarkup(const QString& src) const; - void collectNodesByTypeAndSubtype(const InnerNode* parent); + Node* collectNodesByTypeAndSubtype(const InnerNode* parent); void writeDitaRefs(const DitaRefList& ditarefs); void writeTopicrefs(NodeMultiMap* nmm, const QString& navtitle); bool isDuplicate(NodeMultiMap* nmm, const QString& key, Node* node); diff --git a/src/tools/qdoc/node.h b/src/tools/qdoc/node.h index 23ee38c..8c6eb67 100644 --- a/src/tools/qdoc/node.h +++ b/src/tools/qdoc/node.h @@ -174,6 +174,7 @@ public: void setPageType(const QString& t); void setParent(InnerNode* n) { parent_ = n; } void setIndexNodeFlag() { indexNodeFlag_ = true; } + virtual void setOutputFileName(const QString& ) { } virtual bool isInnerNode() const = 0; virtual bool isReimp() const { return false; } @@ -194,6 +195,7 @@ public: QString moduleName() const; QString url() const; virtual QString nameForLists() const { return name_; } + virtual QString outputFileName() const { return QString(); } Access access() const { return access_; } QString accessString() const; @@ -324,6 +326,8 @@ public: virtual void addPageKeywords(const QString& t) { pageKeywds << t; } virtual void setCurrentChild() { } virtual void setCurrentChild(InnerNode* ) { } + virtual void setOutputFileName(const QString& f) { outputFileName_ = f; } + virtual QString outputFileName() const { return outputFileName_; } protected: InnerNode(Type type, InnerNode* parent, const QString& name); @@ -337,6 +341,7 @@ private: void removeRelated(Node* pseudoChild); void removeChild(Node* child); + QString outputFileName_; QStringList pageKeywds; QStringList inc; NodeList children; diff --git a/src/tools/qdoc/pagegenerator.cpp b/src/tools/qdoc/pagegenerator.cpp index d8c3bab..6a52b77 100644 --- a/src/tools/qdoc/pagegenerator.cpp +++ b/src/tools/qdoc/pagegenerator.cpp @@ -298,6 +298,7 @@ void PageGenerator::beginSubPage(const InnerNode* node, const QString& fileName) if (outputCodec) out->setCodec(outputCodec); outStreamStack.push(out); + const_cast(node)->setOutputFileName(fileName); } /*!