Commit Graph

9 Commits

Author SHA1 Message Date
Richard Moe Gustavsen c20026be93 QQuickTreeView: implement support for selecting cells
Selecting cells in a table is quite different from selecting
cells in a tree. The reason is that in a table, all model
items share the same model parent. And ItemSelectionModel
is optimized for this case, meaning that you can select
an area of cells by simply specifying the top-left index,
and the bottom-right index, as long as the cells
in-between all have the same parent.

A tree is not structured this way. Instead it's structured
as a hierarchy of parent-child relationships, where the
requirement that all model items should have the same parent
obviously will not hold.

Because of this, the implementation in TreeView that lets
the user select cells, needs to be quite different from the
optimized version in TableView. Instead, it basically needs to
divide the selected area into individual rows, and sometimes
indices, that can be selected, or deselected, one-by-one.

This patch overrides the 'updateSelection()' function for
QQuickTreeView, and rewrites the logic to take all this into
account. This will make selecting cells work for TreeView.

Change-Id: I2157efcd0e83b5a0342f6af4018323b64d31f6f3
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-06-04 22:45:24 +02:00
Mitch Curtis 36c6c1ea57 QtQuickTest: add API for checking for polish at window level
This adds a qIsPolishScheduled(QQuickWindow *) overload of
qIsPolishScheduled(QQuickItem *) (added in
40d6072bc8) and deprecates
qWaitForItemPolished() (added in
7a3cad0619) in favor of qWaitForPolish(),
which has QQuickItem* and QQuickWindow* overloads.

The existing functions that take QQuickItem are useful, but testing
Qt Quick applications can be made even easier by allowing users to
check if a window has any items that need to be polished. This
information is already present (in QQuickWindowPrivate::itemsToPolish),
so it's very efficient to check for.

This is especially useful now that Qt Quick Layouts using polishing for
their layouting, for example, as it's no longer necessary to find
individual polishable items in complex hierarchies before proceeding
to interact with child items.

[ChangeLog][QtQuickTest][QQuickTest] Added
QQuickTest::qIsPolishScheduled(QQuickWindow *) and
QQuickTest::qWaitForPolish(QQuickWindow *) functions for verifying that
updatePolish() was called on one or more items managed by a window.

[ChangeLog][QtQuickTest][QQuickTest] Deprecated
QQuickTest::qWaitForItemPolished(QQuickItem *). Use the new
QQuickTest::qWaitForPolish(QQuickItem *) function instead.

Fixes: QTBUG-93757
Change-Id: I95b6e051b3c9fd2fa93604f4d9ccda486bb29f9d
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-06-02 12:46:11 +08:00
Richard Moe Gustavsen b23626d0b8 QQuickTreeView: add keyboard navigation support
Override keyPressEvent in QQuickTreeView to let
the left and right arrow keys expand and collapse
the current row in the tree. Note that the application
developer can set keyNavigationEnabled to false if this
default behavior is not wanted.

Change-Id: If5201dafd1d3d7e2e4a113aeb2a60f601a1a4c35
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-05-06 00:06:29 +02:00
Richard Moe Gustavsen 7d4b507cc8 QQuickTableView: change order of row and column
The modelIndex() function is added for Qt 6.4, and
therefore not yet in any release.
Looking at the other functions in QQuickTableView that
takes a row and column as arguments (e.g
positionViewAtCell() and itemAtCell()), they all have
column as first argument, and row as second. So change
the modelIndex() function to do the same, so that the
TableView API ends up consistent.

Change-Id: Ia85ceb3a4719c1e3c16e2023aa039263fef83f6e
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-04-07 15:15:57 +02:00
Richard Moe Gustavsen c013439598 QQuickTreeView: add expandToIndex()
Add a function that lets you expand the tree recursively
from an index in the model, and all the way up to the root.

[ChangeLog][QtQuick] New function "expandToIndex()"
has been added to TreeView.

Change-Id: I063ef698e37f44730438e1638d3b7c1b4edaa0d0
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-02-18 00:09:53 +01:00
Richard Moe Gustavsen 060e0b2cd1 QQuickTreeView: add collapseRecursively()
Add a new function collapseRecursively() to TreeView
that lets you collapse a node all the way down to
the leaves.

[ChangeLog][QtQuick] New function "collapseRecursively()"
has been added to TreeView.

Change-Id: Ic82def1e45b7d9c2be4c5e7b04d1001e75452ba0
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-02-14 12:38:11 +01:00
Richard Moe Gustavsen abe854b0cc QQuickTreeView: add expandRecursively()
Add a new function expandRecursively() to TreeView
that lets you expand a node all the way down to
the leaves.

[ChangeLog][QtQuick] New function "expandRecursively()"
has been added to TreeView.

Change-Id: I665cad48e2a76e2f50ae559f1623ac9427c98fad
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2022-02-14 12:38:11 +01:00
Richard Moe Gustavsen a43912865e QQuickTreeView: be able to expand rows that are not yet visible in the view
If the app expands a row in TreeView, that row will for a brief moment
be expanded in the proxy model, but not in the view, until the
view is polished. For that reason, when determining if a row can be
expanded or not, we should check the state of the proxy model, and
not the view.

Note: if the application needs the state of the view to reflect the
state of the proxy model immediataly after a call to expand,
forcePolish() is always possible.

Task-number: QTBUG-91374
Pick-to: 6.3
Change-Id: I5b85e0b5c3b32d17f93409153041df3fc2437424
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
2022-01-24 10:31:30 +01:00
Richard Moe Gustavsen 18da655b77 quick: add qquicktreeview
This patch adds TreeView to Qt Quick. It is more or less
a copy from the TreeView in Marketplace, but with some
modifications to make it more equal to the already
existing TableView, ListView, and GridView.

[ChangeLog][Item Views] A new view is added: TreeView

Fixes: QTBUG-61630
Change-Id: Ibb9d22cf9c9df021e77d03287872134c2682682a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-12-04 23:41:45 +01:00