Commit Graph

104 Commits

Author SHA1 Message Date
Richard Moe Gustavsen adfff7ec77 TableView: allow negative spacing
There is no apparent reason why negative spacing should not be allowed.
And in fact, you can use negative spacing to eliminate double edges
in the grid when the delegate is e.g a rectangle with a border.

Fixes: QTBUG-83956
Pick-to: 5.15
Change-Id: I3be9d58ac8c43142e26e75165274e41872e878f4
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2020-05-07 13:25:13 +02:00
Richard Moe Gustavsen 654959e2e2 QQuickTableView: add functions to get current rows and columns
This API can be used to query and iterate the currently loaded
rows and columns inside the view.

[ChangeLog][QtQuick][TableView] Added the properties leftColumn,
rightColumn, topRow, and bottomRow, which can be used to query
which part of the model is currently visible inside the view.

Change-Id: I06f99cc1e8da1004dc8614977f149192e1880ba4
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-09 18:32:15 +02:00
Richard Moe Gustavsen 4822e96d14 QQuickTableView: add cellAtPos() functions
[ChangeLog][QtQuick][TableView] cellAtPos(x, y) has been added to
query which cell is under the given position.

Change-Id: I69523868158b589ea3bb9facba815000d2a058d7
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-09 18:31:13 +02:00
Richard Moe Gustavsen f296c30061 QQuickTableView: add function: itemAtCell(const QPoint)
Add a function to the API to let the application get
the item loaded for a specific cell.

[ChangeLog][TableView] A function 'itemAtCell()' has now
been added to let the application get the delegate
item loaded for a specific cell.

Change-Id: Ie84ef44ea2a0a901487812c4d611b98d4c86ee22
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-08 15:57:16 +02:00
Richard Moe Gustavsen be12b71fae QQuickTableView: add positionViewAtRow()/Column()
Add functions to let the application scroll the table to a
specific row or column using a specific mode. This API
partially mirrors the API found in ListView.

[ChangeLog][QtQuick][TableView] positionViewAtCell(), positionViewAtRow(), and
positionViewAtColumn() have been added to enable the application to position
the contents to show a specific cell.

Fixes: QTBUG-83215
Change-Id: I321588041977f9ded40f84fc0499ea1c5f6ac801
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2020-04-08 15:57:11 +02:00
Tor Arne Vestbø a5df29201f CMake: Update Apple platform defines after rename in qtbase
Change-Id: Ia0a075e3199eab735f9b289873beeb8730ebc47e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2020-03-17 10:42:00 +01:00
Alexandru Croitor 1d4fa26a70 Regenerate qtdeclarative
Change-Id: I48d7fd306f3d1b161a8e73029282ee591b1ef612
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
2020-02-12 17:30:34 +00:00
Alexandru Croitor 12f0381a34 Regenerate tests
Change-Id: I8b685745f0c7bf42904f7e8fca34ba14097f4686
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2020-01-29 15:38:42 +00:00
Leander Beernaert 1d333d3375 Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I0c5b939c70bdb91ccdf7068784308416dcaa5736
2020-01-16 16:25:06 +01:00
Qt Forward Merge Bot 9dee7b331c Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: Iadbdd0fb63ca2a9e0b186343f8b730e4114cd71b
2019-12-10 01:01:06 +01:00
Richard Moe Gustavsen e1cc06972a QQuickTableView: set empty content size when table is empty
From before we would bail out early from the rebuild process if we
detected an empty table. A result from this is that we left
both contentWidth and contentHeight unchanged.

This patch will set an empty content size when the table is
empty. The effect will be that the user cannot flick the view
around based on the old size.

Fixes: QTBUG-80505
Change-Id: I3ac080476269fd5906ce79fa007eabb59b5ff4b1
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2019-12-09 14:16:07 +01:00
Richard Moe Gustavsen f60f2aaa51 QQuickTableView: ensure we release items in the old model and not the new
As it stood, we would wait to release loaded items until we started the
rebuild process, if the old model was a DelegateModel. But at that time,
the model would alread have been changed, so we would release the items
by calling out to the wrong model.

This patch will ensure that we always release the items immediately when
syncing the model, which will also cover the case when the model is a
DelegateModel.

Fixes: QTBUG-80570
Change-Id: I1b06011f4795727d04d9cd8c20381f65552b8fe8
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-12-09 14:16:07 +01:00
Richard Moe Gustavsen 6bc4d55fe1 QQuickTableView: support assigning a DelegateModel
Normally you either assign a model to TableView that
already has a delegate (or don't need one), like
DelegateModel or ObjectModel. Or instead you assign
a QAIM model and a delegate directly. But if you
assign both a delegate and an ObjectModel, TableView
would be confused, and ignore the assigned model
and instead create an internal wrapper model that
ends up empty.

This patch will ensure that we don't create a wrapper
model in such cases, but instead forward the
delegate to whichever model is assigned, even
if it ends up as a no-op for models that don't
use one.

Task-number: QTBUG-80534
Change-Id: Idd220df08617c379dc7808ee1f41c862b78cc201
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-12-09 14:16:07 +01:00
Richard Moe Gustavsen 3770696ce5 tst_qquicktableview: ensure test checks for correct error message
Change 631ef67458 fixed a bug that wrote a wrong error message
to the console. But there is a test that checks for that message
that was also wrong (but for some reason the test passed in the CI,
but it has started to fail locally).

This patch will ensure that the test don't fail because we check
for a wrong error message.

Change-Id: I27e16b0f4aa6a0ffeb8c42f846c344436a41ad3c
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-12-09 14:16:07 +01:00
Qt Forward Merge Bot 88490da44e Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
	tests/auto/quick/qquicktableview/tst_qquicktableview.cpp

Change-Id: Ib46bc1c717cf524eea2fb3d876810c8d55747c91
2019-12-05 10:09:17 +01:00
Ulf Hermann 41dd68344c QQuickTableView: Clear items before deleting the model
Fixes: QTBUG-71374
Change-Id: I534b7612268bb9407844961267865f490d7ff7b2
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2019-12-04 14:08:47 +01:00
Richard Moe Gustavsen c28ec259b7 tst_qquicktableview: fix warning about missing JS function
Change 35fdf3a7b7 added a binding to a function in one of
the QML files used for testing (plaintableview.qml). The
problem is that this file is also used from other places
where we wrap a QSharedPointer that points to the model
inside a QVariant. And when assigning that variant to
a TableView, the QML binding will see the QSharedPointer, and
not the model it points to. And hence complain that the
model doesn't have the API that is exported from the
model.

The easy fix is to just create a new QML file for the
new test added, that has the binding, but assigns
a QVariant that wraps the model directly without
usign a QSharedPointer.

Change-Id: Ic2b77426c2d700479a9b5f4007384661e2ca0801
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-12-04 13:55:31 +01:00
Liang Qi aa3813366a Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/qml/qml/qqmlextensionplugin.cpp
	tests/auto/quick/qquicktableview/tst_qquicktableview.cpp

Change-Id: Ic58d36a8532015bae30f2690063db9829b3bf372
2019-11-22 09:50:11 +01:00
Kari Hormi acb6ed0815 TableView: use fetchMore() when scrolling to the end of the table
QQmlTableInstanceModel implements canFetchMore and fetchMore functions,
but these are not called at any point in QQuickTableView. This change
checks if additional data can be fetched when atYEndChanged signal is
emitted.

Fixes: QTBUG-78273
Change-Id: I49b41b09d9a218826b34f32cd9fe4724a6097b52
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2019-11-20 12:45:34 +02:00
Alexandru Croitor ba494aaa24 Regenerate all projects with new CMake API version
Change-Id: Ie0db35f674137c229eaf049616f38f8e818f7092
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-11-15 12:24:51 +00:00
Alexandru Croitor 387f360b3b Regenerate tests
Change-Id: I67a6c8f1659e7b471a4fcb92a2699292cf4eea81
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-11-14 10:22:34 +00:00
Richard Moe Gustavsen 35fdf3a7b7 QQmlTableInstanceModel: always emit index changed when an item is reused
When reusing a delegate item, it can sometimes happen that the item
ends up being reused at the same location in the table as it had
before it was pooled. And in that case, we don't emit changes to
index, row and column since they technically didn't change.

The problem is that the model might have changed in-between, e.g if
a row has been removed. And in that case, row and column will, even
when unchanged, point to other parts of the model. So all bindings
needs to be reevaluated to ensure that the values they use are
refreshed.

This patch will therefore ensure that we always emit changes to
the mentioned properties when an item is reused, regardless if
they change or not.

Fixes: QTBUG-79209
Change-Id: Icec201a43a30b9f677303fbf652baf6487621deb
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-11-14 11:19:26 +01:00
Richard Moe Gustavsen 91eb02eca2 autotest, tableview: silence compiler warning
Change-Id: I311f0c21baa73521717ad98b2398d5469b9ac208
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-11-12 14:46:54 +01:00
Richard Moe Gustavsen 8952800c68 QQuickTableView::forceLayout(): rebuild table if the size of the model has changed
An assert will trigger if forceLayout() is called while the model is
being reset. The reason is that the forceLayout() schedules a relayout
which assumes that the size of the model hasn't changed. But while
layouting, it will try to fetch data from the model according to the
old size, which will trigger an assert.

This patch will add an extra path to forceLayout() that checks if the
size of the model has changed, and if so, schedule a complete
rebuild instead of just a relayout.

Fixes: QTBUG-79395
Change-Id: If61658912d9e90c1a5aef9bc28083da20fa6ec76
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-11-12 14:46:41 +01:00
Alexandru Croitor c2f8b9535d Merge remote-tracking branch 'origin/dev' into wip/cmake
Removed dependencies.yaml because we don't use it yet in wip/cmake.
Fixed conflict in qmlcachegen.cpp.

Change-Id: Ie1060c737bee1daa85779903598e5b6d5020d922
2019-10-14 19:02:37 +02:00
Qt Forward Merge Bot 9c7121df15 Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
	src/imports/qtquick2/plugins.qmltypes
	src/quick/items/qquickitemsmodule.cpp

Change-Id: I841c65c9c131354788b4f3fcfe3d7ed27be316d5
2019-10-04 11:29:16 +02:00
Fabian Kosmale 0cc6d2a8ac Support required properties in model delegates
If a delegates declares a required property of a given name, and that
name exists as a role in the model, we set the property accordingly.
The same holds true for the special properties that come from the
QQmlDelegateModel like "index" and "model".

All roles are still injected into scope and thus accessible;
changing this in Qt5 would be tedious or even impossible while still
maintaining backwardscompatibility with delegates that do not use
required properties.

Change-Id: I4f388ba549c42f1ff9822bdb3b8357c4d45e4b66
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-09-12 09:19:25 +02:00
Liang Qi c80eb38354 Merge remote-tracking branch 'origin/5.13' into 5.14
Conflicts:
	src/qml/jsruntime/qv4engine.cpp
	src/quick/handlers/qquicktaphandler.cpp
	src/quick/items/qquicktableview.cpp

Done-With: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Done-With: Ulf Hermann <ulf.hermann@qt.io>
Done-With: Shawn Rutledge <shawn.rutledge@qt.io>
Change-Id: If9558a33f01693ce96420c094e0b57dfff0626cd
2019-09-12 08:01:21 +02:00
Richard Moe Gustavsen da04b1d716 QQuickTableView: always relayout after a rebuild
The current logic was based on the idea that if both rowHeight-, and
columnWidthProveders were set, we didn't have to relayout the items
at the end of a rebuild. Because in that case, the row and column sizes
would already be correct after the initial load.

This assumption turns out to be false, because the providers are
allowed to return -1 to signal that the size of a row or column should
use default values (meaning, calculated by TableView). And for those
cases, we need to do a relayout at the end of a rebuild.

Fixes: QTBUG-77074
Change-Id: I0e0f2fdca1cfa9e98f2a0a2b227c3715c16a70f9
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-08-28 10:53:07 +02:00
Leander Beernaert 4e14f6e70a Add QtDeclarative Test Coverage
All tests compile and run on a developer build.

These tests are failing:
tst_qqmlsqldatabase Fails due to missing sql driver
tst_qqmlsqldatabase Fails in wip/qt6
tst_ququicklayouts Fails in wip/qt6
tst_flickableinterop Fails in wip/qt6
tst_qquickpinchandler Fails in wip/qt6
tst_qquickflickable Fails in wip/qt6
tst_qquickgridview Fails in wip/qt6
tst_qquickimage Fails due to missing jpeg plugin
tst_qquicklistview Fails in wip/qt6
tst_qquicktext Fails in wip/qt6
tst_qquickcanvasitem Fails in wip/qt6
tst_scenegraph Fails due to missing jpeg plugin
tst_TestFiltering Fails in wip/qt6

Change-Id: I4b9d69c118e23c095cb72ad5a67653fc30943bb1
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2019-08-14 14:01:58 +00:00
Friedemann Kleint 83f8d886ce Fix some compiler warnings in tests
- Signedness of integer comparison
- Unused parameters and variables
- Ignored return values of QTest::qWaitForWindowExposed() (nodiscard)
- float to int conversions

Change-Id: Ibece620d3c980a5af3b7717486c841d8072ed8af
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-07-12 16:00:51 +02:00
Richard Moe Gustavsen e9852df2d7 QQuickTableView: don't recalculate content width while flicking
There are now three mechanisms in TableView that works together to
ensure that the table ends up edge-to-edge with the content view. They
are applied in the following order:

1. Adjust the content size, based on the predicted size of the table.
2. Adjust the origin and endExtend on the fly, if the content size is wrong.
3. Move the table directly to where it should be, in case we don't have
    time to wait for the origin to change.

We could have, strictly speaking, setteled with just one of them, but choose
to use them all at the same time for best flicking experience. Still, 1. and
2. sometimes step on each others feet when they both detect that something is
a bit off, and adjust.

So rather than adjusting the size of the content view every time we load a
new row or column, we just keep the first prediction. And then we leave all
later ajustments to 2. and 3. This turns out to be a more stable, and will
avoid some glitches that occur when flicking using a scrollbar, if several
mechanisms kick in at the same time.

Change-Id: Ib551a0bf8f6ee59ac9b3556b9462c91adb9cc80b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-05-15 11:14:09 +02:00
Richard Moe Gustavsen 3fff03048a QQuickTableView: change implementation of enforceTableAtOrigin()
We set the size of the content view to be the size of the complete
table. The problem is that the exact size will always be just
a prediction, since we would otherwise need to iterate over all rows
and column up front, to be able calculate the exact size.
This is not acceptable when using non-trival table models.

A side effect of this, is that is will be possible to flick the
viewport further out than the actual end of the table, if the
content view turns out to be larger than the table itself. From
before we used to just move the whole table back into the viewport
when that happened, which could be seen as a sudden jump of the
table to a new position.

This change will improve this logic so that we can avoid most
visual jumps. Instead of moving the table around, QQuickFlickable
supports moving the origin instead. So when we see that the
table is not in sync with the content view, we simple move the
origin to the edge of the table. The effect is that any flicking
or ongoing momentum animation in QQuickFlickable will continue as
if nothing happened. This is also the same logic used by QQuickListView.

Change-Id: I6060b7e84b9489c8fa569e6ff41b958e3871f8e7
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-05-11 09:47:36 +00:00
Richard Moe Gustavsen dafdc9d701 QQuickTableView: sync viewport rect with syncView when rebuilding
When moving contentX/Y, we also need to ensure that the viewport rect
reflects the change. Otherwise we'll end up loading rows and columns
somewhere else then under the viewport.

Change-Id: Ifbd3d66b9b3a822414aefde9b5bd088274dfa2ad
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-05-09 13:25:23 +00:00
Richard Moe Gustavsen fee256e641 Autotest: add syncView tests for QQuickTableView
Change-Id: I0c311a4cc7d0765e234739c005cb68a60cfee129
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-05-03 07:39:06 +00:00
Ulf Hermann 325e6305b4 Move model types into their own library
The model types are not part of the core QML runtime and should only be
loaded if you explicitly import them. We cannot enforce that in Qt5 as
some of them are available from the QtQml import, but we can change it
in Qt6.

Change-Id: I1e49e84d748e352537ec2d4af901c034c91d038f
Reviewed-by: Erik Verbruggen <erik.verbruggen@me.com>
2019-05-02 09:26:04 +00:00
Richard Moe Gustavsen 48f9dbf06a QQuickTableView: remove superfluous rebuildScheduled property
We already have the variable 'scheduledRebuildOptions'. When this
is set to something else than RebuildOption::None, it means
that a rebuild is scheduled.

Change-Id: I85cde5c45eba15023cd389ebb0ba86f9d58835ae
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-04-11 10:24:21 +00:00
Liang Qi 3baa2d5505 Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts:
	tests/auto/quick/qquicktableview/tst_qquicktableview.cpp

Change-Id: If3bf1abc23a59c458be0bb862d92f2edcb16b79f
2019-02-22 14:26:13 +01:00
Richard Moe Gustavsen 2c16e0c30c QQmlDelegateModel: guard new row/column properties with revision 12
Tag the new 'row' and 'column' properties with revision 12.
This will make sure that they cannot be accessed by the delegate
unless the QQmlAdaptorModel has the correct minorVersion set.

Fixes: QTBUG-70031
Change-Id: I49e67c37ab5b7925c7bca313bbb99f04d1387cc4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2019-02-21 10:55:13 +00:00
Richard Moe Gustavsen 0068575602 QQuickTableView: add support for hiding rows and columns
This patch will add support for hiding rows and columns to TableView.
You can now hide a column by returning 0 width for it from the
columnWidthProvider. The same can be done to hide a row (by using the
rowHeightProvider). If you return NaN or negative number, TableView
will fall back to calculate the size of the column/row by looking at
the delegate items, like before. This to make it possible to hide
some rows/columns, without having to calculate and return the heights
and widths of the other rows and columns.

[ChangeLog][QtQuick][TableView] Added support for hiding rows and columns
by setting their size to 0 from the columnsWidthProvider/rowHeightProvider.

Change-Id: If9e1a8db91e257d36cb2787bab4856e6201456ac
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-02-08 08:53:47 +00:00
Richard Moe Gustavsen 965f49bb4f QQuickTableView: use QMap instead of a QRect to keep track of loaded columns
TableView keeps track of which rows and columns that are loaded
at any point by using a QRect called "loadedTable". loadedTable
basically describes the top-left and bottom-right corner of the
table that has been loaded (which also is what ends up visible
on screen).

But now that we prepare for making it possible to hide rows
and columns, using just a QRect becomes to simple. A rectangle will
only tell what the edges of the table are, but not if any of the
rows and columns in-between are hidden and therefore not loaded.
So a QRect(0, 0, 10, 10) will give us the impression that we have
10 visible columns on screen, but in reality, we might have a
lot less.

This patch will change this to instead use two QMaps to record
loaded rows and columns. This will make it much more easy
to deal with hidden rows and columns in upcoming patches. We
use a QMap instead of a QHash/QSet to keep the list of columns and
rows sorted, since we frequently still need to know the edges of
the table, like before.

Change-Id: I45736485c67042403b095e73b5f2effa411281d0
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2019-01-30 11:04:04 +00:00
Mitch Curtis b888745211 tst_qquicktableview: use QQuickTest::qWaitForItemPolished()
Change-Id: Iac53158bdd5138f41e5cc8d8fe1e1a5f7959be23
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2018-10-31 08:54:06 +00:00
Richard Moe Gustavsen d973907f6e TableView: connect to 'layoutChanged' signal from the model
Ensure we rebuild the table when the model emits 'layoutChanged'.

Fixes: QTBUG-71140
Change-Id: I70dac897830bf5a12ae6987920e388743fd358a1
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2018-10-17 10:59:36 +00:00
Richard Moe Gustavsen b09bc0c0eb QQmlAdaptorModel: return correct column count from the model
There is no reason for QQmlAdaptorModel to return the
wrong column count to the view. For models that are not
QAIM, the accessor that wraps the model will report the
column count to be 1 anyway. The same is also true
for QAbstractListModel.

Change-Id: Ia259b044201d76743e5f43d9f0999d3848912075
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2018-10-17 10:59:31 +00:00
Richard Moe Gustavsen 863bc570ca QQuickTableView: improve performance when scrolling with scrollbars
When flicking, the current implementation would load and unload
edges around the table until the new viewport was covered. The downside
of that strategy is that you if you move the viewport a long
distance in one go, you will need to load and unload edges hidden
outside the viewport until it catches up with the new viewport. It gets
even worse if you flick with a scrollbar, since then you can end up
flicking thousands of rows in one go. And this will keep tableview
busy loading and unloading edges for a "long" time.

This patch will fix this issue by checking how much the viewport
changes during a flick, and select a strategy based on that. So if the
viewport moves more than a page (which is the size of the viewport), it
will schedule a rebuild of the table from the viewports new location,
rather than trying to load and unload edges until it catches up.

Fixes: QTBUG-70704
Change-Id: I88909e118ec0759a7b7a305c19ccc6670af6263b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-09-29 06:26:17 +00:00
Richard Moe Gustavsen f4e96bf319 QQuickTableView: build the table when the component is finalized
componentComplete() is called on us after all static values
have been assigned, but before bindings to any ancestors
have been evaluated. Especially this means that if our size
is bound to the parents size, it will not be ready at that point.
Since we cannot build the table without knowing our own size, we
waited for the updatePolish() call before we started to build
the table.

The problem with that strategy, is that any asynchronous loaders that
TableView might be inside would already be finished by the time
we received the updatePolish() call. The result would be that we
ended up loading all the delegate items synchronously instead of
asynchronously. (As soon as a loader has finished loading the initial
item, async loading will no longer be used).

This patch will therefore add a componentFinalized function that gets
called after all bindings have been evaluated, but before the loader
has finished. When receiving this call, we load the delegate items (and
build the table).

A nice side effect is that the table will also be ready
by the time Component.onCompeted is emitted to the QML
app. This means that e.g contentWidth/Height has valid values.

Change-Id: Ief92d2fecfaea54f6191da116ed4ba79cc673b01
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-09-17 07:51:20 +00:00
Richard Moe Gustavsen 00afb51baa 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>
2018-09-13 04:57:01 +00:00
Richard Moe Gustavsen 8e5578d3fc QQuickTableView: override fixup() to preserve contentX/Y at start-up
Flickable::fixup() will be called from Flickable::componentComplete().
fixup() is a virtual function that subclasses can override to e.g
ensure that cells snap to grid etc (which is not yet supported by
TableView). The default implementation will check if the assigned
contentX/Y is within the current content item size, and adjust it
back to 0,0 if not. The problem is that during componentComplete(), the
table has not yet been built. And we don't want Flickable to reset
any assignments to contentX/Y until that has happened. So override the
function and block it from doing any adjustments before the table has
been built.

Change-Id: Id6c5a3b5f053f71bf1854573cd5b9dc3ecc9f246
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-09-11 12:37:36 +00:00
Richard Moe Gustavsen 5b95cc34c1 QQuickTableView: don't rebuild table upon querying content size
Overriding contentWidth/Height was done to be able to force build the
table early if the app needed to know the size of the table already at
Component.onCompleted (to e.g center the viewport on the center of
the table). But now that we have a forceLayout() function, it's better
to require that that function should be called before querying
contentWidth/Height at this stage.

By not building the table on the fly, we allow the application to
bind expressions directly to contentWidth/Height, without being concerned
about potential binding loops that can occur as a result of us
rebuilding the whole table behind his back. The benefit of this overshadows
the need to call forceLayout() explicit for some corner cases.

Note that we still redefine the contentWidth/Height properties in TableView
so that we can catch if the application sets an explicit contentWidth/Height
(which is tested by checkExplicitContentWidthAndHeight()).

Change-Id: Ic4499b3939af1cb3a543e4c006023d0d6f12fd3b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-09-11 12:37:29 +00:00
Richard Moe Gustavsen 5ec0599032 QQuickTableView: don't set contentX/Y to zero when building the table
Don't reset the content item to 0,0 when we do a rebuild of the
table, since that will overwrite whatever the user has set to contentX/Y
explicitly. Doing the latter can be handy if he needs to flick the table
to a start position upon construction. If the user want's to move the
content item back to origin when changing the model, he can instead do
so manually.

Change-Id: Ic7bc424312569e49115dea5037dd1109261a3aff
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-09-10 09:31:04 +00:00