1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QCALENDAR_BACKEND_P_H |
41 | #define QCALENDAR_BACKEND_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists for the convenience |
48 | // of calendar implementations. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtCore/qobjectdefs.h> |
55 | #include <QtCore/qcalendar.h> |
56 | #include <QtCore/qstringlist.h> |
57 | #include <QtCore/qstring.h> |
58 | #include <QtCore/qmap.h> |
59 | #include <QtCore/private/qlocale_p.h> |
60 | |
61 | QT_BEGIN_NAMESPACE |
62 | |
63 | // Locale-related parts, mostly handled in ../text/qlocale.cpp |
64 | |
65 | struct QCalendarLocale { |
66 | quint16 m_language_id, m_script_id, m_country_id; |
67 | |
68 | #define rangeGetter(name) \ |
69 | QLocaleData::DataRange name() const { return { m_ ## name ## _idx, m_ ## name ## _size }; } |
70 | |
71 | rangeGetter(longMonthStandalone) rangeGetter(longMonth) |
72 | rangeGetter(shortMonthStandalone) rangeGetter(shortMonth) |
73 | rangeGetter(narrowMonthStandalone) rangeGetter(narrowMonth) |
74 | #undef rangeGetter |
75 | |
76 | // Month name indexes: |
77 | quint16 m_longMonthStandalone_idx, m_longMonth_idx; |
78 | quint16 m_shortMonthStandalone_idx, m_shortMonth_idx; |
79 | quint16 m_narrowMonthStandalone_idx, m_narrowMonth_idx; |
80 | |
81 | // Twelve long month names (separated by commas) can add up to more than 256 |
82 | // QChars - e.g. kde_TZ gets to 264. |
83 | quint16 m_longMonthStandalone_size, m_longMonth_size; |
84 | quint8 m_shortMonthStandalone_size, m_shortMonth_size; |
85 | quint8 m_narrowMonthStandalone_size, m_narrowMonth_size; |
86 | }; |
87 | |
88 | // Partial implementation, of methods with common forms, in qcalendar.cpp |
89 | class Q_CORE_EXPORT QCalendarBackend |
90 | { |
91 | friend class QCalendar; |
92 | public: |
93 | virtual ~QCalendarBackend(); |
94 | virtual QString name() const = 0; |
95 | virtual QCalendar::System calendarSystem() const; |
96 | // Date queries: |
97 | virtual int daysInMonth(int month, int year = QCalendar::Unspecified) const = 0; |
98 | virtual int daysInYear(int year) const; |
99 | virtual int monthsInYear(int year) const; |
100 | virtual bool isDateValid(int year, int month, int day) const; |
101 | // Properties of the calendar: |
102 | virtual bool isLeapYear(int year) const = 0; |
103 | virtual bool isLunar() const = 0; |
104 | virtual bool isLuniSolar() const = 0; |
105 | virtual bool isSolar() const = 0; |
106 | virtual bool isProleptic() const; |
107 | virtual bool hasYearZero() const; |
108 | virtual int maximumDaysInMonth() const; |
109 | virtual int minimumDaysInMonth() const; |
110 | virtual int maximumMonthsInYear() const; |
111 | // Julian Day conversions: |
112 | virtual bool dateToJulianDay(int year, int month, int day, qint64 *jd) const = 0; |
113 | virtual QCalendar::YearMonthDay julianDayToDate(qint64 jd) const = 0; |
114 | // Day of week and week numbering: |
115 | virtual int dayOfWeek(qint64 jd) const; |
116 | |
117 | // Names of months and week-days (implemented in qlocale.cpp): |
118 | virtual QString monthName(const QLocale &locale, int month, int year, |
119 | QLocale::FormatType format) const; |
120 | virtual QString standaloneMonthName(const QLocale &locale, int month, int year, |
121 | QLocale::FormatType format) const; |
122 | virtual QString weekDayName(const QLocale &locale, int day, |
123 | QLocale::FormatType format) const; |
124 | virtual QString standaloneWeekDayName(const QLocale &locale, int day, |
125 | QLocale::FormatType format) const; |
126 | |
127 | // Formatting of date-times (implemented in qlocale.cpp): |
128 | virtual QString dateTimeToString(QStringView format, const QDateTime &datetime, |
129 | QDate dateOnly, QTime timeOnly, |
130 | const QLocale &locale) const; |
131 | |
132 | // Calendar enumeration by name: |
133 | static QStringList availableCalendars(); |
134 | |
135 | protected: |
136 | QCalendarBackend(const QString &name, QCalendar::System id = QCalendar::System::User); |
137 | |
138 | // Locale support: |
139 | virtual const QCalendarLocale *localeMonthIndexData() const = 0; |
140 | virtual const char16_t *localeMonthData() const = 0; |
141 | |
142 | bool registerAlias(const QString &name); |
143 | |
144 | private: |
145 | // QCalendar's access to its registry: |
146 | static const QCalendarBackend *fromName(QStringView name); |
147 | static const QCalendarBackend *fromName(QLatin1String name); |
148 | // QCalendar's access to singletons: |
149 | static const QCalendarBackend *(QCalendar::System system); |
150 | }; |
151 | |
152 | QT_END_NAMESPACE |
153 | |
154 | #endif // QCALENDAR_BACKEND_P_H |
155 | |