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::SharedDetailGroup
106 \brief One documentation body and see-also list shared by a group of members.
107
108 SharedDetailGroup captures the detail content that a group of members
109 documented by a single shared comment (a SharedCommentNode) all share:
110 one body and one see-also list, rendered once for the whole group.
111
112 The group references its members positionally: \c firstIndex is the
113 zero-based index of the group's first member in the section's member
114 list, and \c count is the number of members it covers. Member identity,
115 synopses, anchors, and per-member fields stay in the section's flat
116 member list, which keeps ordinary member JSON unchanged; members of the
117 group carry the group's index in their \c sharedGroup field instead of
118 the shared body and see-also content.
119
120 The lookup context the shared content was authored in (the
121 SharedCommentNode) is deliberately not part of this IR; the extractor
122 keeps it outside the template-facing representation.
123
124 JSON output always emits \c firstIndex, \c count, \c body, and
125 \c alsoList, the latter two even when empty, so that templates can
126 index a group positionally and guard only on array length. The group's
127 status sentence uses \c status and \c isPlural, with the noun and
128 version fields emitted only when nonempty. The \c anchorId key is
129 emitted only when nonempty; anonymous groups carry no key at all.
130*/
131
132/*!
133 \variable IR::SharedDetailGroup::firstIndex
134 Zero-based index of the group's first member in the section's member
135 list. Negative when the group is not populated.
136*/
137
138/*!
139 \variable IR::SharedDetailGroup::count
140 Number of section members the group covers.
141*/
142
143/*!
144 \variable IR::SharedDetailGroup::status
145 The status of the shared comment, rather than any individual child.
146*/
147
148/*!
149 \variable IR::SharedDetailGroup::isPlural
150 Whether the group describes multiple members. Named property groups
151 describe one entity and remain singular.
152*/
153
154/*!
155 \variable IR::SharedDetailGroup::anchorId
156 The page fragment the group itself is reachable at, such as
157 \c font-prop for a named QML property group. Empty when the group
158 has no anchor of its own (an anonymous shared comment) or when the
159 fragment is already owned by another destination on the page. The
160 group's children keep their own \c anchorId values.
161*/
162
163/*!
164 \variable IR::SharedDetailGroup::deprecatedSince
165 The plain version used in a scheduled-deprecation sentence.
166*/
167
168/*!
169 \variable IR::SharedDetailGroup::typeNoun
170 The singular or plural type noun used in the group's status sentence.
171*/
172
173/*!
174 \variable IR::SharedDetailGroup::deprecatedSinceQualified
175 The deprecation version, prefixed with the logical module name for QML.
176*/
177
178/*!
179 \variable IR::SharedDetailGroup::body
180 The documentation body authored on the shared comment.
181*/
182
183/*!
184 \variable IR::SharedDetailGroup::alsoList
185 The see-also list authored on the shared comment.
186*/
187
188/*!
189 Converts the shared detail group to a QJsonObject for template rendering.
190
191 Always emits \c firstIndex and \c count, and both the \c body and
192 \c alsoList arrays, which may be empty. The \c anchorId key is
193 omitted when empty.
194*/
196{
197 QJsonObject json;
198 json["firstIndex"_L1] = firstIndex;
199 json["count"_L1] = count;
200 json["status"_L1] = statusToJson(status);
201 json["isPlural"_L1] = isPlural;
202 if (!anchorId.isEmpty())
203 json["anchorId"_L1] = anchorId;
204 if (!deprecatedSince.isEmpty())
205 json["deprecatedSince"_L1] = deprecatedSince;
206 if (!typeNoun.isEmpty())
207 json["typeNoun"_L1] = typeNoun;
208 if (!deprecatedSinceQualified.isEmpty())
209 json["deprecatedSinceQualified"_L1] = deprecatedSinceQualified;
210 if (!deprecationNote.isEmpty()) {
211 QJsonArray note;
212 for (const auto &block : deprecationNote)
213 note.append(block.toJson());
214 json["deprecationNote"_L1] = note;
215 }
216
217 QJsonArray bodyArray;
218 for (const auto &block : body)
219 bodyArray.append(block.toJson());
220 json["body"_L1] = bodyArray;
221
222 QJsonArray alsoArray;
223 for (const auto &block : alsoList)
224 alsoArray.append(block.toJson());
225 json["alsoList"_L1] = alsoArray;
226
227 return json;
228}
229
230/*!
231 \struct IR::MemberIR
232 \brief Intermediate representation of a single documentable member.
233
234 MemberIR captures identity, classification, and type-specific
235 metadata for one member of an aggregate (such as a class,
236 namespace, or QML type). Function members carry parameter lists
237 and overload metadata; enum members carry value listings.
238 Templates use this to render summary tables and detail sections.
239
240 JSON output omits \c parameters and \c enumValues when the
241 respective lists are empty. The \c nodeType field is omitted
242 when set to NoType.
243*/
244
245/*!
246 \variable IR::MemberIR::name
247 Unqualified member name.
248*/
249
250/*!
251 \variable IR::MemberIR::fullName
252 Fully qualified name including the enclosing scope.
253*/
254
255/*!
256 \variable IR::MemberIR::signature
257 Display signature for synopsis rendering. The format depends on
258 the member type: functions include return type and default values,
259 properties use "name : type", and enums include the scoped or
260 unscoped distinction.
261*/
262
263/*!
264 \variable IR::MemberIR::href
265 URL of the member's detailed documentation.
266*/
267
268/*!
269 \variable IR::MemberIR::brief
270 One-line summary extracted from the member's doc comment,
271 empty if none.
272*/
273
274/*!
275 \variable IR::MemberIR::nodeType
276 Classification of the member's entity type (function, property,
277 enum, and so on). Defaults to NoType.
278*/
279
280/*!
281 \variable IR::MemberIR::access
282 Access level (public, protected, or private). Defaults to Public.
283*/
284
285/*!
286 \variable IR::MemberIR::status
287 Documentation status (active, deprecated, preliminary, or
288 internal). Defaults to Active.
289*/
290
291/*!
292 \variable IR::MemberIR::deprecatedSince
293 Version the member was deprecated in, or the version in which a
294 scheduled deprecation takes place. Empty when no deprecation
295 status sentence applies.
296*/
297
298/*!
299 \variable IR::MemberIR::typeNoun
300 Human-readable noun for the member's node type (such as
301 "function", "property", or "method"), used to build the
302 deprecation status sentence. Empty when no status sentence
303 applies.
304*/
305
306/*!
307 \variable IR::MemberIR::deprecatedSinceQualified
308 The deprecation version prefixed with the QML module name for QML
309 members that have a logical module name (such as "QtQuick 6.5");
310 otherwise the plain \c deprecatedSince. Empty when no status
311 sentence applies or when there is no version.
312*/
313
314/*!
315 \variable IR::MemberIR::parameters
316 Parameter list for function members. Empty for non-functions.
317*/
318
319/*!
320 \variable IR::MemberIR::overloadNumber
321 Zero-based overload index. Zero indicates the primary overload.
322*/
323
324/*!
325 \variable IR::MemberIR::isPrimaryOverload
326 Whether this is the primary (first) overload of its name.
327 Defaults to true.
328*/
329
330/*!
331 \variable IR::MemberIR::enumValues
332 Value list for enum members. Empty for non-enums.
333*/
334
335/*!
336 \variable IR::MemberIR::signatureSpans
337 Structured signature spans carrying semantic roles and resolved
338 hrefs. When populated, templates can render rich signatures with
339 type links and role-based styling. Empty by default for backward
340 compatibility with the plain text \c synopsis field.
341*/
342
343/*!
344 \variable IR::MemberIR::isStatic
345 Whether the member is declared static.
346*/
347
348/*!
349 \variable IR::MemberIR::isConst
350 Whether the member is declared const.
351*/
352
353/*!
354 \variable IR::MemberIR::isVirtual
355 Whether the member is virtual (including pure virtual and
356 override).
357*/
358
359/*!
360 \variable IR::MemberIR::isSignal
361 Whether the member is a Qt signal.
362*/
363
364/*!
365 \variable IR::MemberIR::isSlot
366 Whether the member is a Qt slot.
367*/
368
369/*!
370 \variable IR::MemberIR::sharedGroup
371 Index of the section's shared detail group this member belongs to, or
372 -1 when the member carries its own body and see-also content. A member
373 of a shared group has an empty \c body and \c alsoList; the shared
374 content is rendered once from the group its index refers to. The
375 \c sharedGroup key is omitted from JSON when -1.
376*/
377
378/*!
379 Converts the member to a QJsonObject for template rendering.
380
381 Emits identity fields (name, fullName, signature, href),
382 classification as \c {id, label} objects, overload metadata, and
383 qualifier flags. The \c brief, \c parameters, and \c enumValues
384 fields are omitted when empty. The \c nodeType field is omitted
385 when NoType. The \c sharedGroup field is omitted when -1.
386*/
388{
389 QJsonObject json;
390
391 json["name"_L1] = name;
392 json["fullName"_L1] = fullName;
393 json["signature"_L1] = signature;
394 json["href"_L1] = href;
395 if (!brief.isEmpty())
396 json["brief"_L1] = brief;
397
398 if (const auto t = nodeTypeToJson(nodeType))
399 json["nodeType"_L1] = *t;
400 json["status"_L1] = statusToJson(status);
401 json["access"_L1] = accessToJson(access);
402 if (!deprecatedSince.isEmpty())
403 json["deprecatedSince"_L1] = deprecatedSince;
404 if (!typeNoun.isEmpty())
405 json["typeNoun"_L1] = typeNoun;
406 if (!deprecatedSinceQualified.isEmpty())
407 json["deprecatedSinceQualified"_L1] = deprecatedSinceQualified;
408 if (!deprecationNote.isEmpty()) {
409 QJsonArray note;
410 for (const auto &block : deprecationNote)
411 note.append(block.toJson());
412 json["deprecationNote"_L1] = note;
413 }
414
415 json["overloadNumber"_L1] = overloadNumber;
416 json["isPrimaryOverload"_L1] = isPrimaryOverload;
417
418 if (!parameters.isEmpty()) {
419 QJsonArray arr;
420 for (const auto &p : parameters)
421 arr.append(p.toJson());
422 json["parameters"_L1] = arr;
423 }
424
425 if (!enumValues.isEmpty()) {
426 QJsonArray arr;
427 for (const auto &ev : enumValues)
428 arr.append(ev.toJson());
429 json["enumValues"_L1] = arr;
430 }
431
432 json["isStatic"_L1] = isStatic;
433 json["isConst"_L1] = isConst;
434 json["isVirtual"_L1] = isVirtual;
435 json["isSignal"_L1] = isSignal;
436 json["isSlot"_L1] = isSlot;
437
438 if (isAttached)
439 json["isAttached"_L1] = true;
440 if (isDefault)
441 json["isDefault"_L1] = true;
442 if (isReadOnly)
443 json["isReadOnly"_L1] = true;
444 if (isRequired)
445 json["isRequired"_L1] = true;
446 if (!dataType.isEmpty())
447 json["dataType"_L1] = dataType;
448
449 json["anchorId"_L1] = anchorId;
450 json["synopsis"_L1] = synopsis;
451 if (!signatureSpans.isEmpty()) {
452 QJsonArray arr;
453 for (const auto &span : signatureSpans)
454 arr.append(span.toJson());
455 json["signatureSpans"_L1] = arr;
456 }
457 if (!since.isEmpty())
458 json["since"_L1] = since;
459 if (!threadSafety.isEmpty())
460 json["threadSafety"_L1] = threadSafety;
461 if (!comparisonCategory.isEmpty())
462 json["comparisonCategory"_L1] = comparisonCategory;
463 if (isNoexcept)
464 json["isNoexcept"_L1] = true;
465 if (!noexceptNote.isEmpty())
466 json["noexceptNote"_L1] = noexceptNote;
467
468 if (!body.isEmpty()) {
469 QJsonArray arr;
470 for (const auto &block : body)
471 arr.append(block.toJson());
472 json["body"_L1] = arr;
473 }
474
475 if (!alsoList.isEmpty()) {
476 QJsonArray arr;
477 for (const auto &block : alsoList)
478 arr.append(block.toJson());
479 json["alsoList"_L1] = arr;
480 }
481
482 if (sharedGroup >= 0)
483 json["sharedGroup"_L1] = sharedGroup;
484
485 return json;
486}
487
488/*!
489 \struct IR::InheritedMembersIR
490 \brief Summary of members inherited from a single base class.
491
492 InheritedMembersIR stores a count and link target for one base
493 class's contributed members. Templates use this to render lines
494 such as "5 public functions inherited from QObject" at the end
495 of a section.
496*/
497
498/*!
499 \variable IR::InheritedMembersIR::className
500 Fully qualified name of the base class.
501*/
502
503/*!
504 \variable IR::InheritedMembersIR::count
505 Number of members inherited from this base class.
506*/
507
508/*!
509 \variable IR::InheritedMembersIR::href
510 URL of the base class's documentation page.
511*/
512
513/*!
514 Converts the inherited members summary to a QJsonObject.
515
516 Emits \c className, \c count, and \c href. Templates combine
517 this with the enclosing section's \c plural field to render
518 links such as "5 public functions inherited from QObject".
519*/
521{
522 QJsonObject json;
523 json["className"_L1] = className;
524 json["count"_L1] = count;
525 json["href"_L1] = href;
526 return json;
527}
528
529/*!
530 \struct IR::SectionIR
531 \brief Intermediate representation of a member summary section.
532
533 SectionIR groups members by category (such as "Public Functions"
534 or "Properties") for summary table rendering. Each section carries
535 a title, singular and plural forms for inherited-member links, and
536 three member lists: primary members, reimplemented members, and
537 inherited member summaries.
538
539 The \c sharedGroups list carries the shared detail content of
540 member groups documented by a single shared comment; each group's
541 members stay in the flat \c members list and reference their group
542 through \c sharedGroup. The \c reimplementedMembers,
543 \c inheritedMembers, and \c sharedGroups arrays are omitted from
544 JSON when empty.
545*/
546
547/*!
548 \variable IR::SectionIR::id
549 Stable ASCII identifier for anchor links, generated from the
550 title via TextUtils::asAsciiPrintable().
551*/
552
553/*!
554 \variable IR::SectionIR::title
555 Display title (such as "Public Functions" or "Properties").
556*/
557
558/*!
559 \variable IR::SectionIR::singular
560 Singular form of the member type (such as "function").
561*/
562
563/*!
564 \variable IR::SectionIR::plural
565 Plural form of the member type (such as "functions").
566*/
567
568/*!
569 \variable IR::SectionIR::members
570 Primary members in this section.
571*/
572
573/*!
574 \variable IR::SectionIR::reimplementedMembers
575 Members that reimplement a virtual function from a base class.
576*/
577
578/*!
579 \variable IR::SectionIR::inheritedMembers
580 Summaries of members inherited from base classes.
581*/
582
583/*!
584 \variable IR::SectionIR::sharedGroups
585 Shared detail groups whose members appear in this section's
586 \c members list, in the order the groups are encountered. Empty
587 (and omitted from JSON) when the section has no shared comment
588 groups.
589*/
590
591/*!
592 Converts the section to a QJsonObject for template rendering.
593
594 Emits \c id, \c title, \c singular, \c plural, and the \c members
595 array. The \c reimplementedMembers, \c inheritedMembers, and
596 \c sharedGroups arrays are omitted when empty.
597*/
599{
600 QJsonObject json;
601
602 json["id"_L1] = id;
603 json["title"_L1] = title;
604 json["singular"_L1] = singular;
605 json["plural"_L1] = plural;
606
607 QJsonArray membersArray;
608 for (const auto &m : members)
609 membersArray.append(m.toJson());
610 json["members"_L1] = membersArray;
611
612 if (!reimplementedMembers.isEmpty()) {
613 QJsonArray arr;
614 for (const auto &m : reimplementedMembers)
615 arr.append(m.toJson());
616 json["reimplementedMembers"_L1] = arr;
617 }
618
619 if (!inheritedMembers.isEmpty()) {
620 QJsonArray arr;
621 for (const auto &im : inheritedMembers)
622 arr.append(im.toJson());
623 json["inheritedMembers"_L1] = arr;
624 }
625
626 if (!sharedGroups.isEmpty()) {
627 QJsonArray arr;
628 for (const auto &group : sharedGroups)
629 arr.append(group.toJson());
630 json["sharedGroups"_L1] = arr;
631 }
632
633 return json;
634}
635
636/*!
637 \struct IR::AllMemberEntry
638 \brief A single entry in an all-members listing page.
639
640 AllMemberEntry captures the display signature and link target for
641 one member on an all-members sub-page. QML properties carry display
642 hints (such as "read-only" or "default") and property groups nest
643 child entries under a parent.
644*/
645
646/*!
647 Converts the entry to a QJsonObject for template rendering.
648
649 Always emits \c signature and \c href. The \c hints array, \c
650 isPropertyGroup flag, and \c children array are omitted when
651 empty or false.
652*/
654{
655 QJsonObject json;
656 json["signature"_L1] = signature;
657 if (!signatureSpans.isEmpty()) {
658 QJsonArray arr;
659 for (const auto &span : signatureSpans)
660 arr.append(span.toJson());
661 json["signatureSpans"_L1] = arr;
662 }
663 json["href"_L1] = href;
664
665 if (!hints.isEmpty()) {
666 QJsonArray arr;
667 for (const auto &hint : hints)
668 arr.append(hint);
669 json["hints"_L1] = arr;
670 }
671
672 if (isPropertyGroup)
673 json["isPropertyGroup"_L1] = true;
674
675 if (!children.isEmpty()) {
676 QJsonArray arr;
677 for (const auto &child : children)
678 arr.append(child.toJson());
679 json["children"_L1] = arr;
680 }
681
682 return json;
683}
684
685/*!
686 \struct IR::MemberGroup
687 \brief Members grouped by originating QML type in an all-members listing.
688
689 MemberGroup groups AllMemberEntry items by the QML type they originate
690 from, enabling templates to render "inherited from ..." headings. An
691 empty \c typeName indicates the type's own members.
692*/
693
694/*!
695 Converts the member group to a QJsonObject for template rendering.
696
697 Always emits \c typeName (even when empty, since empty means own
698 members), \c typeHref, and \c members array.
699*/
701{
702 QJsonObject json;
703 json["typeName"_L1] = typeName;
704 json["typeHref"_L1] = typeHref;
705
706 QJsonArray arr;
707 for (const auto &entry : members)
708 arr.append(entry.toJson());
709 json["members"_L1] = arr;
710
711 return json;
712}
713
714/*!
715 \struct IR::AllMembersIR
716 \brief Intermediate representation of the all-members listing page.
717
718 AllMembersIR captures all data needed to render a member listing
719 sub-page. It supports two rendering paths: a flat alphabetical list
720 for C++ classes and a grouped-by-origin-type list for QML types.
721 The \c isQmlType flag determines which path the template uses.
722*/
723
724/*!
725 Converts the all-members IR to a QJsonObject for template rendering.
726
727 Always emits \c typeName, \c typeHref, and \c isQmlType. The
728 \c members and \c memberGroups arrays are emitted only when
729 non-empty, letting templates distinguish C++ from QML by checking
730 which key exists.
731*/
733{
734 QJsonObject json;
735 json["typeName"_L1] = typeName;
736 json["typeHref"_L1] = typeHref;
737 json["isQmlType"_L1] = isQmlType;
738
739 if (!members.isEmpty()) {
740 QJsonArray arr;
741 for (const auto &entry : members)
742 arr.append(entry.toJson());
743 json["members"_L1] = arr;
744 }
745
746 if (!memberGroups.isEmpty()) {
747 QJsonArray arr;
748 for (const auto &group : memberGroups)
749 arr.append(group.toJson());
750 json["memberGroups"_L1] = arr;
751 }
752
753 return json;
754}
755
756} // namespace IR
757
758QT_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:129
QJsonObject toJson() const
Converts the entry to a QJsonObject for template rendering.
Definition member.cpp:653
Intermediate representation of the all-members listing page.
Definition member.h:146
QJsonObject toJson() const
Converts the all-members IR to a QJsonObject for template rendering.
Definition member.cpp:732
Intermediate representation of a single enum value.
Definition member.h:28
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:108
QJsonObject toJson() const
\variable IR::InheritedMembersIR::className Fully qualified name of the base class.
Definition member.cpp:520
Members grouped by originating QML type in an all-members listing.
Definition member.h:139
QJsonObject toJson() const
Converts the member group to a QJsonObject for template rendering.
Definition member.cpp:700
Intermediate representation of a single documentable member.
Definition member.h:54
QJsonObject toJson() const
\variable IR::MemberIR::name Unqualified member name.
Definition member.cpp:387
Intermediate representation of a function parameter.
Definition member.h:21
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:115
QJsonObject toJson() const
\variable IR::SectionIR::id Stable ASCII identifier for anchor links, generated from the title via Te...
Definition member.cpp:598
One documentation body and see-also list shared by a group of members.
Definition member.h:35
QJsonObject toJson() const
\variable IR::SharedDetailGroup::firstIndex Zero-based index of the group's first member in the secti...
Definition member.cpp:195