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 "qhelpengine.h"
5#include "qhelpengine_p.h"
6#include "qhelpdbreader_p.h"
7#include "qhelpcontentwidget.h"
8#include "qhelpindexwidget.h"
9#include "qhelpsearchengine.h"
10#include "qhelpcollectionhandler_p.h"
11#include "qhelpfilterengine.h"
12
13#include <QtCore/QDir>
14#include <QtCore/QFile>
15#include <QtCore/QPluginLoader>
16#include <QtCore/QTimer>
17#include <QtWidgets/QApplication>
18#include <QtSql/QSqlQuery>
19
20QT_BEGIN_NAMESPACE
21
22void QHelpEnginePrivate::init(const QString &collectionFile,
23 QHelpEngineCore *helpEngineCore)
24{
25 QHelpEngineCorePrivate::init(collectionFile, helpEngineCore);
26
27 if (!contentModel)
28 contentModel = new QHelpContentModel(this);
29 if (!indexModel)
30 indexModel = new QHelpIndexModel(this);
31
32 connect(sender: helpEngineCore, signal: &QHelpEngineCore::setupFinished,
33 context: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
34 connect(sender: helpEngineCore, signal: &QHelpEngineCore::currentFilterChanged,
35 context: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
36 connect(sender: helpEngineCore->filterEngine(), signal: &QHelpFilterEngine::filterActivated,
37 context: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
38}
39
40void QHelpEnginePrivate::scheduleApplyCurrentFilter()
41{
42 if (!error.isEmpty())
43 return;
44
45 if (m_isApplyCurrentFilterScheduled)
46 return;
47
48 m_isApplyCurrentFilterScheduled = true;
49 QTimer::singleShot(interval: 0, receiver: this, slot: &QHelpEnginePrivate::applyCurrentFilter);
50}
51
52void QHelpEnginePrivate::applyCurrentFilter()
53{
54 m_isApplyCurrentFilterScheduled = false;
55 const QString filter = usesFilterEngine
56 ? q->filterEngine()->activeFilter()
57 : currentFilter;
58 contentModel->createContents(customFilterName: filter);
59 indexModel->createIndex(customFilterName: filter);
60}
61
62void QHelpEnginePrivate::setContentsWidgetBusy()
63{
64#if QT_CONFIG(cursor)
65 contentWidget->setCursor(Qt::WaitCursor);
66#endif
67}
68
69void QHelpEnginePrivate::unsetContentsWidgetBusy()
70{
71#if QT_CONFIG(cursor)
72 contentWidget->unsetCursor();
73#endif
74}
75
76void QHelpEnginePrivate::setIndexWidgetBusy()
77{
78#if QT_CONFIG(cursor)
79 indexWidget->setCursor(Qt::WaitCursor);
80#endif
81}
82
83void QHelpEnginePrivate::unsetIndexWidgetBusy()
84{
85#if QT_CONFIG(cursor)
86 indexWidget->unsetCursor();
87#endif
88}
89
90/*!
91 \class QHelpEngine
92 \since 4.4
93 \inmodule QtHelp
94 \brief The QHelpEngine class provides access to contents and
95 indices of the help engine.
96*/
97
98/*!
99 Constructs a new help engine with the given \a parent. The help
100 engine uses the information stored in the \a collectionFile for
101 providing help. If the collection file does not already exist,
102 it will be created.
103*/
104QHelpEngine::QHelpEngine(const QString &collectionFile, QObject *parent)
105 : QHelpEngineCore(d = new QHelpEnginePrivate(), parent)
106{
107 d->init(collectionFile, helpEngineCore: this);
108}
109
110/*!
111 Destroys the help engine object.
112*/
113QHelpEngine::~QHelpEngine()
114{
115}
116
117/*!
118 Returns the content model.
119*/
120QHelpContentModel *QHelpEngine::contentModel() const
121{
122 return d->contentModel;
123}
124
125/*!
126 Returns the index model.
127*/
128QHelpIndexModel *QHelpEngine::indexModel() const
129{
130 return d->indexModel;
131}
132
133/*!
134 Returns the content widget.
135*/
136QHelpContentWidget *QHelpEngine::contentWidget()
137{
138 if (!d->contentWidget) {
139 d->contentWidget = new QHelpContentWidget();
140 d->contentWidget->setModel(d->contentModel);
141 connect(sender: d->contentModel, signal: &QHelpContentModel::contentsCreationStarted,
142 context: d, slot: &QHelpEnginePrivate::setContentsWidgetBusy);
143 connect(sender: d->contentModel, signal: &QHelpContentModel::contentsCreated,
144 context: d, slot: &QHelpEnginePrivate::unsetContentsWidgetBusy);
145 }
146 return d->contentWidget;
147}
148
149/*!
150 Returns the index widget.
151*/
152QHelpIndexWidget *QHelpEngine::indexWidget()
153{
154 if (!d->indexWidget) {
155 d->indexWidget = new QHelpIndexWidget();
156 d->indexWidget->setModel(d->indexModel);
157 connect(sender: d->indexModel, signal: &QHelpIndexModel::indexCreationStarted,
158 context: d, slot: &QHelpEnginePrivate::setIndexWidgetBusy);
159 connect(sender: d->indexModel, signal: &QHelpIndexModel::indexCreated,
160 context: d, slot: &QHelpEnginePrivate::unsetIndexWidgetBusy);
161 }
162 return d->indexWidget;
163}
164
165/*!
166 Returns the default search engine.
167*/
168QHelpSearchEngine* QHelpEngine::searchEngine()
169{
170 if (!d->searchEngine)
171 d->searchEngine = new QHelpSearchEngine(this, this);
172 return d->searchEngine;
173}
174
175QT_END_NAMESPACE
176

source code of qttools/src/assistant/help/qhelpengine.cpp