summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
Commit message (Collapse)AuthorAgeFilesLines
* QtWidgets: restore Qt 5 compatibility for save/restore stateGiuseppe D'Angelo2022-05-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | Several classes in QWidget use QDataStream internally in order to save and restore state. These QDataStream usages were not versioned, meaning that if Qt changes the serialization for some datatype, then the data saved between different Qt versions becomes incompatible. Note that the save/restore API in question just produce opaque blobs as QByteArrays -- the user has no control over the QDataStream objects and thus versions. Fix by version the usages. In QHeaderView this has caused a regression because QBitArray *did* change version between Qt 5 and 6. In general, using QDataStream without explicit versioning is a mistake, so deploy the same fix elsewhere as well. Fixes: QTBUG-99487 Pick-to: 5.15 6.2 6.3 Change-Id: I82bb5c266f4e5dedc0887cbef855dccab1015e29 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: <doctor.whom@gmail.com>
* Use SPDX license identifiersLucie Gérard2022-05-1650-1901/+101
| | | | | | | | | | | | | 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. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Item widgets: clean up treatment of Qt::TextAlignmentRole / CheckStateRoleGiuseppe D'Angelo2022-05-166-8/+112
| | | | | | | | | | | | | | | | | | | | | | | The item widgets all have an API flaw: getters and setters for the text alignment deal with int instead of Qt::Alignment. Deprecate the existing setters and introduce others taking Qt::Alignment. Store the alignment directly into the item widget (now that views know how to handle it). We can't change the getters without cluttering the API, so make that a Qt 7 change. Users can prepare by forcibly casting the return value to Qt::Alignment; this is going to work in Qt 6 and 7. While at it: streamline the handling of Qt::CheckStateRole as well, avoiding to rely on a pointless Qt::CheckState to int conversion through QVariant (the setter stores a Qt::CheckState, but the getter retrieves an int and converts it to a Qt::CheckState). Task-number: QTBUG-75172 Change-Id: I9f29e818e93cb2dc1d8e042bc320162c2f692112 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemDelegate: fix rect given to tooltip handingDavid Faure2022-05-091-6/+1
| | | | | | | | | | | | | | | | | | | * The rect passed to QToolTip::showText() is in view coordinates, not in global coordinates. * Determining this rect in the first place doesn't need calling view->visualRect(index) The view already did this before calling this method, and stored it in option.rect, so just use that. * The widget passed to QToolTip::showText() should be the viewport, that's what option.rect is relative to (thanks Giuseppe!). Found these issues when implementing my own tooltip handing (for a subrect of a delegate) by looking at this code. Pick-to: 6.3 6.2 5.15 Change-Id: I852e5409def28da98137cd0c4c996083e5e45706 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QAbstractItemView: check the index emitted by the delegate's sizeHintChangedGiuseppe D'Angelo2022-04-283-6/+18
| | | | | | | | The index in question has to belong to the view's model. An erroneous emission shouldn't be silently ignored. Change-Id: I7e037e72affb210f609a9a1029777acafae041f1 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemView: warn in some erroneous conditionsGiuseppe D'Angelo2022-04-271-2/+6
| | | | | | | | | | | | | If a user or a delegate asks a view to act on an editor that does not belong to the view, report a warning instead of silently ignoring the problem. This erroneous condition can happen for instance if a user installs the same delegate on multiple views (something that the documentation says _not_ to do) and the delegate indeed emits signals related to the editors of one view -- the other views don't know about that editor. Change-Id: I2d10582ebb7aefca4acea306b8a57bcc3162050a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QtWidgets: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-262-2/+2
| | | | | | | | | | | Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. As a drive-by, fix qsizetype -> int narrowing conversion warnings for the touched lines. Change-Id: I133b80334b66e0a5ab9546dd8e1ff0631e79601e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTableView: Document the customizations applied to QHeaderViewSze Howe Koh2022-03-291-0/+2
| | | | | | | | | | | These are non-default options which the user needs to manually set when applying a custom QHeaderView. Task-number: QTBUG-102034 Pick-to: 6.3 6.2 5.15 Change-Id: Ib3396f0a82c358c71a8501fc2d71158f725bc228 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* QAbstractItemView: with single selection, deselect on Ctrl+ReleaseVolker Hilsheimer2022-03-241-9/+22
| | | | | | | | | | | | | | | | | After cbf1b4bc60bca3994b8f8685ee922e53a6b4eed2 the selected item got deselected on Ctrl+Press, which made Ctrl+dragging a selected item impossible. Only deselect on Ctrl+Release. Add scenario to existing test case, and update the documentation to clarify the properties involved, and to point out that the event parameter might be nullptr. Fixes: QTBUG-101647 Pick-to: 6.3 6.2 Change-Id: I749b1cb1a0a311f5c1d4c333984716f05f2c90b5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Volker Enderlein <volker.enderlein@ifm-chemnitz.de> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Itemviews: start fixing mixups of int/enum for Qt's item rolesGiuseppe D'Angelo2022-03-234-9/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | A model is supposed to return a Qt::CheckState for a CheckStateRole, and a Qt::Alignment for a Qt::TextAlignmentRole. This is what the documentation says (and what makes sense), but unfortunately Qt's default delegate expected a plain `int` instead. This sometimes worked (via QVariant conversions, e.g. when using a plain enum) and sometimes didn't (e.g. when using a flag type). This is confusing for end-users (and type unsafe, killing the whole point of using enums and flags in the first place). Adding some automatic flags<->int conversions through QVariant is frowned upon, so I don't want to go there. Instead, add some private convenience functions that extract either the right type from a variant, or try to extract an `int` and convert it to the expected type. Use these from within itemviews code. Change-Id: I44bee98c4a26a1ef6c3b2fa1b8de2edfee7aef32 Pick-to: 6.2 6.3 Fixes: QTBUG-75172 Task-number: QTBUG-74639 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Make sure all qtbase private headers include at least one otherThiago Macieira2022-02-241-0/+1
| | | | | | | | | | See script in qtbase/util/includeprivate for the rules. Since these files are being touched anyway, I also ran the updatecopyright.pl script too. Change-Id: Ib056b47dde3341ef9a52ffff13ef677e471674b6 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Core: Remove 'properties' featureKai Köhne2022-02-142-22/+0
| | | | | | | | | | | | | Even QtCore alone cannot be built without the properties feature since Qt 5.5. While fixing this is easy, other modules like dbus, networking are also using QObject::property() and friends liberally. All in all I doubt that anybody will miss the feature (otherwise it would have been fixed in the last decade). Change-Id: Iaf3cc20bda54ee2ff3b809fac8fa82b94ecc88c0 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Always update pressedPosition when drag was enabledZhang Hao2022-02-101-12/+13
| | | | | | | | | | | | | | | | | | | | | | | Since e02293a76d21e7077f1952d4ed8af6c6d1970190 and 2e0c29a4bbe2b3ae427137e65f179b0550dcf169 was committed, If a item width more than others,the selectionRect.x() always consist of currentStartSelection item's rect.center().x(),this will cause selectionRect size is not right. Because the code of 2e0c29a4bbe2b3ae427137e65f179b0550dcf169 is to fix the new bug introduced by e02293a76d21e7077f1952d4ed8af6c6d1970190, we need to use a better way to solve QTBUG-78797. When itemview enable drag,we need always update pressedPosition because pressedPosition was used to determine the drag distance, otherwise keep previous logic. Fixes: QTBUG-78797 Fixes: QTBUG-81542 Fixes: QTBUG-99512 Pick-to: 6.2 6.3 Change-Id: Ibc5020e35b0eb319e4b5546bdba39ff527c209a6 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QAbstractItemView: do not access invalid model indices (3/N)Giuseppe D'Angelo2022-02-021-7/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | The slots connected to rowsAboutToBeRemoved and columnsAboutToBeRemoved attempt to find a new current index by scanning the model around the existing current index -- in case that index is indeed about to be removed. The problem is that the scanning was done without any sorts of bounds checking; instead it was relying on the model's index() to return an invalid index for an out of bounds request. Fix that by adding bounds checking. Since models are not supposed to return invalid indices for in-bounds index() calls, added some warnings if that happens. For some reason, the code handling rows and columns isn't perfectly symmetrical. Rows are searched both forwards and backwards, while columns only backwards, and the related code is slightly different. Filed QTBUG-100273 to try and understand what's going on. Change-Id: I7452d8c521e74daa4408e6cc969ce5a6059f53ea Pick-to: 5.15 6.2 6.3 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QAbstractItemView: do not access invalid model indices (2/N)Giuseppe D'Angelo2022-02-011-0/+2
| | | | | | | | | Similar to the parent patch, the private selectAll() was doing two out of bounds accesses on an empty model. Guard it. Change-Id: If0f3ce1e6c44a152791313e47db79985e71ef955 Pick-to: 5.15 6.2 6.3 Reviewed-by: David Faure <david.faure@kdab.com>
* QAbstractItemView: do not access invalid model indices (1/N)Giuseppe D'Angelo2022-02-011-1/+2
| | | | | | | | | | Calling selectAll() on a view with an empty model, with the view in ContiguousSelection, causes an out of bounds access into the model. Guard the access. Change-Id: I3830a979bad760e9e1526c1c8b12d9767d41fc99 Pick-to: 5.15 6.2 6.3 Reviewed-by: David Faure <david.faure@kdab.com>
* QAbstractItemView: code tidiesGiuseppe D'Angelo2022-02-011-4/+12
| | | | | | | | | In preparation for an upcoming fix, refactor an if over an enumerator to a switch (which is how this code should've been to begin with). Change-Id: I11a2de6d66f0359b985b587b7fd37022a7bf56e6 Pick-to: 5.15 6.2 6.3 Reviewed-by: David Faure <david.faure@kdab.com>
* QTableWidgetSelectionRange: make relational operators noexceptMarc Mutz2022-01-211-4/+4
| | | | | | | | Also remove the superfluous inline keyword. Pick-to: 6.3 Change-Id: I2cd2fc46687626a6f9eab60553bc3022c7eed6de Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QtWidgets: auto-test-export private classes, unbreaking ubsan buildsMarc Mutz2021-12-161-1/+1
| | | | | | | | | | | | These classes are used in their respective tests, but since these only seem to access data members, the missing export macro was never detected. UBSan, however, checks the type_info on each access, so it needs the (polymorphic) class exported. Do so (for -developer-builds). Change-Id: I97b41cfb5dd7f1665cdf4f7a819a42fbf0388621 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix item view auto-scrolling during drag'n'dropVolker Hilsheimer2021-12-101-8/+24
| | | | | | | | | | | | | | | | | | | | Amends 71aaf831d175a164b508ce169131a794d55d6fb0, which wrongly assumed that dragMoveEvent will be called and update the dragged position as we scroll the viewport. This is not the case, so we have to do so manually when the view is in DraggingState. Since dragMoveEvent cannot be faked, and since we cannot fake a mouseMoveEvent (it would throw off the drag'n'drop state machine), calculate the new draggedPosition based on old position and the new offset. As with all drag'n'drop, we cannot test this using an auto test. Task-number: QTBUG-96124 Fixes: QTBUG-98961 Change-Id: Ifcfc1a11aa7258ec4610a548a276b4dd4a814590 Reviewed-by: Zhang Hao <zhanghao@uniontech.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QTableWidget doc: remove wrong comment for itemExpanded()Christian Ehrlicher2021-12-081-3/+0
| | | | | | | | | | Since Qt5.1 (80fa4b6c8ef) expandAll() emits expanded() but within this change, the comment in itemExpanded() was forgotten. Pick-to: 6.2 Pick-to: 5.15 Change-Id: Ic487e5f8999d6af27a4747b861464058faf03889 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QListView: fix a broken qBoundGiuseppe D'Angelo2021-12-061-1/+1
| | | | | | | | | | | | | | | | | If a QListView's model is reset to an empty one, its columnCount() below the root is going to be 0. Therefore, the code was doing a qBound(0, d->column, -1) which is meaningless (high < low). Instead, do the two logical operations explicitly: first do an upper bound on d->column (using qMin) and then lower bound the result by 0 (using qMax). The code worked by chance, because 0 was eventually the correct number to use as a bound for d->column. Change-Id: Ic32077cdab01eaa715137c05ed1f9d66c8eb2f67 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTableView: correctly toggle column selection when scrolledVolker Hilsheimer2021-12-021-1/+1
| | | | | | | | | | | | | | | | We need to check whether the horizontal header's selection includes the index for the row at the top, rather than for row 0, as the index we check is based on the scrolled position of the header, so would never be included in the top row when the view is scrolled. This is correctly done in selectRow already. Add a test case that simulates selection of rows and columns by clicking on the header. Fixes: QTBUG-98444 Pick-to: 6.2 Change-Id: I2fa1b32bf75dc96225b40145b713bf7e2ffc29dd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Draw QTableView grid lines centered between table cellsTor Arne Vestbø2021-11-081-3/+5
| | | | | | | | | | | | | | | | We were reserving space between table cells corresponding to one logical pixel, which on retina screen results in two device pixels. By drawing the grid line with a cosmetic pen, we were only filling one of these pixels, leaving space for leftover pixel dust from earlier blits. By drawing with a non-cosmetic pen of size 1, and ensuring that the grid line is drawn at the center of the grid, we end up filling the entire grid line, without overdrawing the table cells. Pick-to: 6.2 Change-Id: I7f4d2b27380e5a3d221e265a25f7531fdc4a02b3 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* QAIV: Reset double-click flag in mousePressEventVolker Hilsheimer2021-11-051-0/+1
| | | | | | | | | | | | | | | Amends 17c1ebf8bfd254ff75cc55e335d1c1fb01da547f, which introduced logic that recognizes double clicks to avoid duplicate clicked() emits. If a slot connected to doubleClicked opens a dialog, then the release-event will not be seen by the item view, leaving the flag incorrectly set and preventing the next clicked signal. Fixes: QTBUG-97853 Pick-to: 6.2 5.15 Change-Id: Iced83e8c66a763672f522265435dc52a745227e4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QAbstractItemView: auto-scroll with selection rectangleVolker Hilsheimer2021-10-222-10/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | Some item views, such as QListView in icon mode, implement a selection rectangle with which the user can "lasso" items. So far, dragging that rectangle did not trigger auto scroll, so unless an item near the edge was selected, the user had to stop the lassoing and scroll manually to reach more items. Since QAbtractItemView implements auto scrolling for drag'n'drop, we can use that mechanism also when the selection rectangle is dragged. This requires some modifications: We need to make sure that scrolling the view during a drag-selection generates mouse move events so that the selection is extended and the rectangle is updated in subclasses. And we need to stop using QCursor::pos to get the position of the mouse pointer, as this makes the auto-scrolling untestable. Instead, record the mouse position last seen during a mouseMove or dragMoveEvent in content-coordinates (identical to pressedPosition). As a drive-by, fix some coding-style issues in nearby code. Done-with: Zhang Hao <zhanghao@uniontech.com> Fixes: QTBUG-96124 Change-Id: I426f786e5842ae9f9fb04e9d34dc6d3379a6207f Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* widgets: Fix typos in source code commentsJonas Kvinge2021-10-154-10/+10
| | | | | | Pick-to: 6.2 Change-Id: I22f71a53b0f7f0698450123343e25548c889c3e2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* widgets: Fix typos in documentationJonas Kvinge2021-10-122-2/+2
| | | | | | Pick-to: 5.15 6.2 Change-Id: I6b77f0ec043d08da3b7958d780dce9595daf97a6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Select a single range of cells in QTableView, away from merged cellsShawn Rutledge2021-10-121-7/+17
| | | | | | | | | | | | | | | | | | | | | - when there is no intersection between the current selection and the spans collection, get ranges for all cells, just as if no span exists - when there is an intersection between the current selection and the spans collection, get separate ranges for each cell (as before) This fixes the regular case of selecting multiple non-spanned cells after some cells are merged (get a single range for all cells instead of separate range for each cell). However, when selecting together a group of spanned and non-spanned cells, you still get a separate range for each cell. But this is normal behavior in similar applications; for example in LibreOffice, you cannot select and merge spanned and non-spanned cells: an error dialog tells you that it's not allowed. Done-with: Christos Kokkinidis Pick-to: 6.2 Fixes: QTBUG-255 Change-Id: Ic38f9a064a1f499825e7f750668013fc2dc564ba Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTableWidgetSelectionRange: Make it possible to compare for equalityVolker Hilsheimer2021-10-122-0/+22
| | | | | | | | | Add operators as hidden friends, add test case to make sure that basic value-type operations are possible with this type. Task-number: QTBUG-255 Change-Id: I7fbf453aa16084c0b2a0079487cacb4e092ff664 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QAbstractItemView: fix crash if setData() does a model resetDavid Faure2021-10-011-3/+10
| | | | | | | Task-number: QTBUG-96654 Pick-to: 6.2 Change-Id: I2dca4af387ef5ad549a1a41fba2bc6de217f4ea9 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QAbstractItemView: Fix IM input starting edit sessionVolker Hilsheimer2021-10-012-21/+94
| | | | | | | | | | | | | | | | | | | | | | | | | | | Item views can open an editor widget on the first key press, and need to take special care not to break input methods. The initial key press starts compositing by the system input method, which is then interrupted by the focus transfer to the editor. To solve this problem, the widget needs to keep focus while the initial composition is ongoing, and only transfer focus to the editor once the composition is either accepted or cancelled by the user. Add a state flag that is set during this initial preedit phase. During this initial composition, the item view will receive all input method events, and needs to forward these to the open, but not yet focused editor for the user to get the correct visual feedback during the preedit phase. The item view also needs to report to input method queries on behalf of the editor to make sure that the IM UI is correctly positioned without covering the user input. Implement a test that simulates the sequences through synthesized QInputMethodEvents; we can't simulate the entire system input stack. Fixes: QTBUG-54848 Change-Id: Ief3fe349f9d7542949032905c7f9ca2beb197611 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Fix QListView assert when the last row is moved in IconModeChunLin Wang2021-09-011-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | After the last row is moved, 0 will be returned when obtaining row and column data. At this time, QListView::doitemslayout will not call d->doitemslayout, so the QBspTree data structure will not be cleaned up, leaving a stale tree structure behind. This will trigger an assert during paintEvent handling if QListView is set to IconMode In QListView::ListMode the test for a valid model index doesn't use an assert. Call QListViewPrivate::clear explicitly if the column count is 0 so that the QBspTree and other data structures are cleared. Add a test case that simulates this scenario by implementing a model that returns a 0 column count for an index after the model structure was changed through a move of rows. Done-with: Volker Hilsheimer Fixes: QTBUG-95463 Pick-to: 5.15 6.1 6.2 Change-Id: I36419be5459b8ced930c619f538482ea1db4ad03 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Port to QImage and QPixmap deviceIndependentSize()Morten Sørvig2021-09-012-4/+4
| | | | | | | | | Replace the “size() / devicePixelRatio()” pattern with a call to deviceIndependentSize(). Change-Id: I9d9359e80b9e6643e7395028cd43e3261d449ae7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QListView: fix AdjustToContents (sizeAdjustPolicy)Thorbjørn Lund Martsum2021-08-101-1/+41
| | | | | | | | | | | | | | | | | | | | Unlike an acceptable effect in QTableView + QTreeView setAdjustPolicy(QAbstractScrollArea::AdjustToContents) unfortunately didn't work for QListViews (and QListWidget). This patch corrects QListViews AdjustToContents behavior. [ChangeLog][QtWidgets][QListView] A more correct implementation of QListView::viewportSizeHint has been made. That implies that setting the sizeAdjustPolicy to AdjustToContent on QListView and QListWidget will now cause the view to size after the contents and avoid scrollbars. Pick-to: 6.2 Task-number: QTBUG-58749 Change-Id: I1675115f2348e2fcf0b2c39b451ef337e10eb872 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Doc: Fix typo Ctr -> CtrlAlexander Volkov2021-07-281-1/+1
| | | | | | Pick-to: 6.1 6.2 Change-Id: I89c9526aa74b312dd67a6d194395b3298bbc31fe Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* emit layoutAboutToBeChanged timelyLuca Beldi2021-07-201-4/+8
| | | | | | | | | | | layoutAboutToBeChanged must be called before persistentIndexList as the user might create persistent indexes as a response to the signal Fixes: QTBUG-93466 Pick-to: 6.2 5.15 Change-Id: I73c24501f536ef9b6092c3374821497f0a8f0de4 Reviewed-by: David Faure <david.faure@kdab.com>
* QListView: don't scroll if selected items are removedVolker Hilsheimer2021-07-161-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | For SingleSelection, removing the selected item will select the nearest item and, if autoScroll is enabled, ensures that the newly selected item is visible in the viewport. This may result in scrolling. For Multi- or ExtendedSelection, this should not happen, as having no selection is perfectly fine in those modes. However, QListView still tried to scroll to the current item in response to the currentIndexChanged signal. Since the currentIndex is at this point already hidden, the rectangle for it became invalid, and the attempt to scroll resulted in a one-pixel up-movement of the viewport (since the invalid rectangle has width == height == -1). Fix this by not scrolling if the rect for the index is invalid. Note that the index is still valid at this point, so we can't shortcut the call stack earlier. Add test that exercises the different combinations of ViewMode and SelectionMode, and demonstrates the one-pixel movement without the fix. Fixes: QTBUG-94788 Pick-to: 6.2 6.1 5.15 Change-Id: I1f36973eadb46e8c9b8b8068bc76ee09e9f490dd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Consistent handling of disabled items in QItemSelectionModelAndreas Buhr2021-07-152-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | In QItemSelectionModel, items which are disabled or marked as not selectable should not be considered as selected. But this was not handled consistently. The following methods considered only items which are enabled and marked selectable: selectedIndexes(), rowIntersectsSelection(), and columnIntersectsSelection(). The following methods considered only items which are marked selectable, but did not check whether they are enabled: selectedRows(), selectedColumns(), isRowSelected(), isColumnSelected(), isSelected(). Finally there is hasSelection(), which did not check for enabled nor for selectable. This patch introduces consistent behavior. All methods check both whether the items are enabled and whether they are selectable now. [ChangeLog][QtCore][QItemSelectionModel][Important Behavior Changes] All methods in QItemSelectionModel now consider only items which are marked as enabled and selectable as part of the selection. Fixes: QTBUG-93829 Pick-to: 6.2 Change-Id: I4725243ea6b0db4f289ce34ada22c7a9d3282713 Reviewed-by: David Faure <david.faure@kdab.com>
* Initialize class members of QTreeWidgetItem at declarationAndreas Buhr2021-07-152-57/+15
| | | | | | | | | The members view, par, and itemFlags were initialized in each of its nine constructors. This patch moves the initilaization to the declaration to prevent this repetition. Change-Id: I71d136e7615dca5d87e8a4dc161c877633017ad0 Reviewed-by: David Faure <david.faure@kdab.com>
* Point out that QTreeView's expandAll/expandToDepth don't fetch dataVolker Hilsheimer2021-07-141-2/+11
| | | | | | | | | | | They will only expand what's currently in the model. As a drive-by, remove superfluous : after the \warning macro. Fixes: QTBUG-94981 Pick-to: 6.2 6.1 5.15 Change-Id: I85d38373fb7edf5a5407622b32870e7bcd5d9aeb Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QDuplicateTracker: accept the number of elements to reserve as a ctor argumentMarc Mutz2021-07-141-2/+1
| | | | | | | | | | | | This prevents us from first reserve()ing Prealloc elements, and then possibly reserve()ing a larger number, which leaves the first bucket list's memory unused. Consequently, deprecate reserve(). Change-Id: Ifc0a5a021097f4589557e7b5e45d9d0892797ade Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use RAII object to skip pending sorts in QTreeWidgetAndreas Buhr2021-07-122-19/+9
| | | | | | | | | | | | | Cleanup: This patch does not change functionality. In several places, sorting inside of the QTreeModel is disabled and afterwards restored. There is a RAII class for this, which is used in some places, but not in others. This patch introduces more consistent usage of this RAII object. Change-Id: I9802998ad31d0f9d4417824f72ff0abbb0c38a17 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QTableView: fix selection with rows and cells in ExtendedSelection modeChristian Ehrlicher2021-07-122-5/+4
| | | | | | | | | | | | QTableView stored the current row/column selection start in an own variable instead using currentSelectionStartIndex. This leads to an inconsistent behavior when the selection is done with a click on the header and then in a cell (and the other way round) Fixes: QTBUG-92561 Change-Id: I4c8bda3a938de451b6eff2819141e86a6870fbef Pick-to: 6.1 6.2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* add todo comment for Qt 7Andreas Buhr2021-07-091-0/+2
| | | | | | Task-number: QTBUG-94546 Change-Id: I86a40dcb2b6e33140c31acc450bcd47fa6ff3f2d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Consistent indentation for all Q_PROPERTYsAndreas Buhr2021-06-243-7/+14
| | | | | | | | Task-number: QTBUG-94407 Pick-to: 6.2 Change-Id: I8c97a0b2de2bed78456322be271724fc47479d83 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add a style hint to draw the left/top border lines when header is hiddenAndy Shaw2021-06-161-0/+22
| | | | | | | | | | | | Since there is no header then the cells appear with no actual border so it can look a bit strange without it. This ensures that the border is at least shown when there is no header to represent it if the style hint is turned on. This gives an option for those who want it to have it turned on. Fixes: QTBUG-85523 Change-Id: Ib94874bddddd31738fbcd41c6f77a2e0fa2ef443 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAIV: Don't open editor on release when press closed editorVolker Hilsheimer2021-06-142-2/+18
| | | | | | | | | | | | | | | | | A mouse press that transfers focus from an open editor back to the view will close the editor. To prevent that the corresponding release then opens the same editor again we need to know that the closeEditor call was caused by the mouse press. Since Qt first generates the focusOut event, and then delivers the mouse press, we have to start a zero-timer to check whether we are in the same event delivery process. If so, ignore the corresponding release. Add test case that simulates that chain of events. Fixes: QTBUG-20456 Pick-to: 6.2 6.1 Change-Id: I28fa32bfbc776db207c594c329961f575ae58ea9 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* Check scrollbar ScrollBarOverlap when computing QListView marginsZhang Hao2021-06-101-0/+1
| | | | | | | | | | | | | | | | | When the listview setWordWrap is true and ScrollBarPolicy is ScrollBarAsNeeded, if QStyle::PM_ScrollView_ScrollBarOverlap returns true, the text displayed an empty line. Fix this by not reserving the width of the vertical scrollbar if the flow is TopToBottom and the vertical scrollbar, and QStyle returns true for PM_ScrollView_ScrollBarOverlap. Amends aeef92c3c33e4ebcb7e5d8dd955020f4f4600e84 Pick-to: 6.1 6.2 Fixes: QTBUG-94248 Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io> Change-Id: I4d47c7e86bbb86474cb1a99bb26d8b67f0e8a7e2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemView: block autoScroll from interfering with QScrollerVolker Hilsheimer2021-06-091-0/+4
| | | | | | | | | | | | | | | | When pressing an index in order to start a flick gesture, QAIV sets the current index. When QScroller changes state to Dragging, then QAIV restores the current index to what it was before the press, as the user is clearly scrolling the view. With autoScroll enabled, this will produce an ugly jump if the old current index is no longer in the viewport. To prevent this, disable autoScroll before restoring the currentIndex. Fixes: QTBUG-64543 Pick-to: 6.2 6.1 5.15 Change-Id: I3e0a18a6a179d80b9d810fce5aa658f0cfff9a29 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>