1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Assistant of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qhelpengine.h"
41#include "qhelpengine_p.h"
42#include "qhelpdbreader_p.h"
43#include "qhelpcontentwidget.h"
44#include "qhelpindexwidget.h"
45#include "qhelpsearchengine.h"
46#include "qhelpcollectionhandler_p.h"
47#include "qhelpfilterengine.h"
48
49#include <QtCore/QDir>
50#include <QtCore/QFile>
51#include <QtCore/QPluginLoader>
52#include <QtCore/QTimer>
53#include <QtWidgets/QApplication>
54#include <QtSql/QSqlQuery>
55
56QT_BEGIN_NAMESPACE
57
58void QHelpEnginePrivate::init(const QString &collectionFile,
59 QHelpEngineCore *helpEngineCore)
60{
61 QHelpEngineCorePrivate::init(collectionFile, helpEngineCore);
62
63 if (!contentModel)
64 contentModel = new QHelpContentModel(this);
65 if (!indexModel)
66 indexModel = new QHelpIndexModel(this);
67
68 connect(sender: helpEngineCore, signal: &QHelpEngineCore::setupFinished,
69 receiver: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
70 connect(sender: helpEngineCore, signal: &QHelpEngineCore::currentFilterChanged,
71 receiver: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
72 connect(sender: helpEngineCore->filterEngine(), signal: &QHelpFilterEngine::filterActivated,
73 receiver: this, slot: &QHelpEnginePrivate::scheduleApplyCurrentFilter);
74}
75
76void QHelpEnginePrivate::scheduleApplyCurrentFilter()
77{
78 if (!error.isEmpty())
79 return;
80
81 if (m_isApplyCurrentFilterScheduled)
82 return;
83
84 m_isApplyCurrentFilterScheduled = true;
85 QTimer::singleShot(interval: 0, receiver: this, slot: &QHelpEnginePrivate::applyCurrentFilter);
86}
87
88void QHelpEnginePrivate::applyCurrentFilter()
89{
90 m_isApplyCurrentFilterScheduled = false;
91 const QString filter = usesFilterEngine
92 ? q->filterEngine()->activeFilter()
93 : currentFilter;
94 contentModel->createContents(customFilterName: filter);
95 indexModel->createIndex(customFilterName: filter);
96}
97
98void QHelpEnginePrivate::setContentsWidgetBusy()
99{
100#if QT_CONFIG(cursor)
101 contentWidget->setCursor(Qt::WaitCursor);
102#endif
103}
104
105void QHelpEnginePrivate::unsetContentsWidgetBusy()
106{
107#if QT_CONFIG(cursor)
108 contentWidget->unsetCursor();
109#endif
110}
111
112void QHelpEnginePrivate::setIndexWidgetBusy()
113{
114#if QT_CONFIG(cursor)
115 indexWidget->setCursor(Qt::WaitCursor);
116#endif
117}
118
119void QHelpEnginePrivate::unsetIndexWidgetBusy()
120{
121#if QT_CONFIG(cursor)
122 indexWidget->unsetCursor();
123#endif
124}
125
126/*!
127 \class QHelpEngine
128 \since 4.4
129 \inmodule QtHelp
130 \brief The QHelpEngine class provides access to contents and
131 indices of the help engine.
132*/
133
134/*!
135 Constructs a new help engine with the given \a parent. The help
136 engine uses the information stored in the \a collectionFile for
137 providing help. If the collection file does not already exist,
138 it will be created.
139*/
140QHelpEngine::QHelpEngine(const QString &collectionFile, QObject *parent)
141 : QHelpEngineCore(d = new QHelpEnginePrivate(), parent)
142{
143 d->init(collectionFile, helpEngineCore: this);
144}
145
146/*!
147 Destroys the help engine object.
148*/
149QHelpEngine::~QHelpEngine()
150{
151}
152
153/*!
154 Returns the content model.
155*/
156QHelpContentModel *QHelpEngine::contentModel() const
157{
158 return d->contentModel;
159}
160
161/*!
162 Returns the index model.
163*/
164QHelpIndexModel *QHelpEngine::indexModel() const
165{
166 return d->indexModel;
167}
168
169/*!
170 Returns the content widget.
171*/
172QHelpContentWidget *QHelpEngine::contentWidget()
173{
174 if (!d->contentWidget) {
175 d->contentWidget = new QHelpContentWidget();
176 d->contentWidget->setModel(d->contentModel);
177 connect(sender: d->contentModel, signal: &QHelpContentModel::contentsCreationStarted,
178 receiver: d, slot: &QHelpEnginePrivate::setContentsWidgetBusy);
179 connect(sender: d->contentModel, signal: &QHelpContentModel::contentsCreated,
180 receiver: d, slot: &QHelpEnginePrivate::unsetContentsWidgetBusy);
181 }
182 return d->contentWidget;
183}
184
185/*!
186 Returns the index widget.
187*/
188QHelpIndexWidget *QHelpEngine::indexWidget()
189{
190 if (!d->indexWidget) {
191 d->indexWidget = new QHelpIndexWidget();
192 d->indexWidget->setModel(d->indexModel);
193 connect(sender: d->indexModel, signal: &QHelpIndexModel::indexCreationStarted,
194 receiver: d, slot: &QHelpEnginePrivate::setIndexWidgetBusy);
195 connect(sender: d->indexModel, signal: &QHelpIndexModel::indexCreated,
196 receiver: d, slot: &QHelpEnginePrivate::unsetIndexWidgetBusy);
197 }
198 return d->indexWidget;
199}
200
201/*!
202 Returns the default search engine.
203*/
204QHelpSearchEngine* QHelpEngine::searchEngine()
205{
206 if (!d->searchEngine)
207 d->searchEngine = new QHelpSearchEngine(this, this);
208 return d->searchEngine;
209}
210
211QT_END_NAMESPACE
212

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