summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qabstractitemmodel.h
Commit message (Collapse)AuthorAgeFilesLines
* QPersistentModelIndex: fix relational operators not being noexceptMarc Mutz2023-09-301-5/+5
| | | | | | | | | | | | | They actually can be, so the implementation need not change. Just add the noexcept tag (which is BC, it's not part of the name mangling on any compiler). Silences a bunch of XFAIL in the test (the test is automatically picking up the change, no need, and no way, to manually remove the QEXPECT_FAIL). Change-Id: I24b6ba1248001056de64f341617943e7aea5ae93 Reviewed-by: David Faure <david.faure@kdab.com>
* QModelIndex: improve qHashThiago Macieira2023-05-161-1/+7
| | | | | | | | | | | QModelIndex's qHash is really bad. It was retained from Qt 5, but ends up producing poor results in large hashes. This can't be fixed in Qt 6. Task-number: QTBUG-113613 Change-Id: I5f7f427ded124479baa6fffd175f7810e1dc2580 Reviewed-by: Lars Knoll <lars@knoll.priv.no>
* Replace qExchange calls with std::exchangeFabian Kosmale2022-09-281-1/+1
| | | | | | | | | | | | | | | | | | | | | qExchange is one of the few remaining functionalities that have not been moved out of qglobal. Given that std::exchange exists in the standard, we can simply move to it everywhere... ...if it weren't for the fact that std::exchange is only constexpr in C++20, and only has its noexceptness specified in (most likely) C++23. Still, we want to move to the existing std functionality where possible, to allow the removal of qglobal includes in lieu of something more fine-grained in the future. So leave any constexpr calls[1] alone for now (and observe that none of our current usages cares about the conditional noexceptness), but replace everything else. [1] QScopedValueRollback' ctor and QExplicitlySharedDataPointerV2::take Task-number: QTBUG-99313 Change-Id: I599cb9846cf319c7ffd3457130938347a75aad25 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QAbstractItemModel: Add revisions to new methodsUlf Hermann2022-06-241-13/+13
| | | | | | | | | | | These methods show up in QML-exposed types. They should be revisioned in order to keep those types backwards-compatible. Pick-to: 6.4 Change-Id: I8e826dc2e7db49d8abe69f67605dfb1991855b96 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | 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>
* QAbstractItemModel: make naming of arguments consistentAndreas Buhr2022-02-191-2/+2
| | | | | | | | | The signals rowsAboutToBeMoved/rowsMoved have the same arguments, but use different argument names. This patch aligns the naming, making it consistent. Same for columnsAboutToBeMoved/columnsMoved. Change-Id: I1cefe54319e569b8d57f6579ae9d5c3e33b66dc2 Reviewed-by: David Faure <david.faure@kdab.com>
* Prevent repeated instantiations of some qRegisterNormalizedMetaType<>s [1/N] ↵Marc Mutz2022-01-211-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (QtGui) Create macros that wrap the magic developed in 7d63efc16f65f98c657caa90e0d7e9b72a879ade and apply it to all Q_DECLARE_METATYPE invocations that show up in Clang -ftime-trace for a PCH'ed QtGui build. Effects on compile times: Clang 10 -ftme-trace: $ ClangBuildAnalyzer --analyze qtgui-before.trace | head -n6 Analyzing build trace from 'qtgui-before.trace'... **** Time summary: Compilation (523 times): Parsing (frontend): 628.3 s Codegen & opts (backend): 304.5 s $ ClangBuildAnalyzer --analyze qtgui-after.trace | head -n6 Analyzing build trace from 'qtgui-after.trace'... **** Time summary: Compilation (523 times): Parsing (frontend): 546.0 s Codegen & opts (backend): 304.4 s GCC 11 time (bash builtin): before: $ time for ((i=0; i < 3; ++i)) do touch src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done real 4m13,539s user 49m24,416s sys 3m18,177s after: $ time for ((i=0; i < 3; ++i)) do touch src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done real 3m55,697s user 45m19,941s sys 3m7,370s Task-number: QTBUG-97601 Pick-to: 6.3 Change-Id: Ia8e37a58937568a7ed21cfeb4b27274deca4d53b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtCore: replace qSwap with std::swap/member-swap where possibleMarc Mutz2022-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qSwap() is a monster that looks for ADL overloads of swap() and also detects the noexcept of the wrapped swap() function, so it should only be used when the argument type is unknown. In the vast majority of cases, the type is known to be efficiently std::swap()able or to have a member-swap. Call either of these. For the common case of pointer types, circumvent the expensive trait checks on std::swap() by providing a hand-rolled qt_ptr_swap() template, the advantage being that it can be unconditionally noexcept, removing all type traits instantiations. Don't document it, otherwise we'd be unable to pick it to 6.2. Effects on Clang -ftime-trace of a PCH'ed libQt6Gui.so build: before: **** Template sets that took longest to instantiate: [...] 27766 ms: qSwap<$> (9073 times, avg 3 ms) [...] 2806 ms: std::swap<$> (1229 times, avg 2 ms) (30572ms) after: **** Template sets that took longest to instantiate: [...] 5047 ms: qSwap<$> (641 times, avg 7 ms) [...] 3371 ms: std::swap<$> (1376 times, avg 2 ms) [qt_ptr_swap<$> does not appear in the top 400, so < 905ms] (< 9323ms) As a drive-by, remove superfluous inline keywords and template ornaments. Task-number: QTBUG-97601 Pick-to: 6.3 6.2 Change-Id: I88f9b4e3cbece268c4a1238b6d50e5712a1bab5a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Prevent repeated instantiations of ↵Marc Mutz2022-01-151-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | qRegisterNormalizedMetaType<QList<QModelIndex>>() This, finally, shows some expected results: Clang -ftime-trace: $ ClangBuildAnalyzer --analyze qtgui-spec-before.trace | head -n6 Analyzing build trace from 'qtgui-spec-before.trace'... **** Time summary: Compilation (523 times): Parsing (frontend): 665.7 s Codegen & opts (backend): 298.9 s $ ClangBuildAnalyzer --analyze qtgui-spec-after.trace | head -n6 Analyzing build trace from 'qtgui-spec-after.trace'... **** Time summary: Compilation (525 times): Parsing (frontend): 628.3 s Codegen & opts (backend): 301.0 s GCC 11 time (bash builtin): $ time for ((i=0; i < 3; ++i)) do touch ../qt5/qtbase/src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so real 4m10,918s user 49m10,099s sys 3m11,719s $ git revert --no-commit HEAD $ time for ((i=0; i < 3; ++i)) do touch ../qt5/qtbase/src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so [268/268] Creating library symlink qtbase/lib/libQt6Gui.so.6 qtbase/lib/libQt6Gui.so real 4m18,630s user 51m11,491s sys 3m16,479s The technique in the comment in qmetatype.h doesn't work on Clang - it runs into -Winstantiation-after-specialization. The whole extern template stuff so miserably fails to meet the goals set out in N1448, not only for MSVC and class templates, but, it seems, on all compilers, and for function templates, too, that I'm giving up on it for now. Unfortunately, I'm not really seeing a way to hide this stuff behind a macro, yet. Task-number: QTBUG-97601 Pick-to: 6.3 Change-Id: I500fd04555e0bd76ac021f75582bd8d8cf339378 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QAbstractItemModel::insert|move|remove(Columns|Rows)[s]() invokableVolker Krause2021-12-211-13/+13
| | | | | | | Useful for example for calling those from QML. Change-Id: I07fe32944c76b58cb074b6dd7eff17af1f0ae00f Reviewed-by: David Faure <david.faure@kdab.com>
* Allow proxy models access to the parent-child hierarchy of sourceLuca Beldi2021-04-191-2/+1
| | | | | | | | | | | 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>
* Dont' return a const ref to QModelIndexLars Knoll2020-12-041-1/+1
| | | | | | | | | | | 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-301-3/+3
| | | | | | | | | | | | | | 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>
* 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>
* 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>
* Long live QAIM::multiData!Giuseppe D'Angelo2020-09-021-0/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 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>
* Replace Qt CONSTEXPR defines with constexprAllan Sandfeld Jensen2020-08-141-10/+10
| | | | | | | | 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>
* Unexport QModelIndexGiuseppe D'Angelo2020-06-261-1/+1
| | | | | | | It is entirely inline. Change-Id: I626d6e4f6338dabfcc1e34127c898ed13c5a513b Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Use QList instead of QVector in corelibJarek Kobus2020-06-251-4/+5
| | | | | | | | | | Applied to headers only. Source file to be changed separately. Omitted statemachine for now to avoid conflicts. Omitted qmetatype.h for now - to be handled later. Task-number: QTBUG-84469 Change-Id: I317376037a62467c313467d92955ad0b7473aa97 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* ItemModels: remove deprecated functionsChristian Ehrlicher2020-06-071-33/+1
| | | | | Change-Id: Id3430493a62b11977f64e146f7668ca30935b959 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QAbstractItemModel: remove deprecated setRoleNames()Christian Ehrlicher2020-06-071-8/+0
| | | | | | | Remove setRoleNames() and all its now unneeded helper functions. Change-Id: I0a83751aace35700655d4cc7c79278325994cbdd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QModelIndex/QAIM: improve const correctnessGiuseppe D'Angelo2020-05-061-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QAIM::createIndex() takes a non-const void*. It's typically called from inside QAIM::index(), which is a const member function. If the data storage wrapped by the model is const correct, it means that we have to drop constness somewhere before calling createIndex(). To support this: change createIndex() to take a const void * instead. This is painless. Accessing the pointer is a bit more troubling, because the accessor (QModelIndex::internalPointer()) returns void *. (Effectively, now it does a const_cast...). To avoid a massive source break, I've left it alone, and instead added another function to retrieve a const void *. Read-only models can now be fully (deep) const correct. [ChangeLog][QtCore][QAbstractItemModel] The createIndex() function now takes a const void *, rather than a void *. [ChangeLog][QtCore][QModelIndex] Added the constInternalPointer() function, to retrieve the internal pointer as a pointer-to-const. Change-Id: I108912b6814fcd5fe0c5cb7db6c721ba51e83de0 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change qHash() to work with size_t instead of uintLars Knoll2020-04-091-5/+5
| | | | | | | | | | | This is required, so that QHash and QSet can hold more than 2^32 items on 64 bit platforms. The actual hashing functions for strings are still 32bit, this will be changed in a follow-up commit. Change-Id: I4372125252486075ff3a0b45ecfa818359fe103b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Get rid of QList forward declarationsLars Knoll2019-10-041-1/+0
| | | | | | | | Include qcontainerfwd.h instead where required. This prepares for unifying QList and QVector. Change-Id: I6c85e2bdd44fb41aedd884b0d551f682760df5b5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove handling of missing Q_COMPILER_RVALUE_REFSAllan Sandfeld Jensen2019-04-081-2/+0
| | | | | Change-Id: I7bc6c455fbae4cdad584c76773299a6d8cd40c82 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-19/+19
| | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make QAbstractItemModel::resetInternalData virtual for Qt 6Frederik Gladhorn2018-11-081-1/+3
| | | | | | | Change-Id: I9cfeb93addb717abc187a8dab8d24076f68bd61d Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* New proxy model: QTransposeProxyModelLuca Beldi2018-11-051-0/+2
| | | | | | | | | | | | Implemented a new proxy model to transpose the source model. Rows will become columns and vice-versa. Both flat and tree models supported. [ChangeLog][QtCore] New class QTransposeProxyModel to swap rows and columns of the source model. Change-Id: I902963c6b81aa0f63b5ad2bddca538f28b565084 Reviewed-by: David Faure <david.faure@kdab.com>
* Add a method to clear the data to QStandardItemModelLuca Beldi2018-08-171-0/+3
| | | | | | | | | | After the behavior of setItemData has been changed following QTBUG-45114, QStandardItemModel was lacking an interface to clear all the data from a single index. Task-number: QTBUG-69616 Change-Id: Ide0b5bb6358439fc42c474df8b044fbace6def8d Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: David Faure <david.faure@kdab.com>
* Make sure we can build with -no-feature-itemmodelUlf Hermann2018-03-211-0/+2
| | | | | | | Various pieces of code have to be disabled in this case. Change-Id: I83b133f17e9f024016a79c9103293627185449d2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* Add QModelIndex::siblingAtColumn and ::siblingAtRowAndre Somers2018-01-121-0/+8
| | | | | | | | | | | | | | | | | | | | Data in item models is most often organized in rows, where each column contains an attribute of the item represented by the row. Often when sibling is used, it is to request another piece of data from the same row. Having a specialized version makes this easier and less awkward to do, simplifying auto sibling = index.sibling(index.row(), columnOfInterest); to auto sibling = index.siblingAtColumn(columnOfInterest); For symmetry reasons, siblingAtRow(rowOfInterest) was also added. Change-Id: Ib203b2cdb16154cbb2680d16fb5c6a7538f33d07 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* Introduce QAbstractItemModel::checkIndex()Giuseppe D'Angelo2018-01-081-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When implementing a custom model there's the habit, in each and every function that takes a QModelIndex, to carefully checking the index passed by the caller. This index is checked for "legality" (*): does the index belong to this model, is the index pointing to an existing row and column, and so on. These checks are hand-rolled and, as such, slightly different and possibly incomplete (i.e. wrong) every time. What's worse, these checks are implemented via "ordinary" code (if statements). However, passing an illegal index to a QAIM function is a precondition violation, and as such does not (and must not) be checked in ordinary conditions, as it triggers undefined behavior. On the other hand, while debugging a custom model or a custom hierarchy of (proxy) models, having such checks in place can be a significant aid. Enter checkIndex(): a debugging helper for QAbstractItemModel and its subclasses. checkIndex() centralizes the checks for legality of a given index. User code is free to assert on it, or have some other fallback mechanism in case a check fails. (*) Using "legality" here instead of "validity" in order to avoid confusion between QModelIndex::isValid() and what checkIndex() really does. [ChangeLog][QtCore][QAbstractItemModel] Added QAbstractItemModel::checkIndex(), a debugging function for QAbstractItemModel subclasses. Change-Id: I1eea0586b1ac3ededdbfbf46759145022dc5ad86 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Merge remote-tracking branch 'origin/5.10' into devLiang Qi2017-09-261-1/+1
|\ | | | | | | | | | | | | | | | | | | | | Conflicts: src/gui/kernel/qguiapplication.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h src/plugins/platforms/cocoa/qcocoawindow.h src/testlib/qtestsystem.h Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
| * QModelIndex: use std::less to compare pointersGiuseppe D'Angelo2017-09-011-1/+1
| | | | | | | | | | | | | | | | Comparing pointers not belonging to the same array requires using std::less. Change-Id: I2725aa0899f6b9fece73dadd9ee5c10242d50ae1 Reviewed-by: David Faure <david.faure@kdab.com>
* | Replace Q_NULLPTR with nullptr where possibleKevin Funk2017-09-191-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Remaining uses of Q_NULLPTR are in: src/corelib/global/qcompilerdetection.h (definition and documentation of Q_NULLPTR) tests/manual/qcursor/qcursorhighdpi/main.cpp (a test executable compilable both under Qt4 and Qt5) Change-Id: If6b074d91486e9b784138f4514f5c6d072acda9a Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Replace Q_DECL_OVERRIDE with override where possibleKevin Funk2017-09-191-13/+13
|/ | | | | | | | | | | | | | | | Remaining uses of Q_DECL_OVERRIDE are in: src/corelib/global/qcompilerdetection.h src/corelib/global/qglobal.cpp doc/global/qt-cpp-defines.qdocconf (definition and documentation of Q_DECL_OVERRIDE) tests/manual/qcursor/qcursorhighdpi/main.cpp (a test executable compilable both under Qt4 and Qt5) Change-Id: Ib9b05d829add69e98a86238274b6a1fcb19b49ba Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Deprecate Q(Persistent)ModelIndex::childGiuseppe D'Angelo2016-08-161-2/+8
| | | | | | | | | | | | | | | | | | | | | | Due to how invalid model indices are handled in Qt, child() is unsuitable for general purpose usage. In particular you can never get a top level item in the model because the root model index by definition hasn't got a pointer to the model it belongs. That makes child() useless for anything but tree models (and even there you'd need to special case your code anyhow). [ChangeLog][QtCore][QModelIndex] QModelIndex::child has been deprecated due to its lack of generality. Use model->index(row, column, index) instead. [ChangeLog][QtCore][QPersistentModelIndex] QPersistentModelIndex::child has been deprecated due to its lack of generality. Use model->index(row, column, index) instead. Change-Id: Ice73c17133aaf71355fa2af1eacfe64da01bd456 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-04-071-1/+1
|\ | | | | | | | | | | | | | | | | | | Conflicts: src/network/access/qftp.cpp src/widgets/itemviews/qheaderview.cpp src/widgets/itemviews/qlistview.cpp tests/auto/network/access/qftp/tst_qftp.cpp Change-Id: I9f928f25d45d8944dd60bb583f649fc1615bc5d9
| * Fix UB (shift of negative number) in qHash(QModelIndex)Marc Mutz2016-04-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found by UBSan: itemmodels/qabstractitemmodel.h:426:28: runtime error: left shift of negative value -1 Fix by casting the lhs of the left-shift operator to uint before shifting. Since Qt assumes two's complement repre- sentation of signed integers, this should yield the same result as the old code, but without UBs. It is critically important that the result is identical to the old code (modulo the compiler exploiting the UB, which this patch aims to prevent even in future compilers), because the function is inline, and changing the hash value would mean changing the layout of a QHash<QModelIndex,.> between users compiled against the old and new libraries. Change-Id: I7b826a34fb78b02021e40c3f85fd11af398dbec4 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | Updated license headersJani Heikkinen2016-01-151-14/+20
|/ | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QtCore: Use Q_NULLPTR instead of 0 in all public headersMarc Mutz2015-07-011-7/+7
| | | | | | | | | This is in preparation of adding -Wzero-as-null-pointer-constant (or similar) to the headers check. Task-number: QTBUG-45291 Change-Id: I0cc388ef9faf45cbcf425ad0dc77db3060c104a8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QModelIndex: Fix a nullptr literal 0 that would look odd as nullptrMarc Mutz2015-06-301-1/+1
| | | | | | | | By dropping it. Found while looking into Task-number: QTBUG-45291 Change-Id: Ie7655d607244aa67219ade465525ec771c87ccf5 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* qdoc: Remove #ifdef Q_QDOC for uses of QPrivateSignalMartin Smith2015-04-201-70/+14
| | | | | | | | | | | | Signals marked with QPrivateSignal had the QPrivateSignal marker ifdefed out for qdoc. This is no longer necessary, so the #ifdefs are removed. Change-Id: Idb334ed311c6ed6883d7b7b5a3fcdede60c4a1f8 Task-number: QTBUG-45535 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
* QAbstractItemModel: Make the match() method Q_INVOKABLEStephen Kelly2015-03-251-4/+4
| | | | | | | | With reasoning similar to commit v5.5.0-alpha1~123 (Make some QAbstractItemModel API invokable, 2015-02-25) Change-Id: I77c72f7bb856a1eee966b45950384fe03a8eaac6 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
* Make QPersistentModelIndex an internal meta-typeGabriel de Dietrich2015-03-061-1/+0
| | | | | | | | | | | It was already a user meta-type, so it only gets promoted to internal. [ChangeLog][QtCore] QPersistentModel index becomes an built-in meta-type, including QVariant support. Change-Id: I63d733d1eb66aa61691e7afce27fe7372a83ac00 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Make some QAbstractItemModel API invokableStephen Kelly2015-03-041-13/+13
| | | | | | | | | | | | | | | As QAIM and related classes are becoming more useful in the QML environment, it makes sense to make these invokable. Make the access API and the setData method scriptable. Avoid making the structure changing APIs scriptable now to be conservative. Export the ItemDataRole enum through the staticQtMetaObject to make built-in roles available. Change-Id: I47b1682e6fa8ba32c7314c73fc10a7bbaa6d1f98 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> Reviewed-by: Stephen Kelly <steveire@gmail.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* QAbstractTableModel/QAbstractListModel: reimplement sibling()Marc Mutz2015-02-051-0/+2
| | | | | | | | | | | | | | | | | | | | This basically inlines the call to parent(), which unconditionally returns QModelIndex(). The change is binary compatible, because even though we newly override a previously non-overridden virtual method, it doesn't matter whether old code still calls the base class' method, as the new implementation is semantically equivalent, at least if subclasses don't inherit parent() (but why would they). [ChangeLog][QtCore][Important Behavior Changes] QAbstractTableModel and QAbstractListModel now reimplement sibling() to avoid calling parent() (which returns a constant). Subclasses of these models that override parent(), will likely also need to override sibling() now. Change-Id: I9e0cb5622a6d3826e40acaf0e0cd3fdea85cba2d Reviewed-by: David Faure <david.faure@kdab.com>