From a5d2fb468cabff8dc0702c7ddcd9f5b08993b827 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 12 Apr 2018 13:02:30 +0200 Subject: QQmlAdaptorModel: support dataChanged signals from multi-column models When receiving a signal that model items have changed, the current implementation assumed that the underlying QAIM only had one column. This patch will check how many columns actually changed, and make sure we call itemsChanged for them all. Change-Id: I05f301dee604f2675ec7e89dfbca28b6f956d483 Reviewed-by: J-P Nurmi --- src/qml/types/qqmldelegatemodel.cpp | 11 +++++++++-- src/qml/util/qqmladaptormodel.cpp | 5 +++++ src/qml/util/qqmladaptormodel_p.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/qml') diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 29e0baa3ac..27a84bc2f1 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1709,8 +1709,15 @@ void QQmlDelegateModel::_q_rowsMoved( void QQmlDelegateModel::_q_dataChanged(const QModelIndex &begin, const QModelIndex &end, const QVector &roles) { Q_D(QQmlDelegateModel); - if (begin.parent() == d->m_adaptorModel.rootIndex) - _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, roles); + if (begin.parent() != d->m_adaptorModel.rootIndex) + return; + + int rowCount = end.row() - begin.row() + 1; + + for (int col = begin.column(); col <= end.column(); ++col) { + int startIndex = d->m_adaptorModel.indexAt(begin.row(), col); + _q_itemsChanged(startIndex, rowCount, roles); + } } bool QQmlDelegateModel::isDescendantOf(const QPersistentModelIndex& desc, const QList< QPersistentModelIndex >& parents) const diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp index 1cc347d6bc..f754e0e1a5 100644 --- a/src/qml/util/qqmladaptormodel.cpp +++ b/src/qml/util/qqmladaptormodel.cpp @@ -1034,6 +1034,11 @@ int QQmlAdaptorModel::columnAt(int index) const return count <= 0 ? -1 : index / count; } +int QQmlAdaptorModel::indexAt(int row, int column) const +{ + return row + (column * rowCount()); +} + void QQmlAdaptorModel::objectDestroyed(QObject *) { setModel(QVariant(), nullptr, nullptr); diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h index d3b26a1ad5..82a4ebfcf6 100644 --- a/src/qml/util/qqmladaptormodel_p.h +++ b/src/qml/util/qqmladaptormodel_p.h @@ -125,6 +125,7 @@ public: int columnCount() const; int rowAt(int index) const; int columnAt(int index) const; + int indexAt(int row, int column) const; inline QAbstractItemModel *aim() { return static_cast(object()); } inline const QAbstractItemModel *aim() const { return static_cast(object()); } -- cgit v1.2.3