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