Warning, file /libraries/kopeninghours/src/qml/kopeninghoursqmlplugin.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 
0008 #include <KOpeningHours/Interval>
0009 #include <KOpeningHours/IntervalModel>
0010 #include <KOpeningHours/OpeningHours>
0011 
0012 #include <QCoreApplication>
0013 #include <QQmlEngine>
0014 #include <QQmlExtensionPlugin>
0015 
0016 class KOpeningHoursQmlPlugin : public QQmlExtensionPlugin
0017 {
0018     Q_OBJECT
0019     Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
0020 public:
0021     void registerTypes(const char* uri) override;
0022 };
0023 
0024 namespace KOpeningHours {
0025 class OpeningHoursFactory
0026 {
0027     Q_GADGET
0028 public:
0029     Q_INVOKABLE KOpeningHours::OpeningHours parse(const QString &expression, int modes = OpeningHours::IntervalMode) const;
0030 };
0031 
0032 OpeningHours OpeningHoursFactory::parse(const QString &expression, int modes) const
0033 {
0034     return OpeningHours(expression.toUtf8(), OpeningHours::Modes(modes));
0035 }
0036 
0037 }
0038 
0039 void KOpeningHoursQmlPlugin::registerTypes(const char*)
0040 {
0041     qRegisterMetaType<KOpeningHours::Interval>();
0042     qRegisterMetaType<KOpeningHours::OpeningHours>();
0043     qRegisterMetaType<KOpeningHours::OpeningHours::Modes>();
0044 
0045     qmlRegisterUncreatableType<KOpeningHours::Interval>("org.kde.kopeninghours", 1, 0, "Interval", {});
0046     qmlRegisterUncreatableType<KOpeningHours::OpeningHours>("org.kde.kopeninghours", 1, 0, "OpeningHours", {});
0047 
0048     qmlRegisterType<KOpeningHours::IntervalModel>("org.kde.kopeninghours", 1, 0, "IntervalModel");
0049 
0050     // HACK qmlplugindump chokes on gadget singletons, to the point of breaking ecm_find_qmlmodule()
0051     if (QCoreApplication::applicationName() != QLatin1String("qmlplugindump")) {
0052         qmlRegisterSingletonType("org.kde.kopeninghours", 1, 0, "OpeningHoursParser", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
0053             return engine->toScriptValue(KOpeningHours::OpeningHoursFactory());
0054         });
0055     }
0056 }
0057 
0058 #include "kopeninghoursqmlplugin.moc"