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/OpeningHours>
10
11#include <QCoreApplication>
12#include <QQmlEngine>
13#include <QQmlExtensionPlugin>
14
15class KOpeningHoursQmlPlugin : public QQmlExtensionPlugin
16{
18 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
19public:
20 void registerTypes(const char* uri) override;
21};
22
23namespace KOpeningHours {
24class OpeningHoursFactory
25{
26 Q_GADGET
27public:
28 Q_INVOKABLE KOpeningHours::OpeningHours parse(const QString &expression, int modes = OpeningHours::IntervalMode) const;
29};
30
31OpeningHours OpeningHoursFactory::parse(const QString &expression, int modes) const
32{
33 return OpeningHours(expression.toUtf8(), OpeningHours::Modes(modes));
34}
35
36}
37
38void KOpeningHoursQmlPlugin::registerTypes(const char*)
39{
40 // HACK qmlplugindump chokes on gadget singletons, to the point of breaking ecm_find_qmlmodule()
41 if (QCoreApplication::applicationName() != QLatin1String("qmlplugindump")) {
42 qmlRegisterSingletonType("org.kde.kopeninghours", 1, 0, "OpeningHoursParser", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
43 return engine->toScriptValue(KOpeningHours::OpeningHoursFactory());
44 });
45 qmlRegisterSingletonType("org.kde.kopeninghours", 1, 0, "Display", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
46 return engine->toScriptValue(KOpeningHours::Display());
47 });
48 }
49}
50
51#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 Oct 11 2024 12:20:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.