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 returns early for collection nodes (groups,
153 // modules, QML modules, concepts) so their member listings can be
154 // written last in an index file. When rendering a single collection
155 // page, that leaves the document empty, so emit the section explicitly.
156 if (node->isCollectionNode())
157 std::ignore = qdocIndexFiles->generateIndexSection(writer, node, this, this);
158 }
159}
160
161// Handles callbacks from QDocIndexFiles to add documentation to node
162void WebXMLGenerator::append(QXmlStreamWriter &writer, Node *node)
163{
164 Q_ASSERT(marker_);
165
166 writer.writeStartElement("description");
167 if (Config::instance().get(CONFIG_LOCATIONINFO).asBool()) {
168 writer.writeAttribute("path", node->doc().location().filePath());
169 writer.writeAttribute("line", QString::number(node->doc().location().lineNo()));
170 writer.writeAttribute("column", QString::number(node->doc().location().columnNo()));
171 }
172
173 if (node->isTextPageNode())
174 generateRelations(writer, node);
175
176 if (node->isModule()) {
177 writer.writeStartElement("generatedlist");
178 writer.writeAttribute("contents", "classesbymodule");
179 auto *cnn = static_cast<CollectionNode *>(node);
180
181 if (cnn->hasNamespaces()) {
182 writer.writeStartElement("section");
183 writer.writeStartElement("heading");
184 writer.writeAttribute("level", "1");
185 writer.writeCharacters("Namespaces");
186 writer.writeEndElement(); // heading
187 NodeMap namespaces{cnn->getMembers(NodeType::Namespace)};
188 generateAnnotatedList(writer, node, namespaces);
189 writer.writeEndElement(); // section
190 }
191 if (cnn->hasClasses()) {
192 writer.writeStartElement("section");
193 writer.writeStartElement("heading");
194 writer.writeAttribute("level", "1");
195 writer.writeCharacters("Classes");
196 writer.writeEndElement(); // heading
197 NodeMap classes{cnn->getMembers([](const Node *n){ return n->isClassNode(); })};
198 generateAnnotatedList(writer, node, classes);
199 writer.writeEndElement(); // section
200 }
201 writer.writeEndElement(); // generatedlist
202 }
203
204 m_inLink = m_inSectionHeading = m_hasQuotingInformation = false;
205
206 const Atom *atom = node->doc().body().firstAtom();
207 while (atom)
208 atom = addAtomElements(writer, atom, node, marker_);
209
210 QList<Text> alsoList = node->doc().alsoList();
211 supplementAlsoList(node, alsoList);
212
213 if (!alsoList.isEmpty()) {
214 writer.writeStartElement("see-also");
215 for (const auto &item : alsoList) {
216 const auto *atom = item.firstAtom();
217 while (atom)
218 atom = addAtomElements(writer, atom, node, marker_);
219 }
220 writer.writeEndElement(); // see-also
221 }
222
223 if (node->isExample()) {
224 m_supplement = true;
226 m_supplement = false;
227 } else if (node->isGroup()) {
228 auto *cn = static_cast<CollectionNode *>(node);
229 if (!cn->noAutoList())
230 generateAnnotatedList(writer, node, cn->members());
231 }
232
233 writer.writeEndElement(); // description
234}
235
237{
238 // Don't generate nodes that are already processed, or if they're not supposed to
239 // generate output, ie. external, index or images nodes.
240 if (!node->url().isNull() || node->isExternalPage() || node->isIndexNode())
241 return;
242
243 const InclusionPolicy policy = Config::instance().createInclusionPolicy();
244 const NodeContext context = node->createContext();
245 if (!InclusionFilter::isIncluded(policy, context))
246 return;
247
248 if (node->parent()) {
249 if (node->isNamespace() || node->isClassNode() || node->isHeader())
250 generateCppReferencePage(static_cast<Aggregate *>(node), nullptr);
251 else if (node->isCollectionNode()) {
252 if (node->wasSeen()) {
253 // see remarks in base class impl.
254 m_qdb->mergeCollections(static_cast<CollectionNode *>(node));
255 generatePageNode(static_cast<PageNode *>(node), nullptr);
256 }
257 } else if (node->isTextPageNode())
258 generatePageNode(static_cast<PageNode *>(node), nullptr);
259 // else if TODO: anything else?
260 }
261
262 if (node->isAggregate()) {
263 auto *aggregate = static_cast<Aggregate *>(node);
264 for (auto c : aggregate->childNodes()) {
265 if ((c->isAggregate() || c->isTextPageNode() || c->isCollectionNode())
266 && !c->isPrivate())
267 generateDocumentation(c);
268 }
269 }
270}
271
272const Atom *WebXMLGenerator::addAtomElements(QXmlStreamWriter &writer, const Atom *atom,
273 const Node *relative, CodeMarker *marker)
274{
275 bool keepQuoting = false;
276
277 if (!atom)
278 return nullptr;
279
280 switch (atom->type()) {
281 case Atom::AnnotatedList: {
282 const CollectionNode *cn = m_qdb->getCollectionNode(atom->string(), NodeType::Group);
283 if (cn)
284 generateAnnotatedList(writer, relative, cn->members());
285 } break;
286 case Atom::AutoLink: {
287 const Node *node{nullptr};
288 QString link{};
289
290 if (!m_inLink && !m_inSectionHeading) {
291 link = getAutoLink(atom, relative, &node, Genus::API);
292
293 if (!link.isEmpty() && node && node->isDeprecated()
294 && relative->parent() != node && !relative->isDeprecated()) {
295 link.clear();
296 }
297 }
298
299 startLink(writer, atom, node, link);
300
301 writer.writeCharacters(atom->string());
302
303 if (m_inLink) {
304 writer.writeEndElement(); // link
305 m_inLink = false;
306 }
307
308 break;
309 }
310 case Atom::BaseName:
311 break;
312 case Atom::BriefLeft:
313
314 writer.writeStartElement("brief");
315 switch (relative->nodeType()) {
317 writer.writeCharacters("This property");
318 break;
320 writer.writeCharacters("This variable");
321 break;
322 default:
323 break;
324 }
325 if (relative->isProperty() || relative->isVariable()) {
326 QString str;
327 const Atom *a = atom->next();
328 while (a != nullptr && a->type() != Atom::BriefRight) {
330 str += a->string();
331 a = a->next();
332 }
333 str[0] = str[0].toLower();
334 if (str.endsWith('.'))
335 str.chop(1);
336
337 const QList<QStringView> words = QStringView{str}.split(' ');
338 if (!words.isEmpty()) {
339 QStringView first(words.at(0));
340 if (!(first == u"contains" || first == u"specifies" || first == u"describes"
341 || first == u"defines" || first == u"holds" || first == u"determines"))
342 writer.writeCharacters(" holds ");
343 else
344 writer.writeCharacters(" ");
345 }
346 }
347 break;
348
349 case Atom::BriefRight:
350 if (relative->isProperty() || relative->isVariable())
351 writer.writeCharacters(".");
352
353 writer.writeEndElement(); // brief
354 break;
355
356 case Atom::C:
357 writer.writeStartElement("teletype");
358 if (m_inLink)
359 writer.writeAttribute("type", "normal");
360 else
361 writer.writeAttribute("type", "highlighted");
362
363 writer.writeCharacters(plainCode(atom->string()));
364 writer.writeEndElement(); // teletype
365 break;
366
367 case Atom::Code:
368 if (!m_hasQuotingInformation)
369 writer.writeTextElement(
370 "code", trimmedTrailing(plainCode(atom->string()), QString(), QString()));
371 else
372 keepQuoting = true;
373 break;
374
375 case Atom::CodeBad:
376 writer.writeTextElement("badcode",
377 trimmedTrailing(plainCode(atom->string()), QString(), QString()));
378 break;
379
381 if (m_quoting) {
382 if (quoteCommand == "dots") {
383 writer.writeAttribute("indent", atom->string());
384 writer.writeCharacters("...");
385 } else {
386 writer.writeCharacters(atom->string());
387 }
388 writer.writeEndElement(); // code
389 keepQuoting = true;
390 }
391 break;
392
394 if (m_quoting) {
395 quoteCommand = atom->string();
396 writer.writeStartElement(quoteCommand);
397 }
398 break;
399
400 case Atom::DetailsSummaryLeft: // Ignore/skip \details summary
401 return atom->find(Atom::DetailsSummaryRight, nullptr);
402
404 break;
405
407 if (!m_inLink) {
408 QString link = linkForExampleFile(atom->string());
409 if (!link.isEmpty())
410 startLink(writer, atom, relative, link);
411 }
412 } break;
413
415 if (!m_inLink) {
416 QString link = atom->string();
417 if (!link.isEmpty())
418 startLink(writer, atom, nullptr, "images/used-in-examples/" + link);
419 }
420 } break;
421
423 writer.writeStartElement("footnote");
424 break;
425
427 writer.writeEndElement(); // footnote
428 break;
429
431 writer.writeEndElement(); // raw
432 break;
433 case Atom::FormatIf:
434 writer.writeStartElement("raw");
435 writer.writeAttribute("format", atom->string());
436 break;
438 if (atom->string() == ATOM_FORMATTING_BOLD)
439 writer.writeStartElement("bold");
440 else if (atom->string() == ATOM_FORMATTING_ITALIC)
441 writer.writeStartElement("italic");
442 else if (atom->string() == ATOM_FORMATTING_UNDERLINE)
443 writer.writeStartElement("underline");
444 else if (atom->string() == ATOM_FORMATTING_SUBSCRIPT)
445 writer.writeStartElement("subscript");
446 else if (atom->string() == ATOM_FORMATTING_SUPERSCRIPT)
447 writer.writeStartElement("superscript");
448 else if (atom->string() == ATOM_FORMATTING_TELETYPE || atom->string() == ATOM_FORMATTING_NOTRANSLATE)
449 writer.writeStartElement("teletype");
450 else if (atom->string() == ATOM_FORMATTING_PARAMETER)
451 writer.writeStartElement("argument");
452 else if (atom->string() == ATOM_FORMATTING_INDEX)
453 writer.writeStartElement("index");
454 } break;
455
457 if (atom->string() == ATOM_FORMATTING_BOLD)
458 writer.writeEndElement();
459 else if (atom->string() == ATOM_FORMATTING_ITALIC)
460 writer.writeEndElement();
461 else if (atom->string() == ATOM_FORMATTING_UNDERLINE)
462 writer.writeEndElement();
463 else if (atom->string() == ATOM_FORMATTING_SUBSCRIPT)
464 writer.writeEndElement();
465 else if (atom->string() == ATOM_FORMATTING_SUPERSCRIPT)
466 writer.writeEndElement();
467 else if (atom->string() == ATOM_FORMATTING_TELETYPE || atom->string() == ATOM_FORMATTING_NOTRANSLATE)
468 writer.writeEndElement();
469 else if (atom->string() == ATOM_FORMATTING_PARAMETER)
470 writer.writeEndElement();
471 else if (atom->string() == ATOM_FORMATTING_INDEX)
472 writer.writeEndElement();
473 else if (atom->string() == ATOM_FORMATTING_TRADEMARK && appendTrademark(atom))
474 writer.writeCharacters(QChar(0x2122)); // 'TM' symbol
475 }
476 if (m_inLink) {
477 writer.writeEndElement(); // link
478 m_inLink = false;
479 }
480 break;
481
483 writer.writeStartElement("generatedlist");
484 writer.writeAttribute("contents", atom->string());
485 writer.writeEndElement();
486 break;
487
488 // TODO: The other generators treat inlineimage and image
489 // simultaneously as the diffirences aren't big. It should be
490 // possible to do the same for webxmlgenerator instead of
491 // repeating the code.
492
493 // TODO: [generator-insufficient-structural-abstraction]
494 case Atom::Image:
495 case Atom::InlineImage: {
496 auto maybe_resolved_file{file_resolver.resolve(atom->string())};
497 if (!maybe_resolved_file) {
498 // TODO: [uncentralized-admonition][failed-resolve-file]
499 relative->location().warning(QStringLiteral("Missing image: %1").arg(atom->string()));
500 } else {
501 ResolvedFile file{*maybe_resolved_file};
502 QString file_name{QFileInfo{file.get_path()}.fileName()};
503
504 // TODO: [uncentralized-output-directory-structure]
505 Config::copyFile(relative->doc().location(), file.get_path(), file_name,
506 "%1/%2"_L1.arg(outputDir(), imagesOutputDir()));
507
508 writer.writeStartElement(atom->typeString().toLower());
509 const auto &imgPath = "%1/%2"_L1.arg(imagesOutputDir(), file_name);
510 // TODO: [uncentralized-output-directory-structure]
511 writer.writeAttribute("href", imgPath);
512 writer.writeEndElement();
513 // TODO: [uncentralized-output-directory-structure]
514 setImageFileName(relative, imgPath);
515 }
516 break;
517 }
518 case Atom::ImageText:
519 break;
520
522 writer.writeStartElement("para");
523 writer.writeTextElement("bold", "Important:");
524 writer.writeCharacters(" ");
525 break;
526
528 writer.writeStartElement("legalese");
529 break;
530
532 writer.writeEndElement(); // legalese
533 break;
534
535 case Atom::Link:
536 case Atom::LinkNode:
537 if (!m_inLink) {
538 const Node *node = nullptr;
539 QString link = getLink(atom, relative, &node);
540 if (!link.isEmpty())
541 startLink(writer, atom, node, link);
542 }
543 break;
544
545 case Atom::ListLeft:
546 writer.writeStartElement("list");
547
548 if (atom->string() == ATOM_LIST_BULLET)
549 writer.writeAttribute("type", "bullet");
550 else if (atom->string() == ATOM_LIST_TAG)
551 writer.writeAttribute("type", "definition");
552 else if (atom->string() == ATOM_LIST_VALUE) {
553 if (relative->isEnumType())
554 writer.writeAttribute("type", "enum");
555 else
556 writer.writeAttribute("type", "definition");
557 } else {
558 writer.writeAttribute("type", "ordered");
559 if (atom->string() == ATOM_LIST_UPPERALPHA)
560 writer.writeAttribute("start", "A");
561 else if (atom->string() == ATOM_LIST_LOWERALPHA)
562 writer.writeAttribute("start", "a");
563 else if (atom->string() == ATOM_LIST_UPPERROMAN)
564 writer.writeAttribute("start", "I");
565 else if (atom->string() == ATOM_LIST_LOWERROMAN)
566 writer.writeAttribute("start", "i");
567 else if (atom->next() != nullptr) // ATOM_LIST_NUMERIC with explicit start
568 writer.writeAttribute("start", atom->next()->string());
569 else
570 writer.writeAttribute("start", "1");
571 }
572 break;
573
575 break;
576 case Atom::ListTagLeft: {
577 writer.writeStartElement("definition");
578
579 writer.writeTextElement(
580 "term", plainCode(marker->markedUpEnumValue(atom->next()->string(), relative)));
581 } break;
582
584 writer.writeEndElement(); // definition
585 break;
586
588 writer.writeStartElement("item");
589 break;
590
592 writer.writeEndElement(); // item
593 break;
594
595 case Atom::ListRight:
596 writer.writeEndElement(); // list
597 break;
598
599 case Atom::NoteLeft:
600 writer.writeStartElement("para");
601 writer.writeTextElement("bold", "Note:");
602 writer.writeCharacters(" ");
603 break;
604
605 // End admonition elements
607 case Atom::NoteRight:
609 writer.writeEndElement(); // para
610 break;
611
612 case Atom::Nop:
613 break;
614
616 case Atom::ParaLeft:
617 writer.writeStartElement("para");
618 break;
619
621 case Atom::ParaRight:
622 writer.writeEndElement(); // para
623 break;
624
626 writer.writeStartElement("quote");
627 break;
628
630 writer.writeEndElement(); // quote
631 break;
632
633 case Atom::RawString:
634 writer.writeCharacters(atom->string());
635 break;
636
638 writer.writeStartElement("section");
639 writer.writeAttribute("id",
640 TextUtils::asAsciiPrintable(Text::sectionHeading(atom).toString()));
641 break;
642
644 writer.writeEndElement(); // section
645 break;
646
648 writer.writeStartElement("heading");
649 int unit = atom->string().toInt(); // + hOffset(relative)
650 writer.writeAttribute("level", QString::number(unit));
651 m_inSectionHeading = true;
652 } break;
653
655 writer.writeEndElement(); // heading
656 m_inSectionHeading = false;
657 break;
658
661 break;
662
664 if (m_quoting) {
665 writer.writeStartElement(atom->string());
666 }
667 break;
668
670 if (m_quoting) {
671 writer.writeAttribute("identifier", atom->string());
672 writer.writeEndElement();
673 keepQuoting = true;
674 }
675 break;
676
678 if (m_quoting) {
679 const QString &location = atom->string();
680 writer.writeAttribute("location", location);
681 auto maybe_resolved_file{file_resolver.resolve(location)};
682 // const QString resolved = Doc::resolveFile(Location(), location);
683 if (maybe_resolved_file)
684 writer.writeAttribute("path", (*maybe_resolved_file).get_path());
685 else {
686 // TODO: [uncetnralized-admonition][failed-resolve-file]
687 QString details = std::transform_reduce(
688 file_resolver.get_search_directories().cbegin(),
689 file_resolver.get_search_directories().cend(),
690 u"Searched directories:"_s,
691 std::plus(),
692 [](const DirectoryPath &directory_path) -> QString { return u' ' + directory_path.value(); }
693 );
694
695 relative->location().warning(u"Cannot find file to quote from: %1"_s.arg(location), details);
696 }
697 }
698 break;
699
700 case Atom::String:
701 writer.writeCharacters(atom->string());
702 break;
703 case Atom::TableLeft:
704 writer.writeStartElement("table");
705 if (atom->string().contains("%"))
706 writer.writeAttribute("width", atom->string());
707 break;
708
709 case Atom::TableRight:
710 writer.writeEndElement(); // table
711 break;
712
714 writer.writeStartElement("header");
715 break;
716
718 writer.writeEndElement(); // header
719 break;
720
722 writer.writeStartElement("row");
723 break;
724
726 writer.writeEndElement(); // row
727 break;
728
729 case Atom::TableItemLeft: {
730 writer.writeStartElement("item");
731 QStringList spans = atom->string().split(",");
732 if (spans.size() == 2) {
733 if (spans.at(0) != "1")
734 writer.writeAttribute("colspan", spans.at(0).trimmed());
735 if (spans.at(1) != "1")
736 writer.writeAttribute("rowspan", spans.at(1).trimmed());
737 }
738 } break;
740 writer.writeEndElement(); // item
741 break;
742
744 // Skip to the closing \endtoc atom
745 if (const auto *endtoc = atom->find(Atom::TableOfContentsRight))
746 atom = endtoc;
747 break;
748
749 case Atom::Target:
750 writer.writeStartElement("target");
751 writer.writeAttribute("name", TextUtils::asAsciiPrintable(atom->string()));
752 writer.writeEndElement();
753 break;
754
756 writer.writeStartElement("para");
757 writer.writeTextElement("bold", "Warning:");
758 writer.writeCharacters(" ");
759 break;
760
763 writer.writeCharacters(atom->typeString());
764 break;
765 default:
766 break;
767 }
768
769 m_hasQuotingInformation = keepQuoting;
770 return atom->next();
771}
772
773void WebXMLGenerator::startLink(QXmlStreamWriter &writer, const Atom *atom, const Node *node,
774 const QString &link)
775{
776 QString fullName = link;
777 if (node)
778 fullName = node->fullName();
779 if (!fullName.isEmpty() && !link.isEmpty()) {
780 writer.writeStartElement("link");
781 if (atom && !atom->string().isEmpty())
782 writer.writeAttribute("raw", atom->string());
783 else
784 writer.writeAttribute("raw", fullName);
785 writer.writeAttribute("href", link);
786 writer.writeAttribute("type", targetType(node));
787 if (node) {
788 switch (node->nodeType()) {
789 case NodeType::Enum:
790 writer.writeAttribute("enum", fullName);
791 break;
792 case NodeType::Example: {
793 const auto *en = static_cast<const ExampleNode *>(node);
794 const QString fileTitle = atom ? exampleFileTitle(en, atom->string()) : QString();
795 if (!fileTitle.isEmpty()) {
796 writer.writeAttribute("page", fileTitle);
797 break;
798 }
799 }
800 Q_FALLTHROUGH();
801 case NodeType::Page:
802 writer.writeAttribute("page", fullName);
803 break;
804 case NodeType::Property: {
805 const auto *propertyNode = static_cast<const PropertyNode *>(node);
806 if (!propertyNode->getters().empty())
807 writer.writeAttribute("getter", propertyNode->getters().at(0)->fullName());
808 } break;
809 default:
810 break;
811 }
812 }
813 m_inLink = true;
814 }
815}
816
817void WebXMLGenerator::endLink(QXmlStreamWriter &writer)
818{
819 if (m_inLink) {
820 writer.writeEndElement(); // link
821 m_inLink = false;
822 }
823}
824
825void WebXMLGenerator::generateRelations(QXmlStreamWriter &writer, const Node *node)
826{
827 if (node && !node->links().empty()) {
828 std::pair<QString, QString> anchorPair;
829 const Node *linkNode;
830
831 for (auto it = node->links().cbegin(); it != node->links().cend(); ++it) {
832
833 linkNode = m_qdb->findNodeForTarget(it.value().first, node);
834
835 if (!linkNode)
836 linkNode = node;
837
838 if (linkNode == node)
839 anchorPair = it.value();
840 else
841 anchorPair = anchorForNode(linkNode);
842
843 writer.writeStartElement("relation");
844 writer.writeAttribute("href", anchorPair.first);
845 writer.writeAttribute("type", targetType(linkNode));
846
847 switch (it.key()) {
848 case Node::StartLink:
849 writer.writeAttribute("meta", "start");
850 break;
851 case Node::NextLink:
852 writer.writeAttribute("meta", "next");
853 break;
854 case Node::PreviousLink:
855 writer.writeAttribute("meta", "previous");
856 break;
857 case Node::ContentsLink:
858 writer.writeAttribute("meta", "contents");
859 break;
860 default:
861 writer.writeAttribute("meta", "");
862 }
863 writer.writeAttribute("description", anchorPair.second);
864 writer.writeEndElement(); // link
865 }
866 }
867}
868
869void WebXMLGenerator::generateAnnotatedList(QXmlStreamWriter &writer, const Node *relative,
870 const NodeMap &nodeMap)
871{
872 generateAnnotatedList(writer, relative, nodeMap.values());
873}
874
875void WebXMLGenerator::generateAnnotatedList(QXmlStreamWriter &writer, const Node *relative,
876 const NodeList &nodeList)
877{
878 writer.writeStartElement("table");
879 writer.writeAttribute("width", "100%");
880
881 for (const auto *node : nodeList) {
882 writer.writeStartElement("row");
883 writer.writeStartElement("item");
884 writer.writeStartElement("para");
885 const QString link = linkForNode(node, relative);
886 startLink(writer, node->doc().body().firstAtom(), node, link);
887 endLink(writer);
888 writer.writeEndElement(); // para
889 writer.writeEndElement(); // item
890
891 writer.writeStartElement("item");
892 writer.writeStartElement("para");
893 writer.writeCharacters(node->doc().briefText().toString());
894 writer.writeEndElement(); // para
895 writer.writeEndElement(); // item
896 writer.writeEndElement(); // row
897 }
898 writer.writeEndElement(); // table
899}
900
902{
903 return Generator::fileBase(node);
904}
905
906QT_END_NAMESPACE
#define ATOM_LIST_BULLET
Definition atom.h:220
#define ATOM_FORMATTING_TELETYPE
Definition atom.h:215
#define ATOM_LIST_LOWERALPHA
Definition atom.h:223
#define ATOM_FORMATTING_UNDERLINE
Definition atom.h:218
#define ATOM_LIST_UPPERALPHA
Definition atom.h:226
#define ATOM_FORMATTING_NOTRANSLATE
Definition atom.h:210
#define ATOM_LIST_TAG
Definition atom.h:221
#define ATOM_LIST_LOWERROMAN
Definition atom.h:224
#define ATOM_FORMATTING_SUBSCRIPT
Definition atom.h:213
#define ATOM_FORMATTING_BOLD
Definition atom.h:206
#define ATOM_FORMATTING_TRADEMARK
Definition atom.h:216
#define ATOM_LIST_VALUE
Definition atom.h:222
#define ATOM_FORMATTING_ITALIC
Definition atom.h:208
#define ATOM_LIST_UPPERROMAN
Definition atom.h:227
#define ATOM_FORMATTING_SUPERSCRIPT
Definition atom.h:214
#define ATOM_FORMATTING_INDEX
Definition atom.h:207
#define ATOM_FORMATTING_PARAMETER
Definition atom.h:211
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:154
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:237
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: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.
Definition node.h:210
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:233
virtual bool wasSeen() const
Returns the seen flag data member of this node if it is a NamespaceNode or a CollectionNode.
Definition node.h:194
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
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_