summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
Commit message (Collapse)AuthorAgeFilesLines
* QAbstractProxyModel: Use QCompatProperty with custom getterIevgenii Meshcheriakov2021-11-012-68/+5
| | | | | | | | | Use new API for QCompatProperty with custom getter instead of ad-hoc solution. Task-number: QTBUG-89655 Change-Id: I06481ad4d360b178be001ceb9c6c8460b73391f6 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix segfault in QItemSelectionModel::hasSelectionAndreas Buhr2021-10-141-2/+5
| | | | | | | | | | | Amends 0c2125458a9fdddaf3385b257ba4350da872a1d1. The code assumed that a QItemSelectionModel always has a model. But during initialization from QML, it hasn't. Fixes: QTBUG-97475 Pick-to: 6.2 6.2.1 Change-Id: Ie9c680f8989a23ef732faaf5da7ef7ae273126aa Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
* corelib: Fix typos in source code commentsJonas Kvinge2021-10-121-1/+1
| | | | | | Pick-to: 6.2 Change-Id: Ic78afb67143112468c6f84677ac88f27a74b53aa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QSFPM: remove redundant call to update_source_sort_column()David Faure2021-10-051-2/+1
| | | | | | | | | | | | | | | | | | | | | Everywhere else in this code, it says if (update_source_sort_column() && dynamic_sortfilter) so, doing the same here. This originally comes from commit 3ffcfc357dbc51bf62ffb but skelly isn't around anymore, and Milian (reviewer) had no objection to this change either. Looking into the implementation, calling it twice is a no-op anyway, create_mapping will early-return with "already done". On the other hand, now it has a chance of returning true, while before it would always return false in the second call ("return true if the column was changed"). I couldn't write a unittest for that case though, it would require that a source reset also changes the proxy->source column mapping somehow, but I don't see how that can be done (the latter being the QSFPM setup). Change-Id: Ie560facf1039a1afc02543e83bfdef0f8f2e09fc Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* emit layoutAboutToBeChanged timelyLuca Beldi2021-07-201-11/+19
| | | | | | | | | | | 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>
* Consistent handling of disabled items in QItemSelectionModelAndreas Buhr2021-07-153-22/+56
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* Consistent indentation for BINDABLE propertiesAndreas Buhr2021-06-242-7/+12
| | | | | | | | | Triggered by API review in Gerrit patch 355960. Task-number: QTBUG-94407 Pick-to: 6.2 Change-Id: I7cafc1cc9d4b929040b53c6bf92c91d73c3b39f2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add "We mean it" warning to qidentityproxymodel_p.hMitch Curtis2021-06-141-0/+12
| | | | | | | | This was missed in b42e2d70fbda5afb462b869583b925ad5f1a5480. Pick-to: 6.2 Change-Id: Id06bd880456534293cf6c0d215f794b6ad0552ca Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QSortFilterProxyModel: create mappings on demand againDavid Faure2021-06-031-10/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Calling create_mapping in setSourceModel as introduced by 8455bfee76ed3f1bd3bba8bd3688a7afa94ae0bb can lead to an early call to filterAcceptsRow, and some existing applications may crash. It is also an incomplete solution since it was only done for the toplevel index but not for child indexes. Instead, go back to creating mappings on demand. This means coming up with a different fix for QTBUG-87781 (dataChanged not emitted for indexes that haven't been mapped yet, i.e. not queried or shown anywhere). When this happens, we can't know if the index was previously filtered out or not (for lack of a dataAboutToBeChanged signal...). Creating the mapping with the new data only gives us the new state of affairs, there's no reference state to compare to. Therefore, when the mapping is missing (during dataChanged handling), create it, but skip all the logic about row insertion/removal, just forward the dataChanged signal if the row isn't filtered out. Creating the mapping might require creating first mappings for parents, recursively, which wasn't done anywhere in QSFPM yet, hence the new create_mapping_recursive() method. In addition to all this, the handling of removed items was incorrect, remove_source_items did nothing if the parent was gone, and then source_items_removed was trying to adjust indexes in an incorrect list. If the parent is gone, clear the proxy_to_source list, so there's nothing to adjust afterwards. This bug actually doesn't happen anymore in this version of the patch, but the change still seems right and might prevent repeating a long debugging session in the future. Thanks to ChunLin Wang for the unittest in this commit. Done-with: ChunLin Wang Pick-to: 6.1 6.0 5.15 Change-Id: Id543d0cc98f1a03b5852bda01d2f49b980e06be7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Move QIdentityProxyModelPrivate out into its own headerMitch Curtis2021-06-012-36/+87
| | | | | | | | | qtquickcontrols2 needs to use it. Change-Id: Ic5e3105095a8fcd36a38a3ce4353db4057ada0de Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* Fix qdoc warningsVolker Hilsheimer2021-05-272-2/+3
| | | | | Change-Id: Ie51ccff3272f078e062380033678828a01f03eb8 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* Item models: code tidiesGiuseppe D'Angelo2021-05-182-3/+3
| | | | | | | | Use QFlags::testAnyFlag instead of relying on implicit conversions. Change-Id: I7ac8149535ad28e47fbf3e250042892bdf8c3a72 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
* Fix QItemSelectionModel::selectionChanged emissionAndreas Buhr2021-05-181-8/+32
| | | | | | | | | | | | | | | | | | | | QItemSelectionModel has the property selectedIndexes with the notification signal selectionChanged. When a row is deleted or inserted above the current selection, the row number of the current selection changes and thus the return value of selectedIndexes changes. This should trigger its notification signal. This signal was not emitted. This patch fixes this and adds a unit test to verify this. [ChangeLog][Important Behavior Changes][QtCore] QItemSelectionModel now emits the selectionChanged signal if only the indexes of the selected items change. Fixes: QTBUG-93305 Change-Id: Ia5fb5ca32d658c9c0e1d7093c57cc08a966b9402 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* QAbstractItemModel::match: code tidiesGiuseppe D'Angelo2021-05-121-1/+1
| | | | | | | | Remove a magic number from the code, by adding it (as a private value) to the right enumeration. Use toInt() to convert to integer. Change-Id: Id1b00dde900619684b5a3df247d46938439150ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QSFPM: make filterRegularExpression and filterCaseSensitivity bindableIvan Solovev2021-05-112-39/+133
| | | | | | | | | | | | | | | | | This takes care of the last two QSFPM properties. They were postponed because of the tricky relation between them and some bugs in handling the changes. The bug was fixed in bcbbbdb2d640c059c19e9337c7418b83b1b7e4ea and now the behavior is well-determined: updating filter regexp does trigger case sensitivity change and vice versa. However updating only regexp pattern (via QString overload or setFilterFixedString or setFilterWildcard) does not change case sensitivity. Task-number: QTBUG-85520 Change-Id: Idc41cf817de9e6263ed65a80fa40fc8415c8c856 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QSortFilterProxyModel: port to new property systemIvan Solovev2021-05-112-47/+192
| | | | | | | | | | filterRegularExpression and filterCaseSensitivity will be handled in a separate commit Task-number: QTBUG-85520 Change-Id: I848c5c6cbe8642efa156f4f5d33467976bbf0351 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
* QAbstractProxyModel: port to new property systemIvan Solovev2021-05-043-6/+96
| | | | | | | | | | | | | | The biggest trick here is the getter (QAbstractProxyModel::sourceModel), which is returning nullptr, while internally using a global staticEmptyModel() instance. This lead to inconsistency while binding to a proxy model without source model. The bound object would point to staticEmptyModel() instance, while sourceModel() getter returns nullptr. To solve this issue a custom QBindableInterface is implemented. Task-number: QTBUG-85520 Change-Id: I597df891c7e425d51b55f50ccbacabdfe935cbac Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QSFPM: fix filterCaseSensitivityChanged signal emission logicIvan Solovev2021-04-301-0/+4
| | | | | | | | | | | | | | | | | | This patch amends bcbbbdb2d640c059c19e9337c7418b83b1b7e4ea. It fixes the logic of filterCaseSensitivityChanged signal emission. The call to QRegularExpression overload of setFilterRegularExpression could change the filterCaseSensitivity, but the signal was never emitted. [ChangeLog][QtCore][QSortFilterProxyModel] A call to QRegularExpression overload of setFilterRegularExpression now emits a filterCaseSensitivityChanged signal, if required. Pick-to: 6.0 Pick-to: 6.1 Change-Id: Id4ef04227c1f8ed98153fa5107ec3fbe4c0c77fb Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Port of QItemSelectionModel::model to new property systemAndreas Buhr2021-04-273-24/+86
| | | | | | | | | | The property 'model' is ported to a bindable property. The properties hasSelection, selection, selectedIndexes, and currentIndex are left for later patches. Task-number: QTBUG-85520 Change-Id: Ia424ce99fc80c3d807c634c21d161a3ad94b27d2 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Optimize quadratic-time insertion in QSortFilterProxyModelIgor Kushnir2021-04-241-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Let N = proxy_to_source.size() before the code modified in this commit. Let M = (N - proxy_start). Let K = source_items.size(). The algorithmic complexity of the removed loop is O(N+K+K*M), assuming the number of O(N+K) reallocations is a constant. The complexity of the QList::insert and std::copy implementation is O(N+K). This is much faster in practice when K and M are of the same order of magnitude as N. For example, this quadratic complexity issue results in noticeable slowdown in the following scenario: * a QSortFilterProxyModel is used only for filtering, not sorting; * first set a filter that matches a single item in the middle of a huge number of items (about one million) - this is reasonably fast (takes about a second); * then clear the filter (i.e. set an empty filter so that no item is filtered out) and watch your application's UI freeze for a minute. The "Add QSortFilterProxyModel clear-filter benchmark" commit (with Change-Id I419a5521dd0be7676fbb09b34b4069d4a76423b1) adds a benchmark that runs much faster with this performance fix. Pick-to: 6.0 6.1 Change-Id: Ieaec173e6910f5d21eaee49402087f7711abbedf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fix case sensitivity handling QSFPMSamuel Gaist2021-04-221-24/+44
| | | | | | | | | | | | | | | | | | | | | | This patch fixes the breaking of case sensitivity handling. The removal of QRegExp killed the wrong code paths which leads to inconsistencies when changing the regular expression throuh methods like setFilterWildCard or setFilterFixedString. Changing the case sensitivity also nukes the original options that were set on the regular expression if it was set through setFilterRegularExpression. [ChangeLog][QtCore][QSortFilterProxyModel] Case sensitivity as well as regular expression options handling have been fixed. The original value is properly kept when using setFilterWildCard and setFilterFixedString. The regular expression options are now also properly kept when changing the case senstitivity through setFilterCaseSensitivity. Fixes: QTBUG-92260 Pick-to: 6.1 Pick-to: 6.0 Change-Id: Ifb4732306f0c7d79ad0b18d3f5437c4523bb40e5 Reviewed-by: Igor Kushnir <igorkuo@gmail.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Allow proxy models access to the parent-child hierarchy of sourceLuca Beldi2021-04-195-6/+24
| | | | | | | | | | | As discussed in the related bug report, the current way proxy models access the parent-child hierarchy of the source model requires modifying Qt sources. This changes adds a method to allow easy implementation of this common feature to proxy model subclasses. Fixes: QTBUG-83911 Change-Id: Ic88d40c13c2be7b6b44fcc58118bac471a11da95 Reviewed-by: David Faure <david.faure@kdab.com>
* Fix get out of bounds index in QSortFilterProxyModel::filterAcceptsRowChunLin Wang2021-04-071-3/+5
| | | | | | | | | Before calling the index function, we need to check the validity of the parameters. Fixes: QTBUG-91878 Pick-to: 5.15 6.0 6.1 Change-Id: I9ec7265fff3f81b8a288c4ba8fae606a2ec808a6 Reviewed-by: David Faure <david.faure@kdab.com>
* Fix removing columns when QSortFilterProxyModel has not been sorted yetJoni Poikelin2021-03-251-1/+4
| | | | | | | Fixes: QTBUG-91788 Pick-to: 6.1 6.0 5.15 Change-Id: Iddcafd3171f0f3703b94893a32b4ccaaeea9e713 Reviewed-by: David Faure <david.faure@kdab.com>
* QConcatenateTablesProxyModel: skip dataChanged in hidden columnsDavid Faure2021-03-091-1/+6
| | | | | | | | | | | | | | | | When the source models don't have the same number of columns, the proxy keeps only the smallest number of columns across all source models. Afterwards, if a source model emits dataChanged in a column past that number (a "hidden" column), the proxy needs to ignore it rather than assert. But also, if the source model emits a dataChanged signal across both visible and hidden columns, then the last column number needs to be adjusted so that the signal is correctly processed and forwarded. Task-number: QTBUG-91253 Pick-to: 6.1 6.0 5.15 Change-Id: I939e8ec0faf41370472f86785851292e4372f72c Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Fix build of Core module without regularexpression featureAlexey Edelev2021-03-042-13/+1
| | | | | | | | | | | | | | | | | | qregularexpression.h requires FEATURE_regularexpression to be enabled. Add a condition to the 'qt_pch.h' header to fix the build when PCH are enabled and FEATURE_regularexpression is disabled. It seems that the filter implementation of QSortFilterProxyModel has QRegularExpression as its base. It's necessary to make sortfilterproxymodel dependent on the regularexpression feature. Fix the precompiler condition for the extractSections function in the QString implementation. Use the same precompiler condition for the QString::section and extractSections functions, since QString::section depends on extractSections. Change-Id: I5b775e0842a0aa1a8d47f8dded376bdfcf63b5bf Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Replace some more erase/remove patterns with removeIfGiuseppe D'Angelo2021-01-101-4/+1
| | | | | Change-Id: I6c6f33450fbfd798e5ef71a8ba18f590581dc3a2 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Remove the qmake project filesJoerg Bornemann2021-01-071-63/+0
| | | | | | | | | | | | | | | | Remove the qmake project files for most of Qt. Leave the qmake project files for examples, because we still test those in the CI to ensure qmake does not regress. Also leave the qmake project files for utils and other minor parts that lack CMake project files. Task-number: QTBUG-88742 Change-Id: I6cdf059e6204816f617f9624f3ea9822703f73cc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Use (new) erase()/erase_if() algorithmsMarc Mutz2020-12-051-7/+2
| | | | | Change-Id: I45c18fd45c20b226e44d16315e3ebb6c305d4ab0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Dont' return a const ref to QModelIndexLars Knoll2020-12-042-6/+5
| | | | | | | | | | | The conversion operator from QPMI to QModelIndex should return by value, to hide implementation details and so that we don't have to rely on a static empty QModelIndex. Change-Id: I92b3f8451422f2b69bf31f28b387a124fd24ec46 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 0cd2935ed9d772f0eb06d03201baabd60764ec80) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Fix hashing of QPersistentModelIndexLars Knoll2020-12-041-0/+2
| | | | | | | | | | | | | The hash and equality operators used need to be consistent with each other. Unfortunately, QPMI::operator==() is not suitable to do this. So specialize qHashEquals() for QPMI. Fixes: QTBUG-88966 Change-Id: If5f19a722ae9fc4e78e93537e7ea15726f148768 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 83e95956ed58e88b11e2cc3cb61c5beacb7985db) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Replace discouraged Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPEAndreas Buhr2020-11-303-5/+5
| | | | | | | | | | | | | | Q_MOVABLE_TYPE was conceived before C++ had move semantics. Now, with move semantics, its name is misleading. Q_RELOCATABLE_TYPE was introduced as a synonym to Q_MOVABLE_TYPE. Usage of Q_MOVABLE_TYPE is discouraged now. This patch replaces all usages of Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPE in QtBase. As the two are synonymous, this patch should have no impact on users. Pick-to: 6.0 Change-Id: Ie653984363198c1aeb1f70f8e0fa189aae38eb5c Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Fix invalid QSortFilterProxyModel::dataChanged parametersWang ChunLin2020-11-301-9/+13
| | | | | | | | | QSortFilterModel shouldn't forward dataChanged() when the source model changes data in columns that the filter model refuses Fixes: QTBUG-86850 Pick-to: 5.15 Change-Id: I26565d119d2aa36ea07b3de0c15f1b137bc002f8 Reviewed-by: David Faure <david.faure@kdab.com>
* Fix QSFPM not emitting dataChanged when source model is setWang ChunLin2020-11-181-0/+2
| | | | | | | | | | | | | | QSortFilterProxyModel did not emit dataChanged when calling setSourceModel() after modifying the source model. QSortFilterProxyModel::setSourceModel and QSortFilterProxyModelPrivate::_q_sourceReset(), _q_clearMapping is called to delete the source_index_mapping. They also need to call create_mapping function to re-create it. Fixes: QTBUG-87781 Pick-to: 5.15 Change-Id: Idbe34696c9d3a2fbf354b653c870bac61378811d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QItemSelection: Use public constructor from baseclassVolker Hilsheimer2020-11-131-1/+1
| | | | | | | Addresses code review comment. Change-Id: I51c1d790217346358e15ed5ca750ea397a765406 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Resolve corelib's remaining ### Qt 6 commentsEdward Welbourne2020-11-021-1/+1
| | | | | | | | | | | | | No action taken at Qt 6, suggesting it shall never happen. Four removed, one converted to Qt 7, others converted to unversioned TODOs. Filed Jira tasks, and referenced in comments, for those retained. There remain two "once bootstrap builds are obsolete" comments and one other on which pending action may yet happen. Fixes: QTBUG-85700 Change-Id: Ib140a6a21c63370e51e4734cc591f67573a29d9a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove QItemSelectionRange's operator<()Edward Welbourne2020-10-282-44/+0
| | | | | | | | | | | | As advocated in a ### Qt 6 comment. [ChangeLog][QtCore][QItemSelectionRange] QItemSelectionRange no longer supports ordering. The prior ordering was inconsistent with equality and should not be needed. Task-number: QTBUG-85700 Change-Id: I5eb372c203cae19db40fa67f706d911785652d5f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Deprecate ordering on QItemSelectionRangeEdward Welbourne2020-10-282-3/+7
| | | | | | | | | | | | | | | Ready for removal at Qt 6, as advocated in a ### comment. It was never done consistently with operator==(), apparently, and should not be needed in any case. [ChangeLog][QtCore][QItemSelectionRange] Ordering of QItemSelectionRange is now deprecated. It was not consistent with equality and should not be needed. Task-number: QTBUG-85700 Pick-to: 5.15 5.15.2 Change-Id: Ie99294bd7fc18f2a497598ae08840886b0a6d62d Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QAbstractItemModelTester: don't rely on hasChildren()David Faure2020-10-271-2/+2
| | | | | | | | | | | | | | | | | | | Dynamic models which use fetchMore to asynchronously fill subdirs (like KDirModel) return true in hasChildren() for dirs that are expected to have children (so that the "+" shows in the treeview) but do not actually have children readily available. They will be inserted later on once the async listing job is done (as a result of fetchMore triggering that job). So QAbstractItemModelTester should use rowCount instead, to find out if there are children present. This detected a bug in QConcatenateTablesProxyModel: it returned a non-zero rowCount for its items, while it's flat. Change-Id: Idcdc86159f1fc79ed5297075dfcf30c09896287a Pick-to: 5.15 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Centralize the implementation of move assignment operatorsGiuseppe D'Angelo2020-10-031-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment we have two main strategies for dealing with move assignment in Qt: 1) move-and-swap, used by "containers" (in the broad sense): containers, but also smart pointers and similar classes that can hold user-defined types; 2) pure swap, used by containers that hold only memory (e.g. QString, QByteArray, ...) as well as most implicitly shared datatypes. Given the fact that a move assignment operator's code is just boilerplate (whether it's move-and-swap or pure swap), provide two _strictly internal_ macros to help write them, and apply the macros across corelib and gui, porting away from the hand-rolled implementations. The rule of thumb when porting to the new macros is: * Try to stick to the existing code behavior, unless broken * if changing, then follow this checklist: * if the class does not have a move constructor => pure swap (but consider ADDING a move constructor, if possible!) * if the class does have a move constructor, try to follow the criteria above, namely: * if the class holds only memory, pure swap; * if the class may hold anything else but memory (file handles, etc.), then move and swap. Noteworthy details: * some operators planned to be removed in Qt 6 were not ported; * as drive-by, some move constructors were simplified to be using qExchange(); others were outright broken and got fixed; * some contained some more interesting code and were not touched. Change-Id: Idaab3489247dcbabb6df3fa1e5286b69e1d372e9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* QAIM docs: use \nullptr instead of 0Giuseppe D'Angelo2020-10-021-2/+2
| | | | | | Pick-to: 5.15 Change-Id: I30b541f28ba8271eb4234c7f642485a1614808bf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_REQUIRED_RESULT with [[nodiscard]]Allan Sandfeld Jensen2020-09-251-1/+1
| | | | | | | It was already used many places directly making the code inconsistent. Change-Id: I3b14bc6c333640fb3ba33c71eba97e78c973e44b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Doc: link QModelRoleData and QModelRoleDataSpan documentationVolker Hilsheimer2020-09-221-17/+17
| | | | | Change-Id: I49bb356d5296dc73effd18399b7a205f00c24252 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Remove some comments that are no longer relevantEdward Welbourne2020-09-051-1/+0
| | | | | | | Task-number: QTBUG-85700 Change-Id: I5ce368e8edca2b9483a0f0ef34bc9eb6b4e44574 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Long live QAIM::multiData!Giuseppe D'Angelo2020-09-022-0/+408
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Views / delegates absolutely *adore* hammering data(). A simple QListView showing a couple of dozens entries can call data() a hundred of times on the first show. Back of the hand calculation, * 2 times per visible item (sizeHint() + paint()), * times 9 roles used by the default delegate, * times 20 visible items = 360 as a bare minimum, assuming the view doesn't redraw twice accidentally. Move the mouse over the view, and that'll cause a full update with certain styles: 360 calls to data() per update. This has an overhead visible in profilers. The model's data() has to re-fetch the index from its data structure and extract the requested field every time. Also, QVariant is used for the data interexchange, meaning anything that won't fit in one is also a memory allocation. This problem will likely be gone in Qt6Variant as that will store sizeof(void*) * 3, meaning QImage/QPixmap and similar polymorphic classes will fit in a QVariant now... So I'm trying to to remove part of that overhead by allowing views to request all the data they need in one go. For now, one index a a time. A view might also store the data returned. The idea is that the same role on different indexes will _very likely_ return variants of the same type. So a model could move-assign the data into the variant, avoiding the memory allocation /deallocation for the variant's private. This patch: 1) Introduces QModelRoleData as a holder for role+data. 2) Introduces QModelRoleDataSpan as a span over QModelRoleData. The idea of a span type is twofold. First and foremost, we are in no position to choose which kind of container a view should use to store the QModelRoleData objects for a multiData() call; a span abstracts any contiguous sequence, leaving the view free to do whatever it wants (statically allocate, use a vector, etc.). It also solves the problem of efficient passing the roles and gathering the returned variants from multiData(). 3) Add multiData(), which populates a span of roles for a given model index. The main advantage here is that a model can fetch all the needed information for a given index just once, then iterate on the span and provide data for each requested role. Cf. this with data(), where every call has to re-fetch the information for the index. A couple of models have been ported to multiData(), as well as QStyledItemDelegate. [ChangeLog][QtCore][QModelRoleData] New class. [ChangeLog][QtCore][QModelRoleDataSpan] New class. [ChangeLog][QtCore][QAbstractItemModel] Added the multiData() function. Change-Id: Icce0d108ad4e156c9fb05c83ce6df5f58f99f118 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Fix CaseSensitivity handling for QRegularExpression in QSortFilterProxyModelMarcel Krems2020-08-231-1/+2
| | | | | | | | | | | setFilterRegExp retains the caseSensitivity() while setFilterRegularExpression did not. Change setFilterRegularExpression to also retain the case sensitivity. Fixes: QTBUG-83313 Pick-to: 5.15 Change-Id: I46f494d320aee99d50612f01f63558c693276989 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: David Faure <david.faure@kdab.com>
* Fix qHash(const QModelIndex &index)Friedemann Kleint2020-08-201-1/+1
| | | | | | | | | The default seed = 0 parameter was missing, so, it was never used. Manifested as a failing test in Qt for Python (bug_PYSIDE-41.py). Amends c6cdf38e752c22babdbe645366bdfb7ce51d01ff. Change-Id: Ia3db8b6123a695d839fbec419b8d316991d18bf7 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Disentangle QIODevice dependenciesLars Knoll2020-08-151-4/+4
| | | | | | | | | | | | | | | | | Move the QIODevice::OpenMode enum into a base class, so that we can remove the full QIODevice (and thus QObject) dependency from qdatastream.h and qtextstream.h. This is required so that we can include QDataStream in qmetatype.h without getting circular dependencies. As a nice side effect, QDataStream and QTextStream can now inherit QIODeviceBase and provide the OpenMode enum directly in their class scope. Change-Id: Ifa68b7b1d8d95687ed032f6c9206f92e63bfacdf Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-143-15/+15
| | | | | | | | Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* MSVC: remove the extern templateThiago Macieira2020-08-051-25/+9
| | | | | | | | | | | | The problem was that QtCore exported those classes deriving from containers, which caused applications to try and import those same functions from QtCore, depending on whether they saw the #include or not. Now we don't need the hack anymore. Change-Id: I0a103569c81b4711a649fffd14ec9282454a1fdc Reviewed-by: Lars Knoll <lars.knoll@qt.io>