mirror of
https://github.com/status-im/SortFilterProxyModel.git
synced 2025-02-21 15:18:08 +00:00
Check the roles after a row is added for a model with no roles intially
Fixes #13
This commit is contained in:
parent
edf53b56ef
commit
a3d95d2290
@ -194,6 +194,13 @@ bool QQmlSortFilterProxyModel::lessThan(const QModelIndex& source_left, const QM
|
||||
return source_left.row() < source_right.row();
|
||||
}
|
||||
|
||||
void QQmlSortFilterProxyModel::resetInternalData()
|
||||
{
|
||||
QSortFilterProxyModel::resetInternalData();
|
||||
if (roleNames().isEmpty()) // workaround for when a model has no roles and roles are added when the model is populated (ListModel)
|
||||
connect(this, &QAbstractItemModel::rowsAboutToBeInserted, this, &QQmlSortFilterProxyModel::initRoles);
|
||||
}
|
||||
|
||||
void QQmlSortFilterProxyModel::invalidateFilter()
|
||||
{
|
||||
if (m_completed)
|
||||
@ -231,6 +238,12 @@ void QQmlSortFilterProxyModel::updateRoles()
|
||||
updateSortRole();
|
||||
}
|
||||
|
||||
void QQmlSortFilterProxyModel::initRoles()
|
||||
{
|
||||
disconnect(this, &QAbstractItemModel::rowsAboutToBeInserted, this , &QQmlSortFilterProxyModel::initRoles);
|
||||
resetInternalData();
|
||||
}
|
||||
|
||||
QVariantMap QQmlSortFilterProxyModel::modelDataMap(const QModelIndex& modelIndex) const
|
||||
{
|
||||
QVariantMap map;
|
||||
|
@ -84,12 +84,16 @@ protected:
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
|
||||
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
|
||||
|
||||
protected Q_SLOTS:
|
||||
void resetInternalData();
|
||||
|
||||
private Q_SLOTS:
|
||||
void invalidateFilter();
|
||||
void invalidate();
|
||||
void updateFilterRole();
|
||||
void updateSortRole();
|
||||
void updateRoles();
|
||||
void initRoles();
|
||||
|
||||
private:
|
||||
QVariantMap modelDataMap(const QModelIndex& modelIndex) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user