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
contentbuilder.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef QDOC_IR_CONTENTBUILDER_H
5#define QDOC_IR_CONTENTBUILDER_H
6
7#include "contentblock.h"
8
9#include <QJsonObject>
10#include <QList>
11#include <QString>
12
13#include <functional>
14
15QT_BEGIN_NAMESPACE
16
17class Atom;
18
19namespace IR {
20
22
23/*!
24 \enum IR::BriefHandling
25 \internal
26
27 Controls whether ContentBuilder emits brief content into the body.
28
29 \value Skip Brief content between BriefLeft/BriefRight is suppressed.
30 This is the default for IR::Builder, where the brief is stored
31 as a separate field in IR::Document.
32 \value Include Brief content is emitted as a normal Paragraph block.
33 This enables callers that need the brief rendered as part of
34 the body, matching the behavior where the brief appears as the
35 opening paragraph.
36*/
37enum class BriefHandling { Skip, Include };
38
40{
41public:
42 explicit ContentBuilder(BriefHandling briefHandling = BriefHandling::Skip,
43 int headingOffset = 0,
44 DiagnosticHandler diagnosticHandler = {});
45 QList<ContentBlock> build(const Atom *firstAtom);
46
47private:
48 void processAtoms(const Atom *atom);
49 const Atom *skipFormatIfBlock(const Atom *atom);
50 const Atom *dispatchAtom(const Atom *atom);
51
52 void openBlock(BlockType type, QJsonObject attrs = {});
53 void closeBlock();
54 void addInline(InlineContent inline_);
55 void addLeafInline(InlineType type, const QString &text);
56 void pushInlineContainer(InlineContent container);
57
58 ContentBlock *resolveBlock();
59 InlineContent *resolveInline();
60
61 QList<ContentBlock> m_result;
62
63 // Index path through m_result / children hierarchy.
64 // First index selects from m_result; subsequent indices descend
65 // through children lists. Indices remain valid as long as we only
66 // append and never remove or reorder items.
67 QList<qsizetype> m_blockPath;
68
69 QList<qsizetype> m_inlinePath;
70
71 // Records m_inlinePath.size() at each openBlock() call, so that
72 // closeBlock() can verify/restore inline depth (one entry per
73 // m_blockPath entry, always in sync).
74 QList<qsizetype> m_inlineBaseDepths;
75
76 BriefHandling m_briefHandling = BriefHandling::Skip;
77 int m_headingOffset = 0;
78 bool m_inBrief = false;
79 bool m_inLink = false;
80 DiagnosticHandler m_diagnose;
81};
82
83} // namespace IR
84
85QT_END_NAMESPACE
86
87#endif // QDOC_IR_CONTENTBUILDER_H
#define ATOM_FORMATTING_TELETYPE
Definition atom.h:213
#define ATOM_FORMATTING_UNDERLINE
Definition atom.h:216
#define ATOM_FORMATTING_NOTRANSLATE
Definition atom.h:208
#define ATOM_LIST_TAG
Definition atom.h:219
#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_FORMATTING_LINK
Definition atom.h:207
#define ATOM_FORMATTING_SUPERSCRIPT
Definition atom.h:212
#define ATOM_FORMATTING_INDEX
Definition atom.h:205
#define ATOM_FORMATTING_UICONTROL
Definition atom.h:215
#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
@ TableRight
Definition atom.h:97
@ GeneratedList
Definition atom.h:52
@ BriefRight
Definition atom.h:27
@ TableHeaderRight
Definition atom.h:99
@ FormatElse
Definition atom.h:47
@ InlineImage
Definition atom.h:58
@ TableRowRight
Definition atom.h:101
@ Nop
Definition atom.h:74
@ WarningRight
Definition atom.h:111
@ ListTagRight
Definition atom.h:68
@ NavLink
Definition atom.h:73
@ ListItemNumber
Definition atom.h:66
@ SinceTagRight
Definition atom.h:91
@ CodeBad
Definition atom.h:32
@ 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
@ Code
Definition atom.h:31
@ ListLeft
Definition atom.h:65
@ NavAutoLink
Definition atom.h:72
@ BriefLeft
Definition atom.h:26
@ ImageText
Definition atom.h:55
@ ListRight
Definition atom.h:71
@ ParaRight
Definition atom.h:78
@ Qml
Definition atom.h:79
@ FormattingLeft
Definition atom.h:50
@ FormattingRight
Definition atom.h:51
@ SectionHeadingRight
Definition atom.h:86
@ Link
Definition atom.h:63
@ FormatEndif
Definition atom.h:48
@ SinceTagLeft
Definition atom.h:90
@ AutoLink
Definition atom.h:23
@ TableItemLeft
Definition atom.h:102
@ NoteRight
Definition atom.h:76
@ BaseName
Definition atom.h:24
@ FormatIf
Definition atom.h:49
virtual bool isLinkAtom() const
Definition atom.h:163
const Atom * next() const
Return the next atom in the atom list.
Definition atom.h:152
virtual Genus genus()
Definition atom.h:164
Converts Atom chains to QList<IR::ContentBlock> trees.
QList< ContentBlock > build(const Atom *firstAtom)
Walks the atom chain starting at firstAtom and returns a list of ContentBlock trees representing the ...
ContentBuilder(BriefHandling briefHandling=BriefHandling::Skip, int headingOffset=0, DiagnosticHandler diagnosticHandler={})
Constructs a ContentBuilder.
static QString genusToString(Genus genus)
Definition builder.cpp:14
LinkState
LinkOrigin
BriefHandling
BlockType
static InlineType formattingToInlineType(const QString &formatting)
InlineType
Combined button and popup list for selecting options.
Represents a structural block element in documentation.
Represents inline content within a documentation block.