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
qquickweeknumbercolumn.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#include <QtQml/qqmlinfo.h>
10
12
13/*!
14 \qmltype WeekNumberColumn
15 \inherits Control
16//! \nativetype QQuickWeekNumberColumn
17 \inqmlmodule QtQuick.Controls
18 \brief A column of week numbers.
19
20 WeekNumberColumn presents week numbers in a column. The week numbers
21 are calculated for a given \l month and \l year, using the specified
22 \l {Control::locale}{locale}.
23
24 \image qtquickcontrols-weeknumbercolumn.webp
25 \snippet qtquickcontrols-weeknumbercolumn.qml 1
26
27 WeekNumberColumn can be used as a standalone control, but it is most
28 often used in conjunction with MonthGrid. Regardless of the use case,
29 positioning of the column is left to the user.
30
31 \image qtquickcontrols-weeknumbercolumn-layout.webp
32 \snippet qtquickcontrols-weeknumbercolumn-layout.qml 1
33
34 The visual appearance of WeekNumberColumn can be changed by
35 implementing a \l {delegate}{custom delegate}.
36
37 \sa MonthGrid, DayOfWeekRow
38*/
39
51
53{
54 if (!contentItem)
55 return;
56
57 QSizeF itemSize;
58 itemSize.setWidth(contentItem->width());
59 itemSize.setHeight((contentItem->height() - 5 * spacing) / 6);
60
61 const auto childItems = contentItem->childItems();
62 for (QQuickItem *item : childItems)
63 item->setSize(itemSize);
64}
65
66QQuickWeekNumberColumn::QQuickWeekNumberColumn(QQuickItem *parent) :
67 QQuickControl(*(new QQuickWeekNumberColumnPrivate), parent)
68{
69 Q_D(QQuickWeekNumberColumn);
70 d->model = new QQuickWeekNumberModel(this);
71 d->source = QVariant::fromValue(d->model);
72 connect(d->model, &QQuickWeekNumberModel::monthChanged, this, &QQuickWeekNumberColumn::monthChanged);
73 connect(d->model, &QQuickWeekNumberModel::yearChanged, this, &QQuickWeekNumberColumn::yearChanged);
74}
75
76/*!
77 \qmlproperty int QtQuick.Controls::WeekNumberColumn::month
78
79 This property holds the number of the month that the week numbers are
80 calculated for. The default value is the current month.
81
82 \include zero-based-months.qdocinc
83
84 \sa Calendar
85*/
87{
88 Q_D(const QQuickWeekNumberColumn);
89 return d->model->month() - 1;
90}
91
93{
94 Q_D(QQuickWeekNumberColumn);
95 if (month < 0 || month > 11) {
96 qmlWarning(this) << "month " << month << " is out of range [0...11]";
97 return;
98 }
99 d->model->setMonth(month + 1);
100}
101
102/*!
103 \qmlproperty int QtQuick.Controls::WeekNumberColumn::year
104
105 This property holds the number of the year that the week numbers are calculated for.
106
107 The value must be in the range from \c -271820 to \c 275759. The default
108 value is the current year.
109*/
111{
112 Q_D(const QQuickWeekNumberColumn);
113 return d->model->year();
114}
115
117{
118 Q_D(QQuickWeekNumberColumn);
119 if (year < -271820 || year > 275759) {
120 qmlWarning(this) << "year " << year << " is out of range [-271820...275759]";
121 return;
122 }
123 d->model->setYear(year);
124}
125
126/*!
127 \internal
128 \qmlproperty model QtQuick.Controls::WeekNumberColumn::source
129
130 This property holds the source model that is used as a data model
131 for the internal content column.
132*/
134{
135 Q_D(const QQuickWeekNumberColumn);
136 return d->source;
137}
138
139void QQuickWeekNumberColumn::setSource(const QVariant &source)
140{
141 Q_D(QQuickWeekNumberColumn);
142 if (d->source != source) {
143 d->source = source;
144 emit sourceChanged();
145 }
146}
147
148/*!
149 \qmlproperty Component QtQuick.Controls::WeekNumberColumn::delegate
150
151 This property holds the item delegate that visualizes each week number.
152
153 In addition to the \c index property, a list of model data roles
154 are available in the context of each delegate:
155 \table
156 \row \li \b model.weekNumber : int \li The week number
157 \endtable
158
159 The following snippet presents the default implementation of the item
160 delegate. It can be used as a starting point for implementing custom
161 delegates.
162
163 \snippet basic/WeekNumberColumn.qml delegate
164
165 \include delegate-ownership.qdocinc {no-ownership} {WeekNumberColumn}
166*/
167QQmlComponent *QQuickWeekNumberColumn::delegate() const
168{
169 Q_D(const QQuickWeekNumberColumn);
170 return d->delegate;
171}
172
173void QQuickWeekNumberColumn::setDelegate(QQmlComponent *delegate)
174{
175 Q_D(QQuickWeekNumberColumn);
176 if (d->delegate != delegate) {
177 d->delegate = delegate;
178 emit delegateChanged();
179 }
180}
181
183{
184 Q_D(QQuickWeekNumberColumn);
185 QQuickControl::componentComplete();
186 d->resizeItems();
187}
188
189void QQuickWeekNumberColumn::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
190{
191 Q_D(QQuickWeekNumberColumn);
192 QQuickControl::geometryChange(newGeometry, oldGeometry);
193 if (isComponentComplete())
194 d->resizeItems();
195}
196
197void QQuickWeekNumberColumn::localeChange(const QLocale &newLocale, const QLocale &oldLocale)
198{
199 Q_D(QQuickWeekNumberColumn);
200 QQuickControl::localeChange(newLocale, oldLocale);
201 d->model->setLocale(newLocale);
202}
203
204void QQuickWeekNumberColumn::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding)
205{
206 Q_D(QQuickWeekNumberColumn);
207 QQuickControl::paddingChange(newPadding, oldPadding);
208 if (isComponentComplete())
209 d->resizeItems();
210}
211
212QT_END_NAMESPACE
213
214#include "moc_qquickweeknumbercolumn_p.cpp"
int year() const
\qmlproperty int QtQuick.Controls::WeekNumberColumn::year
void setSource(const QVariant &source)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
int month() const
\qmlproperty int QtQuick.Controls::WeekNumberColumn::month
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void localeChange(const QLocale &newLocale, const QLocale &oldLocale) override
void setDelegate(QQmlComponent *delegate)
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override
QQmlComponent * delegate() const
\qmlproperty Component QtQuick.Controls::WeekNumberColumn::delegate