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