Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
outputcontext.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
"outputcontext.h"
5
6
#
include
"config.h"
7
#
include
"location.h"
8
9
#
include
<
QtCore
/
qregularexpression
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
using
namespace
Qt::StringLiterals;
14
15
/*!
16
\class OutputContext
17
\internal
18
\brief Bundles output configuration without static variables.
19
20
OutputContext captures all the configuration state that generators
21
need for output, replacing Generator's 19 static variables with
22
explicit, injectable state.
23
24
This enables:
25
\list
26
\li Testability - configurations can be created for tests.
27
\li Reusability - HrefResolver, IndexWriter can use the same context.
28
\li Statelessness - no global mutable state between runs.
29
\endlist
30
31
\section1 Relationship to Generator Statics
32
33
| OutputContext field | Generator static |
34
|---------------------|------------------|
35
| outputDir | s_outDir |
36
| project | s_project |
37
| subdir | s_outSubdir |
38
| outputPrefixes | s_outputPrefixes |
39
| outputSuffixes | s_outputSuffixes |
40
| useSubdirs | s_useOutputSubdirs |
41
42
\sa DocumentWriter, FileDocumentWriter
43
*/
44
45
/*!
46
Creates an OutputContext from the given \a config for the specified output
47
\a format.
48
49
This method extracts all relevant configuration values that generators need,
50
centralizing the logic that was previously scattered across Generator's
51
static initialization.
52
*/
53
OutputContext
OutputContext
::fromConfig(
const
Config
&config,
const
QString &format)
54
{
55
QString project = config.get(
CONFIG_PROJECT
).asString();
56
57
// Determine output directory
58
QString outDir = config.getOutputDir(format);
59
if
(outDir.isEmpty())
60
outDir = config.getOutputDir();
// Fallback to default
61
62
QString subdir;
63
OutputDirectory
outputDir{outDir};
64
if
(!outDir.isEmpty()) {
65
outputDir = OutputDirectory::ensure(outDir,
Location
{
}
);
66
subdir = outDir.mid(outDir.lastIndexOf(
'/'_L1
) + 1);
67
}
68
69
// Extract output prefixes
70
QHash<QString, QString> prefixes;
71
QStringList prefixItems = config.get(
CONFIG_OUTPUTPREFIXES
).asStringList();
72
for
(
const
auto
&prefix : prefixItems) {
73
prefixes[prefix] =
74
config.get(
CONFIG_OUTPUTPREFIXES
+ Config::dot + prefix).asString();
75
}
76
// Default QML prefix if not specified
77
if
(!prefixItems.contains(u"QML"_s))
78
prefixes[u"QML"_s] = u"qml-"_s;
79
80
// Extract output suffixes
81
QHash<QString, QString> suffixes;
82
for
(
const
auto
&suffix : config.get(
CONFIG_OUTPUTSUFFIXES
).asStringList()) {
83
suffixes[suffix] =
84
config.get(
CONFIG_OUTPUTSUFFIXES
+ Config::dot + suffix).asString();
85
}
86
87
bool
useSubdirs = !config.get(format + Config::dot +
"nosubdirs"
).asBool();
88
bool
noLinkErrors = config.get(
CONFIG_NOLINKERRORS
).asBool();
89
bool
autolinkErrors = config.get(
CONFIG_AUTOLINKERRORS
).asBool();
90
91
return
OutputContext{
92
std::move(outputDir),
93
std::move(project),
94
std::move(subdir),
95
QString{},
// Is set by caller based on generator
96
std::move(prefixes),
97
std::move(suffixes),
98
useSubdirs,
99
noLinkErrors,
100
autolinkErrors
101
};
102
}
103
104
namespace
{
105
106
QString genusKey(Genus genus)
107
{
108
switch
(genus) {
109
case
Genus::QML:
110
return
u"QML"_s;
111
case
Genus::CPP:
112
return
u"CPP"_s;
113
default
:
114
return
{};
115
}
116
}
117
118
}
// namespace
119
120
/*!
121
Returns the output prefix for the given \a genus. The configured
122
prefixes are stored against the QDoc-internal \c "QML" and \c "CPP"
123
keys; the Genus-typed interface lets callers avoid handling those
124
string keys (or having to reach for Node) just to answer
125
"what prefix belongs to this page?".
126
*/
127
QString
OutputContext
::
outputPrefix
(Genus genus)
const
128
{
129
return
outputPrefixes.value(genusKey(genus));
130
}
131
132
/*!
133
Returns the output suffix for the given \a genus. See outputPrefix()
134
for why the interface is Genus-typed.
135
*/
136
QString
OutputContext
::
outputSuffix
(Genus genus)
const
137
{
138
return
outputSuffixes.value(genusKey(genus));
139
}
140
141
QT_END_NAMESPACE
Config
The Config class contains the configuration variables for controlling how qdoc produces documentation...
Definition
config.h:95
Location
The Location class provides a way to mark a location in a file.
Definition
location.h:20
Location::Location
Location()
Constructs an empty location.
Definition
location.cpp:50
OutputDirectory
Represents an output directory that has been verified to exist.
Definition
outputdirectory.h:16
CONFIG_AUTOLINKERRORS
#define CONFIG_AUTOLINKERRORS
Definition
config.h:384
CONFIG_OUTPUTSUFFIXES
#define CONFIG_OUTPUTSUFFIXES
Definition
config.h:439
CONFIG_OUTPUTPREFIXES
#define CONFIG_OUTPUTPREFIXES
Definition
config.h:438
CONFIG_NOLINKERRORS
#define CONFIG_NOLINKERRORS
Definition
config.h:435
CONFIG_PROJECT
#define CONFIG_PROJECT
Definition
config.h:444
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
OutputContext
Bundles output configuration without static variables.
Definition
outputcontext.h:18
OutputContext::outputPrefix
QString outputPrefix(Genus genus) const
Returns the output prefix for the given genus.
Definition
outputcontext.cpp:127
OutputContext::outputSuffix
QString outputSuffix(Genus genus) const
Returns the output suffix for the given genus.
Definition
outputcontext.cpp:136
qttools
src
qdoc
qdoc
src
qdoc
outputcontext.cpp
Generated on
for Qt by
1.18.0