summaryrefslogtreecommitdiffstats
path: root/src/assistant/plugins/help/qhelpengineplugin.cpp
blob: 55296c8e8d9bc76db79169390bdeea5d7dce6098 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qhelpengineplugin.h"

#include <algorithm>
#include <iterator>
#include <memory>

QT_BEGIN_NAMESPACE

static std::vector<QQmlLSHelpProvider::DocumentLink>
transformQHelpLink(QList<QHelpLink> &&qhelplinklist)
{
    std::vector<QQmlLSHelpProvider::DocumentLink> result(qhelplinklist.size());
    std::transform(qhelplinklist.begin(), qhelplinklist.end(), result.begin(),
                   [&](const auto &item) {
                       QQmlLSHelpProvider::DocumentLink element;
                       element.title = item.title;
                       element.url = item.url;
                       return element;
                   });
    return result;
}

QQmlLSHelpProvider::QQmlLSHelpProvider(const QString &qhcFilePath, QObject *parent)
{
    m_helpEngine.emplace(qhcFilePath, parent);
    m_helpEngine->setReadOnly(false);
    m_helpEngine->setupData();
}

bool QQmlLSHelpProvider::registerDocumentation(const QString &documentationFileName)
{
    Q_ASSERT(m_helpEngine.has_value());
    return m_helpEngine->registerDocumentation(documentationFileName);
}

QByteArray QQmlLSHelpProvider::fileData(const QUrl &url) const
{
    Q_ASSERT(m_helpEngine.has_value());
    return m_helpEngine->fileData(url);
}

std::vector<QQmlLSHelpProvider::DocumentLink>
QQmlLSHelpProvider::documentsForIdentifier(const QString &id) const
{
    Q_ASSERT(m_helpEngine.has_value());
    return transformQHelpLink(m_helpEngine->documentsForIdentifier(id));
}

std::vector<QQmlLSHelpProvider::DocumentLink>
QQmlLSHelpProvider::documentsForIdentifier(const QString &id, const QString &filterName) const
{
    Q_ASSERT(m_helpEngine.has_value());
    return transformQHelpLink(m_helpEngine->documentsForIdentifier(id, filterName));
}

std::vector<QQmlLSHelpProvider::DocumentLink>
QQmlLSHelpProvider::documentsForKeyword(const QString &keyword) const
{
    Q_ASSERT(m_helpEngine.has_value());
    return transformQHelpLink(m_helpEngine->documentsForKeyword(keyword));
}

std::vector<QQmlLSHelpProvider::DocumentLink>
QQmlLSHelpProvider::documentsForKeyword(const QString &keyword, const QString &filter) const
{
    Q_ASSERT(m_helpEngine.has_value());
    return transformQHelpLink(m_helpEngine->documentsForKeyword(keyword, filter));
}

QStringList QQmlLSHelpProvider::registeredNamespaces() const
{
    Q_ASSERT(m_helpEngine.has_value());
    return m_helpEngine->registeredDocumentations();
}

QString QQmlLSHelpProvider::error() const
{
    Q_ASSERT(m_helpEngine.has_value());
    return m_helpEngine->error();
}

QHelpEnginePlugin::QHelpEnginePlugin(QObject *parent) : QObject(parent) { }

std::unique_ptr<QQmlLSHelpProviderBase> QHelpEnginePlugin::initialize(const QString &collectionFile,
                                                                      QObject *parent)
{
    return std::make_unique<QQmlLSHelpProvider>(collectionFile, parent);
}

QT_END_NAMESPACE

#include "moc_qhelpengineplugin.cpp"