Qt 6.x
The Qt SDK
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
63public:
64 virtual ~QCalendarBackend();
65 virtual QString name() const = 0;
66
67 QStringList names() const;
68
69 QCalendar::System calendarSystem() const;
70 QCalendar::SystemId calendarId() const { return m_id; }
71 // Date queries:
72 virtual int daysInMonth(int month, int year = QCalendar::Unspecified) const = 0;
73 virtual int daysInYear(int year) const;
74 virtual int monthsInYear(int year) const;
75 virtual bool isDateValid(int year, int month, int day) const;
76 // Properties of the calendar:
77 virtual bool isLeapYear(int year) const = 0;
78 virtual bool isLunar() const = 0;
79 virtual bool isLuniSolar() const = 0;
80 virtual bool isSolar() const = 0;
81 virtual bool isProleptic() const;
82 virtual bool hasYearZero() const;
83 virtual int maximumDaysInMonth() const;
84 virtual int minimumDaysInMonth() const;
85 virtual int maximumMonthsInYear() const;
86 // Julian Day conversions:
87 virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0;
89 // Day of week and week numbering:
90 virtual int dayOfWeek(qint64 jd) const;
91
92 // Names of months and week-days (implemented in qlocale.cpp):
93 virtual QString monthName(const QLocale &locale, int month, int year,
95 virtual QString standaloneMonthName(const QLocale &locale, int month, int year,
97 virtual QString weekDayName(const QLocale &locale, int day,
99 virtual QString standaloneWeekDayName(const QLocale &locale, int day,
101
102 // Formatting of date-times (implemented in qlocale.cpp):
103 virtual QString dateTimeToString(QStringView format, const QDateTime &datetime,
104 QDate dateOnly, QTime timeOnly,
105 const QLocale &locale) const;
106
107 bool isGregorian() const;
108
109 QCalendar::SystemId registerCustomBackend(const QStringList &names);
110
111 // Calendar enumeration by name:
112 static QStringList availableCalendars();
113
114protected:
115 // Locale support:
116 virtual const QCalendarLocale *localeMonthIndexData() const = 0;
117 virtual const char16_t *localeMonthData() const = 0;
118
119private:
121
122 void setIndex(size_t index);
123
124 // QCalendar's access to its registry:
125 static const QCalendarBackend *fromName(QAnyStringView name);
126 static const QCalendarBackend *fromId(QCalendar::SystemId id);
127 // QCalendar's access to singletons:
128 static const QCalendarBackend *fromEnum(QCalendar::System system);
129 static const QCalendarBackend *gregorian();
130};
131
133
134#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.
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:257
\inmodule QtCore \reentrant
Definition qdatetime.h:27
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore \reentrant
Definition qdatetime.h:189
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
#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:43
long long qint64
Definition qtypes.h:55
unsigned char quint8
Definition qtypes.h:41
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