26#include <QtCore/qhash.h>
30using namespace Qt::StringLiterals;
34 reset(defaultFileName, g);
42
43
44
45
50 Config &config = Config::instance();
51 m_outputDir = config.getOutputDir();
53 const QStringList names{config.get(
CONFIG_QHP + Config::dot +
"projects").asStringList()};
55 for (
const auto &projectName : names) {
57 project.m_name = projectName;
59 QString prefix =
CONFIG_QHP + Config::dot + projectName + Config::dot;
60 project.m_helpNamespace = config.get(prefix +
"namespace").asString();
61 project.m_virtualFolder = config.get(prefix +
"virtualFolder").asString();
63 project.m_fileName = config.get(prefix +
"file").asString();
64 if (project.m_fileName.isEmpty())
65 project.m_fileName = defaultFileName;
66 project.m_extraFiles = config.get(prefix +
"extraFiles").asStringSet();
67 project.m_extraFiles += config.get(
CONFIG_QHP + Config::dot +
"extraFiles").asStringSet();
68 project.m_indexTitle = config.get(prefix +
"indexTitle").asString();
69 project.m_indexRoot = config.get(prefix +
"indexRoot").asString();
70 project.m_filterAttributes = config.get(prefix +
"filterAttributes").asStringSet();
71 project.m_includeIndexNodes = config.get(prefix +
"includeIndexNodes").asBool();
72 const QSet<QString> customFilterNames = config.subVars(prefix +
"customFilters");
73 for (
const auto &filterName : customFilterNames) {
74 QString name{config.get(prefix +
"customFilters" + Config::dot + filterName
75 + Config::dot +
"name").asString()};
76 project.m_customFilters[name] =
77 config.get(prefix +
"customFilters" + Config::dot + filterName
78 + Config::dot +
"filterAttributes").asStringSet();
81 const auto excludedPrefixes = config.get(prefix +
"excluded").asStringSet();
82 for (
auto name : excludedPrefixes)
83 project.m_excluded.insert(name.replace(QLatin1Char(
'\\'), QLatin1Char(
'/')));
85 const auto subprojectPrefixes{config.get(prefix +
"subprojects").asStringList()};
86 for (
const auto &name : subprojectPrefixes) {
87 SubProject subproject;
88 QString subprefix = prefix +
"subprojects" + Config::dot + name + Config::dot;
89 subproject.m_title = config.get(subprefix +
"title").asString();
90 if (subproject.m_title.isEmpty())
92 subproject.m_indexTitle = config.get(subprefix +
"indexTitle").asString();
93 subproject.m_sortPages = config.get(subprefix +
"sortPages").asBool();
94 subproject.m_type = config.get(subprefix +
"type").asString();
95 readSelectors(subproject, config.get(subprefix +
"selectors").asStringList());
97 subproject.m_prefix = std::move(subprefix);
98 project.m_subprojects.append(subproject);
101 if (project.m_subprojects.isEmpty()) {
102 SubProject subproject;
103 readSelectors(subproject, config.get(prefix +
"selectors").asStringList());
104 project.m_subprojects.insert(0, subproject);
107 m_projects.append(project);
113 QHash<QString, NodeType> typeHash;
141 for (
const QString &selector : selectors) {
142 QStringList pieces = selector.split(QLatin1Char(
':'));
144 if (pieces.size() > 1 && typeHash.value(pieces[0].toLower()) == NodeType::Page)
147 QString typeName = pieces.takeFirst().toLower();
148 if (!typeHash.contains(typeName))
151 subproject.m_selectors <<
static_cast<
unsigned char>(typeHash.value(typeName));
153 if (typeHash.value(typeName) == NodeType::Class) {
154 subproject.m_selectors <<
static_cast<
unsigned char>(NodeType::Struct)
155 <<
static_cast<
unsigned char>(NodeType::Union);
158 if (typeHash.value(typeName) == NodeType::QmlType)
159 subproject.m_selectors <<
static_cast<
unsigned char>(NodeType::QmlValueType);
160 if (!pieces.isEmpty()) {
161 pieces = pieces[0].split(QLatin1Char(
','));
162 for (
const auto &piece : std::as_const(pieces)) {
163 if (typeHash[typeName] == NodeType::Group
164 || typeHash[typeName] == NodeType::Module
165 || typeHash[typeName] == NodeType::QmlModule) {
166 subproject.m_groups << piece.toLower();
175 for (HelpProject &project : m_projects)
176 project.m_extraFiles.insert(file);
181 QString ref = m_gen->fullDocumentLocation(node);
190 return Keyword(name, id, ref);
192 const QString &name = node->name();
193 QString moduleName = node->logicalModuleName();
194 QStringList ids(
"QML." + name);
195 if (!moduleName.isEmpty()) {
199 ids <<
"QML." + moduleName + majorVersion +
"." + name;
201 return Keyword(name, ids, ref);
203 const QLatin1Char delim(
'.');
204 QStringList parts = node->logicalModuleName().split(delim) <<
"QML";
205 std::reverse(parts.begin(), parts.end());
206 return Keyword(node->logicalModuleName(), parts.join(delim), ref);
208 const auto *pageNode =
static_cast<
const PageNode *>(node);
209 return Keyword(pageNode->fullTitle(), pageNode->fullTitle(), ref);
211 return Keyword(node->name(), node->name(), ref);
218 if (!node->url().isEmpty() && !(project
.m_includeIndexNodes && !node->url().startsWith(
"http")))
225 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
230 if (node->name().isEmpty())
234 if (!docPath.isEmpty() && project.m_excluded.contains(docPath))
237 QString objName = node
->isTextPageNode() ? node->fullTitle() : node->fullDocumentName();
241 auto acceptNode = [&](
SubProject &subproject,
const QString &name,
const Node *n) {
242 subproject.m_nodes.insert(name, n);
243 project.markPagePresent(m_gen->fullDocumentLocation(n));
246 for (
auto &subproject : project.m_subprojects) {
248 if (subproject.m_selectors.isEmpty()) {
249 acceptNode(subproject, objName, node);
250 }
else if (subproject.m_selectors.contains(
static_cast<
unsigned char>(node->nodeType()))) {
252 if (node->isCollectionNode()) {
253 if (subproject.m_groups.contains(node->name().toLower())) {
254 const auto *cn =
static_cast<
const CollectionNode *>(node);
255 const auto members = cn->members();
256 for (
const Node *m : members) {
260 m->isTextPageNode() ? m->fullTitle() : m->fullDocumentName();
261 acceptNode(subproject, memberName, m);
264 }
else if (!subproject.m_groups.isEmpty()) {
267 }
else if (node->isTextPageNode()) {
268 if (node->isExternalPage() || node->fullTitle().isEmpty())
271 acceptNode(subproject, objName, node);
275 auto appendDocKeywords = [&](
const Node *n) {
278 for (
const auto *kw : n->doc().keywords()) {
279 if (!kw->string().isEmpty()) {
280 QStringList ref_parts = m_gen->fullDocumentLocation(n).split(
'#'_L1);
282 if (kw->count() > 1) {
283 if (ref_parts.count() > 1)
284 ref_parts.pop_back();
285 ref_parts << kw->string(1);
287 project.m_keywords.append(Keyword(kw->string(), kw->string(),
288 ref_parts.join(
'#'_L1)));
301 project.m_keywords.append(keywordDetails(node));
305 appendDocKeywords(node);
306 project.m_keywords.append(keywordDetails(node));
310 project.m_keywords.append(keywordDetails(node));
315 project.m_keywords.append(keywordDetails(node));
317 const auto *enumNode =
static_cast<
const EnumNode *>(node);
318 const auto items = enumNode->items();
319 for (
const auto &item : items) {
320 if (enumNode->itemAccess(item.name()) == Access::Private)
325 if (!node->parent()->name().isEmpty()) {
326 name = id = node->parent()->name() +
"::" + item.name();
328 name = id = item.name();
330 QString ref = m_gen->fullDocumentLocation(node);
331 project.m_keywords.append(Keyword(std::move(name), std::move(id), std::move(ref)));
339 if (!node->fullTitle().isEmpty()) {
340 appendDocKeywords(node);
341 project.m_keywords.append(keywordDetails(node));
347 project.m_keywords.append(keywordDetails(node));
351 const auto *funcNode =
static_cast<
const FunctionNode *>(node);
354
355
356
357
358 if (funcNode->isQmlNode()) {
359 project.m_keywords.append(keywordDetails(node));
365 if (!funcNode->isSomeCtor())
366 project.m_keywords.append(keywordDetails(node));
379 const auto *typedefNode =
static_cast<
const TypedefNode *>(node);
380 Keyword typedefDetails = keywordDetails(node);
381 const EnumNode *enumNode = typedefNode->associatedEnum();
385 typedefDetails.m_ref = m_gen->fullDocumentLocation(enumNode);
387 project.m_keywords.append(typedefDetails);
391 project.m_keywords.append(keywordDetails(node));
397 if (!node->fullTitle().isEmpty()) {
398 appendDocKeywords(node);
399 project.m_keywords.append(keywordDetails(node));
410 QStringList pieces = atom->string().split(
'/'_L1);
411 project.m_extraFiles.insert(
"%1/%2"_L1.arg(m_gen->imagesOutputDir(), pieces.last()));
423
424
427 if (!generateSection(project, writer, node))
431 const auto *aggregate =
static_cast<
const Aggregate *>(node);
435 NodeList children = aggregate->childNodes();
437 for (
auto *child : children) {
439 if (child->parent() != aggregate)
442 if (child->isGroup() && !child->wasSeen()) {
446 if (child->isIndexNode())
449 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
450 const NodeContext context = child->createContext();
451 if (!InclusionFilter::isIncluded(policy, context))
454 if (child->isTextPageNode()) {
455 if (!childSet.contains(child))
459 project.m_memberStatus[node].insert(child->status());
460 if (child->isFunction() &&
static_cast<
const FunctionNode *>(child)->isOverload())
462 if (!childSet.contains(child))
466 for (
const auto *child : std::as_const(childSet))
467 generateSections(project, writer, child);
474 if (
auto &config = Config::instance(); m_projects.isEmpty() && config.get(
CONFIG_QHP).asBool()) {
475 config.location().warning(u"Documentation configuration for '%1' doesn't define a help project (qhp)"_s
478 if (m_projects.isEmpty())
483 QSet<QString> pagesInHelp;
484 for (HelpProject &project : m_projects) {
485 generateProject(project);
486 pagesInHelp.unite(project.m_structurePages);
491 if (pagesInHelp.isEmpty())
495 auto isNonEssential = [](
const PageNode *page) {
496 const auto *metaTags = page
->doc().metaTagMap();
497 return metaTags && metaTags->values(u"toc"_s).contains(u"nonessential"_s);
500 for (
const auto *page : m_gen->generatedPages()) {
503 if (page->isProxyNode())
507 if (page->isNamespace() &&
static_cast<
const NamespaceNode *>(page)->docNode())
509 if (!pagesInHelp.contains(m_gen->fullDocumentLocation(page)) && !isNonEssential(page))
510 page->doc().location().warning(
511 u"Topic missing from generated Qt Help structure."_s,
512 u"%1 does not define a qhp subproject that includes it."_s.arg(
513 Config::instance().location().fileName()));
517void HelpProjectWriter::writeSection(QXmlStreamWriter &writer,
const QString &path,
518 const QString &value)
520 writer.writeStartElement(QStringLiteral(
"section"));
521 writer.writeAttribute(QStringLiteral(
"ref"), path);
522 writer.writeAttribute(QStringLiteral(
"title"), value);
523 writer.writeEndElement();
527
528
531 QString href = m_gen->fullDocumentLocation(node);
532 href = href.left(href.size() - 5);
536 bool derivedClass =
false;
538 derivedClass = !(
static_cast<
const ClassNode *>(node)->baseClasses().isEmpty());
543 && (derivedClass || node
->isQmlType() || !project.m_memberStatus[node].isEmpty())) {
544 QString membersPath = href + QStringLiteral(
"-members.html");
545 writeSection(writer, membersPath, QStringLiteral(
"List of all members"));
548 QString obsoletePath = href + QStringLiteral(
"-obsolete.html");
549 writeSection(writer, obsoletePath, QStringLiteral(
"Obsolete members"));
555 QString href = m_gen->fullDocumentLocation(node);
558 project.markPagePresent(href);
559 QString objName = node->name();
568 QString typeStr = NodeText::nodeTypeDescription(node);
569 if (!typeStr.isEmpty())
570 typeStr[0] = typeStr[0].toTitleCase();
571 writer.writeStartElement(
"section");
572 writer.writeAttribute(
"ref", href);
574 writer.writeAttribute(
"title",
575 QStringLiteral(
"%1::%2 %3 Reference")
576 .arg(node
->parent()->name(), objName, typeStr));
578 writer.writeAttribute(
"title", QStringLiteral(
"%1 %2 Reference").arg(objName, typeStr));
580 addMembers(project, writer, node);
581 writer.writeEndElement();
584 case NodeType::Namespace:
585 writeSection(writer, href,
"%1 Namespace Reference"_L1.arg(objName));
594 writer.writeStartElement(
"section");
595 writer.writeAttribute(
"ref", href);
596 writer.writeAttribute(
"title", node->fullTitle());
597 if (node->nodeType() == NodeType::HeaderFile)
598 addMembers(project, writer, node);
599 writer.writeEndElement();
607 const Node *rootNode;
610 QList<Tree *> searchOrder = m_qdb->searchOrder();
613 if (!project.m_indexRoot.isEmpty())
614 rootNode = m_qdb->findPageNodeByTitle(project.m_indexRoot);
618 if (rootNode ==
nullptr)
621 project.m_structurePages.clear();
622 project.m_keywords.clear();
625 OutputDirectory::ensure(m_outputDir,
Location());
627 QFile file(outputDir.absoluteFilePath(project.m_fileName));
628 if (!file.open(QFile::WriteOnly)) {
629 Location().error(u"Cannot open '%1' for writing"_s.arg(file.fileName()));
633 QXmlStreamWriter writer(&file);
634 writer.setAutoFormatting(
true);
635 writer.writeStartDocument();
636 writer.writeStartElement(
"QtHelpProject");
637 writer.writeAttribute(
"version",
"1.0");
640 writer.writeTextElement(
"namespace", project.m_helpNamespace);
641 writer.writeTextElement(
"virtualFolder", project.m_virtualFolder);
642 writer.writeStartElement(
"metaData");
643 writer.writeAttribute(
"name",
"version");
644 writer.writeAttribute(
"value", project.m_version);
645 writer.writeEndElement();
648 for (
auto it = project.m_customFilters.constBegin(); it != project.m_customFilters.constEnd();
650 writer.writeStartElement(
"customFilter");
651 writer.writeAttribute(
"name", it.key());
652 QStringList sortedAttributes = it.value().values();
653 sortedAttributes.sort();
654 for (
const auto &filter : std::as_const(sortedAttributes))
655 writer.writeTextElement(
"filterAttribute", filter);
656 writer.writeEndElement();
660 writer.writeStartElement(
"filterSection");
663 QStringList sortedFilterAttributes = project.m_filterAttributes.values();
664 sortedFilterAttributes.sort();
665 for (
const auto &filterName : std::as_const(sortedFilterAttributes))
666 writer.writeTextElement(
"filterAttribute", filterName);
668 writer.writeStartElement(
"toc");
669 writer.writeStartElement(
"section");
670 const Node *node = m_qdb->findPageNodeByTitle(project.m_indexTitle);
672 node = m_qdb->findNodeByNameAndType(QStringList(project.m_indexTitle), &
Node::isPageNode);
674 node = m_qdb->findNodeByNameAndType(QStringList(
"index.html"), &
Node::isPageNode);
677 indexPath = m_gen->fullDocumentLocation(node);
679 indexPath =
"index.html";
680 writer.writeAttribute(
"ref", indexPath);
681 writer.writeAttribute(
"title", project.m_indexTitle);
682 project.markPagePresent(indexPath);
684 generateSections(project, writer, rootNode);
686 for (
int i = 0; i < project.m_subprojects.size(); i++) {
687 SubProject subproject = project.m_subprojects[i];
689 if (subproject.m_type == QLatin1String(
"manual")) {
691 const Node *indexPage = m_qdb->findNodeForTarget(subproject.m_indexTitle,
nullptr);
695 QStack<
int> sectionStack;
701 sectionStack.push(0);
704 if (sectionStack.pop() > 0)
705 writer.writeEndElement();
716 const Node *page = m_qdb->findNodeForTarget(atom->string(),
nullptr);
720 if (sectionStack.top() > 0)
721 writer.writeEndElement();
723 writer.writeStartElement(
"section");
724 QString indexPath = m_gen->fullDocumentLocation(page);
725 writer.writeAttribute(
"ref", indexPath);
726 project.markPagePresent(indexPath);
727 writer.writeAttribute(
"title", atom->linkText());
729 sectionStack.top() += 1;
734 if (
const auto *cn = m_qdb->getCollectionNode(atom->string(), NodeType::Group)) {
735 const auto sortOrder{Generator::sortOrder(atom->strings().last())};
739 members.erase(
std::remove_if(members.begin(), members.end(),
743 if (members.isEmpty())
746 if (sortOrder == Qt::DescendingOrder)
751 for (
const auto *m : members) {
752 writer.writeStartElement(
"section");
753 const QString memberHref = m_gen->fullDocumentLocation(m);
754 writer.writeAttribute(
"ref", memberHref);
755 project.markPagePresent(memberHref);
756 writer.writeAttribute(
"title", m->title());
757 writer.writeEndElement();
769 Config::instance().location().warning(
770 "Failed to find %1.indexTitle '%2'"_L1.arg(subproject.m_prefix, subproject.m_indexTitle));
774 writer.writeStartElement(
"section");
775 const Node *indexNode = m_qdb->findNodeForTarget(subproject.m_indexTitle,
nullptr);
776 QString indexPath = m_gen->fullDocumentLocation(indexNode);
777 if (indexPath.isEmpty() && !subproject.m_indexTitle.isEmpty())
778 Config::instance().location().warning(
779 "Failed to find %1.indexTitle '%2'"_L1.arg(subproject.m_prefix, subproject.m_indexTitle));
780 writer.writeAttribute(
"ref", indexPath);
781 project.markPagePresent(indexPath);
782 writer.writeAttribute(
"title", subproject.m_title);
785 QStringList titles = subproject.m_nodes.keys();
787 for (
const auto &title : std::as_const(titles)) {
788 writeNode(project, writer, subproject.m_nodes[title]);
792 QSet<QString> visited;
793 bool contentsFound =
false;
794 for (
const auto *node : std::as_const(subproject.m_nodes)) {
795 QString nextTitle = node->links().value(Node::NextLink).first;
796 if (!nextTitle.isEmpty()
797 && node->links().value(Node::ContentsLink).first.isEmpty()) {
799 const Node *nextPage = m_qdb->findNodeForTarget(nextTitle,
nullptr);
802 writeNode(project, writer, node);
803 contentsFound =
true;
806 writeNode(project, writer, nextPage);
807 nextTitle = nextPage->links().value(Node::NextLink).first;
808 if (nextTitle.isEmpty() || visited.contains(nextTitle))
810 nextPage = m_qdb->findNodeForTarget(nextTitle,
nullptr);
811 visited.insert(nextTitle);
817 if (!contentsFound) {
818 QList<
const Node *> subnodes = subproject.m_nodes.values();
822 for (
const auto *node : std::as_const(subnodes))
823 writeNode(project, writer, node);
827 writer.writeEndElement();
832 m_qdb->setSearchOrder(searchOrder);
834 writer.writeEndElement();
835 writer.writeEndElement();
837 writer.writeStartElement(
"keywords");
838 std::sort(project.m_keywords.begin(), project.m_keywords.end());
839 for (
const auto &k : std::as_const(project.m_keywords)) {
840 for (
const auto &id : std::as_const(k.m_ids)) {
841 writer.writeStartElement(
"keyword");
842 writer.writeAttribute(
"name", k.m_name);
843 writer.writeAttribute(
"id", id);
844 writer.writeAttribute(
"ref", k.m_ref);
845 writer.writeEndElement();
848 writer.writeEndElement();
850 writer.writeStartElement(
"files");
854 QSet<QString> files =
855 QSet<QString>(m_gen->outputFileNames().cbegin(), m_gen->outputFileNames().cend());
856 files.unite(QSet<QString>(m_gen->exampleImageFileNames().cbegin(),
857 m_gen->exampleImageFileNames().cend()));
858 files.unite(project.m_extraFiles);
859 QStringList sortedFiles = files.values();
861 for (
const auto &usedFile : std::as_const(sortedFiles)) {
862 if (!usedFile.isEmpty())
863 writer.writeTextElement(
"file", usedFile);
865 writer.writeEndElement();
867 writer.writeEndElement();
868 writer.writeEndElement();
869 writer.writeEndDocument();
The Atom class is the fundamental unit for representing documents internally.
AtomType type() const
Return the type of this atom.
const Atom * next() const
Return the next atom in the atom list.
The Config class contains the configuration variables for controlling how qdoc produces documentation...
const Location & location() const
Returns the starting location of a qdoc comment.
const Text & body() const
HelpProjectWriter(const QString &defaultFileName, Generator *g)
void addExtraFile(const QString &file)
void reset(const QString &defaultFileName, Generator *g)
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
The Location class provides a way to mark a location in a file.
Location()
Constructs an empty location.
Represents an output directory that has been verified to exist.
A PageNode is a Node that generates a documentation page.
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
NamespaceNode * primaryTreeRoot()
Returns a pointer to the root node of the primary tree.
Status
Specifies the status of the QQmlIncubator.
const Atom * firstAtom() const
Combined button and popup list for selecting options.
The Node class is the base class for all the nodes in QDoc's parse tree.
bool isExternalPage() const
Returns true if the node type is ExternalPage.
bool isDontDocument() const
Returns true if this node's status is DontDocument.
const Doc & doc() const
Returns a reference to the node's Doc data member.
bool isGroup() const
Returns true if the node type is Group.
virtual bool isWrapper() const
Returns true if the node is a class node or a QML type node that is marked as being a wrapper class o...
bool isNamespace() const
Returns true if the node type is Namespace.
bool isTypedef() const
Returns true if the node type is Typedef.
bool isQmlBasicType() const
Returns true if the node type is QmlBasicType.
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
bool isHeader() const
Returns true if the node type is HeaderFile.
NodeType nodeType() const override
Returns this node's type.
virtual bool isPageNode() const
Returns true if this node represents something that generates a documentation page.
bool isEnumType() const
Returns true if the node type is Enum.
virtual Status status() const
Returns the node's status value.
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
virtual bool isAggregate() const
Returns true if this node is an aggregate, which means it inherits Aggregate and can therefore have c...
static bool nodeNameLessThan(const Node *first, const Node *second)
Returns true if the node n1 is less than node n2.
virtual bool wasSeen() const
Returns the seen flag data member of this node if it is a NamespaceNode or a CollectionNode.
NodeContext createContext() const
virtual CollectionNode * logicalModule() const
If this is a QmlTypeNode, a pointer to its QML module is returned, which is a pointer to a Collection...
bool isRelatedNonmember() const
Returns true if this is a related nonmember of something.
virtual bool isClassNode() const
Returns true if this is an instance of ClassNode.
static bool nodeSortKeyOrNameLessThan(const Node *n1, const Node *n2)
Returns true if node n1 is less than node n2 when comparing the sort keys, defined with.
bool isQmlModule() const
Returns true if the node type is QmlModule.
bool isIndexNode() const
Returns true if this node was created from something in an index file.