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
qhelpengine.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 "qhelpengine.h"
10
11#include <QtCore/qtimer.h>
12
14
16{
17public:
18 QHelpEnginePrivate(QHelpEngineCore *helpEngineCore);
19
20 QHelpContentModel *contentModel = nullptr;
21 QHelpContentWidget *contentWidget = nullptr;
22
23 QHelpIndexModel *indexModel = nullptr;
24 QHelpIndexWidget *indexWidget = nullptr;
25
26 QHelpSearchEngine *searchEngine = nullptr;
27
29 QHelpEngineCore *m_helpEngineCore = nullptr;
30};
31
32QHelpEnginePrivate::QHelpEnginePrivate(QHelpEngineCore *helpEngineCore)
33 : m_helpEngineCore(helpEngineCore)
34{
35 if (!contentModel)
36 contentModel = new QHelpContentModel(helpEngineCore);
37 if (!indexModel)
38 indexModel = new QHelpIndexModel(m_helpEngineCore);
39
40 const auto applyCurrentFilter = [this] {
42 contentModel->createContentsForCurrentFilter();
43 indexModel->createIndexForCurrentFilter();
44 };
45
46 const auto scheduleApplyCurrentFilter = [this, applyCurrentFilter] {
47 if (!m_helpEngineCore->error().isEmpty())
48 return;
49
51 return;
52
54 QTimer::singleShot(0, m_helpEngineCore, applyCurrentFilter);
55 };
56
57 QObject::connect(m_helpEngineCore, &QHelpEngineCore::setupFinished,
58 m_helpEngineCore, scheduleApplyCurrentFilter);
59 QObject::connect(m_helpEngineCore, &QHelpEngineCore::currentFilterChanged,
60 m_helpEngineCore, scheduleApplyCurrentFilter);
61 QObject::connect(m_helpEngineCore->filterEngine(), &QHelpFilterEngine::filterActivated,
62 m_helpEngineCore, scheduleApplyCurrentFilter);
63}
64
65/*!
66 \class QHelpEngine
67 \since 4.4
68 \inmodule QtHelp
69 \brief The QHelpEngine class provides access to contents and
70 indices of the help engine.
71*/
72
73/*!
74 Constructs a new help engine with the given \a parent. The help
75 engine uses the information stored in the \a collectionFile for
76 providing help. If the collection file does not already exist,
77 it will be created.
78*/
79QHelpEngine::QHelpEngine(const QString &collectionFile, QObject *parent)
80 : QHelpEngineCore(collectionFile, parent)
81 , d(new QHelpEnginePrivate(this))
82{}
83
84/*!
85 Destroys the help engine object.
86*/
87QHelpEngine::~QHelpEngine()
88{
89 delete d;
90}
91
92/*!
93 Returns the content model.
94*/
95QHelpContentModel *QHelpEngine::contentModel() const
96{
97 return d->contentModel;
98}
99
100/*!
101 Returns the index model.
102*/
103QHelpIndexModel *QHelpEngine::indexModel() const
104{
105 return d->indexModel;
106}
107
108/*!
109 Returns the content widget.
110*/
111QHelpContentWidget *QHelpEngine::contentWidget()
112{
113 if (!d->contentWidget) {
114 d->contentWidget = new QHelpContentWidget;
115 d->contentWidget->setModel(d->contentModel);
116#if QT_CONFIG(cursor)
117 connect(d->contentModel, &QHelpContentModel::contentsCreationStarted, this, [this] {
118 d->contentWidget->setCursor(Qt::WaitCursor);
119 });
120 connect(d->contentModel, &QHelpContentModel::contentsCreated, this, [this] {
121 d->contentWidget->unsetCursor();
122 });
123#endif
124 }
125 return d->contentWidget;
126}
127
128/*!
129 Returns the index widget.
130*/
131QHelpIndexWidget *QHelpEngine::indexWidget()
132{
133 if (!d->indexWidget) {
134 d->indexWidget = new QHelpIndexWidget;
135 d->indexWidget->setModel(d->indexModel);
136#if QT_CONFIG(cursor)
137 connect(d->indexModel, &QHelpIndexModel::indexCreationStarted, this, [this] {
138 d->indexWidget->setCursor(Qt::WaitCursor);
139 });
140 connect(d->indexModel, &QHelpIndexModel::indexCreated, this, [this] {
141 d->indexWidget->unsetCursor();
142 });
143#endif
144 }
145 return d->indexWidget;
146}
147
148/*!
149 Returns the default search engine.
150*/
151QHelpSearchEngine* QHelpEngine::searchEngine()
152{
153 if (!d->searchEngine)
154 d->searchEngine = new QHelpSearchEngine(this, this);
155 return d->searchEngine;
156}
157
158QT_END_NAMESPACE
QHelpSearchEngine * searchEngine
QHelpIndexWidget * indexWidget
QHelpContentModel * contentModel
QHelpEnginePrivate(QHelpEngineCore *helpEngineCore)
QHelpEngineCore * m_helpEngineCore
bool m_isApplyCurrentFilterScheduled
QHelpIndexModel * indexModel
QHelpContentWidget * contentWidget
Combined button and popup list for selecting options.