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::deprecatedSince
167 Version the member was deprecated in, or the version in which a
168 scheduled deprecation takes place. Empty when no deprecation
169 status sentence applies.
170*/
171
172/*!
173 \variable IR::MemberIR::typeNoun
174 Human-readable noun for the member's node type (such as
175 "function", "property", or "method"), used to build the
176 deprecation status sentence. Empty when no status sentence
177 applies.
178*/
179
180/*!
181 \variable IR::MemberIR::deprecatedSinceQualified
182 The deprecation version prefixed with the QML module name for QML
183 members that have a logical module name (such as "QtQuick 6.5");
184 otherwise the plain \c deprecatedSince. Empty when no status
185 sentence applies or when there is no version.
186*/
187
188/*!
189 \variable IR::MemberIR::parameters
190 Parameter list for function members. Empty for non-functions.
191*/
192
193/*!
194 \variable IR::MemberIR::overloadNumber
195 Zero-based overload index. Zero indicates the primary overload.
196*/
197
198/*!
199 \variable IR::MemberIR::isPrimaryOverload
200 Whether this is the primary (first) overload of its name.
201 Defaults to true.
202*/
203
204/*!
205 \variable IR::MemberIR::enumValues
206 Value list for enum members. Empty for non-enums.
207*/
208
209/*!
210 \variable IR::MemberIR::signatureSpans
211 Structured signature spans carrying semantic roles and resolved
212 hrefs. When populated, templates can render rich signatures with
213 type links and role-based styling. Empty by default for backward
214 compatibility with the plain text \c synopsis field.
215*/
216
217/*!
218 \variable IR::MemberIR::isStatic
219 Whether the member is declared static.
220*/
221
222/*!
223 \variable IR::MemberIR::isConst
224 Whether the member is declared const.
225*/
226
227/*!
228 \variable IR::MemberIR::isVirtual
229 Whether the member is virtual (including pure virtual and
230 override).
231*/
232
233/*!
234 \variable IR::MemberIR::isSignal
235 Whether the member is a Qt signal.
236*/
237
238/*!
239 \variable IR::MemberIR::isSlot
240 Whether the member is a Qt slot.
241*/
242
243/*!
244 Converts the member to a QJsonObject for template rendering.
245
246 Emits identity fields (name, fullName, signature, href),
247 classification as \c {id, label} objects, overload metadata, and
248 qualifier flags. The \c brief, \c parameters, and \c enumValues
249 fields are omitted when empty. The \c nodeType field is omitted
250 when NoType.
251*/
253{
254 QJsonObject json;
255
256 json["name"_L1] = name;
257 json["fullName"_L1] = fullName;
258 json["signature"_L1] = signature;
259 json["href"_L1] = href;
260 if (!brief.isEmpty())
261 json["brief"_L1] = brief;
262
263 if (const auto t = nodeTypeToJson(nodeType))
264 json["nodeType"_L1] = *t;
265 json["status"_L1] = statusToJson(status);
266 json["access"_L1] = accessToJson(access);
267 if (!deprecatedSince.isEmpty())
268 json["deprecatedSince"_L1] = deprecatedSince;
269 if (!typeNoun.isEmpty())
270 json["typeNoun"_L1] = typeNoun;
271 if (!deprecatedSinceQualified.isEmpty())
272 json["deprecatedSinceQualified"_L1] = deprecatedSinceQualified;
273
274 json["overloadNumber"_L1] = overloadNumber;
275 json["isPrimaryOverload"_L1] = isPrimaryOverload;
276
277 if (!parameters.isEmpty()) {
278 QJsonArray arr;
279 for (const auto &p : parameters)
280 arr.append(p.toJson());
281 json["parameters"_L1] = arr;
282 }
283
284 if (!enumValues.isEmpty()) {
285 QJsonArray arr;
286 for (const auto &ev : enumValues)
287 arr.append(ev.toJson());
288 json["enumValues"_L1] = arr;
289 }
290
291 json["isStatic"_L1] = isStatic;
292 json["isConst"_L1] = isConst;
293 json["isVirtual"_L1] = isVirtual;
294 json["isSignal"_L1] = isSignal;
295 json["isSlot"_L1] = isSlot;
296
297 if (isAttached)
298 json["isAttached"_L1] = true;
299 if (isDefault)
300 json["isDefault"_L1] = true;
301 if (isReadOnly)
302 json["isReadOnly"_L1] = true;
303 if (isRequired)
304 json["isRequired"_L1] = true;
305 if (!dataType.isEmpty())
306 json["dataType"_L1] = dataType;
307
308 json["anchorId"_L1] = anchorId;
309 json["synopsis"_L1] = synopsis;
310 if (!signatureSpans.isEmpty()) {
311 QJsonArray arr;
312 for (const auto &span : signatureSpans)
313 arr.append(span.toJson());
314 json["signatureSpans"_L1] = arr;
315 }
316 if (!since.isEmpty())
317 json["since"_L1] = since;
318 if (!threadSafety.isEmpty())
319 json["threadSafety"_L1] = threadSafety;
320 if (!comparisonCategory.isEmpty())
321 json["comparisonCategory"_L1] = comparisonCategory;
322 if (isNoexcept)
323 json["isNoexcept"_L1] = true;
324 if (!noexceptNote.isEmpty())
325 json["noexceptNote"_L1] = noexceptNote;
326
327 if (!body.isEmpty()) {
328 QJsonArray arr;
329 for (const auto &block : body)
330 arr.append(block.toJson());
331 json["body"_L1] = arr;
332 }
333
334 if (!alsoList.isEmpty()) {
335 QJsonArray arr;
336 for (const auto &block : alsoList)
337 arr.append(block.toJson());
338 json["alsoList"_L1] = arr;
339 }
340
341 return json;
342}
343
344/*!
345 \struct IR::InheritedMembersIR
346 \brief Summary of members inherited from a single base class.
347
348 InheritedMembersIR stores a count and link target for one base
349 class's contributed members. Templates use this to render lines
350 such as "5 public functions inherited from QObject" at the end
351 of a section.
352*/
353
354/*!
355 \variable IR::InheritedMembersIR::className
356 Fully qualified name of the base class.
357*/
358
359/*!
360 \variable IR::InheritedMembersIR::count
361 Number of members inherited from this base class.
362*/
363
364/*!
365 \variable IR::InheritedMembersIR::href
366 URL of the base class's documentation page.
367*/
368
369/*!
370 Converts the inherited members summary to a QJsonObject.
371
372 Emits \c className, \c count, and \c href. Templates combine
373 this with the enclosing section's \c plural field to render
374 links such as "5 public functions inherited from QObject".
375*/
377{
378 QJsonObject json;
379 json["className"_L1] = className;
380 json["count"_L1] = count;
381 json["href"_L1] = href;
382 return json;
383}
384
385/*!
386 \struct IR::SectionIR
387 \brief Intermediate representation of a member summary section.
388
389 SectionIR groups members by category (such as "Public Functions"
390 or "Properties") for summary table rendering. Each section carries
391 a title, singular and plural forms for inherited-member links, and
392 three member lists: primary members, reimplemented members, and
393 inherited member summaries.
394
395 The \c reimplementedMembers and \c inheritedMembers arrays are
396 omitted from JSON when empty.
397*/
398
399/*!
400 \variable IR::SectionIR::id
401 Stable ASCII identifier for anchor links, generated from the
402 title via TextUtils::asAsciiPrintable().
403*/
404
405/*!
406 \variable IR::SectionIR::title
407 Display title (such as "Public Functions" or "Properties").
408*/
409
410/*!
411 \variable IR::SectionIR::singular
412 Singular form of the member type (such as "function").
413*/
414
415/*!
416 \variable IR::SectionIR::plural
417 Plural form of the member type (such as "functions").
418*/
419
420/*!
421 \variable IR::SectionIR::members
422 Primary members in this section.
423*/
424
425/*!
426 \variable IR::SectionIR::reimplementedMembers
427 Members that reimplement a virtual function from a base class.
428*/
429
430/*!
431 \variable IR::SectionIR::inheritedMembers
432 Summaries of members inherited from base classes.
433*/
434
435/*!
436 Converts the section to a QJsonObject for template rendering.
437
438 Emits \c id, \c title, \c singular, \c plural, and the \c members
439 array. The \c reimplementedMembers and \c inheritedMembers arrays
440 are omitted when empty.
441*/
443{
444 QJsonObject json;
445
446 json["id"_L1] = id;
447 json["title"_L1] = title;
448 json["singular"_L1] = singular;
449 json["plural"_L1] = plural;
450
451 QJsonArray membersArray;
452 for (const auto &m : members)
453 membersArray.append(m.toJson());
454 json["members"_L1] = membersArray;
455
456 if (!reimplementedMembers.isEmpty()) {
457 QJsonArray arr;
458 for (const auto &m : reimplementedMembers)
459 arr.append(m.toJson());
460 json["reimplementedMembers"_L1] = arr;
461 }
462
463 if (!inheritedMembers.isEmpty()) {
464 QJsonArray arr;
465 for (const auto &im : inheritedMembers)
466 arr.append(im.toJson());
467 json["inheritedMembers"_L1] = arr;
468 }
469
470 return json;
471}
472
473/*!
474 \struct IR::AllMemberEntry
475 \brief A single entry in an all-members listing page.
476
477 AllMemberEntry captures the display signature and link target for
478 one member on an all-members sub-page. QML properties carry display
479 hints (such as "read-only" or "default") and property groups nest
480 child entries under a parent.
481*/
482
483/*!
484 Converts the entry to a QJsonObject for template rendering.
485
486 Always emits \c signature and \c href. The \c hints array, \c
487 isPropertyGroup flag, and \c children array are omitted when
488 empty or false.
489*/
491{
492 QJsonObject json;
493 json["signature"_L1] = signature;
494 if (!signatureSpans.isEmpty()) {
495 QJsonArray arr;
496 for (const auto &span : signatureSpans)
497 arr.append(span.toJson());
498 json["signatureSpans"_L1] = arr;
499 }
500 json["href"_L1] = href;
501
502 if (!hints.isEmpty()) {
503 QJsonArray arr;
504 for (const auto &hint : hints)
505 arr.append(hint);
506 json["hints"_L1] = arr;
507 }
508
509 if (isPropertyGroup)
510 json["isPropertyGroup"_L1] = true;
511
512 if (!children.isEmpty()) {
513 QJsonArray arr;
514 for (const auto &child : children)
515 arr.append(child.toJson());
516 json["children"_L1] = arr;
517 }
518
519 return json;
520}
521
522/*!
523 \struct IR::MemberGroup
524 \brief Members grouped by originating QML type in an all-members listing.
525
526 MemberGroup groups AllMemberEntry items by the QML type they originate
527 from, enabling templates to render "inherited from ..." headings. An
528 empty \c typeName indicates the type's own members.
529*/
530
531/*!
532 Converts the member group to a QJsonObject for template rendering.
533
534 Always emits \c typeName (even when empty, since empty means own
535 members), \c typeHref, and \c members array.
536*/
538{
539 QJsonObject json;
540 json["typeName"_L1] = typeName;
541 json["typeHref"_L1] = typeHref;
542
543 QJsonArray arr;
544 for (const auto &entry : members)
545 arr.append(entry.toJson());
546 json["members"_L1] = arr;
547
548 return json;
549}
550
551/*!
552 \struct IR::AllMembersIR
553 \brief Intermediate representation of the all-members listing page.
554
555 AllMembersIR captures all data needed to render a member listing
556 sub-page. It supports two rendering paths: a flat alphabetical list
557 for C++ classes and a grouped-by-origin-type list for QML types.
558 The \c isQmlType flag determines which path the template uses.
559*/
560
561/*!
562 Converts the all-members IR to a QJsonObject for template rendering.
563
564 Always emits \c typeName, \c typeHref, and \c isQmlType. The
565 \c members and \c memberGroups arrays are emitted only when
566 non-empty, letting templates distinguish C++ from QML by checking
567 which key exists.
568*/
570{
571 QJsonObject json;
572 json["typeName"_L1] = typeName;
573 json["typeHref"_L1] = typeHref;
574 json["isQmlType"_L1] = isQmlType;
575
576 if (!members.isEmpty()) {
577 QJsonArray arr;
578 for (const auto &entry : members)
579 arr.append(entry.toJson());
580 json["members"_L1] = arr;
581 }
582
583 if (!memberGroups.isEmpty()) {
584 QJsonArray arr;
585 for (const auto &group : memberGroups)
586 arr.append(group.toJson());
587 json["memberGroups"_L1] = arr;
588 }
589
590 return json;
591}
592
593} // namespace IR
594
595QT_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:102
QJsonObject toJson() const
Converts the entry to a QJsonObject for template rendering.
Definition member.cpp:490
Intermediate representation of the all-members listing page.
Definition member.h:119
QJsonObject toJson() const
Converts the all-members IR to a QJsonObject for template rendering.
Definition member.cpp:569
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:84
QJsonObject toJson() const
\variable IR::InheritedMembersIR::className Fully qualified name of the base class.
Definition member.cpp:376
Members grouped by originating QML type in an all-members listing.
Definition member.h:112
QJsonObject toJson() const
Converts the member group to a QJsonObject for template rendering.
Definition member.cpp:537
Intermediate representation of a single documentable member.
Definition member.h:35
QJsonObject toJson() const
\variable IR::MemberIR::name Unqualified member name.
Definition member.cpp:252
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:91
QJsonObject toJson() const
\variable IR::SectionIR::id Stable ASCII identifier for anchor links, generated from the title via Te...
Definition member.cpp:442