diff options
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 9f259166df..f8f56557ae 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -1593,21 +1593,22 @@ void QQuickTableViewPrivate::forceLayout() const QSize actualTableSize = calculateTableSize(); if (tableSize != actualTableSize) { - // This can happen if the app is calling forceLayout while - // the model is updated, but before we're notified about it. - rebuildOptions = RebuildOption::All; - } else { - // Resizing a column (or row) can result in the table going from being - // e.g completely inside the viewport to go outside. And in the latter - // case, the user needs to be able to scroll the viewport, also if - // flags such as Flickable.StopAtBounds is in use. So we need to - // update contentWidth/Height to support that case. - rebuildOptions = RebuildOption::LayoutOnly - | RebuildOption::CalculateNewContentWidth - | RebuildOption::CalculateNewContentHeight - | checkForVisibilityChanges(); + // The table size will have changed if forceLayout is called after + // the row count in the model has changed, but before we received + // a rowsInsertedCallback about it (and vice versa for columns). + rebuildOptions |= RebuildOption::ViewportOnly; } + // Resizing a column (or row) can result in the table going from being + // e.g completely inside the viewport to go outside. And in the latter + // case, the user needs to be able to scroll the viewport, also if + // flags such as Flickable.StopAtBounds is in use. So we need to + // update contentWidth/Height to support that case. + rebuildOptions |= RebuildOption::LayoutOnly + | RebuildOption::CalculateNewContentWidth + | RebuildOption::CalculateNewContentHeight + | checkForVisibilityChanges(); + scheduleRebuildTable(rebuildOptions); auto rootView = rootSyncView(); @@ -3232,9 +3233,6 @@ QVariant QQuickTableViewPrivate::modelImpl() const void QQuickTableViewPrivate::setModelImpl(const QVariant &newModel) { - if (newModel == assignedModel) - return; - assignedModel = newModel; scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::All); emit q_func()->modelChanged(); @@ -3242,7 +3240,7 @@ void QQuickTableViewPrivate::setModelImpl(const QVariant &newModel) void QQuickTableViewPrivate::syncModel() { - if (modelVariant == assignedModel) + if (compareModel(modelVariant, assignedModel)) return; if (model) { @@ -3498,6 +3496,13 @@ void QQuickTableViewPrivate::modelResetCallback() scheduleRebuildTable(RebuildOption::All); } +bool QQuickTableViewPrivate::compareModel(const QVariant& model1, const QVariant& model2) const +{ + return (model1 == model2 || + (model1.userType() == qMetaTypeId<QJSValue>() && model2.userType() == qMetaTypeId<QJSValue>() && + model1.value<QJSValue>().strictlyEquals(model2.value<QJSValue>()))); +} + void QQuickTableViewPrivate::scheduleRebuildIfFastFlick() { Q_Q(QQuickTableView); @@ -3727,6 +3732,9 @@ QVariant QQuickTableView::model() const void QQuickTableView::setModel(const QVariant &newModel) { + if (d_func()->compareModel(newModel, d_func()->assignedModel)) + return; + return d_func()->setModelImpl(newModel); } |