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 {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
51
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
66QQuickDayOfWeekRow::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*/
82{
83 Q_D(const QQuickDayOfWeekRow);
84 return d->source;
85}
86
87void 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*/
129QQmlComponent *QQuickDayOfWeekRow::delegate() const
130{
131 Q_D(const QQuickDayOfWeekRow);
132 return d->delegate;
133}
134
135void QQuickDayOfWeekRow::setDelegate(QQmlComponent *delegate)
136{
137 Q_D(QQuickDayOfWeekRow);
138 if (d->delegate != delegate) {
139 d->delegate = delegate;
140 emit delegateChanged();
141 }
142}
143
145{
146 Q_D(QQuickDayOfWeekRow);
147 QQuickControl::componentComplete();
148 d->resizeItems();
149}
150
151void 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
159void 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
166void 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
174QT_END_NAMESPACE
175
176#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
Combined button and popup list for selecting options.