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
link.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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 "link.h"
5
7
8using namespace Qt::Literals::StringLiterals;
9
10namespace IR {
11
12/*!
13 \struct IR::Link
14 \brief Intermediate representation for a resolved hyperlink.
15
16 Link represents a fully-resolved link in QDoc's intermediate representation
17 layer. All target resolution happens during the IR building phase, so templates
18 receive only pre-computed URLs and display text. This eliminates the need for
19 generators to perform database lookups during output generation.
20
21 \sa IR::Document
22*/
23
24/*!
25 \enum IR::Link::State
26 Indicates the resolution state of the link target.
27
28 \value Resolved Link target was found and resolved.
29 \value External Link points to an external resource.
30 \value Unresolved Target not found (will produce warning).
31 \value Broken Target explicitly marked as broken.
32*/
33
34
35/*!
36 Converts the Link to a QJsonObject for template rendering.
37
38 The JSON structure uses camelCase field names following the established
39 IR-to-JSON convention. The state is represented as a string for readability
40 in templates: "resolved", "external", "unresolved", or "broken".
41
42 Returns a QJsonObject containing all link data suitable for template
43 rendering via InjaBridge.
44*/
46{
47 QJsonObject json;
48 json["target"_L1] = target;
49 json["text"_L1] = text;
50
51 if (!title.isEmpty())
52 json["title"_L1] = title;
53
54 QString stateStr;
55 switch (state) {
56 case State::Resolved:
57 stateStr = "resolved"_L1;
58 break;
59 case State::External:
60 stateStr = "external"_L1;
61 break;
62 case State::Unresolved:
63 stateStr = "unresolved"_L1;
64 break;
65 case State::Broken:
66 stateStr = "broken"_L1;
67 break;
68 }
69 json["state"_L1] = stateStr;
70
71 json["isResolved"_L1] = (state == State::Resolved);
72 json["isExternal"_L1] = (state == State::External);
73
74 if (!originalTarget.isEmpty() && originalTarget != target)
75 json["originalTarget"_L1] = originalTarget;
76
77 return json;
78}
79
80} // namespace IR
81
82QT_END_NAMESPACE
Definition builder.cpp:14
Combined button and popup list for selecting options.