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