1// Copyright (C) 2024 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 "qhelpcontentitem.h"
5
6#include <QtCore/qstring.h>
7#include <QtCore/qurl.h>
8
9QT_BEGIN_NAMESPACE
10
11class QHelpContentItemPrivate
12{
13public:
14 QString title;
15 QUrl link;
16 QHelpContentItem *parent;
17 QList<QHelpContentItem *> childItems = {};
18};
19
20/*!
21 \class QHelpContentItem
22 \inmodule QtHelp
23 \brief The QHelpContentItem class provides an item for use with QHelpContentModel.
24 \since 4.4
25*/
26
27QHelpContentItem::QHelpContentItem(const QString &name, const QUrl &link, QHelpContentItem *parent)
28 : d(new QHelpContentItemPrivate{.title: name, .link: link, .parent: parent})
29{
30 if (parent)
31 parent->d->childItems.append(t: this);
32}
33
34/*!
35 Destroys the help content item.
36*/
37QHelpContentItem::~QHelpContentItem()
38{
39 qDeleteAll(c: d->childItems);
40 delete d;
41}
42
43/*!
44 Returns the child of the content item in the give \a row.
45
46 \sa parent()
47*/
48QHelpContentItem *QHelpContentItem::child(int row) const
49{
50 return d->childItems.value(i: row);
51}
52
53/*!
54 Returns the number of child items.
55*/
56int QHelpContentItem::childCount() const
57{
58 return d->childItems.size();
59}
60
61/*!
62 Returns the row of this item from its parents view.
63*/
64int QHelpContentItem::row() const
65{
66 // TODO: Optimize by keeping the index internally.
67 return d->parent ? d->parent->d->childItems.indexOf(t: const_cast<QHelpContentItem*>(this)) : 0;
68}
69
70/*!
71 Returns the title of the content item.
72*/
73QString QHelpContentItem::title() const
74{
75 return d->title;
76}
77
78/*!
79 Returns the URL of this content item.
80*/
81QUrl QHelpContentItem::url() const
82{
83 return d->link;
84}
85
86/*!
87 Returns the parent content item.
88*/
89QHelpContentItem *QHelpContentItem::parent() const
90{
91 return d->parent;
92}
93
94/*!
95 Returns the position of a given \a child.
96*/
97int QHelpContentItem::childPosition(QHelpContentItem *child) const
98{
99 return d->childItems.indexOf(t: child);
100}
101
102QT_END_NAMESPACE
103

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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