diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-09-12 09:33:47 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-09-13 04:57:01 +0000 |
commit | 00afb51baaf0b0398ba7780dec491cf144dad0d9 (patch) | |
tree | 231bc76a2c1726aaa1edd184274cdce48fea625a /src/quick/items/qquicktableview_p_p.h | |
parent | 22a5630d3c97709b09412dc1037d7dae959bdae5 (diff) |
QQuickTableView: sync model and delegate when ready to do so
Doing (silly) things in the delegate, like:
Component.onCompleted: TableView.view.delegate = null
will lead to a crash. The same if you change the model.
The reason is that you end up changing the model
while e.g a row is half-way loaded. Information needed for
building the row, like model size, will then be invalid.
To protect against this, we insert a "sync" phase to the
code that takes any such changes into effect at a time
when we know it's safe to do so.
Change-Id: I85a992dfc0e04ec6635b10c9768a8ddc140e09da
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview_p_p.h')
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 9ff2b2e10b..6bf3de76df 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -206,6 +206,11 @@ public: QPointer<QQmlTableInstanceModel> tableModel = nullptr; QVariant modelVariant; + // When the applications assignes a new model or delegate to the view, we keep them + // around until we're ready to take them into use (syncWithPendingChanges). + QVariant assignedModel = QVariant(int(0)); + QQmlComponent *assignedDelegate = nullptr; + // loadedTable describes the table cells that are currently loaded (from top left // row/column to bottom right row/column). loadedTableOuterRect describes the actual // pixels that those cells cover, and is matched agains the viewport to determine when @@ -332,6 +337,11 @@ public: void itemReusedCallback(int modelIndex, QObject *object); void modelUpdated(const QQmlChangeSet &changeSet, bool reset); + inline void syncWithPendingChanges(); + inline void syncDelegate(); + inline void syncModel(); + inline void syncRebuildOptions(); + void connectToModel(); void disconnectFromModel(); |