Commit Graph

74 Commits

Author SHA1 Message Date
Richard Moe Gustavsen b5d7be57cc QQuickTableView: set delegate parent early-on
Set the parent before bindings are evaluated.

Change-Id: I370524fe32c66699bd73aafeac55c58667b4dff1
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-19 09:05:30 +00:00
Richard Moe Gustavsen 379ba8640a QQuickTableView: remove TableView.cellWidth/Height
The attached properties TableView.cellWidth/Height were added
for corner cases where you couldn't set/override implicit size
for a delegate item. But now that we have added rowHeightProvider
and columnWidthProvider (and we know that we're going to offer a
broader API to set row/column size from a HeaderView), you have
a way out for those cases as well. So lets remove the attached
properties until we know for sure if they will be needed.

Change-Id: I7d20fb02c36aebd3f24964630ccb68d4c813e93e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-18 22:12:18 +00:00
Nicolas Ettlin ab1df24c82 Qt Quick Table View: set the default row and column spacing to 0
Currently, in the TableView QML component, the initial row and column
spacing is set to (-1, -1), as in the default QSizeF constructor. As
the negative spacing was ignored when positioning the items, but taken
in account when computing the total content size, it caused an issue
where the user wouldn’t be able to scroll to the bottom right corner of
the TableView. This commit fixes this issue by setting a default
spacing to (0, 0). It also prevents the developer from using invalid
spacing values (such as negative numbers, NaN or Infinite).

Task-number: QTBUG-69454
Change-Id: I343475790c384954372afad0a778f8da7dff0b0d
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-18 18:22:23 +00:00
Richard Moe Gustavsen 790e2f37d4 tst_qquicktableview: make checkRowColumnCount() more stable
tst_QQuickTableView::checkRowColumnCount() was prone to fail, since
it compared the maximum number of created delegate items to the
initial count before flicking. But as we flick, TableView will normally
need to load and show an extra column and/or row compared to the start.

Change-Id: If39ae6eeff9a85acbc84cc61b8b94ee68565e347
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-18 18:22:09 +00:00
Richard Moe Gustavsen 7661a4197c QQuickTableView: change how tableview resolves column width and row height
The current solution of storing column widths as the user flicks around
turns out to not scale so well for huge data models. We basically don't
want to take on the responsibility of storing column widths and row
heights for e.g 100 000 rows/columns. Instead, we now choose to ask the
application for the sizes, whenever we need them. This way, the application
developer can optimize how to store/calculate/determine/persist row and
column sizes locally.

To implement this functionality, we add two new properties:
rowHeightProvider and columnWidthProvider. They both accept a javascript
function that takes one argument (row or column), and returns the
corresponing row height or column width.

If no function is assigned to the properties, TableView will calculate
the row height / column width based on the currently visible items, as
before.

Change-Id: I6e5552599f63c896531cf3963e8745658ba4d45a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-18 15:36:59 +00:00
Mitch Curtis e792c08ef2 TableView: invalidate table when model is reset
Signals like rowsInserted() were already accounted for in
QQuickTableViewPrivate::connectToModel(), but modelReset() was not.

Change-Id: I6b8248d745d507d4ea846e9bee717182915792b3
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
2018-07-17 18:03:20 +00:00
Richard Moe Gustavsen a0bd478550 QQuikTableView: use TableViewModel instead of QQmlDelegateModel
Swap out QQmlDelegateModel in favor of the new QQmlTableInstanceModel.

QQmlTableInstanceModel skips using QQmlChangeSets all together, and lets
us subscribe to model changes directly from the underlying QAIM instead.
This will make it much easier to handle model changes more
gracefully later.

Change-Id: I0315e91f39671744fb48d1869e4b73b1becbb929
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-17 15:11:30 +00:00
Richard Moe Gustavsen 58c988e090 TableView: remove row and column from attached object
TableView.row and TableView.column is no different from the row
and column properties that are injected into the context from the
model classes. So just remove them to not bloat the API.

This attached properties where added at an early stage where we
thought that it should be possible to set a different row and
column count on the view than compared to the model (to e.g to
"fake" a table layout when just assigning an integer as a model).
Also, we consider supporting right-to-left etc, where we might
end up with cells that have a different row/column in the view
compared to where the cell is in the model. If we decide to
do this later (not for the first release), we can consider
adding the attached properties back again at that point.

Change-Id: I588a45913b968db789978339bc9a63cd2ccfad49
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-07-10 12:39:52 +00:00
Richard Moe Gustavsen 1e8d409786 QQuickTableView: use QHash instead of QList to store delegate items
Using a QList to store all loaded delegate items was a legacy solution
inherited from QQuickItemView.  But we look-up items in the list based
on index all the time, so switching to use QHash instead should be more
optimal.

Change-Id: I1aa8d23b3ac208a9424982491faaa5dd42775280
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-06-26 11:47:35 +00:00
Richard Moe Gustavsen 7d55fb4029 QQmlDelegateModelItem: move row and column up to the base class
Change 8c33c70 injected row and column (alongside index) into
the QML context of a delegate when the view had a
QAbstractItemModel as model.

Rather than only inject those properties when using QAIM, this patch
will move the code to the base class. This way, if a view uses e.g
a javascript list as model, row and column is still be available. This
is useful, since then the delegate can bind to both row and column
regardless of what kind of model the view uses. In the case of a
list model, the column property will always be 0.

Change-Id: I1d9f11c0b7d7a5beb83198184ba12cc1e48cd100
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-06-09 16:58:13 +00:00
Richard Moe Gustavsen 90fea15e0d TableView: fix copy/paste failure
This patch fixes a small typo originated from an earlier
copy/paste. QQuickTableViewPrivate::rowHeight() should use
cellHeight, not cellWidth.

Change-Id: I85cb3730dfd0daf0a9bb16dbb0771c31a453fa13
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-06-09 16:57:59 +00:00
Richard Moe Gustavsen af46cc1993 TableView: fall back to use implicit size for delegate items
Rather than forcing users to set TableView.cellWidth/cellHeight (and
therefore also force them to create an attached object for every
cell), we now also accept setting implict size as a fall back.

Change-Id: I4c4c4d23fe7fc193581728d3878cf2c7e40c0745
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2018-06-04 13:03:13 +00:00
Richard Moe Gustavsen cf9c07539c TableView: check if the model can produce items before loading
If you assign a non-empty model, the model can still return a count
of zero if something else is amiss, like the delegate being null.
So we need to do en extra check for this before we load the first
top-left item, otherwise we'll hit an assert later in the loading process.

Change-Id: I747868faf7955b8784b2957505ae03e5b1aa0b45
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-25 11:21:59 +00:00
Richard Moe Gustavsen 1b0e6861ba TableView: load and unload edges in the same loop
Normally when you flick the table around, a column (row) will
be flicked out of view on one side, while another column
will be flicked in and loaded on the opposite side. But if you
flick really fast, you sometimes manage to flick in and out
several columns in one go before tableview gets an updatePolish
call to catch up. In the latter case, we would then first unload
all flicked-out columns, and then afterwards continue loading all
flicked-in columns.

This approach is currently not a big problem, but it will be once
we start recycling delegate items. Because then we should take
care to not overflow the pool with unloaded column items, since
the pool will most likely have a maximum size. So we therefore change
the algorithm a bit so that we always alternate between unloading
and loading one column at a time, rather than unload several columns
in one go before we start loading new ones.

Change-Id: Ia0f1968a4b3579e4445e1f7b6e68a28a1d2b360b
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-23 20:24:12 +00:00
Richard Moe Gustavsen 8db3e76960 TableView: fall back to use default column/row size
If we cannot determine the size of a row or column, we need
to fall back to some size other than 0 while layouting. The
reason for this is that we fill up with as many rows and
columns that fits inside the viewport. But if e.g the width
of column is zero, we will never make any progress, and
therefore just keep loading and loading columns.

Change-Id: I96ea410dc5a75831e44c2924172254634598b680
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-23 20:22:28 +00:00
Richard Moe Gustavsen f61a49efa2 TableView: ensure we don't update viewport rect while loading edges
Flickable will change the viewport recursively while we're
loading/unloading rows/columns. This will confuse TableView
and might cause it to freeze. The correct time to update
the internal viewport rect is from inside updatePolish(), where
we have better control over the current state.

Change-Id: I94f964b8b0f6920ffe31cedd7a461f3853998be3
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-16 06:41:44 +00:00
Richard Moe Gustavsen 42720cb625 TableView: remove using a floatingPointMargin
The floatingPointMargin was added at an early stage to avoid
that we ended up in a locked situation where we loaded
and unloaded the same edge continuously without being able to
exit the loading loop. This was done wrongly because we didn't
take spacing into account in QQuickTableViewPrivate::canLoadTableEdge
(spacing was usually one pixel, coincidentally the same as the
floatingPointMargin). This has now been fixed in a previous patch, so
we can remove the faulty floatingPointMargin as well.

Change-Id: I3caa7808298a1954a3c02f609bad98c3c2c2426a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-15 07:45:31 +00:00
Richard Moe Gustavsen 1b46ba1e35 TableView: ensure to take spacing into account then loading edges
As it stood, we forgot to take spacing into account when determining
if an edge should be loaded. This meant that we sometimes would
load more edges than necessary when spacing was set to a large value.

Change-Id: I9a2ab96a838d00116aa282b6a40d58a19849936f
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-14 10:28:02 +00:00
Richard Moe Gustavsen b7b49e3208 TableView: add support for table margins
Instead of always drawing the table at 0,0 in the content
view of the flickable, add support for setting margins.
The margins will let the developer add some extra space
around the table to e.g make space for custom headers etc.

Change-Id: I4a69b2cf3594bd72255d21372b5bf0d3220676dc
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-14 10:27:56 +00:00
Richard Moe Gustavsen bbcf4193b3 TableView: ensure we check that returned iterators are not at the end
The current implementation would sometimes just crash because we
didn't check if the returned iterators were pointing to something
valid. This patch will fix this.

Change-Id: Ia45a8e3b701fb9067bf9116f39d7753b88f4f734
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-09 11:16:46 +00:00
Richard Moe Gustavsen 5e9fc09f17 tests, qquicktableview: check that the expected number of delegate items are created
Change-Id: I96bc282a6678954d73cf5a15241ac30f43964dcb
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-05-09 11:16:32 +00:00
Lars Knoll 1ff97a7dad Revert "tests, qquicktableview: add countDelegateItems()"
This reverts commit 1cfd61f636.
The commit came in during a time where tests aren't run, and fails
at least on some of our linux platforms.

Change-Id: Idd5c68b0fdec06ca93a9bab9604ad64974ee00e3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2018-05-02 14:20:47 +00:00
Richard Moe Gustavsen 1cfd61f636 tests, qquicktableview: add countDelegateItems()
Change-Id: I1794a46b697467af152a6346fa7d7b5d0ce31807
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-04-27 07:09:40 +00:00
Richard Moe Gustavsen 5e5107493c test, TableView: add boilerplate code for testing TableView
Change-Id: I4d68e033074442c402df11f779b6875e80ec6412
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2018-04-25 15:31:22 +00:00