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