8#include <QtCore/qfuturewatcher.h>
11#include <QtCore/qdir.h>
12#include <QtWidgets/qheaderview.h>
16using namespace Qt::StringLiterals;
48void QHelpContentModelPrivate::createContents(
const ItemFutureProvider &futureProvider)
50 const bool wasRunning =
bool(watcher);
51 watcher.reset(
new QFutureWatcher<std::shared_ptr<QHelpContentItem>>);
52 QObject::connect(watcher.get(), &QFutureWatcherBase::finished, q, [
this] {
53 if (!watcher->isCanceled()) {
54 const std::shared_ptr<QHelpContentItem> result = watcher->result();
55 if (result && result.get()) {
61 watcher.release()->deleteLater();
62 emit q->contentsCreated();
64 watcher->setFuture(futureProvider());
74 emit q->contentsCreationStarted();
79
80
81
82
83
86
87
88
89
90
91
92
93
96
97
98
99
101QHelpContentModel::QHelpContentModel(QHelpEngineCore *helpEngine)
102 : QAbstractItemModel(helpEngine)
103 , d(
new QHelpContentModelPrivate{
this, helpEngine})
107
108
109QHelpContentModel::~QHelpContentModel()
115
116
117
118
119void QHelpContentModel::createContentsForCurrentFilter()
122 d->createContents([
this] {
return d->helpEngine->requestContentForCurrentFilter(); });
127
128
129
130void QHelpContentModel::createContents(
const QString &filter)
133 d->createContents([
this, filter] {
return d->helpEngine->requestContent(filter); });
138void QHelpContentModel::insertContents()
142
143
144
145bool QHelpContentModel::isCreatingContents()
const
148 return bool(d->watcher);
155
156
157
158QHelpContentItem *QHelpContentModel::contentItemAt(
const QModelIndex &index)
const
160 return index.isValid() ?
static_cast<QHelpContentItem *>(index.internalPointer())
165
166
167
168QModelIndex QHelpContentModel::index(
int row,
int column,
const QModelIndex &parent)
const
173 QHelpContentItem *parentItem = contentItemAt(parent);
174 QHelpContentItem *item = parentItem->child(row);
177 return createIndex(row, column, item);
181
182
183
184QModelIndex QHelpContentModel::parent(
const QModelIndex &index)
const
186 QHelpContentItem *item = contentItemAt(index);
190 QHelpContentItem *parentItem =
static_cast<QHelpContentItem*>(item->parent());
194 QHelpContentItem *grandparentItem =
static_cast<QHelpContentItem*>(parentItem->parent());
195 if (!grandparentItem)
198 const int row = grandparentItem->childPosition(parentItem);
199 return createIndex(row, index.column(), parentItem);
203
204
205int QHelpContentModel::rowCount(
const QModelIndex &parent)
const
207 QHelpContentItem *parentItem = contentItemAt(parent);
209 return parentItem->childCount();
214
215
216int QHelpContentModel::columnCount(
const QModelIndex &parent)
const
223
224
225
226QVariant QHelpContentModel::data(
const QModelIndex &index,
int role)
const
228 if (role == Qt::DisplayRole) {
229 QHelpContentItem *item = contentItemAt(index);
231 return item->title();
237
238
239
240
241
244
245
246
247
248
250QHelpContentWidget::QHelpContentWidget()
253 setUniformRowHeights(
true);
254 connect(
this, &QAbstractItemView::activated,
this, &QHelpContentWidget::showLink);
258
259
260
261QModelIndex QHelpContentWidget::indexOf(
const QUrl &link)
263 QHelpContentModel *contentModel = qobject_cast<QHelpContentModel*>(model());
264 if (!contentModel || link.scheme() !=
"qthelp"_L1)
268 for (
int i = 0; i < contentModel->rowCount(); ++i) {
269 QHelpContentItem *itm = contentModel->contentItemAt(contentModel->index(i, 0));
270 if (itm && itm->url().host() == link.host()) {
271 if (searchContentItem(contentModel, contentModel->index(i, 0), QDir::cleanPath(link.path())))
278bool QHelpContentWidget::searchContentItem(QHelpContentModel *model,
const QModelIndex &parent,
279 const QString &cleanPath)
281 QHelpContentItem *parentItem = model->contentItemAt(parent);
285 if (QDir::cleanPath(parentItem->url().path()) == cleanPath) {
286 m_syncIndex = parent;
290 for (
int i = 0; i < parentItem->childCount(); ++i) {
291 if (searchContentItem(model, model->index(i, 0, parent), cleanPath))
297void QHelpContentWidget::showLink(
const QModelIndex &index)
299 QHelpContentModel *contentModel = qobject_cast<QHelpContentModel*>(model());
303 QHelpContentItem *item = contentModel->contentItemAt(index);
306 QUrl url = item->url();
308 emit linkActivated(url);
std::shared_ptr< QHelpContentItem > rootItem
QHelpEngineCore * helpEngine
Combined button and popup list for selecting options.