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
member.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 "member.h"
5
7
8#include <QJsonArray>
9
11
12using namespace Qt::Literals::StringLiterals;
13
14namespace IR {
15
16/*!
17 \struct IR::ParameterIR
18 \brief Intermediate representation of a function parameter.
19
20 ParameterIR captures the type, name, and optional default value
21 of a single function parameter. Templates use this to render
22 parameter lists in function synopses.
23
24 JSON output omits \c defaultValue when the string is empty,
25 following the convention of suppressing absent optional fields.
26*/
27
28/*!
29 \variable IR::ParameterIR::type
30 Parameter type (such as "const QString &").
31*/
32
33/*!
34 \variable IR::ParameterIR::name
35 Parameter name.
36*/
37
38/*!
39 \variable IR::ParameterIR::defaultValue
40 Default value expression, empty if none.
41*/
42
43/*!
44 Converts the parameter to a QJsonObject for template rendering.
45
46 Always emits \c type and \c name. The \c defaultValue key is
47 omitted when the default value string is empty.
48*/
50{
51 QJsonObject json;
52 json["type"_L1] = type;
53 json["name"_L1] = name;
54 if (!defaultValue.isEmpty())
55 json["defaultValue"_L1] = defaultValue;
56 return json;
57}
58
59/*!
60 \struct IR::EnumValueIR
61 \brief Intermediate representation of a single enum value.
62
63 EnumValueIR captures the name, explicit initializer, and version
64 information for one enumerator. Templates use this to render
65 enum value tables in class documentation.
66
67 JSON output omits \c value and \c since when their respective
68 strings are empty.
69*/
70
71/*!
72 \variable IR::EnumValueIR::name
73 Enumerator name.
74*/
75
76/*!
77 \variable IR::EnumValueIR::value
78 Explicit initializer expression, empty if the compiler assigns
79 the value.
80*/
81
82/*!
83 \variable IR::EnumValueIR::since
84 Qt version that introduced this enumerator, empty if unversioned.
85*/
86
87/*!
88 Converts the enum value to a QJsonObject for template rendering.
89
90 Always emits \c name. The \c value and \c since keys are omitted
91 when their respective strings are empty.
92*/
94{
95 QJsonObject json;
96 json["name"_L1] = name;
97 if (!value.isEmpty())
98 json["value"_L1] = value;
99 if (!since.isEmpty())
100 json["since"_L1] = since;
101 return json;
102}
103
104/*!
105 \struct IR::MemberIR
106 \brief Intermediate representation of a single documentable member.
107
108 MemberIR captures identity, classification, and type-specific
109 metadata for one member of an aggregate (such as a class,
110 namespace, or QML type). Function members carry parameter lists
111 and overload metadata; enum members carry value listings.
112 Templates use this to render summary tables and detail sections.
113
114 JSON output omits \c parameters and \c enumValues when the
115 respective lists are empty. The \c nodeType field is omitted
116 when set to NoType.
117*/
118
119/*!
120 \variable IR::MemberIR::name
121 Unqualified member name.
122*/
123
124/*!
125 \variable IR::MemberIR::fullName
126 Fully qualified name including the enclosing scope.
127*/
128
129/*!
130 \variable IR::MemberIR::signature
131 Display signature for synopsis rendering. The format depends on
132 the member type: functions include return type and default values,
133 properties use "name : type", and enums include the scoped or
134 unscoped distinction.
135*/
136
137/*!
138 \variable IR::MemberIR::href
139 URL of the member's detailed documentation.
140*/
141
142/*!
143 \variable IR::MemberIR::brief
144 One-line summary extracted from the member's doc comment,
145 empty if none.
146*/
147
148/*!
149 \variable IR::MemberIR::nodeType
150 Classification of the member's entity type (function, property,
151 enum, and so on). Defaults to NoType.
152*/
153
154/*!
155 \variable IR::MemberIR::access
156 Access level (public, protected, or private). Defaults to Public.
157*/
158
159/*!
160 \variable IR::MemberIR::status
161 Documentation status (active, deprecated, preliminary, or
162 internal). Defaults to Active.
163*/
164
165/*!
166 \variable IR::MemberIR::parameters
167 Parameter list for function members. Empty for non-functions.
168*/
169
170/*!
171 \variable IR::MemberIR::overloadNumber
172 Zero-based overload index. Zero indicates the primary overload.
173*/
174
175/*!
176 \variable IR::MemberIR::isPrimaryOverload
177 Whether this is the primary (first) overload of its name.
178 Defaults to true.
179*/
180
181/*!
182 \variable IR::MemberIR::enumValues
183 Value list for enum members. Empty for non-enums.
184*/
185
186/*!
187 \variable IR::MemberIR::isStatic
188 Whether the member is declared static.
189*/
190
191/*!
192 \variable IR::MemberIR::isConst
193 Whether the member is declared const.
194*/
195
196/*!
197 \variable IR::MemberIR::isVirtual
198 Whether the member is virtual (including pure virtual and
199 override).
200*/
201
202/*!
203 \variable IR::MemberIR::isSignal
204 Whether the member is a Qt signal.
205*/
206
207/*!
208 \variable IR::MemberIR::isSlot
209 Whether the member is a Qt slot.
210*/
211
212/*!
213 Converts the member to a QJsonObject for template rendering.
214
215 Emits identity fields (name, fullName, signature, href),
216 classification as \c {id, label} objects, overload metadata, and
217 qualifier flags. The \c brief, \c parameters, and \c enumValues
218 fields are omitted when empty. The \c nodeType field is omitted
219 when NoType.
220*/
222{
223 QJsonObject json;
224
225 json["name"_L1] = name;
226 json["fullName"_L1] = fullName;
227 json["signature"_L1] = signature;
228 json["href"_L1] = href;
229 if (!brief.isEmpty())
230 json["brief"_L1] = brief;
231
232 if (const auto t = nodeTypeToJson(nodeType))
233 json["nodeType"_L1] = *t;
234 json["status"_L1] = statusToJson(status);
235 json["access"_L1] = accessToJson(access);
236
237 json["overloadNumber"_L1] = overloadNumber;
238 json["isPrimaryOverload"_L1] = isPrimaryOverload;
239
240 if (!parameters.isEmpty()) {
241 QJsonArray arr;
242 for (const auto &p : parameters)
243 arr.append(p.toJson());
244 json["parameters"_L1] = arr;
245 }
246
247 if (!enumValues.isEmpty()) {
248 QJsonArray arr;
249 for (const auto &ev : enumValues)
250 arr.append(ev.toJson());
251 json["enumValues"_L1] = arr;
252 }
253
254 json["isStatic"_L1] = isStatic;
255 json["isConst"_L1] = isConst;
256 json["isVirtual"_L1] = isVirtual;
257 json["isSignal"_L1] = isSignal;
258 json["isSlot"_L1] = isSlot;
259
260 if (isAttached)
261 json["isAttached"_L1] = true;
262 if (isDefault)
263 json["isDefault"_L1] = true;
264 if (isReadOnly)
265 json["isReadOnly"_L1] = true;
266 if (isRequired)
267 json["isRequired"_L1] = true;
268 if (!dataType.isEmpty())
269 json["dataType"_L1] = dataType;
270
271 if (!anchorId.isEmpty())
272 json["anchorId"_L1] = anchorId;
273 if (!synopsis.isEmpty())
274 json["synopsis"_L1] = synopsis;
275 if (!since.isEmpty())
276 json["since"_L1] = since;
277 if (!threadSafety.isEmpty())
278 json["threadSafety"_L1] = threadSafety;
279 if (!comparisonCategory.isEmpty())
280 json["comparisonCategory"_L1] = comparisonCategory;
281 if (isNoexcept)
282 json["isNoexcept"_L1] = true;
283 if (!noexceptNote.isEmpty())
284 json["noexceptNote"_L1] = noexceptNote;
285
286 if (!body.isEmpty()) {
287 QJsonArray arr;
288 for (const auto &block : body)
289 arr.append(block.toJson());
290 json["body"_L1] = arr;
291 }
292
293 if (!alsoList.isEmpty()) {
294 QJsonArray arr;
295 for (const auto &block : alsoList)
296 arr.append(block.toJson());
297 json["alsoList"_L1] = arr;
298 }
299
300 return json;
301}
302
303/*!
304 \struct IR::InheritedMembersIR
305 \brief Summary of members inherited from a single base class.
306
307 InheritedMembersIR stores a count and link target for one base
308 class's contributed members. Templates use this to render lines
309 such as "5 public functions inherited from QObject" at the end
310 of a section.
311*/
312
313/*!
314 \variable IR::InheritedMembersIR::className
315 Fully qualified name of the base class.
316*/
317
318/*!
319 \variable IR::InheritedMembersIR::count
320 Number of members inherited from this base class.
321*/
322
323/*!
324 \variable IR::InheritedMembersIR::href
325 URL of the base class's documentation page.
326*/
327
328/*!
329 Converts the inherited members summary to a QJsonObject.
330
331 Emits \c className, \c count, and \c href. Templates combine
332 this with the enclosing section's \c plural field to render
333 links such as "5 public functions inherited from QObject".
334*/
336{
337 QJsonObject json;
338 json["className"_L1] = className;
339 json["count"_L1] = count;
340 json["href"_L1] = href;
341 return json;
342}
343
344/*!
345 \struct IR::SectionIR
346 \brief Intermediate representation of a member summary section.
347
348 SectionIR groups members by category (such as "Public Functions"
349 or "Properties") for summary table rendering. Each section carries
350 a title, singular and plural forms for inherited-member links, and
351 three member lists: primary members, reimplemented members, and
352 inherited member summaries.
353
354 The \c reimplementedMembers and \c inheritedMembers arrays are
355 omitted from JSON when empty.
356*/
357
358/*!
359 \variable IR::SectionIR::id
360 Stable ASCII identifier for anchor links, generated from the
361 title via Utilities::asAsciiPrintable().
362*/
363
364/*!
365 \variable IR::SectionIR::title
366 Display title (such as "Public Functions" or "Properties").
367*/
368
369/*!
370 \variable IR::SectionIR::singular
371 Singular form of the member type (such as "function").
372*/
373
374/*!
375 \variable IR::SectionIR::plural
376 Plural form of the member type (such as "functions").
377*/
378
379/*!
380 \variable IR::SectionIR::members
381 Primary members in this section.
382*/
383
384/*!
385 \variable IR::SectionIR::reimplementedMembers
386 Members that reimplement a virtual function from a base class.
387*/
388
389/*!
390 \variable IR::SectionIR::inheritedMembers
391 Summaries of members inherited from base classes.
392*/
393
394/*!
395 Converts the section to a QJsonObject for template rendering.
396
397 Emits \c id, \c title, \c singular, \c plural, and the \c members
398 array. The \c reimplementedMembers and \c inheritedMembers arrays
399 are omitted when empty.
400*/
402{
403 QJsonObject json;
404
405 json["id"_L1] = id;
406 json["title"_L1] = title;
407 json["singular"_L1] = singular;
408 json["plural"_L1] = plural;
409
410 QJsonArray membersArray;
411 for (const auto &m : members)
412 membersArray.append(m.toJson());
413 json["members"_L1] = membersArray;
414
415 if (!reimplementedMembers.isEmpty()) {
416 QJsonArray arr;
417 for (const auto &m : reimplementedMembers)
418 arr.append(m.toJson());
419 json["reimplementedMembers"_L1] = arr;
420 }
421
422 if (!inheritedMembers.isEmpty()) {
423 QJsonArray arr;
424 for (const auto &im : inheritedMembers)
425 arr.append(im.toJson());
426 json["inheritedMembers"_L1] = arr;
427 }
428
429 return json;
430}
431
432/*!
433 \struct IR::AllMemberEntry
434 \brief A single entry in an all-members listing page.
435
436 AllMemberEntry captures the display signature and link target for
437 one member on an all-members sub-page. QML properties carry display
438 hints (such as "read-only" or "default") and property groups nest
439 child entries under a parent.
440*/
441
442/*!
443 Converts the entry to a QJsonObject for template rendering.
444
445 Always emits \c signature and \c href. The \c hints array, \c
446 isPropertyGroup flag, and \c children array are omitted when
447 empty or false.
448*/
450{
451 QJsonObject json;
452 json["signature"_L1] = signature;
453 json["href"_L1] = href;
454
455 if (!hints.isEmpty()) {
456 QJsonArray arr;
457 for (const auto &hint : hints)
458 arr.append(hint);
459 json["hints"_L1] = arr;
460 }
461
462 if (isPropertyGroup)
463 json["isPropertyGroup"_L1] = true;
464
465 if (!children.isEmpty()) {
466 QJsonArray arr;
467 for (const auto &child : children)
468 arr.append(child.toJson());
469 json["children"_L1] = arr;
470 }
471
472 return json;
473}
474
475/*!
476 \struct IR::MemberGroup
477 \brief Members grouped by originating QML type in an all-members listing.
478
479 MemberGroup groups AllMemberEntry items by the QML type they originate
480 from, enabling templates to render "inherited from ..." headings. An
481 empty \c typeName indicates the type's own members.
482*/
483
484/*!
485 Converts the member group to a QJsonObject for template rendering.
486
487 Always emits \c typeName (even when empty, since empty means own
488 members), \c typeHref, and \c members array.
489*/
491{
492 QJsonObject json;
493 json["typeName"_L1] = typeName;
494 json["typeHref"_L1] = typeHref;
495
496 QJsonArray arr;
497 for (const auto &entry : members)
498 arr.append(entry.toJson());
499 json["members"_L1] = arr;
500
501 return json;
502}
503
504/*!
505 \struct IR::AllMembersIR
506 \brief Intermediate representation of the all-members listing page.
507
508 AllMembersIR captures all data needed to render a member listing
509 sub-page. It supports two rendering paths: a flat alphabetical list
510 for C++ classes and a grouped-by-origin-type list for QML types.
511 The \c isQmlType flag determines which path the template uses.
512*/
513
514/*!
515 Converts the all-members IR to a QJsonObject for template rendering.
516
517 Always emits \c typeName, \c typeHref, and \c isQmlType. The
518 \c members and \c memberGroups arrays are emitted only when
519 non-empty, letting templates distinguish C++ from QML by checking
520 which key exists.
521*/
523{
524 QJsonObject json;
525 json["typeName"_L1] = typeName;
526 json["typeHref"_L1] = typeHref;
527 json["isQmlType"_L1] = isQmlType;
528
529 if (!members.isEmpty()) {
530 QJsonArray arr;
531 for (const auto &entry : members)
532 arr.append(entry.toJson());
533 json["members"_L1] = arr;
534 }
535
536 if (!memberGroups.isEmpty()) {
537 QJsonArray arr;
538 for (const auto &group : memberGroups)
539 arr.append(group.toJson());
540 json["memberGroups"_L1] = arr;
541 }
542
543 return json;
544}
545
546} // namespace IR
547
548QT_END_NAMESPACE
Definition builder.cpp:14
Combined button and popup list for selecting options.
A single entry in an all-members listing page.
Definition member.h:96
QJsonObject toJson() const
Converts the entry to a QJsonObject for template rendering.
Definition member.cpp:449
Intermediate representation of the all-members listing page.
Definition member.h:112
QJsonObject toJson() const
Converts the all-members IR to a QJsonObject for template rendering.
Definition member.cpp:522
Intermediate representation of a single enum value.
Definition member.h:27
QJsonObject toJson() const
\variable IR::EnumValueIR::name Enumerator name.
Definition member.cpp:93
Summary of members inherited from a single base class.
Definition member.h:78
QJsonObject toJson() const
\variable IR::InheritedMembersIR::className Fully qualified name of the base class.
Definition member.cpp:335
Members grouped by originating QML type in an all-members listing.
Definition member.h:105
QJsonObject toJson() const
Converts the member group to a QJsonObject for template rendering.
Definition member.cpp:490
Intermediate representation of a single documentable member.
Definition member.h:34
QJsonObject toJson() const
\variable IR::MemberIR::name Unqualified member name.
Definition member.cpp:221
Intermediate representation of a function parameter.
Definition member.h:20
QJsonObject toJson() const
\variable IR::ParameterIR::type Parameter type (such as "const QString &").
Definition member.cpp:49
Intermediate representation of a member summary section.
Definition member.h:85
QJsonObject toJson() const
\variable IR::SectionIR::id Stable ASCII identifier for anchor links, generated from the title via Ut...
Definition member.cpp:401