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