Commit f310fdbc authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Register singletons as types rather than context properties

The use of global ContextProperties is discouraged (and has been for a
while) and is being phased out because of performance concerns.
parent 92422fb4
......@@ -29,15 +29,6 @@
#include <resources/ResourcesUpdatesModel.h>
#include <resources/SourcesModel.h>
void DiscoverDeclarativePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
engine->rootContext()->setContextProperty(QStringLiteral("ResourcesModel"), ResourcesModel::global());
engine->rootContext()->setContextProperty(QStringLiteral("TransactionModel"), TransactionModel::global());
engine->rootContext()->setContextProperty(QStringLiteral("SourcesModel"), SourcesModel::global());
engine->rootContext()->setContextProperty(QStringLiteral("CategoryModel"), CategoryModel::global());
QQmlExtensionPlugin::initializeEngine(engine, uri);
}
void DiscoverDeclarativePlugin::registerTypes(const char * /*uri*/)
{
qmlRegisterType<TransactionListener>("org.kde.discover", 2, 0, "TransactionListener");
......@@ -63,5 +54,10 @@ void DiscoverDeclarativePlugin::registerTypes(const char * /*uri*/)
qmlRegisterAnonymousType<AbstractReviewsBackend>("org.kde.discover", 1);
qmlRegisterAnonymousType<Category>("org.kde.discover", 1);
qmlRegisterAnonymousType<ResourcesModel>("org.kde.discover", 1);
qmlRegisterSingletonInstance("org.kde.discover", 2, 0, "CategoryModel", CategoryModel::global());
qmlRegisterSingletonInstance("org.kde.discover", 2, 0, "ResourcesModel", ResourcesModel::global());
qmlRegisterSingletonInstance("org.kde.discover", 2, 0, "TransactionModel", TransactionModel::global());
qmlRegisterSingletonInstance("org.kde.discover", 2, 0, "SourcesModel", SourcesModel::global());
qmlProtectModule("org.kde.discover", 2);
}
......@@ -14,7 +14,6 @@ class DiscoverDeclarativePlugin : public QQmlExtensionPlugin
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void initializeEngine(QQmlEngine *engine, const char *uri) override;
void registerTypes(const char *uri) override;
};
......
......@@ -10,6 +10,7 @@ import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.1
import "navigation.js" as Navigation
import org.kde.discover 2.0
import org.kde.kirigami 2.14 as Kirigami
Kirigami.AbstractCard
......
import org.kde.kirigami 2.14 as Kirigami
import org.kde.userfeedback 1.0 as UserFeedback
import org.kde.kquickcontrolsaddons 2.0 as KQCA
import org.kde.discover 2.0
import org.kde.discover.app 1.0
import QtQml 2.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment