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
qcalendarbackend_p.h
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
4#ifndef QCALENDAR_BACKEND_P_H
5#define QCALENDAR_BACKEND_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of calendar implementations. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qobjectdefs.h>
19#include <QtCore/qcalendar.h>
20#include <QtCore/qstringlist.h>
21#include <QtCore/qstring.h>
22#include <QtCore/qmap.h>
23#include <QtCore/qanystringview.h>
24#include <QtCore/private/qlocale_p.h>
25
27
28namespace QtPrivate {
29class QCalendarRegistry;
30}
31
32// Locale-related parts, mostly handled in ../text/qlocale.cpp
33
36
37#define rangeGetter(name) \
38 QLocaleData::DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; }
39
40 rangeGetter(longMonthStandalone) rangeGetter(longMonth)
41 rangeGetter(shortMonthStandalone) rangeGetter(shortMonth)
42 rangeGetter(narrowMonthStandalone) rangeGetter(narrowMonth)
43#undef rangeGetter
44
45 // Month name indexes:
46 quint16 m_longMonthStandalone_idx, m_longMonth_idx;
49
50 // Twelve long month names (separated by commas) can add up to more than 256
51 // QChars - e.g. kde_TZ gets to 264.
55};
56
57// Partial implementation, of methods with common forms, in qcalendar.cpp
58class Q_CORE_EXPORT QCalendarBackend
59{
60 friend class QCalendar;
62 Q_DISABLE_COPY_MOVE(QCalendarBackend)
63
64public:
65 QCalendarBackend() = default;
66 virtual ~QCalendarBackend();
67 virtual QString name() const = 0;
68
69 QStringList names() const;
70
71 QCalendar::System calendarSystem() const;
72 QCalendar::SystemId calendarId() const { return m_id; }
73 // Date queries:
74 virtual int daysInMonth(int month, int year = QCalendar::Unspecified) const = 0;
75 virtual int daysInYear(int year) const;
76 virtual int monthsInYear(int year) const;
77 virtual bool isDateValid(int year, int month, int day) const;
78 // Properties of the calendar:
79 virtual bool isLeapYear(int year) const = 0;
80 virtual bool isLunar() const = 0;
81 virtual bool isLuniSolar() const = 0;
82 virtual bool isSolar() const = 0;
83 virtual bool isProleptic() const;
84 virtual bool hasYearZero() const;
85 virtual int maximumDaysInMonth() const;
86 virtual int minimumDaysInMonth() const;
87 virtual int maximumMonthsInYear() const;
88 // Julian Day conversions:
89 virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0;
91 // Day of week:
92 virtual int dayOfWeek(qint64 jd) const;
93 virtual qint64 matchCenturyToWeekday(const QCalendar::YearMonthDay &parts, int dow) const;
94
95 // Names of months and week-days (implemented in qlocale.cpp):
96 virtual QString monthName(const QLocale &locale, int month, int year,
98 virtual QString standaloneMonthName(const QLocale &locale, int month, int year,
100 virtual QString weekDayName(const QLocale &locale, int day,
102 virtual QString standaloneWeekDayName(const QLocale &locale, int day,
104
105 // Formatting of date-times (implemented in qlocale.cpp):
106 virtual QString dateTimeToString(QStringView format, const QDateTime &datetime,
107 QDate dateOnly, QTime timeOnly,
108 const QLocale &locale) const;
109
110 bool isGregorian() const;
111
112 QCalendar::SystemId registerCustomBackend(const QStringList &names);
113
114 // Calendar enumeration by name:
115 static QStringList availableCalendars();
116
117protected:
118 // Locale support:
119 virtual const QCalendarLocale *localeMonthIndexData() const = 0;
120 virtual const char16_t *localeMonthData() const = 0;
121
122private:
124
125 void setIndex(size_t index);
126
127 // QCalendar's access to its registry:
128 static const QCalendarBackend *fromName(QAnyStringView name);
129 static const QCalendarBackend *fromId(QCalendar::SystemId id);
130 // QCalendar's access to singletons:
131 static const QCalendarBackend *fromEnum(QCalendar::System system);
132 static const QCalendarBackend *gregorian();
133};
134
136
137#endif // QCALENDAR_BACKEND_P_H
\inmodule QtCore
The QCalendarBackend class provides basic calendaring functions.
virtual int daysInMonth(int month, int year=QCalendar::Unspecified) const =0
Returns number of days in the month number month, in year year.
virtual const char16_t * localeMonthData() const =0
virtual bool isSolar() const =0
Returns true if this calendar is a solar calendar.
virtual bool isLuniSolar() const =0
Returns true if this calendar is a lunisolar calendar.
QCalendar::SystemId calendarId() const
virtual const QCalendarLocale * localeMonthIndexData() const =0
virtual bool isLeapYear(int year) const =0
Returns true if the specified year is a leap year for this calendar.
QCalendarBackend()=default
virtual bool isLunar() const =0
Returns true if this calendar is a lunar calendar.
virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const =0
Computes the Julian day number corresponding to the specified year, month, and day.
virtual QCalendar::YearMonthDay julianDayToDate(qint64 jd) const =0
Computes the year, month, and day in this calendar for the given Julian day number jd.
virtual QString name() const =0
Returns the primary name of the calendar.
\inmodule QtCore
Definition qcalendar.h:98
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
System
This enumerated type is used to specify a choice of calendar system.
Definition qcalendar.h:73
@ Unspecified
Definition qcalendar.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore \reentrant
Definition qdatetime.h:29
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore \reentrant
Definition qdatetime.h:215
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
#define rangeGetter(name)
static void setIndex(int *index, int candidate, int min, int max, bool isIncreasing)
Definition qmdiarea.cpp:175
GLuint index
[2]
GLuint name
GLint GLsizei GLsizei GLenum format
GLuint GLuint * names
unsigned short quint16
Definition qtypes.h:48
long long qint64
Definition qtypes.h:60
unsigned char quint8
Definition qtypes.h:46
quint16 m_longMonthStandalone_size
quint16 m_shortMonthStandalone_idx
quint8 m_narrowMonthStandalone_size
quint8 m_shortMonthStandalone_size
rangeGetter(longMonthStandalone) rangeGetter(longMonth) rangeGetter(shortMonthStandalone) rangeGetter(shortMonth) rangeGetter(narrowMonthStandalone) rangeGetter(narrowMonth) quint16 m_longMonthStandalone_idx
quint16 m_narrowMonthStandalone_idx