From 2b8d6ef2a469ef1d025f80d9ae3044e21faa983a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 22 Oct 2015 16:14:27 +0200 Subject: Make it possible to set a new emitter on the listresultmodel --- common/listmodelresult.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'common/listmodelresult.h') diff --git a/common/listmodelresult.h b/common/listmodelresult.h index 62d1c4e..a095c2a 100644 --- a/common/listmodelresult.h +++ b/common/listmodelresult.h @@ -22,7 +22,7 @@ #include #include -#include "common/resultprovider.h" +#include "resultprovider.h" enum Roles { DomainObjectRole = Qt::UserRole + 1 @@ -33,11 +33,24 @@ class ListModelResult : public QAbstractListModel { public: + ListModelResult(const QList &propertyColumns) + :QAbstractListModel(), + mPropertyColumns(propertyColumns) + { + } + ListModelResult(const QSharedPointer > &emitter, const QList &propertyColumns) :QAbstractListModel(), - mEmitter(emitter), mPropertyColumns(propertyColumns) { + setEmitter(emitter); + } + + void setEmitter(const QSharedPointer > &emitter) + { + beginResetModel(); + mEntities.clear(); + mEmitter = emitter; emitter->onAdded([this](const T &value) { const auto keys = mEntities.keys(); int index = 0; @@ -73,6 +86,7 @@ public: mEntities.clear(); endResetModel(); }); + endResetModel(); } int rowCount(const QModelIndex &parent = QModelIndex()) const @@ -85,7 +99,7 @@ public: return mPropertyColumns.size(); } - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const { if (index.row() >= mEntities.size()) { qWarning() << "Out of bounds access"; -- cgit v1.2.3