aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates/qquickheaderviewdelegate.cpp
blob: e90d72afbe6748afdc29f13fe68a65d8f6d8a025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qquickheaderviewdelegate_p.h"

#include <QtQuickTemplates2/private/qquickheaderview_p.h>
#include <QtQuickTemplates2/private/qquickheaderview_p_p.h>
#include <QtQuickTemplates2/private/qquicktableviewdelegate_p_p.h>

/*!
    \qmltype HorizontalHeaderViewDelegate
    \inherits TableViewDelegate
    \inqmlmodule QtQuick.Controls
    \since 6.10
    \ingroup qtquickcontrols-delegates

    \image qtquickcontrols-headerviewdelegate.png

    The HorizontalHeaderViewDelegate serves as the default delegate
    automatically assigned to the \l HorizontalHeaderView's
    \l {TableView::delegate} {delegate property}.
    This delegate handles rendering every header cell using the
    application's predefined style specifications.

    HorizontalHeaderViewDelegate inherits TableViewDelegate, which means
    that it's composed of two items:
    a \l[QML]{Control::}{background} and
    a \l [QML]{Control::}{contentItem}.

    \sa {Customizing HeaderViewDelegate}, {HorizontalHeaderView}
*/

/*!
    \qmltype VerticalHeaderViewDelegate
    \inherits TableViewDelegate
    \inqmlmodule QtQuick.Controls
    \since 6.10
    \ingroup qtquickcontrols-delegates

    \image qtquickcontrols-headerviewdelegate.png

     The VerticalHeaderViewDelegate serves as the default delegate
     automatically assigned to the \l VerticalHeaderView's
     \l {TableView::delegate} {delegate property}.
     This delegate handles rendering every header cell using the
     application's predefined style specifications.

     VerticalHeaderViewDelegate inherits TableViewDelegate, which means
     that it's composed of two items:
     a \l[QML]{Control::}{background} and
     a \l [QML]{Control::}{contentItem}.

     \sa {Customizing HeaderViewDelegate}, {VerticalHeaderView}
*/

/*!
    \qmlproperty HeaderView QtQuick.Controls::HorizontalHeaderViewDelegate::headerView

    This property points to the \l HorizontalHeaderView that contains the delegate item.
*/

/*!
    \qmlproperty HeaderView QtQuick.Controls::VerticalHeaderViewDelegate::headerView

    This property points to the \l VerticalHeaderView that contains the delegate item.
*/

/*!
    \qmlproperty Qt::Orientations QtQuick.Controls::HorizontalHeaderViewDelegate::orientation

    This property has the same value of the headerView's orientation.
*/

/*!
    \qmlproperty Qt::Orientations QtQuick.Controls::VerticalHeaderViewDelegate::orientation

    This property has the same value of the headerView's orientation.
*/


QT_BEGIN_NAMESPACE

class QQuickHeaderViewDelegatePrivate : public QQuickTableViewDelegatePrivate
{
public:
    Q_DECLARE_PUBLIC(QQuickHeaderViewDelegate)

public:
    QPointer<QQuickHeaderViewBase> headerView;
    QVariant model;
};

QQuickHeaderViewDelegate::QQuickHeaderViewDelegate(QQuickItem *parent)
    : QQuickTableViewDelegate(*(new QQuickHeaderViewDelegatePrivate), parent)
{
}

QQuickHeaderViewBase *QQuickHeaderViewDelegate::headerView() const
{
    return d_func()->headerView;
}

Qt::Orientation QQuickHeaderViewDelegate::orientation() const
{
    return headerView()
            ? QQuickHeaderViewBasePrivate::get(headerView())->orientation()
            : Qt::Horizontal;
}

void QQuickHeaderViewDelegate::setHeaderView(QQuickHeaderViewBase *headerView)
{
    Q_D(QQuickHeaderViewDelegate);
    if (d->headerView == headerView)
        return;

    const Qt::Orientation oldOrientation = orientation();

    d->headerView = headerView;
    emit headerViewChanged();

    if (oldOrientation != orientation())
        emit orientationChanged();
}

QVariant QQuickHeaderViewDelegate::model() const
{
    return d_func()->model;
}

void QQuickHeaderViewDelegate::setModel(const QVariant &model)
{
    Q_D(QQuickHeaderViewDelegate);
    if (d->model == model)
        return;
    d->model = model;
    emit modelChanged();
}

QT_END_NAMESPACE

#include "moc_qquickheaderviewdelegate_p.cpp"