diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-09-11 14:01:58 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-09-15 20:07:59 +0200 |
| commit | a5ad373e6e19909a814a813daafd8402cf5153bd (patch) | |
| tree | b9760ad7dc05940564f9de4fb165416f7e12a030 /src/quick/items/qquicktableview.cpp | |
| parent | 7105eb6d0d46949e235d213cfe77dda95f16c6c5 (diff) | |
QQuickTableView: Expose internal model changes via the model property
If the delegate changes the model, those changes need to be visible in
the "model" property of the view. To this end, use
QQmlTableInstanceModel's model variant instead of the assigned one once
it has been synchronized.
The inner change signaling from the delegates to the view will be
added in a separate change.
Pick-to: 6.10
Task-number: QTBUG-139941
Change-Id: I1296fa2c886dad063b6b39defef56cb7faf1e943
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
| -rw-r--r-- | src/quick/items/qquicktableview.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 6c8ace80e6..56e5819080 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -4573,12 +4573,17 @@ void QQuickTableViewPrivate::syncDelegateModelAccess() QVariant QQuickTableViewPrivate::modelImpl() const { - return assignedModel; + if (needsModelSynchronization) + return assignedModel; + if (tableModel) + return tableModel->model(); + return QVariant::fromValue(model); } void QQuickTableViewPrivate::setModelImpl(const QVariant &newModel) { assignedModel = newModel; + needsModelSynchronization = true; scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::All); emit q_func()->modelChanged(); } @@ -4612,6 +4617,7 @@ void QQuickTableViewPrivate::syncModel() tableModel->setModel(assignedModel); } + needsModelSynchronization = false; connectToModel(); } @@ -4748,6 +4754,11 @@ void QQuickTableViewPrivate::connectToModel() } else { QObjectPrivate::connect(model, &QQmlInstanceModel::modelUpdated, this, &QQuickTableViewPrivate::modelUpdated); } + + if (tableModel) { + QObject::connect(tableModel, &QQmlTableInstanceModel::modelChanged, + q, &QQuickTableView::modelChanged); + } } void QQuickTableViewPrivate::disconnectFromModel() @@ -4774,6 +4785,11 @@ void QQuickTableViewPrivate::disconnectFromModel() } else { QObjectPrivate::disconnect(model, &QQmlInstanceModel::modelUpdated, this, &QQuickTableViewPrivate::modelUpdated); } + + if (tableModel) { + QObject::disconnect(tableModel, &QQmlTableInstanceModel::modelChanged, + q, &QQuickTableView::modelChanged); + } } void QQuickTableViewPrivate::modelUpdated(const QQmlChangeSet &changeSet, bool reset) |
