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