aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-21 12:42:56 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-08-27 11:48:26 +0000
commit4dc3582a1ee332bf8b577bb974f29e7692df85e9 (patch)
tree396a0622c9b6887a2ab1fa5217a54246a9b5d9d9
parentc9a35639d43cfa0673675923415d57ff155ccd45 (diff)
QQuickTableView: rename to scheduleRebuildTable, and add rebuild options
Rebuilding the table from scratch whenever e.g the model adds a new row or column is slow and unnecessary. What happens is that we always rebuild the table from the origin, and continue load and unload edges until the loaded rows and columns overlaps with the viewport. This can be slow if you are e.g at row 1000 when you start to rebuild. Instead we can just start from current position in the viewport. So add some options to control what needs to be done. Note: This patch doesn't change any logic as it stands. But the options will be used in a subsequent patch. Change-Id: I9705dbae3a2c04e7e7189ec453756358a1b9fc14 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquicktableview.cpp34
-rw-r--r--src/quick/items/qquicktableview_p_p.h12
2 files changed, 32 insertions, 14 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 0a980bc01c..e1ec5aff75 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -932,6 +932,8 @@ void QQuickTableViewPrivate::beginRebuildTable()
Q_Q(QQuickTableView);
rebuildScheduled = false;
+ rebuildOptions = scheduledRebuildOptions;
+ scheduledRebuildOptions = RebuildOption::None;
if (loadRequest.isActive())
cancelLoadRequest();
@@ -1086,8 +1088,14 @@ void QQuickTableViewPrivate::drainReusePoolAfterLoadRequest()
tableModel->drainReusableItemsPool(maxTime);
}
-void QQuickTableViewPrivate::invalidateTable() {
+void QQuickTableViewPrivate::scheduleRebuildTable(RebuildOptions options) {
+ if (!q_func()->isComponentComplete()) {
+ // We'll rebuild the table once complete anyway
+ return;
+ }
+
rebuildScheduled = true;
+ scheduledRebuildOptions |= options;
q_func()->polish();
}
@@ -1261,7 +1269,7 @@ void QQuickTableViewPrivate::modelUpdated(const QQmlChangeSet &changeSet, bool r
Q_UNUSED(reset);
Q_TABLEVIEW_ASSERT(!model->abstractItemModel(), "");
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::rowsMovedCallback(const QModelIndex &parent, int, int, const QModelIndex &, int )
@@ -1269,7 +1277,7 @@ void QQuickTableViewPrivate::rowsMovedCallback(const QModelIndex &parent, int, i
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::columnsMovedCallback(const QModelIndex &parent, int, int, const QModelIndex &, int)
@@ -1277,7 +1285,7 @@ void QQuickTableViewPrivate::columnsMovedCallback(const QModelIndex &parent, int
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::rowsInsertedCallback(const QModelIndex &parent, int, int)
@@ -1285,7 +1293,7 @@ void QQuickTableViewPrivate::rowsInsertedCallback(const QModelIndex &parent, int
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::rowsRemovedCallback(const QModelIndex &parent, int, int)
@@ -1293,7 +1301,7 @@ void QQuickTableViewPrivate::rowsRemovedCallback(const QModelIndex &parent, int,
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::columnsInsertedCallback(const QModelIndex &parent, int, int)
@@ -1301,7 +1309,7 @@ void QQuickTableViewPrivate::columnsInsertedCallback(const QModelIndex &parent,
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::columnsRemovedCallback(const QModelIndex &parent, int, int)
@@ -1309,12 +1317,12 @@ void QQuickTableViewPrivate::columnsRemovedCallback(const QModelIndex &parent, i
if (parent != QModelIndex())
return;
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::ViewportOnly);
}
void QQuickTableViewPrivate::modelResetCallback()
{
- invalidateTable();
+ scheduleRebuildTable(RebuildOption::All);
}
bool QQuickTableViewPrivate::updatePolishIfPossible() const
@@ -1466,7 +1474,7 @@ void QQuickTableView::setRowHeightProvider(QJSValue provider)
return;
d->rowHeightProvider = provider;
- d->invalidateTable();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly);
emit rowHeightProviderChanged();
}
@@ -1482,7 +1490,7 @@ void QQuickTableView::setColumnWidthProvider(QJSValue provider)
return;
d->columnWidthProvider = provider;
- d->invalidateTable();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::ViewportOnly);
emit columnWidthProviderChanged();
}
@@ -1518,7 +1526,7 @@ void QQuickTableView::setModel(const QVariant &newModel)
}
d->connectToModel();
- d->invalidateTable();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::All);
emit modelChanged();
}
@@ -1541,7 +1549,7 @@ void QQuickTableView::setDelegate(QQmlComponent *newDelegate)
d->createWrapperModel();
d->tableModel->setDelegate(newDelegate);
- d->invalidateTable();
+ d->scheduleRebuildTable(QQuickTableViewPrivate::RebuildOption::All);
emit delegateChanged();
}
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h
index 7241fac7d3..81127adae4 100644
--- a/src/quick/items/qquicktableview_p_p.h
+++ b/src/quick/items/qquicktableview_p_p.h
@@ -175,6 +175,13 @@ public:
Done
};
+ enum class RebuildOption {
+ None = 0,
+ ViewportOnly = 0x1,
+ All = 0x2,
+ };
+ Q_DECLARE_FLAGS(RebuildOptions, RebuildOption)
+
public:
QQuickTableViewPrivate();
~QQuickTableViewPrivate() override;
@@ -209,6 +216,9 @@ public:
QSize tableSize;
RebuildState rebuildState = RebuildState::Done;
+ RebuildOptions rebuildOptions = RebuildOption::All;
+ RebuildOptions scheduledRebuildOptions = RebuildOption::All;
+
TableEdgeLoadRequest loadRequest;
QPoint contentSizeBenchMarkPoint = QPoint(-1, -1);
@@ -307,7 +317,7 @@ public:
void beginRebuildTable();
void layoutAfterLoadingInitialTable();
- void invalidateTable();
+ void scheduleRebuildTable(QQuickTableViewPrivate::RebuildOptions options);
void invalidateColumnRowPositions();
void createWrapperModel();