KOpeningHours

kopeninghoursqmlplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include <KOpeningHours/Display>
8#include <KOpeningHours/Interval>
9#include <KOpeningHours/IntervalModel>
10#include <KOpeningHours/OpeningHours>
11
12#include <QCoreApplication>
13#include <QQmlEngine>
14#include <QQmlExtensionPlugin>
15
16class KOpeningHoursQmlPlugin : public QQmlExtensionPlugin
17{
19 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
20public:
21 void registerTypes(const char* uri) override;
22};
23
24namespace KOpeningHours {
25class OpeningHoursFactory
26{
27 Q_GADGET
28public:
29 Q_INVOKABLE KOpeningHours::OpeningHours parse(const QString &expression, int modes = OpeningHours::IntervalMode) const;
30};
31
32OpeningHours OpeningHoursFactory::parse(const QString &expression, int modes) const
33{
34 return OpeningHours(expression.toUtf8(), OpeningHours::Modes(modes));
35}
36
37}
38
39void KOpeningHoursQmlPlugin::registerTypes(const char*)
40{
41 qRegisterMetaType<KOpeningHours::Interval>();
42 qRegisterMetaType<KOpeningHours::OpeningHours>();
43 qRegisterMetaType<KOpeningHours::OpeningHours::Modes>();
44
45 qmlRegisterUncreatableMetaObject(KOpeningHours::Interval::staticMetaObject, "org.kde.kopeninghours", 1, 0, "Interval", {});
46 qmlRegisterUncreatableMetaObject(KOpeningHours::OpeningHours::staticMetaObject, "org.kde.kopeninghours", 1, 0, "OpeningHours", {});
47
48 qmlRegisterType<KOpeningHours::IntervalModel>("org.kde.kopeninghours", 1, 0, "IntervalModel");
49
50 // HACK qmlplugindump chokes on gadget singletons, to the point of breaking ecm_find_qmlmodule()
51 if (QCoreApplication::applicationName() != QLatin1String("qmlplugindump")) {
52 qmlRegisterSingletonType("org.kde.kopeninghours", 1, 0, "OpeningHoursParser", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
53 return engine->toScriptValue(KOpeningHours::OpeningHoursFactory());
54 });
55 qmlRegisterSingletonType("org.kde.kopeninghours", 1, 0, "Display", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
56 return engine->toScriptValue(KOpeningHours::Display());
57 });
58 }
59}
60
61#include "kopeninghoursqmlplugin.moc"
Utilities for displaying human-readable/localized opening hours information.
Definition display.h:22
An OSM opening hours specification.
@ IntervalMode
Expressions that describe time ranges.
OSM opening hours parsing and evaluation.
Definition display.h:16
QJSValue toScriptValue(const T &value)
Q_OBJECTQ_OBJECT
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:55:59 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.