| 1 | // Copyright (C) 2024 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 "qhelpengineplugin.h" |
| 5 | |
| 6 | #include <algorithm> |
| 7 | #include <iterator> |
| 8 | #include <memory> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | static std::vector<QQmlLSHelpProvider::DocumentLink> |
| 13 | transformQHelpLink(QList<QHelpLink> &&qhelplinklist) |
| 14 | { |
| 15 | std::vector<QQmlLSHelpProvider::DocumentLink> result(qhelplinklist.size()); |
| 16 | std::transform(first: qhelplinklist.begin(), last: qhelplinklist.end(), result: result.begin(), |
| 17 | unary_op: [&](const auto &item) { |
| 18 | QQmlLSHelpProvider::DocumentLink element; |
| 19 | element.title = item.title; |
| 20 | element.url = item.url; |
| 21 | return element; |
| 22 | }); |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | QQmlLSHelpProvider::QQmlLSHelpProvider(const QString &qhcFilePath, QObject *parent) |
| 27 | { |
| 28 | m_helpEngine.emplace(args: qhcFilePath, args&: parent); |
| 29 | m_helpEngine->setReadOnly(false); |
| 30 | m_helpEngine->setupData(); |
| 31 | } |
| 32 | |
| 33 | bool QQmlLSHelpProvider::registerDocumentation(const QString &documentationFileName) |
| 34 | { |
| 35 | Q_ASSERT(m_helpEngine.has_value()); |
| 36 | return m_helpEngine->registerDocumentation(documentationFileName); |
| 37 | } |
| 38 | |
| 39 | QByteArray QQmlLSHelpProvider::fileData(const QUrl &url) const |
| 40 | { |
| 41 | Q_ASSERT(m_helpEngine.has_value()); |
| 42 | return m_helpEngine->fileData(url); |
| 43 | } |
| 44 | |
| 45 | std::vector<QQmlLSHelpProvider::DocumentLink> |
| 46 | QQmlLSHelpProvider::documentsForIdentifier(const QString &id) const |
| 47 | { |
| 48 | Q_ASSERT(m_helpEngine.has_value()); |
| 49 | return transformQHelpLink(qhelplinklist: m_helpEngine->documentsForIdentifier(id)); |
| 50 | } |
| 51 | |
| 52 | std::vector<QQmlLSHelpProvider::DocumentLink> |
| 53 | QQmlLSHelpProvider::documentsForIdentifier(const QString &id, const QString &filterName) const |
| 54 | { |
| 55 | Q_ASSERT(m_helpEngine.has_value()); |
| 56 | return transformQHelpLink(qhelplinklist: m_helpEngine->documentsForIdentifier(id, filterName)); |
| 57 | } |
| 58 | |
| 59 | std::vector<QQmlLSHelpProvider::DocumentLink> |
| 60 | QQmlLSHelpProvider::documentsForKeyword(const QString &keyword) const |
| 61 | { |
| 62 | Q_ASSERT(m_helpEngine.has_value()); |
| 63 | return transformQHelpLink(qhelplinklist: m_helpEngine->documentsForKeyword(keyword)); |
| 64 | } |
| 65 | |
| 66 | std::vector<QQmlLSHelpProvider::DocumentLink> |
| 67 | QQmlLSHelpProvider::documentsForKeyword(const QString &keyword, const QString &filter) const |
| 68 | { |
| 69 | Q_ASSERT(m_helpEngine.has_value()); |
| 70 | return transformQHelpLink(qhelplinklist: m_helpEngine->documentsForKeyword(keyword, filterName: filter)); |
| 71 | } |
| 72 | |
| 73 | QStringList QQmlLSHelpProvider::registeredNamespaces() const |
| 74 | { |
| 75 | Q_ASSERT(m_helpEngine.has_value()); |
| 76 | return m_helpEngine->registeredDocumentations(); |
| 77 | } |
| 78 | |
| 79 | QString QQmlLSHelpProvider::error() const |
| 80 | { |
| 81 | Q_ASSERT(m_helpEngine.has_value()); |
| 82 | return m_helpEngine->error(); |
| 83 | } |
| 84 | |
| 85 | QHelpEnginePlugin::QHelpEnginePlugin(QObject *parent) : QObject(parent) { } |
| 86 | |
| 87 | std::unique_ptr<QQmlLSHelpProviderBase> QHelpEnginePlugin::initialize(const QString &collectionFile, |
| 88 | QObject *parent) |
| 89 | { |
| 90 | return std::make_unique<QQmlLSHelpProvider>(args: collectionFile, args&: parent); |
| 91 | } |
| 92 | |
| 93 | QT_END_NAMESPACE |
| 94 | |
| 95 | #include "moc_qhelpengineplugin.cpp" |
| 96 | |