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
anchorid.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 "anchorid.h"
5
6#include "functionnode.h"
7#include "node.h"
8#include "propertynode.h"
9#include "typedefnode.h"
10
11using namespace Qt::Literals::StringLiterals;
12
14
15/*!
16 \internal
17 Computes the raw anchor base for \a node based on its type.
18
19 QML properties receive a \c{-prop} or \c{-attached-prop} suffix,
20 signals receive \c{-signal}, methods receive \c{-method} with an
21 optional overload number, and so on. The returned string isn't
22 sanitized — each caller applies its own cleanup or finalization
23 (such as Generator::cleanRef() or HrefResolverConfig::cleanRefFn).
24
25 Both HrefResolver::anchorForNode() and XmlGenerator::refForNode()
26 delegate to this function for the shared node-type dispatch,
27 ensuring consistent anchor naming across the IR extraction and
28 legacy generation paths.
29*/
30QString computeAnchorId(const Node *node)
31{
32 QString ref;
33
34 switch (node->nodeType()) {
35 case NodeType::Enum:
36 case NodeType::QmlEnum:
37 ref = node->name() + "-enum"_L1;
38 break;
39 case NodeType::Typedef: {
40 const auto *tdf = static_cast<const TypedefNode *>(node);
41 if (tdf->associatedEnum())
42 return computeAnchorId(tdf->associatedEnum());
43 } Q_FALLTHROUGH();
44 case NodeType::TypeAlias:
45 ref = node->name() + "-typedef"_L1;
46 break;
47 case NodeType::Function: {
48 const auto *fn = static_cast<const FunctionNode *>(node);
49 switch (fn->metaness()) {
50 case FunctionNode::QmlSignal:
51 ref = fn->name() + "-signal"_L1;
52 break;
53 case FunctionNode::QmlSignalHandler:
54 ref = fn->name() + "-signal-handler"_L1;
55 break;
56 case FunctionNode::QmlMethod:
57 ref = fn->name() + "-method"_L1;
58 if (fn->overloadNumber() != 0)
59 ref += '-'_L1 + QString::number(fn->overloadNumber());
60 break;
61 default:
62 if (const auto *p = fn->primaryAssociatedProperty(); p && fn->doc().isEmpty()) {
63 return computeAnchorId(p);
64 } else {
65 ref = fn->name();
66 if (fn->overloadNumber() != 0)
67 ref += '-'_L1 + QString::number(fn->overloadNumber());
68 }
69 break;
70 }
71 } break;
72 case NodeType::SharedComment: {
73 if (!node->isPropertyGroup())
74 break;
75 } Q_FALLTHROUGH();
76 case NodeType::QmlProperty:
77 if (node->isAttached())
78 ref = node->name() + "-attached-prop"_L1;
79 else
80 ref = node->name() + "-prop"_L1;
81 break;
82 case NodeType::Property:
83 ref = node->name() + "-prop"_L1;
84 break;
85 case NodeType::Variable:
86 ref = node->name() + "-var"_L1;
87 break;
88 default:
89 break;
90 }
91
92 return ref;
93}
94
95QT_END_NAMESPACE
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:177