aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitem_p.h
Commit message (Collapse)AuthorAgeFilesLines
* Give focus to parent window when focus chain wrapsDoris Verria2024-05-021-1/+1
| | | | | | | | | | | | If the focus chain wraps when tabbing (prev == last && next == first), we need to give a chance to the parent window to gain focus so that the focus can be passed to the next/prev object in the focus chain. To give focus to the prev/next target, override new virtual setFocusToTarget for QQuickWindowPrivate. Task-number: QTBUG-121789 Change-Id: Ibe91af53ca622e7fe2b7fc662a95f1a5d7cb479b Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Declare some missing value typesUlf Hermann2024-04-171-1/+1
| | | | | | | | | | | | | | * An opaque pointer for the execution engine * QQmlChangeSet * long and ulong: For those we cannot know the size in advance. Therefore we cannot handle them as aliases of other numbers. * QTextBlock * FileProperty * QQmlXmlListModuleQueryResult Task-number: QTBUG-101143 Change-Id: If66d1fa3ab734351006e5a9f071e171c97dd738e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Set default layout size policies for quick itemsSanthosh Kumar2024-02-091-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | The quick items are initiliazed with default layout size policy. This size policy can be either Preferred or Fixed and it can vary depending on controls and its orientation. [ChangeLog][QtQuick][Item Behavior Changes] The QtQuick items now set their default size policy and it would be effective when used within QtQuick Layouts. The following types now behave differently by default when used in layouts: Button, CheckBox, ComboBox, Dial, DialogButtonBox, Frame, Flickable, GridView, GroupBox, HorizontalHeaderView, ListView, Page, Pane, PathView, ProgressBar, RadioButton, RangeSlider, RoundButton, ScrollBar, ScrollIndicator, ScrollView, Slider, SpinBox, SplitView, StackView, SwipeView, Switch, TabBar, TabButton, TableView, TextArea, TextEdit, TextField, TextInput, ToolButton, TreeView, Tumbler, VerticalHeaderView. Task-number: QTBUG-117597 Pick-to: 6.7 Change-Id: I41fe73a2e466e396f26604a14d1f15b8b42df338 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* API Cleanup: Remove focusReason from QQuickItem's public API and add docsDoris Verria2024-01-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | Make changes according to API review comments: - Remove focusReason property and relevant API from QQuickItem. Move it to private API in QQuickItemPrivate and rename it to lastFocusChangeReason. Defer exposing this property to QML for now. (In Qt7 we can expose it by adding it as a signal parameter to QQuickItem's focusChanged signal) - Add documentation for focusPolicy C++ API - Don't mark focusPolicy property as FINAL Partially reverts 1ca9928856c47108000ffe5f310f2b99740f087b Task-number: QTBUG-119952 Task-number: QTBUG-117596 Pick-to: 6.7 Change-Id: Ib4632b86c64e3221ca5e651d80d58b8c89fcf2b7 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Remove the use of Q_QUICK_PRIVATE_EXPORTAlexey Edelev2024-01-091-4/+4
| | | | | | Task-number: QTBUG-117983 Change-Id: Ia904c9390efb13b92de2e16fa0690e48394f9bab Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* QQuickItem: Respect focusPolicy when delivering eventsDoris Verria2023-12-161-0/+4
| | | | | | | | | | | | | | | When delivering events that may potentially transfer focus based on the focusPolicy of the item, we need to set the focus (if needed) before letting the item handle the event. Do this in QQuickItem::event so that the specific event handlers don't need to deal with setting focus, as well as overrides don't need to know about those handler's implementations in the base. Task-number: QTBUG-117596 Pick-to: 6.7 Change-Id: I8223638ce4abf80c212dc63bffdb876254e43442 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Move focusPolicy from QQuickControl to QQuickItemDoris Verria2023-12-081-1/+3
| | | | | | | | | [ChangeLog][QtQuick][Item] The focusPolicy property has now moved from QQuickControl to QQuickItem. Task-number: QTBUG-117596 Change-Id: I3a3d5c26f4d7a8bd4890b3e4fdfc34d6e716362b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Move focusReason from QQuickControl to QQuickItemVolker Hilsheimer2023-12-081-0/+2
| | | | | | | | | | [ChangeLog][QtQuick][Item] The focusReason property has now moved from QQuickControl to QQuickItem. Task-number: QTBUG-117596 Change-Id: I7ddfbe535b6f0e7289dd3408a074ad0b8aa4de01 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Ensure ItemObservesViewport works when item is moved to new ancestorTor Arne Vestbø2023-12-071-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | When an item has ItemObservesViewport set, it will receive transformChanged callbacks when any of its ancestors changes their position, size, etc. This relies on every ancestor having the subtreeTransformChangedEnabled flag set, which was previously ensured when the item called setFlag(). But when the item then moved to a different ancestor hierarchy, we would only set subtreeTransformChangedEnabled on the new parent, but not any of its ancestors, which meant that the item would no longer pick up changes beyond the immediate parent. We would also not send a transformChanged in response to the reparenting itself, which is critical, as the item's clip or scene positions may have changed in response to the new parent. Both of these cases are now handled as part of the ItemChildAddedChange of the new parent. Change-Id: I5000fb46d7638ce9674d4879890cf4344e5ce538 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Remove all QML_DECLARE_TYPE from src and toolsUlf Hermann2023-11-181-8/+0
| | | | | | | | They are generally not useful for anything. Change-Id: I12e959ce9338e6eb7465633496c7921fa09a3fe8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Include what you need: <QPointer>Marc Mutz2023-10-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | All these TUs relied on transitive includes of qpointer.h, maybe to a large extent via qevent.h, though, given that qevent.h is more or less the only public QtBase header that includes qpointer.h, something else seems to be at play here. Said qevent.h actually needs QPointer in-name-only, so a forward declaration would suffice. Prepare for qevent.h dropping the include. The algorithm I used was: If the TU mentions 'passiveGrabbers', the name of the QEvent function that returns QPointers, and the TU doesn't have qpointer.h included explicitly, include it. That may produce False Positives, but better safe than sorry. Otherwise, in src/, add an include to all source and header files which mention QPointer. Exception: if foo.h of a foo.cpp already includes it, don't include again. Task-number: QTBUG-117670 Change-Id: I9b98cda524a0e6a61be7805edda708916bb2bc2b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQuickItem: Remove declaration of not implemented list operationIvan Tkachenko2023-09-191-1/+0
| | | | | | | | | | | Item::visibleChildren is a read-only QML list property, and not meant to be externally modifiable. Append operation is not defined for it anymore, but a symbol declaration apparently remained after refactoring. Amends 3e9caba478695443669ff880334ea69db6f764eb Change-Id: I1bd1de1e917c13178bd73c4aecb4f7853e5a4e01 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Make properties in Qt Quick FINAL to prevent shadowingOliver Eftevaag2023-06-081-25/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without setting the FINAL flag, properties can be shadowed by users. In the following example: Image { property string source: "Shadowing QQuickImage::source" } The source property of QQuickImage, will be shadowed by a new property with the same name. This can both cause confusion for non-experienced users, and it causes issues with qmlsc. Shadowing a property is usually unwanted. But there are some situations where it might be intended. The QML Object Attributes doc page demonstrates that you can override the color property in QQuickRectangle, for instance. [ChangeLog][Important Behavior Changes][QtQuick] Most properties for types in the QtQuick module are now FINAL, meaning that they can no longer be shadowed by declaring new properties with the same names. With few exceptions. A warning will be printed out to the console, when a FINAL property is shadowed. We recommend that users rename those properties to avoid potential unexpected behavior changes. Task-number: QTBUG-108739 Pick-to: 6.6 Change-Id: I1070926606f4d88ef7edf088ff80fb3ec82305c8 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QQuickItem: Do not synthesize replace() for data/resources/childrenUlf Hermann2023-05-091-0/+3
| | | | | | | | | | | | | Those properties are not actually sequential containers. They have some internal logic that refuses certain operations and changes the semantics of others. We should not run things like splice() on them. We can natively implement removeLast(), though. Pick-to: 6.5 Fixes: QTBUG-112949 Change-Id: Ic9fa84f98a68428df9e958ba7fc72b0987e8601f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Accessibility: respect value in attached Accessible in controlsVolker Hilsheimer2023-04-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | QQuickItemPrivate::accessibleRole is virtual and called by the framework to determine the role of an item. The default implementation checks and respects a possible Accessible attached object. However, subclasses that override the virtual don't, so the attached properties are ignored, and the class-specific implementation wins. This makes it impossible to change the role of e.g. a checkable button. To fix that, move the code respecting the attached object into a non- virtual function that the framework calls instead, and only call the virtual member if there is no attached object, or if that object is not initialized with a role. Replace calls to the virtual from the framework with calls to the non-virtual wrapper. Do this for both QQuickItem and for QQuickPopup, and adjust the logic in QQuickControl types that create an attached object and initialize it's role when accessibility becomes active. Use the non-overridable effective role value for that as well. Add a test case, and to avoid any new framework calls to the virtual, make it private. Fixes: QTBUG-110114 Pick-to: 6.5 6.2 Change-Id: Ia709cecbd181b6d8ee3297a4af60c1e7db9a2c51 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QQuickItem: merge notifyChangeListeners overloadsVolker Hilsheimer2023-04-181-15/+7
| | | | | | | | | | | | | The two template methods did the same, we can use if constexpr to detect whether the function pointer is a member function pointer and call it on the listener object if so, otherwise as a free function. Refactoring, but enables bug fixes and stability improvements in follow up commits. Pick-to: 6.5 Change-Id: Idc3f81fd22f3246482fdc99fcdae43074c70d9df Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QQuickItemKeyFilter: do not overload shortcutOverride-signalSami Shalayel2023-02-151-2/+2
| | | | | | | | | | | | | | Renames the virtual shortcutOverride(QKeyEvent*) method of QQuickItemKeyFilter and QQuickKeysAttached to shortcutOverrideEvent to avoid overloading the shortcutOverride(QQuickKeyEvent*)-signal of QQuickKeysAttached. Signals should not be overloaded. Also, it makes code generation in qmltc more complicated. Task-number: QTBUG-110029 Change-Id: I1b2362a67095ade085a829e51c2d309a2f7c50af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* QQuickItemPrivate::itemToParentTransform: pass transform by pointerShawn Rutledge2023-02-081-1/+1
| | | | | | | | | | | | | https://wiki.qt.io/API_Design_Principles#Pointers_vs._References says we prefer pointers for out-parameters because it's clearer at the call site that the argument will be modified. Amends bfb3c424abc7c839dc44de0e36024ede99ece736 As a drive-by, re-indented nearby internal doc comments. Change-Id: Id7f377e94e6917185fc26d7ac7c564841d45a257 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io> Reviewed-by: JiDe Zhang <zhangjide@uniontech.com>
* Fix build with -no-feature-quick-shadereffectTasuku Suzuki2023-01-241-0/+2
| | | | | | | | | | | Changes the feature from PRIVATE to PUBLIC to disable the private layer property in qquickitem.h. Disables UniformAnimator and Item::layer. Fixes missing headers seen by disabling the feature. Pick-to: 6.5 Change-Id: I9025568c5d98cb708ed2fcfb323ac33c06c2ccaf Reviewed-by: Kaj Grönholm <kaj.gronholm@qt.io>
* QQuickItem: avoid emitting signals during destructionVolker Hilsheimer2022-11-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | If a QQuickItem is in the QQuickItem destructor, then it is both unsafe and unnecessary to emit property change notifications. Connected code can no longer rely on the state of the emitting object - if it was originally a subclass of QQuickItem, then those subclass destructors will already have run. And the QQuickItem destructor will also have partially run, leaving the object in an undefined state. Add a flag that we set to true at the top of ~QQuickItem, and don't emit visibleChildrenChanged, parentChanged, visibleChanged, and childrenChanged for items that are partially destroyed already. [ChangeLog][Qt Quick][QQuickItem] QQuickItem no longer emits change notifications for the parent, children, visible, and visibleChildren properties while it is being destroyed. Task-number: QTBUG-107850 Change-Id: I36ea98842c89ad89fcc1c4a328d138f66f2a0446 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Check only for enabled HoverHandlersShawn Rutledge2022-10-311-1/+1
| | | | | | | | | | QQuickItemPrivate::hasHoverHandlers() was used only in QQuickItemPrivate::setHasHoverInChild(). In that context it's ok to ignore disabled HoverHandler instances: the point is we don't need to deliver hover events to an item subtree if nobody is listening. Change-Id: Ie44b6e259db862161a28ab5b7d1e910dc6ca4640 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* ScrollBar: fix crash on exit when flickable created before ScrollViewMitch Curtis2022-10-311-0/+5
| | | | | | | | | | | | | | | | | | | | | | In the case from the related QTBUG-106118, the ListView is declared before the ScrollView, so when the QObject destruction happens, it gets destroyed first. The ScrollView being destroyed causes the attached ScrollBar object to be destroyed, which causes the attached object to access the flickable (ListView) which has already been destroyed. So a workaround for the crash is to declare the ListView after the ScrollView. With typical usage where ScrollView is used as-is, ScrollView (and hence QQuickScrollBarAttached) is destroyed before the flickable. This patch also adds a PRINT_LISTENERS debugging helper, as item change listener crashes can be difficult to debug. Fixes: QTBUG-106106 Pick-to: 6.2 6.4 Change-Id: I8d0d5544ea28c1f1557abdc38d48b26d21a7f1f5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Add live property to QQuickItem layerKristoffer Skau2022-09-081-0/+6
| | | | | | | | | | | | QQuickItemLayer now has a live property that can be set to determine if its contents should change whenever the item updates. This enables variable refresh rate for quick items. [ChangeLog] Added live property to QQuickItem layer. Fixes: QTBUG-77343 Change-Id: I8bf7e7af4cfed6deef2253d346bb0b72d0fef66e Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Reduce QQuickItemPrivate memory usageFabian Kosmale2022-08-111-45/+45
| | | | | | | | | | | | | | | | | | - Avoid mixed type bitfields: There are compilers which generally support bitfields, but will not combine members if the type is different. Requires explicitly casting bitfield members to bool in a few places to avoid ambiguous overloads. - Move all containment mask members into extraData: extraData will be allocated anyway to store the contains meta-method, so we might as well move the mask pointer there. - Do not store quickMask separately; instead, cast mask to QQuickItem on demand. qobject_cast<QQuickItem *> is fast, as it only has to check a single flag. - Do not store a QMetaMethod for the mask's contains method. Instead store only the index, and retrieve the metaObject on demand. Change-Id: Ib2120c3b01ea037eb17c6c903a2977c38cd6c40c Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QQuickItemPrivate::handlePointerEvent: avoid passive grabbers tooShawn Rutledge2022-07-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | ...if avoidGrabbers == true. When allPointsGrabbed() was implemented incorrectly and HoverHandlers took passive grabs, QQuickDeliveryAgentPrivate::deliverUpdatedPoints() delivered subsequent mouse moves to HoverHandlers because of their passive grabs, while the loop at the bottom that was to deliver to remaining handlers depended more on whether any exclusive grab was taken by any other item or handler (because there weren't any remaining HoverHandlers, they all had passive grabs; and if any point had an exclusive grab, allPointsGrabbed() returned false). In practice, that loop seldom ran. But now we want it to run and deliver hover events to HoverHandlers, which no longer take passive grabs. While doing so, any PointerHandler that _does_ have a passive grab would get visited an extra time, if we did not rule it out. We already visited those handlers in the middle part of deliverUpdatedPoints(). Pick-to: 6.3 6.4 Task-number: QTBUG-101932 Change-Id: I91ee19ec1adf410b9e97e2aa954cdf2e181a237b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Use SPDX license identifiersLucie Gérard2022-06-111-38/+2
| | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Pick-to: 6.4 Task-number: QTBUG-67283 Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Export private QQuickKeyEvent and QQuickKeysAttachedAndrei Golubev2021-12-111-1/+1
| | | | | | | | | Qmltc needs those exported as it generates code that directly uses objects of those classes. If I recall correctly, in `Key.onPressed` and cases that involve key events Change-Id: Ib9cd5209fd4c969ae5c80813a6b141be50931abb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow reparenting Pointer HandlersShawn Rutledge2021-12-101-0/+2
| | | | | | | | | | | | [ChangeLog][Event Handlers] The parent property of any Pointer Handler is now settable. Fixes: QTBUG-84730 Task-number: QTBUG-85926 Task-number: QTBUG-17286 Change-Id: Id738dd783de1acfbef9b5be203025040b0913008 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix setting the focus reason in Qt Quick ControlsVolker Hilsheimer2021-12-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Focus might go to the content item, which is a QQuickItem that has no concept of either focusPolicy or focusReason. For Qt Quick Controls to update the focusReason property when an item in it's item tree receives or loses focus, it has to install itself as a notification listener on the item. However, QQuickItemChangeListener didn't have any notification type for focus changes. Add the new change type, and notify listeners whenever the an item's focus changes. Focus scoping might mean that an item never loses focus, but nevertheless loses active focus. To be able to update items recursively with the correct focusReason, add the reason parameter to the QQuickDeliveryAgent helper function. Fixes: QTBUG-75862 Pick-to: 6.2 Change-Id: I3d19b722bb07b55416b8cfbb4a9cdb0edd0da3ec Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Refactor: move change listener notification logic into helpersVolker Hilsheimer2021-12-041-0/+27
| | | | | | | | | | | | | | | | | | A dozen loops doing more or less the same, all with the comment "intentional copy (QTBUG-54732)", are best factored out into a helper. Most of the loops call a different QQuickItemChangeListener member, so provide a template that expects a pointer to a QQuickItemChangeListener member function. Some loops have some additional logic, so provide a second template that just calls a functor. No functional change, but needed for follow-up fixes to focus reason handling in Qt Quick Controls. Pick-to: 6.2 Change-Id: I6b11e06331da44b288315fc0732009d5f34f539a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Allow any Item to act as a viewport for any of its childrenShawn Rutledge2021-11-291-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The children that have the ItemObservesViewport flag set will have transformChanged() called whenever any parent moves, and can use clipRect() to avoid creating SG nodes that fall outside the viewport. So now the viewport can be narrower than the whole QQuickWindow; but the fallback is the window. It was always unclear why we had both boundingRect() and clipRect(), returning the same rectangular areas. Now clipRect() can actually be used for a rough pre-clipping, to limit the amount of vertex data going into the scene graph, which can save a lot of memory in some cases. setClip() sets the ItemIsViewport flag, for the sake of making it easy to do viewporting without writing C++; but it's well known that scissoring has a performance impact, so we recommend that users who are writing C++ anyway can set the flags in C++ rather than in QML. In case there are nested items with both flags ItemIsViewport and ItemObservesViewport, calling clipRect() on something inside the innermost viewport is recursive: we intersect all the viewports, going up the hierarchy to the window. So it's possible for the innermost item to be clipped down to a small "iris" where all the viewports are letting "light" pass through. [ChangeLog][QtQuick][QQuickItem] QQuickItem::clipRect() now provides the region visible in the viewport, and can be used to limit SG node vertices as an optimization in custom items, at the cost of having updatePaintNode() called more often. See docs about the new ItemObservesViewport and ItemIsViewport flags. Fixes: QTBUG-37364 Task-number: QTBUG-60491 Task-number: QTBUG-65741 Task-number: QTBUG-77521 Task-number: QTBUG-90734 Change-Id: I71a26c2dab4e991d7fb0f6679f1aa0c34e7a14ee Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Large Text: populate only lines visible in Window into SGShawn Rutledge2021-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Text is rendered top-to-bottom: QQuickTextNode::addTextLayout() iterates lines of text. Now it first maps the window size() rectangle into the Text item's coordinate system, and treats that as the viewport: lines whose y coordinates fall outside are omitted. This saves a huge amount of time and memory when the text is large. So Flickable { Text { } } can actually be used in an ebook reader now, for example. QQuickItemPrivate::transformChanged(parent) is now used to inform all children when a parent moves; so e.g. when a content item is moved inside a "viewport" item (like a Flickable, or any other item that is being used as a clipping viewport or just as a holder), all children of the content item will be notified; and QQuickTextPrivate uses this occasion to mark itself dirty so that the updatePaintNode() will be called again. This happens directly after the actual movement: QQuickTextPrivate::transformChanged qquicktext.cpp 2990 QQuickItemPrivate::transformChanged qquickitem.cpp 5200 QQuickItemPrivate::dirty qquickitem.cpp 6339 QQuickItem::setY qquickitem.cpp 6830 QQuickFlickablePrivate::setViewportY qquickflickable.cpp 1800 Task-number: QTBUG-60491 Task-number: QTBUG-90734 Change-Id: I152d23caa725f194a186a604fbc8d0c07f597b16 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Add invokable QQuickItem::dumpItemTree()Shawn Rutledge2021-09-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's possible to do something like this in JS code with a for loop (and now we have docs explaining how!); but it can also be handy to do it from C++ code, including in autotests. It simply uses the QQuickItem debug operator, recursively, with indentation to show the nesting. Similar to QObject::dumpObjectTree(), but the item tree can be different. Output from one of the repeater autotests now looks like this (only when the qt.quick.tests logging category is enabled): === item tree: QQuickRootItem(0x55bcd3e45770) QQuickRectangle_QML_0(0x55bcd3e70bc0) QQuickColumn(0x55bcd3e710d0, name = container) QQuickRectangle(0x55bcd3e71450, name = item1) QQuickText(0x7f35d800cc80, name = text1) QQuickRectangle(0x55bcd3e74020, name = item2) QQuickText(0x55bcd3e743a0, name = text2) QQuickRectangle(0x55bcd3e7c250, name = item3) QQuickText(0x55bcd3e7c620, name = text3) QQuickRepeater(0x55bcd3e7f160, name = repeater) === object tree: QQuickView:: QQuickRootItem:: QQuickDeliveryAgent:: QQuickRectangle_QML_0:: QQmlObjectModel::itemModel1 QQuickRectangle::item1 QQuickText::text1 QQmlObjectModelAttached:: QQuickRectangle::item2 QQuickText::text2 QQmlObjectModelAttached:: QQuickRectangle::item3 QQuickText::text3 QQmlObjectModelAttached:: QQmlObjectModel::itemModel2 QQuickRectangle::item4 QQuickText::text4 QQmlObjectModelAttached:: QQuickRectangle::item5 QQuickText::text5 QQmlObjectModelAttached:: QQuickColumn::container QQuickRepeater::repeater QQmlEngine:: QQuickFontValueType:: QQmlComponent:: which shows that Repeater normally reparents the items that it creates to _its_ parent, but these items have QQmlObjectModels as their QObject parents because of being declared that way. [ChangeLog][QtQuick][QQuickItem] dumpItemTree() has been added; it can be called from C++ (similar to QObject::dumpObjectTree()) or from QML, to show the qDebug-operator output for an item and all its children, indented to show the tree structure. Task-number: QTBUG-66771 Change-Id: I70410b19610b621fd1bb35d00575d7001efa6580 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Make QQuickItem containmentMask be dependent on positionIgor Bugaev2021-07-021-0/+1
| | | | | | | | | | | | | [ChangeLog][QQuickItem] Previously, containmentMask's position was ignored. If containmentMask parent inherit from QQuickItem, then position will take into account. In some cases, this is useful, for example, to make click on button larger than the size of the button itself, in all directions, not just to the right and bottom. Fixes: QTBUG-82678 Pick-to: 6.2 Change-Id: Iec70352db2d866198713a72d4d589a06105f30bc Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* QQuickItem::{width,height}Valid: correctly handle binding being undefinedFabian Kosmale2021-06-301-2/+2
| | | | | | | | | | | | | The width/height is valid if we have a binding, unless the binding' value is actually undefined. In that case, the width/height has been reset. We still need to keep the binding, as it might change to a defined state. Thus we need to explicitly check in the undefined case whether the binding might be undefined. Pick-to: 6.2 Fixes: QTBUG-94703 Change-Id: I0fd4ac608fdf4eeab09bb2c092045ef803233adc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQuickItemPrivate: Make {width,height}Valid a functionFabian Kosmale2021-06-301-2/+5
| | | | | | | | | | There is now some additional logic, so we cannot simply rely on the boolean flag. Task-number: QTBUG-94703 Pick-to: 6.2 Change-Id: Id4674efd205a58b015a82b3c06e63c8a031f6607 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQuickItem: Make x/y/width/height bindableFabian Kosmale2021-06-031-4/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This ports the four properties properties to Q_OBJECT_COMPAT_PROPERTY. It is not possible to use Q_OBJECT_BINDABLE_PROPERTY, not even for the simpler x and y properties, as QQuickItem calls the virtual geometryChange method in the setters, making them non-trivial. For width/height, we use the new property system to improve the width/heightValid check: We return not only valid if the property has explictily been set (either via a direct setter call, or because the setter has been called when a binding evaluated), but also when a binding is set. This matches the fact that implicitWidth/Height should only be used when width/height is not specified. In theory, this could help in cases where one sets both implicit and explicit properties for Text, skipping one initial layout calculation. As the setters now remove the binding (this aligns with the behavior of writing through the meta-object system), a few test cases had to be adjusted, which relied on the setter not removing it. Further test changes were necessary because the location of a few warnings changed, due to differences in binding order evaluation and error reporting. [ChangeLog][QtQuick][QQuickItem] The x, y, width and height properties of QQuickItem are now bindable. This enables modifying their bindings from C++. One could for instance swap the width of two items, preserving the bindings: // QML Item { Rectangle { id: a; width: parent.width / 2 } Rectangle { id: b; width: parent.width / 3; anchors.right: a.left } } // C++ auto rootCtxt = engine.rootContext(); auto a = qobject_cast<QQuickItem*>(rootCtxt->objectForName(u"a"_qs)); auto b = qobject_cast<QQuickItem*>(rootCtxt->objectForName(u"b"_qs)); auto aBinding = a->bindableWidth().takeBinding(); auto bBinding = b->bindableWidth().takeBinding(); a->bindableWidth()->setBinding(bBinding); b->bindableWidth()->setBinding(aBinding); Afterwards, if the root item gets resized, the width of the rectangles will still be adjusted. [ChangeLog][QtQuick][QQuickItem][Important Behavior Changes] Calling the setWidth, setHeight, setX and setY properties now removes any existing binding from the corresponding property. Change-Id: I5e1553611cb92b033247ada715cea48c962395bc Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix click-to-focus in items within subscenes; improve loggingShawn Rutledge2021-03-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the ability to focus an item by clicking (such as a TextInput) when it's part of a subscene mapped to a 3D object in Qt Quick 3D, even if there are multiple subscenes with focusable items. QQuickDeliveryAgentPrivate::setFocusInScope(subsceneRoot, textInput) for example did not succeed; for one thing, this check fails: // Does this change the active focus? if (item == rootItem || scopePrivate->activeFocus) { because in a 3D scene, so far the viewport has focus by default, so the given scope (subscene root) does not have active focus. Each window ultimately has one actively focused item, so we need to delegate to the delivery agent belonging to the window's root item, to set its active focus. It's not even clear whether it's really a good idea for each subscene delivery agent to have its own QQuickDeliveryAgentPrivate::activeFocusItem. It might give us flexibility: perhaps each subscene root item should be a focus scope, and each delivery agent should decide which item would be hypothetically focused if the whole subscene got focus. But for now, it seems enough to set the activeFocusItem on the root item of the whole scene. Another problem was that when QQuickItem::forceActiveFocus() goes up the parent hierarchy, it didn't find a focus scope. So when you clicked on a TextInput that already had its focus property set to true, 1) QQuickItem::setFocus() does nothing because d->focus is already set 2) QQuickItem::forceActiveFocus() did not find a parent focus scope Therefore neither of them changed anything, and it wouldn't get active focus. Setting the ItemIsFocusScope flag on each subscene root item fixes (2), and that seems to be enough for now. Another problem was that QQuickWindow::event() was calling QQuickDeliveryAgent::grabberAgent() even when delivering an event that is NOT a press event, in spite of the comment "When delivering _update_ and _release_ events to existing grabbers, use the subscene delivery agent, if any." A hover event often results in a HoverHandler getting a passive grab, but that passive grab is not a reason to deliver a subsequent press event to the same subscene. When the mouse moves, we need to start over with picking in the 3D scene. When the 60fps frame-synchronous hover event occurs, we need to start over with picking, in case 3D objects are being animated under the cursor. When a press occurs, we need to start over with picking in case the press occurs in a different location from the last hover (even though that's unlikely with a mouse, it happens easily with a touchscreen). Another problem was that QQuickItemPrivate::deliveryAgent() was not finding the subscene DA during delivery of key events. A child item's extra is often not allocated, but we still need to keep looking at the parents. The optimization from 68c103225f4e8bd6c1b18ef547108fd60f398c0f was also wrong: after an Item's default initialization, we always need to do the search for the subcene DA. Only if we are sure that the item is NOT in a subscene (as in all normal 2D scenes) we can avoid doing that search next time. Consolidate the number of lines of output in the qt.quick.focus logging category and show the activeFocusItem transition. As with most logging in Qt Quick, it's expected that you set QT_MESSAGE_PATTERN to include %{function} so that you can always see where each line comes from. Therefore the log output itself has only minimal context (as in "q focus item x in scope y") rather than repeating the function name. Pick-to: 6.1 Change-Id: I1b2a989c02c58c966653f965c0de512aa641bb99 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* Move event delivery from QQWindow to QQuickDeliveryAgentShawn Rutledge2021-02-241-0/+8
| | | | | | | | | | | | | | | | | | | | QQuickWindow owns QQuickRootItem which owns QQuickDeliveryAgent, so for every window there's an object responsible for event delivery, while the window itself is mainly responsible for rendering (separation of concerns). However, QQuickRootItem and QQuickDeliveryAgent can now be used in cases where the scene doesn't directly belong to a window, such as when a Qt Quick sub-scene is mapped somewhere into a Qt Quick 3D scene. In that case, we must remember which delivery agent was in use at the time when a QEventPoint is grabbed and deliver subsequent updates via the same DA. There's also a QQuickDeliveryAgent::Transform abstraction which subscene-management code (such as QQuick3DViewport) can implement, to provide a formula to map the window's scene coordinates to subscene coordinates; if defined, it will be used during delivery of subsequent updates to existing grabbers. Task-number: QTBUG-84870 Change-Id: I70b433f7ebb05d2e60214ff3192e05da0aa84a42 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* Use QMutable*Event classes to copy and synthesize eventsVolker Hilsheimer2020-11-181-1/+1
| | | | | | | | | | QMutableTouch/SinglePointEvent can be publicly copy constructed from their non-mutable counterparts, make use of that. Change-Id: I7f56a9f9649bb7726cca1eaddccfdc3f21d47554 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QQmlListProperty: Use qsizetype rather than int for sizesUlf Hermann2020-11-091-10/+10
| | | | | | | | | | [ChangeLog][QtQml] The QQmlListProperty callback functions use qsizetype now as type for the size of a list. This is in line with the containers that you might use to back the list. Fixes: QTBUG-88269 Change-Id: Ia38403cb32f241e6c70e1a580dbeff1d6d694331 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Remove QQuickPointerEvent etc.; deliver QPointerEvents directlyShawn Rutledge2020-09-181-2/+3
| | | | | | | | | | | | | | | | | | | | | | | QEventPoint does not have an accessor to get the QPointerEvent that it came from, because that's inconsistent with the idea that QPointerEvent instances are temporary, stack-allocated and movable (the pointer would often be wrong or null, therefore could not be relied upon). So most functions that worked directly with QQuickEventPoint before (which fortunately are still private API) now need to receive the QPointerEvent too, which we choose to pass by pointer. QEventPoint is always passed by reference (const where possible) to be consistent with functions in QPointerEvent that take QEventPoint by reference. QEventPoint::velocity() should be always in scene coordinates now, which saves us the trouble of transforming it to each item's coordinate system during delivery, but means that it will need to be done in handlers or applications sometimes. If we were going to transform it, it would be important to also store the sceneVelocity separately in QEventPoint so that the transformation could be done repeatedly for different items. Task-number: QTBUG-72173 Change-Id: I7ee164d2e6893c4e407fb7d579c75aa32843933a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Privately export QQuickItemLayerLaszlo Agocs2020-09-131-1/+1
| | | | | | | Required by Quick 3D. Change-Id: I0da6aa8163da71b2d27cb0e358473aa5ecc85a1f Reviewed-by: Andy Nichols <andy.nichols@qt.io>
* Quick: Clean up some includesUlf Hermann2020-06-041-21/+18
| | | | | | | Uniformly use <...> and sort them by modules. Change-Id: I11cd160783dfb141d8824d635bdc56a63aaee50f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* Replace QFlagPointer with QTaggedPointerSimon Hausmann2020-04-031-3/+12
| | | | | | | | The latter has the advantage of allowing the use of a real type for the tag, instead of the generic flag/flag2 boolean accessors. Change-Id: Icc9e854ce4af3eb5808a4bed45aa22f377e223da Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Introduce new mechanism to manage palette functionality in QMLVitaly Fanaskov2020-03-161-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Main goals of these changes: 1) Add an ability to work with disabled and inactive palettes from QML 2) Eliminate massive code duplication in qtquickcontrols2 module 3) Provide easily extensible architecture for this piece of functionality Architectural part. Palette It was decided to not change existing QPalette, but add thin wrappers around it to provide all required functionality. These wrappers are highly coupled with QPalette class because of using some enum values from it. There are two new classes QQuickPalette and QQuickColorGroup. QQuickPalette class inherits QQuickColorGroup class and represents Active/All color group. QQuickPalette also provides an access to three color groups: Active, Inactive, and Disabled. In order to access colors the special class QQuickPaletteColorProvider is used. This is a wrapper around QPalette that provides some convenience functions. Interface The private property "palette" should be exposed. Implementation All private parts of classes that implement QQuickAbstractPaletteProvider have to inherit QQuickPaletteProviderPrivateBase class. This template class implement all functionality: create palette, resolve dependencies, connect objects etc. This is important to mention that related data is lazily allocatable on demand only. Hence, there is no memory overhead for regular items. Change-Id: I911424b730451b1ad47f68fd8007953b66eddb28 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add major version to all Q_REVISIONsUlf Hermann2020-02-191-1/+5
| | | | | Change-Id: Id72fbe10c16de61bd847773d0055d83cfe03f63c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add PointerHandler.cursorShape propertyShawn Rutledge2020-01-311-0/+5
| | | | | | | | | | | | | | | | | | Also, QQuickItemPrivate::setHasCursorInChild() was unable to check the QQuickItemPrivate::hasCursor variable, because the function argument hasCursor was shadowing that, even though the comment "nope! sorry, I have a cursor myself" hints that the intention was to check that. So this change exposed a problem there, and we have to fix that too, in order to keep the tst_qquickwindow::cursor() test passing. [ChangeLog][Event Handlers] Pointer Handlers now have a cursorShape property to set the cursor when the handler is active and the mouse is hovering, and restore to the previous cursor when the mouse leaves. Fixes: QTBUG-68073 Change-Id: Ib5c66bd59c4691c4210ee5465e1c95e7bdcf5ae1 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QQmlListProperty: Add replace and removeLast functionsUlf Hermann2020-01-151-1/+1
| | | | | | | | | | | This allows us to implement QmlListWrapper::virtualPut(). Also, the additional functions make the list properties useful in other contexts. Fixes: QTBUG-79263 Change-Id: I528bc69222ca7743f0fc3697c3aed2a3468b4d87 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Merge remote-tracking branch 'origin/5.14' into 5.15Qt Forward Merge Bot2020-01-091-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: src/particles/qquickitemparticle.cpp src/qmlmodels/qqmladaptormodel.cpp tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp Change-Id: Ibd8fbb91da6893a09f4ffe61ad0b95d8149bbc87