on xenial help sign in
simplify plugin registration
commit9ce048ebcf00c29bc0010477b6c0e18d802035a1 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 10 Sep 2015, 01:51 (11 years ago) parent2ef0d41
3 files changed+5−34
plugins/Wizard/plugin.cpp+2−16 plugins/Wizard/plugin.h+1−2 tests/mocks/Wizard/mockplugin.cpp+2−16
plugins/Wizard/plugin.cpp+2−16
@@ -23,26 +23,12 @@
2323
2424#include <QtQml/qqml.h>
2525
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−
4026void WizardPlugin::registerTypes(const char *uri)
4127{
4228 Q_ASSERT(uri == QLatin1String("Wizard"));
4329 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
44− qmlRegisterSingletonType<System>(uri, 0, 1, "System", system_provider);
45− qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", status_provider);
30+ qmlRegisterSingletonType<System>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new System; });
31+ qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
4632 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
4733 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
4834 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");
plugins/Wizard/plugin.h+1−2
@@ -17,13 +17,12 @@
1717#ifndef WIZARD_PLUGIN_H
1818#define WIZARD_PLUGIN_H
1919
20−#include <QtQml/QQmlEngine>
2120#include <QtQml/QQmlExtensionPlugin>
2221
2322class WizardPlugin : public QQmlExtensionPlugin
2423{
2524 Q_OBJECT
26− Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
25+ Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
2726
2827public:
2928 void registerTypes(const char *uri) override;
tests/mocks/Wizard/mockplugin.cpp+2−16
@@ -23,26 +23,12 @@
2323
2424#include <QtQml/qqml.h>
2525
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−
4026void MockWizardPlugin::registerTypes(const char *uri)
4127{
4228 Q_ASSERT(uri == QLatin1String("Wizard"));
4329 qmlRegisterType<PageList>(uri, 0, 1, "PageList");
44− qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", system_provider);
45− qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", status_provider);
30+ qmlRegisterSingletonType<MockSystem>(uri, 0, 1, "System", [](QQmlEngine*, QJSEngine*) -> QObject* { return new MockSystem; });
31+ qmlRegisterSingletonType<Status>(uri, 0, 1, "Status", [](QQmlEngine*, QJSEngine*) -> QObject* { return new Status; });
4632 qmlRegisterType<TimeZoneModel>(uri, 0, 1, "TimeZoneModel");
4733 qmlRegisterType<TimeZoneFilterModel>(uri, 0, 1, "TimeZoneFilterModel");
4834 qmlRegisterType<LocalePlugin>(uri, 0, 1, "LocalePlugin");