summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qcalendarbackend_p.h
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-07-19 13:14:12 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2021-08-06 19:46:18 +0200
commitd0ae1ef33a6eed02acde7304298794f4f0119e16 (patch)
treed5666dd8c391635bc2c2728d8a36285cb7c82768 /src/corelib/time/qcalendarbackend_p.h
parentf84adba1023d019e54d82b1479d9b8d33eff6729 (diff)
QCalendar: Thread-safe calendar backend registration
All calendar backend accounting was moved into QCalendarRegistry class (renamed from Registry). Calendar backends are no longer registered inside constructors, because in multithreaded environment this may lead to incompletely initialized instances becoming visible via QCalendar API in multithreaded environment. All system backends are registered by QCalendarRegistry itself when they are needed. New method QCalendarBackend::registerCustomBackend() is provided to register any 3rd-party calendar backends. Registration by names was also simplified. The list of names is now passed to QCalendarBackend::registerCustomBackend(). The checks are provided to ensure that all system backends have non-conflicting names. Name conflicts for custom backends are resolved in favor of earlier registered backends, as it is already the case in the existing code. The documentation was updated to reflect that. Method QCalendarBackend::names() was added to query the list of names associated with a backend after it is registered. Calendar backend deregistration was completely removed because it is not possible to perform it safely without reference counting. Fixes: QTBUG-93004 Pick-to: 6.2 Change-Id: I0ab1eccc02fdd1e1c66b5e5dd076c93de32d5a49 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/time/qcalendarbackend_p.h')
-rw-r--r--src/corelib/time/qcalendarbackend_p.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/corelib/time/qcalendarbackend_p.h b/src/corelib/time/qcalendarbackend_p.h
index 83893571fc..130a67e340 100644
--- a/src/corelib/time/qcalendarbackend_p.h
+++ b/src/corelib/time/qcalendarbackend_p.h
@@ -61,6 +61,10 @@
QT_BEGIN_NAMESPACE
+namespace QtPrivate {
+class QCalendarRegistry;
+}
+
// Locale-related parts, mostly handled in ../text/qlocale.cpp
struct QCalendarLocale {
@@ -90,9 +94,14 @@ struct QCalendarLocale {
class Q_CORE_EXPORT QCalendarBackend
{
friend class QCalendar;
+ friend class QtPrivate::QCalendarRegistry;
+
public:
virtual ~QCalendarBackend();
virtual QString name() const = 0;
+
+ QStringList names() const;
+
QCalendar::System calendarSystem() const;
QCalendar::SystemId calendarId() const { return m_id; }
// Date queries:
@@ -131,25 +140,29 @@ public:
QDate dateOnly, QTime timeOnly,
const QLocale &locale) const;
+ bool isGregorian() const;
+
+ QCalendar::SystemId registerCustomBackend(const QStringList &names);
+
// Calendar enumeration by name:
static QStringList availableCalendars();
protected:
- QCalendarBackend(const QString &name, QCalendar::System system = QCalendar::System::User);
-
// Locale support:
virtual const QCalendarLocale *localeMonthIndexData() const = 0;
virtual const char16_t *localeMonthData() const = 0;
- bool registerAlias(const QString &name);
-
private:
- const QCalendar::SystemId m_id;
+ QCalendar::SystemId m_id;
+
+ void setIndex(size_t index);
+
// QCalendar's access to its registry:
static const QCalendarBackend *fromName(QAnyStringView name);
static const QCalendarBackend *fromId(QCalendar::SystemId id);
// QCalendar's access to singletons:
static const QCalendarBackend *fromEnum(QCalendar::System system);
+ static const QCalendarBackend *gregorian();
};
QT_END_NAMESPACE