From 0b47e6ff8a89d114b00cd67629f884f6372b3814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Fri, 5 Apr 2024 12:38:47 +0200 Subject: [PATCH] feat(StatusQ/LeftJoinModel): Add init check on componentComplete Earier attempts to initialize proxy may fail bc left/right models may be not ready when they are set. It may lead to a situation where the model remains uninitialized and reporint 0 row count. --- ui/StatusQ/include/StatusQ/leftjoinmodel.h | 6 +++++- ui/StatusQ/src/leftjoinmodel.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ui/StatusQ/include/StatusQ/leftjoinmodel.h b/ui/StatusQ/include/StatusQ/leftjoinmodel.h index 43b656867a..8d96c2d257 100644 --- a/ui/StatusQ/include/StatusQ/leftjoinmodel.h +++ b/ui/StatusQ/include/StatusQ/leftjoinmodel.h @@ -2,8 +2,9 @@ #include #include +#include -class LeftJoinModel : public QAbstractListModel +class LeftJoinModel : public QAbstractListModel, public QQmlParserStatus { Q_OBJECT @@ -38,6 +39,9 @@ public: QHash roleNames() const override; QVariant data(const QModelIndex& index, int role) const override; + void classBegin() override; + void componentComplete() override; + signals: void leftModelChanged(); void rightModelChanged(); diff --git a/ui/StatusQ/src/leftjoinmodel.cpp b/ui/StatusQ/src/leftjoinmodel.cpp index 62db8a6c30..3617478068 100644 --- a/ui/StatusQ/src/leftjoinmodel.cpp +++ b/ui/StatusQ/src/leftjoinmodel.cpp @@ -271,6 +271,16 @@ QVariant LeftJoinModel::data(const QModelIndex& index, int role) const return match.first().data(role - m_rightModelRolesOffset); } +void LeftJoinModel::classBegin() +{ +} + +void LeftJoinModel::componentComplete() +{ + if (!m_initialized) + initializeIfReady(false); +} + void LeftJoinModel::setLeftModel(QAbstractItemModel* model) { if (m_leftModel == model)