Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickdayofweekrow.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
// Qt-Security score:significant reason:default
4
5
#
include
"qquickdayofweekrow_p.h"
6
#
include
"qquickdayofweekmodel_p.h"
7
8
#
include
<
QtQuickTemplates2
/
private
/
qquickcontrol_p_p
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
/*!
13
\qmltype DayOfWeekRow
14
\inherits Control
15
//! \nativetype QQuickDayOfWeekRow
16
\inqmlmodule QtQuick.Controls
17
\brief A row of names for the days in a week.
18
19
DayOfWeekRow presents day of week names in a row. The names of the days
20
are ordered and formatted using the specified \l {Control::locale}{locale}.
21
22
\image qtquickcontrols-dayofweekrow.webp
23
{Day of week row displaying weekday names}
24
\snippet qtquickcontrols-dayofweekrow.qml 1
25
26
DayOfWeekRow can be used as a standalone control, but it is most
27
often used in conjunction with MonthGrid. Regardless of the use case,
28
positioning of the row is left to the user.
29
30
\image qtquickcontrols-dayofweekrow-layout.webp
31
{Day of week row in calendar layout}
32
\snippet qtquickcontrols-dayofweekrow-layout.qml 1
33
34
The visual appearance of DayOfWeekRow can be changed by
35
implementing a \l {delegate}{custom delegate}.
36
37
\sa MonthGrid, WeekNumberColumn
38
*/
39
40
class
QQuickDayOfWeekRowPrivate
:
public
QQuickControlPrivate
41
{
42
public
:
43
QQuickDayOfWeekRowPrivate
() :
delegate
(
nullptr
),
model
(
nullptr
) { }
44
45
void
resizeItems
();
46
47
QVariant
source
;
48
QQmlComponent *
delegate
;
49
QQuickDayOfWeekModel
*
model
;
50
};
51
52
void
QQuickDayOfWeekRowPrivate
::
resizeItems
()
53
{
54
if
(!contentItem)
55
return
;
56
57
QSizeF itemSize;
58
itemSize.setWidth((contentItem->width() - 6 * spacing) / 7);
59
itemSize.setHeight(contentItem->height());
60
61
const
auto
childItems = contentItem->childItems();
62
for
(QQuickItem *item : childItems)
63
item->setSize(itemSize);
64
}
65
66
QQuickDayOfWeekRow
::QQuickDayOfWeekRow(QQuickItem *parent) :
67
QQuickControl(*(
new
QQuickDayOfWeekRowPrivate), parent)
68
{
69
Q_D(QQuickDayOfWeekRow);
70
d->model =
new
QQuickDayOfWeekModel(
this
);
71
d->source = QVariant::fromValue(d->model);
72
}
73
74
/*!
75
\internal
76
\qmlproperty model QtQuick.Controls::DayOfWeekRow::source
77
78
This property holds the source model that is used as a data model
79
for the internal content row.
80
*/
81
QVariant
QQuickDayOfWeekRow
::
source
()
const
82
{
83
Q_D(
const
QQuickDayOfWeekRow);
84
return
d->source;
85
}
86
87
void
QQuickDayOfWeekRow
::
setSource
(
const
QVariant &source)
88
{
89
Q_D(QQuickDayOfWeekRow);
90
if
(d->source != source) {
91
d->source = source;
92
emit sourceChanged();
93
}
94
}
95
96
/*!
97
\qmlproperty Component QtQuick.Controls::DayOfWeekRow::delegate
98
99
This property holds the item delegate that visualizes each day of the week.
100
101
In addition to the \c index property, a list of model data roles
102
are available in the context of each delegate:
103
\table
104
\row
105
\li \b model.day : int
106
\li The day of week (\l Qt::DayOfWeek)
107
\row
108
\li \b model.longName : string
109
\li The long version of the day name; for example,
110
"Monday" (\l QLocale::LongFormat)
111
\row
112
\li \b model.shortName : string
113
\li The short version of the day name; for example, "Mon"
114
(\l QLocale::ShortFormat)
115
\row
116
\li \b model.narrowName : string
117
\li A special version of the day name for use when space is limited.
118
For example, "M" (\l QLocale::NarrowFormat)
119
\endtable
120
121
The following snippet presents the default implementation of the item
122
delegate. It can be used as a starting point for implementing custom
123
delegates.
124
125
\snippet basic/DayOfWeekRow.qml delegate
126
127
\include delegate-ownership.qdocinc {no-ownership} {DayOfWeekRow}
128
*/
129
QQmlComponent *
QQuickDayOfWeekRow
::
delegate
()
const
130
{
131
Q_D(
const
QQuickDayOfWeekRow);
132
return
d->delegate;
133
}
134
135
void
QQuickDayOfWeekRow
::
setDelegate
(QQmlComponent *delegate)
136
{
137
Q_D(QQuickDayOfWeekRow);
138
if
(d->delegate != delegate) {
139
d->delegate = delegate;
140
emit delegateChanged();
141
}
142
}
143
144
void
QQuickDayOfWeekRow
::
componentComplete
()
145
{
146
Q_D(QQuickDayOfWeekRow);
147
QQuickControl::componentComplete();
148
d->resizeItems();
149
}
150
151
void
QQuickDayOfWeekRow
::
geometryChange
(
const
QRectF &newGeometry,
const
QRectF &oldGeometry)
152
{
153
Q_D(QQuickDayOfWeekRow);
154
QQuickControl::geometryChange(newGeometry, oldGeometry);
155
if
(isComponentComplete())
156
d->resizeItems();
157
}
158
159
void
QQuickDayOfWeekRow
::
localeChange
(
const
QLocale &newLocale,
const
QLocale &oldLocale)
160
{
161
Q_D(QQuickDayOfWeekRow);
162
QQuickControl::localeChange(newLocale, oldLocale);
163
d->model->setLocale(newLocale);
164
}
165
166
void
QQuickDayOfWeekRow
::
paddingChange
(
const
QMarginsF &newPadding,
const
QMarginsF &oldPadding)
167
{
168
Q_D(QQuickDayOfWeekRow);
169
QQuickControl::paddingChange(newPadding, oldPadding);
170
if
(isComponentComplete())
171
d->resizeItems();
172
}
173
174
QT_END_NAMESPACE
175
176
#
include
"moc_qquickdayofweekrow_p.cpp"
QQuickDayOfWeekModel
Definition
qquickdayofweekmodel_p.h:29
QQuickDayOfWeekRowPrivate
A row of names for the days in a week.
Definition
qquickdayofweekrow.cpp:41
QQuickDayOfWeekRowPrivate::model
QQuickDayOfWeekModel * model
Definition
qquickdayofweekrow.cpp:49
QQuickDayOfWeekRowPrivate::delegate
QQmlComponent * delegate
Definition
qquickdayofweekrow.cpp:48
QQuickDayOfWeekRowPrivate::resizeItems
void resizeItems()
Definition
qquickdayofweekrow.cpp:52
QQuickDayOfWeekRowPrivate::source
QVariant source
Definition
qquickdayofweekrow.cpp:47
QQuickDayOfWeekRowPrivate::QQuickDayOfWeekRowPrivate
QQuickDayOfWeekRowPrivate()
Definition
qquickdayofweekrow.cpp:43
QQuickDayOfWeekRow
Definition
qquickdayofweekrow_p.h:27
QQuickDayOfWeekRow::delegate
QQmlComponent * delegate() const
\qmlproperty Component QtQuick.Controls::DayOfWeekRow::delegate
Definition
qquickdayofweekrow.cpp:129
QQuickDayOfWeekRow::setDelegate
void setDelegate(QQmlComponent *delegate)
Definition
qquickdayofweekrow.cpp:135
QQuickDayOfWeekRow::localeChange
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
Definition
qquickdayofweekrow.cpp:159
QQuickDayOfWeekRow::geometryChange
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
Definition
qquickdayofweekrow.cpp:151
QQuickDayOfWeekRow::componentComplete
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Definition
qquickdayofweekrow.cpp:144
QQuickDayOfWeekRow::setSource
void setSource(const QVariant &source)
Definition
qquickdayofweekrow.cpp:87
QQuickDayOfWeekRow::source
QVariant source() const
Definition
qquickdayofweekrow.cpp:81
QQuickDayOfWeekRow::paddingChange
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override
Definition
qquickdayofweekrow.cpp:166
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quicktemplates
qquickdayofweekrow.cpp
Generated on
for Qt by
1.18.0