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
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
16
QT_BEGIN_NAMESPACE
17
18
using
namespace
Qt::StringLiterals;
19
20
QString
HelpClient
::
designerManualUrl
()
const
21
{
22
return
documentUrl
(u"qtdesigner"_s);
23
}
24
25
std::unique_ptr<HelpClient>
HelpClient
::create(
HelpClientType
type)
26
{
27
std::unique_ptr<HelpClient> result;
28
switch
(type) {
29
case
HelpClientType
::
Assistant
:
30
#
if
QT_CONFIG
(
process
)
31
result = std::make_unique<AssistantClient>();
32
break
;
33
#
endif
34
case
HelpClientType
::
Web
:
35
result =
std
::make_unique<
WebHelpClient
>();
36
break
;
37
case
HelpClientType
::
Python
:
38
result =
std
::make_unique<
PythonWebHelpClient
>();
39
break
;
40
}
41
return
result;
42
}
43
44
static
constexpr
auto
webPrefix
=
"https://doc.qt.io/qt-6/"_L1
;
45
static
constexpr
auto
pythonWebPrefix
=
"https://doc.qt.io/qtforpython-6/PySide6/"_L1
;
46
static
constexpr
auto
htmlSuffix
=
".html"_L1
;
47
static
constexpr
auto
propertySeparator
=
"::"_L1
;
48
49
bool
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
60
QString
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
71
bool
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
78
QString
WebHelpClient
::
documentUrl
(
const
QString &)
const
79
{
80
return
webPrefix;
81
}
82
83
// Python: "QWidget::geometry" -> "QWidget.html" (no property anchors)
84
QString
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"
93
bool
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
103
QT_END_NAMESPACE
HelpClient
Definition
helpclient.h:20
HelpClient::documentUrl
virtual QString documentUrl(const QString &module) const =0
HelpClient::designerManualUrl
QString designerManualUrl() const
Definition
helpclient.cpp:20
PythonWebHelpClient
Definition
helpclient.h:53
PythonWebHelpClient::activateIdentifier
bool activateIdentifier(const QString &identifier, QString *errorMessage) override
Definition
helpclient.cpp:93
WebHelpClient
Definition
helpclient.h:38
WebHelpClient::documentUrl
QString documentUrl(const QString &module) const override
Definition
helpclient.cpp:78
WebHelpClient::activateIdentifier
bool activateIdentifier(const QString &identifier, QString *errorMessage) override
Definition
helpclient.cpp:71
WebHelpClient::showPage
bool showPage(const QString &path, QString *errorMessage) override
Definition
helpclient.cpp:49
webPrefix
static constexpr auto webPrefix
Definition
helpclient.cpp:44
pythonWebPrefix
static constexpr auto pythonWebPrefix
Definition
helpclient.cpp:45
propertySeparator
static constexpr auto propertySeparator
Definition
helpclient.cpp:47
htmlSuffix
static constexpr auto htmlSuffix
Definition
helpclient.cpp:46
HelpClientType
HelpClientType
Definition
helpclient.h:17
HelpClientType::Assistant
@ Assistant
Definition
helpclient.h:17
HelpClientType::Python
@ Python
Definition
helpclient.h:17
HelpClientType::Web
@ Web
Definition
helpclient.h:17
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qttools
src
shared
helpclient
helpclient.cpp
Generated on
for Qt by
1.18.0