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