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
qhelp_global.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 "qhelp_global.h"
6#include <QtTools/qttools-config.h>
7
8#include <QtCore/qcoreapplication.h>
9#include <QtCore/qhash.h>
10#include <QtCore/qmutex.h>
11#if QT_CONFIG(fullqthelp)
12# include <QtGui/qtextdocument.h>
13#endif
14
16
17using namespace Qt::StringLiterals;
18
19QString QHelpGlobal::uniquifyConnectionName(const QString &name, void *pointer)
20{
21 static QMutex mutex;
22 QMutexLocker locker(&mutex);
23 static QHash<QString, quint16> idHash;
24 return QString::asprintf("%ls-%p-%d", qUtf16Printable(name), pointer, ++idHash[name]);
25}
26
27QString QHelpGlobal::documentTitle(const QString &content)
28{
29#if QT_CONFIG(fullqthelp)
30 QString title = QCoreApplication::translate("QHelp", "Untitled");
31 if (!content.isEmpty()) {
32 const int start = content.indexOf("<title>"_L1, 0, Qt::CaseInsensitive) + 7;
33 const int end = content.indexOf("</title>"_L1, 0, Qt::CaseInsensitive);
34 if ((end - start) > 0) {
35 title = content.mid(start, end - start);
36 if (Qt::mightBeRichText(title) || title.contains(u'&')) {
37 QTextDocument doc;
38 doc.setHtml(title);
39 title = doc.toPlainText();
40 }
41 }
42 }
43 return title;
44#else
45 Q_UNUSED(content);
46 return {};
47#endif
48}
49
50QT_END_NAMESPACE
Combined button and popup list for selecting options.