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