qdoc: Resolve .qhp table of contents sections correctly

With the recent changes in QDoc, we can no longer assume that
pages listed in the TOC are of type DocNode. For example, all
Qt modules want to list C++/QML type index pages in the TOC,
and those are now of type CollectionNode.

This change fixes the issue by using a more generic search
function when generating the .qhp TOC, one that doesn't
restrict the results to any specific node type. As an
exception, the main index page for a project must still be a
DocNode, i.e. a page declared using the \page command.

However, we do want to restrict the search to the pages in
this documentation module only - for that purpose, a function
for setting a local search order is introduced.

Task-number: QTBUG-40241
Change-Id: Ibaa5af9c5de6436f34b7ae67e56733817fc090b9
Reviewed-by: Martin Smith <martin.smith@digia.com>
This commit is contained in:
Topi Reinio 2014-09-08 12:24:52 +02:00 committed by Topi Reiniö
parent 892af51834
commit 162010441f
2 changed files with 16 additions and 5 deletions

View File

@ -646,6 +646,11 @@ void HelpProjectWriter::writeNode(HelpProject &project, QXmlStreamWriter &writer
void HelpProjectWriter::generateProject(HelpProject &project)
{
const Node *rootNode;
// Restrict searching only to the local (primary) tree
QVector<Tree*> searchOrder = qdb_->searchOrder();
qdb_->setLocalSearch();
if (!project.indexRoot.isEmpty())
rootNode = qdb_->findDocNodeByTitle(project.indexRoot);
else
@ -708,7 +713,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
if (subproject.type == QLatin1String("manual")) {
const DocNode *indexPage = qdb_->findDocNodeByTitle(subproject.indexTitle);
const Node *indexPage = qdb_->findNodeForTarget(subproject.indexTitle, 0);
if (indexPage) {
Text indexBody = indexPage->doc().body();
const Atom *atom = indexBody.firstAtom();
@ -735,7 +740,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
if (sectionStack.top() > 0)
writer.writeEndElement(); // section
const DocNode *page = qdb_->findDocNodeByTitle(atom->string());
const Node *page = qdb_->findNodeForTarget(atom->string(), 0);
writer.writeStartElement("section");
QString indexPath = gen_->fullDocumentLocation(page,
Generator::useOutputSubdirs());
@ -762,7 +767,8 @@ void HelpProjectWriter::generateProject(HelpProject &project)
if (!name.isEmpty()) {
writer.writeStartElement("section");
QString indexPath = gen_->fullDocumentLocation(qdb_->findDocNodeByTitle(subproject.indexTitle),Generator::useOutputSubdirs());
QString indexPath = gen_->fullDocumentLocation(qdb_->findNodeForTarget(subproject.indexTitle, 0),
Generator::useOutputSubdirs());
writer.writeAttribute("ref", indexPath);
writer.writeAttribute("title", subproject.title);
}
@ -781,7 +787,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
if (!nextTitle.isEmpty() &&
node->links().value(Node::ContentsLink).first.isEmpty()) {
DocNode *nextPage = const_cast<DocNode *>(qdb_->findDocNodeByTitle(nextTitle));
const Node *nextPage = qdb_->findNodeForTarget(nextTitle, 0);
// Write the contents node.
writeNode(project, writer, node);
@ -791,7 +797,7 @@ void HelpProjectWriter::generateProject(HelpProject &project)
nextTitle = nextPage->links().value(Node::NextLink).first;
if (nextTitle.isEmpty() || visited.contains(nextTitle))
break;
nextPage = const_cast<DocNode *>(qdb_->findDocNodeByTitle(nextTitle));
nextPage = qdb_->findNodeForTarget(nextTitle, 0);
visited.insert(nextTitle);
}
break;
@ -804,6 +810,9 @@ void HelpProjectWriter::generateProject(HelpProject &project)
}
}
// Restore original search order
qdb_->setSearchOrder(searchOrder);
writer.writeEndElement(); // section
writer.writeEndElement(); // toc

View File

@ -370,6 +370,8 @@ class QDocDatabase
void newPrimaryTree(const QString& module) { forest_.newPrimaryTree(module); }
NamespaceNode* newIndexTree(const QString& module) { return forest_.newIndexTree(module); }
const QVector<Tree*>& searchOrder() { return forest_.searchOrder(); }
void setLocalSearch() { forest_.searchOrder_ = QVector<Tree*>(1, primaryTree()); }
void setSearchOrder(const QVector<Tree*>& searchOrder) { forest_.searchOrder_ = searchOrder; }
void setSearchOrder() { forest_.setSearchOrder(); }
void mergeCollections(Node::Type nt, CNMap& cnm, const Node* relative);
void mergeCollections(CollectionNode* cn);