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