1// Copyright (C) 2025 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 "qquickheaderviewdelegate_p.h"
5
6#include <QtQuickTemplates2/private/qquickheaderview_p.h>
7#include <QtQuickTemplates2/private/qquickheaderview_p_p.h>
8#include <QtQuickTemplates2/private/qquicktableviewdelegate_p_p.h>
9
10/*!
11 \qmltype HorizontalHeaderViewDelegate
12 \inherits TableViewDelegate
13 \inqmlmodule QtQuick.Controls
14 \since 6.10
15 \ingroup qtquickcontrols-delegates
16
17 \image qtquickcontrols-headerviewdelegate.png
18
19 The HorizontalHeaderViewDelegate serves as the default delegate
20 automatically assigned to the \l HorizontalHeaderView's
21 \l {TableView::delegate} {delegate property}.
22 This delegate handles rendering every header cell using the
23 application's predefined style specifications.
24
25 HorizontalHeaderViewDelegate inherits TableViewDelegate, which means
26 that it's composed of two items:
27 a \l[QML]{Control::}{background} and
28 a \l [QML]{Control::}{contentItem}.
29
30 \sa {Customizing HeaderViewDelegate}, {HorizontalHeaderView}
31*/
32
33/*!
34 \qmltype VerticalHeaderViewDelegate
35 \inherits TableViewDelegate
36 \inqmlmodule QtQuick.Controls
37 \since 6.10
38 \ingroup qtquickcontrols-delegates
39
40 \image qtquickcontrols-headerviewdelegate.png
41
42 The VerticalHeaderViewDelegate serves as the default delegate
43 automatically assigned to the \l VerticalHeaderView's
44 \l {TableView::delegate} {delegate property}.
45 This delegate handles rendering every header cell using the
46 application's predefined style specifications.
47
48 VerticalHeaderViewDelegate inherits TableViewDelegate, which means
49 that it's composed of two items:
50 a \l[QML]{Control::}{background} and
51 a \l [QML]{Control::}{contentItem}.
52
53 \sa {Customizing HeaderViewDelegate}, {VerticalHeaderView}
54*/
55
56/*!
57 \qmlproperty HeaderView QtQuick.Controls::HorizontalHeaderViewDelegate::headerView
58
59 This property points to the \l HorizontalHeaderView that contains the delegate item.
60*/
61
62/*!
63 \qmlproperty HeaderView QtQuick.Controls::VerticalHeaderViewDelegate::headerView
64
65 This property points to the \l VerticalHeaderView that contains the delegate item.
66*/
67
68/*!
69 \qmlproperty Qt::Orientations QtQuick.Controls::HorizontalHeaderViewDelegate::orientation
70
71 This property has the same value of the headerView's orientation.
72*/
73
74/*!
75 \qmlproperty Qt::Orientations QtQuick.Controls::VerticalHeaderViewDelegate::orientation
76
77 This property has the same value of the headerView's orientation.
78*/
79
80
81QT_BEGIN_NAMESPACE
82
83class QQuickHeaderViewDelegatePrivate : public QQuickTableViewDelegatePrivate
84{
85public:
86 Q_DECLARE_PUBLIC(QQuickHeaderViewDelegate)
87
88public:
89 QPointer<QQuickHeaderViewBase> headerView;
90 QVariant model;
91};
92
93QQuickHeaderViewDelegate::QQuickHeaderViewDelegate(QQuickItem *parent)
94 : QQuickTableViewDelegate(*(new QQuickHeaderViewDelegatePrivate), parent)
95{
96}
97
98QQuickHeaderViewBase *QQuickHeaderViewDelegate::headerView() const
99{
100 return d_func()->headerView;
101}
102
103Qt::Orientation QQuickHeaderViewDelegate::orientation() const
104{
105 return headerView()
106 ? QQuickHeaderViewBasePrivate::get(q: headerView())->orientation()
107 : Qt::Horizontal;
108}
109
110void QQuickHeaderViewDelegate::setHeaderView(QQuickHeaderViewBase *headerView)
111{
112 Q_D(QQuickHeaderViewDelegate);
113 if (d->headerView == headerView)
114 return;
115
116 const Qt::Orientation oldOrientation = orientation();
117
118 d->headerView = headerView;
119 emit headerViewChanged();
120
121 if (oldOrientation != orientation())
122 emit orientationChanged();
123}
124
125QVariant QQuickHeaderViewDelegate::model() const
126{
127 return d_func()->model;
128}
129
130void QQuickHeaderViewDelegate::setModel(const QVariant &model)
131{
132 Q_D(QQuickHeaderViewDelegate);
133 if (d->model == model)
134 return;
135 d->model = model;
136 emit modelChanged();
137}
138
139QT_END_NAMESPACE
140
141#include "moc_qquickheaderviewdelegate_p.cpp"
142

source code of qtdeclarative/src/quicktemplates/qquickheaderviewdelegate.cpp