From 348d7821cc3b38f618a35ae9b8323e52b2ce240a Mon Sep 17 00:00:00 2001 From: Yari Polla Date: Mon, 6 Mar 2023 02:11:58 +0100 Subject: [PATCH] halcyon: use static method to register object --- .../homescreens/halcyon/plugin/applicationlistmodel.cpp | 6 ++++++ .../homescreens/halcyon/plugin/applicationlistmodel.h | 1 + containments/homescreens/halcyon/plugin/halcyonplugin.cpp | 5 ++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp b/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp index b794251f..bca016e5 100644 --- a/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp +++ b/containments/homescreens/halcyon/plugin/applicationlistmodel.cpp @@ -30,6 +30,12 @@ ApplicationListModel::ApplicationListModel(QObject *parent) ApplicationListModel::~ApplicationListModel() = default; +ApplicationListModel *ApplicationListModel::self() +{ + static ApplicationListModel *inst = new ApplicationListModel(nullptr); + return inst; +} + QHash ApplicationListModel::roleNames() const { return {{ApplicationRole, QByteArrayLiteral("application")}}; diff --git a/containments/homescreens/halcyon/plugin/applicationlistmodel.h b/containments/homescreens/halcyon/plugin/applicationlistmodel.h index 13f95e2b..ea27988f 100644 --- a/containments/homescreens/halcyon/plugin/applicationlistmodel.h +++ b/containments/homescreens/halcyon/plugin/applicationlistmodel.h @@ -24,6 +24,7 @@ public: ApplicationListModel(QObject *parent = nullptr); ~ApplicationListModel() override; + static ApplicationListModel *self(); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; diff --git a/containments/homescreens/halcyon/plugin/halcyonplugin.cpp b/containments/homescreens/halcyon/plugin/halcyonplugin.cpp index e2df70ad..409af31f 100644 --- a/containments/homescreens/halcyon/plugin/halcyonplugin.cpp +++ b/containments/homescreens/halcyon/plugin/halcyonplugin.cpp @@ -14,9 +14,8 @@ void HalcyonPlugin::registerTypes(const char *uri) WindowListener::instance(); // ensure it is created - ApplicationListModel *applicationListModel = new ApplicationListModel{this}; - qmlRegisterSingletonType(uri, 1, 0, "ApplicationListModel", [applicationListModel](QQmlEngine *, QJSEngine *) -> QObject * { - return applicationListModel; + qmlRegisterSingletonType(uri, 1, 0, "ApplicationListModel", [](QQmlEngine *, QJSEngine *) -> QObject * { + return ApplicationListModel::self(); }); PinnedModel *pinnedModel = new PinnedModel{this};