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
locationplanlookup.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 "locationplan.h"
5
6#include <QtCore/qdir.h>
7
9
10using namespace Qt::StringLiterals;
11
12LocationPlan::LocationPlan(LocationRules rules, EntityLocations entities)
14{
15}
16
17LocationPlan::LocationPlan(LocationRules rules) : LocationPlan(std::move(rules), {}) { }
18
19/*!
20 Returns the planned location of \a node. Returns no value when the entity
21 is not published; querying the plan never invents a publication location.
22*/
23std::optional<PublicationLocation> LocationPlan::entity(const Node *node) const
24{
25 if (const auto it = m_entities.constFind(node); it != m_entities.constEnd())
26 return it.value();
27 return std::nullopt;
28}
29
31{
32 return explicitUrl || fragment.isEmpty() ? path : path + u'#' + fragment;
33}
34
35/*!
36 Returns the location of \a node as one link target, or an empty string
37 when the entity is not published. This is the form the index export writes.
38*/
40{
41 const auto location = entity(node);
42 return location ? location->href() : QString();
43}
44
45/*!
46 Adds a published \a format at \a outputDir, with its completed \a plan.
47 Finish building the set before handing it to renderers.
48*/
49void LocationPlanSet::add(QString format, QString outputDir, LocationPlan plan)
50{
51 m_publications.insert_or_assign(std::move(format),
52 Publication{ std::move(outputDir), std::move(plan) });
53}
54
55const LocationPlan *LocationPlanSet::plan(const QString &format) const
56{
57 const auto it = m_publications.find(format);
58 return it == m_publications.end() ? nullptr : &it->second.plan;
59}
60
61/*!
62 Resolves \a node in \a format, then in published HTML. The result is relative
63 to \a relativeDir. Explicit URLs retain their original spelling. Neither
64 lookup nor path relativization requires output files to exist.
65*/
66std::optional<PublicationLocation> LocationPlanSet::entity(const Node *node,
67 const QString &format,
68 const QString &relativeDir) const
69{
70 const auto lookup = [&](const QString &candidate) -> std::optional<PublicationLocation> {
71 const auto it = m_publications.find(candidate);
72 if (it == m_publications.end())
73 return std::nullopt;
74 auto location = it->second.plan.entity(node);
75 if (location && !location->explicitUrl) {
76 const QString path = QDir(it->second.outputDir).absoluteFilePath(location->path);
77 location->path = QDir(relativeDir).relativeFilePath(path);
78 }
79 return location;
80 };
81 if (auto location = lookup(format))
82 return location;
83 return format == "HTML"_L1 ? std::nullopt : lookup(u"HTML"_s);
84}
85
86QT_END_NAMESPACE
\variable PublicationLocation::path
LocationPlan(LocationRules rules, EntityLocations entities)
QString documentLocation(const Node *node) const
Returns the location of node as one link target, or an empty string when the entity is not published.
std::optional< PublicationLocation > entity(const Node *node) const
Returns the planned location of node.
Combined button and popup list for selecting options.
Holds the configuration a format needs to name its published files.
The Node class is the base class for all the nodes in QDoc's parse tree.
\variable LocationRules::fileExtension