KHealthCertificate

khealthcertificateqmlplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include <KHealthCertificate>
8#include <KHealthCertificateParser>
9#include <KRecoveryCertificate>
10#include <KTestCertificate>
11#include <KVaccinationCertificate>
12
13#include <QCoreApplication>
14#include <QQmlEngine>
15#include <QQmlExtensionPlugin>
16
17class KHealthCertificateQmlPlugin : public QQmlExtensionPlugin
18{
20 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
21public:
22 void registerTypes(const char* uri) override;
23};
24
25
26class KHealthCertificateParserWrapper
27{
28 Q_GADGET
29public:
30 Q_INVOKABLE QVariant parse(const QVariant &data) const;
31};
32
33QVariant KHealthCertificateParserWrapper::parse(const QVariant &data) const
34{
35 if (data.userType() == QMetaType::QByteArray) {
37 }
38 if (data.userType() == QMetaType::QString) {
40 }
41 return {};
42}
43
44void KHealthCertificateQmlPlugin::registerTypes(const char*)
45{
46 qRegisterMetaType<KRecoveryCertificate>();
47 qRegisterMetaType<KTestCertificate>();
48 qRegisterMetaType<KVaccinationCertificate>();
49
50 qmlRegisterUncreatableMetaObject(KHealthCertificate::staticMetaObject, "org.kde.khealthcertificate", 1, 0, "HealthCertificate", {});
51 qmlRegisterUncreatableMetaObject(KTestCertificate::staticMetaObject, "org.kde.khealthcertificate", 1, 0, "TestCertificate", {});
52 qmlRegisterUncreatableMetaObject(KVaccinationCertificate::staticMetaObject, "org.kde.khealthcertificate", 1, 0, "VaccinationCertificate", {});
53
54 // HACK qmlplugindump chokes on gadget singletons, to the point of breaking ecm_find_qmlmodule()
55 if (QCoreApplication::applicationName() != QLatin1String("qmlplugindump")) {
56 qmlRegisterSingletonType("org.kde.khealthcertificate", 1, 0, "HealthCertificateParser", [](QQmlEngine*, QJSEngine *engine) -> QJSValue {
57 return engine->toScriptValue(KHealthCertificateParserWrapper());
58 });
59 }
60}
61
62#include "khealthcertificateqmlplugin.moc"
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Parse a single digital health certificate.
QJSValue toScriptValue(const T &value)
Q_OBJECTQ_OBJECT
QByteArray toUtf8() const const
QByteArray toByteArray() const const
QString toString() const const
int userType() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:51:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.