mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-27 06:33:08 +00:00
halcyon/pinnedmodel: build singleton type using static method
This commit is contained in:
parent
8b5ec57d0b
commit
ed87f57938
3 changed files with 9 additions and 3 deletions
|
|
@ -18,9 +18,8 @@ void HalcyonPlugin::registerTypes(const char *uri)
|
||||||
return ApplicationListModel::self();
|
return ApplicationListModel::self();
|
||||||
});
|
});
|
||||||
|
|
||||||
PinnedModel *pinnedModel = new PinnedModel{this};
|
qmlRegisterSingletonType<PinnedModel>(uri, 1, 0, "PinnedModel", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||||
qmlRegisterSingletonType<PinnedModel>(uri, 1, 0, "PinnedModel", [pinnedModel](QQmlEngine *, QJSEngine *) -> QObject * {
|
return PinnedModel::self();
|
||||||
return pinnedModel;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
qmlRegisterType<Application>(uri, 1, 0, "Application");
|
qmlRegisterType<Application>(uri, 1, 0, "Application");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@ PinnedModel::PinnedModel(QObject *parent)
|
||||||
|
|
||||||
PinnedModel::~PinnedModel() = default;
|
PinnedModel::~PinnedModel() = default;
|
||||||
|
|
||||||
|
PinnedModel *PinnedModel::self()
|
||||||
|
{
|
||||||
|
static PinnedModel *inst = new PinnedModel();
|
||||||
|
return inst;
|
||||||
|
}
|
||||||
|
|
||||||
int PinnedModel::rowCount(const QModelIndex &parent) const
|
int PinnedModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return m_applications.count();
|
return m_applications.count();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ public:
|
||||||
|
|
||||||
PinnedModel(QObject *parent = nullptr);
|
PinnedModel(QObject *parent = nullptr);
|
||||||
~PinnedModel() override;
|
~PinnedModel() override;
|
||||||
|
static PinnedModel *self();
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue