summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
Commit message (Collapse)AuthorAgeFilesLines
* QItemSelectionRange: use new comparison helper macrosTatiana Borisova8 days2-8/+16
| | | | | | | | | | | | Replace public operators operator==(), operator!=() of QItemSelectionRange class to friend methods comparesEqual(). Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Task-number: QTBUG-120304 Change-Id: Ideff990c942d5ee1c89a93ac2081cc5d7067b23f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QEmptyItemModel: add Q_OBJECT macroJuha Vuolle8 days1-0/+2
| | | | | | | | Task-number: QTBUG-122619 Change-Id: Ie84e13d64071d2735e0f873b26a73e476d761742 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QIdentityProxyModel: add setHandleSourceLayoutChanges(bool)Ahmad Samir2023-12-153-4/+44
| | | | | | | | | | | | | | | | | | | | | | | Some sub-classes have special handling of source model layout changes (abbreviated as SMLC from here on out), they relied on disconnecting the connections to the _q_*layout* slots in the private class using the SLOT macro. This isn't possible any more after recent changes (and the method were renamed to remove _q_ prefix). Sub-classes resorting to using private API is a clear sign some functionality is missing from the public API, so a cleaner solution for this issue is adding this setter which enables sub-classes to tell QIdentityProxyModel to leave handling of the SMLC to them. Thanks to David Faure for the idea/solution. [ChangeLog][QtCore][QIdentityProxyModel] Added setHandleSourceLayoutChanges(bool) method to allow sub-classes to indicate to QIdentityProxyModel that they will handle source model layout changes on their own. Also added a getter, isHandleSourceLayoutChanges(). Change-Id: I1de79dd693ce32a6e2df9a7c81dd4abdc5f00248 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QIdentityProxyModel: store connection handles in a containerAhmad Samir2023-12-153-135/+110
| | | | | | | | | | | | | | | | | | | | | Port to PMF signal/slot syntax: compile-time type checking vs. run-time string-based search. Given how many connections are made, this is both safer and more readable. Drop the _q_ prefix from method names, it was needed since Q_PRIVATE_SLOT() was used for those methods. Use QVLA since we know the size at compile time, (not a std::array like other changes because some elements in the std::initializer_list are going to be split out, so using a container with a push_back() is simpler than fiddling with indexes to use operator[], see next commit in this chain for details). This is similar to c609b8dba0ae43aeba142164684536f808aad501, so a similar performance improvement is expected. Change-Id: Ia7e7d0b1f3c1a95bc399bd06de3b5c96e845b34d Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* Itemmodels: s/QPair/std::pair/Marc Mutz2023-12-144-29/+28
| | | | | | | | | | | | | | Also port from qMakePair() to just braced initialization and CTAD. As a drive-by, use emplacement instead of appending pairs explicitly, rewrite typedef into `using`, and remove the qpair.h include from the .cpp file (cannot affect other TUs and <utility> is considered included in qcompilerdetection.h). Pick-to: 6.7 Task-number: QTBUG-115841 Change-Id: Ia985520dfce6b77b1c0fe7669fc92d2df97e1b06 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QSortFilterProxyModel: scope a variable tighterMarc Mutz2023-12-131-2/+1
| | | | | | | | | | The clear() will not preserve capacity, since the QList has been copied into proxy_intervals already, so is shared. But then creating a new QList is just as efficient, or more so. Pick-to: 6.7 Change-Id: I7ffd91bae8ded5ac28d58bcc545c479f6edc7c90 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QAbstractProxyModel: Emit headerDataChanged() signal with valid dataIevgenii Meshcheriakov2023-12-122-30/+48
| | | | | | | | | | | | | | | | This amends commit a0bcad39033bddd9b9d14a524b829513105913d3. Delayed signals emitted by the previous commit may have invalid parameters if the source model was updated several times before entering the event loop. This commit fixes that by evaluating the section range immediately before emitting the signal. This commit also ensures that the signal is emitted only once after entering the event loop. Fixes: QTBUG-119155 Pick-to: 6.6 6.5 6.7 Change-Id: I9e84703cca26fde8464a6b9a414bb7462cbb9abd Reviewed-by: David Faure <david.faure@kdab.com>
* Doc: Fix \fn template arguments for Qt CoreLuca Di Sera2023-11-301-1/+1
| | | | | | | | | Upcoming changes to QDoc require accurate definition for template arguments in \fn commands. Task-number: QTBUG-118080 Change-Id: I64d50919bc6ffab61ef5ead553d1da99d63a9f21 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Doc: Fix template information for a QModelRoleDataSpan constructorLuca Di Sera2023-11-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When QDoc parses a project, it parses the source code to extract the user-provided documentation and perform sanity checkings based on the code itself on it. When QDoc parses an "\fn" command as part of this process, it tries to understand, based on its intermediate representation built on the information extracted from the code-base, which "documentable element" the "\fn" refers to. When QDoc performs this "matching" process, it takes into consideration only a certain amount of information. For example, no checking is performed over the template declaration of a callable. Due to some upcoming documentation, where two callables are indistinguishable to the current process, as they differ only in their template declaration, QDoc will start to take into consideration the template declaration of a callable when matching. This implies that an "\fn" command should now provide information parity, with regards to template declaration for callables, with the code-base so that QDoc can perform the match correctly. The documentation for `QModelRoleDataSpan::QModelRoleDataSpan(Container&)` is not in sync with the intended target template declaration. Hence, add the missing information to the relevant "\fn" commands. Task-number: QTBUG-118080 Change-Id: I08c7adf901fac81bb1c115a5017908cba4656bea Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QSortFilterProxyModel: remove duplicate implementationsPo-Hao Su2023-10-201-15/+3
| | | | | | | | | Since these functions perform the same operation as the base class QAbstractProxyModel, we can use the counterparts of the basic class directly to keep the implementation clean. Change-Id: Ie16a988f5ad25eb202351713e6aee73df266209b Reviewed-by: David Faure <david.faure@kdab.com>
* Doc: Fix warnings and linking issuesTopi Reinio2023-10-091-1/+7
| | | | | | | | | | | | | | | | | | | | Remove or replace links to examples that were removed or moved under manual tests. Replace code snippets that were quoting the now-missing examples. Fix documentation of QSet::removeIf(). Fix typo in documentation macro: Unknown command '\examplecateogry'. Add qtopengl, qtshadertools dependencies to Qt Widgets documentation project to enable correct linking to those topics. Mark all documentation sets in qtbase as free of warnings. Pick-to: 6.6 6.5 Change-Id: I058cd5f2063aa933ea310bceff906f05422a7cb2 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Doc: state that models are not thread-safeMitch Curtis2023-10-021-1/+3
| | | | | | | Fixes: QTBUG-107598 Pick-to: 5.15 6.2 6.5 6.6 Change-Id: I0e7ea8d4b2094d92b3cad5eec5b30e6e3ac64018 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QPersistentModelIndex: fix relational operators not being noexceptMarc Mutz2023-09-302-9/+9
| | | | | | | | | | | | | 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>
* QPersistentModelIndex: fix UB (op< on unrelated pointers)Marc Mutz2023-09-301-1/+3
| | | | | | | | | | | | | | Pointers can only be legitimately compared with less-than (<) if they point into the same array (or one past the end). This is decidedly not the case for heap-allocated objects like QPersistentModelIndexPrivates, so doing it is UB. Fix by using std::less, which is guaranteed to be a total order, even for unrelated pointer values. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: If04341b4b55784e7732782f3ae829f53b0ceab9c Reviewed-by: David Faure <david.faure@kdab.com>
* QConcatenateTablesProxyModel: store connections in a containerAhmad Samir2023-09-252-80/+113
| | | | | | | | | | | | | | | | | | | | Reuse the existing QList container, but instead of holding QAbstrictItemModel* now it holds a struct{model,std::array<Connections>}. Use std::array since the number of connections is known at compile time. Drop the _q_ prefix from method names, it was used to mark them as being used in Q_PRIVATE_SLOT(). This is similar to c609b8dba0ae43aeba142164684536f808aad501, so a similar performance improvement is expected. Drive-by change, fix narrowing by using qsizetype instead of int in a for-loop. Change-Id: Iac70dcbff0a949c72daa6dae52e3f752c2ee0557 Reviewed-by: David Faure <david.faure@kdab.com>
* QItemSelectionModel: remove some redundant codeAhmad Samir2023-09-231-3/+1
| | | | | | | | | | | | QObject::disconnect(connection) already sets connection.d_ptr to nullptr, and the default constructor only does that: QMetaObject::Connection::Connection() : d_ptr(nullptr) {} So calling disconnect() suffices in this case. Pick-to: 6.6 6.5 6.2 Change-Id: Icd5f9a15c83939eeecd9efb474ac3b38c0f2dfe4 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QConcatenateTablesProxyModel: simplify codeAhmad Samir2023-09-221-2/+2
| | | | | | | | If there is a reason to static_cast to `const QAIM*` then cast away the const, I failed to see it. QObject::sender() returns a non-co. Change-Id: Ibf8c8613c3de1584b426269c1ffba94db75d26d6 Reviewed-by: David Faure <david.faure@kdab.com>
* QItemSelectionModel: don't warn when destroying the modelVolker Hilsheimer2023-09-221-3/+3
| | | | | | | | | | | | | | | | | | | Amends 4f4a8e75ab34003a4a49b89392ae7712415ac788, after which QItemSelectionModel printed a warning when destroying the model. We reset the selection model in response to the model getting destroyed, and since the model is already set to be nullptr at this point the select() function complains about changing the selection with no model set being a no-op. Fix this by not calling reset() when the model gets destroyed - the stored selection and currentIndex are already reset at this point - and instead only call reset() when a new model is set in initModel. Fixes: QTBUG-117200 Pick-to: 6.6.0 6.6 6.5 6.2 Change-Id: I12fc6b3fb2f2ff2a34b46988d5f58151123f9976 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QItemSelectionModel: fix binding loopsIvan Solovev2023-09-061-16/+17
| | | | | | | | | | | | | | | ... by using valueBypassingBindings() when accessing the properties from the setters. Also adjust initModel() to use the raw pointers instead of accessing the property when comparing the value and doing all connections. This change is safe, because initModel() is a private method that is only called from the constructors of the class and the setter. Task-number: QTBUG-116346 Pick-to: 6.6 6.5 Change-Id: I6ecde571aeed74077099c6bf8f66736ba14d29f8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QItemSelectionModelPrivate: improve formatting of the connectionsIvan Solovev2023-09-061-24/+25
| | | | | | | | | | | | | | The formatting of the connections in the initModel() call was confusing and made me overlook the fact that they all were directly used to initialize the connections array. Indent all the nested connections, and move the closing '}' to a separate line to make the code more readable. This commit amends 4f4a8e75ab34003a4a49b89392ae7712415ac788. Pick-to: 6.6 6.5 Change-Id: I607e09699a3b4865cb17639ffc75f754f4400c91 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
* QSortFilterProxyModel: fix binding loopsIvan Solovev2023-09-031-7/+8
| | | | | | | | | | ... by using valueBypassingBindings() when accessing the properties from the setters. Task-number: QTBUG-116346 Pick-to: 6.6 6.5 Change-Id: Ibbad552fa1e611f4bb704b4e47667df5f328f152 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QAbstractProxyModel: fix binding loopsIvan Solovev2023-09-031-5/+6
| | | | | | | | | | | | | | | | ... by using valueBypassingBindings() when accessing the properties from the setters. This commit is mostly trivial. Had to change the template parameters in the unit-test, because the updated QTestPrivate::testReadWritePropertyBasics() creates an instance of the TestedClass, and QAbstractProxyModel cannot be instantiated, since it has pure virtual methods. Task-number: QTBUG-116346 Pick-to: 6.6 6.5 Change-Id: I0cae29263ea9bb92c9de06891b0ba8633fb9fd72 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QItemSelectionModelPrivate: use QObjectPrivate::connectAxel Spoerl2023-09-013-60/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | QItemSelectionModelPrivate::initModel() uses string based connections, to connect/disconnet its QAbstractItemModel. The QObject::destroyed signal is connected to modelDestroyed(), which does not disconnect other signals. QQuickTableView's selection model binds to its QAbstractItemModel. The binding also reacts to QObject::destroyed Eventually, QItemSelectionModel::setModel(nullptr) is called. At this point, only a QOBject is left from the QAbstractItemModel. That leads to warnings about disconnecting string based signals, which belong to QAbstractItemModel. This patch changes the connect syntax to the QObjectPrivate::connect API. Instead of keeping a list of string based connections around, the connections themselves are kept in a list member. Disconnecting happens based on that list. Connections are also disconnected in QAbstractItemModelPrivate::modelDestroyed. An auto test is added in tst_QItemSelectionModel. Fixes: QTBUG-116056 Pick-to: 6.6 6.5 6.2 Change-Id: I57e5c0f0a574f154eb312a282003774dd0613dd6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Doc: Remove links to removed examplesAndreas Eliasson2023-08-281-5/+4
| | | | | | | | These examples have been removed as part of the examples revamp project. Pick-to: 6.6 6.5 Change-Id: I2a8237334a2acae2735c2dbd86004048d288896a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QSortFilterProxyModel: "fix" connection names in connect callsAhmad Samir2023-08-161-19/+19
| | | | | | | | | | d->model is the source model, so a QAbstractItemModel; techincally it made no difference because it resolves to the same signal(s), but it's less confusing as QAbstractItemModel. Pick-to: 6.6 Change-Id: I4388a50ac33a2bee628fccc1aef6a9d1898e2ca2 Reviewed-by: David Faure <david.faure@kdab.com>
* 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>
* 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>
* QAbstractProxyModel: delay headerDataChanged emissions when ↵Giuseppe D'Angelo2023-06-231-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | inserting/removing rows/columns 33c88f86b5b8714977719a8ccff0f7c15c9cbd44 added some logic to QAPM in order to have it automatically emit headerDataChanged when rows/columns were added or removed in the model. This was done as a stopgap measure to prevent QAPM from asking for illegal indices in order to implement automatic remapping of the section headings (since there's no mapSectionToSource). The commit seems to have introduced a regression in QHeaderView, which isn't prepared to receive headerDataChanged while a row/column count change is in progress. When receiving headerDataChanged, QHeaderView will try to read the row/column count and will store it internally. When it will then receive the signals for insertion/removal of rows/columns, it will interpret it as a modification of the previously stored value -- even if the value it stored was already correct. Fix this by avoiding to have two signals in flight at the same time; emit headerDataChanged as a queued invocation. Task-number: QTBUG-114225 Change-Id: I521465a852b8c7135f22f730ead41dca760ba428 Pick-to: 6.5 6.6 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Add missing #includesAhmad Samir2023-06-052-0/+2
| | | | | | | | | | | | This is needed by static analysis tools (which compile each header on its own, IIUC), e.g. clang-tidy: src/widgets/itemviews/qtableview_p.h:99:22: error: unknown type name 'QTableView' [clang-diagnostic-error]. Q_DECLARE_PUBLIC(QTableView) ^ Change-Id: I84a1221469e9a78f243cc892ef7c60da9b515718 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* 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>
* QAbstractItemModel: fix match() with Qt::MatchWildcardGiuseppe D'Angelo2023-03-091-2/+4
| | | | | | | | | | | | | | | | | | | QAIM::match() supports different matching modes. The wildcard match mode was never meant to be specifically a filepath globbing wildcard, but rather a generic one -- something like "*" should match into a string like "a/b/c". This is a regression from Qt 5, where QRegExp::Wildcard was ported to only allow for path globbing rather than generic matching. [ChangeLog][QtCore][QAbstractItemModel] QAbstractItemModel::match() now uses more generic wildcard matches rather than file path globbing. Please refer to the documentation of QRegularExpression::wildcardToRegularExpression() for more information about the differences. Change-Id: I28b8a76b01fdd9c5dd8f99528fac1c7b704564bc Fixes: QTBUG-104585 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live QScopedPropertyUpdateGroupMarc Mutz2023-02-101-4/+2
| | | | | | | | | | | | A RAII wrapper around Qt::{begin,end}PropertyUpdateGroup(). [ChangeLog][QtCore][QScopedPropertyUpdateGroup] New RAII class wrapping Qt::beginPropertyUpdateGroup() and Qt::endPropertyUpdateGroup(). Fixes: QTBUG-110710 Change-Id: If2619e9584dd9d57985d63e3babca75421499ab9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QSortFilterProxyModel: port to PMF connects for performance reasonsDavid Faure2023-02-022-108/+48
| | | | | | | | | | | | | BEFORE: 0.21 msecs per iteration (total: 56, iterations: 256) 801,946 CPU cycles per iteration (total: 801,946, iterations: 1) AFTER: 0.084 msecs per iteration (total: 87, iterations: 1024) 300,259 CPU cycles per iteration (total: 300,259, iterations: 1) Change-Id: I5b2703c217bb25e18f1d9f6a1eda19c60e1edcb0 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QAbstractProxyModel: normalize signals/slots signaturesDavid Faure2023-01-111-6/+8
| | | | | | | | | | | | This is better for performance. Switching to PMF connects would break some subclasses outside Qt (like KExtraColumnsProxyModel) which need to disconnect some internal connections,so it would require adding API to toggle those things; too complicated for this small performance fix. Change-Id: If89dbadc9cc84c94ca70b71cbc5afc267aebffd1 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-037-49/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 qAsConst() to std::as_const()Marc Mutz2022-10-114-15/+15
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-044-42/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 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>
* QAbstractItemModel: Fix Qt::TextAlignmentRole when metatype is uintJonas Kvinge2022-05-221-4/+8
| | | | | | | | | | | When combining text alignment flags, it no longer works since the metatype for example QVariant(Qt::AlignRight | Qt::AlignVCenter) is uint, not int. Fixes: QTBUG-103576 Pick-to: 6.2 6.3 Change-Id: If0291b99606787081c4bc26fd00431f8a17a61a2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-1621-800/+44
| | | | | | | | | | | | | 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>
* Document the default value of QSFPM::sortOrder()Andreas Hartmetz2022-04-281-2/+5
| | | | | | | | | ...and how to change the value, which is by calling sort(). Also, this is not a property either. Pick-to: 5.15 6.2 6.3 Change-Id: I1b1be90dc43c29e85903a33d0f99569fd6c87abb Reviewed-by: David Faure <david.faure@kdab.com>
* Better document how to enable sorting in QSPFMAndreas Hartmetz2022-04-281-2/+7
| | | | | | | | | | | | | | This can be a big time sink otherwise. Unlike reimplementing filterAcceptsRow() for filtering, reimplementing lessThan() is *not* sufficient to enable sorting. As a drive-by, change \brief to \return because sortOrder() is not a (formal) property. Pick-to: 5.15 6.2 6.3 Change-Id: I7e7be6f1e8e6b03a9923a7f77f04005b19a69d41 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Exploit the new macro varargs form of Q_GLOBAL_STATICEdward Welbourne2022-04-221-3/+3
| | | | | | | | Convert various uses of Q_GLOBAL_STATIC_WITH_ARGS() to the less verbose form the recent reworking makes possible. Change-Id: I57820660b5d00d39bf54b5a08cb921ebaec57c7c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QAbstractProxyModel: do not access invalid indexesGiuseppe D'Angelo2022-04-133-9/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QAbstractProxyModel::headerData tries to do the "smart" thing and map sections in the proxy to sections in the source. However there's no "mapSectionToSource" virtual. Instead, to map horizontal headers, the code builds a proxy index at row 0 and section N, maps it to the source, and finds out which source column it gets mapped to. (Same story for the vertical headers). ... in general this can obviously fail, say you've got a "horizontal scrambling" proxy model, but in the common case this is OK. Except, if the proxy is empty (e.g. 0 rows or columns). In this case, it asks for an illegal index, and if you reimplemented index() yourself (which you must, since it's a pure virtual in QAPM) and you do bounds checking, you'll not be pleased at the result. This turns out to be a massive API liability. To fix this somehow properly, we can decide that empty models don't get the section remapped (easy). Less easy is the fact that, when the model does get some data, we have to emit headerDataChanged() otherwise the views will get broken. So add this logic too. Note that QAPM does not normally forward any source model's signal -- a subclass has to connect to them and handle them explicitly. That's *another* API liability, all over the place -- data(), headerData(), flags(), etc. What I mean by this is that one can create a valid QAPM (by implementing its pure virtuals) that however is immediately broken by the convenience that QAPM provides for the rest (data(), headerData(), etc.). This commit doesn't try and change this in any way, but I'm less and less convinced of the usefulness of QAPM in its current shape. Change-Id: I45a8c2139f2c1917ffbf429910fdb92f005f4feb Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Faure <david.faure@kdab.com>
* Itemviews: start fixing mixups of int/enum for Qt's item rolesGiuseppe D'Angelo2022-03-231-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | A model is supposed to return a Qt::CheckState for a CheckStateRole, and a Qt::Alignment for a Qt::TextAlignmentRole. This is what the documentation says (and what makes sense), but unfortunately Qt's default delegate expected a plain `int` instead. This sometimes worked (via QVariant conversions, e.g. when using a plain enum) and sometimes didn't (e.g. when using a flag type). This is confusing for end-users (and type unsafe, killing the whole point of using enums and flags in the first place). Adding some automatic flags<->int conversions through QVariant is frowned upon, so I don't want to go there. Instead, add some private convenience functions that extract either the right type from a variant, or try to extract an `int` and convert it to the expected type. Use these from within itemviews code. Change-Id: I44bee98c4a26a1ef6c3b2fa1b8de2edfee7aef32 Pick-to: 6.2 6.3 Fixes: QTBUG-75172 Task-number: QTBUG-74639 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Core: Do not depend on transitive includesFabian Kosmale2022-03-175-0/+5
| | | | | Change-Id: I2c71188a4d27692a2d6ef1aa447b329627214b17 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QItemSelectionModel: avoid 24 relocationsMarc Mutz2022-03-111-35/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use qOffsetStringArray() instead of an array of pairs of pointers. This unearthed a problem with SIGNAL and SLOT calling qFlagLocation() (meaning in debug mode, the array was runtime-initialized, not just relocated), which we work around by using the new QT_STRINGIFY_ {SIGNAL,SLOT} macros now. Saves 24 relocations, but, interestingly, saves only 4b in text size on GCC 11.2 Linux AMD64 -O2 C++20 builds (TEXT and DATA combined) while saving 760b on the equivalent Clang 10 libc++ build (expected, in both cases: 24 * (sizeof(void*) - sizeof(quint16))): Clang: $ size qtbase/lib/libQt6Core.so.6.4.0 text data bss dec hex filename 5476156 90520 16185 5582861 55300d qtbase/lib/libQt6Core.so.6.4.0 $ ~/bin/relinfo.pl qtbase/lib/libQt6Core.so.6.4.0 qtbase/lib/libQt6Core.so.6.4.0: 6528 relocations, 3598 relative (55%), 2540 PLT entries, 2227 for local syms (87%), 0 users $ ninja libQt6Core.so [6/6] Creating library symlink qtbase/lib/libQt6Core.so.6 qtbase/lib/libQt6Core.so $ size qtbase/lib/libQt6Core.so.6.4.0 text data bss dec hex filename 5475604 90312 16185 5582101 552d15 qtbase/lib/libQt6Core.so.6.4.0 $ ~/bin/relinfo.pl qtbase/lib/libQt6Core.so.6.4.0 qtbase/lib/libQt6Core.so.6.4.0: 6504 relocations, 3574 relative (54%), 2540 PLT entries, 2227 for local syms (87%), 0 users GCC: $ ~/bin/relinfo.pl qtbase/lib/libQt6Core.so.6.4.0 qtbase/lib/libQt6Core.so.6.4.0: 6300 relocations, 5343 relative (84%), 318 PLT entries, 1 for local syms (0%), 0 users $ size qtbase/lib/libQt6Core.so.6.4.0 text data bss dec hex filename 6019871 75896 16952 6112719 5d45cf qtbase/lib/libQt6Core.so.6.4.0 $ ninja libQt6Core.so [6/6] Creating library symlink qtbase/lib/libQt6Core.so.6 qtbase/lib/libQt6Core.so $ ~/bin/relinfo.pl qtbase/lib/libQt6Core.so.6.4.0 qtbase/lib/libQt6Core.so.6.4.0: 6276 relocations, 5319 relative (84%), 318 PLT entries, 1 for local syms (0%), 0 users $ size qtbase/lib/libQt6Core.so.6.4.0 text data bss dec hex filename 6020091 75672 16952 6112715 5d45cb qtbase/lib/libQt6Core.so.6.4.0 Pick-to: 6.3 Change-Id: I60749953f1a63d23d696a5a547cd924ec259ead3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QAbstractItemModel: fix persistent index corruption when moving columnsDavid Faure2022-02-281-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | QHeaderView creates persistent indexes in _q_sectionsAboutToBeChanged(), called by the slot connected to rowsAboutToBeMoved/columnsAboutToBeMoved. In the case of rows, QAbstractItemModel emits the signal *before* preparing to update persistent indexes in itemsAboutToBeMoved(), so it can see the ones newly created by QHeaderView, all is well. In the case of columns, the emit was done *after* calling itemsAboutToBeMoved(), so the additional persistent indexes created by QHeaderView were ignored, and in endMoveRows() we could end up with: ASSERT failure in QPersistentModelIndex::~QPersistentModelIndex: "persistent model indexes corrupted" This bug has been there since the very beginning of beginMoveColumns(), but was undetected because moving columns in a model is pretty rare (in my case there's a QTransposeProxyModel that turns columns into rows in the underlying model, and a proxy that handles dropMimeData...) Pick-to: 6.3 6.2 5.15 Change-Id: I74bad137594019a04c2a19c2abb351ff3065c25a Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QAbstractItemModel: make naming of arguments consistentAndreas Buhr2022-02-192-10/+10
| | | | | | | | | 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>