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
builder.cpp
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#include "builder.h"
5
6#include "pagemetadata.h"
7
8#include <utility>
9
10QT_BEGIN_NAMESPACE
11
12using namespace Qt::Literals;
13
14namespace IR {
15
16/*!
17 \class IR::Builder
18 \internal
19 \brief Assembles IR Documents from pre-extracted metadata.
20
21 Builder consumes PageMetadata, a value-type struct populated by the
22 driver-side extraction layer (NodeExtractor). It copies pre-extracted
23 fields into an IR::Document without touching Node subclass headers,
24 Atom chains, or the documentation database.
25
26 This separation means Builder has no dependencies on the legacy Node
27 layer and is eligible for QDocLib migration. Generators receive
28 pre-built IR and focus purely on formatting output.
29
30 \section1 Content Pipeline
31
32 Content arrives pre-built as a list of ContentBlock values in
33 PageMetadata::body. ContentBuilder (called at extraction time)
34 handles the atom-to-block transformation, including brief
35 exclusion. Format-conditional atoms are skipped unconditionally
36 since the IR is format-agnostic. Builder's role is assembly, not
37 transformation.
38
39 \section1 Flat Text Fallback
40
41 Builder computes a flat text representation from the structured body
42 for \c{content.text}. This is transitional — templates will consume
43 \c{content.blocks} directly once content rendering is in place.
44
45 \sa IR::Document, IR::PageMetadata, TemplateGenerator
46*/
47
48
49/*!
50 \internal
51 Assemble an IR Document from pre-extracted PageMetadata.
52
53 Classification, identity, and content fields are moved from
54 \a pm. The body (a list of ContentBlock values built by
55 ContentBuilder at extraction time) is transferred as-is. A flat
56 text fallback is computed until templates consume the structured
57 body directly.
58*/
60{
61 Document ir;
62
63 ir.nodeType = pm.nodeType;
64 ir.genus = pm.genus;
65 ir.status = pm.status;
66 ir.access = pm.access;
67
68 ir.title = std::move(pm.title);
69 ir.fullTitle = std::move(pm.fullTitle);
70 ir.url = std::move(pm.url);
71 ir.since = std::move(pm.since);
72 ir.deprecatedSince = std::move(pm.deprecatedSince);
73 ir.brief = std::move(pm.brief);
74
75 ir.body = std::move(pm.body);
76 ir.summarySections = std::move(pm.summarySections);
77 ir.detailSections = std::move(pm.detailSections);
78
79 if (pm.qmlTypeData) {
80 const auto &src = *pm.qmlTypeData;
81 QmlTypeInfo info;
82 info.importStatement = src.importStatement;
83 info.isSingleton = src.isSingleton;
84 info.isValueType = src.isValueType;
85
86 if (src.inherits) {
87 info.inherits = QmlTypeInfo::InheritsInfo{
88 src.inherits->name, src.inherits->href, src.inherits->moduleName
89 };
90 }
91
92 for (const auto &entry : src.inheritedBy)
93 info.inheritedBy.append({entry.name, entry.href});
94
95 if (src.nativeType)
96 info.nativeType = QmlTypeInfo::NativeTypeInfo{src.nativeType->name, src.nativeType->href};
97
98 ir.qmlTypeInfo = std::move(info);
99 }
100
101 if (pm.collectionData) {
102 const auto &src = *pm.collectionData;
103 CollectionInfo info;
104 info.logicalModuleName = src.logicalModuleName;
105 info.logicalModuleVersion = src.logicalModuleVersion;
106 info.qtVariable = src.qtVariable;
107 info.cmakePackage = src.cmakePackage;
108 info.cmakeComponent = src.cmakeComponent;
109 info.cmakeTargetItem = src.cmakeTargetItem;
110 info.state = src.state;
111
112 info.isModule = src.isModule;
113 info.isQmlModule = src.isQmlModule;
114 info.isGroup = src.isGroup;
115 info.noAutoList = src.noAutoList;
116
117 for (const auto &entry : src.namespaces)
118 info.namespaces.append({entry.name, entry.href, entry.brief});
119 for (const auto &entry : src.classes)
120 info.classes.append({entry.name, entry.href, entry.brief});
121 for (const auto &entry : src.members)
122 info.members.append({entry.name, entry.href, entry.brief});
123
124 ir.collectionInfo = std::move(info);
125 }
126
127 // Transitional: templates don't yet consume content.blocks.
128 QStringList paragraphs;
129 for (const auto &block : ir.body) {
130 const QString text = block.plainText();
131 if (!text.isEmpty())
132 paragraphs.append(text);
133 }
134 ir.contentJson["text"_L1] = paragraphs.join("\n\n"_L1);
135
136 return ir;
137}
138
139} // namespace IR
140
141QT_END_NAMESPACE
Assembles IR Documents from pre-extracted metadata.
Definition builder.h:15
Document buildPageIR(PageMetadata pm) const
Definition builder.cpp:59
Definition builder.cpp:14
Intermediate representation for a documentation topic.
Definition document.h:81
Access access
Definition document.h:86
Status status
Definition document.h:85
NodeType nodeType
Definition document.h:83
Genus genus
Definition document.h:84