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
helpclient.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "helpclient.h"
6#if QT_CONFIG(process)
7# include "assistantclient.h"
8#endif
9#include <QtGui/qdesktopservices.h>
10
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qstring.h>
13#include <QtCore/qtextstream.h>
14#include <QtCore/qurl.h>
15
17
18using namespace Qt::StringLiterals;
19
21{
22 return documentUrl(u"qtdesigner"_s);
23}
24
25std::unique_ptr<HelpClient> HelpClient::create(HelpClientType type)
26{
27 std::unique_ptr<HelpClient> result;
28 switch (type) {
30#if QT_CONFIG(process)
31 result = std::make_unique<AssistantClient>();
32 break;
33#endif
35 result = std::make_unique<WebHelpClient>();
36 break;
38 result = std::make_unique<PythonWebHelpClient>();
39 break;
40 }
41 return result;
42}
43
44static constexpr auto webPrefix = "https://doc.qt.io/qt-6/"_L1;
45static constexpr auto pythonWebPrefix = "https://doc.qt.io/qtforpython-6/PySide6/"_L1;
46static constexpr auto htmlSuffix = ".html"_L1;
47static constexpr auto propertySeparator = "::"_L1;
48
49bool WebHelpClient::showPage(const QString &path, QString *errorMessage)
50{
51 const bool result = QDesktopServices::openUrl(QUrl(path));
52 if (!result) {
53 *errorMessage = QCoreApplication::translate("WebHelpClient",
54 "Unable to open url (%1).").arg(path);
55 }
56 return result;
57}
58
59// C++ "QWidget::geometry" -> "qwidget.html#geometry-prop
60QString WebHelpClient::webPage(const QString &identifier)
61{
62 const auto propPos = identifier.lastIndexOf(propertySeparator);
63 const QString widget = propPos != -1 ? identifier.sliced(0, propPos) : identifier;
64 QString result = widget.toLower() + htmlSuffix;
65 if (propPos != -1)
66 result += u'#' + identifier.sliced(propPos + propertySeparator.size()) + "-prop"_L1;
67 return result;
68}
69
70// C++ "QWidget::geometry" -> // https://doc.qt.io/qt-6/qwidget.html#geometry-prop
71bool WebHelpClient::activateIdentifier(const QString &identifier, QString *errorMessage)
72{
73 const QString url = identifier.startsWith("http"_L1)
74 ? identifier : webPrefix + webPage(identifier);
75 return showPage(url, errorMessage);
76}
77
78QString WebHelpClient::documentUrl(const QString &) const
79{
80 return webPrefix;
81}
82
83// Python: "QWidget::geometry" -> "QWidget.html" (no property anchors)
84QString PythonWebHelpClient::webPage(const QString &identifier)
85{
86 const auto propPos = identifier.lastIndexOf(propertySeparator);
87 const QString widget = propPos != -1 ? identifier.sliced(0, propPos) : identifier;
88 return widget + htmlSuffix;
89}
90
91// Python: "QWidget::geometry" ->
92// "https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QWidget.html"
93bool PythonWebHelpClient::activateIdentifier(const QString &identifier, QString *errorMessage)
94{
95 QString url = identifier;
96 if (!identifier.startsWith("http"_L1)) {
97 const auto module = identifier.startsWith("QAction"_L1) ? "QtGui"_L1 : "QtWidgets"_L1;
98 url = pythonWebPrefix + module + u'/'+ webPage(identifier);
99 }
100 return showPage(url, errorMessage);
101}
102
103QT_END_NAMESPACE
virtual QString documentUrl(const QString &module) const =0
QString designerManualUrl() const
bool activateIdentifier(const QString &identifier, QString *errorMessage) override
QString documentUrl(const QString &module) const override
bool activateIdentifier(const QString &identifier, QString *errorMessage) override
bool showPage(const QString &path, QString *errorMessage) override
static constexpr auto webPrefix
static constexpr auto pythonWebPrefix
static constexpr auto propertySeparator
static constexpr auto htmlSuffix
HelpClientType
Definition helpclient.h:17
Combined button and popup list for selecting options.