on xenial help sign in
simplify plugin registration
9ce048eLukáš Tinkl
plugins/Wizard/plugin.cpp+2−16
@@ -23,26 +23,12 @@
23
23
24#include <QtQml/qqml.h>
24#include <QtQml/qqml.h>
25
25
26−static QObject *system_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
27−{
28− Q_UNUSED(engine)
29− Q_UNUSED(scriptEngine)
30− return new System();
31−}
32−
33−static QObject *status_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
34−{
35− Q_UNUSED(engine)
36− Q_UNUSED(scriptEngine)
37− return new Status();
38−}
39−
40void WizardPlugin::registerTypes(const char *uri)
26void WizardPlugin::registerTypes(const char *uri)
41{
27{
42 Q_ASSERT(uri == QLatin1String("Wizard"));
28 Q_ASSERT(uri == QLatin1String("Wizard"));
43 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
29 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
44− qmlRegisterSingletonType<System>(uri, 0, 1, "System", system_provider);
30+ qmlRegisterSingletonType<System>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new System; });
45− qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", status_provider);
31+ qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
46 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
32 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
47 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
33 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
48 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
34 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
plugins/Wizard/plugin.h+1−2
@@ -17,13 +17,12 @@
17#ifndef WIZARD_PLUGIN_H
17#ifndef WIZARD_PLUGIN_H
18#define WIZARD_PLUGIN_H
18#define WIZARD_PLUGIN_H
19
19
20−#include <QtQml/QQmlEngine>
21#include <QtQml/QQmlExtensionPlugin>
20#include <QtQml/QQmlExtensionPlugin>
22
21
23class WizardPlugin : public QQmlExtensionPlugin
22class WizardPlugin : public QQmlExtensionPlugin
24{
23{
25 Q_OBJECT
24 Q_OBJECT
26− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
25+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
27
26
28public:
27public:
29 void registerTypes(const char *uri) override;
28 void registerTypes(const char *uri) override;
tests/mocks/Wizard/mockplugin.cpp+2−16
@@ -23,26 +23,12 @@
23
23
24#include <QtQml/qqml.h>
24#include <QtQml/qqml.h>
25
25
26−static QObject *system_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
27−{
28− Q_UNUSED(engine)
29− Q_UNUSED(scriptEngine)
30− return new MockSystem();
31−}
32−
33−static QObject *status_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
34−{
35− Q_UNUSED(engine)
36− Q_UNUSED(scriptEngine)
37− return new Status();
38−}
39−
40void MockWizardPlugin::registerTypes(const char *uri)
26void MockWizardPlugin::registerTypes(const char *uri)
41{
27{
42 Q_ASSERT(uri == QLatin1String("Wizard"));
28 Q_ASSERT(uri == QLatin1String("Wizard"));
43 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
29 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
44− qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", system_provider);
30+ qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new MockSystem; });
45− qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", status_provider);
31+ qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
46 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
32 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
47 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
33 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
48 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
34 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");