Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickdayofweekmodel.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
5
6#include <QtCore/private/qabstractitemmodel_p.h>
7
9
11{
12 Q_DECLARE_PUBLIC(QQuickDayOfWeekModel)
13
14public:
16};
17
22
24{
25 Q_D(const QQuickDayOfWeekModel);
26 return d->locale;
27}
28
30{
32 if (d->locale != locale) {
33 d->locale = locale;
35 emit dataChanged(index(0, 0), index(6, 0));
36 }
37}
38
40{
41 Q_D(const QQuickDayOfWeekModel);
42 int day = d->locale.firstDayOfWeek() + index;
43 if (day > 7)
44 day -= 7;
45 if (day == 7)
46 day = 0; // Qt::Sunday = 7, but Sunday is 0 in JS Date
47 return day;
48}
49
51{
52 Q_D(const QQuickDayOfWeekModel);
53 if (index.isValid() && index.row() < 7) {
54 int day = dayAt(index.row());
55 switch (role) {
56 case DayRole:
57 return day;
58 case LongNameRole:
59 return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::LongFormat);
60 case ShortNameRole:
61 return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::ShortFormat);
62 case NarrowNameRole:
63 return d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::NarrowFormat);
64 default:
65 break;
66 }
67 }
68 return QVariant();
69}
70
72{
73 if (parent.isValid())
74 return 0;
75 return 7;
76}
77
78QHash<int, QByteArray> QQuickDayOfWeekModel::roleNames() const
79{
80 QHash<int, QByteArray> roles;
81 roles[DayRole] = QByteArrayLiteral("day");
82 roles[LongNameRole] = QByteArrayLiteral("longName");
83 roles[ShortNameRole] = QByteArrayLiteral("shortName");
84 roles[NarrowNameRole] = QByteArrayLiteral("narrowName");
85 return roles;
86}
87
89
90#include "moc_qquickdayofweekmodel_p.cpp"
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
@ LongFormat
Definition qlocale.h:875
@ NarrowFormat
Definition qlocale.h:875
@ ShortFormat
Definition qlocale.h:875
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
Q_INVOKABLE int dayAt(int index) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
QHash< int, QByteArray > roleNames() const override
void setLocale(const QLocale &locale)
QQuickDayOfWeekModel(QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
@ Sunday
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
GLuint index
[2]
#define emit