Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
// Qt-Security score:significant reason:default
4
5
#
include
"qquickdayofweekmodel_p.h"
6
7
#
include
<
QtCore
/
private
/
qabstractitemmodel_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
class
QQuickDayOfWeekModelPrivate
:
public
QAbstractItemModelPrivate
12
{
13
Q_DECLARE_PUBLIC(QQuickDayOfWeekModel)
14
15
public
:
16
QLocale
locale
;
17
};
18
19
QQuickDayOfWeekModel
::QQuickDayOfWeekModel(QObject *parent) :
20
QAbstractListModel(*(
new
QQuickDayOfWeekModelPrivate), parent)
21
{
22
}
23
24
QLocale
QQuickDayOfWeekModel
::
locale
()
const
25
{
26
Q_D(
const
QQuickDayOfWeekModel);
27
return
d->locale;
28
}
29
30
void
QQuickDayOfWeekModel
::
setLocale
(
const
QLocale &locale)
31
{
32
Q_D(QQuickDayOfWeekModel);
33
if
(d->locale != locale) {
34
d->locale = locale;
35
emit localeChanged();
36
emit dataChanged(index(0, 0), index(6, 0));
37
}
38
}
39
40
int
QQuickDayOfWeekModel
::
dayAt
(
int
index)
const
41
{
42
Q_D(
const
QQuickDayOfWeekModel);
43
int
day = d->locale.firstDayOfWeek() + index;
44
if
(day > 7)
45
day -= 7;
46
if
(day == 7)
47
day = 0;
// Qt::Sunday = 7, but Sunday is 0 in JS Date
48
return
day;
49
}
50
51
QVariant
QQuickDayOfWeekModel
::
data
(
const
QModelIndex &index,
int
role)
const
52
{
53
Q_D(
const
QQuickDayOfWeekModel);
54
if
(index.isValid() && index.row() < 7) {
55
int
day = dayAt(index.row());
56
switch
(role) {
57
case
DayRole
:
58
return
day;
59
case
LongNameRole:
60
return
d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::LongFormat);
61
case
ShortNameRole:
62
return
d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::ShortFormat);
63
case
NarrowNameRole:
64
return
d->locale.standaloneDayName(day == 0 ? Qt::Sunday : day, QLocale::NarrowFormat);
65
default
:
66
break
;
67
}
68
}
69
return
QVariant();
70
}
71
72
int
QQuickDayOfWeekModel
::
rowCount
(
const
QModelIndex &parent)
const
73
{
74
if
(parent.isValid())
75
return
0;
76
return
7;
77
}
78
79
QHash
<
int
,
QByteArray
>
QQuickDayOfWeekModel
::
roleNames
()
const
80
{
81
QHash<
int
, QByteArray> roles;
82
roles[
DayRole
] = QByteArrayLiteral(
"day"
);
83
roles[
LongNameRole
] = QByteArrayLiteral(
"longName"
);
84
roles[
ShortNameRole
] = QByteArrayLiteral(
"shortName"
);
85
roles[
NarrowNameRole
] = QByteArrayLiteral(
"narrowName"
);
86
return
roles;
87
}
88
89
QT_END_NAMESPACE
90
91
#
include
"moc_qquickdayofweekmodel_p.cpp"
QQuickDayOfWeekModelPrivate
Definition
qquickdayofweekmodel.cpp:12
QQuickDayOfWeekModel
Definition
qquickdayofweekmodel_p.h:29
QQuickDayOfWeekModel::locale
QLocale locale() const
Definition
qquickdayofweekmodel.cpp:24
QQuickDayOfWeekModel::dayAt
Q_INVOKABLE int dayAt(int index) const
Definition
qquickdayofweekmodel.cpp:40
QQuickDayOfWeekModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
Definition
qquickdayofweekmodel.cpp:72
QQuickDayOfWeekModel::roleNames
QHash< int, QByteArray > roleNames() const override
Definition
qquickdayofweekmodel.cpp:79
QQuickDayOfWeekModel::setLocale
void setLocale(const QLocale &locale)
Definition
qquickdayofweekmodel.cpp:30
QQuickDayOfWeekModel::NarrowNameRole
@ NarrowNameRole
Definition
qquickdayofweekmodel_p.h:46
QQuickDayOfWeekModel::DayRole
@ DayRole
Definition
qquickdayofweekmodel_p.h:43
QQuickDayOfWeekModel::LongNameRole
@ LongNameRole
Definition
qquickdayofweekmodel_p.h:44
QQuickDayOfWeekModel::ShortNameRole
@ ShortNameRole
Definition
qquickdayofweekmodel_p.h:45
QQuickDayOfWeekModel::data
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.
Definition
qquickdayofweekmodel.cpp:51
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quicktemplates
qquickdayofweekmodel.cpp
Generated on
for Qt by
1.18.0