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