Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
docbookgenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 Thibaut Cuvelier
2// Copyright (C) 2021 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
4
6
7#include "access.h"
8#include "aggregate.h"
9#include "classnode.h"
10#include "codemarker.h"
11#include "collectionnode.h"
13#include "config.h"
14#include "enumnode.h"
15#include "examplenode.h"
16#include "functionnode.h"
17#include "generator.h"
18#include "genustypes.h"
20#include "node.h"
21#include "nodecontext.h"
23#include "propertynode.h"
24#include "quoter.h"
25#include "qdocdatabase.h"
29#include "typedefnode.h"
30#include "utilities.h"
31#include "textutils.h"
32#include "variablenode.h"
33
34#include <QtCore/qlist.h>
35#include <QtCore/qmap.h>
36#include <QtCore/quuid.h>
37#include <QtCore/qurl.h>
38#include <QtCore/qregularexpression.h>
39#include <QtCore/qversionnumber.h>
40
41#include <algorithm>
42#include <cctype>
43#include <iterator>
44
45QT_BEGIN_NAMESPACE
46
47using namespace Qt::StringLiterals;
48
49static const char dbNamespace[] = "http://docbook.org/ns/docbook";
50static const char xlinkNamespace[] = "http://www.w3.org/1999/xlink";
51static const char itsNamespace[] = "http://www.w3.org/2005/11/its";
52
54
55inline void DocBookGenerator::newLine()
56{
57 m_writer->writeCharacters("\n");
58}
59
60void DocBookGenerator::writeXmlId(const QString &id)
61{
62 if (id.isEmpty())
63 return;
64
65 m_writer->writeAttribute("xml:id", registerRef(id, true));
66}
67
68void DocBookGenerator::writeXmlId(const Node *node)
69{
70 if (!node)
71 return;
72
73 // Specifically for nodes, do not use the same code path as for QString
74 // inputs, as refForNode calls registerRef in all cases. Calling
75 // registerRef a second time adds a character to "disambiguate" the two IDs
76 // (the one returned by refForNode, then the one that is written as
77 // xml:id).
78 QString id = Generator::cleanRef(refForNode(node), true);
79 if (!id.isEmpty())
80 m_writer->writeAttribute("xml:id", id);
81}
82
83void DocBookGenerator::startSectionBegin(const QString &id)
84{
85 m_hasSection = true;
86
87 m_writer->writeStartElement(dbNamespace, "section");
88 writeXmlId(id);
89 newLine();
90 m_writer->writeStartElement(dbNamespace, "title");
91}
92
93void DocBookGenerator::startSectionBegin(const Node *node)
94{
95 m_writer->writeStartElement(dbNamespace, "section");
96 writeXmlId(node);
97 newLine();
98 m_writer->writeStartElement(dbNamespace, "title");
99}
100
101void DocBookGenerator::startSectionEnd()
102{
103 m_writer->writeEndElement(); // title
104 newLine();
105}
106
107void DocBookGenerator::startSection(const QString &id, const QString &title)
108{
109 startSectionBegin(id);
110 m_writer->writeCharacters(title);
111 startSectionEnd();
112}
113
114void DocBookGenerator::startSection(const Node *node, const QString &title)
115{
116 startSectionBegin(node);
117 m_writer->writeCharacters(title);
118 startSectionEnd();
119}
120
121void DocBookGenerator::startSection(const QString &title)
122{
123 // No xml:id given: down the calls, "" is interpreted as "no ID".
124 startSection("", title);
125}
126
127void DocBookGenerator::endSection()
128{
129 m_writer->writeEndElement(); // section
130 newLine();
131}
132
133void DocBookGenerator::writeAnchor(const QString &id)
134{
135 if (id.isEmpty())
136 return;
137
138 m_writer->writeEmptyElement(dbNamespace, "anchor");
139 writeXmlId(id);
140 newLine();
141}
142
143/*!
144 Initializes the DocBook output generator's data structures
145 from the configuration (Config).
146 */
148{
149 // Excerpts from HtmlGenerator::initializeGenerator.
151 m_config = &Config::instance();
152
153 m_project = m_config->get(CONFIG_PROJECT).asString();
154 m_productName = m_config->get(CONFIG_PRODUCTNAME).asString();
155
156 m_projectDescription = m_config->get(CONFIG_DESCRIPTION).asString();
157 if (m_projectDescription.isEmpty() && !m_project.isEmpty())
158 m_projectDescription = m_project + QLatin1String(" Reference Documentation");
159
160 m_naturalLanguage = m_config->get(CONFIG_NATURALLANGUAGE).asString();
161 if (m_naturalLanguage.isEmpty())
162 m_naturalLanguage = QLatin1String("en");
163
164 m_buildVersion = m_config->get(CONFIG_BUILDVERSION).asString();
165 m_useDocBook52 = m_config->get(CONFIG_DOCBOOKEXTENSIONS).asBool() ||
166 m_config->get(format() + Config::dot + "usedocbookextensions").asBool();
167 m_useITS = m_config->get(format() + Config::dot + "its").asBool();
168}
169
171{
172 return "DocBook";
173}
174
175/*!
176 Returns "xml" for this subclass of Generator.
177 */
179{
180 return "xml";
181}
182
183/*!
184 Generate the documentation for \a relative. i.e. \a relative
185 is the node that represents the entity where a qdoc comment
186 was found, and \a text represents the qdoc comment.
187 */
188bool DocBookGenerator::generateText(const Text &text, const Node *relative)
189{
190 // From Generator::generateText.
191 if (!text.firstAtom())
192 return false;
193
194 int numAtoms = 0;
196 generateAtomList(text.firstAtom(), relative, nullptr, true, numAtoms);
198 return true;
199}
200
201QString removeCodeMarkers(const QString& code) {
202 QString rewritten = code;
203 static const QRegularExpression re("(<@[^>&]*>)|(<\\/@[^&>]*>)");
204 rewritten.replace(re, "");
205 return rewritten;
206}
207
208/*!
209 Generate DocBook from an instance of Atom.
210 */
212{
213 Q_ASSERT(m_writer);
214 // From HtmlGenerator::generateAtom, without warning generation.
215 qsizetype idx = 0;
216 qsizetype skipAhead = 0;
217 Genus genus = Genus::DontCare;
218
219 switch (atom->type()) {
220 case Atom::AutoLink:
221 // Allow auto-linking to nodes in API reference
222 genus = Genus::API;
223 Q_FALLTHROUGH();
225 if (!m_inLink && !m_inContents && !m_inSectionHeading) {
226 const Node *node = nullptr;
227 QString link = getAutoLink(atom, relative, &node, genus);
228 if (!link.isEmpty() && node && node->isDeprecated()
229 && relative->parent() != node && !relative->isDeprecated()) {
230 link.clear();
231 }
232 if (link.isEmpty()) {
233 m_writer->writeCharacters(atom->string());
234 } else {
235 beginLink(link, node, relative);
236 generateLink(atom);
237 endLink();
238 }
239 } else {
240 m_writer->writeCharacters(atom->string());
241 }
242 break;
243 case Atom::BaseName:
244 break;
246 skipAhead = skipAtoms(atom, Atom::DeprecatedRight);
247 break;
249 break;
250 case Atom::BriefLeft:
251 if (!hasBrief(relative)) {
252 skipAhead = skipAtoms(atom, Atom::BriefRight);
253 break;
254 }
255 m_writer->writeStartElement(dbNamespace, "para");
256 m_inPara = true;
257 rewritePropertyBrief(atom, relative);
258 break;
259 case Atom::BriefRight:
260 if (hasBrief(relative)) {
261 m_writer->writeEndElement(); // para
262 m_inPara = false;
263 newLine();
264 }
265 break;
266 case Atom::C:
267 // This may at one time have been used to mark up C++ code but it is
268 // now widely used to write teletype text. As a result, text marked
269 // with the \c command is not passed to a code marker.
270 if (m_inTeletype)
271 m_writer->writeCharacters(plainCode(atom->string()));
272 else
273 m_writer->writeTextElement(dbNamespace, "code", plainCode(atom->string()));
274 break;
275 case Atom::CaptionLeft:
276 m_writer->writeStartElement(dbNamespace, "title");
277 break;
279 endLink();
280 m_writer->writeEndElement(); // title
281 newLine();
282 break;
283 case Atom::Qml:
284 m_writer->writeStartElement(dbNamespace, "programlisting");
285 m_writer->writeAttribute("language", "qml");
286 if (m_useITS)
287 m_writer->writeAttribute(itsNamespace, "translate", "no");
288 m_writer->writeCharacters(plainCode(removeCodeMarkers(atom->string())));
289 m_writer->writeEndElement(); // programlisting
290 newLine();
291 break;
292 case Atom::Code:
293 m_writer->writeStartElement(dbNamespace, "programlisting");
294 // Recover an additional string containing the code language, if present.
295 if (atom->strings().count() == 2)
296 m_writer->writeAttribute("language", atom->string(1));
297 else
298 m_writer->writeAttribute("language", "cpp");
299 if (m_useITS)
300 m_writer->writeAttribute(itsNamespace, "translate", "no");
301 m_writer->writeCharacters(plainCode(removeCodeMarkers(atom->string())));
302 m_writer->writeEndElement(); // programlisting
303 newLine();
304 break;
305 case Atom::CodeBad:
306 m_writer->writeStartElement(dbNamespace, "programlisting");
307 m_writer->writeAttribute("language", "cpp");
308 m_writer->writeAttribute("role", "bad");
309 if (m_useITS)
310 m_writer->writeAttribute(itsNamespace, "translate", "no");
311 m_writer->writeCharacters(plainCode(removeCodeMarkers(atom->string())));
312 m_writer->writeEndElement(); // programlisting
313 newLine();
314 break;
317 break;
318 case Atom::DetailsSummaryLeft: { // Ignore/skip \details summary
319 qsizetype offset{ 0 };
320 std::ignore = atom->find(Atom::DetailsSummaryRight, &offset);
321 skipAhead += offset;
322 } break;
324 break;
325 case Atom::DivLeft:
326 case Atom::DivRight:
327 break;
328 case Atom::FootnoteLeft:
329 m_writer->writeStartElement(dbNamespace, "footnote");
330 newLine();
331 m_writer->writeStartElement(dbNamespace, "para");
332 m_inPara = true;
333 break;
334 case Atom::FootnoteRight:
335 m_writer->writeEndElement(); // para
336 m_inPara = false;
337 newLine();
338 m_writer->writeEndElement(); // footnote
339 break;
340 case Atom::FormatElse:
342 case Atom::FormatIf:
343 break;
345 if (atom->string() == ATOM_FORMATTING_BOLD) {
346 m_writer->writeStartElement(dbNamespace, "emphasis");
347 m_writer->writeAttribute("role", "bold");
348 } else if (atom->string() == ATOM_FORMATTING_ITALIC) {
349 m_writer->writeStartElement(dbNamespace, "emphasis");
350 } else if (atom->string() == ATOM_FORMATTING_UNDERLINE) {
351 m_writer->writeStartElement(dbNamespace, "emphasis");
352 m_writer->writeAttribute("role", "underline");
353 } else if (atom->string() == ATOM_FORMATTING_SUBSCRIPT) {
354 m_writer->writeStartElement(dbNamespace, "subscript");
355 } else if (atom->string() == ATOM_FORMATTING_SUPERSCRIPT) {
356 m_writer->writeStartElement(dbNamespace, "superscript");
357 } else if (atom->string() == ATOM_FORMATTING_TELETYPE
358 || atom->string() == ATOM_FORMATTING_PARAMETER) {
359 m_writer->writeStartElement(dbNamespace, "code");
360 if (m_useITS)
361 m_writer->writeAttribute(itsNamespace, "translate", "no");
362
363 if (atom->string() == ATOM_FORMATTING_PARAMETER)
364 m_writer->writeAttribute("role", "parameter");
365 else // atom->string() == ATOM_FORMATTING_TELETYPE
366 m_inTeletype = true;
367 } else if (atom->string() == ATOM_FORMATTING_UICONTROL) {
368 m_writer->writeStartElement(dbNamespace, "guilabel");
369 if (m_useITS)
370 m_writer->writeAttribute(itsNamespace, "translate", "no");
371 } else if (atom->string() == ATOM_FORMATTING_TRADEMARK) {
372 m_writer->writeStartElement(dbNamespace,
373 appendTrademark(atom->find(Atom::FormattingRight)) ?
374 "trademark" : "phrase");
375 if (m_useITS)
376 m_writer->writeAttribute(itsNamespace, "translate", "no");
377 } else if (atom->string() == ATOM_FORMATTING_NOTRANSLATE) {
378 m_writer->writeStartElement(dbNamespace, "phrase");
379 if (m_useITS)
380 m_writer->writeAttribute(itsNamespace, "translate", "no");
381 } else {
382 relative->location().warning(QStringLiteral("Unsupported formatting: %1").arg(atom->string()));
383 }
384 break;
386 if (atom->string() == ATOM_FORMATTING_BOLD || atom->string() == ATOM_FORMATTING_ITALIC
387 || atom->string() == ATOM_FORMATTING_UNDERLINE
388 || atom->string() == ATOM_FORMATTING_SUBSCRIPT
389 || atom->string() == ATOM_FORMATTING_SUPERSCRIPT
390 || atom->string() == ATOM_FORMATTING_TELETYPE
391 || atom->string() == ATOM_FORMATTING_PARAMETER
392 || atom->string() == ATOM_FORMATTING_UICONTROL
393 || atom->string() == ATOM_FORMATTING_TRADEMARK
394 || atom->string() == ATOM_FORMATTING_NOTRANSLATE) {
395 m_writer->writeEndElement();
396 } else if (atom->string() == ATOM_FORMATTING_LINK) {
397 if (atom->string() == ATOM_FORMATTING_TELETYPE)
398 m_inTeletype = false;
399 endLink();
400 } else {
401 relative->location().warning(QStringLiteral("Unsupported formatting: %1").arg(atom->string()));
402 }
403 break;
404 case Atom::AnnotatedList: {
405 if (const CollectionNode *cn = m_qdb->getCollectionNode(atom->string(), NodeType::Group))
406 generateList(cn, atom->string(), Generator::sortOrder(atom->strings().last()));
407 } break;
408 case Atom::GeneratedList: {
409 const auto sortOrder{Generator::sortOrder(atom->strings().last())};
410 bool hasGeneratedSomething = false;
411 if (atom->string() == QLatin1String("annotatedclasses")
412 || atom->string() == QLatin1String("attributions")
413 || atom->string() == QLatin1String("namespaces")) {
414 const NodeMultiMap things = atom->string() == QLatin1String("annotatedclasses")
415 ? m_qdb->getCppClasses()
416 : atom->string() == QLatin1String("attributions") ? m_qdb->getAttributions()
417 : m_qdb->getNamespaces();
418 generateAnnotatedList(relative, things.values(), atom->string(), Auto, sortOrder);
419 hasGeneratedSomething = !things.isEmpty();
420 } else if (atom->string() == QLatin1String("annotatedexamples")
421 || atom->string() == QLatin1String("annotatedattributions")) {
422 const NodeMultiMap things = atom->string() == QLatin1String("annotatedexamples")
423 ? m_qdb->getExamples()
424 : m_qdb->getAttributions();
425 generateAnnotatedLists(relative, things, atom->string());
426 hasGeneratedSomething = !things.isEmpty();
427 } else if (atom->string() == QLatin1String("classes")
428 || atom->string() == QLatin1String("qmlbasictypes") // deprecated!
429 || atom->string() == QLatin1String("qmlvaluetypes")
430 || atom->string() == QLatin1String("qmltypes")) {
431 const NodeMultiMap things = atom->string() == QLatin1String("classes")
432 ? m_qdb->getCppClasses()
433 : (atom->string() == QLatin1String("qmlvaluetypes")
434 || atom->string() == QLatin1String("qmlbasictypes"))
435 ? m_qdb->getQmlValueTypes()
436 : m_qdb->getQmlTypes();
437 generateCompactList(relative, things, true, QString(), atom->string());
438 hasGeneratedSomething = !things.isEmpty();
439 } else if (atom->string().contains("classes ")) {
440 QString rootName = atom->string().mid(atom->string().indexOf("classes") + 7).trimmed();
441 NodeMultiMap things = m_qdb->getCppClasses();
442
443 hasGeneratedSomething = !things.isEmpty();
444 generateCompactList(relative, things, true, rootName, atom->string());
445 } else if ((idx = atom->string().indexOf(QStringLiteral("bymodule"))) != -1) {
446 QString moduleName = atom->string().mid(idx + 8).trimmed();
447 NodeType moduleType = typeFromString(atom);
449 if (const CollectionNode *cn = qdb->getCollectionNode(moduleName, moduleType)) {
450 NodeMap map;
451 switch (moduleType) {
452 case NodeType::Module:
453 // classesbymodule <module_name>
454 map = cn->getMembers([](const Node *n){ return n->isClassNode(); });
455 break;
457 if (atom->string().contains(QLatin1String("qmlvaluetypes")))
458 map = cn->getMembers(NodeType::QmlValueType); // qmlvaluetypesbymodule <module_name>
459 else
460 map = cn->getMembers(NodeType::QmlType); // qmltypesbymodule <module_name>
461 break;
462 default: // fall back to generating all members
463 generateAnnotatedList(relative, cn->members(), atom->string(), Auto, sortOrder);
464 hasGeneratedSomething = !cn->members().isEmpty();
465 break;
466 }
467 if (!map.isEmpty()) {
468 generateAnnotatedList(relative, map.values(), atom->string(), Auto, sortOrder);
469 hasGeneratedSomething = true;
470 }
471 }
472 } else if (atom->string() == QLatin1String("classhierarchy")) {
473 generateClassHierarchy(relative, m_qdb->getCppClasses());
474 hasGeneratedSomething = !m_qdb->getCppClasses().isEmpty();
475 } else if (atom->string().startsWith("obsolete")) {
476 QString prefix = atom->string().contains("cpp") ? QStringLiteral("Q") : QString();
477 const NodeMultiMap &things = atom->string() == QLatin1String("obsoleteclasses")
478 ? m_qdb->getObsoleteClasses()
479 : atom->string() == QLatin1String("obsoleteqmltypes")
480 ? m_qdb->getObsoleteQmlTypes()
481 : atom->string() == QLatin1String("obsoletecppmembers")
482 ? m_qdb->getClassesWithObsoleteMembers()
483 : m_qdb->getQmlTypesWithObsoleteMembers();
484 generateCompactList(relative, things, false, prefix, atom->string());
485 hasGeneratedSomething = !things.isEmpty();
486 } else if (atom->string() == QLatin1String("functionindex")) {
487 generateFunctionIndex(relative);
488 hasGeneratedSomething = !m_qdb->getFunctionIndex().isEmpty();
489 } else if (atom->string() == QLatin1String("legalese")) {
490 generateLegaleseList(relative);
491 hasGeneratedSomething = !m_qdb->getLegaleseTexts().isEmpty();
492 } else if (atom->string() == QLatin1String("overviews")
493 || atom->string() == QLatin1String("cpp-modules")
494 || atom->string() == QLatin1String("qml-modules")
495 || atom->string() == QLatin1String("related")) {
496 generateList(relative, atom->string());
497 hasGeneratedSomething = true; // Approximation, because there is
498 // some nontrivial logic in generateList.
499 } else if (const auto *cn = m_qdb->getCollectionNode(atom->string(), NodeType::Group); cn) {
500 generateAnnotatedList(cn, cn->members(), atom->string(), ItemizedList, sortOrder);
501 hasGeneratedSomething = true; // Approximation
502 }
503
504 // There must still be some content generated for the DocBook document
505 // to be valid (except if already in a paragraph).
506 if (!hasGeneratedSomething && !m_inPara) {
507 m_writer->writeEmptyElement(dbNamespace, "para");
508 newLine();
509 }
510 }
511 break;
512 case Atom::SinceList:
513 // Table of contents, should automatically be generated by the DocBook processor.
514 Q_FALLTHROUGH();
515 case Atom::LineBreak:
516 case Atom::BR:
517 case Atom::HR:
518 // Not supported in DocBook.
519 break;
520 case Atom::Image: // mediaobject
521 // An Image atom is always followed by an ImageText atom,
522 // containing the alternative text.
523 // If no caption is present, we just output a <db:mediaobject>,
524 // avoiding the wrapper as it is not required.
525 // For bordered images, there is another atom before the
526 // caption, DivRight (the corresponding DivLeft being just
527 // before the image).
528
531 // If there is a caption, there must be a <db:figure>
532 // wrapper starting with the caption.
533 Q_ASSERT(atom->next());
534 Q_ASSERT(atom->next()->next());
535 Q_ASSERT(atom->next()->next()->next());
538
539 m_writer->writeStartElement(dbNamespace, "figure");
540 newLine();
541
542 const Atom *current = atom->next()->next()->next();
543 skipAhead += 2;
544
545 Q_ASSERT(current->type() == Atom::CaptionLeft);
546 generateAtom(current, relative, nullptr);
547 current = current->next();
548 ++skipAhead;
549
550 while (current->type() != Atom::CaptionRight) { // The actual caption.
551 generateAtom(current, relative, nullptr);
552 current = current->next();
553 ++skipAhead;
554 }
555
556 Q_ASSERT(current->type() == Atom::CaptionRight);
557 generateAtom(current, relative, nullptr);
558 current = current->next();
559 ++skipAhead;
560
561 m_closeFigureWrapper = true;
562 }
563
565 // If there is a caption, there must be a <db:figure>
566 // wrapper starting with the caption.
567 Q_ASSERT(atom->next());
568 Q_ASSERT(atom->next()->next());
569 Q_ASSERT(atom->next()->next()->next());
571
572 m_writer->writeStartElement(dbNamespace, "figure");
573 newLine();
574
575 const Atom *current = atom->next()->next();
576 ++skipAhead;
577
578 Q_ASSERT(current->type() == Atom::CaptionLeft);
579 generateAtom(current, relative, nullptr);
580 current = current->next();
581 ++skipAhead;
582
583 while (current->type() != Atom::CaptionRight) { // The actual caption.
584 generateAtom(current, relative, nullptr);
585 current = current->next();
586 ++skipAhead;
587 }
588
589 Q_ASSERT(current->type() == Atom::CaptionRight);
590 generateAtom(current, relative, nullptr);
591 current = current->next();
592 ++skipAhead;
593
594 m_closeFigureWrapper = true;
595 }
596
597 Q_FALLTHROUGH();
598 case Atom::InlineImage: { // inlinemediaobject
599 // TODO: [generator-insufficient-structural-abstraction]
600 // The structure of the computations for this part of the
601 // docbook generation and the same parts in other format
602 // generators is the same.
603 //
604 // The difference, instead, lies in what the generated output
605 // is like. A correct abstraction for a generator would take
606 // this structural equivalence into account and encapsulate it
607 // into a driver for the format generators.
608 //
609 // This would avoid the replication of content, and the
610 // subsequent friction for changes and desynchronization
611 // between generators.
612 //
613 // Review all the generators routines and find the actual
614 // skeleton that is shared between them, then consider it when
615 // extracting the logic for the generation phase.
616 QString tag = atom->type() == Atom::Image ? "mediaobject" : "inlinemediaobject";
617 m_writer->writeStartElement(dbNamespace, tag);
618 newLine();
619
620 auto maybe_resolved_file{file_resolver.resolve(atom->string())};
621 if (!maybe_resolved_file) {
622 // TODO: [uncetnralized-admonition][failed-resolve-file]
623 relative->location().warning(QStringLiteral("Missing image: %1").arg(atom->string()));
624
625 m_writer->writeStartElement(dbNamespace, "textobject");
626 newLine();
627 m_writer->writeStartElement(dbNamespace, "para");
628 m_writer->writeTextElement(dbNamespace, "emphasis",
629 "[Missing image " + atom->string() + "]");
630 m_writer->writeEndElement(); // para
631 newLine();
632 m_writer->writeEndElement(); // textobject
633 newLine();
634 } else {
635 ResolvedFile file{*maybe_resolved_file};
636 QString file_name{QFileInfo{file.get_path()}.fileName()};
637
638 // TODO: [uncentralized-output-directory-structure]
639 Config::copyFile(relative->doc().location(), file.get_path(), file_name,
640 "%1/%2"_L1.arg(outputDir(), imagesOutputDir()));
641
642 if (atom->next() && !atom->next()->string().isEmpty()
644 m_writer->writeTextElement(dbNamespace, "alt", atom->next()->string());
645 newLine();
646 }
647
648 m_writer->writeStartElement(dbNamespace, "imageobject");
649 newLine();
650 m_writer->writeEmptyElement(dbNamespace, "imagedata");
651 const auto &imgPath = "%1/%2"_L1.arg(imagesOutputDir(), file_name);
652 // TODO: [uncentralized-output-directory-structure]
653 m_writer->writeAttribute("fileref", imgPath);
654 newLine();
655 m_writer->writeEndElement(); // imageobject
656 newLine();
657
658 // TODO: [uncentralized-output-directory-structure]
659 setImageFileName(relative, imgPath);
660 }
661
662 m_writer->writeEndElement(); // [inline]mediaobject
663 if (atom->type() == Atom::Image)
664 newLine();
665
666 if (m_closeFigureWrapper) {
667 m_writer->writeEndElement(); // figure
668 newLine();
669 m_closeFigureWrapper = false;
670 }
671 } break;
672 case Atom::ImageText:
673 break;
675 case Atom::NoteLeft:
676 case Atom::WarningLeft: {
677 QString admonType = atom->typeString().toLower();
678 // Remove 'Left' to get the admonition type
679 admonType.chop(4);
680 m_writer->writeStartElement(dbNamespace, admonType);
681 newLine();
682 m_writer->writeStartElement(dbNamespace, "para");
683 m_inPara = true;
684 } break;
685 case Atom::ImportantRight:
686 case Atom::NoteRight:
687 case Atom::WarningRight:
688 m_writer->writeEndElement(); // para
689 m_inPara = false;
690 newLine();
691 m_writer->writeEndElement(); // note/important
692 newLine();
693 break;
696 break;
697 case Atom::Link:
698 case Atom::NavLink: {
699 const Node *node = nullptr;
700 QString link = getLink(atom, relative, &node);
701 beginLink(link, node, relative); // Ended at Atom::FormattingRight
702 skipAhead = 1;
703 } break;
704 case Atom::LinkNode: {
705 const Node *node = static_cast<const Node*>(Utilities::nodeForString(atom->string()));
706 beginLink(linkForNode(node, relative), node, relative);
707 skipAhead = 1;
708 } break;
709 case Atom::ListLeft:
710 if (m_inPara) {
711 // The variable m_inPara is not set in a very smart way, because
712 // it ignores nesting. This might in theory create false positives
713 // here. A better solution would be to track the depth of
714 // paragraphs the generator is in, but determining the right check
715 // for this condition is far from trivial (think of nested lists).
716 m_writer->writeEndElement(); // para
717 newLine();
718 m_inPara = false;
719 }
720
721 if (atom->string() == ATOM_LIST_BULLET) {
722 m_writer->writeStartElement(dbNamespace, "itemizedlist");
723 newLine();
724 } else if (atom->string() == ATOM_LIST_TAG) {
725 m_writer->writeStartElement(dbNamespace, "variablelist");
726 newLine();
727 } else if (atom->string() == ATOM_LIST_VALUE) {
728 m_writer->writeStartElement(dbNamespace, "informaltable");
729 newLine();
730 m_writer->writeStartElement(dbNamespace, "thead");
731 newLine();
732 m_writer->writeStartElement(dbNamespace, "tr");
733 newLine();
734 m_writer->writeTextElement(dbNamespace, "th", "Constant");
735 newLine();
736
737 m_threeColumnEnumValueTable = isThreeColumnEnumValueTable(atom);
738 if (m_threeColumnEnumValueTable && relative->isEnumType(Genus::CPP)) {
739 // With three columns, if not in \enum topic, skip the value column
740 m_writer->writeTextElement(dbNamespace, "th", "Value");
741 newLine();
742 }
743
744 if (!isOneColumnValueTable(atom)) {
745 m_writer->writeTextElement(dbNamespace, "th", "Description");
746 newLine();
747 }
748
749 m_writer->writeEndElement(); // tr
750 newLine();
751 m_writer->writeEndElement(); // thead
752 newLine();
753 } else { // No recognized list type.
754 m_writer->writeStartElement(dbNamespace, "orderedlist");
755
756 if (atom->next() != nullptr && atom->next()->string().toInt() != 1)
757 m_writer->writeAttribute("startingnumber", atom->next()->string());
758
759 if (atom->string() == ATOM_LIST_UPPERALPHA)
760 m_writer->writeAttribute("numeration", "upperalpha");
761 else if (atom->string() == ATOM_LIST_LOWERALPHA)
762 m_writer->writeAttribute("numeration", "loweralpha");
763 else if (atom->string() == ATOM_LIST_UPPERROMAN)
764 m_writer->writeAttribute("numeration", "upperroman");
765 else if (atom->string() == ATOM_LIST_LOWERROMAN)
766 m_writer->writeAttribute("numeration", "lowerroman");
767 else // (atom->string() == ATOM_LIST_NUMERIC)
768 m_writer->writeAttribute("numeration", "arabic");
769
770 newLine();
771 }
772 m_inList++;
773 break;
775 break;
777 if (atom->string() == ATOM_LIST_TAG) {
778 m_writer->writeStartElement(dbNamespace, "varlistentry");
779 newLine();
780 m_writer->writeStartElement(dbNamespace, "item");
781 } else { // (atom->string() == ATOM_LIST_VALUE)
782 std::pair<QString, int> pair = getAtomListValue(atom);
783 skipAhead = pair.second;
784
785 m_writer->writeStartElement(dbNamespace, "tr");
786 newLine();
787 m_writer->writeStartElement(dbNamespace, "td");
788 newLine();
789 m_writer->writeStartElement(dbNamespace, "para");
790 if (m_useITS)
791 m_writer->writeAttribute(itsNamespace, "translate", "no");
792 generateEnumValue(pair.first, relative);
793 m_writer->writeEndElement(); // para
794 newLine();
795 m_writer->writeEndElement(); // td
796 newLine();
797
798 if (relative->isEnumType(Genus::CPP)) {
799 const auto enume = static_cast<const EnumNode *>(relative);
800 QString itemValue = enume->itemValue(atom->next()->string());
801
802 m_writer->writeStartElement(dbNamespace, "td");
803 if (itemValue.isEmpty())
804 m_writer->writeCharacters("?");
805 else {
806 m_writer->writeStartElement(dbNamespace, "code");
807 if (m_useITS)
808 m_writer->writeAttribute(itsNamespace, "translate", "no");
809 m_writer->writeCharacters(itemValue);
810 m_writer->writeEndElement(); // code
811 }
812 m_writer->writeEndElement(); // td
813 newLine();
814 }
815 }
816 m_inList++;
817 break;
819 if (atom->string() == ATOM_LIST_TAG) {
820 m_writer->writeEndElement(); // item
821 newLine();
822 }
823 break;
825 if (m_inList > 0 && atom->string() == ATOM_LIST_TAG) {
826 m_writer->writeEndElement(); // item
827 newLine();
828 m_inList = false;
829 }
830 break;
832 if (m_inList > 0) {
833 m_inListItemLineOpen = false;
834 if (atom->string() == ATOM_LIST_TAG) {
835 m_writer->writeStartElement(dbNamespace, "listitem");
836 newLine();
837 m_writer->writeStartElement(dbNamespace, "para");
838 m_inPara = true;
839 } else if (atom->string() == ATOM_LIST_VALUE) {
840 if (m_threeColumnEnumValueTable) {
842 m_writer->writeEmptyElement(dbNamespace, "td");
843 newLine();
844 m_inListItemLineOpen = false;
845 } else {
846 m_writer->writeStartElement(dbNamespace, "td");
847 newLine();
848 m_inListItemLineOpen = true;
849 }
850 }
851 } else {
852 m_writer->writeStartElement(dbNamespace, "listitem");
853 newLine();
854 }
855 // Don't skip a paragraph, DocBook requires them within list items.
856 }
857 break;
859 if (m_inList > 0) {
860 if (atom->string() == ATOM_LIST_TAG) {
861 m_writer->writeEndElement(); // para
862 m_inPara = false;
863 newLine();
864 m_writer->writeEndElement(); // listitem
865 newLine();
866 m_writer->writeEndElement(); // varlistentry
867 newLine();
868 } else if (atom->string() == ATOM_LIST_VALUE) {
869 if (m_inListItemLineOpen) {
870 m_writer->writeEndElement(); // td
871 newLine();
872 m_inListItemLineOpen = false;
873 }
874 m_writer->writeEndElement(); // tr
875 newLine();
876 } else {
877 m_writer->writeEndElement(); // listitem
878 newLine();
879 }
880 }
881 break;
882 case Atom::ListRight:
883 // Depending on atom->string(), closing a different item:
884 // - ATOM_LIST_BULLET: itemizedlist
885 // - ATOM_LIST_TAG: variablelist
886 // - ATOM_LIST_VALUE: informaltable
887 // - ATOM_LIST_NUMERIC: orderedlist
888 m_writer->writeEndElement();
889 newLine();
890 m_inList--;
891 break;
892 case Atom::Nop:
893 break;
894 case Atom::ParaLeft:
895 m_writer->writeStartElement(dbNamespace, "para");
896 m_inPara = true;
897 break;
898 case Atom::ParaRight:
899 endLink();
900 if (m_inPara) {
901 m_writer->writeEndElement(); // para
902 newLine();
903 m_inPara = false;
904 }
905 break;
906 case Atom::QuotationLeft:
907 m_writer->writeStartElement(dbNamespace, "blockquote");
908 m_inBlockquote = true;
909 break;
910 case Atom::QuotationRight:
911 m_writer->writeEndElement(); // blockquote
912 newLine();
913 m_inBlockquote = false;
914 break;
915 case Atom::RawString: {
916 m_writer->device()->write(atom->string().toUtf8());
917 }
918 break;
920 m_hasSection = true;
921
922 currentSectionLevel = atom->string().toInt() + hOffset(relative);
923 // Level 1 is dealt with at the header level (info tag).
924 if (currentSectionLevel > 1) {
925 // Unfortunately, SectionRight corresponds to the end of any section,
926 // i.e. going to a new section, even deeper.
927 while (!sectionLevels.empty() && sectionLevels.top() >= currentSectionLevel) {
928 sectionLevels.pop();
929 m_writer->writeEndElement(); // section
930 newLine();
931 }
932
933 sectionLevels.push(currentSectionLevel);
934
935 m_writer->writeStartElement(dbNamespace, "section");
936 writeXmlId(Tree::refForAtom(atom));
937 newLine();
938 // Unlike startSectionBegin, don't start a title here.
939 }
940
946 // A lonely section at the end of the document indicates that a
947 // generated list of some sort should be within this section.
948 // Close this section later on, in generateFooter().
949 generateAtom(atom->next(), relative, nullptr);
950 generateAtom(atom->next()->next(), relative, nullptr);
951 generateAtom(atom->next()->next()->next(), relative, nullptr);
952
953 m_closeSectionAfterGeneratedList = true;
954 skipAhead += 4;
955 sectionLevels.pop();
956 }
957
959 // No section title afterwards, make one up. This likely indicates a problem in the original documentation.
960 m_writer->writeTextElement(dbNamespace, "title", "");
961 }
962 break;
964 // All the logic about closing sections is done in the SectionLeft case
965 // and generateFooter() for the end of the page.
966 break;
968 // Level 1 is dealt with at the header level (info tag).
969 if (currentSectionLevel > 1) {
970 m_writer->writeStartElement(dbNamespace, "title");
971 m_inSectionHeading = true;
972 }
973 break;
975 // Level 1 is dealt with at the header level (info tag).
976 if (currentSectionLevel > 1) {
977 m_writer->writeEndElement(); // title
978 newLine();
979 m_inSectionHeading = false;
980 }
981 break;
982 case Atom::SidebarLeft:
983 m_writer->writeStartElement(dbNamespace, "sidebar");
984 break;
985 case Atom::SidebarRight:
986 m_writer->writeEndElement(); // sidebar
987 newLine();
988 break;
989 case Atom::String:
990 if (m_inLink && !m_inContents && !m_inSectionHeading)
991 generateLink(atom);
992 else
993 m_writer->writeCharacters(atom->string());
994 break;
995 case Atom::TableLeft: {
996 std::pair<QString, QString> pair = getTableWidthAttr(atom);
997 QString attr = pair.second;
998 QString width = pair.first;
999
1000 if (m_inPara) {
1001 m_writer->writeEndElement(); // para or blockquote
1002 newLine();
1003 m_inPara = false;
1004 }
1005
1006 m_tableHeaderAlreadyOutput = false;
1007
1008 m_writer->writeStartElement(dbNamespace, "informaltable");
1009 m_writer->writeAttribute("style", attr);
1010 if (!width.isEmpty())
1011 m_writer->writeAttribute("width", width);
1012 newLine();
1013 } break;
1014 case Atom::TableRight:
1015 m_tableWidthAttr = {"", ""};
1016 m_writer->writeEndElement(); // table
1017 newLine();
1018 break;
1019 case Atom::TableHeaderLeft: {
1021 ++skipAhead;
1022 break;
1023 }
1024
1025 if (m_tableHeaderAlreadyOutput) {
1026 // Headers are only allowed at the beginning of the table: close
1027 // the table and reopen one.
1028 m_writer->writeEndElement(); // table
1029 newLine();
1030
1031 const QString &attr = m_tableWidthAttr.second;
1032 const QString &width = m_tableWidthAttr.first;
1033
1034 m_writer->writeStartElement(dbNamespace, "informaltable");
1035 m_writer->writeAttribute("style", attr);
1036 if (!width.isEmpty())
1037 m_writer->writeAttribute("width", width);
1038 newLine();
1039 } else {
1040 m_tableHeaderAlreadyOutput = true;
1041 }
1042
1043 const Atom *next = atom->next();
1044 QString id{""};
1045 if (matchAhead(atom, Atom::Target)) {
1046 id = TextUtils::asAsciiPrintable(next->string());
1047 next = next->next();
1048 ++skipAhead;
1049 }
1050
1051 m_writer->writeStartElement(dbNamespace, "thead");
1052 newLine();
1053 m_writer->writeStartElement(dbNamespace, "tr");
1054 writeXmlId(id);
1055 newLine();
1056 m_inTableHeader = true;
1057
1059 m_closeTableCell = true;
1060 m_writer->writeStartElement(dbNamespace, "td");
1061 newLine();
1062 }
1063 }
1064 break;
1066 if (m_closeTableCell) {
1067 m_closeTableCell = false;
1068 m_writer->writeEndElement(); // td
1069 newLine();
1070 }
1071
1072 m_writer->writeEndElement(); // tr
1073 newLine();
1075 skipAhead = 1;
1076 m_writer->writeStartElement(dbNamespace, "tr");
1077 newLine();
1078 } else {
1079 m_writer->writeEndElement(); // thead
1080 newLine();
1081 m_inTableHeader = false;
1082 }
1083 break;
1084 case Atom::TableRowLeft: {
1086 skipAhead = 1;
1087 break;
1088 }
1089
1090 QString id{""};
1091 bool hasTarget {false};
1092 if (matchAhead(atom, Atom::Target)) {
1093 id = TextUtils::asAsciiPrintable(atom->next()->string());
1094 ++skipAhead;
1095 hasTarget = true;
1096 }
1097
1098 m_writer->writeStartElement(dbNamespace, "tr");
1099 writeXmlId(id);
1100
1101 if (atom->string().isEmpty()) {
1102 m_writer->writeAttribute("valign", "top");
1103 } else {
1104 // Basic parsing of attributes, should be enough. The input string (atom->string())
1105 // looks like:
1106 // arg1="val1" arg2="val2"
1107 QStringList args = atom->string().split("\"", Qt::SkipEmptyParts);
1108 // arg1=, val1, arg2=, val2,
1109 // \-- 1st --/ \-- 2nd --/ \-- remainder
1110 const int nArgs = args.size();
1111
1112 if (nArgs % 2) {
1113 // Problem...
1114 relative->doc().location().warning(
1115 QStringLiteral("Error when parsing attributes for the table: got \"%1\"")
1116 .arg(atom->string()));
1117 }
1118 for (int i = 0; i + 1 < nArgs; i += 2) {
1119 // args.at(i): name of the attribute being set.
1120 // args.at(i + 1): value of the said attribute.
1121 const QString &attr = args.at(i).chopped(1);
1122 if (attr == "id") { // Too bad if there is an anchor later on
1123 // (currently never happens).
1124 writeXmlId(args.at(i + 1));
1125 } else {
1126 m_writer->writeAttribute(attr, args.at(i + 1));
1127 }
1128 }
1129 }
1130 newLine();
1131
1132 // If there is nothing in this row, close it right now. There might be keywords before the row contents.
1133 bool isRowEmpty = hasTarget ? !matchAhead(atom->next(), Atom::TableItemLeft) : !matchAhead(atom, Atom::TableItemLeft);
1134 if (isRowEmpty && matchAhead(atom, Atom::Keyword)) {
1135 const Atom* next = atom->next();
1136 while (matchAhead(next, Atom::Keyword))
1137 next = next->next();
1138 isRowEmpty = !matchAhead(next, Atom::TableItemLeft);
1139 }
1140
1141 if (isRowEmpty) {
1142 m_closeTableRow = true;
1143 m_writer->writeEndElement(); // td
1144 newLine();
1145 }
1146 }
1147 break;
1149 if (m_closeTableRow) {
1150 m_closeTableRow = false;
1151 m_writer->writeEndElement(); // td
1152 newLine();
1153 }
1154
1155 m_writer->writeEndElement(); // tr
1156 newLine();
1157 break;
1158 case Atom::TableItemLeft:
1159 m_writer->writeStartElement(dbNamespace, m_inTableHeader ? "th" : "td");
1160
1161 for (int i = 0; i < atom->count(); ++i) {
1162 const QString &p = atom->string(i);
1163 if (p.contains('=')) {
1164 QStringList lp = p.split(QLatin1Char('='));
1165 m_writer->writeAttribute(lp.at(0), lp.at(1));
1166 } else {
1167 QStringList spans = p.split(QLatin1Char(','));
1168 if (spans.size() == 2) {
1169 if (spans.at(0) != "1")
1170 m_writer->writeAttribute("colspan", spans.at(0).trimmed());
1171 if (spans.at(1) != "1")
1172 m_writer->writeAttribute("rowspan", spans.at(1).trimmed());
1173 }
1174 }
1175 }
1176 newLine();
1177 // No skipahead, as opposed to HTML: in DocBook, the text must be wrapped in paragraphs.
1178 break;
1179 case Atom::TableItemRight:
1180 m_writer->writeEndElement(); // th if m_inTableHeader, otherwise td
1181 newLine();
1182 break;
1184 // Skip \toc .. \endtoc content, handled separately by TOCWriter
1185 std::ignore = atom->find(Atom::TableOfContentsRight, &skipAhead);
1186 break;
1187 case Atom::Keyword:
1188 break;
1189 case Atom::Target:
1190 // Sometimes, there is a \target just before a section title with the same ID. Only output one xml:id.
1192 QString nextId = TextUtils::asAsciiPrintable(
1194 QString ownId = TextUtils::asAsciiPrintable(atom->string());
1195 if (nextId == ownId)
1196 break;
1197 }
1198
1199 writeAnchor(TextUtils::asAsciiPrintable(atom->string()));
1200 break;
1201 case Atom::UnhandledFormat:
1202 m_writer->writeStartElement(dbNamespace, "emphasis");
1203 m_writer->writeAttribute("role", "bold");
1204 m_writer->writeCharacters("<Missing DocBook>");
1205 m_writer->writeEndElement(); // emphasis
1206 break;
1207 case Atom::UnknownCommand:
1208 m_writer->writeStartElement(dbNamespace, "emphasis");
1209 m_writer->writeAttribute("role", "bold");
1210 if (m_useITS)
1211 m_writer->writeAttribute(itsNamespace, "translate", "no");
1212 m_writer->writeCharacters("<Unknown command>");
1213 m_writer->writeStartElement(dbNamespace, "code");
1214 m_writer->writeCharacters(atom->string());
1215 m_writer->writeEndElement(); // code
1216 m_writer->writeEndElement(); // emphasis
1217 break;
1220 case Atom::ComparesLeft:
1225 // No output (ignore).
1226 break;
1227 default:
1228 unknownAtom(atom);
1229 }
1230 return skipAhead;
1231}
1232
1233void DocBookGenerator::generateClassHierarchy(const Node *relative, NodeMultiMap &classMap)
1234{
1235 // From HtmlGenerator::generateClassHierarchy.
1236 if (classMap.isEmpty())
1237 return;
1238
1239 std::function<void(ClassNode *)> generateClassAndChildren
1240 = [this, &relative, &generateClassAndChildren](ClassNode * classe) {
1241 m_writer->writeStartElement(dbNamespace, "listitem");
1242 newLine();
1243
1244 // This class.
1245 m_writer->writeStartElement(dbNamespace, "para");
1246 generateFullName(classe, relative);
1247 m_writer->writeEndElement(); // para
1248 newLine();
1249
1250 // Children, if any.
1251 bool hasChild = false;
1252 for (const RelatedClass &relatedClass : classe->derivedClasses()) {
1253 if (relatedClass.m_node && relatedClass.m_node->isInAPI()) {
1254 hasChild = true;
1255 break;
1256 }
1257 }
1258
1259 if (hasChild) {
1260 m_writer->writeStartElement(dbNamespace, "itemizedlist");
1261 newLine();
1262
1263 for (const RelatedClass &relatedClass: classe->derivedClasses()) {
1264 if (relatedClass.m_node && relatedClass.m_node->isInAPI()) {
1265 generateClassAndChildren(relatedClass.m_node);
1266 }
1267 }
1268
1269 m_writer->writeEndElement(); // itemizedlist
1270 newLine();
1271 }
1272
1273 // End this class.
1274 m_writer->writeEndElement(); // listitem
1275 newLine();
1276 };
1277
1278 m_writer->writeStartElement(dbNamespace, "itemizedlist");
1279 newLine();
1280
1281 for (const auto &it : classMap) {
1282 auto *classe = static_cast<ClassNode *>(it);
1283 if (classe->baseClasses().isEmpty())
1284 generateClassAndChildren(classe);
1285 }
1286
1287 m_writer->writeEndElement(); // itemizedlist
1288 newLine();
1289}
1290
1291void DocBookGenerator::generateLink(const Atom *atom)
1292{
1293 Q_ASSERT(m_inLink);
1294
1295 // From HtmlGenerator::generateLink.
1296 if (m_linkNode && m_linkNode->isFunction()) {
1297 auto match = XmlGenerator::m_funcLeftParen.match(atom->string());
1298 if (match.hasMatch()) {
1299 // C++: move () outside of link
1300 qsizetype leftParenLoc = match.capturedStart(1);
1301 m_writer->writeCharacters(atom->string().left(leftParenLoc));
1302 endLink();
1303 m_writer->writeCharacters(atom->string().mid(leftParenLoc));
1304 return;
1305 }
1306 }
1307 m_writer->writeCharacters(atom->string());
1308}
1309
1310/*!
1311 This version of the function is called when the \a link is known
1312 to be correct.
1313 */
1314void DocBookGenerator::beginLink(const QString &link, const Node *node, const Node *relative)
1315{
1316 // From HtmlGenerator::beginLink.
1317 m_writer->writeStartElement(dbNamespace, "link");
1318 m_writer->writeAttribute(xlinkNamespace, "href", link);
1319 if (node && !(relative && node->status() == relative->status())
1320 && node->isDeprecated())
1321 m_writer->writeAttribute("role", "deprecated");
1322 m_inLink = true;
1323 m_linkNode = node;
1324}
1325
1326void DocBookGenerator::endLink()
1327{
1328 // From HtmlGenerator::endLink.
1329 if (m_inLink)
1330 m_writer->writeEndElement(); // link
1331 m_inLink = false;
1332 m_linkNode = nullptr;
1333}
1334
1335void DocBookGenerator::generateList(const Node *relative, const QString &selector,
1336 Qt::SortOrder sortOrder)
1337{
1338 // From HtmlGenerator::generateList, without warnings, changing prototype.
1339 CNMap cnm;
1341 if (selector == QLatin1String("overviews"))
1342 type = NodeType::Group;
1343 else if (selector == QLatin1String("cpp-modules"))
1344 type = NodeType::Module;
1345 else if (selector == QLatin1String("qml-modules"))
1346 type = NodeType::QmlModule;
1347
1348 if (type != NodeType::NoType) {
1349 NodeList nodeList;
1350 m_qdb->mergeCollections(type, cnm, relative);
1351 const QList<CollectionNode *> collectionList = cnm.values();
1352 nodeList.reserve(collectionList.size());
1353 for (auto *collectionNode : collectionList)
1354 nodeList.append(collectionNode);
1355 generateAnnotatedList(relative, nodeList, selector, Auto, sortOrder);
1356 } else {
1357 /*
1358 \generatelist {selector} is only allowed in a comment where
1359 the topic is \group, \module, or \qmlmodule.
1360 */
1361 Node *n = const_cast<Node *>(relative);
1362 auto *cn = static_cast<CollectionNode *>(n);
1363 m_qdb->mergeCollections(cn);
1364 generateAnnotatedList(cn, cn->members(), selector, Auto, sortOrder);
1365 }
1366}
1367
1368/*!
1369 Outputs an annotated list of the nodes in \a nodeList.
1370 A two-column table is output.
1371 */
1372void DocBookGenerator::generateAnnotatedList(const Node *relative, const NodeList &nodeList,
1373 const QString &selector, GeneratedListType type,
1374 Qt::SortOrder sortOrder)
1375{
1376 if (nodeList.isEmpty())
1377 return;
1378
1379 // Do nothing if all items are internal or obsolete.
1380 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
1381 if (std::all_of(nodeList.cbegin(), nodeList.cend(), [&policy](const Node *n) {
1382 const NodeContext context = n->createContext();
1383 return !InclusionFilter::isIncluded(policy, context) || n->isDeprecated();
1384 })) {
1385 return;
1386 }
1387
1388 // Detect if there is a need for a variablelist (i.e. titles mapped to
1389 // descriptions) or a regular itemizedlist (only titles).
1390 bool noItemsHaveTitle =
1391 type == ItemizedList || std::all_of(nodeList.begin(), nodeList.end(),
1392 [](const Node* node) {
1393 return node->doc().briefText().toString().isEmpty();
1394 });
1395
1396 // Wrap the list in a section if needed.
1397 if (type == AutoSection && m_hasSection)
1398 startSection("", "Contents");
1399
1400 // From WebXMLGenerator::generateAnnotatedList.
1401 if (!nodeList.isEmpty()) {
1402 m_writer->writeStartElement(dbNamespace, noItemsHaveTitle ? "itemizedlist" : "variablelist");
1403 m_writer->writeAttribute("role", selector);
1404 newLine();
1405
1406 NodeList members;
1407 members.reserve(nodeList.size());
1408 std::copy_if(nodeList.cbegin(), nodeList.cend(), std::back_inserter(members),
1409 [&policy](const Node *n) {
1410 const NodeContext context = n->createContext();
1411 return InclusionFilter::isIncluded(policy, context) && !n->isDeprecated();
1412 });
1413
1414 if (sortOrder == Qt::DescendingOrder)
1415 std::sort(members.rbegin(), members.rend(), Node::nodeSortKeyOrNameLessThan);
1416 else
1417 std::sort(members.begin(), members.end(), Node::nodeSortKeyOrNameLessThan);
1418
1419 // Multiple nodes may share a documentation page; list each page only once.
1420 auto sameLocation = [this](const Node *a, const Node *b) {
1421 return fullDocumentLocation(a) == fullDocumentLocation(b);
1422 };
1423 members.erase(std::unique(members.begin(), members.end(), sameLocation), members.end());
1424
1425 for (const auto &node : std::as_const(members)) {
1426 if (noItemsHaveTitle) {
1427 m_writer->writeStartElement(dbNamespace, "listitem");
1428 newLine();
1429 m_writer->writeStartElement(dbNamespace, "para");
1430 } else {
1431 m_writer->writeStartElement(dbNamespace, "varlistentry");
1432 newLine();
1433 m_writer->writeStartElement(dbNamespace, "term");
1434 }
1435 generateFullName(node, relative);
1436 if (noItemsHaveTitle) {
1437 m_writer->writeEndElement(); // para
1438 newLine();
1439 m_writer->writeEndElement(); // listitem
1440 } else {
1441 m_writer->writeEndElement(); // term
1442 newLine();
1443 m_writer->writeStartElement(dbNamespace, "listitem");
1444 newLine();
1445 m_writer->writeStartElement(dbNamespace, "para");
1446 m_writer->writeCharacters(node->doc().briefText().toString());
1447 m_writer->writeEndElement(); // para
1448 newLine();
1449 m_writer->writeEndElement(); // listitem
1450 newLine();
1451 m_writer->writeEndElement(); // varlistentry
1452 }
1453 newLine();
1454 }
1455
1456 m_writer->writeEndElement(); // itemizedlist or variablelist
1457 newLine();
1458 }
1459
1460 if (type == AutoSection && m_hasSection)
1461 endSection();
1462}
1463
1464/*!
1465 Outputs a series of annotated lists from the nodes in \a nmm,
1466 divided into sections based by the key names in the multimap.
1467 */
1468void DocBookGenerator::generateAnnotatedLists(const Node *relative, const NodeMultiMap &nmm,
1469 const QString &selector)
1470{
1471 // From HtmlGenerator::generateAnnotatedLists.
1472 for (const QString &name : nmm.uniqueKeys()) {
1473 if (!name.isEmpty())
1474 startSection(name.toLower(), name);
1475 generateAnnotatedList(relative, nmm.values(name), selector);
1476 if (!name.isEmpty())
1477 endSection();
1478 }
1479}
1480
1481/*!
1482 This function finds the common prefix of the names of all
1483 the classes in the class map \a nmm and then generates a
1484 compact list of the class names alphabetized on the part
1485 of the name not including the common prefix. You can tell
1486 the function to use \a comonPrefix as the common prefix,
1487 but normally you let it figure it out itself by looking at
1488 the name of the first and last classes in the class map
1489 \a nmm.
1490 */
1491void DocBookGenerator::generateCompactList(const Node *relative, const NodeMultiMap &nmm,
1492 bool includeAlphabet, const QString &commonPrefix,
1493 const QString &selector)
1494{
1495 // From HtmlGenerator::generateCompactList. No more "includeAlphabet", this should be handled by
1496 // the DocBook toolchain afterwards.
1497 // TODO: In DocBook, probably no need for this method: this is purely presentational, i.e. to be
1498 // fully handled by the DocBook toolchain.
1499
1500 if (nmm.isEmpty())
1501 return;
1502
1503 const int NumParagraphs = 37; // '0' to '9', 'A' to 'Z', '_'
1504 qsizetype commonPrefixLen = commonPrefix.size();
1505
1506 /*
1507 Divide the data into 37 paragraphs: 0, ..., 9, A, ..., Z,
1508 underscore (_). QAccel will fall in paragraph 10 (A) and
1509 QXtWidget in paragraph 33 (X). This is the only place where we
1510 assume that NumParagraphs is 37. Each paragraph is a NodeMultiMap.
1511 */
1512 NodeMultiMap paragraph[NumParagraphs + 1];
1513 QString paragraphName[NumParagraphs + 1];
1514 QSet<char> usedParagraphNames;
1515
1516 for (auto c = nmm.constBegin(); c != nmm.constEnd(); ++c) {
1517 QStringList pieces = c.key().split("::");
1518 int idx = commonPrefixLen;
1519 if (idx > 0 && !pieces.last().startsWith(commonPrefix, Qt::CaseInsensitive))
1520 idx = 0;
1521 QString last = pieces.last().toLower();
1522 QString key = last.mid(idx);
1523
1524 int paragraphNr = NumParagraphs - 1;
1525
1526 if (key[0].digitValue() != -1) {
1527 paragraphNr = key[0].digitValue();
1528 } else if (key[0] >= QLatin1Char('a') && key[0] <= QLatin1Char('z')) {
1529 paragraphNr = 10 + key[0].unicode() - 'a';
1530 }
1531
1532 paragraphName[paragraphNr] = key[0].toUpper();
1533 usedParagraphNames.insert(key[0].toLower().cell());
1534 paragraph[paragraphNr].insert(last, c.value());
1535 }
1536
1537 /*
1538 Each paragraph j has a size: paragraph[j].count(). In the
1539 discussion, we will assume paragraphs 0 to 5 will have sizes
1540 3, 1, 4, 1, 5, 9.
1541
1542 We now want to compute the paragraph offset. Paragraphs 0 to 6
1543 start at offsets 0, 3, 4, 8, 9, 14, 23.
1544 */
1545 int paragraphOffset[NumParagraphs + 1]; // 37 + 1
1546 paragraphOffset[0] = 0;
1547 for (int i = 0; i < NumParagraphs; i++) // i = 0..36
1548 paragraphOffset[i + 1] = paragraphOffset[i] + paragraph[i].size();
1549
1550 // Output the alphabet as a row of links.
1551 if (includeAlphabet && !usedParagraphNames.isEmpty()) {
1552 m_writer->writeStartElement(dbNamespace, "simplelist");
1553 newLine();
1554
1555 for (int i = 0; i < 26; i++) {
1556 QChar ch('a' + i);
1557 if (usedParagraphNames.contains(char('a' + i))) {
1558 m_writer->writeStartElement(dbNamespace, "member");
1559 generateSimpleLink(ch, ch.toUpper());
1560 m_writer->writeEndElement(); // member
1561 newLine();
1562 }
1563 }
1564
1565 m_writer->writeEndElement(); // simplelist
1566 newLine();
1567 }
1568
1569 // Build a map of all duplicate names across the entire list
1570 QHash<QString, int> nameOccurrences;
1571 for (const auto &[key, node] : nmm.asKeyValueRange()) {
1572 QStringList pieces{node->fullName(relative).split("::"_L1)};
1573 const QString &name{pieces.last()};
1574 nameOccurrences[name]++;
1575 }
1576
1577 // Actual output.
1578 int curParNr = 0;
1579 int curParOffset = 0;
1580
1581 m_writer->writeStartElement(dbNamespace, "variablelist");
1582 m_writer->writeAttribute("role", selector);
1583 newLine();
1584
1585 for (int i = 0; i < nmm.size(); i++) {
1586 while ((curParNr < NumParagraphs) && (curParOffset == paragraph[curParNr].size())) {
1587
1588 ++curParNr;
1589 curParOffset = 0;
1590 }
1591
1592 // Starting a new paragraph means starting a new varlistentry.
1593 if (curParOffset == 0) {
1594 if (i > 0) {
1595 m_writer->writeEndElement(); // itemizedlist
1596 newLine();
1597 m_writer->writeEndElement(); // listitem
1598 newLine();
1599 m_writer->writeEndElement(); // varlistentry
1600 newLine();
1601 }
1602
1603 m_writer->writeStartElement(dbNamespace, "varlistentry");
1604 if (includeAlphabet)
1605 writeXmlId(paragraphName[curParNr][0].toLower());
1606 newLine();
1607
1608 m_writer->writeStartElement(dbNamespace, "term");
1609 m_writer->writeStartElement(dbNamespace, "emphasis");
1610 m_writer->writeAttribute("role", "bold");
1611 m_writer->writeCharacters(paragraphName[curParNr]);
1612 m_writer->writeEndElement(); // emphasis
1613 m_writer->writeEndElement(); // term
1614 newLine();
1615
1616 m_writer->writeStartElement(dbNamespace, "listitem");
1617 newLine();
1618 m_writer->writeStartElement(dbNamespace, "itemizedlist");
1619 newLine();
1620 }
1621
1622 // Output a listitem for the current offset in the current paragraph.
1623 m_writer->writeStartElement(dbNamespace, "listitem");
1624 newLine();
1625 m_writer->writeStartElement(dbNamespace, "para");
1626
1627 if ((curParNr < NumParagraphs) && !paragraphName[curParNr].isEmpty()) {
1628 NodeMultiMap::Iterator it;
1629 NodeMultiMap::Iterator next;
1630 it = paragraph[curParNr].begin();
1631 for (int j = 0; j < curParOffset; j++)
1632 ++it;
1633
1634 // Cut the name into pieces to determine whether it is simple (one piece) or complex
1635 // (more than one piece).
1636 QStringList pieces{it.value()->fullName(relative).split("::"_L1)};
1637 const auto &name{pieces.last()};
1638
1639 // Add module disambiguation if there are multiple types with the same name
1640 if (nameOccurrences[name] > 1) {
1641 const QString moduleName = it.value()->isQmlNode() ? it.value()->logicalModuleName()
1642 : it.value()->tree()->camelCaseModuleName();
1643 pieces.last().append(": %1"_L1.arg(moduleName));
1644 }
1645
1646 // Write the link to the element, which is identical if the element is obsolete or not.
1647 m_writer->writeStartElement(dbNamespace, "link");
1648 m_writer->writeAttribute(xlinkNamespace, "href", linkForNode(*it, relative));
1649 if (const QString type = targetType(it.value()); !type.isEmpty())
1650 m_writer->writeAttribute("role", type);
1651 m_writer->writeCharacters(pieces.last());
1652 m_writer->writeEndElement(); // link
1653
1654 // Outside the link, give the full name of the node if it is complex.
1655 if (pieces.size() > 1) {
1656 m_writer->writeCharacters(" (");
1657 generateFullName(it.value()->parent(), relative);
1658 m_writer->writeCharacters(")");
1659 }
1660 }
1661
1662 m_writer->writeEndElement(); // para
1663 newLine();
1664 m_writer->writeEndElement(); // listitem
1665 newLine();
1666
1667 curParOffset++;
1668 }
1669 m_writer->writeEndElement(); // itemizedlist
1670 newLine();
1671 m_writer->writeEndElement(); // listitem
1672 newLine();
1673 m_writer->writeEndElement(); // varlistentry
1674 newLine();
1675
1676 m_writer->writeEndElement(); // variablelist
1677 newLine();
1678}
1679
1680void DocBookGenerator::generateFunctionIndex(const Node *relative)
1681{
1682 // From HtmlGenerator::generateFunctionIndex.
1683
1684 // First list: links to parts of the second list, one item per letter.
1685 m_writer->writeStartElement(dbNamespace, "simplelist");
1686 m_writer->writeAttribute("role", "functionIndex");
1687 newLine();
1688 for (int i = 0; i < 26; i++) {
1689 QChar ch('a' + i);
1690 m_writer->writeStartElement(dbNamespace, "member");
1691 m_writer->writeAttribute(xlinkNamespace, "href", QString("#") + ch);
1692 m_writer->writeCharacters(ch.toUpper());
1693 m_writer->writeEndElement(); // member
1694 newLine();
1695 }
1696 m_writer->writeEndElement(); // simplelist
1697 newLine();
1698
1699 // Second list: the actual list of functions, sorted by alphabetical
1700 // order. One entry of the list per letter.
1701 if (m_qdb->getFunctionIndex().isEmpty())
1702 return;
1703 char nextLetter = 'a';
1704 char currentLetter;
1705
1706 m_writer->writeStartElement(dbNamespace, "itemizedlist");
1707 newLine();
1708
1709 NodeMapMap &funcIndex = m_qdb->getFunctionIndex();
1710 QMap<QString, NodeMap>::ConstIterator f = funcIndex.constBegin();
1711 while (f != funcIndex.constEnd()) {
1712 m_writer->writeStartElement(dbNamespace, "listitem");
1713 newLine();
1714 m_writer->writeStartElement(dbNamespace, "para");
1715 m_writer->writeCharacters(f.key() + ": ");
1716
1717 currentLetter = f.key()[0].unicode();
1718 while (islower(currentLetter) && currentLetter >= nextLetter) {
1719 writeAnchor(QString(nextLetter));
1720 nextLetter++;
1721 }
1722
1723 NodeMap::ConstIterator s = (*f).constBegin();
1724 while (s != (*f).constEnd()) {
1725 m_writer->writeCharacters(" ");
1726 generateFullName((*s)->parent(), relative);
1727 ++s;
1728 }
1729
1730 m_writer->writeEndElement(); // para
1731 newLine();
1732 m_writer->writeEndElement(); // listitem
1733 newLine();
1734 ++f;
1735 }
1736 m_writer->writeEndElement(); // itemizedlist
1737 newLine();
1738}
1739
1740void DocBookGenerator::generateLegaleseList(const Node *relative)
1741{
1742 // From HtmlGenerator::generateLegaleseList.
1743 TextToNodeMap &legaleseTexts = m_qdb->getLegaleseTexts();
1744 for (auto it = legaleseTexts.cbegin(), end = legaleseTexts.cend(); it != end; ++it) {
1745 Text text = it.key();
1746 generateText(text, relative);
1747 m_writer->writeStartElement(dbNamespace, "itemizedlist");
1748 newLine();
1749 do {
1750 m_writer->writeStartElement(dbNamespace, "listitem");
1751 newLine();
1752 m_writer->writeStartElement(dbNamespace, "para");
1753 generateFullName(it.value(), relative);
1754 m_writer->writeEndElement(); // para
1755 newLine();
1756 m_writer->writeEndElement(); // listitem
1757 newLine();
1758 ++it;
1759 } while (it != legaleseTexts.constEnd() && it.key() == text);
1760 m_writer->writeEndElement(); // itemizedlist
1761 newLine();
1762 }
1763}
1764
1765void DocBookGenerator::generateBrief(const Node *node)
1766{
1767 // From HtmlGenerator::generateBrief. Also see generateHeader, which is specifically dealing
1768 // with the DocBook header (and thus wraps the brief in an abstract).
1769 Text brief = node->doc().briefText();
1770
1771 if (!brief.isEmpty()) {
1772 if (!brief.lastAtom()->string().endsWith('.'))
1773 brief << Atom(Atom::String, ".");
1774
1775 m_writer->writeStartElement(dbNamespace, "para");
1776 generateText(brief, node);
1777 m_writer->writeEndElement(); // para
1778 newLine();
1779 }
1780}
1781
1783{
1784 if (node->since().isEmpty())
1785 return false;
1786
1787 const auto *shared = node->isSharedCommentNode()
1788 ? static_cast<const SharedCommentNode *>(node) : nullptr;
1789 const bool plural = shared && shared->collective().size() > 1;
1790 const Node *described = plural ? shared->collective().first() : node;
1791 const auto number = plural ? NodeText::GrammaticalNumber::Plural
1793
1794 m_writer->writeStartElement(dbNamespace, "para");
1795 m_writer->writeCharacters((plural ? "These "_L1 : "This "_L1)
1796 + NodeText::nodeTypeDescription(described, number)
1797 + (plural ? " were introduced in "_L1 : " was introduced in "_L1)
1798 + formatSince(node) + "."_L1);
1799 m_writer->writeEndElement(); // para
1800 newLine();
1801 return true;
1802}
1803
1804/*!
1805 Generate the DocBook header for the file, including the abstract.
1806 Equivalent to calling generateTitle and generateBrief in HTML.
1807*/
1808void DocBookGenerator::generateHeader(const Text &title, const QString &subTitle,
1809 const Node *node)
1810{
1811 generateHeader(title, node);
1812
1813 if (!subTitle.isEmpty()) {
1814 m_writer->writeStartElement(dbNamespace, "subtitle");
1815 if (isApiGenus(node->genus()) && m_useITS)
1816 m_writer->writeAttribute(itsNamespace, "translate", "no");
1817 m_writer->writeCharacters(subTitle);
1818 m_writer->writeEndElement(); // subtitle
1819 newLine();
1820 }
1821
1822 finishHeader(node);
1823}
1824
1825/*!
1826 Generates the opening portion of the DocBook header — \c{<db:info>}
1827 and the title element. The caller emits any subtitle (text-only or
1828 element-rich) directly into the writer afterwards, then calls
1829 finishHeader() to close \c{<db:info>} and write the abstract.
1830
1831 Class pages with template declarations use this two-step form so the
1832 subtitle element can carry \c{<db:link>} elements for concept
1833 references — content that wouldn't survive the plain-text subtitle
1834 path the 3-argument overload uses.
1835*/
1836void DocBookGenerator::generateHeader(const Text &title, const Node *node)
1837{
1838 refMap.clear();
1839
1840 // Output the DocBook header.
1841 m_writer->writeStartElement(dbNamespace, "info");
1842 newLine();
1843 m_writer->writeStartElement(dbNamespace, "title");
1844 if (isApiGenus(node->genus()) && m_useITS)
1845 m_writer->writeAttribute(itsNamespace, "translate", "no");
1846 generateText(title, node);
1847 m_writer->writeEndElement(); // title
1848 newLine();
1849}
1850
1851/*!
1852 Emits the tail of the DocBook header — product, edition, titleabbrev,
1853 navigation links, and abstract — then closes \c{<db:info>}. Used as
1854 the companion to the two-argument \c{generateHeader} overload that
1855 leaves the info element open for the caller to emit a rich subtitle.
1856*/
1858{
1859 if (!m_productName.isEmpty() || !m_project.isEmpty()) {
1860 m_writer->writeTextElement(dbNamespace, "productname", m_productName.isEmpty() ?
1861 m_project : m_productName);
1862 newLine();
1863 }
1864
1865 if (!m_buildVersion.isEmpty()) {
1866 m_writer->writeTextElement(dbNamespace, "edition", m_buildVersion);
1867 newLine();
1868 }
1869
1870 if (!m_projectDescription.isEmpty()) {
1871 m_writer->writeTextElement(dbNamespace, "titleabbrev", m_projectDescription);
1872 newLine();
1873 }
1874
1875 // Deal with links.
1876 // Adapted from HtmlGenerator::generateHeader (output part: no need to update a navigationLinks
1877 // or useSeparator field, as this content is only output in the info tag, not in the main
1878 // content).
1879 if (node && !node->links().empty()) {
1880 std::pair<QString, QString> linkPair;
1881 std::pair<QString, QString> anchorPair;
1882 const Node *linkNode;
1883
1884 if (node->links().contains(Node::PreviousLink)) {
1885 linkPair = node->links()[Node::PreviousLink];
1886 linkNode = m_qdb->findNodeForTarget(linkPair.first, node);
1887 if (!linkNode || linkNode == node)
1888 anchorPair = linkPair;
1889 else
1890 anchorPair = anchorForNode(linkNode);
1891
1892 m_writer->writeStartElement(dbNamespace, "extendedlink");
1893 m_writer->writeAttribute(xlinkNamespace, "type", "extended");
1894 m_writer->writeEmptyElement(dbNamespace, "link");
1895 m_writer->writeAttribute(xlinkNamespace, "to", anchorPair.first);
1896 m_writer->writeAttribute(xlinkNamespace, "type", "arc");
1897 m_writer->writeAttribute(xlinkNamespace, "arcrole", "prev");
1898 if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
1899 m_writer->writeAttribute(xlinkNamespace, "title", anchorPair.second);
1900 else
1901 m_writer->writeAttribute(xlinkNamespace, "title", linkPair.second);
1902 m_writer->writeEndElement(); // extendedlink
1903 newLine();
1904 }
1905 if (node->links().contains(Node::NextLink)) {
1906 linkPair = node->links()[Node::NextLink];
1907 linkNode = m_qdb->findNodeForTarget(linkPair.first, node);
1908 if (!linkNode || linkNode == node)
1909 anchorPair = linkPair;
1910 else
1911 anchorPair = anchorForNode(linkNode);
1912
1913 m_writer->writeStartElement(dbNamespace, "extendedlink");
1914 m_writer->writeAttribute(xlinkNamespace, "type", "extended");
1915 m_writer->writeEmptyElement(dbNamespace, "link");
1916 m_writer->writeAttribute(xlinkNamespace, "to", anchorPair.first);
1917 m_writer->writeAttribute(xlinkNamespace, "type", "arc");
1918 m_writer->writeAttribute(xlinkNamespace, "arcrole", "next");
1919 if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
1920 m_writer->writeAttribute(xlinkNamespace, "title", anchorPair.second);
1921 else
1922 m_writer->writeAttribute(xlinkNamespace, "title", linkPair.second);
1923 m_writer->writeEndElement(); // extendedlink
1924 newLine();
1925 }
1926 if (node->links().contains(Node::StartLink)) {
1927 linkPair = node->links()[Node::StartLink];
1928 linkNode = m_qdb->findNodeForTarget(linkPair.first, node);
1929 if (!linkNode || linkNode == node)
1930 anchorPair = linkPair;
1931 else
1932 anchorPair = anchorForNode(linkNode);
1933
1934 m_writer->writeStartElement(dbNamespace, "extendedlink");
1935 m_writer->writeAttribute(xlinkNamespace, "type", "extended");
1936 m_writer->writeEmptyElement(dbNamespace, "link");
1937 m_writer->writeAttribute(xlinkNamespace, "to", anchorPair.first);
1938 m_writer->writeAttribute(xlinkNamespace, "type", "arc");
1939 m_writer->writeAttribute(xlinkNamespace, "arcrole", "start");
1940 if (linkPair.first == linkPair.second && !anchorPair.second.isEmpty())
1941 m_writer->writeAttribute(xlinkNamespace, "title", anchorPair.second);
1942 else
1943 m_writer->writeAttribute(xlinkNamespace, "title", linkPair.second);
1944 m_writer->writeEndElement(); // extendedlink
1945 newLine();
1946 }
1947 }
1948
1949 // Deal with the abstract (what qdoc calls brief).
1950 if (node) {
1951 // Adapted from HtmlGenerator::generateBrief, without extraction marks. The parameter
1952 // addLink is always false. Factoring this function out is not as easy as in HtmlGenerator:
1953 // abstracts only happen in the header (info tag), slightly different tags must be used at
1954 // other places. Also includes code from HtmlGenerator::generateCppReferencePage to handle
1955 // the name spaces.
1956 m_writer->writeStartElement(dbNamespace, "abstract");
1957 newLine();
1958
1959 bool generatedSomething = false;
1960
1961 Text brief;
1962 const NamespaceNode *ns =
1963 node->isNamespace() ? static_cast<const NamespaceNode *>(node) : nullptr;
1964 if (ns && !ns->hasDoc() && ns->docNode()) {
1965 NamespaceNode *NS = ns->docNode();
1966 brief << "The " << ns->name()
1967 << " namespace includes the following elements from module "
1968 << ns->tree()->camelCaseModuleName() << ". The full namespace is "
1969 << "documented in module " << NS->tree()->camelCaseModuleName();
1970 addNodeLink(brief, fullDocumentLocation(NS), " here.");
1971 } else {
1972 brief = node->doc().briefText();
1973 }
1974
1975 if (!brief.isEmpty()) {
1976 if (!brief.lastAtom()->string().endsWith('.'))
1977 brief << Atom(Atom::String, ".");
1978
1979 m_writer->writeStartElement(dbNamespace, "para");
1980 generateText(brief, node);
1981 m_writer->writeEndElement(); // para
1982 newLine();
1983
1984 generatedSomething = true;
1985 }
1986
1987 // Generate other paragraphs that should go into the abstract.
1988 generatedSomething |= generateStatus(node);
1989 generatedSomething |= generateSince(node);
1990 generatedSomething |= generateThreadSafeness(node);
1991 generatedSomething |= generateComparisonTable(node);
1992
1993 // An abstract cannot be empty, hence use the project description.
1994 if (!generatedSomething)
1995 m_writer->writeTextElement(dbNamespace, "para", m_projectDescription + ".");
1996
1997 m_writer->writeEndElement(); // abstract
1998 newLine();
1999 }
2000
2001 // End of the DocBook header.
2002 m_writer->writeEndElement(); // info
2003 newLine();
2004}
2005
2007{
2008 while (!sectionLevels.isEmpty()) {
2009 sectionLevels.pop();
2010 endSection();
2011 }
2012}
2013
2015{
2016 if (m_closeSectionAfterGeneratedList) {
2017 m_closeSectionAfterGeneratedList = false;
2018 endSection();
2019 }
2020 if (m_closeSectionAfterRawTitle) {
2021 m_closeSectionAfterRawTitle = false;
2022 endSection();
2023 }
2024
2026 m_writer->writeEndElement(); // article
2027}
2028
2029void DocBookGenerator::generateSimpleLink(const QString &href, const QString &text)
2030{
2031 m_writer->writeStartElement(dbNamespace, "link");
2032 m_writer->writeAttribute(xlinkNamespace, "href", href);
2033 m_writer->writeCharacters(text);
2034 m_writer->writeEndElement(); // link
2035}
2036
2037/*!
2038 Writes the extra synopsis string \a extra, processing any embedded
2039 <@extref> tags and converting them to DocBook links.
2040*/
2041void DocBookGenerator::generateExtraSynopsis(const QString &extra)
2042{
2043 static const QHash<QString, QString> extrefUrls = {
2044 {u"cpp-explicitly-defaulted"_s,
2045 u"https://en.cppreference.com/w/cpp/language/function#Defaulted_functions"_s},
2046 {u"cpp-deleted-functions"_s,
2047 u"https://en.cppreference.com/w/cpp/language/function#Deleted_functions"_s},
2048 };
2049
2050 static const QRegularExpression extrefRegex(
2051 u"<@extref target=\"([^\"]+)\">([^<]*)</@extref>"_s);
2052
2053 qsizetype pos = 0;
2054 auto it = extrefRegex.globalMatch(extra);
2055 while (it.hasNext()) {
2056 auto match = it.next();
2057 if (match.capturedStart() > pos)
2058 m_writer->writeCharacters(extra.mid(pos, match.capturedStart() - pos));
2059
2060 QString target = match.captured(1);
2061 QString text = match.captured(2);
2062 QString url = extrefUrls.value(target);
2063 if (!url.isEmpty())
2064 generateSimpleLink(url, text);
2065 else
2066 m_writer->writeCharacters(text);
2067
2068 pos = match.capturedEnd();
2069 }
2070 if (pos < extra.size())
2071 m_writer->writeCharacters(extra.mid(pos));
2072}
2073
2074void DocBookGenerator::generateObsoleteMembers(const Sections &sections)
2075{
2076 // From HtmlGenerator::generateObsoleteMembersFile.
2077 SectionPtrVector summary_spv; // Summaries are ignored in DocBook (table of contents).
2078 SectionPtrVector details_spv;
2079 if (!sections.hasObsoleteMembers(&summary_spv, &details_spv))
2080 return;
2081
2082 const Aggregate *aggregate = sections.aggregate();
2083 startSection("obsolete", "Obsolete Members for " + aggregate->plainFullName());
2084
2085 m_writer->writeStartElement(dbNamespace, "para");
2086 m_writer->writeStartElement(dbNamespace, "emphasis");
2087 m_writer->writeAttribute("role", "bold");
2088 m_writer->writeCharacters("The following members of class ");
2089 generateSimpleLink(linkForNode(aggregate, nullptr), aggregate->name());
2090 m_writer->writeCharacters(" are deprecated.");
2091 m_writer->writeEndElement(); // emphasis bold
2092 m_writer->writeCharacters(" We strongly advise against using them in new code.");
2093 m_writer->writeEndElement(); // para
2094 newLine();
2095
2096 for (const Section *section : details_spv) {
2097 const QString &title = "Obsolete " + section->title();
2098 startSection(title.toLower(), title);
2099
2100 const NodeVector &members = section->obsoleteMembers();
2101 NodeVector::ConstIterator m = members.constBegin();
2102 while (m != members.constEnd()) {
2103 if ((*m)->access() != Access::Private)
2104 generateDetailedMember(*m, aggregate);
2105 ++m;
2106 }
2107
2108 endSection();
2109 }
2110
2111 endSection();
2112}
2113
2114/*!
2115 Generates a separate section where obsolete members of the QML
2116 type \a qcn are listed. The \a marker is used to generate
2117 the section lists, which are then traversed and output here.
2118
2119 Note that this function currently only handles correctly the
2120 case where \a status is \c {Section::Deprecated}.
2121 */
2122void DocBookGenerator::generateObsoleteQmlMembers(const Sections &sections)
2123{
2124 // From HtmlGenerator::generateObsoleteQmlMembersFile.
2125 SectionPtrVector summary_spv; // Summaries are not useful in DocBook.
2126 SectionPtrVector details_spv;
2127 if (!sections.hasObsoleteMembers(&summary_spv, &details_spv))
2128 return;
2129
2130 const Aggregate *aggregate = sections.aggregate();
2131 startSection("obsolete", "Obsolete Members for " + aggregate->name());
2132
2133 m_writer->writeStartElement(dbNamespace, "para");
2134 m_writer->writeStartElement(dbNamespace, "emphasis");
2135 m_writer->writeAttribute("role", "bold");
2136 m_writer->writeCharacters("The following members of QML type ");
2137 generateSimpleLink(linkForNode(aggregate, nullptr), aggregate->name());
2138 m_writer->writeCharacters(" are deprecated.");
2139 m_writer->writeEndElement(); // emphasis bold
2140 m_writer->writeCharacters(" We strongly advise against using them in new code.");
2141 m_writer->writeEndElement(); // para
2142 newLine();
2143
2144 for (const auto *section : details_spv) {
2145 const QString &title = "Obsolete " + section->title();
2146 startSection(title.toLower(), title);
2147
2148 const NodeVector &members = section->obsoleteMembers();
2149 NodeVector::ConstIterator m = members.constBegin();
2150 while (m != members.constEnd()) {
2151 if ((*m)->access() != Access::Private)
2152 generateDetailedQmlMember(*m, aggregate);
2153 ++m;
2154 }
2155
2156 endSection();
2157 }
2158
2159 endSection();
2160}
2161
2162static QString nodeToSynopsisTag(const Node *node)
2163{
2164 // Order from Node::nodeTypeString.
2165 if (node->isClass() || node->isQmlType())
2166 return QStringLiteral("classsynopsis");
2167 if (node->isNamespace())
2168 return QStringLiteral("packagesynopsis");
2169 if (node->isPageNode()) {
2170 node->doc().location().warning("Unexpected document node in nodeToSynopsisTag");
2171 return QString();
2172 }
2173 if (node->isEnumType())
2174 return QStringLiteral("enumsynopsis");
2175 if (node->isTypedef())
2176 return QStringLiteral("typedefsynopsis");
2177 if (node->isFunction()) {
2178 // Signals are also encoded as functions (including QML ones).
2179 const auto fn = static_cast<const FunctionNode *>(node);
2180 if (fn->isCtor() || fn->isCCtor() || fn->isMCtor())
2181 return QStringLiteral("constructorsynopsis");
2182 if (fn->isDtor())
2183 return QStringLiteral("destructorsynopsis");
2184 return QStringLiteral("methodsynopsis");
2185 }
2186 if (node->isProperty() || node->isVariable() || node->isQmlProperty())
2187 return QStringLiteral("fieldsynopsis");
2188
2189 node->doc().location().warning(QString("Unknown node tag %1").arg(node->nodeTypeString()));
2190 return QStringLiteral("synopsis");
2191}
2192
2193void DocBookGenerator::generateStartRequisite(const QString &description)
2194{
2195 m_writer->writeStartElement(dbNamespace, "varlistentry");
2196 newLine();
2197 m_writer->writeTextElement(dbNamespace, "term", description);
2198 newLine();
2199 m_writer->writeStartElement(dbNamespace, "listitem");
2200 newLine();
2201 m_writer->writeStartElement(dbNamespace, "para");
2202 m_inPara = true;
2203}
2204
2205void DocBookGenerator::generateEndRequisite()
2206{
2207 m_writer->writeEndElement(); // para
2208 m_inPara = false;
2209 newLine();
2210 m_writer->writeEndElement(); // listitem
2211 newLine();
2212 m_writer->writeEndElement(); // varlistentry
2213 newLine();
2214}
2215
2216void DocBookGenerator::generateRequisite(const QString &description, const QString &value)
2217{
2218 generateStartRequisite(description);
2219 m_writer->writeCharacters(value);
2220 generateEndRequisite();
2221}
2222
2223/*!
2224 * \internal
2225 * Generates the CMake (\a description) requisites
2226 */
2227void DocBookGenerator::generateCMakeRequisite(const QString &findPackage, const QString &linkLibraries)
2228{
2229 const QString description("CMake");
2230 generateStartRequisite(description);
2231 m_writer->writeCharacters(findPackage);
2232 m_writer->writeEndElement(); // para
2233 newLine();
2234
2235 m_writer->writeStartElement(dbNamespace, "para");
2236 m_writer->writeCharacters(linkLibraries);
2237 generateEndRequisite();
2238}
2239
2240void DocBookGenerator::generateSortedNames(const ClassNode *cn, const QList<RelatedClass> &rc)
2241{
2242 // From Generator::appendSortedNames.
2243 QMap<QString, ClassNode *> classMap;
2244 QList<RelatedClass>::ConstIterator r = rc.constBegin();
2245 while (r != rc.constEnd()) {
2246 ClassNode *rcn = (*r).m_node;
2247 if (rcn && rcn->access() == Access::Public && !rcn->isInternal()
2248 && !rcn->doc().isEmpty()) {
2249 classMap[rcn->plainFullName(cn).toLower()] = rcn;
2250 }
2251 ++r;
2252 }
2253
2254 QStringList classNames = classMap.keys();
2255 classNames.sort();
2256
2257 int index = 0;
2258 for (const QString &className : classNames) {
2259 generateFullName(classMap.value(className), cn);
2260 m_writer->writeCharacters(TextUtils::comma(index++, classNames.size()));
2261 }
2262}
2263
2264void DocBookGenerator::generateSortedQmlNames(const Node *base, const QStringList &knownTypes,
2265 const NodeList &subs)
2266{
2267 // From Generator::appendSortedQmlNames.
2268 QMap<QString, Node *> classMap;
2269 QStringList typeNames(knownTypes);
2270 for (const auto sub : subs)
2271 typeNames << sub->name();
2272
2273 for (auto sub : subs) {
2274 QString key{sub->plainFullName(base).toLower()};
2275 // Disambiguate with '(<QML module name>)' if there are clashing type names
2276 if (typeNames.count(sub->name()) > 1)
2277 key.append(": (%1)"_L1.arg(sub->logicalModuleName()));
2278 classMap[key] = sub;
2279 }
2280
2281 QStringList names = classMap.keys();
2282 names.sort();
2283
2284 int index = 0;
2285 for (const QString &name : names) {
2286 generateFullName(classMap.value(name), base);
2287 if (name.contains(':'))
2288 m_writer->writeCharacters(name.section(':', 1));
2289 m_writer->writeCharacters(TextUtils::comma(index++, names.size()));
2290 }
2291}
2292
2293/*!
2294 Lists the required imports and includes.
2295*/
2297{
2298 // Adapted from HtmlGenerator::generateRequisites, but simplified: no need to store all the
2299 // elements, they can be produced one by one.
2300
2301 // Generate the requisites first separately: if some of them are generated, output them in a wrapper.
2302 // This complexity is required to ensure the DocBook file is valid: an empty list is not valid. It is not easy
2303 // to write a truly comprehensive condition.
2304 QXmlStreamWriter* oldWriter = m_writer;
2305 QString output;
2306 m_writer = new QXmlStreamWriter(&output);
2307
2308 // Includes.
2309 if (aggregate->includeFile()) generateRequisite("Header", *aggregate->includeFile());
2310
2311 // Since and project.
2312 if (!aggregate->since().isEmpty())
2313 generateRequisite("Since", formatSince(aggregate));
2314
2315 if (aggregate->isClassNode() || aggregate->isNamespace()) {
2316 // CMake and QT variable.
2317 const CollectionNode *cn =
2318 m_qdb->getCollectionNode(aggregate->physicalModuleName(), NodeType::Module);
2319
2320 if (const auto result = cmakeRequisite(cn)) {
2321 generateCMakeRequisite(result->first, result->second);
2322 }
2323
2324 if (cn && !cn->qtVariable().isEmpty())
2325 generateRequisite("qmake", "QT += " + cn->qtVariable());
2326 }
2327
2328 if (aggregate->nodeType() == NodeType::Class) {
2329 // Native type information.
2330 auto *classe = const_cast<ClassNode *>(static_cast<const ClassNode *>(aggregate));
2331 if (classe && classe->isQmlNativeType() && !classe->isInternal()) {
2332 generateStartRequisite("In QML");
2333
2334 qsizetype idx{0};
2335 QList<QmlTypeNode *> nativeTypes { classe->qmlNativeTypes().cbegin(), classe->qmlNativeTypes().cend()};
2336 std::sort(nativeTypes.begin(), nativeTypes.end(), Node::nodeNameLessThan);
2337
2338 for (const auto &item : std::as_const(nativeTypes)) {
2339 generateFullName(item, classe);
2340 m_writer->writeCharacters(
2341 TextUtils::comma(idx++, nativeTypes.size()));
2342 }
2343 generateEndRequisite();
2344 }
2345
2346 // Inherits.
2347 QList<RelatedClass>::ConstIterator r;
2348 const auto *metaTags = classe ? classe->doc().metaTagMap() : nullptr;
2349 bool suppressInherits = metaTags && metaTags->contains(u"qdoc-suppress-inheritance"_s);
2350 if (classe && !suppressInherits && !classe->baseClasses().isEmpty()) {
2351 generateStartRequisite("Inherits");
2352
2353 r = classe->baseClasses().constBegin();
2354 int index = 0;
2355 while (r != classe->baseClasses().constEnd()) {
2356 if ((*r).m_node) {
2357 generateFullName((*r).m_node, classe);
2358
2359 if ((*r).m_access == Access::Protected)
2360 m_writer->writeCharacters(" (protected)");
2361 else if ((*r).m_access == Access::Private)
2362 m_writer->writeCharacters(" (private)");
2363 m_writer->writeCharacters(
2364 TextUtils::comma(index++, classe->baseClasses().size()));
2365 }
2366 ++r;
2367 }
2368
2369 generateEndRequisite();
2370 }
2371
2372 // Inherited by.
2373 if (!classe->derivedClasses().isEmpty()) {
2374 generateStartRequisite("Inherited By");
2375 generateSortedNames(classe, classe->derivedClasses());
2376 generateEndRequisite();
2377 }
2378 }
2379
2380 // Group.
2381 if (!aggregate->groupNames().empty()) {
2382 generateStartRequisite("Group");
2383 generateGroupReferenceText(aggregate);
2384 generateEndRequisite();
2385 }
2386
2387 // Status.
2388 if (auto status = formatStatus(aggregate, m_qdb); status)
2389 generateRequisite("Status", status.value());
2390
2391 // Write the elements as a list if not empty.
2392 delete m_writer;
2393 m_writer = oldWriter;
2394
2395 if (!output.isEmpty()) {
2396 // Namespaces are mangled in this output, because QXmlStreamWriter doesn't know about them. (Letting it know
2397 // would imply generating the xmlns declaration one more time.)
2398 static const QRegularExpression xmlTag(R"(<(/?)n\d+:)"); // Only for DocBook tags.
2399 static const QRegularExpression xmlnsDocBookDefinition(R"( xmlns:n\d+=")" + QString{dbNamespace} + "\"");
2400 static const QRegularExpression xmlnsXLinkDefinition(R"( xmlns:n\d+=")" + QString{xlinkNamespace} + "\"");
2401 static const QRegularExpression xmlAttr(R"( n\d+:)"); // Only for XLink attributes.
2402 // Space at the beginning!
2403 const QString cleanOutput = output.replace(xmlTag, R"(<\1db:)")
2404 .replace(xmlnsDocBookDefinition, "")
2405 .replace(xmlnsXLinkDefinition, "")
2406 .replace(xmlAttr, " xlink:");
2407
2408 m_writer->writeStartElement(dbNamespace, "variablelist");
2409 if (m_useITS)
2410 m_writer->writeAttribute(itsNamespace, "translate", "no");
2411 newLine();
2412
2413 m_writer->device()->write(cleanOutput.toUtf8());
2414
2415 m_writer->writeEndElement(); // variablelist
2416 newLine();
2417 }
2418}
2419
2420/*!
2421 Lists the required imports and includes.
2422*/
2424{
2425 // From HtmlGenerator::generateQmlRequisites, but simplified: no need to store all the elements,
2426 // they can be produced one by one and still keep the right order.
2427 if (!qcn)
2428 return;
2429
2430 const QString importText = "Import Statement";
2431 const QString sinceText = "Since";
2432 const QString inheritedByText = "Inherited By";
2433 const QString inheritsText = "Inherits";
2434 const QString nativeTypeText = "In C++";
2435 const QString groupText = "Group";
2436 const QString statusText = "Status";
2437
2438 const CollectionNode *collection = qcn->logicalModule();
2439
2440 NodeList subs;
2441 QmlTypeNode::subclasses(qcn, subs);
2442
2443 QmlTypeNode *base = qcn->qmlBaseNode();
2444 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
2445 while (base) {
2446 const NodeContext context = base->createContext();
2447 if (InclusionFilter::isIncluded(policy, context))
2448 break;
2449 base = base->qmlBaseNode();
2450 }
2451
2452 // Skip import statement for \internal collections
2453 bool generate_import_statement = !qcn->logicalModuleName().isEmpty();
2454 if (generate_import_statement && collection) {
2455 const NodeContext context = collection->createContext();
2456 generate_import_statement = InclusionFilter::isIncluded(policy, context);
2457 }
2458 // Detect if anything is generated in this method. If not, exit early to avoid having an empty list.
2459 const bool generates_something = generate_import_statement || !qcn->since().isEmpty() || !subs.isEmpty() || base;
2460
2461 if (!generates_something)
2462 return;
2463
2464 QStringList knownTypeNames{qcn->name()};
2465 if (base)
2466 knownTypeNames << base->name();
2467
2468 // Start writing the elements as a list.
2469 m_writer->writeStartElement(dbNamespace, "variablelist");
2470 if (m_useITS)
2471 m_writer->writeAttribute(itsNamespace, "translate", "no");
2472 newLine();
2473
2474 if (generate_import_statement) {
2475 QStringList parts = QStringList() << "import" << qcn->logicalModuleName() << qcn->logicalModuleVersion();
2476 generateRequisite(importText, parts.join(' ').trimmed());
2477 }
2478
2479 // Since and project.
2480 if (!qcn->since().isEmpty())
2481 generateRequisite(sinceText, formatSince(qcn));
2482
2483 // Native type information.
2484 ClassNode *cn = (const_cast<QmlTypeNode *>(qcn))->classNode();
2485 if (cn && cn->isQmlNativeType() && !cn->isInternal()) {
2486 generateStartRequisite(nativeTypeText);
2487 generateSimpleLink(fullDocumentLocation(cn), cn->name());
2488 generateEndRequisite();
2489 }
2490
2491 // Inherits.
2492 if (base) {
2493 generateStartRequisite(inheritsText);
2494 generateSimpleLink(fullDocumentLocation(base), base->name());
2495 // Disambiguate with '(<QML module name>)' if there are clashing type names
2496 for (const auto sub : std::as_const(subs)) {
2497 if (knownTypeNames.contains(sub->name())) {
2498 m_writer->writeCharacters(" (%1)"_L1.arg(base->logicalModuleName()));
2499 break;
2500 }
2501 }
2502 generateEndRequisite();
2503 }
2504
2505 // Inherited by.
2506 if (!subs.isEmpty()) {
2507 generateStartRequisite(inheritedByText);
2508 generateSortedQmlNames(qcn, knownTypeNames, subs);
2509 generateEndRequisite();
2510 }
2511
2512 // Group.
2513 if (!qcn->groupNames().empty()) {
2514 generateStartRequisite(groupText);
2516 generateEndRequisite();
2517 }
2518
2519 // Status.
2520 if (auto status = formatStatus(qcn, m_qdb); status)
2521 generateRequisite(statusText, status.value());
2522
2523 m_writer->writeEndElement(); // variablelist
2524 newLine();
2525}
2526
2528{
2529 // From Generator::generateStatus.
2530 const auto *shared = node->isSharedCommentNode()
2531 ? static_cast<const SharedCommentNode *>(node) : nullptr;
2532 const bool plural = shared && !shared->isPropertyGroup() && shared->collective().size() > 1;
2533 const QString subject = plural
2534 ? "These "_L1 + NodeText::nodeTypeDescription(shared->collective().first(), NodeText::GrammaticalNumber::Plural) + " are"_L1
2535 : "This "_L1 + NodeText::nodeTypeDescription(node) + " is"_L1;
2536
2537 switch (node->status()) {
2538 case Status::Active:
2539 // Output the module 'state' description if set.
2540 if (node->isModule() || node->isQmlModule()) {
2541 const QString &state = static_cast<const CollectionNode*>(node)->state();
2542 if (!state.isEmpty()) {
2543 m_writer->writeStartElement(dbNamespace, "para");
2544 m_writer->writeCharacters("This " + NodeText::nodeTypeDescription(node) + " is in ");
2545 m_writer->writeStartElement(dbNamespace, "emphasis");
2546 m_writer->writeCharacters(state);
2547 m_writer->writeEndElement(); // emphasis
2548 m_writer->writeCharacters(" state.");
2549 m_writer->writeEndElement(); // para
2550 newLine();
2551 return true;
2552 }
2553 }
2554 if (const auto &version = node->deprecatedSince(); !version.isEmpty()) {
2555 m_writer->writeStartElement(dbNamespace, "para");
2556 m_writer->writeCharacters(subject
2557 + " scheduled for deprecation in version "
2558 + version + ".");
2559 if (const Text reason = node->doc().deprecationText(); !reason.isEmpty()) {
2560 m_writer->writeCharacters(" "_L1);
2561 generateText(reason, node);
2562 }
2563 m_writer->writeEndElement(); // para
2564 newLine();
2565 return true;
2566 }
2567 return false;
2568 case Status::Preliminary:
2569 m_writer->writeStartElement(dbNamespace, "para");
2570 m_writer->writeStartElement(dbNamespace, "emphasis");
2571 m_writer->writeAttribute("role", "bold");
2572 m_writer->writeCharacters(
2573 Config::instance()
2574 .get(CONFIG_PRELIMINARY + Config::dot + CONFIG_DESCRIPTION)
2575 .asString()
2576 .replace('\1'_L1, NodeText::nodeTypeDescription(node)));
2577 m_writer->writeEndElement(); // emphasis
2578 m_writer->writeEndElement(); // para
2579 newLine();
2580 return true;
2581 case Status::Deprecated:
2582 m_writer->writeStartElement(dbNamespace, "para");
2583 if (node->isAggregate()) {
2584 m_writer->writeStartElement(dbNamespace, "emphasis");
2585 m_writer->writeAttribute("role", "bold");
2586 }
2587 m_writer->writeCharacters(subject + " deprecated");
2588 if (const QString &version = node->deprecatedSince(); !version.isEmpty()) {
2589 m_writer->writeCharacters(" since ");
2590 if (node->isQmlNode() && !node->logicalModuleName().isEmpty())
2591 m_writer->writeCharacters(node->logicalModuleName() + " ");
2592 m_writer->writeCharacters(version);
2593 }
2594 m_writer->writeCharacters(". We strongly advise against using "
2595 + (plural ? "them"_L1 : "it"_L1) + " in new code.");
2596 if (node->isAggregate())
2597 m_writer->writeEndElement(); // emphasis
2598 if (const Text reason = node->doc().deprecationText(); !reason.isEmpty()) {
2599 m_writer->writeCharacters(" "_L1);
2600 generateText(reason, node);
2601 }
2602 m_writer->writeEndElement(); // para
2603 newLine();
2604 return true;
2605 case Status::Internal:
2607 default:
2608 return false;
2609 }
2610}
2611
2612/*!
2613 Generate a list of function signatures. The function nodes
2614 are in \a nodes.
2615 */
2616void DocBookGenerator::generateSignatureList(const NodeList &nodes)
2617{
2618 // From Generator::signatureList and Generator::appendSignature.
2619 m_writer->writeStartElement(dbNamespace, "itemizedlist");
2620 newLine();
2621
2622 NodeList::ConstIterator n = nodes.constBegin();
2623 while (n != nodes.constEnd()) {
2624 m_writer->writeStartElement(dbNamespace, "listitem");
2625 newLine();
2626 m_writer->writeStartElement(dbNamespace, "para");
2627
2628 generateSimpleLink(currentGenerator()->fullDocumentLocation(*n),
2629 (*n)->signature(Node::SignaturePlain));
2630
2631 m_writer->writeEndElement(); // para
2632 newLine();
2633 m_writer->writeEndElement(); // itemizedlist
2634 newLine();
2635 ++n;
2636 }
2637
2638 m_writer->writeEndElement(); // itemizedlist
2639 newLine();
2640}
2641
2642/*!
2643 * Return a string representing a text that exposes information about
2644 * the groups that the \a node is part of.
2645 */
2647{
2648 // From HtmlGenerator::groupReferenceText
2649
2650 if (!node->isAggregate())
2651 return;
2652 const auto aggregate = static_cast<const Aggregate *>(node);
2653
2654 const QStringList &groups_names{aggregate->groupNames()};
2655 if (!groups_names.empty()) {
2656 m_writer->writeCharacters(aggregate->name() + " is part of ");
2657 m_writer->writeStartElement(dbNamespace, "simplelist");
2658
2659 for (qsizetype index{0}; index < groups_names.size(); ++index) {
2660 CollectionNode* group{m_qdb->groups()[groups_names[index]]};
2661 m_qdb->mergeCollections(group);
2662
2663 m_writer->writeStartElement(dbNamespace, "member");
2664 if (QString target{linkForNode(group, nullptr)}; !target.isEmpty())
2665 generateSimpleLink(target, group->fullTitle());
2666 else
2667 m_writer->writeCharacters(group->name());
2668 m_writer->writeEndElement(); // member
2669 }
2670
2671 m_writer->writeEndElement(); // simplelist
2672 newLine();
2673 }
2674}
2675
2676/*!
2677 Generates text that explains how threadsafe and/or reentrant
2678 \a node is.
2679 */
2681{
2682 // From Generator::generateThreadSafeness
2684
2685 const Node *reentrantNode;
2686 Atom reentrantAtom = Atom(Atom::Link, "reentrant");
2687 QString linkReentrant = getAutoLink(&reentrantAtom, node, &reentrantNode);
2688 const Node *threadSafeNode;
2689 Atom threadSafeAtom = Atom(Atom::Link, "thread-safe");
2690 QString linkThreadSafe = getAutoLink(&threadSafeAtom, node, &threadSafeNode);
2691
2692 if (ts == Node::NonReentrant) {
2693 m_writer->writeStartElement(dbNamespace, "warning");
2694 newLine();
2695 m_writer->writeStartElement(dbNamespace, "para");
2696 m_writer->writeCharacters("This " + NodeText::nodeTypeDescription(node) + " is not ");
2697 generateSimpleLink(linkReentrant, "reentrant");
2698 m_writer->writeCharacters(".");
2699 m_writer->writeEndElement(); // para
2700 newLine();
2701 m_writer->writeEndElement(); // warning
2702
2703 return true;
2704 } else if (ts == Node::Reentrant || ts == Node::ThreadSafe) {
2705 m_writer->writeStartElement(dbNamespace, "note");
2706 newLine();
2707 m_writer->writeStartElement(dbNamespace, "para");
2708
2709 if (node->isAggregate()) {
2710 m_writer->writeCharacters("All functions in this " + NodeText::nodeTypeDescription(node) + " are ");
2711 if (ts == Node::ThreadSafe)
2712 generateSimpleLink(linkThreadSafe, "thread-safe");
2713 else
2714 generateSimpleLink(linkReentrant, "reentrant");
2715
2716 NodeList reentrant;
2717 NodeList threadsafe;
2718 NodeList nonreentrant;
2719 bool exceptions = hasExceptions(node, reentrant, threadsafe, nonreentrant);
2720 if (!exceptions || (ts == Node::Reentrant && !threadsafe.isEmpty())) {
2721 m_writer->writeCharacters(".");
2722 m_writer->writeEndElement(); // para
2723 newLine();
2724 } else {
2725 m_writer->writeCharacters(" with the following exceptions:");
2726 m_writer->writeEndElement(); // para
2727 newLine();
2728 m_writer->writeStartElement(dbNamespace, "para");
2729
2730 if (ts == Node::Reentrant) {
2731 if (!nonreentrant.isEmpty()) {
2732 m_writer->writeCharacters("These functions are not ");
2733 generateSimpleLink(linkReentrant, "reentrant");
2734 m_writer->writeCharacters(":");
2735 m_writer->writeEndElement(); // para
2736 newLine();
2737 generateSignatureList(nonreentrant);
2738 }
2739 if (!threadsafe.isEmpty()) {
2740 m_writer->writeCharacters("These functions are also ");
2741 generateSimpleLink(linkThreadSafe, "thread-safe");
2742 m_writer->writeCharacters(":");
2743 m_writer->writeEndElement(); // para
2744 newLine();
2745 generateSignatureList(threadsafe);
2746 }
2747 } else { // thread-safe
2748 if (!reentrant.isEmpty()) {
2749 m_writer->writeCharacters("These functions are only ");
2750 generateSimpleLink(linkReentrant, "reentrant");
2751 m_writer->writeCharacters(":");
2752 m_writer->writeEndElement(); // para
2753 newLine();
2754 generateSignatureList(reentrant);
2755 }
2756 if (!nonreentrant.isEmpty()) {
2757 m_writer->writeCharacters("These functions are not ");
2758 generateSimpleLink(linkReentrant, "reentrant");
2759 m_writer->writeCharacters(":");
2760 m_writer->writeEndElement(); // para
2761 newLine();
2762 generateSignatureList(nonreentrant);
2763 }
2764 }
2765 }
2766 } else {
2767 m_writer->writeCharacters("This " + NodeText::nodeTypeDescription(node) + " is ");
2768 if (ts == Node::ThreadSafe)
2769 generateSimpleLink(linkThreadSafe, "thread-safe");
2770 else
2771 generateSimpleLink(linkReentrant, "reentrant");
2772 m_writer->writeCharacters(".");
2773 m_writer->writeEndElement(); // para
2774 newLine();
2775 }
2776 m_writer->writeEndElement(); // note
2777 newLine();
2778
2779 return true;
2780 }
2781
2782 return false;
2783}
2784
2785/*!
2786 Generate the body of the documentation from the qdoc comment
2787 found with the entity represented by the \a node.
2788 */
2790{
2791 // From Generator::generateBody, without warnings.
2792 const FunctionNode *fn = node->isFunction() ? static_cast<const FunctionNode *>(node) : nullptr;
2793
2794 if (!node->hasDoc()) {
2795 /*
2796 Test for special function, like a destructor or copy constructor,
2797 that has no documentation.
2798 */
2799 if (fn) {
2800 QString t;
2801 if (fn->isDtor()) {
2802 t = "Destroys the instance of " + fn->parent()->name() + ".";
2803 if (fn->isVirtual())
2804 t += " The destructor is virtual.";
2805 } else if (fn->isCtor()) {
2806 t = "Default constructs an instance of " + fn->parent()->name() + ".";
2807 } else if (fn->isCCtor()) {
2808 t = "Copy constructor.";
2809 } else if (fn->isMCtor()) {
2810 t = "Move-copy constructor.";
2811 } else if (fn->isCAssign()) {
2812 t = "Copy-assignment constructor.";
2813 } else if (fn->isMAssign()) {
2814 t = "Move-assignment constructor.";
2815 }
2816
2817 if (!t.isEmpty())
2818 m_writer->writeTextElement(dbNamespace, "para", t);
2819 }
2820 } else if (!node->isSharingComment()) {
2821 // Reimplements clause and type alias info precede body text
2822 if (fn && !fn->overridesThis().isEmpty())
2823 generateReimplementsClause(fn);
2824 else if (node->isProperty()) {
2825 if (static_cast<const PropertyNode *>(node)->propertyType() != PropertyNode::PropertyType::StandardProperty)
2827 }
2828
2829 // Generate the body.
2830 if (!generateText(node->doc().body(), node)) {
2831 if (node->isMarkedReimp())
2832 return;
2833 }
2834
2835 // Output what is after the main body.
2836 if (fn) {
2837 if (fn->isQmlSignal())
2839 if (fn->isPrivateSignal())
2841 if (fn->isInvokable())
2845 if (fn->hasOverloads() && fn->doc().hasOverloadCommand()
2846 && !fn->isSignal() && !fn->isSlot())
2848 }
2849
2850 // Warning generation skipped with respect to Generator::generateBody.
2851 }
2852
2853 generateEnumValuesForQmlReference(node, nullptr);
2854 generateRequiredLinks(node);
2855}
2856
2857/*!
2858 Generates either a link to the project folder for example \a node, or a list
2859 of links files/images if 'url.examples config' variable is not defined.
2860
2861 Does nothing for non-example nodes.
2862*/
2863void DocBookGenerator::generateRequiredLinks(const Node *node)
2864{
2865 // From Generator::generateRequiredLinks.
2866 if (!node->isExample())
2867 return;
2868
2869 const auto en = static_cast<const ExampleNode *>(node);
2870 QString exampleUrl{Config::instance().get(CONFIG_URL + Config::dot + CONFIG_EXAMPLES).asString()};
2871
2872 if (exampleUrl.isEmpty()) {
2873 if (!en->noAutoList()) {
2874 generateFileList(en, false); // files
2875 generateFileList(en, true); // images
2876 }
2877 } else {
2878 generateLinkToExample(en, exampleUrl);
2879 }
2880}
2881
2882/*!
2883 The path to the example replaces a placeholder '\1' character if
2884 one is found in the \a baseUrl string. If no such placeholder is found,
2885 the path is appended to \a baseUrl, after a '/' character if \a baseUrl did
2886 not already end in one.
2887*/
2888void DocBookGenerator::generateLinkToExample(const ExampleNode *en, const QString &baseUrl)
2889{
2890 // From Generator::generateLinkToExample.
2891 QString exampleUrl(baseUrl);
2892 QString link;
2893#ifndef QT_BOOTSTRAPPED
2894 link = QUrl(exampleUrl).host();
2895#endif
2896 if (!link.isEmpty())
2897 link.prepend(" @ ");
2898 link.prepend("Example project");
2899
2900 const QLatin1Char separator('/');
2901 const QLatin1Char placeholder('\1');
2902 if (!exampleUrl.contains(placeholder)) {
2903 if (!exampleUrl.endsWith(separator))
2904 exampleUrl += separator;
2905 exampleUrl += placeholder;
2906 }
2907
2908 // Construct a path to the example; <install path>/<example name>
2909 QStringList path = QStringList()
2910 << Config::instance().get(CONFIG_EXAMPLESINSTALLPATH).asString() << en->name();
2911 path.removeAll(QString());
2912
2913 // Write the link to the example. Typically, this link comes after sections, hence
2914 // wrap it in a section too.
2915 startSection("Example project");
2916
2917 m_writer->writeStartElement(dbNamespace, "para");
2918 generateSimpleLink(exampleUrl.replace(placeholder, path.join(separator)), link);
2919 m_writer->writeEndElement(); // para
2920 newLine();
2921
2922 endSection();
2923}
2924
2925// TODO: [multi-purpose-function-with-flag][generate-file-list]
2926
2927/*!
2928 This function is called when the documentation for an example is
2929 being formatted. It outputs a list of files for the example, which
2930 can be the example's source files or the list of images used by the
2931 example. The images are copied into a subtree of
2932 \c{...doc/html/images/used-in-examples/...}
2933*/
2934void DocBookGenerator::generateFileList(const ExampleNode *en, bool images)
2935{
2936 // TODO: [possibly-stale-duplicate-code][generator-insufficient-structural-abstraction]
2937 // Review and compare this code with
2938 // Generator::generateFileList.
2939 // Some subtle changes that might be semantically equivalent are
2940 // present between the two.
2941 // Supposedly, this version is to be considered stale compared to
2942 // Generator's one and it might be possible to remove it in favor
2943 // of that as long as the difference in output are taken into consideration.
2944
2945 // From Generator::generateFileList
2946 QString tag;
2947 QStringList paths;
2948 if (images) {
2949 paths = en->images();
2950 tag = "Images:";
2951 } else { // files
2952 paths = en->files();
2953 tag = "Files:";
2954 }
2955 std::sort(paths.begin(), paths.end(), Generator::comparePaths);
2956
2957 if (paths.isEmpty())
2958 return;
2959
2960 startSection("", "List of Files");
2961
2962 m_writer->writeStartElement(dbNamespace, "para");
2963 m_writer->writeCharacters(tag);
2964 m_writer->writeEndElement(); // para
2965 newLine();
2966
2967 startSection("List of Files");
2968
2969 m_writer->writeStartElement(dbNamespace, "itemizedlist");
2970 newLine();
2971
2972 for (const auto &path : std::as_const(paths)) {
2973 auto maybe_resolved_file{file_resolver.resolve(path)};
2974 if (!maybe_resolved_file) {
2975 // TODO: [uncentralized-admonition][failed-resolve-file]
2976 QString details = std::transform_reduce(
2977 file_resolver.get_search_directories().cbegin(),
2978 file_resolver.get_search_directories().cend(),
2979 u"Searched directories:"_s,
2980 std::plus(),
2981 [](const DirectoryPath &directory_path) -> QString { return u' ' + directory_path.value(); }
2982 );
2983
2984 en->location().warning(u"Cannot find file to quote from: %1"_s.arg(path), details);
2985
2986 continue;
2987 }
2988
2989 const auto &file{*maybe_resolved_file};
2990 if (images) addImageToCopy(en, file);
2991 else generateExampleFilePage(en, file);
2992
2993 m_writer->writeStartElement(dbNamespace, "listitem");
2994 newLine();
2995 m_writer->writeStartElement(dbNamespace, "para");
2996 generateSimpleLink(file.get_query(), file.get_query());
2997 m_writer->writeEndElement(); // para
2998 m_writer->writeEndElement(); // listitem
2999 newLine();
3000 }
3001
3002 m_writer->writeEndElement(); // itemizedlist
3003 newLine();
3004
3005 endSection();
3006}
3007
3008/*!
3009 Generate a file with the contents of a C++ or QML source file.
3010 */
3012{
3013 // TODO: [generator-insufficient-structural-abstraction]
3014
3015 // From HtmlGenerator::generateExampleFilePage.
3016 if (!node->isExample())
3017 return;
3018
3019 // TODO: Understand if this is safe.
3020 const auto en = static_cast<const ExampleNode *>(node);
3021
3022 // Store current (active) writer
3023 QXmlStreamWriter *currentWriter = m_writer;
3024 m_writer = startDocument(en, resolved_file.get_query());
3025 generateHeader(en->doc().title(), en->subtitle(), en);
3026
3027 Text text;
3028 Quoter quoter;
3029 Doc::quoteFromFile(en->doc().location(), quoter, resolved_file);
3030 QString code = quoter.quoteTo(en->location(), QString(), QString());
3031 CodeMarker *codeMarker = CodeMarker::markerForFileName(resolved_file.get_path());
3032 text << Atom(codeMarker->atomType(), code);
3033 Atom a(codeMarker->atomType(), code);
3034 generateText(text, en);
3035
3036 endDocument(); // Delete m_writer.
3037 m_writer = currentWriter; // Restore writer.
3038}
3039
3040void DocBookGenerator::generateReimplementsClause(const FunctionNode *fn)
3041{
3042 // From Generator::generateReimplementsClause, without warning generation.
3043 if (fn->overridesThis().isEmpty() || !fn->parent()->isClassNode())
3044 return;
3045
3046 auto cn = static_cast<ClassNode *>(fn->parent());
3047
3048 if (const FunctionNode *overrides = cn->findOverriddenFunction(fn);
3049 overrides && !overrides->isPrivate() && !overrides->parent()->isPrivate()) {
3050 if (overrides->hasDoc()) {
3051 m_writer->writeStartElement(dbNamespace, "para");
3052 m_writer->writeCharacters("Reimplements: ");
3053 QString fullName =
3054 overrides->parent()->name() + "::" + overrides->signature(Node::SignaturePlain);
3055 generateFullName(overrides->parent(), fullName, overrides);
3056 m_writer->writeCharacters(".");
3057 m_writer->writeEndElement(); // para
3058 newLine();
3059 return;
3060 }
3061 }
3062
3063 if (const PropertyNode *sameName = cn->findOverriddenProperty(fn); sameName && sameName->hasDoc()) {
3064 m_writer->writeStartElement(dbNamespace, "para");
3065 m_writer->writeCharacters("Reimplements an access function for property: ");
3066 QString fullName = sameName->parent()->name() + "::" + sameName->name();
3067 generateFullName(sameName->parent(), fullName, sameName);
3068 m_writer->writeCharacters(".");
3069 m_writer->writeEndElement(); // para
3070 newLine();
3071 return;
3072 }
3073}
3074
3076{
3077 // From Generator::generateAlsoList.
3078 QList<Text> alsoList = node->doc().alsoList();
3079 supplementAlsoList(node, alsoList);
3080
3081 if (!alsoList.isEmpty()) {
3082 startSection("See Also");
3083
3084 m_writer->writeStartElement(dbNamespace, "para");
3085 m_writer->writeStartElement(dbNamespace, "emphasis");
3086 m_writer->writeCharacters("See also ");
3087 m_writer->writeEndElement(); // emphasis
3088 newLine();
3089
3090 m_writer->writeStartElement(dbNamespace, "simplelist");
3091 m_writer->writeAttribute("type", "vert");
3092 m_writer->writeAttribute("role", "see-also");
3093 newLine();
3094
3095 for (const Text &text : alsoList) {
3096 m_writer->writeStartElement(dbNamespace, "member");
3097 generateText(text, node);
3098 m_writer->writeEndElement(); // member
3099 newLine();
3100 }
3101
3102 m_writer->writeEndElement(); // simplelist
3103 newLine();
3104
3105 m_writer->writeEndElement(); // para
3106 newLine();
3107
3108 endSection();
3109 }
3110}
3111
3112/*!
3113 Open a new file to write XML contents, including the DocBook
3114 opening tag.
3115 */
3116QXmlStreamWriter *DocBookGenerator::startGenericDocument(const Node *node, const QString &fileName)
3117{
3118 Q_ASSERT(node->isPageNode());
3119 QFile *outFile = openSubPageFile(static_cast<const PageNode*>(node), fileName);
3120 m_writer = new QXmlStreamWriter(outFile);
3121 m_writer->setAutoFormatting(false); // We need a precise handling of line feeds.
3122
3123 m_writer->writeStartDocument();
3124 newLine();
3125 m_writer->writeNamespace(dbNamespace, "db");
3126 m_writer->writeNamespace(xlinkNamespace, "xlink");
3127 if (m_useITS)
3128 m_writer->writeNamespace(itsNamespace, "its");
3129 m_writer->writeStartElement(dbNamespace, "article");
3130 m_writer->writeAttribute("version", "5.2");
3131 if (!m_naturalLanguage.isEmpty())
3132 m_writer->writeAttribute("xml:lang", m_naturalLanguage);
3133 newLine();
3134
3135 // Reset the state for the new document.
3136 sectionLevels.resize(0);
3137 m_inPara = false;
3138 m_inList = 0;
3139
3140 return m_writer;
3141}
3142
3143QXmlStreamWriter *DocBookGenerator::startDocument(const Node *node)
3144{
3145 m_hasSection = false;
3146 refMap.clear();
3147
3148 QString fileName = Generator::fileName(node, fileExtension());
3149 return startGenericDocument(node, fileName);
3150}
3151
3152QXmlStreamWriter *DocBookGenerator::startDocument(const ExampleNode *en, const QString &file)
3153{
3154 m_hasSection = false;
3155
3156 QString fileName = linkForExampleFile(file);
3157 return startGenericDocument(en, fileName);
3158}
3159
3160void DocBookGenerator::endDocument()
3161{
3162 m_writer->writeEndElement(); // article
3163 m_writer->writeEndDocument();
3164
3165 m_writer->device()->close();
3166 delete m_writer->device();
3167 delete m_writer;
3168 m_writer = nullptr;
3169}
3170
3171/*!
3172 Generate a reference page for the C++ class, namespace, or
3173 header file documented in \a node.
3174 */
3176{
3177 // Based on HtmlGenerator::generateCppReferencePage.
3178 Q_ASSERT(node->isAggregate());
3179 const auto aggregate = static_cast<const Aggregate *>(node);
3180
3181 QString title;
3182 Text titleText;
3183 const QString typeWord{aggregate->typeWord(true)};
3184 if (aggregate->isNamespace()) {
3185 title = "%1 %2"_L1.arg(aggregate->plainFullName(), typeWord);
3186 } else if (aggregate->isClass()) {
3187 title = "%1 %2"_L1.arg(aggregate->plainFullName(), typeWord);
3188 } else if (aggregate->isHeader()) {
3189 title = aggregate->fullTitle();
3190 if (!aggregate->doc().title().isEmpty())
3191 titleText << aggregate->name() << " - "_L1 << aggregate->doc().title();
3192 }
3193
3194 // Start producing the DocBook file.
3195 m_writer = startDocument(node);
3196
3197 // Info container. Class pages with a template declaration emit the
3198 // subtitle in two steps so concept references in the template head
3199 // can surface as <db:link> elements inside the subtitle text rather
3200 // than being flattened to characters.
3201 if (aggregate->isClass()) {
3202 if (auto templateDecl = node->templateDecl()) {
3203 if (!titleText.isEmpty())
3204 generateHeader(titleText, aggregate);
3205 else
3206 generateHeader(Text() << title, aggregate);
3207
3208 m_writer->writeStartElement(dbNamespace, "subtitle");
3209 if (isApiGenus(aggregate->genus()) && m_useITS)
3210 m_writer->writeAttribute(itsNamespace, "translate", "no");
3211 generateTemplateDecl(&*templateDecl, aggregate);
3212 m_writer->writeCharacters(" "_L1 + aggregate->typeWord(false) + " "_L1
3213 + aggregate->plainFullName());
3214 m_writer->writeEndElement(); // subtitle
3215 newLine();
3216
3217 finishHeader(aggregate);
3218 } else {
3219 if (!titleText.isEmpty())
3220 generateHeader(titleText, QString(), aggregate);
3221 else
3222 generateHeader(title, QString(), aggregate);
3223 }
3224 } else {
3225 if (!titleText.isEmpty())
3226 generateHeader(titleText, QString(), aggregate);
3227 else
3228 generateHeader(title, QString(), aggregate);
3229 }
3230
3231 generateRequisites(aggregate);
3232 generateStatus(aggregate);
3233
3234 // Element synopsis.
3236
3237 // Actual content.
3238 if (!aggregate->doc().isEmpty()) {
3239 startSection("details", "Detailed Description");
3240
3241 generateBody(aggregate);
3242 generateAlsoList(aggregate);
3243
3244 endSection();
3245 }
3246
3247 Sections sections(aggregate);
3248 const SectionVector &sectionVector = sections.detailsSections();
3249 for (const Section &section : sectionVector) {
3250 if (section.members().isEmpty())
3251 continue;
3252
3253 startSection(section.title().toLower(), section.title());
3254
3255 for (const Node *member : section.members()) {
3256 if (member->nodeType() != NodeType::Class) {
3257 // This function starts its own section.
3258 generateDetailedMember(member, aggregate);
3259 } else {
3260 startSectionBegin();
3261 m_writer->writeCharacters("class ");
3262 generateFullName(member, aggregate);
3263 startSectionEnd();
3264
3265 generateBrief(member);
3266
3267 endSection();
3268 }
3269 }
3270
3271 endSection();
3272 }
3273
3274 generateObsoleteMembers(sections);
3275
3276 endDocument();
3277}
3278
3279void DocBookGenerator::generateSynopsisInfo(const QString &key, const QString &value)
3280{
3281 m_writer->writeStartElement(dbNamespace, "synopsisinfo");
3282 m_writer->writeAttribute("role", key);
3283 m_writer->writeCharacters(value);
3284 m_writer->writeEndElement(); // synopsisinfo
3285 newLine();
3286}
3287
3288void DocBookGenerator::generateModifier(const QString &value)
3289{
3290 m_writer->writeTextElement(dbNamespace, "modifier", value);
3291 newLine();
3292}
3293
3294/*!
3295 Generate the metadata for the given \a node in DocBook.
3296 */
3298{
3299 if (!node)
3300 return;
3301
3302 // From Generator::generateStatus, HtmlGenerator::generateRequisites,
3303 // Generator::generateThreadSafeness, QDocIndexFiles::generateIndexSection.
3304
3305 // This function is the major place where DocBook extensions are used.
3306 if (!m_useDocBook52)
3307 return;
3308
3309 // Nothing to export in some cases. Note that isSharedCommentNode() returns
3310 // true also for QML property groups.
3312 return;
3313
3314 // Cast the node to several subtypes (null pointer if the node is not of the required type).
3315 const Aggregate *aggregate =
3316 node->isAggregate() ? static_cast<const Aggregate *>(node) : nullptr;
3317 const ClassNode *classNode = node->isClass() ? static_cast<const ClassNode *>(node) : nullptr;
3318 const FunctionNode *functionNode =
3319 node->isFunction() ? static_cast<const FunctionNode *>(node) : nullptr;
3320 const PropertyNode *propertyNode =
3321 node->isProperty() ? static_cast<const PropertyNode *>(node) : nullptr;
3322 const VariableNode *variableNode =
3323 node->isVariable() ? static_cast<const VariableNode *>(node) : nullptr;
3324 const EnumNode *enumNode = node->isEnumType() ? static_cast<const EnumNode *>(node) : nullptr;
3325 const QmlPropertyNode *qpn =
3326 node->isQmlProperty() ? static_cast<const QmlPropertyNode *>(node) : nullptr;
3327 const QmlTypeNode *qcn = node->isQmlType() ? static_cast<const QmlTypeNode *>(node) : nullptr;
3328 // Typedefs are ignored, as they correspond to enums.
3329 // Groups and modules are ignored.
3330 // Documents are ignored, they have no interesting metadata.
3331
3332 // Start the synopsis tag.
3333 QString synopsisTag = nodeToSynopsisTag(node);
3334 m_writer->writeStartElement(dbNamespace, synopsisTag);
3335 newLine();
3336
3337 // Name and basic properties of each tag (like types and parameters).
3338 if (node->isClass()) {
3339 m_writer->writeStartElement(dbNamespace, "ooclass");
3340 m_writer->writeTextElement(dbNamespace, "classname", node->plainName());
3341 m_writer->writeEndElement(); // ooclass
3342 newLine();
3343 } else if (node->isNamespace()) {
3344 m_writer->writeTextElement(dbNamespace, "namespacename", node->plainName());
3345 newLine();
3346 } else if (node->isQmlType()) {
3347 m_writer->writeStartElement(dbNamespace, "ooclass");
3348 m_writer->writeTextElement(dbNamespace, "classname", node->plainName());
3349 m_writer->writeEndElement(); // ooclass
3350 newLine();
3351 if (!qcn->groupNames().isEmpty())
3352 m_writer->writeAttribute("groups", qcn->groupNames().join(QLatin1Char(',')));
3353 } else if (node->isProperty()) {
3354 m_writer->writeTextElement(dbNamespace, "modifier", "(Qt property)");
3355 newLine();
3356 m_writer->writeTextElement(dbNamespace, "type", propertyNode->dataType());
3357 newLine();
3358 m_writer->writeTextElement(dbNamespace, "varname", node->plainName());
3359 newLine();
3360 } else if (node->isVariable()) {
3361 if (variableNode->isStatic()) {
3362 m_writer->writeTextElement(dbNamespace, "modifier", "static");
3363 newLine();
3364 }
3365 m_writer->writeTextElement(dbNamespace, "type", variableNode->dataType());
3366 newLine();
3367 m_writer->writeTextElement(dbNamespace, "varname", node->plainName());
3368 newLine();
3369 } else if (node->isEnumType()) {
3370 if (!enumNode->isAnonymous()) {
3371 m_writer->writeTextElement(dbNamespace, "enumname", node->plainName());
3372 newLine();
3373 }
3374 } else if (node->isQmlProperty()) {
3375 QString name = node->name();
3376 if (qpn->isAttached())
3377 name.prepend(qpn->element() + QLatin1Char('.'));
3378
3379 m_writer->writeTextElement(dbNamespace, "type", qpn->dataType());
3380 newLine();
3381 m_writer->writeTextElement(dbNamespace, "varname", name);
3382 newLine();
3383
3384 const bool readOnly = qpn->isReadOnly();
3385 const bool required = qpn->isRequired();
3386
3387 // Semantic modifiers for DocBook (machine-readable)
3388 if (qpn->isAttached()) {
3389 m_writer->writeTextElement(dbNamespace, "modifier", "attached");
3390 newLine();
3391 }
3392 if (!readOnly) {
3393 m_writer->writeTextElement(dbNamespace, "modifier", "writable");
3394 newLine();
3395 }
3396 if (required) {
3397 m_writer->writeTextElement(dbNamespace, "modifier", "required");
3398 newLine();
3399 }
3400 // Presentation modifiers (human-readable)
3401 if (readOnly) {
3402 generateModifier("[read-only]");
3403 newLine();
3404 }
3405 if (qpn->isDefault()) {
3406 generateModifier("[default]");
3407 newLine();
3408 }
3409 } else if (node->isFunction()) {
3410 if (functionNode->virtualness() != "non")
3411 generateModifier("virtual");
3412 if (functionNode->isConst())
3413 generateModifier("const");
3414 if (functionNode->isStatic())
3415 generateModifier("static");
3416
3417 if (!functionNode->isMacro() && !functionNode->isCtor() &&
3418 !functionNode->isCCtor() && !functionNode->isMCtor()
3419 && !functionNode->isDtor()) {
3420 if (functionNode->returnType() == "void")
3421 m_writer->writeEmptyElement(dbNamespace, "void");
3422 else
3423 m_writer->writeTextElement(dbNamespace, "type", functionNode->returnTypeString());
3424 newLine();
3425 }
3426 // Remove two characters from the plain name to only get the name
3427 // of the method without parentheses (only for functions, not macros).
3428 QString name = node->plainName();
3429 if (name.endsWith("()"))
3430 name.chop(2);
3431 m_writer->writeTextElement(dbNamespace, "methodname", name);
3432 newLine();
3433
3434 if (functionNode->parameters().isEmpty()) {
3435 m_writer->writeEmptyElement(dbNamespace, "void");
3436 newLine();
3437 }
3438
3439 const Parameters &lp = functionNode->parameters();
3440 for (int i = 0; i < lp.count(); ++i) {
3441 const Parameter &parameter = lp.at(i);
3442 m_writer->writeStartElement(dbNamespace, "methodparam");
3443 newLine();
3444 m_writer->writeTextElement(dbNamespace, "type", parameter.type());
3445 newLine();
3446 m_writer->writeTextElement(dbNamespace, "parameter", parameter.name());
3447 newLine();
3448 if (!parameter.defaultValue().isEmpty()) {
3449 m_writer->writeTextElement(dbNamespace, "initializer", parameter.defaultValue());
3450 newLine();
3451 }
3452 m_writer->writeEndElement(); // methodparam
3453 newLine();
3454 }
3455
3456 if (functionNode->isImplicitlyGenerated())
3457 generateModifier("implicit");
3458 else if (functionNode->isExplicitlyDefaulted())
3459 generateModifier("default");
3460 else if (functionNode->isDeletedAsWritten())
3461 generateModifier("delete");
3462 if (functionNode->isFinal())
3463 generateModifier("final");
3464 if (functionNode->isOverride())
3465 generateModifier("override");
3466 } else if (node->isTypedef()) {
3467 m_writer->writeTextElement(dbNamespace, "typedefname", node->plainName());
3468 newLine();
3469 } else {
3470 node->doc().location().warning(
3471 QStringLiteral("Unexpected node type in generateDocBookSynopsis: %1")
3472 .arg(node->nodeTypeString()));
3473 newLine();
3474 }
3475
3476 // Enums and typedefs.
3477 if (enumNode) {
3478 for (const EnumItem &item : enumNode->items()) {
3479 m_writer->writeStartElement(dbNamespace, "enumitem");
3480 newLine();
3481 m_writer->writeTextElement(dbNamespace, "enumidentifier", item.name());
3482 newLine();
3483 m_writer->writeTextElement(dbNamespace, "enumvalue", item.value());
3484 newLine();
3485 m_writer->writeEndElement(); // enumitem
3486 newLine();
3487 }
3488
3489 if (enumNode->items().isEmpty()) {
3490 // If the enumeration is empty (really rare case), still produce
3491 // something for the DocBook document to be valid.
3492 m_writer->writeStartElement(dbNamespace, "enumitem");
3493 newLine();
3494 m_writer->writeEmptyElement(dbNamespace, "enumidentifier");
3495 newLine();
3496 m_writer->writeEndElement(); // enumitem
3497 newLine();
3498 }
3499 }
3500
3501 // Below: only synopsisinfo within synopsisTag. These elements must be at
3502 // the end of the tag, as per DocBook grammar.
3503
3504 // Information for functions that could not be output previously
3505 // (synopsisinfo).
3506 if (node->isFunction()) {
3507 generateSynopsisInfo("meta", functionNode->metanessString());
3508
3509 if (functionNode->isOverload()) {
3510 generateSynopsisInfo("overload", "overload");
3511 generateSynopsisInfo("overload-number",
3512 QString::number(functionNode->overloadNumber()));
3513 }
3514
3515 if (functionNode->isRef())
3516 generateSynopsisInfo("refness", QString::number(1));
3517 else if (functionNode->isRefRef())
3518 generateSynopsisInfo("refness", QString::number(2));
3519
3520 if (functionNode->hasAssociatedProperties()) {
3521 QStringList associatedProperties;
3522 const auto &nodes = functionNode->associatedProperties();
3523 for (const Node *n : nodes) {
3524 const auto pn = static_cast<const PropertyNode *>(n);
3525 associatedProperties << pn->name();
3526 }
3527 associatedProperties.sort();
3528 generateSynopsisInfo("associated-property",
3529 associatedProperties.join(QLatin1Char(',')));
3530 }
3531
3532 QString signature = functionNode->signature(Node::SignatureReturnType);
3533 // 'const' is already part of FunctionNode::signature()
3534 if (functionNode->isFinal())
3535 signature += " final";
3536 if (functionNode->isOverride())
3537 signature += " override";
3538 if (functionNode->isPureVirtual())
3539 signature += " = 0";
3540 else if (functionNode->isExplicitlyDefaulted())
3541 signature += " = default";
3542 else if (functionNode->isDeletedAsWritten())
3543 signature += " = delete";
3544 if (const auto &req = functionNode->trailingRequiresClause(); req && !req->isEmpty())
3545 signature += " requires " + *req;
3546 generateSynopsisInfo("signature", signature);
3547 }
3548
3549 // Accessibility status.
3550 if (!node->isPageNode() && !node->isCollectionNode()) {
3551 switch (node->access()) {
3552 case Access::Public:
3553 generateSynopsisInfo("access", "public");
3554 break;
3555 case Access::Protected:
3556 generateSynopsisInfo("access", "protected");
3557 break;
3558 case Access::Private:
3559 generateSynopsisInfo("access", "private");
3560 break;
3561 default:
3562 break;
3563 }
3564 if (node->isAbstract())
3565 generateSynopsisInfo("abstract", "true");
3566 }
3567
3568 // Status.
3569 switch (node->status()) {
3570 case Status::Active:
3571 generateSynopsisInfo("status", "active");
3572 break;
3573 case Status::Preliminary:
3574 generateSynopsisInfo("status",
3575 Config::instance().get(CONFIG_PRELIMINARY).asString().toLower());
3576 break;
3577 case Status::Deprecated:
3578 generateSynopsisInfo("status", "deprecated");
3579 break;
3580 case Status::Internal:
3581 case Status::InternalAuto:
3582 generateSynopsisInfo("status", "internal");
3583 break;
3584 default:
3585 generateSynopsisInfo("status", "main");
3586 break;
3587 }
3588
3589 // C++ classes and name spaces.
3590 if (aggregate) {
3591 // Includes.
3592 if (aggregate->includeFile()) generateSynopsisInfo("headers", *aggregate->includeFile());
3593
3594 // Since and project.
3595 if (!aggregate->since().isEmpty())
3596 generateSynopsisInfo("since", formatSince(aggregate));
3597
3598 if (aggregate->nodeType() == NodeType::Class || aggregate->nodeType() == NodeType::Namespace) {
3599 // CMake and QT variable.
3600 if (!aggregate->physicalModuleName().isEmpty()) {
3601 const CollectionNode *cn =
3602 m_qdb->getCollectionNode(aggregate->physicalModuleName(), NodeType::Module);
3603
3604 if (const auto result = cmakeRequisite(cn)) {
3605 generateSynopsisInfo("cmake-find-package", result->first);
3606 generateSynopsisInfo("cmake-target-link-libraries", result->second);
3607 }
3608
3609 if (cn && !cn->qtVariable().isEmpty())
3610 generateSynopsisInfo("qmake", "QT += " + cn->qtVariable());
3611 }
3612 }
3613
3614 if (aggregate->nodeType() == NodeType::Class) {
3615 // Native type
3616 auto *classe = const_cast<ClassNode *>(static_cast<const ClassNode *>(aggregate));
3617 if (classe && classe->isQmlNativeType() && !classe->isInternal()) {
3618 m_writer->writeStartElement(dbNamespace, "synopsisinfo");
3619 m_writer->writeAttribute("role", "nativeTypeFor");
3620
3621 QList<QmlTypeNode *> nativeTypes { classe->qmlNativeTypes().cbegin(), classe->qmlNativeTypes().cend()};
3622 std::sort(nativeTypes.begin(), nativeTypes.end(), Node::nodeNameLessThan);
3623
3624 for (auto item : std::as_const(nativeTypes)) {
3625 const Node *otherNode{nullptr};
3626 Atom a = Atom(Atom::LinkNode, Utilities::stringForNode(item));
3627 const QString &link = getAutoLink(&a, aggregate, &otherNode);
3628 generateSimpleLink(link, item->name());
3629 }
3630
3631 m_writer->writeEndElement(); // synopsisinfo
3632 }
3633
3634 // Inherits.
3635 QList<RelatedClass>::ConstIterator r;
3636 if (!classe->baseClasses().isEmpty()) {
3637 m_writer->writeStartElement(dbNamespace, "synopsisinfo");
3638 m_writer->writeAttribute("role", "inherits");
3639
3640 r = classe->baseClasses().constBegin();
3641 int index = 0;
3642 while (r != classe->baseClasses().constEnd()) {
3643 if ((*r).m_node) {
3644 generateFullName((*r).m_node, classe);
3645
3646 if ((*r).m_access == Access::Protected) {
3647 m_writer->writeCharacters(" (protected)");
3648 } else if ((*r).m_access == Access::Private) {
3649 m_writer->writeCharacters(" (private)");
3650 }
3651 m_writer->writeCharacters(
3652 TextUtils::comma(index++, classe->baseClasses().size()));
3653 }
3654 ++r;
3655 }
3656
3657 m_writer->writeEndElement(); // synopsisinfo
3658 newLine();
3659 }
3660
3661 // Inherited by.
3662 if (!classe->derivedClasses().isEmpty()) {
3663 m_writer->writeStartElement(dbNamespace, "synopsisinfo");
3664 m_writer->writeAttribute("role", "inheritedBy");
3665 generateSortedNames(classe, classe->derivedClasses());
3666 m_writer->writeEndElement(); // synopsisinfo
3667 newLine();
3668 }
3669 }
3670 }
3671
3672 // QML types.
3673 if (qcn) {
3674 // Module name and version (i.e. import).
3675 QString logicalModuleVersion;
3676 const CollectionNode *collection =
3677 m_qdb->getCollectionNode(qcn->logicalModuleName(), qcn->nodeType());
3678 if (collection)
3679 logicalModuleVersion = collection->logicalModuleVersion();
3680 else
3681 logicalModuleVersion = qcn->logicalModuleVersion();
3682
3683 QStringList importText;
3684 importText << "import " + qcn->logicalModuleName();
3685 if (!logicalModuleVersion.isEmpty())
3686 importText << logicalModuleVersion;
3687 generateSynopsisInfo("import", importText.join(' '));
3688
3689 // Since and project.
3690 if (!qcn->since().isEmpty())
3691 generateSynopsisInfo("since", formatSince(qcn));
3692
3693 QmlTypeNode *base = qcn->qmlBaseNode();
3694 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
3695 while (base) {
3696 const NodeContext context = base->createContext();
3697 if (InclusionFilter::isIncluded(policy, context))
3698 break;
3699 base = base->qmlBaseNode();
3700 }
3701
3702 QStringList knownTypeNames{qcn->name()};
3703 if (base)
3704 knownTypeNames << base->name();
3705
3706 // Inherited by.
3707 NodeList subs;
3708 QmlTypeNode::subclasses(qcn, subs);
3709 if (!subs.isEmpty()) {
3710 m_writer->writeTextElement(dbNamespace, "synopsisinfo");
3711 m_writer->writeAttribute("role", "inheritedBy");
3712 generateSortedQmlNames(qcn, knownTypeNames, subs);
3713 m_writer->writeEndElement(); // synopsisinfo
3714 newLine();
3715 }
3716
3717 // Inherits.
3718 if (base) {
3719 const Node *otherNode = nullptr;
3720 Atom a = Atom(Atom::LinkNode, Utilities::stringForNode(base));
3721 QString link = getAutoLink(&a, base, &otherNode);
3722
3723 m_writer->writeTextElement(dbNamespace, "synopsisinfo");
3724 m_writer->writeAttribute("role", "inherits");
3725 generateSimpleLink(link, base->name());
3726 // Disambiguate with '(<QML module name>)' if there are clashing type names
3727 for (const auto sub : std::as_const(subs)) {
3728 if (knownTypeNames.contains(sub->name())) {
3729 m_writer->writeCharacters(" (%1)"_L1.arg(base->logicalModuleName()));
3730 break;
3731 }
3732 }
3733 m_writer->writeEndElement(); // synopsisinfo
3734 newLine();
3735 }
3736
3737 // Native type
3738 ClassNode *cn = (const_cast<QmlTypeNode *>(qcn))->classNode();
3739
3740 if (cn && cn->isQmlNativeType() && !cn->isInternal()) {
3741 const Node *otherNode = nullptr;
3742 Atom a = Atom(Atom::LinkNode, Utilities::stringForNode(qcn));
3743 QString link = getAutoLink(&a, cn, &otherNode);
3744
3745 m_writer->writeTextElement(dbNamespace, "synopsisinfo");
3746 m_writer->writeAttribute("role", "nativeType");
3747 generateSimpleLink(link, cn->name());
3748 m_writer->writeEndElement(); // synopsisinfo
3749 newLine();
3750 }
3751 }
3752
3753 // Thread safeness.
3754 switch (node->threadSafeness()) {
3755 case Node::UnspecifiedSafeness:
3756 generateSynopsisInfo("threadsafeness", "unspecified");
3757 break;
3758 case Node::NonReentrant:
3759 generateSynopsisInfo("threadsafeness", "non-reentrant");
3760 break;
3761 case Node::Reentrant:
3762 generateSynopsisInfo("threadsafeness", "reentrant");
3763 break;
3764 case Node::ThreadSafe:
3765 generateSynopsisInfo("threadsafeness", "thread safe");
3766 break;
3767 default:
3768 generateSynopsisInfo("threadsafeness", "unspecified");
3769 break;
3770 }
3771
3772 // Module.
3773 if (!node->physicalModuleName().isEmpty())
3774 generateSynopsisInfo("module", node->physicalModuleName());
3775
3776 // Group.
3777 if (classNode && !classNode->groupNames().isEmpty()) {
3778 generateSynopsisInfo("groups", classNode->groupNames().join(QLatin1Char(',')));
3779 } else if (qcn && !qcn->groupNames().isEmpty()) {
3780 generateSynopsisInfo("groups", qcn->groupNames().join(QLatin1Char(',')));
3781 }
3782
3783 // Properties.
3784 if (propertyNode) {
3785 for (const Node *fnNode : propertyNode->getters()) {
3786 if (fnNode) {
3787 const auto funcNode = static_cast<const FunctionNode *>(fnNode);
3788 generateSynopsisInfo("getter", funcNode->name());
3789 }
3790 }
3791 for (const Node *fnNode : propertyNode->setters()) {
3792 if (fnNode) {
3793 const auto funcNode = static_cast<const FunctionNode *>(fnNode);
3794 generateSynopsisInfo("setter", funcNode->name());
3795 }
3796 }
3797 for (const Node *fnNode : propertyNode->resetters()) {
3798 if (fnNode) {
3799 const auto funcNode = static_cast<const FunctionNode *>(fnNode);
3800 generateSynopsisInfo("resetter", funcNode->name());
3801 }
3802 }
3803 for (const Node *fnNode : propertyNode->notifiers()) {
3804 if (fnNode) {
3805 const auto funcNode = static_cast<const FunctionNode *>(fnNode);
3806 generateSynopsisInfo("notifier", funcNode->name());
3807 }
3808 }
3809 }
3810
3811 m_writer->writeEndElement(); // nodeToSynopsisTag (like classsynopsis)
3812 newLine();
3813
3814 // The typedef associated to this enum. It is output *after* the main tag,
3815 // i.e. it must be after the synopsisinfo.
3816 if (enumNode && enumNode->flagsType()) {
3817 m_writer->writeStartElement(dbNamespace, "typedefsynopsis");
3818 newLine();
3819
3820 m_writer->writeTextElement(dbNamespace, "typedefname",
3821 enumNode->flagsType()->fullDocumentName());
3822 newLine();
3823
3824 m_writer->writeEndElement(); // typedefsynopsis
3825 newLine();
3826 }
3827}
3828
3830{
3831 // From CodeMarker::taggedNode, but without the tag part (i.e. only the QML specific case
3832 // remaining).
3833 // TODO: find a better name for this.
3834 if (node->nodeType() == NodeType::QmlType && node->name().startsWith(QLatin1String("QML:")))
3835 return node->name().mid(4);
3836 return node->name();
3837}
3838
3839/*!
3840 Parses a string with method/variable name and (return) type
3841 to include type tags.
3842 */
3843void DocBookGenerator::typified(const QString &string, const Node *relative, bool trailingSpace,
3844 bool generateType)
3845{
3846 // Adapted from CodeMarker::typified and HtmlGenerator::highlightedCode.
3847 QString result;
3848 QString pendingWord;
3849
3850 for (int i = 0; i <= string.size(); ++i) {
3851 QChar ch;
3852 if (i != string.size())
3853 ch = string.at(i);
3854
3855 QChar lower = ch.toLower();
3856 if ((lower >= QLatin1Char('a') && lower <= QLatin1Char('z')) || ch.digitValue() >= 0
3857 || ch == QLatin1Char('_') || ch == QLatin1Char(':')) {
3858 pendingWord += ch;
3859 } else {
3860 if (!pendingWord.isEmpty()) {
3861 bool isProbablyType = (pendingWord != QLatin1String("const"));
3862 if (generateType && isProbablyType) {
3863 // Flush the current buffer.
3864 m_writer->writeCharacters(result);
3865 result.truncate(0);
3866
3867 // Add the link, logic from HtmlGenerator::highlightedCode.
3868 const Node *n = m_qdb->findTypeNode(pendingWord, relative, Genus::DontCare);
3869 QString href;
3870 if (!(n && n->isQmlBasicType())
3871 || (relative
3872 && (relative->genus() == n->genus() || Genus::DontCare == n->genus()))) {
3873 href = linkForNode(n, relative);
3874 }
3875
3876 m_writer->writeStartElement(dbNamespace, "type");
3877 if (href.isEmpty())
3878 m_writer->writeCharacters(pendingWord);
3879 else
3880 generateSimpleLink(href, pendingWord);
3881 m_writer->writeEndElement(); // type
3882 } else {
3883 result += pendingWord;
3884 }
3885 }
3886 pendingWord.clear();
3887
3888 if (ch.unicode() != '\0')
3889 result += ch;
3890 }
3891 }
3892
3893 if (trailingSpace && string.size()) {
3894 if (!string.endsWith(QLatin1Char('*')) && !string.endsWith(QLatin1Char('&')))
3895 result += QLatin1Char(' ');
3896 }
3897
3898 m_writer->writeCharacters(result);
3899}
3900
3901/*!
3902 \internal
3903
3904 Emits the requires-clause \a text, wrapping each occurrence of a name
3905 in \a concepts in a \c{<db:link>} element pointing at the corresponding
3906 documented \\concept page. Concept identifiers consist of letters,
3907 digits, and underscores only, so word-boundary regex matches reliably
3908 isolate standalone concept tokens. The list is sorted longest first so
3909 prefix-sharing concept names (such as \c{Hashable} and
3910 \c{HashableContainer}) substitute correctly without overlap.
3911
3912 If a concept name doesn't resolve to a documented entity through
3913 \c{QDocDatabase::findConceptNode}, the bare text is written instead —
3914 matching the graceful-degradation behavior of the legacy HTML
3915 \c{<@concept>} resolver branch.
3916*/
3917void DocBookGenerator::generateRequiresClauseText(const QString &text,
3918 const QStringList &concepts,
3919 const Node *relative)
3920{
3921 if (concepts.isEmpty()) {
3922 m_writer->writeCharacters(text);
3923 return;
3924 }
3925
3926 QStringList sorted = concepts;
3927 std::sort(sorted.begin(), sorted.end(),
3928 [](const QString &a, const QString &b) { return a.size() > b.size(); });
3929
3930 // Match by the unqualified spelling that appears in the clause text, but
3931 // carry the fully-qualified name as the lookup target: concepts register
3932 // under their qualified name, so a namespaced reference such as
3933 // traits::Sortable resolves only through the qualified target.
3934 struct Match { qsizetype offset; qsizetype length; QString name; QString target; };
3935 QList<Match> matches;
3936 QList<bool> occupied(text.size(), false);
3937
3938 for (const QString &concept_name : sorted) {
3939 const QString unqualified = concept_name.section("::"_L1, -1);
3940 const QRegularExpression re("\\b"_L1
3941 + QRegularExpression::escape(unqualified) + "\\b"_L1);
3942 auto it = re.globalMatch(text);
3943 while (it.hasNext()) {
3944 const auto m = it.next();
3945 const qsizetype start = m.capturedStart();
3946 const qsizetype len = m.capturedLength();
3947 bool clear = true;
3948 for (qsizetype i = start; i < start + len; ++i) {
3949 if (occupied[i]) {
3950 clear = false;
3951 break;
3952 }
3953 }
3954 if (!clear)
3955 continue;
3956 for (qsizetype i = start; i < start + len; ++i)
3957 occupied[i] = true;
3958 matches.append({start, len, unqualified, concept_name});
3959 }
3960 }
3961
3962 std::sort(matches.begin(), matches.end(),
3963 [](const Match &a, const Match &b) { return a.offset < b.offset; });
3964
3965 qsizetype pos = 0;
3966 for (const auto &m : matches) {
3967 if (m.offset > pos)
3968 m_writer->writeCharacters(text.mid(pos, m.offset - pos));
3969 const Node *n = m_qdb->findConceptNode(m.target);
3970 if (n)
3971 generateSimpleLink(linkForNode(n, relative), m.name);
3972 else
3973 m_writer->writeCharacters(m.name);
3974 pos = m.offset + m.length;
3975 }
3976 if (pos < text.size())
3977 m_writer->writeCharacters(text.mid(pos));
3978}
3979
3980/*!
3981 \internal
3982
3983 Emits one template parameter into the current writer position. When the
3984 parameter carries a direct concept constraint (such as \c {Integral T}),
3985 the unqualified concept name is wrapped in a \c{<db:link>} pointing at
3986 the documented concept page; otherwise the plain \c{typename} keyword is
3987 written. The shape mirrors \c {CppCodeMarker::formatTemplateParameter},
3988 but writes DocBook XML directly rather than producing a marker string.
3989*/
3990void DocBookGenerator::generateTemplateParameter(const RelaxedTemplateParameter &param,
3991 const Node *relative)
3992{
3993 const auto &decl = param.valued_declaration;
3994
3995 if (param.template_declaration) {
3996 // Template-template parameter: emit the nested template declaration
3997 // recursively. The nested declaration is a TemplateDeclarationStorage,
3998 // not a RelaxedTemplateDeclaration, so it has no requires_clause or
3999 // referenced_concepts to consider.
4000 m_writer->writeCharacters("template <"_L1);
4001 bool first = true;
4002 for (const auto &sub : param.template_declaration->parameters) {
4003 if (sub.sfinae_constraint)
4004 continue;
4005 if (!first)
4006 m_writer->writeCharacters(", "_L1);
4007 generateTemplateParameter(sub, relative);
4008 first = false;
4009 }
4010 m_writer->writeCharacters("> "_L1);
4011 }
4012
4013 switch (param.kind) {
4015 if (param.concept_name) {
4016 const QString fq = QString::fromStdString(*param.concept_name);
4017 const QString unqualified = fq.section("::"_L1, -1);
4018 const Node *n = m_qdb->findConceptNode(fq);
4019 if (n)
4020 generateSimpleLink(linkForNode(n, relative), unqualified);
4021 else
4022 // No documented concept to link: keep the qualified spelling
4023 // the author wrote rather than silently dropping the namespace.
4024 m_writer->writeCharacters(fq);
4025 } else {
4026 m_writer->writeCharacters("typename"_L1);
4027 }
4028 break;
4029 case RelaxedTemplateParameter::Kind::NonTypeTemplateParameter:
4030 if (!decl.type.empty())
4031 typified(QString::fromStdString(decl.type), relative, false, true);
4032 break;
4033 case RelaxedTemplateParameter::Kind::TemplateTemplateParameter:
4034 m_writer->writeCharacters("typename"_L1);
4035 break;
4036 }
4037
4038 if (param.is_parameter_pack)
4039 m_writer->writeCharacters("..."_L1);
4040
4041 if (!decl.name.empty()) {
4042 m_writer->writeCharacters(" "_L1);
4043 m_writer->writeCharacters(QString::fromStdString(decl.name));
4044 }
4045
4046 if (!decl.initializer.empty()) {
4047 m_writer->writeCharacters(" = "_L1);
4050 typified(QString::fromStdString(decl.initializer), relative, false, true);
4051 } else {
4052 m_writer->writeCharacters(QString::fromStdString(decl.initializer));
4053 }
4054 }
4055}
4056
4057/*!
4058 \internal
4059
4060 Emits a full \c {template <...> requires ...} declaration element by
4061 element so concept references inside both the parameter list and the
4062 requires clause become \c{<db:link>} anchors. Multi-line layout kicks in
4063 when the visible parameter count exceeds
4064 \c{QDoc::MultilineTemplateParamThreshold}, mirroring
4065 \c {RelaxedTemplateDeclaration::to_qstring_multiline()}.
4066*/
4067void DocBookGenerator::generateTemplateDecl(const RelaxedTemplateDeclaration *templateDecl,
4068 const Node *relative)
4069{
4070 if (!templateDecl)
4071 return;
4072
4073 const bool multiline = templateDecl->visibleParameterCount()
4075
4076 m_writer->writeCharacters("template <"_L1);
4077 if (multiline)
4078 m_writer->writeCharacters("\n"_L1);
4079
4080 bool first = true;
4081 for (const auto &param : templateDecl->parameters) {
4082 if (param.sfinae_constraint)
4083 continue;
4084 if (!first)
4085 m_writer->writeCharacters(multiline ? ",\n"_L1 : ", "_L1);
4086 if (multiline)
4087 m_writer->writeCharacters(" "_L1);
4088 generateTemplateParameter(param, relative);
4089 first = false;
4090 }
4091
4092 if (multiline)
4093 m_writer->writeCharacters("\n"_L1);
4094 m_writer->writeCharacters(">"_L1);
4095
4096 if (templateDecl->requires_clause && !templateDecl->requires_clause->empty()) {
4097 m_writer->writeCharacters(" requires "_L1);
4098 QStringList concepts;
4099 concepts.reserve(int(templateDecl->referenced_concepts.size()));
4100 for (const auto &s : templateDecl->referenced_concepts)
4101 concepts.append(QString::fromStdString(s));
4102 generateRequiresClauseText(QString::fromStdString(*templateDecl->requires_clause),
4103 concepts, relative);
4104 }
4105}
4106
4107void DocBookGenerator::generateSynopsisName(const Node *node, const Node *relative,
4108 bool generateNameLink)
4109{
4110 // Implements the rewriting of <@link> from HtmlGenerator::highlightedCode, only due to calls to
4111 // CodeMarker::linkTag in CppCodeMarker::markedUpSynopsis.
4112 QString name = taggedNode(node);
4113
4114 if (!generateNameLink) {
4115 m_writer->writeCharacters(name);
4116 return;
4117 }
4118
4119 m_writer->writeStartElement(dbNamespace, "emphasis");
4120 m_writer->writeAttribute("role", "bold");
4121 generateSimpleLink(linkForNode(node, relative), name);
4122 m_writer->writeEndElement(); // emphasis
4123}
4124
4125void DocBookGenerator::generateParameter(const Parameter &parameter, const Node *relative,
4126 bool generateExtra, bool generateType)
4127{
4128 const QString &pname = parameter.name();
4129 const QString &ptype = parameter.type();
4130 QString paramName;
4131 qsizetype insertPos = !pname.isEmpty() ? parameter.nameInsertionPoint() : -1;
4132 if (!pname.isEmpty()) {
4133 if (insertPos >= 0) {
4134 // Inside-out declarator: name goes inside the type.
4135 typified(ptype.left(insertPos), relative, false, generateType);
4136 } else {
4137 typified(ptype, relative, true, generateType);
4138 }
4139 paramName = pname;
4140 } else {
4141 paramName = ptype;
4142 }
4143
4144 if (generateExtra || pname.isEmpty()) {
4145 m_writer->writeStartElement(dbNamespace, "emphasis");
4146 m_writer->writeCharacters(paramName);
4147 m_writer->writeEndElement(); // emphasis
4148 }
4149
4150 if (insertPos >= 0)
4151 typified(ptype.mid(insertPos), relative, false, generateType);
4152
4153 const QString &pvalue = parameter.defaultValue();
4154 if (generateExtra && !pvalue.isEmpty())
4155 m_writer->writeCharacters(" = " + pvalue);
4156}
4157
4158void DocBookGenerator::generateSynopsis(const Node *node, const Node *relative,
4159 Section::Style style)
4160{
4161 // From HtmlGenerator::generateSynopsis (conditions written as booleans).
4162 const bool generateExtra = style != Section::AllMembers;
4163 const bool generateType = style != Section::Details;
4164 const bool generateNameLink = style != Section::Details;
4165
4166 // From CppCodeMarker::markedUpSynopsis, reversed the generation of "extra" and "synopsis".
4167 const int MaxEnumValues = 6;
4168
4169 if (generateExtra) {
4170 if (auto extra = CodeMarker::extraSynopsis(node, style); !extra.isEmpty()) {
4171 generateExtraSynopsis(extra);
4172 m_writer->writeCharacters(u" "_s);
4173 }
4174 }
4175
4176 // Then generate the synopsis.
4177 QString namePrefix {};
4178 if (style == Section::Details) {
4179 if (!node->isRelatedNonmember() && !node->isProxyNode() && !node->parent()->name().isEmpty()
4180 && !node->parent()->isHeader() && !node->isProperty() && !node->isQmlNode()) {
4181 namePrefix = taggedNode(node->parent()) + "::";
4182 }
4183 }
4184
4185 switch (node->nodeType()) {
4186 case NodeType::Namespace:
4187 m_writer->writeCharacters("namespace ");
4188 m_writer->writeCharacters(namePrefix);
4189 generateSynopsisName(node, relative, generateNameLink);
4190 break;
4191 case NodeType::Class:
4192 m_writer->writeCharacters("class ");
4193 m_writer->writeCharacters(namePrefix);
4194 generateSynopsisName(node, relative, generateNameLink);
4195 break;
4196 case NodeType::Function: {
4197 const auto func = (const FunctionNode *)node;
4198
4199 if (style == Section::Details) {
4200 if (auto templateDecl = func->templateDecl()) {
4201 generateTemplateDecl(&*templateDecl, relative);
4202 if (templateDecl->visibleParameterCount() > QDoc::MultilineTemplateParamThreshold)
4203 m_writer->writeCharacters("\n"_L1);
4204 else
4205 m_writer->writeCharacters(" "_L1);
4206 }
4207 }
4208
4209 // First, the part coming before the name.
4210 if (style == Section::Summary || style == Section::Accessors) {
4211 if (!func->isNonvirtual())
4212 m_writer->writeCharacters(QStringLiteral("virtual "));
4213 }
4214
4215 // Name and parameters.
4216 if (style != Section::AllMembers && !func->returnType().isEmpty())
4217 typified(func->returnTypeString(), relative, true, generateType);
4218 m_writer->writeCharacters(namePrefix);
4219 generateSynopsisName(node, relative, generateNameLink);
4220
4221 if (!func->isMacroWithoutParams()) {
4222 m_writer->writeCharacters(QStringLiteral("("));
4223 if (!func->parameters().isEmpty()) {
4224 const Parameters &parameters = func->parameters();
4225 for (int i = 0; i < parameters.count(); i++) {
4226 if (i > 0)
4227 m_writer->writeCharacters(QStringLiteral(", "));
4228 generateParameter(parameters.at(i), relative, generateExtra, generateType);
4229 }
4230 }
4231 m_writer->writeCharacters(QStringLiteral(")"));
4232 }
4233
4234 if (func->isConst())
4235 m_writer->writeCharacters(QStringLiteral(" const"));
4236
4237 if (style == Section::Summary || style == Section::Accessors) {
4238 // virtual is prepended, if needed.
4239 QString synopsis;
4240 if (func->isFinal())
4241 synopsis += QStringLiteral(" final");
4242 if (func->isOverride())
4243 synopsis += QStringLiteral(" override");
4244 if (func->isPureVirtual())
4245 synopsis += QStringLiteral(" = 0");
4246 if (func->isRef())
4247 synopsis += QStringLiteral(" &");
4248 else if (func->isRefRef())
4249 synopsis += QStringLiteral(" &&");
4250 m_writer->writeCharacters(synopsis);
4251 } else if (style == Section::AllMembers) {
4252 if (!func->returnType().isEmpty() && func->returnType() != "void") {
4253 m_writer->writeCharacters(QStringLiteral(" : "));
4254 typified(func->returnTypeString(), relative, false, generateType);
4255 }
4256 } else {
4257 QString synopsis;
4258 if (func->isRef())
4259 synopsis += " &"_L1;
4260 else if (func->isRefRef())
4261 synopsis += " &&"_L1;
4262 m_writer->writeCharacters(synopsis);
4263
4264 if (const auto &req = func->trailingRequiresClause(); req && !req->isEmpty()) {
4265 m_writer->writeCharacters(" requires "_L1);
4266 generateRequiresClauseText(*req, func->referencedConcepts(), relative);
4267 }
4268 }
4269 } break;
4270 case NodeType::Enum: {
4271 const auto enume = static_cast<const EnumNode *>(node);
4272 if (!enume->isAnonymous()) {
4273 m_writer->writeCharacters("enum "_L1);
4274 m_writer->writeCharacters(namePrefix);
4275 generateSynopsisName(node, relative, generateNameLink);
4276 } else if (generateNameLink) {
4277 m_writer->writeStartElement(dbNamespace, "emphasis");
4278 m_writer->writeAttribute("role", "bold");
4279 generateSimpleLink(linkForNode(node, relative), "enum");
4280 m_writer->writeEndElement(); // emphasis
4281 } else {
4282 m_writer->writeCharacters("enum"_L1);
4283 }
4284
4285 QString synopsis;
4286 if (style == Section::Summary) {
4287 synopsis += " { ";
4288
4289 QStringList documentedItems = enume->doc().enumItemNames();
4290 if (documentedItems.isEmpty()) {
4291 const auto &enumItems = enume->items();
4292 for (const auto &item : enumItems)
4293 documentedItems << item.name();
4294 }
4295 const QStringList omitItems = enume->doc().omitEnumItemNames();
4296 for (const auto &item : omitItems)
4297 documentedItems.removeAll(item);
4298
4299 if (documentedItems.size() > MaxEnumValues) {
4300 // Take the last element and keep it safe, then elide the surplus.
4301 const QString last = documentedItems.last();
4302 documentedItems = documentedItems.mid(0, MaxEnumValues - 1);
4303 documentedItems += "&#x2026;"; // Ellipsis: in HTML, &hellip;.
4304 documentedItems += last;
4305 }
4306 synopsis += documentedItems.join(QLatin1String(", "));
4307
4308 if (!documentedItems.isEmpty())
4309 synopsis += QLatin1Char(' ');
4310 synopsis += QLatin1Char('}');
4311 }
4312 m_writer->writeCharacters(synopsis);
4313 } break;
4314 case NodeType::TypeAlias: {
4315 if (style == Section::Details) {
4316 if (auto templateDecl = node->templateDecl()) {
4317 generateTemplateDecl(&*templateDecl, relative);
4318 if (templateDecl->visibleParameterCount() > QDoc::MultilineTemplateParamThreshold)
4319 m_writer->writeCharacters("\n"_L1);
4320 else
4321 m_writer->writeCharacters(" "_L1);
4322 }
4323 }
4324 m_writer->writeCharacters(namePrefix);
4325 generateSynopsisName(node, relative, generateNameLink);
4326 } break;
4327 case NodeType::Typedef: {
4328 if (static_cast<const TypedefNode *>(node)->associatedEnum())
4329 m_writer->writeCharacters("flags ");
4330 m_writer->writeCharacters(namePrefix);
4331 generateSynopsisName(node, relative, generateNameLink);
4332 } break;
4333 case NodeType::Property: {
4334 const auto property = static_cast<const PropertyNode *>(node);
4335 m_writer->writeCharacters(namePrefix);
4336 generateSynopsisName(node, relative, generateNameLink);
4337 m_writer->writeCharacters(" : ");
4338 typified(property->qualifiedDataType(), relative, false, generateType);
4339 } break;
4340 case NodeType::Variable: {
4341 const auto variable = static_cast<const VariableNode *>(node);
4342 if (style == Section::AllMembers) {
4343 generateSynopsisName(node, relative, generateNameLink);
4344 m_writer->writeCharacters(" : ");
4345 typified(variable->dataType(), relative, false, generateType);
4346 } else {
4347 typified(variable->leftType(), relative, false, generateType);
4348 m_writer->writeCharacters(" ");
4349 m_writer->writeCharacters(namePrefix);
4350 generateSynopsisName(node, relative, generateNameLink);
4351 m_writer->writeCharacters(variable->rightType());
4352 }
4353 } break;
4354 default:
4355 m_writer->writeCharacters(namePrefix);
4356 generateSynopsisName(node, relative, generateNameLink);
4357 }
4358}
4359
4360void DocBookGenerator::generateEnumValue(const QString &enumValue, const Node *relative)
4361{
4362 // From CppCodeMarker::markedUpEnumValue, simplifications from Generator::plainCode (removing
4363 // <@op>). With respect to CppCodeMarker::markedUpEnumValue, the order of generation of parents
4364 // must be reversed so that they are processed in the order
4365 // A related nonmember is documented under the related class, but its values are qualified
4366 // with the C++ scope in which the enum was declared, so start the scope walk from the
4367 // declaration parent.
4368 const auto *node = relative->declarationParent() ? relative->declarationParent()
4369 : relative->parent();
4370
4371 const NativeEnum *nativeEnum{nullptr};
4372 if (auto *ne_if = dynamic_cast<const NativeEnumInterface *>(relative))
4373 nativeEnum = ne_if->nativeEnum();
4374
4375 if (nativeEnum && nativeEnum->enumNode() && !enumValue.startsWith("%1."_L1.arg(nativeEnum->prefix()))) {
4376 m_writer->writeCharacters("%1.%2"_L1.arg(nativeEnum->prefix(), enumValue));
4377 return;
4378 }
4379
4380 // Respect existing prefixes in \value arguments of \qmlenum topic
4381 if (!relative->isEnumType() || (relative->isEnumType(Genus::QML)
4382 && enumValue.section(' ', 0, 0).contains('.'_L1))) {
4383 m_writer->writeCharacters(enumValue);
4384 return;
4385 }
4386
4387 QList<const Node *> parents;
4388 while (!node->isHeader() && node->parent()) {
4389 parents.prepend(node);
4390 if (node->parent() == relative || node->parent()->name().isEmpty())
4391 break;
4392 node = node->parent();
4393 }
4394 if (static_cast<const EnumNode *>(relative)->isScoped())
4395 parents << relative;
4396
4397 m_writer->writeStartElement(dbNamespace, "code");
4398 for (auto parent : parents) {
4399 generateSynopsisName(parent, relative, true);
4400 m_writer->writeCharacters((relative->genus() == Genus::QML) ? "."_L1 : "::"_L1);
4401 }
4402
4403 m_writer->writeCharacters(enumValue);
4404 m_writer->writeEndElement(); // code
4405}
4406
4407/*!
4408 Generates an addendum note of type \a type for \a node. \a marker
4409 is unused in this generator.
4410*/
4412 AdmonitionPrefix prefix)
4413{
4414 Q_UNUSED(marker)
4415 Q_ASSERT(node && !node->name().isEmpty());
4416
4417 switch (prefix) {
4419 break;
4421 m_writer->writeStartElement(dbNamespace, "note");
4422 newLine();
4423 break;
4424 }
4425 }
4426 switch (type) {
4427 case Invokable:
4428 m_writer->writeStartElement(dbNamespace, "para");
4429 m_writer->writeCharacters(
4430 "This function can be invoked via the meta-object system and from QML. See ");
4431 generateSimpleLink(node->url(), "Q_INVOKABLE");
4432 m_writer->writeCharacters(".");
4433 m_writer->writeEndElement(); // para
4434 newLine();
4435 break;
4436 case PrivateSignal:
4437 m_writer->writeTextElement(
4438 dbNamespace, "para",
4439 "This is a private signal. It can be used in signal connections but "
4440 "cannot be emitted by the user.");
4441 break;
4442 case QmlSignalHandler:
4443 {
4444 QString handler(node->name());
4445 int prefixLocation = handler.lastIndexOf('.', -2) + 1;
4446 handler[prefixLocation] = handler[prefixLocation].toTitleCase();
4447 handler.insert(prefixLocation, QLatin1String("on"));
4448 m_writer->writeStartElement(dbNamespace, "para");
4449 m_writer->writeCharacters("The corresponding handler is ");
4450 m_writer->writeTextElement(dbNamespace, "code", handler);
4451 m_writer->writeCharacters(".");
4452 m_writer->writeEndElement(); // para
4453 newLine();
4454 break;
4455 }
4457 {
4458 if (!node->isFunction())
4459 return;
4460 const auto *fn = static_cast<const FunctionNode *>(node);
4461 auto nodes = fn->associatedProperties();
4462 if (nodes.isEmpty())
4463 return;
4464 std::sort(nodes.begin(), nodes.end(), Node::nodeNameLessThan);
4465
4466 // Group properties by their role for more concise output
4467 QMap<PropertyNode::FunctionRole, QList<const PropertyNode *>> roleGroups;
4468 for (const auto *n : std::as_const(nodes)) {
4469 const auto *pn = static_cast<const PropertyNode *>(n);
4470 PropertyNode::FunctionRole role = pn->role(fn);
4471 roleGroups[role].append(pn);
4472 }
4473
4474 // Generate text for each role group in an explicit order
4475 static constexpr PropertyNode::FunctionRole roleOrder[] = {
4481 };
4482
4483 for (auto role : roleOrder) {
4484 const auto it = roleGroups.constFind(role);
4485 if (it == roleGroups.cend())
4486 continue;
4487
4488 const auto &properties = it.value();
4489
4490 QString msg;
4491 switch (role) {
4493 msg = QStringLiteral("Getter function");
4494 break;
4496 msg = QStringLiteral("Setter function");
4497 break;
4499 msg = QStringLiteral("Resetter function");
4500 break;
4502 msg = QStringLiteral("Notifier signal");
4503 break;
4505 msg = QStringLiteral("Bindable function");
4506 break;
4507 default:
4508 continue;
4509 }
4510
4511 m_writer->writeStartElement(dbNamespace, "para");
4512 if (properties.size() == 1) {
4513 const auto *pn = properties.first();
4514 m_writer->writeCharacters(msg + " for property ");
4515 generateSimpleLink(linkForNode(pn, nullptr), pn->name());
4516 m_writer->writeCharacters(". ");
4517 } else {
4518 m_writer->writeCharacters(msg + " for properties ");
4519 for (qsizetype i = 0; i < properties.size(); ++i) {
4520 const auto *pn = properties.at(i);
4521 generateSimpleLink(linkForNode(pn, nullptr), pn->name());
4522 m_writer->writeCharacters(TextUtils::separator(i, properties.size()));
4523 }
4524 m_writer->writeCharacters(" ");
4525 }
4526 m_writer->writeEndElement(); // para
4527 newLine();
4528 }
4529 break;
4530 }
4531 case BindableProperty:
4532 {
4533 const Node *linkNode;
4534 Atom linkAtom = Atom(Atom::Link, "QProperty");
4535 QString link = getAutoLink(&linkAtom, node, &linkNode);
4536 m_writer->writeStartElement(dbNamespace, "para");
4537 m_writer->writeCharacters("This property supports ");
4538 generateSimpleLink(link, "QProperty");
4539 m_writer->writeCharacters(" bindings.");
4540 m_writer->writeEndElement(); // para
4541 newLine();
4542 break;
4543 }
4544 case OverloadNote: {
4545 const auto *func = static_cast<const FunctionNode *>(node);
4546
4547 // Primary overloads should not display any overload note text
4548 if (func->isPrimaryOverload())
4549 return;
4550
4551 m_writer->writeStartElement(dbNamespace, "para");
4552
4553 if (func->isSignal() || func->isSlot()) {
4554 auto writeDocBookLink = [&](const QString &target, const QString &label) {
4555 const Node *linkNode = nullptr;
4556 const Atom &linkAtom = Atom(Atom::AutoLink, target);
4557 const QString &link = getAutoLink(&linkAtom, node, &linkNode);
4558
4559 m_writer->writeStartElement(dbNamespace, "link");
4560 if (!link.isEmpty() && linkNode) {
4561 m_writer->writeAttribute(xlinkNamespace, "href", link);
4562 } else {
4563 m_writer->writeAttribute(dbNamespace, "linkend", target);
4564 }
4565 m_writer->writeCharacters(label);
4566 m_writer->writeEndElement(); // link
4567 };
4568
4569 const QString &functionType = func->isSignal() ? "signal" : "slot";
4570 const QString &configKey = func->isSignal() ? "overloadedsignalstarget" : "overloadedslotstarget";
4571 const QString &defaultTarget = func->isSignal() ? "connecting-overloaded-signals" : "connecting-overloaded-slots";
4572 const QString &linkTarget = Config::instance().get(configKey).asString(defaultTarget);
4573
4574 m_writer->writeCharacters("This " + functionType + " is overloaded. ");
4575
4576 QString snippet = generateOverloadSnippet(func);
4577 if (!snippet.isEmpty()) {
4578 m_writer->writeCharacters("To connect to this " + functionType + ":");
4579 m_writer->writeEndElement(); // para
4580 newLine();
4581 m_writer->writeStartElement(dbNamespace, "programlisting");
4582 m_writer->writeCharacters(snippet);
4583 m_writer->writeEndElement(); // programlisting
4584 newLine();
4585 // A new para element is needed here because the caller closes it.
4586 // When linkTarget is empty, this creates an empty para, which is
4587 // harmless but slightly verbose.
4588 m_writer->writeStartElement(dbNamespace, "para");
4589 if (!linkTarget.isEmpty()) {
4590 m_writer->writeCharacters("For more examples and approaches, see ");
4591 writeDocBookLink(linkTarget, "connecting to overloaded " + functionType + "s");
4592 m_writer->writeCharacters(".");
4593 }
4594 } else if (!linkTarget.isEmpty()) {
4595 m_writer->writeCharacters("For more examples and approaches, see ");
4596 writeDocBookLink(linkTarget, "connecting to overloaded " + functionType + "s");
4597 m_writer->writeCharacters(".");
4598 }
4599 } else {
4600 // Original behavior for regular overloaded functions
4601 const auto &args = node->doc().overloadList();
4602 if (args.first().first.isEmpty()) {
4603 m_writer->writeCharacters("This is an overloaded function.");
4604 } else {
4605 QString target = args.first().first;
4606 // If the target is not fully qualified and we have a parent class context,
4607 // attempt to qualify it to improve link resolution
4608 if (!target.contains("::")) {
4609 const auto *parent = node->parent();
4610 if (parent && (parent->isClassNode() || parent->isNamespace())) {
4611 target = parent->name() + "::" + target;
4612 }
4613 }
4614 m_writer->writeCharacters("This function overloads ");
4615 // Use the same approach as AutoLink resolution in other generators
4616 const Node *linkNode = nullptr;
4617 Atom linkAtom = Atom(Atom::AutoLink, target);
4618 QString link = getAutoLink(&linkAtom, node, &linkNode);
4619 if (!link.isEmpty() && linkNode)
4620 generateSimpleLink(link, target);
4621 else
4622 m_writer->writeCharacters(target);
4623 m_writer->writeCharacters(".");
4624 }
4625 }
4626
4627 m_writer->writeEndElement(); // para
4628 newLine();
4629 break;
4630 }
4631 default:
4632 break;
4633 }
4634
4635 if (prefix == AdmonitionPrefix::Note) {
4636 m_writer->writeEndElement(); // note
4637 newLine();
4638 }
4639}
4640
4641void DocBookGenerator::generateDetailedMember(const Node *node, const PageNode *relative)
4642{
4643 // From HtmlGenerator::generateDetailedMember.
4644 bool closeSupplementarySection = false;
4645
4646 if (node->isSharedCommentNode()) {
4647 const auto *scn = reinterpret_cast<const SharedCommentNode *>(node);
4648 const QList<Node *> &collective = scn->collective();
4649
4650 bool firstFunction = true;
4651 for (const auto *sharedNode : collective) {
4652 if (firstFunction) {
4653 startSectionBegin(sharedNode);
4654 } else {
4655 m_writer->writeStartElement(dbNamespace, "bridgehead");
4656 m_writer->writeAttribute("renderas", "sect2");
4657 writeXmlId(sharedNode);
4658 }
4659 if (m_useITS)
4660 m_writer->writeAttribute(itsNamespace, "translate", "no");
4661
4662 generateSynopsis(sharedNode, relative, Section::Details);
4663
4664 if (firstFunction) {
4665 startSectionEnd();
4666 firstFunction = false;
4667 } else {
4668 m_writer->writeEndElement(); // bridgehead
4669 newLine();
4670 }
4671 }
4672 } else {
4673 const EnumNode *etn;
4674 if (node->isEnumType(Genus::CPP) && (etn = static_cast<const EnumNode *>(node))->flagsType()) {
4675 startSectionBegin(node);
4676 if (m_useITS)
4677 m_writer->writeAttribute(itsNamespace, "translate", "no");
4678 generateSynopsis(etn, relative, Section::Details);
4679 startSectionEnd();
4680
4681 m_writer->writeStartElement(dbNamespace, "bridgehead");
4682 m_writer->writeAttribute("renderas", "sect2");
4683 generateSynopsis(etn->flagsType(), relative, Section::Details);
4684 m_writer->writeEndElement(); // bridgehead
4685 newLine();
4686 } else {
4687 startSectionBegin(node);
4688 if (m_useITS)
4689 m_writer->writeAttribute(itsNamespace, "translate", "no");
4690 generateSynopsis(node, relative, Section::Details);
4691 startSectionEnd();
4692 }
4693 }
4694 Q_ASSERT(m_hasSection);
4695
4697
4698 generateStatus(node);
4699 generateBody(node);
4700
4701 // If the body ends with a section, the rest of the description must be wrapped in a section too.
4703 closeSupplementarySection = true;
4704 startSection("", "Notes");
4705 }
4706
4707 if (node->isFunction()) {
4708 const auto *func = static_cast<const FunctionNode *>(node);
4709 if (func->hasOverloads() && (func->isSignal() || func->isSlot()))
4711 }
4714 generateSince(node);
4715
4716 if (node->isProperty()) {
4717 const auto property = static_cast<const PropertyNode *>(node);
4718 if (property->propertyType() == PropertyNode::PropertyType::StandardProperty) {
4719 Section section("", "", "", "", Section::Accessors);
4720
4721 section.appendMembers(property->getters().toVector());
4722 section.appendMembers(property->setters().toVector());
4723 section.appendMembers(property->resetters().toVector());
4724
4725 if (!section.members().isEmpty()) {
4726 m_writer->writeStartElement(dbNamespace, "para");
4727 newLine();
4728 m_writer->writeStartElement(dbNamespace, "emphasis");
4729 m_writer->writeAttribute("role", "bold");
4730 m_writer->writeCharacters("Access functions:");
4731 newLine();
4732 m_writer->writeEndElement(); // emphasis
4733 newLine();
4734 m_writer->writeEndElement(); // para
4735 newLine();
4736 generateSectionList(section, node);
4737 }
4738
4739 Section notifiers("", "", "", "", Section::Accessors);
4740 notifiers.appendMembers(property->notifiers().toVector());
4741
4742 if (!notifiers.members().isEmpty()) {
4743 m_writer->writeStartElement(dbNamespace, "para");
4744 newLine();
4745 m_writer->writeStartElement(dbNamespace, "emphasis");
4746 m_writer->writeAttribute("role", "bold");
4747 m_writer->writeCharacters("Notifier signal:");
4748 newLine();
4749 m_writer->writeEndElement(); // emphasis
4750 newLine();
4751 m_writer->writeEndElement(); // para
4752 newLine();
4753 generateSectionList(notifiers, node);
4754 }
4755 }
4756 } else if (node->isEnumType(Genus::CPP)) {
4757 const auto en = static_cast<const EnumNode *>(node);
4758
4759 if (m_qflagsHref.isEmpty()) {
4760 Node *qflags = m_qdb->findClassNode(QStringList("QFlags"));
4761 if (qflags)
4762 m_qflagsHref = linkForNode(qflags, nullptr);
4763 }
4764
4765 if (en->flagsType()) {
4766 m_writer->writeStartElement(dbNamespace, "para");
4767 m_writer->writeCharacters("The ");
4768 m_writer->writeStartElement(dbNamespace, "code");
4769 m_writer->writeCharacters(en->flagsType()->name());
4770 m_writer->writeEndElement(); // code
4771 m_writer->writeCharacters(" type is a typedef for ");
4772 m_writer->writeStartElement(dbNamespace, "code");
4773 generateSimpleLink(m_qflagsHref, "QFlags");
4774 m_writer->writeCharacters("<" + en->name() + ">. ");
4775 m_writer->writeEndElement(); // code
4776 m_writer->writeCharacters("It stores an OR combination of ");
4777 m_writer->writeStartElement(dbNamespace, "code");
4778 m_writer->writeCharacters(en->name());
4779 m_writer->writeEndElement(); // code
4780 m_writer->writeCharacters(" values.");
4781 m_writer->writeEndElement(); // para
4782 newLine();
4783 }
4784 }
4785
4786 if (closeSupplementarySection)
4787 endSection();
4788
4789 // The list of linked pages is always in its own section.
4791
4792 // Close the section for this member.
4793 endSection(); // section
4794}
4795
4796void DocBookGenerator::generateSectionList(const Section &section, const Node *relative,
4797 bool useObsoleteMembers)
4798{
4799 // From HtmlGenerator::generateSectionList, just generating a list (not tables).
4800 const NodeVector &members =
4801 (useObsoleteMembers ? section.obsoleteMembers() : section.members());
4802 if (!members.isEmpty()) {
4803 bool hasPrivateSignals = false;
4804 bool isInvokable = false;
4805
4806 m_writer->writeStartElement(dbNamespace, "itemizedlist");
4807 if (m_useITS)
4808 m_writer->writeAttribute(itsNamespace, "translate", "no");
4809 newLine();
4810
4811 NodeVector::ConstIterator m = members.constBegin();
4812 while (m != members.constEnd()) {
4813 if ((*m)->access() == Access::Private) {
4814 ++m;
4815 continue;
4816 }
4817
4818 m_writer->writeStartElement(dbNamespace, "listitem");
4819 newLine();
4820 m_writer->writeStartElement(dbNamespace, "para");
4821
4822 // prefix no more needed.
4823 generateSynopsis(*m, relative, section.style());
4824 if ((*m)->isFunction()) {
4825 const auto fn = static_cast<const FunctionNode *>(*m);
4826 if (fn->isPrivateSignal())
4827 hasPrivateSignals = true;
4828 else if (fn->isInvokable())
4829 isInvokable = true;
4830 }
4831
4832 m_writer->writeEndElement(); // para
4833 newLine();
4834 m_writer->writeEndElement(); // listitem
4835 newLine();
4836
4837 ++m;
4838 }
4839
4840 m_writer->writeEndElement(); // itemizedlist
4841 newLine();
4842
4843 if (hasPrivateSignals)
4845 if (isInvokable)
4847 }
4848
4849 if (!useObsoleteMembers && section.style() == Section::Summary
4850 && !section.inheritedMembers().isEmpty()) {
4851 m_writer->writeStartElement(dbNamespace, "itemizedlist");
4852 if (m_useITS)
4853 m_writer->writeAttribute(itsNamespace, "translate", "no");
4854 newLine();
4855
4856 generateSectionInheritedList(section, relative);
4857
4858 m_writer->writeEndElement(); // itemizedlist
4859 newLine();
4860 }
4861}
4862
4863void DocBookGenerator::generateSectionInheritedList(const Section &section, const Node *relative)
4864{
4865 // From HtmlGenerator::generateSectionInheritedList.
4866 QList<std::pair<const Aggregate *, int>>::ConstIterator p = section.inheritedMembers().constBegin();
4867 while (p != section.inheritedMembers().constEnd()) {
4868 m_writer->writeStartElement(dbNamespace, "listitem");
4869 m_writer->writeCharacters(QString::number((*p).second) + u' ');
4870 if ((*p).second == 1)
4871 m_writer->writeCharacters(section.singular());
4872 else
4873 m_writer->writeCharacters(section.plural());
4874 m_writer->writeCharacters(" inherited from ");
4875 generateSimpleLink(fileName((*p).first) + '#'
4876 + Generator::cleanRef(section.title().toLower()),
4877 (*p).first->plainFullName(relative));
4878 ++p;
4879 }
4880}
4881
4882/*!
4883 Generate the DocBook page for an entity that doesn't map
4884 to any underlying parsable C++ or QML element.
4885 */
4887{
4888 // From HtmlGenerator::generatePageNode, remove anything related to TOCs.
4889 Q_ASSERT(m_writer == nullptr);
4890 m_writer = startDocument(pn);
4891
4892 generateHeader(pn->doc().title(), pn->subtitle(), pn);
4893 generateBody(pn);
4894 generateAlsoList(pn);
4896
4897 endDocument();
4898}
4899
4900/*!
4901 Generate the DocBook page for a QML type. \qcn is the QML type.
4902 */
4904{
4905 // From HtmlGenerator::generateQmlTypePage.
4906 // Start producing the DocBook file.
4907 Q_ASSERT(m_writer == nullptr);
4908 m_writer = startDocument(qcn);
4909
4911 QString title = qcn->name();
4912 if (qcn->isQmlBasicType())
4913 title.append(" QML Value Type");
4914 else
4915 title.append(" QML Type");
4916
4917 if (qcn->isSingleton())
4918 title.append(" (Singleton)");
4919 else if (qcn->isUncreatable())
4920 title.append(" (Uncreatable)");
4921 // TODO: for ITS attribute, only apply translate="no" on qcn->fullTitle(),
4922 // not its suffix (which should be translated). generateHeader doesn't
4923 // allow this kind of input, the title isn't supposed to be structured.
4924 // Ideally, do the same in HTML.
4925
4926 generateHeader(title, qcn->subtitle(), qcn);
4928 generateStatus(qcn);
4929
4930 if (qcn->isSingleton() || qcn->isUncreatable()) {
4931 m_writer->writeStartElement(dbNamespace, "note");
4932 m_writer->writeStartElement(dbNamespace, "para");
4933 m_writer->writeStartElement(dbNamespace, "emphasis");
4934 m_writer->writeAttribute("role", "bold");
4935 m_writer->writeCharacters("Note: ");
4936 m_writer->writeEndElement(); // emphasis
4937 if (qcn->isSingleton())
4938 m_writer->writeCharacters("This type is a QML singleton. "
4939 "There is only one instance of this type in the QML engine.");
4940 else
4941 m_writer->writeCharacters("This is an uncreatable type. "
4942 "It cannot be instantiated in QML.");
4943 m_writer->writeEndElement(); // para
4944 m_writer->writeEndElement(); // note
4945 }
4946
4947 startSection("details", "Detailed Description");
4948 generateBody(qcn);
4949
4950 generateAlsoList(qcn);
4951
4952 endSection();
4953
4954 Sections sections(qcn);
4955 for (const auto &section : sections.detailsSections()) {
4956 if (!section.isEmpty()) {
4957 startSection(section.title().toLower(), section.title());
4958
4959 for (const auto &member : section.members())
4960 generateDetailedQmlMember(member, qcn);
4961
4962 endSection();
4963 }
4964 }
4965
4966 generateObsoleteQmlMembers(sections);
4967
4970
4971 endDocument();
4972}
4973
4974/*!
4975 Outputs the DocBook detailed documentation for a section
4976 on a QML element reference page.
4977 */
4978void DocBookGenerator::generateDetailedQmlMember(Node *node, const Aggregate *relative)
4979{
4980 // From HtmlGenerator::generateDetailedQmlMember, with elements from
4981 // CppCodeMarker::markedUpQmlItem and HtmlGenerator::generateQmlItem.
4982 auto getQmlPropertyTitle = [&](QmlPropertyNode *n) {
4983 QString title{CodeMarker::extraSynopsis(n, Section::Details)};
4984 if (!title.isEmpty())
4985 title += ' '_L1;
4986 // Finalise generation of name, as per CppCodeMarker::markedUpQmlItem.
4987 if (n->isAttached())
4988 title += n->element() + QLatin1Char('.');
4989 title += n->name() + " : " + n->dataType();
4990
4991 return title;
4992 };
4993
4994 auto generateQmlMethodTitle = [&](Node *node) {
4995 generateSynopsis(node, relative, Section::Details);
4996 };
4997
4998 if (node->isPropertyGroup()) {
4999 const auto *scn = static_cast<const SharedCommentNode *>(node);
5000
5001 QString heading;
5002 if (!scn->name().isEmpty())
5003 heading = scn->name() + " group";
5004 else
5005 heading = node->name();
5006 startSection(scn, heading);
5007 // This last call creates a title for this section. In other words,
5008 // titles are forbidden for the rest of the section, hence the use of
5009 // bridgehead.
5010
5011 const QList<Node *> sharedNodes = scn->collective();
5012 for (const auto &sharedNode : sharedNodes) {
5013 if (sharedNode->isQmlProperty()) {
5014 auto *qpn = static_cast<QmlPropertyNode *>(sharedNode);
5015
5016 m_writer->writeStartElement(dbNamespace, "bridgehead");
5017 m_writer->writeAttribute("renderas", "sect2");
5018 writeXmlId(qpn);
5019 m_writer->writeCharacters(getQmlPropertyTitle(qpn));
5020 m_writer->writeEndElement(); // bridgehead
5021 newLine();
5022
5023 generateDocBookSynopsis(qpn);
5024 }
5025 }
5026 } else if (node->isQmlProperty()) {
5027 auto qpn = static_cast<QmlPropertyNode *>(node);
5028 startSection(qpn, getQmlPropertyTitle(qpn));
5030 } else if (node->isSharedCommentNode()) {
5031 const auto scn = reinterpret_cast<const SharedCommentNode *>(node);
5032 const QList<Node *> &sharedNodes = scn->collective();
5033
5034 // In the section, generate a title for the first node, then bridgeheads for
5035 // the next ones.
5036 int i = 0;
5037 for (const auto &sharedNode : sharedNodes) {
5038 // Ignore this element if there is nothing to generate.
5039 if (!sharedNode->isFunction(Genus::QML) && !sharedNode->isQmlProperty()) {
5040 continue;
5041 }
5042
5043 // Write the tag containing the title.
5044 if (i == 0) {
5045 startSectionBegin(sharedNode);
5046 } else {
5047 m_writer->writeStartElement(dbNamespace, "bridgehead");
5048 m_writer->writeAttribute("renderas", "sect2");
5049 }
5050
5051 // Write the title.
5052 if (sharedNode->isFunction(Genus::QML))
5053 generateQmlMethodTitle(sharedNode);
5054 else if (sharedNode->isQmlProperty())
5055 m_writer->writeCharacters(
5056 getQmlPropertyTitle(static_cast<QmlPropertyNode *>(sharedNode)));
5057
5058 // Complete the title and the synopsis.
5059 if (i == 0)
5060 startSectionEnd();
5061 else
5062 m_writer->writeEndElement(); // bridgehead
5063 generateDocBookSynopsis(sharedNode);
5064 ++i;
5065 }
5066
5067 // If the list is empty, still generate a section.
5068 if (i == 0) {
5069 startSectionBegin(refForNode(node));
5070
5071 if (node->isFunction(Genus::QML))
5072 generateQmlMethodTitle(node);
5073 else if (node->isQmlProperty())
5074 m_writer->writeCharacters(
5075 getQmlPropertyTitle(static_cast<QmlPropertyNode *>(node)));
5076
5077 startSectionEnd();
5078 }
5079 } else if (node->isEnumType(Genus::QML)) {
5080 startSectionBegin(node);
5082 startSectionEnd();
5083 } else { // assume the node is a method/signal handler
5084 startSectionBegin(node);
5085 generateQmlMethodTitle(node);
5086 startSectionEnd();
5087 }
5088
5089 generateStatus(node);
5090 generateBody(node);
5092 generateSince(node);
5094
5095 endSection();
5096}
5097
5098/*!
5099 Recursive writing of DocBook files from the root \a node.
5100 */
5102{
5103 // Mainly from Generator::generateDocumentation, with parts from
5104 // Generator::generateDocumentation and WebXMLGenerator::generateDocumentation.
5105 // Don't generate nodes that are already processed, or if they're not
5106 // supposed to generate output, ie. external, index or images nodes.
5107 if (!node->url().isNull())
5108 return;
5109 if (node->isIndexNode())
5110 return;
5111 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
5112 const NodeContext context = node->createContext();
5113 if (!InclusionFilter::isIncluded(policy, context))
5114 return;
5115 if (node->isExternalPage())
5116 return;
5117
5118 if (node->parent()) {
5119 if (node->isCollectionNode()) {
5120 /*
5121 A collection node collects: groups, C++ modules, or QML
5122 modules. Testing for a CollectionNode must be done
5123 before testing for a TextPageNode because a
5124 CollectionNode is a PageNode at this point.
5125
5126 Don't output an HTML page for the collection node unless
5127 the \group, \module, or \qmlmodule command was actually
5128 seen by qdoc in the qdoc comment for the node.
5129
5130 A key prerequisite in this case is the call to
5131 mergeCollections(cn). We must determine whether this
5132 group, module, or QML module has members in other
5133 modules. We know at this point that cn's members list
5134 contains only members in the current module. Therefore,
5135 before outputting the page for cn, we must search for
5136 members of cn in the other modules and add them to the
5137 members list.
5138 */
5139 auto cn = static_cast<CollectionNode *>(node);
5140 if (cn->wasSeen()) {
5141 m_qdb->mergeCollections(cn);
5142 generateCollectionNode(cn);
5143 } else if (cn->isGenericCollection()) {
5144 // Currently used only for the module's related orphans page
5145 // but can be generalized for other kinds of collections if
5146 // other use cases pop up.
5147 generateGenericCollectionPage(cn);
5148 }
5149 } else if (node->isTextPageNode()) { // Pages.
5150 generatePageNode(static_cast<PageNode *>(node));
5151 } else if (node->isAggregate()) { // Aggregates.
5152 if ((node->isClassNode() || node->isHeader() || node->isNamespace())
5153 && node->docMustBeGenerated()) {
5154 generateCppReferencePage(static_cast<Aggregate *>(node));
5155 } else if (node->isQmlType()) { // Includes QML value types
5156 generateQmlTypePage(static_cast<QmlTypeNode *>(node));
5157 } else if (node->isProxyNode()) {
5158 generateProxyPage(static_cast<Aggregate *>(node));
5159 }
5160 }
5161 }
5162
5163 if (node->isAggregate()) {
5164 auto *aggregate = static_cast<Aggregate *>(node);
5165 for (auto c : aggregate->childNodes()) {
5166 if (node->isPageNode())
5167 generateDocumentation(c);
5168 }
5169 }
5170}
5171
5173{
5174 // Adapted from HtmlGenerator::generateProxyPage.
5175 Q_ASSERT(aggregate->isProxyNode());
5176
5177 // Start producing the DocBook file.
5178 Q_ASSERT(m_writer == nullptr);
5179 m_writer = startDocument(aggregate);
5180
5181 // Info container.
5182 generateHeader(aggregate->plainFullName(), "", aggregate);
5183
5184 // No element synopsis.
5185
5186 // Actual content.
5187 if (!aggregate->doc().isEmpty()) {
5188 startSection("details", "Detailed Description");
5189
5190 generateBody(aggregate);
5191 generateAlsoList(aggregate);
5192
5193 endSection();
5194 }
5195
5196 Sections sections(aggregate);
5197 const SectionVector &detailsSections = sections.detailsSections();
5198
5199 for (const auto &section : detailsSections) {
5200 if (section.isEmpty())
5201 continue;
5202
5203 startSection(section.title().toLower(), section.title());
5204
5205 const QList<Node *> &members = section.members();
5206 for (const auto &member : members) {
5207 if (!member->isClassNode()) {
5208 generateDetailedMember(member, aggregate);
5209 } else {
5210 startSectionBegin();
5211 generateFullName(member, aggregate);
5212 startSectionEnd();
5213
5214 generateBrief(member);
5215 endSection();
5216 }
5217 }
5218
5219 endSection();
5220 }
5221
5223
5224 endDocument();
5225}
5226
5227/*!
5228 Generate the HTML page for a group, module, or QML module.
5229 */
5231{
5232 // Adapted from HtmlGenerator::generateCollectionNode.
5233 // Start producing the DocBook file.
5234 Q_ASSERT(m_writer == nullptr);
5235 m_writer = startDocument(cn);
5236
5237 // Info container.
5238 generateHeader(cn->doc().title(), cn->subtitle(), cn);
5239
5240 // Element synopsis.
5242
5243 // Generate brief for C++ modules, status for all modules.
5244 if (cn->genus() != Genus::DOC && cn->genus() != Genus::DontCare) {
5245 if (cn->isModule())
5246 generateBrief(cn);
5247 generateStatus(cn);
5248 generateSince(cn);
5249 }
5250
5251 // Actual content.
5252 if (cn->isModule()) {
5253 if (!cn->noAutoList()) {
5255 if (!nmm.isEmpty()) {
5256 startSection("namespaces", "Namespaces");
5257 generateAnnotatedList(cn, nmm.values(), "namespaces");
5258 endSection();
5259 }
5260 nmm = cn->getMembers([](const Node *n){ return n->isClassNode(); });
5261 if (!nmm.isEmpty()) {
5262 startSection("classes", "Classes");
5263 generateAnnotatedList(cn, nmm.values(), "classes");
5264 endSection();
5265 }
5266 }
5267 }
5268
5269 bool generatedTitle = false;
5270 if (cn->isModule() && !cn->doc().briefText().isEmpty()) {
5271 startSection("details", "Detailed Description");
5272 generatedTitle = true;
5273 }
5274 // The anchor is only needed if the node has a body.
5275 else if (
5276 // generateBody generates something.
5277 !cn->doc().body().isEmpty() ||
5278 // generateAlsoList generates something.
5279 !cn->doc().alsoList().empty() ||
5280 // generateAnnotatedList generates something.
5281 (!cn->noAutoList() && (cn->isGroup() || cn->isQmlModule()))) {
5282 writeAnchor("details");
5283 }
5284
5285 generateBody(cn);
5286 generateAlsoList(cn);
5287
5288 if (!cn->noAutoList() && (cn->isGroup() || cn->isQmlModule()))
5289 generateAnnotatedList(cn, cn->members(), "members", AutoSection);
5290
5291 if (generatedTitle)
5292 endSection();
5293
5295
5296 endDocument();
5297}
5298
5299/*!
5300 Generate the HTML page for a generic collection. This is usually
5301 a collection of C++ elements that are related to an element in
5302 a different module.
5303 */
5305{
5306 // Adapted from HtmlGenerator::generateGenericCollectionPage.
5307 // TODO: factor out this code to generate a file name.
5308 QString name = cn->name().toLower();
5309 name.replace(QChar(' '), QString("-"));
5310 QString filename = cn->tree()->physicalModuleName() + "-" + name + "." + fileExtension();
5311
5312 // Start producing the DocBook file.
5313 Q_ASSERT(m_writer == nullptr);
5314 m_writer = startGenericDocument(cn, filename);
5315
5316 // Info container.
5317 generateHeader(cn->fullTitle(), cn->subtitle(), cn);
5318
5319 // Element synopsis.
5321
5322 // Actual content.
5323 m_writer->writeStartElement(dbNamespace, "para");
5324 m_writer->writeCharacters("Each function or type documented here is related to a class or "
5325 "namespace that is documented in a different module. The reference "
5326 "page for that class or namespace will link to the function or type "
5327 "on this page.");
5328 m_writer->writeEndElement(); // para
5329
5330 const CollectionNode *cnc = cn;
5331 const QList<Node *> members = cn->members();
5332 for (const auto &member : members)
5333 generateDetailedMember(member, cnc);
5334
5336
5337 endDocument();
5338}
5339
5340void DocBookGenerator::generateFullName(const Node *node, const Node *relative)
5341{
5342 Q_ASSERT(node);
5343 Q_ASSERT(relative);
5344
5345 // From Generator::appendFullName.
5346 m_writer->writeStartElement(dbNamespace, "link");
5347 m_writer->writeAttribute(xlinkNamespace, "href", fullDocumentLocation(node));
5348 m_writer->writeAttribute(xlinkNamespace, "role", targetType(node));
5349 m_writer->writeCharacters(node->fullName(relative));
5350 m_writer->writeEndElement(); // link
5351}
5352
5353void DocBookGenerator::generateFullName(const Node *apparentNode, const QString &fullName,
5354 const Node *actualNode)
5355{
5356 Q_ASSERT(apparentNode);
5357 Q_ASSERT(actualNode);
5358
5359 // From Generator::appendFullName.
5360 m_writer->writeStartElement(dbNamespace, "link");
5361 m_writer->writeAttribute(xlinkNamespace, "href", fullDocumentLocation(actualNode));
5362 m_writer->writeAttribute("role", targetType(actualNode));
5363 m_writer->writeCharacters(fullName);
5364 m_writer->writeEndElement(); // link
5365}
5366
5367QT_END_NAMESPACE
#define ATOM_LIST_BULLET
Definition atom.h:211
#define ATOM_FORMATTING_TELETYPE
Definition atom.h:206
#define ATOM_LIST_LOWERALPHA
Definition atom.h:214
#define ATOM_FORMATTING_UNDERLINE
Definition atom.h:209
#define ATOM_LIST_UPPERALPHA
Definition atom.h:217
#define ATOM_FORMATTING_NOTRANSLATE
Definition atom.h:201
#define ATOM_LIST_TAG
Definition atom.h:212
#define ATOM_LIST_LOWERROMAN
Definition atom.h:215
#define ATOM_FORMATTING_SUBSCRIPT
Definition atom.h:204
#define ATOM_FORMATTING_BOLD
Definition atom.h:197
#define ATOM_FORMATTING_TRADEMARK
Definition atom.h:207
#define ATOM_LIST_VALUE
Definition atom.h:213
#define ATOM_FORMATTING_ITALIC
Definition atom.h:199
#define ATOM_LIST_UPPERROMAN
Definition atom.h:218
#define ATOM_FORMATTING_LINK
Definition atom.h:200
#define ATOM_FORMATTING_SUPERSCRIPT
Definition atom.h:205
#define ATOM_FORMATTING_UICONTROL
Definition atom.h:208
#define ATOM_FORMATTING_PARAMETER
Definition atom.h:202
The Atom class is the fundamental unit for representing documents internally.
Definition atom.h:19
AtomType type() const
Return the type of this atom.
Definition atom.h:146
@ CaptionLeft
Definition atom.h:29
@ ListTagLeft
Definition atom.h:69
@ DivRight
Definition atom.h:44
@ GeneratedList
Definition atom.h:54
@ BriefRight
Definition atom.h:27
@ CodeQuoteArgument
Definition atom.h:33
@ WarningLeft
Definition atom.h:112
@ SinceList
Definition atom.h:91
@ TableOfContentsLeft
Definition atom.h:106
@ TableOfContentsRight
Definition atom.h:107
@ Keyword
Definition atom.h:61
@ TableHeaderRight
Definition atom.h:101
@ FormatElse
Definition atom.h:49
@ InlineImage
Definition atom.h:60
@ TableRowRight
Definition atom.h:103
@ LineBreak
Definition atom.h:64
@ SnippetCommand
Definition atom.h:94
@ TableRowLeft
Definition atom.h:102
@ Nop
Definition atom.h:76
@ LegaleseRight
Definition atom.h:63
@ ListTagRight
Definition atom.h:70
@ CaptionRight
Definition atom.h:30
@ NavLink
Definition atom.h:75
@ ListItemNumber
Definition atom.h:68
@ SinceTagRight
Definition atom.h:93
@ DetailsLeft
Definition atom.h:39
@ RawString
Definition atom.h:84
@ Target
Definition atom.h:108
@ AnnotatedList
Definition atom.h:22
@ SectionRight
Definition atom.h:86
@ SectionHeadingLeft
Definition atom.h:87
@ TableLeft
Definition atom.h:98
@ ListItemRight
Definition atom.h:72
@ DeprecatedLeft
Definition atom.h:37
@ Image
Definition atom.h:56
@ ListItemLeft
Definition atom.h:71
@ String
Definition atom.h:97
@ ListLeft
Definition atom.h:67
@ NavAutoLink
Definition atom.h:74
@ CodeQuoteCommand
Definition atom.h:34
@ BriefLeft
Definition atom.h:26
@ ImageText
Definition atom.h:57
@ LegaleseLeft
Definition atom.h:62
@ ParaRight
Definition atom.h:80
@ FormattingLeft
Definition atom.h:52
@ FormattingRight
Definition atom.h:53
@ SectionHeadingRight
Definition atom.h:88
@ Link
Definition atom.h:65
@ ImportantLeft
Definition atom.h:58
@ FormatEndif
Definition atom.h:50
@ BR
Definition atom.h:25
@ DetailsRight
Definition atom.h:40
@ AutoLink
Definition atom.h:23
@ SnippetLocation
Definition atom.h:96
@ TableHeaderLeft
Definition atom.h:100
@ ComparesRight
Definition atom.h:36
@ DeprecatedRight
Definition atom.h:38
@ SectionLeft
Definition atom.h:85
@ LinkNode
Definition atom.h:66
@ HR
Definition atom.h:55
@ DivLeft
Definition atom.h:43
@ TableItemLeft
Definition atom.h:104
@ BaseName
Definition atom.h:24
@ ComparesLeft
Definition atom.h:35
@ FormatIf
Definition atom.h:51
@ SnippetIdentifier
Definition atom.h:95
@ NoteLeft
Definition atom.h:77
@ DetailsSummaryRight
Definition atom.h:42
@ DetailsSummaryLeft
Definition atom.h:41
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:143
The ClassNode represents a C++ class.
Definition classnode.h:23
bool isQmlNativeType()
Definition classnode.h:54
virtual Atom::AtomType atomType() const
Definition codemarker.h:24
A class for holding the members of a collection of doc pages.
const NodeList & members() const
NodeMap getMembers(NodeType type) const
void generatePageNode(PageNode *pn)
Generate the DocBook page for an entity that doesn't map to any underlying parsable C++ or QML elemen...
void generateQmlTypePage(QmlTypeNode *qcn)
Generate the DocBook page for a QML type.
void generateAlsoList(const Node *node) override
void generateQmlRequisites(const QmlTypeNode *qcn)
Lists the required imports and includes.
void generateAddendum(const Node *node, Generator::Addendum type, CodeMarker *marker, AdmonitionPrefix prefix) override
Generates an addendum note of type type for node.
void generateHeader(const Text &title, const Node *node)
Generates the opening portion of the DocBook header — {<db:info>} and the title element.
void initializeGenerator() override
Initializes the DocBook output generator's data structures from the configuration (Config).
bool generateText(const Text &text, const Node *relative) override
Generate the documentation for relative.
void finishHeader(const Node *node)
Emits the tail of the DocBook header — product, edition, titleabbrev, navigation links,...
void generateCppReferencePage(Node *node)
Generate a reference page for the C++ class, namespace, or header file documented in node.
void generateSortedQmlNames(const Node *base, const QStringList &knownTypes, const NodeList &subs)
DocBookGenerator(FileResolver &file_resolver)
bool generateThreadSafeness(const Node *node)
Generates text that explains how threadsafe and/or reentrant node is.
void generateCollectionNode(CollectionNode *cn)
Generate the HTML page for a group, module, or QML module.
void generateHeader(const Text &title, const QString &subtitle, const Node *node)
void generateDocBookSynopsis(const Node *node)
Generate the metadata for the given node in DocBook.
void generateGenericCollectionPage(CollectionNode *cn)
Generate the HTML page for a generic collection.
void generateList(const Node *relative, const QString &selector, Qt::SortOrder sortOrder=Qt::AscendingOrder)
void generateBody(const Node *node)
Generate the body of the documentation from the qdoc comment found with the entity represented by the...
qsizetype generateAtom(const Atom *atom, const Node *relative, CodeMarker *) override
Generate DocBook from an instance of Atom.
void generateProxyPage(Aggregate *aggregate)
bool generateStatus(const Node *node)
void generateRequisites(const Aggregate *inner)
Lists the required imports and includes.
void generateSortedNames(const ClassNode *cn, const QList< RelatedClass > &rc)
void generateDocumentation(Node *node) override
Recursive writing of DocBook files from the root node.
void generateGroupReferenceText(const Node *node)
Return a string representing a text that exposes information about the groups that the node is part o...
QString format() const override
Returns the format identifier for this producer (e.g., "HTML", "DocBook", "template").
void generateExampleFilePage(const PageNode *en, ResolvedFile resolved_file, CodeMarker *=nullptr) override
Generate a file with the contents of a C++ or QML source file.
QString fileExtension() const override
Returns "xml" for this subclass of Generator.
bool generateSince(const Node *node)
Definition doc.h:32
const Location & location() const
Returns the starting location of a qdoc comment.
Definition doc.cpp:89
static void quoteFromFile(const Location &location, Quoter &quoter, ResolvedFile resolved_file, CodeMarker *marker=nullptr)
Definition doc.cpp:468
const Text & body() const
Definition doc.cpp:114
Text briefText(bool inclusive=false) const
Definition doc.cpp:126
Text deprecationText() const
Definition doc.cpp:131
bool isAnonymous() const
Definition enumnode.h:34
const TypedefNode * flagsType() const
Definition enumnode.h:40
Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are re...
This node is used to represent any kind of function being documented.
bool isMacroWithoutParams() const
bool isPrivateSignal() const
bool isOverride() const
const Parameters & parameters() const
bool isPureVirtual() const override
bool isRef() const
bool isMAssign() const
bool isVirtual() const
bool isCAssign() const
bool isInvokable() const
bool hasOverloads() const
Returns true if this function has overloads.
bool isDtor() const
bool isSignal() const
bool isQmlSignal() const
bool isMacro() const override
returns true if either FunctionNode::isMacroWithParams() or FunctionNode::isMacroWithoutParams() retu...
bool isOverload() const
bool isRefRef() const
bool isDeletedAsWritten() const
bool isCCtor() const
bool isMCtor() const
bool isFinal() const
bool isCtor() const
bool isExplicitlyDefaulted() const
bool hasAssociatedProperties() const
bool isSlot() const
bool generateComparisonCategory(const Node *node, CodeMarker *marker=nullptr)
static void setQmlTypeContext(QmlTypeNode *t)
Definition generator.h:92
const Atom * generateAtomList(const Atom *atom, const Node *relative, CodeMarker *marker, bool generate, int &numGeneratedAtoms)
void unknownAtom(const Atom *atom)
static bool matchAhead(const Atom *atom, Atom::AtomType expectedAtomType)
void generateEnumValuesForQmlReference(const Node *node, CodeMarker *marker)
virtual int skipAtoms(const Atom *atom, Atom::AtomType type) const
@ AssociatedProperties
Definition generator.h:47
@ PrivateSignal
Definition generator.h:45
@ QmlSignalHandler
Definition generator.h:46
@ BindableProperty
Definition generator.h:48
@ OverloadNote
Definition generator.h:49
bool generateComparisonTable(const Node *node)
Generates a table of comparison categories for node, combining both self-comparison (from \compares) ...
virtual void initializeGenerator()
No-op base implementation.
void initializeTextOutput()
Resets the variables used during text output.
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
This class represents a C++ namespace.
NamespaceNode * docNode() const
Returns a pointer to the NamespaceNode that represents where the namespace documentation is actually ...
Tree * tree() const override
Returns a pointer to the Tree that contains this NamespaceNode.
Interface implemented by Node subclasses that can refer to a C++ enum.
Definition nativeenum.h:28
virtual const NativeEnum * nativeEnum() const =0
Encapsulates information about native (C++) enum values.
Definition nativeenum.h:14
const EnumNode * enumNode() const
Definition nativeenum.h:19
A PageNode is a Node that generates a documentation page.
Definition pagenode.h:19
bool noAutoList() const
Returns the value of the no auto-list flag.
Definition pagenode.h:42
The Parameter class describes one function parameter.
Definition parameter.h:14
This class describes one instance of using the Q_PROPERTY macro.
This class provides exclusive access to the qdoc database, which consists of a forrest of trees and a...
static QDocDatabase * qdocDB()
Creates the singleton.
Status
Specifies the status of the QQmlIncubator.
bool isDefault() const override
Returns true if the QML property node is marked as default.
bool isReadOnly() const
Returns true if this QML property node is marked as a read-only property.
bool isRequired() const
Const overloads that delegate to the resolving non-const versions when the attribute hasn't been cach...
bool isAttached() const override
Returns true if the QML property or QML method node is marked as attached.
ClassNode * classNode() const override
If this is a QmlTypeNode, this function returns the pointer to the C++ ClassNode that this QML type r...
Definition qmltypenode.h:27
bool isUncreatable() const
Definition qmltypenode.h:35
static void subclasses(const Node *base, NodeList &subs, bool recurse=false)
Loads the list subs with the nodes of all the subclasses of base.
bool isSingleton() const
Definition qmltypenode.h:31
QmlTypeNode * qmlBaseNode() const override
If this Aggregate is a QmlTypeNode, this function returns a pointer to the QmlTypeNode that is its ba...
Definition qmltypenode.h:54
CollectionNode * logicalModule() const override
If this is a QmlTypeNode, a pointer to its QML module is returned, which is a pointer to a Collection...
Definition qmltypenode.h:47
A class for containing the elements of one documentation section.
Definition sections.h:17
const NodeVector & obsoleteMembers() const
Definition sections.h:54
void appendMembers(const NodeVector &nv)
Definition sections.h:55
@ Summary
Definition sections.h:19
@ Details
Definition sections.h:19
@ Accessors
Definition sections.h:19
@ AllMembers
Definition sections.h:19
const NodeVector & members() const
Definition sections.h:46
Style style() const
Definition sections.h:41
A class for creating vectors of collections for documentation.
Definition sections.h:80
const Aggregate * aggregate() const
Definition sections.h:161
Sections(const Aggregate *aggregate)
This constructor builds the section vectors based on the type of the aggregate node.
Definition sections.cpp:372
bool hasObsoleteMembers(SectionPtrVector *summary_spv, SectionPtrVector *details_spv) const
Returns true if any sections in this object contain obsolete members.
Definition sections.cpp:967
SectionVector & detailsSections()
Definition sections.h:152
Definition text.h:12
static Text sectionHeading(const Atom *sectionBegin)
Definition text.cpp:157
const Atom * firstAtom() const
Definition text.h:33
bool isEmpty() const
Definition text.h:30
Text & operator=(const Text &text)
Definition text.cpp:29
Text()
Definition text.cpp:12
const Atom * lastAtom() const
Definition text.h:34
Atom * lastAtom()
Definition text.h:22
bool isStatic() const override
Returns true if the FunctionNode represents a static function.
static bool isOneColumnValueTable(const Atom *atom)
Determines whether the list atom should be shown with just one column (value).
static void rewritePropertyBrief(const Atom *atom, const Node *relative)
Rewrites the brief of this node depending on its first word.
static int hOffset(const Node *node)
Header offset depending on the type of the node.
static bool hasBrief(const Node *node)
Do not display.
XmlGenerator(FileResolver &file_resolver)
static const QRegularExpression m_funcLeftParen
static NodeType typeFromString(const Atom *atom)
Returns the type of this atom as an enumeration.
#define CONFIG_DOCBOOKEXTENSIONS
Definition config.h:395
#define CONFIG_EXAMPLES
Definition config.h:399
#define CONFIG_URL
Definition config.h:468
#define CONFIG_PRELIMINARY
Definition config.h:442
#define CONFIG_DESCRIPTION
Definition config.h:394
#define CONFIG_PROJECT
Definition config.h:444
#define CONFIG_EXAMPLESINSTALLPATH
Definition config.h:400
#define CONFIG_NATURALLANGUAGE
Definition config.h:433
#define CONFIG_PRODUCTNAME
Definition config.h:443
#define CONFIG_BUILDVERSION
Definition config.h:385
static const char xlinkNamespace[]
static QString nodeToSynopsisTag(const Node *node)
QString removeCodeMarkers(const QString &code)
static const char dbNamespace[]
QString taggedNode(const Node *node)
static const char itsNamespace[]
NodeType
Definition genustypes.h:165
Provides human-readable descriptions of QDoc nodes.
constexpr std::size_t MultilineTemplateParamThreshold
QList< Node * > NodeList
Definition node.h:45
QList< Node * > NodeVector
Definition node.h:47
QMap< QString, Node * > NodeMap
Definition node.h:48
QMap< QString, NodeMap > NodeMapMap
Definition node.h:49
QMap< QString, CollectionNode * > CNMap
Definition node.h:52
QT_BEGIN_NAMESPACE typedef QMultiMap< Text, const Node * > TextToNodeMap
QMultiMap< QString, Node * > NodeMultiMap
Definition generator.h:36
QList< const Section * > SectionPtrVector
Definition sections.h:77
QList< Section > SectionVector
Definition sections.h:76
@ Active
Definition status.h:14
@ InternalAuto
Definition status.h:16
@ Internal
Definition status.h:15
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.
Definition node.h:100
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition node.h:239
bool isQmlNode() const
Returns true if this node's Genus value is QML.
Definition node.h:121
bool isEnumType(Genus g) const
Definition node.h:98
bool isGroup() const
Returns true if the node type is Group.
Definition node.h:105
virtual bool docMustBeGenerated() const
This function is called to perform a test to decide if the node must have documentation generated.
Definition node.h:198
bool isPrivate() const
Returns true if this node's access is Private.
Definition node.h:113
bool isNamespace() const
Returns true if the node type is Namespace.
Definition node.h:110
bool isTypedef() const
Returns true if the node type is Typedef.
Definition node.h:128
bool isQmlBasicType() const
Returns true if the node type is QmlBasicType.
Definition node.h:119
bool isQmlType() const
Returns true if the node type is QmlType or QmlValueType.
Definition node.h:123
bool isSharedCommentNode() const
Returns true if the node type is SharedComment.
Definition node.h:126
virtual bool isInternal() const
Returns true if the node's status is Internal, or if its parent is a class with Internal status.
Definition node.cpp:868
bool isHeader() const
Returns true if the node type is HeaderFile.
Definition node.h:106
NodeType nodeType() const override
Returns this node's type.
Definition node.h:82
Genus genus() const override
Returns this node's Genus.
Definition node.h:85
virtual bool isPageNode() const
Returns true if this node represents something that generates a documentation page.
Definition node.h:150
bool isEnumType() const
Returns true if the node type is Enum.
Definition node.h:94
virtual Status status() const
Returns the node's status value.
Definition node.h:243
virtual bool isTextPageNode() const
Returns true if the node is a PageNode but not an Aggregate.
Definition node.h:155
Aggregate * parent() const
Returns the node's parent pointer, that is, the aggregate under which the node is documented.
Definition node.h:211
bool isVariable() const
Returns true if the node type is Variable.
Definition node.h:133
virtual bool isDeprecated() const
Returns true if this node's status is Deprecated.
Definition node.h:136
virtual bool isAggregate() const
Returns true if this node is an aggregate, which means it inherits Aggregate and can therefore have c...
Definition node.h:138
static bool nodeNameLessThan(const Node *first, const Node *second)
Returns true if the node n1 is less than node n2.
Definition node.cpp:111
const Location & location() const
If this node's definition location is empty, this function returns this node's declaration location.
Definition node.h:235
bool isProxyNode() const
Returns true if the node type is Proxy.
Definition node.h:115
Access access() const
Returns the node's Access setting, which can be Public, Protected, or Private.
Definition node.h:232
bool isFunction(Genus g=Genus::DontCare) const
Returns true if this is a FunctionNode and its Genus is set to g.
Definition node.h:101
ThreadSafeness threadSafeness() const
Returns the thread safeness value for whatever this node represents.
Definition node.cpp:845
virtual bool isMarkedReimp() const
Returns true if the FunctionNode is marked as a reimplemented function.
Definition node.h:152
bool isProperty() const
Returns true if the node type is Property.
Definition node.h:114
virtual Tree * tree() const
Returns a pointer to the Tree this node is in.
Definition node.cpp:899
NodeContext createContext() const
Definition node.cpp:175
bool isModule() const
Returns true if the node type is Module.
Definition node.h:108
bool isClass() const
Returns true if the node type is Class.
Definition node.h:91
virtual bool isPropertyGroup() const
Returns true if the node is a SharedCommentNode for documenting multiple C++ properties or multiple Q...
Definition node.h:153
ThreadSafeness
An unsigned char that specifies the degree of thread-safeness of the element.
Definition node.h:58
@ ThreadSafe
Definition node.h:62
@ NonReentrant
Definition node.h:60
@ Reentrant
Definition node.h:61
bool isSharingComment() const
This function returns true if the node is sharing a comment with other nodes.
Definition node.h:250
bool hasDoc() const
Returns true if this node is documented, or it represents a documented node read from the index ('had...
Definition node.cpp:942
@ NextLink
Definition node.h:73
@ StartLink
Definition node.h:73
@ PreviousLink
Definition node.h:73
bool isRelatedNonmember() const
Returns true if this is a related nonmember of something.
Definition node.h:124
virtual bool isClassNode() const
Returns true if this is an instance of ClassNode.
Definition node.h:145
virtual bool isCollectionNode() const
Returns true if this is an instance of CollectionNode.
Definition node.h:146
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.
Definition node.cpp:161
Aggregate * declarationParent() const
Returns the aggregate in whose C++ scope the node was declared, or null if the node was not adopted b...
Definition node.h:212
bool isQmlModule() const
Returns true if the node type is QmlModule.
Definition node.h:120
@ SignatureReturnType
Definition node.h:68
@ SignaturePlain
Definition node.h:66
bool isExample() const
Returns true if the node type is Example.
Definition node.h:99
bool isIndexNode() const
Returns true if this node was created from something in an index file.
Definition node.h:107
bool isQmlProperty() const
Returns true if the node type is QmlProperty.
Definition node.h:122
A class for parsing and managing a function parameter list.
Definition main.cpp:28
bool isEmpty() const
Definition parameters.h:32
const Parameter & at(int i) const
Definition parameters.h:36
int count() const
Definition parameters.h:34
std::size_t visibleParameterCount() const
Returns the number of template parameters that are visible in rendered output — SFINAE-annotated para...
ValuedDeclaration valued_declaration
Represents a file that is reachable by QDoc based on its current configuration.