summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qabstractitemview.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix -Wimplicit-fallthrough for clangTim Blechmann2024-03-011-0/+1
| | | | | | | | | | | | | | | | | | | Clang's `-Wimplicit-fallthrough` warnings are a little stricter than gcc's interpretation: switch (i) { case 0: foo(); case 4: break; } While gcc accepts the implicit fallthrough, if the following statement is a trivial `break`, clang will warn about it. Pick-to: 6.7 Change-Id: I38e0817f1bc034fbb552aeac21de1516edcbcbb0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemView: Release tab focus when hiddenViktor Arvidsson2024-02-291-1/+1
| | | | | | | | | | | | | | When hiding a widget that has focus we try to focus the next widget in the focus chain by running focusNextPrevChild. The abstract item view overrides this to step the items but does not account for this hide case which makes focusing not only not work, but also by hiding the widget the selection in the item view gets changed. Pick-to: 6.7 6.6 6.5 Change-Id: I29d40a1fb86ced60ec742b2753a87383846a89b3 Reviewed-by: Viktor Arvidsson <viktor.arvidss@gmail.com> Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemView: close all child editors when parent is removedChristian Ehrlicher2024-02-081-1/+12
| | | | | | | | | | | | | QAIV::rowsAboutToBeRemoved() closed all child editors when the child was a direct ancestor of the removed index but forgot to check if the index is an indirect ancestor. Some of those editors were removed later in updateEditorGeometries() but not all as the testcase in the bug report showed. Pick-to: 6.7 6.6 6.5 Fixes: QTBUG-103476 Change-Id: I90b3d3bff3857aa79f96eecf23d980928693b7bc Reviewed-by: David Faure <david.faure@kdab.com>
* Doc: Add missing full stop to briefsPaul Wicking2023-12-201-1/+1
| | | | | | | | | | | | | | QDoc generates missing full stops for briefs in certain situations. Due to how the `\brief` command works, this fails if the brief ends with a link target. As this is a corner case, add the missing full stop to the offending briefs. Task-number: QTBUG-117636 Task-number: QTBUG-117470 Change-Id: I6d9538f517cd39943ab817f45183fadd3b3a9c92 Reviewed-by: Safiyyah Moosa <safiyyah.moosa@qt.io> Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io> Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QAIV: reset state if removing index while editing or committingVolker Hilsheimer2023-12-141-31/+40
| | | | | | | | | | | | | | | | | | | | | | | | | If the commit of data to a model index result in that index getting filtered out, then the editor will be removed as part of committing the data, and the index that the editor is associated with becomes invalid. The subsequent call to closeEditor() will find that the index for the editor is no longer valid. This should not warn, and it should also not abort the clean-up process early. Instead, identify that the editor that we want to closed is already hidden. In that case, skip the warning and most of the cleanup process, and proceed directly to the EndEditHint handling further down. Add a test that simulates the two scenarios where this can happen: either the committing of data results in the index being filtered out by the existing filter; or the filter changes while editing, and the index being edited gets removed. In both cases, we don't want to see a warning, and the state of the item view should be reset correctly. Pick-to: 6.7 6.6 6.5 Fixes: QTBUG-115765 Change-Id: If247172fdac9a1a9279dae96c078d32553d4ee5d Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: 🌴 Alexey Edelev 🌴 <alexey.edelev@qt.io>
* QtWidgets: finally Q_FOREACH-freeAhmad Samir2023-10-131-2/+0
| | | | | | | | | | | | These source files have been ported away from Q_FOREACH but weren't blacklisted, so un-blacklist them by removing "#undef QT_NO_FOREACH", and removing them from NO_PCH_SOURCES. These are the last remnants of the Q_FOREACH blacklisting in QtWidgets. Task-number: QTBUG-115803 Change-Id: Ib73d668687f64d39fa48397d75a0f342e525c1ad Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QAbstractItem/Column/TreeView: rename private functions (remove _q_ prefix)Christian Ehrlicher2023-10-011-26/+26
| | | | | | | | | Cleanup the private function names after the change to pmf-style connections. Task-number: QTBUG-117698 Change-Id: Id15ef245cacca9c00bf65271bccf4da82fb7fd2f Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Widgets/Itemviews: use pmf-style connect in QAbstractItemViewChristian Ehrlicher2023-09-291-111/+130
| | | | | | | | | | Replace all connect() calls with pmf-style connection syntax. This also means that we have to properly disconnect everything in the ctor to not trigger an assertion in QtPrivate::assertObjectType(). Change-Id: I8f2d64b77849bf5fea01b7f80bbd5d0c0a09c4fa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QAccessible: consistently respect rootIndex of item viewsVolker Hilsheimer2023-09-011-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Accessibility implementations rely on correct information about the model dimensions when operating on item views. An item view that has a root index set needs to report it's size based on the root index, rather than for the view's model directly. Pass the rootIndex to all calls to QAbstractItemModel::column/rowCount. Refactor the code to avoid excessive dereferencing of a QPointer, apply const and fix/improve coding style in touched lines. Emit a ModelReset notification when the root index changes, or (in the case of QListView) when the model column changes. Split long Q_ASSERTs into multiple lines to be able to better trace the exact reason for an assertion, and replace the assert with an early return of nil when it's plausible that a cached cell is no longer part of the view (i.e. because the root index changed). Add a test case that verifies that changing the root index changes the dimension of the view as reported through the accessibility interface. Pick-to: 6.6 6.5 Fixes: QTBUG-114423 Change-Id: I7897b79b2e1d10c789cc866b7f5c5dabdabe6770 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QAbstractItemView: port Q_FOREACH to ranged-forAhmad Samir2023-08-301-1/+5
| | | | | | | | | | Take a copy as the loop may end up calling QCoreApplication::postEvent() which in turn could invoke unknown code that results in modifying the QHash that is being iterated over. Task-number: QTBUG-115803 Change-Id: I5f8aabb13ef7f60b470d0d3a986063775e787036 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Mark QtWidgets as free of Q_FOREACH, except where it isn'tMarc Mutz2023-08-091-0/+2
| | | | | | | | | | | | | | | | | | The density of Q_FOREACH uses is high here, too high for this author to tackle in a short amount of time. But they're concentrated in just a few TUs, so pick a different strategy: Mark the whole library with QT_NO_FOREACH, to prevent new uses from creeping in, and whitelist the affected TUs by #undef'ing QT_NO_FOREACH locally, at the top of each file. For TUs that are part of a larger executable, this requires these files to be compiled separately, so add them to NO_PCH_SOURCES (which implies NO_UNITY_BUILD_SOURCES, too). Created QTBUG-115803 to keep track of this. Task-number: QTBUG-115803 Change-Id: Ib5d6192632d98bdcc6625a9a14e05d13bb7f759b Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Implement private visualRect() in QTreeView and QAbstractItemViewAxel Spoerl2023-08-011-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QTreeView::visualRect() returns a given model index's visual rectangle. The method is used to toggle the background during hovering. The previous implementation included the row indicator, when the first row section was hovered. When it was unhovered, the row indicator remained highlighted, until the mouse had left the view port. The reason is, that the highlighting implementation changed the rectangle returned for the first section, to include the row indicator. The implementation for neutralising a highlighted section relies on QAbstractItemViewPrivate::setHoverIndex() and QAbstractItemView::update(). These methods don't know about the row indicator to be included, and therefore do not update() its rectangle. As a consequence, the correct background gets painted but not updated on the screen. This patch moves the calculation of the visual rectangle to a new QTreeViewPrivate::visualRect_impl(). In addition to the model index, the new method expects an enum argument, representing the calculation rule: - SingleSection: Calculate the rectangle of the given section. - FullRow: Returns the rectangle of the entire row, regardless of the index's column. - AddRowIndiCatorToFirstCulumn: Adds the row indicator to the rect, if the model index points to the first column. The patch updates all calls within QTreeView, to use the private method with the right calculation rule for the use case at hand. It elminates manual (and repeated) modifications of the return value. The patch implements QAbstractItemViewPrivate::visualRect(), which returns QAbstractItemView::visualRect(). It is overridden in QTreeViewPrivate, so that QAbstractItemViewPrivate::setHoverIndex() and QAbstractItemView receive the rectangle including row indicator. As a drive-by, several local variables have been constified and/or renamed to indicative variable names. Fixes: QTBUG-115149 Pick-to: 6.6 6.5 Change-Id: I4838bcf744f87d8cfb259c5d8758fb65e091e9fe Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Normalize signal/slot signatures [1/2]: non-QPairMarc Mutz2023-07-121-4/+4
| | | | | | | | | | | | | | | | This is the result of running util/normalize, dropped some false positives: - it removed the space after "d, " in Q_PRIVATE_SLOT(d, foo()) - it removed spaces in moc text streaming of "SLOT(" << ... << ")" In addition, the tool replaces QPair with std::pair. This is surprising and therefore performed in a separate commit. Pick-to: 6.6 Change-Id: If4e3815d7c0840defc1b82bcbf41a8265acda0d8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Immediately drag when start distance is 0 in abstract item viewMikolaj Boc2023-07-051-12/+18
| | | | | | | | | | | | | | | This change makes system drag become initiated right after dragging is detected when drag start distance from QApplication::startDragDistance is 0. Otherwise the starting distance is ignored and the value of 1 is implicitly used. The startDragDistance of 0 is needed on WASM, as the native dragstart event arrives exactly after the first mousemove event. With this change, it is possible to set up drag correctly prior to the native dragstart event arriving. Fixes: QTBUG-114947 Change-Id: I112d97d251c9e9b1a39196ddcc39a37024b441f6 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix qdoc link warnings after moving a few examples to manual testsTor Arne Vestbø2023-06-271-1/+1
| | | | | | Pick-to: 6.5 6.6 Change-Id: I81a6e9d52e858c3f733d4c527c70408772813b56 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbtractItemView: deselect before click opens editorVolker Hilsheimer2023-02-281-1/+1
| | | | | | | | | | | | | | A click on the selected item should deselect all other items before editing starts. Remove the part of the test case that assumes that we can have multiple items selected in ExtendedSelection mode, and click on an item to start editing while maintaining selection. That can never happen. Pick-to: 6.5 6.4 6.2 Fixes: QTBUG-111131 Change-Id: I0312eed4614502cfb77eca26d3f7615427493d7d Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QAbstractItemView: execute posted layouts before paintingVolker Hilsheimer2023-02-281-0/+6
| | | | | | | | | | | | | | | | | | | | | | tst_QListView::moveLastRow asserts now and again, unless only that test function is running. We repeat failing test functions individually, so this never blocked CI. The reason seems to be that we get a paint event only for the viewport, after the item model's structure has been changed by the test. Moving rows does trigger a delayed layout, and in some circumstances the entire view is updated, rather than just the viewport. But if only the viewport is updated, then layout execution in QAbstractItemView::event never happens, and the data structure that the paintEvent implementation relies on is outdated and contains invalid item pointers, resulting in an assert. If we need to execute delayed layouts when the entire view gets painted, then we also need to execute them when only the viewport gets painted. Pick-to: 6.5 6.4 Change-Id: Ibb46c2315825d99c82b884226817c494a3d95975 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QAbstractItemView: don't start editing on Ctrl-ClickVolker Hilsheimer2023-02-161-1/+3
| | | | | | | | | | | | | | | | | | | Amends 17c1ebf8bfd254ff75cc55e335d1c1fb01da547f, after which dragEnabled item views toggled selection on click rather than on press. If the edit trigger included SelectedClicked at the same time, then Ctrl-Clicking a selected item would start editing the item, instead of toggling selection. Fix this by ignoring clicks with modifier when evaluating whether editing should start. Extend the mouseSelection test case by including a column for the editTrigger, and cover the respective combinations. Fixes: QTBUG-111131 Pick-to: 6.5 6.4 6.2 Change-Id: I9605f9b3d5a49e292551a34c3c4c7a5f9ecb2a89 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QAbstractItemView: don't access invalid indexes on copy-keyVolker Hilsheimer2023-02-131-5/+6
| | | | | | | | | | | | | | | When pressing the copy key the view tried to access the model's data for the currentIndex() without checking whether the index is valid. This resulted in debug output to the console, and might break models that didn't check incoming indexes for validity (or asserted validity). Fix this by checking whether the currentIndex() is valid before reading the model's data for that index. Fixes: QTBUG-106569 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: Ide75fbdfdbd1451ab6d48f07b22136553c5b2468 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* QAbstractItemView: Don't unselect on click on empty area in SingleSelectSebastian Beckmann2023-02-111-1/+5
| | | | | | | | | | | | | | | | dfb4697e4a4828acd47292a89207b3975ec6766e made a change to selection behavior that resulted in a regression where clicking on an item view but not on an item would cause the current item to get unselected. Changes the behavior to not update in this case. Added a new test that specifially checks for this scenario and ensures that the current item is still selected, even after the user clicks on empty area. Fixes: QTBUG-105870 Pick-to: 6.2 6.4 6.5 Change-Id: I191c3878819b99897083039fba0ab43908da5429 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Fix build with -no-feature-draganddropTasuku Suzuki2023-01-171-4/+22
| | | | | | Pick-to: 6.5 Change-Id: I88ecd9a84d7fb9f6cb78027cc51e34089e211ff2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Replace QT_NO_ACCESSIBILITY with QT_CONFIG(accessibility)Allan Sandfeld Jensen2022-06-151-8/+8
| | | | | | | Pick-to: 6.4 Change-Id: Iee4bd8970810be1b23bdba65a74de912401dca65 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-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. 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>
* QAbstractItemView: check the index emitted by the delegate's sizeHintChangedGiuseppe D'Angelo2022-04-281-6/+16
| | | | | | | | 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>
* 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>
* 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>
* 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>
* 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-221-10/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-151-2/+2
| | | | | | Pick-to: 6.2 Change-Id: I22f71a53b0f7f0698450123343e25548c889c3e2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* widgets: Fix typos in documentationJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 5.15 6.2 Change-Id: I6b77f0ec043d08da3b7958d780dce9595daf97a6 Reviewed-by: Edward Welbourne <edward.welbourne@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-011-21/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* 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>
* QAIV: Don't open editor on release when press closed editorVolker Hilsheimer2021-06-141-2/+15
| | | | | | | | | | | | | | | | | 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>
* 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>
* QAItemView: in MultiSelection, press deselects only if no drag can startVolker Hilsheimer2021-06-081-3/+10
| | | | | | | | | | | | | | | | | | | | In MultiSelection mode, items are by default toggled on press, which follows the example of standard Windows controls. However, when dragging is enabled, then the press might be the beginning of a drag'n'drop operation, and deselecting the item on press breaks the selection and user experience. Don't toggle the selection for presses on an already selected item that might get dragged; instead, wait for the release event. Extend the test case slightly to cover the special case. Dragging a selection in a drag-enabled and MultiSelection item view wasn't possible before either. Fixes: QTBUG-59888 Change-Id: Ibd3e95a71ea63dd1e9bc3c8a723eafa9a1c21afa Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io>
* QAbstractItemView: don't toggle extended selection on Ctrl+PressVolker Hilsheimer2021-06-071-0/+9
| | | | | | | | | | | | | | | | | | | In ExtendedSelection mode, a Ctrl+Press might be both the start of a selection toggle, or the start of a Ctrl+Drag operation. If we already toggle on the press, then it's impossible to drag the existing selection while the Control key is pressed. Ignore Ctrl+Press events and let the corresponding release event toggle the selection. Adjust the relevant test cases accordingly. The QItemDelegate test case used a click+control event incorrectly, such an event doesn't change the clicked state and should not be eaten, and now it does change the selection, so fix the test. Task-number: QTBUG-59888 Change-Id: Ia76126e31c28bc97d3e93e54965bdb1d0b8ac6a4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QAbstractItemView: Don't change selection if editor ate release eventVolker Hilsheimer2021-06-071-1/+2
| | | | | | | | | If a QItemDelegate implementation eats a release event (which they don't do by default), then don't change the selection. Task-number: QTBUG-59888 Change-Id: Ia08637627ce1da34ff9bdac63dfc72e5f53befac Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QAbstractItemView: don't block dragging after double clickVolker Hilsheimer2021-06-031-2/+5
| | | | | | | | | | | | | | | | | | | | | After d6551fe12520 it was no longer possible to start a drag with a double click (where the first click selects an item, and the second press+move starts the drag). Resetting the pressedItem variable to block the emission of the clicked() signal had this unwanted side effect. Instead, use an explicit boolean to store that the next release event will be the result of a double click, so that the clicked() signal is not emitted again (preventing the double-emission was the purpose of change d6551fe12520). Task-number: QTBUG-77771 Fixes: QTBUG-94087 Pick-to: 6.1 5.15 Change-Id: I082c5169d89eb980dcd7985ef3d302b6ff060fb9 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Olivier BARTHELEMY <perso.olivier.barthelemy@gmail.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Doc: Use \deprecated instead of \obsoletePaul Wicking2021-05-261-1/+1
| | | | | | Task-number: QTBUG-93990 Change-Id: I4e512354a49dde6678ca89cabc56bc76ba666bb3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* ItemViews: Don't remove items on internal moveChristian Ehrlicher2021-01-181-2/+4
| | | | | | | | | | | | | | When an itemview only allows internal moving of items it can happen that the target accepts the drag'n'drop operation since it's out of the control of Qt (e.g. Recycle Bin or an other application). Due to the nature of a move, the original item is deleted. Therefore check if the internal move target is the same as the source and don't delete it otherwse. Fixes: QTBUG-86020 Pick-to: 6.0 Change-Id: I69de4b8d76d1b0f57338b402aee87580226cd6cb Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemView: fix selectionCommand() with no eventChristian Ehrlicher2021-01-051-3/+3
| | | | | | | | | | | | QAbstractItemView::selectionCommand() returned the wrong SelectionFlags when no event is given since c4366ff0183a9a4a5c6eff0312b713e9c5eb97ea. Therefore re-add the call to QGuiApplication::keyboardModifiers() when no event is given and add a unittest for them so it's not removed again. Fixes: QTBUG-89711 Change-Id: I107357df08c4ff1b1a14d49523401c5e7b428f56 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>