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
webxmlgenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
5
6#include "aggregate.h"
8#include "config.h"
11#include "node.h"
12#include "nodecontext.h"
13#include "propertynode.h"
14#include "qdocdatabase.h"
15#include "quoter.h"
17#include "utilities.h"
18#include "textutils.h"
19
20#include <QtCore/qxmlstream.h>
21
23
24using namespace Qt::StringLiterals;
25
26static CodeMarker *marker_ = nullptr;
27
29
31{
32 m_indexWriteState = {};
34}
35
40
42{
43 return "WebXML";
44}
45
47{
48 // As this is meant to be an intermediate format,
49 // use .html for internal references. The name of
50 // the output file is set separately in
51 // beginSubPage() calls.
52 return "html";
53}
54
55/*!
56 Most of the output is generated by QDocIndexFiles and the append() callback.
57 Some pages produce supplementary output while being generated, and that's
58 handled here.
59*/
60qsizetype WebXMLGenerator::generateAtom(const Atom *atom, const Node *relative, CodeMarker *marker)
61{
62 if (m_supplement && currentWriter)
63 addAtomElements(*currentWriter, atom, relative, marker);
64 return 0;
65}
66
68{
69 QByteArray data;
70 QXmlStreamWriter writer(&data);
71 writer.setAutoFormatting(true);
72 beginSubPage(aggregate, Generator::fileName(aggregate, "webxml"));
73 writer.writeStartDocument();
74 writer.writeStartElement("WebXML");
75 writer.writeStartElement("document");
76
77 generateIndexSections(writer, aggregate);
78
79 writer.writeEndElement(); // document
80 writer.writeEndElement(); // WebXML
81 writer.writeEndDocument();
82
83 out() << data;
84 endSubPage();
85}
86
88{
89 QByteArray data;
90 currentWriter.emplace(&data);
91 currentWriter->setAutoFormatting(true);
92 beginSubPage(pn, Generator::fileName(pn, "webxml"));
93 currentWriter->writeStartDocument();
94 currentWriter->writeStartElement("WebXML");
95 currentWriter->writeStartElement("document");
96
97 generateIndexSections(*currentWriter, pn);
98
99 currentWriter->writeEndElement(); // document
100 currentWriter->writeEndElement(); // WebXML
101 currentWriter->writeEndDocument();
102
103 out() << data;
104 endSubPage();
105}
106
107void WebXMLGenerator::generateExampleFilePage(const PageNode *en, ResolvedFile resolved_file, CodeMarker* /* marker */)
108{
109 // TODO: [generator-insufficient-structural-abstraction]
110
111 QByteArray data;
112 QXmlStreamWriter writer(&data);
113 writer.setAutoFormatting(true);
114 beginSubPage(en, linkForExampleFile(resolved_file.get_query(), "webxml"));
115 writer.writeStartDocument();
116 writer.writeStartElement("WebXML");
117 writer.writeStartElement("document");
118 writer.writeStartElement("page");
119 writer.writeAttribute("name", resolved_file.get_query());
120 writer.writeAttribute("href", linkForExampleFile(resolved_file.get_query()));
121 const QString title = exampleFileTitle(static_cast<const ExampleNode *>(en), resolved_file.get_query());
122 writer.writeAttribute("title", title);
123 writer.writeAttribute("fulltitle", title);
124 writer.writeAttribute("subtitle", resolved_file.get_query());
125 writer.writeStartElement("description");
126
127 if (Config::instance().get(CONFIG_LOCATIONINFO).asBool()) {
128 writer.writeAttribute("path", resolved_file.get_path());
129 writer.writeAttribute("line", "0");
130 writer.writeAttribute("column", "0");
131 }
132
133 Quoter quoter;
134 Doc::quoteFromFile(en->doc().location(), quoter, std::move(resolved_file));
135 QString code = quoter.quoteTo(en->location(), QString(), QString());
136 writer.writeTextElement("code", trimmedTrailing(code, QString(), QString()));
137
138 writer.writeEndElement(); // description
139 writer.writeEndElement(); // page
140 writer.writeEndElement(); // document
141 writer.writeEndElement(); // WebXML
142 writer.writeEndDocument();
143
144 out() << data;
145 endSubPage();
146}
147
148void WebXMLGenerator::generateIndexSections(QXmlStreamWriter &writer, Node *node)
149{
150 marker_ = CodeMarker::markerForFileName(node->location().filePath());
151 const Config &config = Config::instance();
153 context.documentLocation = [this](const Node *target) {
154 return fullDocumentLocation(target);
155 };
156 context.inclusionPolicy = config.createInclusionPolicy();
157 context.storeLocationInfo = config.get(CONFIG_LOCATIONINFO).asBool();
159 auto qdocIndexFiles = QDocIndexFiles::qdocIndexFiles();
160 if (qdocIndexFiles) {
161 qdocIndexFiles->generateIndexSections(writer, node, context, m_indexWriteState, this);
162 // generateIndexSections returns early for collection nodes (groups,
163 // modules, QML modules, concepts) so their member listings can be
164 // written last in an index file. When rendering a single collection
165 // page, that leaves the document empty, so emit the section explicitly.
166 if (node->isCollectionNode())
167 std::ignore = qdocIndexFiles->generateIndexSection(writer, node, context,
168 m_indexWriteState, this);
169 }
170}
171
172// Handles callbacks from QDocIndexFiles to add documentation to node
173void WebXMLGenerator::append(QXmlStreamWriter &writer, Node *node)
174{
175 Q_ASSERT(marker_);
176
177 // The index walk doesn't visit shared comment nodes; capture the prose here
178 const Doc &effectiveDoc = (node->doc().body().isEmpty() && node->isSharingComment())
180 : node->doc();
181
182 writer.writeStartElement("description");
183 if (Config::instance().get(CONFIG_LOCATIONINFO).asBool()) {
184 writer.writeAttribute("path", effectiveDoc.location().filePath());
185 writer.writeAttribute("line", QString::number(effectiveDoc.location().lineNo()));
186 writer.writeAttribute("column", QString::number(effectiveDoc.location().columnNo()));
187 }
188
189 if (node->isTextPageNode())
190 generateRelations(writer, node);
191
192 if (node->isModule()) {
193 writer.writeStartElement("generatedlist");
194 writer.writeAttribute("contents", "classesbymodule");
195 auto *cnn = static_cast<CollectionNode *>(node);
196
197 if (cnn->hasNamespaces()) {
198 writer.writeStartElement("section");
199 writer.writeStartElement("heading");
200 writer.writeAttribute("level", "1");
201 writer.writeCharacters("Namespaces");
202 writer.writeEndElement(); // heading
203 NodeMap namespaces{cnn->getMembers(NodeType::Namespace)};
204 generateAnnotatedList(writer, node, namespaces);
205 writer.writeEndElement(); // section
206 }
207 if (cnn->hasClasses()) {
208 writer.writeStartElement("section");
209 writer.writeStartElement("heading");
210 writer.writeAttribute("level", "1");
211 writer.writeCharacters("Classes");
212 writer.writeEndElement(); // heading
213 NodeMap classes{cnn->getMembers([](const Node *n){ return n->isClassNode(); })};
214 generateAnnotatedList(writer, node, classes);
215 writer.writeEndElement(); // section
216 }
217 writer.writeEndElement(); // generatedlist
218 }
219
220 m_inLink = m_inSectionHeading = m_hasQuotingInformation = false;
221
222 if (const Text reason = effectiveDoc.deprecationText(); !reason.isEmpty()) {
223 writer.writeStartElement("deprecated"_L1);
224 const Atom *atom = reason.firstAtom();
225 while (atom)
226 atom = addAtomElements(writer, atom, node, marker_);
227 writer.writeEndElement(); // deprecated
228 }
229
230 const Atom *atom = effectiveDoc.body().firstAtom();
231 while (atom)
232 atom = addAtomElements(writer, atom, node, marker_);
233
234 QList<Text> alsoList = effectiveDoc.alsoList();
235 supplementAlsoList(node, alsoList);
236
237 if (!alsoList.isEmpty()) {
238 writer.writeStartElement("see-also");
239 for (const auto &item : alsoList) {
240 const auto *atom = item.firstAtom();
241 while (atom)
242 atom = addAtomElements(writer, atom, node, marker_);
243 }
244 writer.writeEndElement(); // see-also
245 }
246
247 if (node->isExample()) {
248 m_supplement = true;
250 m_supplement = false;
251 } else if (node->isGroup()) {
252 auto *cn = static_cast<CollectionNode *>(node);
253 if (!cn->noAutoList())
254 generateAnnotatedList(writer, node, cn->members());
255 }
256
257 writer.writeEndElement(); // description
258}
259
261{
262 // Don't generate nodes that are already processed, or if they're not supposed to
263 // generate output, ie. external, index or images nodes.
264 if (!node->url().isNull() || node->isExternalPage() || node->isIndexNode())
265 return;
266
267 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
268 const NodeContext context = node->createContext();
269 if (!InclusionFilter::isIncluded(policy, context))
270 return;
271
272 if (node->parent()) {
273 if (node->isNamespace() || node->isClassNode() || node->isHeader())
274 generateCppReferencePage(static_cast<Aggregate *>(node), nullptr);
275 else if (node->isCollectionNode()) {
276 if (node->wasSeen()) {
277 // see remarks in base class impl.
278 m_qdb->mergeCollections(static_cast<CollectionNode *>(node));
279 generatePageNode(static_cast<PageNode *>(node), nullptr);
280 }
281 } else if (node->isTextPageNode())
282 generatePageNode(static_cast<PageNode *>(node), nullptr);
283 // else if TODO: anything else?
284 }
285
286 if (node->isAggregate()) {
287 auto *aggregate = static_cast<Aggregate *>(node);
288 for (auto c : aggregate->childNodes()) {
289 if ((c->isAggregate() || c->isTextPageNode() || c->isCollectionNode())
290 && !c->isPrivate())
291 generateDocumentation(c);
292 }
293 }
294}
295
296const Atom *WebXMLGenerator::addAtomElements(QXmlStreamWriter &writer, const Atom *atom,
297 const Node *relative, CodeMarker *marker)
298{
299 bool keepQuoting = false;
300
301 if (!atom)
302 return nullptr;
303
304 switch (atom->type()) {
305 case Atom::AnnotatedList: {
306 const CollectionNode *cn = m_qdb->getCollectionNode(atom->string(), NodeType::Group);
307 if (cn)
308 generateAnnotatedList(writer, relative, cn->members());
309 } break;
310 case Atom::AutoLink: {
311 const Node *node{nullptr};
312 QString link{};
313
314 if (!m_inLink && !m_inSectionHeading) {
315 link = getAutoLink(atom, relative, &node, Genus::API);
316
317 if (!link.isEmpty() && node && node->isDeprecated()
318 && relative->parent() != node && !relative->isDeprecated()) {
319 link.clear();
320 }
321 }
322
323 startLink(writer, atom, node, link);
324
325 writer.writeCharacters(atom->string());
326
327 if (m_inLink) {
328 writer.writeEndElement(); // link
329 m_inLink = false;
330 }
331
332 break;
333 }
334 case Atom::BaseName:
335 break;
337 const Atom *end = atom->find(Atom::DeprecatedRight);
338 return end ? end->next() : nullptr;
339 }
341 break;
342 case Atom::BriefLeft:
343
344 writer.writeStartElement("brief");
345 switch (relative->nodeType()) {
347 writer.writeCharacters("This property");
348 break;
350 writer.writeCharacters("This variable");
351 break;
352 default:
353 break;
354 }
355 if (relative->isProperty() || relative->isVariable()) {
356 QString str;
357 const Atom *a = atom->next();
358 while (a != nullptr && a->type() != Atom::BriefRight) {
360 str += a->string();
361 a = a->next();
362 }
363 str[0] = str[0].toLower();
364 if (str.endsWith('.'))
365 str.chop(1);
366
367 const QList<QStringView> words = QStringView{str}.split(' ');
368 if (!words.isEmpty()) {
369 QStringView first(words.at(0));
370 if (!(first == u"contains" || first == u"specifies" || first == u"describes"
371 || first == u"defines" || first == u"holds" || first == u"determines"))
372 writer.writeCharacters(" holds ");
373 else
374 writer.writeCharacters(" ");
375 }
376 }
377 break;
378
379 case Atom::BriefRight:
380 if (relative->isProperty() || relative->isVariable())
381 writer.writeCharacters(".");
382
383 writer.writeEndElement(); // brief
384 break;
385
386 case Atom::C:
387 writer.writeStartElement("teletype");
388 if (m_inLink)
389 writer.writeAttribute("type", "normal");
390 else
391 writer.writeAttribute("type", "highlighted");
392
393 writer.writeCharacters(plainCode(atom->string()));
394 writer.writeEndElement(); // teletype
395 break;
396
397 case Atom::Code:
398 if (!m_hasQuotingInformation)
399 writer.writeTextElement(
400 "code", trimmedTrailing(plainCode(atom->string()), QString(), QString()));
401 else
402 keepQuoting = true;
403 break;
404
405 case Atom::CodeBad:
406 writer.writeTextElement("badcode",
407 trimmedTrailing(plainCode(atom->string()), QString(), QString()));
408 break;
409
411 if (m_quoting) {
412 if (quoteCommand == "dots") {
413 writer.writeAttribute("indent", atom->string());
414 writer.writeCharacters("...");
415 } else {
416 writer.writeCharacters(atom->string());
417 }
418 writer.writeEndElement(); // code
419 keepQuoting = true;
420 }
421 break;
422
424 if (m_quoting) {
425 quoteCommand = atom->string();
426 writer.writeStartElement(quoteCommand);
427 }
428 break;
429
430 case Atom::DetailsSummaryLeft: // Ignore/skip \details summary
431 return atom->find(Atom::DetailsSummaryRight, nullptr);
432
434 break;
435
437 if (!m_inLink) {
438 QString link = linkForExampleFile(atom->string());
439 if (!link.isEmpty())
440 startLink(writer, atom, relative, link);
441 }
442 } break;
443
445 if (!m_inLink) {
446 QString link = atom->string();
447 if (!link.isEmpty())
448 startLink(writer, atom, nullptr, "images/used-in-examples/" + link);
449 }
450 } break;
451
453 writer.writeStartElement("footnote");
454 break;
455
457 writer.writeEndElement(); // footnote
458 break;
459
461 writer.writeEndElement(); // raw
462 break;
463 case Atom::FormatIf:
464 writer.writeStartElement("raw");
465 writer.writeAttribute("format", atom->string());
466 break;
468 if (atom->string() == ATOM_FORMATTING_BOLD)
469 writer.writeStartElement("bold");
470 else if (atom->string() == ATOM_FORMATTING_ITALIC)
471 writer.writeStartElement("italic");
472 else if (atom->string() == ATOM_FORMATTING_UNDERLINE)
473 writer.writeStartElement("underline");
474 else if (atom->string() == ATOM_FORMATTING_SUBSCRIPT)
475 writer.writeStartElement("subscript");
476 else if (atom->string() == ATOM_FORMATTING_SUPERSCRIPT)
477 writer.writeStartElement("superscript");
478 else if (atom->string() == ATOM_FORMATTING_TELETYPE || atom->string() == ATOM_FORMATTING_NOTRANSLATE)
479 writer.writeStartElement("teletype");
480 else if (atom->string() == ATOM_FORMATTING_PARAMETER)
481 writer.writeStartElement("argument");
482 else if (atom->string() == ATOM_FORMATTING_INDEX)
483 writer.writeStartElement("index");
484 } break;
485
487 if (atom->string() == ATOM_FORMATTING_BOLD)
488 writer.writeEndElement();
489 else if (atom->string() == ATOM_FORMATTING_ITALIC)
490 writer.writeEndElement();
491 else if (atom->string() == ATOM_FORMATTING_UNDERLINE)
492 writer.writeEndElement();
493 else if (atom->string() == ATOM_FORMATTING_SUBSCRIPT)
494 writer.writeEndElement();
495 else if (atom->string() == ATOM_FORMATTING_SUPERSCRIPT)
496 writer.writeEndElement();
497 else if (atom->string() == ATOM_FORMATTING_TELETYPE || atom->string() == ATOM_FORMATTING_NOTRANSLATE)
498 writer.writeEndElement();
499 else if (atom->string() == ATOM_FORMATTING_PARAMETER)
500 writer.writeEndElement();
501 else if (atom->string() == ATOM_FORMATTING_INDEX)
502 writer.writeEndElement();
503 else if (atom->string() == ATOM_FORMATTING_TRADEMARK && appendTrademark(atom))
504 writer.writeCharacters(QChar(0x2122)); // 'TM' symbol
505 }
506 if (m_inLink) {
507 writer.writeEndElement(); // link
508 m_inLink = false;
509 }
510 break;
511
513 writer.writeStartElement("generatedlist");
514 writer.writeAttribute("contents", atom->string());
515 writer.writeEndElement();
516 break;
517
518 // TODO: The other generators treat inlineimage and image
519 // simultaneously as the diffirences aren't big. It should be
520 // possible to do the same for webxmlgenerator instead of
521 // repeating the code.
522
523 // TODO: [generator-insufficient-structural-abstraction]
524 case Atom::Image:
525 case Atom::InlineImage: {
526 auto maybe_resolved_file{file_resolver.resolve(atom->string())};
527 if (!maybe_resolved_file) {
528 // TODO: [uncentralized-admonition][failed-resolve-file]
529 relative->location().warning(QStringLiteral("Missing image: %1").arg(atom->string()));
530 } else {
531 ResolvedFile file{*maybe_resolved_file};
532 QString file_name{QFileInfo{file.get_path()}.fileName()};
533
534 // TODO: [uncentralized-output-directory-structure]
535 Config::copyFile(relative->doc().location(), file.get_path(), file_name,
536 "%1/%2"_L1.arg(outputDir(), imagesOutputDir()));
537
538 writer.writeStartElement(atom->typeString().toLower());
539 const auto &imgPath = "%1/%2"_L1.arg(imagesOutputDir(), file_name);
540 // TODO: [uncentralized-output-directory-structure]
541 writer.writeAttribute("href", imgPath);
542 writer.writeEndElement();
543 // TODO: [uncentralized-output-directory-structure]
544 setImageFileName(relative, imgPath);
545 }
546 break;
547 }
548 case Atom::ImageText:
549 break;
550
552 writer.writeStartElement("para");
553 writer.writeTextElement("bold", "Important:");
554 writer.writeCharacters(" ");
555 break;
556
558 writer.writeStartElement("legalese");
559 break;
560
562 writer.writeEndElement(); // legalese
563 break;
564
565 case Atom::Link:
566 case Atom::LinkNode:
567 if (!m_inLink) {
568 const Node *node = nullptr;
569 QString link = getLink(atom, relative, &node);
570 if (!link.isEmpty())
571 startLink(writer, atom, node, link);
572 }
573 break;
574
575 case Atom::ListLeft:
576 writer.writeStartElement("list");
577
578 if (atom->string() == ATOM_LIST_BULLET)
579 writer.writeAttribute("type", "bullet");
580 else if (atom->string() == ATOM_LIST_TAG)
581 writer.writeAttribute("type", "definition");
582 else if (atom->string() == ATOM_LIST_VALUE) {
583 if (relative->isEnumType())
584 writer.writeAttribute("type", "enum");
585 else
586 writer.writeAttribute("type", "definition");
587 } else {
588 writer.writeAttribute("type", "ordered");
589 if (atom->string() == ATOM_LIST_UPPERALPHA)
590 writer.writeAttribute("start", "A");
591 else if (atom->string() == ATOM_LIST_LOWERALPHA)
592 writer.writeAttribute("start", "a");
593 else if (atom->string() == ATOM_LIST_UPPERROMAN)
594 writer.writeAttribute("start", "I");
595 else if (atom->string() == ATOM_LIST_LOWERROMAN)
596 writer.writeAttribute("start", "i");
597 else if (atom->next() != nullptr) // ATOM_LIST_NUMERIC with explicit start
598 writer.writeAttribute("start", atom->next()->string());
599 else
600 writer.writeAttribute("start", "1");
601 }
602 break;
603
605 break;
606 case Atom::ListTagLeft: {
607 writer.writeStartElement("definition");
608
609 writer.writeTextElement(
610 "term", plainCode(marker->markedUpEnumValue(atom->next()->string(), relative)));
611 } break;
612
614 writer.writeEndElement(); // definition
615 break;
616
618 writer.writeStartElement("item");
619 break;
620
622 writer.writeEndElement(); // item
623 break;
624
625 case Atom::ListRight:
626 writer.writeEndElement(); // list
627 break;
628
629 case Atom::NoteLeft:
630 writer.writeStartElement("para");
631 writer.writeTextElement("bold", "Note:");
632 writer.writeCharacters(" ");
633 break;
634
635 // End admonition elements
637 case Atom::NoteRight:
639 writer.writeEndElement(); // para
640 break;
641
642 case Atom::Nop:
643 break;
644
646 case Atom::ParaLeft:
647 writer.writeStartElement("para");
648 break;
649
651 case Atom::ParaRight:
652 writer.writeEndElement(); // para
653 break;
654
656 writer.writeStartElement("quote");
657 break;
658
660 writer.writeEndElement(); // quote
661 break;
662
663 case Atom::RawString:
664 writer.writeCharacters(atom->string());
665 break;
666
668 writer.writeStartElement("section");
669 writer.writeAttribute("id",
670 TextUtils::asAsciiPrintable(Text::sectionHeading(atom).toString()));
671 break;
672
674 writer.writeEndElement(); // section
675 break;
676
678 writer.writeStartElement("heading");
679 int unit = atom->string().toInt(); // + hOffset(relative)
680 writer.writeAttribute("level", QString::number(unit));
681 m_inSectionHeading = true;
682 } break;
683
685 writer.writeEndElement(); // heading
686 m_inSectionHeading = false;
687 break;
688
691 break;
692
694 if (m_quoting) {
695 writer.writeStartElement(atom->string());
696 }
697 break;
698
700 if (m_quoting) {
701 writer.writeAttribute("identifier", atom->string());
702 writer.writeEndElement();
703 keepQuoting = true;
704 }
705 break;
706
708 if (m_quoting) {
709 const QString &location = atom->string();
710 writer.writeAttribute("location", location);
711 auto maybe_resolved_file{file_resolver.resolve(location)};
712 // const QString resolved = Doc::resolveFile(Location(), location);
713 if (maybe_resolved_file)
714 writer.writeAttribute("path", (*maybe_resolved_file).get_path());
715 else {
716 // TODO: [uncetnralized-admonition][failed-resolve-file]
717 QString details = std::transform_reduce(
718 file_resolver.get_search_directories().cbegin(),
719 file_resolver.get_search_directories().cend(),
720 u"Searched directories:"_s,
721 std::plus(),
722 [](const DirectoryPath &directory_path) -> QString { return u' ' + directory_path.value(); }
723 );
724
725 relative->location().warning(u"Cannot find file to quote from: %1"_s.arg(location), details);
726 }
727 }
728 break;
729
730 case Atom::String:
731 writer.writeCharacters(atom->string());
732 break;
733 case Atom::TableLeft:
734 writer.writeStartElement("table");
735 if (atom->string().contains("%"))
736 writer.writeAttribute("width", atom->string());
737 break;
738
739 case Atom::TableRight:
740 writer.writeEndElement(); // table
741 break;
742
744 writer.writeStartElement("header");
745 break;
746
748 writer.writeEndElement(); // header
749 break;
750
752 writer.writeStartElement("row");
753 break;
754
756 writer.writeEndElement(); // row
757 break;
758
759 case Atom::TableItemLeft: {
760 writer.writeStartElement("item");
761 QStringList spans = atom->string().split(",");
762 if (spans.size() == 2) {
763 if (spans.at(0) != "1")
764 writer.writeAttribute("colspan", spans.at(0).trimmed());
765 if (spans.at(1) != "1")
766 writer.writeAttribute("rowspan", spans.at(1).trimmed());
767 }
768 } break;
770 writer.writeEndElement(); // item
771 break;
772
774 // Skip to the closing \endtoc atom
775 if (const auto *endtoc = atom->find(Atom::TableOfContentsRight))
776 atom = endtoc;
777 break;
778
779 case Atom::Target:
780 writer.writeStartElement("target");
781 writer.writeAttribute("name", TextUtils::asAsciiPrintable(atom->string()));
782 writer.writeEndElement();
783 break;
784
786 writer.writeStartElement("para");
787 writer.writeTextElement("bold", "Warning:");
788 writer.writeCharacters(" ");
789 break;
790
793 writer.writeCharacters(atom->typeString());
794 break;
795 default:
796 break;
797 }
798
799 m_hasQuotingInformation = keepQuoting;
800 return atom->next();
801}
802
803void WebXMLGenerator::startLink(QXmlStreamWriter &writer, const Atom *atom, const Node *node,
804 const QString &link)
805{
806 QString fullName = link;
807 if (node)
808 fullName = node->fullName();
809 if (!fullName.isEmpty() && !link.isEmpty()) {
810 writer.writeStartElement("link");
811 if (atom && !atom->string().isEmpty())
812 writer.writeAttribute("raw", atom->string());
813 else
814 writer.writeAttribute("raw", fullName);
815 writer.writeAttribute("href", link);
816 writer.writeAttribute("type", targetType(node));
817 if (node) {
818 switch (node->nodeType()) {
819 case NodeType::Enum:
820 writer.writeAttribute("enum", fullName);
821 break;
822 case NodeType::Example: {
823 const auto *en = static_cast<const ExampleNode *>(node);
824 const QString fileTitle = atom ? exampleFileTitle(en, atom->string()) : QString();
825 if (!fileTitle.isEmpty()) {
826 writer.writeAttribute("page", fileTitle);
827 break;
828 }
829 }
830 Q_FALLTHROUGH();
831 case NodeType::Page:
832 writer.writeAttribute("page", fullName);
833 break;
834 case NodeType::Property: {
835 const auto *propertyNode = static_cast<const PropertyNode *>(node);
836 if (!propertyNode->getters().empty())
837 writer.writeAttribute("getter", propertyNode->getters().at(0)->fullName());
838 } break;
839 default:
840 break;
841 }
842 }
843 m_inLink = true;
844 }
845}
846
847void WebXMLGenerator::endLink(QXmlStreamWriter &writer)
848{
849 if (m_inLink) {
850 writer.writeEndElement(); // link
851 m_inLink = false;
852 }
853}
854
855void WebXMLGenerator::generateRelations(QXmlStreamWriter &writer, const Node *node)
856{
857 if (node && !node->links().empty()) {
858 std::pair<QString, QString> anchorPair;
859 const Node *linkNode;
860
861 for (auto it = node->links().cbegin(); it != node->links().cend(); ++it) {
862
863 linkNode = m_qdb->findNodeForTarget(it.value().first, node);
864
865 if (!linkNode)
866 linkNode = node;
867
868 if (linkNode == node)
869 anchorPair = it.value();
870 else
871 anchorPair = anchorForNode(linkNode);
872
873 writer.writeStartElement("relation");
874 writer.writeAttribute("href", anchorPair.first);
875 writer.writeAttribute("type", targetType(linkNode));
876
877 switch (it.key()) {
878 case Node::StartLink:
879 writer.writeAttribute("meta", "start");
880 break;
881 case Node::NextLink:
882 writer.writeAttribute("meta", "next");
883 break;
885 writer.writeAttribute("meta", "previous");
886 break;
888 writer.writeAttribute("meta", "contents");
889 break;
890 default:
891 writer.writeAttribute("meta", "");
892 }
893 writer.writeAttribute("description", anchorPair.second);
894 writer.writeEndElement(); // link
895 }
896 }
897}
898
899void WebXMLGenerator::generateAnnotatedList(QXmlStreamWriter &writer, const Node *relative,
900 const NodeMap &nodeMap)
901{
902 generateAnnotatedList(writer, relative, nodeMap.values());
903}
904
905void WebXMLGenerator::generateAnnotatedList(QXmlStreamWriter &writer, const Node *relative,
906 const NodeList &nodeList)
907{
908 writer.writeStartElement("table");
909 writer.writeAttribute("width", "100%");
910
911 for (const auto *node : nodeList) {
912 writer.writeStartElement("row");
913 writer.writeStartElement("item");
914 writer.writeStartElement("para");
915 const QString link = linkForNode(node, relative);
916 startLink(writer, node->doc().body().firstAtom(), node, link);
917 endLink(writer);
918 writer.writeEndElement(); // para
919 writer.writeEndElement(); // item
920
921 writer.writeStartElement("item");
922 writer.writeStartElement("para");
923 writer.writeCharacters(node->doc().briefText().toString());
924 writer.writeEndElement(); // para
925 writer.writeEndElement(); // item
926 writer.writeEndElement(); // row
927 }
928 writer.writeEndElement(); // table
929}
930
932{
933 return Generator::fileBase(node);
934}
935
936QT_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_SUPERSCRIPT
Definition atom.h:205
#define ATOM_FORMATTING_INDEX
Definition atom.h:198
#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
@ TableRight
Definition atom.h:99
@ GeneratedList
Definition atom.h:54
@ BriefRight
Definition atom.h:27
@ CodeQuoteArgument
Definition atom.h:33
@ WarningLeft
Definition atom.h:112
@ TableOfContentsLeft
Definition atom.h:106
@ SidebarLeft
Definition atom.h:89
@ TableHeaderRight
Definition atom.h:101
@ InlineImage
Definition atom.h:60
@ TableRowRight
Definition atom.h:103
@ FootnoteRight
Definition atom.h:48
@ SnippetCommand
Definition atom.h:94
@ TableRowLeft
Definition atom.h:102
@ Nop
Definition atom.h:76
@ WarningRight
Definition atom.h:113
@ LegaleseRight
Definition atom.h:63
@ ListTagRight
Definition atom.h:70
@ CaptionRight
Definition atom.h:30
@ ListItemNumber
Definition atom.h:68
@ CodeBad
Definition atom.h:32
@ 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
@ TableItemRight
Definition atom.h:105
@ ListItemLeft
Definition atom.h:71
@ ImportantRight
Definition atom.h:59
@ Code
Definition atom.h:31
@ String
Definition atom.h:97
@ ListLeft
Definition atom.h:67
@ CodeQuoteCommand
Definition atom.h:34
@ BriefLeft
Definition atom.h:26
@ ImageText
Definition atom.h:57
@ ExampleFileLink
Definition atom.h:45
@ LegaleseLeft
Definition atom.h:62
@ ListRight
Definition atom.h:73
@ C
Definition atom.h:28
@ 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
@ UnhandledFormat
Definition atom.h:111
@ ExampleImageLink
Definition atom.h:46
@ FootnoteLeft
Definition atom.h:47
@ AutoLink
Definition atom.h:23
@ SnippetLocation
Definition atom.h:96
@ TableHeaderLeft
Definition atom.h:100
@ DeprecatedRight
Definition atom.h:38
@ QuotationLeft
Definition atom.h:82
@ SectionLeft
Definition atom.h:85
@ LinkNode
Definition atom.h:66
@ TableItemLeft
Definition atom.h:104
@ NoteRight
Definition atom.h:78
@ QuotationRight
Definition atom.h:83
@ ParaLeft
Definition atom.h:79
@ BaseName
Definition atom.h:24
@ FormatIf
Definition atom.h:51
@ SnippetIdentifier
Definition atom.h:95
@ NoteLeft
Definition atom.h:77
@ SidebarRight
Definition atom.h:90
@ UnknownCommand
Definition atom.h:114
@ 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
A class for holding the members of a collection of doc pages.
const NodeList & members() const
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition config.h:95
InclusionPolicy createInclusionPolicy() const
Definition config.cpp:1678
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 deprecationText() const
Definition doc.cpp:131
Encapsulate the logic that QDoc uses to find files whose path is provided by the user and that are re...
static bool appendTrademark(const Atom *atom)
Returns true if a trademark symbol should be appended to the output as determined by atom.
QTextStream & out()
void endSubPage()
Flush the text stream associated with the subpage, and then pop it off the text stream stack and dele...
void generateRequiredLinks(const Node *node, CodeMarker *marker)
Generates either a link to the project folder for example node, or a list of links files/images if 'u...
HtmlGenerator(FileResolver &file_resolver)
void initializeGenerator() override
Initializes the HTML output generator's data structures from the configuration (Config) singleton.
void terminateGenerator() override
Gracefully terminates the HTML output generator.
static bool isIncluded(const InclusionPolicy &policy, const NodeContext &context)
A PageNode is a Node that generates a documentation page.
Definition pagenode.h:19
This class imports QDoc index files and serializes index sections for module indexes and WebXML outpu...
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
QString fileBase(const Node *node) const override
QString format() const override
Returns the format identifier for this producer (e.g., "HTML", "DocBook", "template").
virtual const Atom * addAtomElements(QXmlStreamWriter &writer, const Atom *atom, const Node *relative, CodeMarker *marker)
void terminateGenerator() override
Gracefully terminates the HTML output generator.
void generateDocumentation(Node *node) override
Recursive writing of HTML files from the root node.
void append(QXmlStreamWriter &writer, Node *node) override
virtual void generateIndexSections(QXmlStreamWriter &writer, Node *node)
void generatePageNode(PageNode *pn, CodeMarker *marker) override
Generate the HTML page for an entity that doesn't map to any underlying parsable C++ or QML element.
WebXMLGenerator(FileResolver &file_resolver)
QString fileExtension() const override
Returns "html" for this subclass of Generator.
void initializeGenerator() override
Initializes the HTML output generator's data structures from the configuration (Config) singleton.
void generateExampleFilePage(const PageNode *en, ResolvedFile file, CodeMarker *marker=nullptr) override
Generate an html file with the contents of a C++ or QML source file.
void generateCppReferencePage(Aggregate *aggregate, CodeMarker *marker) override
Generate a reference page for the C++ class, namespace, or header file documented in node using the c...
qsizetype generateAtom(const Atom *atom, const Node *relative, CodeMarker *marker) override
Most of the output is generated by QDocIndexFiles and the append() callback.
#define CONFIG_LOCATIONINFO
Definition config.h:426
NodeType
Definition genustypes.h:165
Combined button and popup list for selecting options.
QList< Node * > NodeList
Definition node.h:45
QMap< QString, Node * > NodeMap
Definition node.h:48
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 isGroup() const
Returns true if the node type is Group.
Definition node.h:105
SharedCommentNode * sharedCommentNode()
Definition node.h:252
bool isNamespace() const
Returns true if the node type is Namespace.
Definition node.h:110
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
bool isEnumType() const
Returns true if the node type is Enum.
Definition node.h:94
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
const Location & location() const
If this node's definition location is empty, this function returns this node's declaration location.
Definition node.h:235
virtual bool wasSeen() const
Returns the seen flag data member of this node if it is a NamespaceNode or a CollectionNode.
Definition node.h:195
bool isProperty() const
Returns true if the node type is Property.
Definition node.h:114
NodeContext createContext() const
Definition node.cpp:175
bool isModule() const
Returns true if the node type is Module.
Definition node.h:108
bool isSharingComment() const
This function returns true if the node is sharing a comment with other nodes.
Definition node.h:250
@ NextLink
Definition node.h:73
@ StartLink
Definition node.h:73
@ ContentsLink
Definition node.h:73
@ PreviousLink
Definition node.h:73
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
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
Represents a file that is reachable by QDoc based on its current configuration.
static CodeMarker * marker_