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.
This commit is contained in:
Michał Cieślak 2024-04-05 12:38:47 +02:00 committed by Michał
parent 0c34325841
commit 0b47e6ff8a
2 changed files with 15 additions and 1 deletions

View File

@ -2,8 +2,9 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QPointer> #include <QPointer>
#include <QQmlParserStatus>
class LeftJoinModel : public QAbstractListModel class LeftJoinModel : public QAbstractListModel, public QQmlParserStatus
{ {
Q_OBJECT Q_OBJECT
@ -38,6 +39,9 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex& index, int role) const override; QVariant data(const QModelIndex& index, int role) const override;
void classBegin() override;
void componentComplete() override;
signals: signals:
void leftModelChanged(); void leftModelChanged();
void rightModelChanged(); void rightModelChanged();

View File

@ -271,6 +271,16 @@ QVariant LeftJoinModel::data(const QModelIndex& index, int role) const
return match.first().data(role - m_rightModelRolesOffset); return match.first().data(role - m_rightModelRolesOffset);
} }
void LeftJoinModel::classBegin()
{
}
void LeftJoinModel::componentComplete()
{
if (!m_initialized)
initializeIfReady(false);
}
void LeftJoinModel::setLeftModel(QAbstractItemModel* model) void LeftJoinModel::setLeftModel(QAbstractItemModel* model)
{ {
if (m_leftModel == model) if (m_leftModel == model)