summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels
Commit message (Collapse)AuthorAgeFilesLines
* QFileSystemModel: Add role for fileinfoSune Vuorela2024-04-112-1/+7
| | | | | | | | | | Instead of having users traverse a ProxyModel hierarchy to get to a QFileSystemModel to use the fileInfo(QModelIndex) function, just let it be available with the roles. Change-Id: I285347d1d85b4c6253fcb893737aa629a56e27fd Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QFileSystemModel: Wake file info gatherer thread up before waiting on itVolker Hilsheimer2024-04-091-1/+1
| | | | | | | | | | | | | | | | | | Amends 0786c17bbc556a0f494fc825af47c604a9dc0241, which added a number of attempts to gracefully shut down the QFileInfoGatherer thread while shutting down a QFileSystemModel. This introduced a 1-second wait upon destruction of the model when the QFileInfoGatherer thread is waiting for an unset wait condition. Instead of QThread::requestInteruption() to make the thread exit, use QFileInfoGatherer::requestAbort(), which calls requestInteruption() but also sets the wait condition afterwards to make sure that the thread wakes up and checks the abort condition. Pick-to: 6.6 6.7 Fixes: QTBUG-124164 Change-Id: I560f2131f226e0bb59f72e558cbab55b89cfb144 Reviewed-by: David Faure <david.faure@kdab.com>
* Port to QDirListingAhmad Samir2024-03-032-5/+6
| | | | | | | | | | | Use QDirListing in the Bootstrap build instead of QDirIterator. Drive-by changes: - more const variables - use emplace_back() instead of append() where appropriate Change-Id: Ie1f0d03856e557c4bfabfff38a87edc7da86d091 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFileSystemModel: don't crash with setIconProvider(nullptr)Ahmad Samir2024-02-013-8/+21
| | | | | | | | | | | | | | | | | | | | The method takes a pointer, so the code shouldn't crash when passed a nullptr. QFileInfoGatherer::getInfo() still needs to generate a descriptive string for the file, so we refactor QAbstractFileIconProvider::type() to put the implementation into a reusable static function QAbstractFileIconProviderPrivate::getFileType(const QFileInfo &info). This unfortunately involves constructing a QMimeDatabase on the fly, but the docs say that is fine. Drive-by change: use nullptr instead of `0` for pointers. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-99178 Change-Id: Ia32ea0a26701d593e74fbecced7be8d9e0aa0f52 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
* QFileSystemModel: respect dir filtersAhmad Samir2024-01-261-2/+7
| | | | | | | | | | | | | | | | | | | | | Given a dir A that has some files and a subdir B, when a model is set to only show files, setting the root path to A, the filters are initially respected. Setting the root path to B then back to A, the filters would be ignored and B would be visible in the model. Traversing the path elements in node() led to dir B getting added to the bypassFilters hash table, which made filtersAcceptNode() bypass the filters. I couldn't find a commit explaining the logic behind using bypassFilters (the trail goes cold at the 'Qt 4.5' mega commit). The only clue I found was the "// always accept drives" comment in the code, which hints at this being useful only on Windows(?). Fixes: QTBUG-74471 Pick-to: 6.7 6.6 6.5 Change-Id: Icb9055524a28990c591e924634a63e29a49835aa Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QFileSystem{Model,Watcher}: port to PMF signal/slot syntaxAhmad Samir2024-01-133-24/+19
| | | | | | | | | | | Also remove the `_q_` prefix from private slot names, it was needed to mark them as being used with Q_PRIVATE_SLOT, which is also gone in this commit. Drive-by change: de-duplicate some code. Change-Id: Ib41d0ac24ae584746751c0c2b5c477f600627db1 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* QFileInfoGatherer: don't create a redundant QFileInfoListAhmad Samir2024-01-101-13/+15
| | | | | | | | It's only needed for the QDir::drives() code path, for the other one create a QFileInfo and use it directly. Change-Id: I82f9f070ee64d208f2877595d9c17cabb7219e02 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QFileInfoGatherer: simplify logic; use std::exchangeAhmad Samir2024-01-091-4/+2
| | | | | Change-Id: I8e3ccc5e30dd2e08b53fd5dcab66bc921de30538 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QFileInfoGatherer: add some API docsAhmad Samir2024-01-091-0/+9
| | | | | | | Task-number: QTBUG-99750 Pick-to: 6.7 6.6 Change-Id: I908e1135b895dbf6116b1dce7416b14905b886b2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* qfilesystemmodel.cpp: Fix building with -no-feature-filesystemwatcherNodir Temirkhodjaev2023-12-191-0/+4
| | | | | | | Pick-to: 6.7 6.6 Fixes: QTBUG-120062 Change-Id: I2d4d0ff06b8088af81330ed0956b86f292c21cac Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Try harder to clean up the file info gatherer without blockingVolker Hilsheimer2023-12-164-39/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QFileSystemModel uses a QFileInfoGatherer, which is a QThread, to populate itself with the data from the file system. Some of the system calls we make for that might block, e.g. on Windows a disconnected network can easily result in 10 minutes of timeout. Destroying the QFileSystemModel destroyed the QFileInfoGatherer class member instance, and the QFileInfoGatherer destructor, being a QThread, had to wait on itself to avoid QThread asserting when being destroyed while still running. This means that shutting down a Qt application that was using a QFileSystemModel, e.g. through the non-native QFileDialog, would hang practically indefinitely instead of shutting down. To fix this, explicitly manage the life-time of the QFileInfoGatherer. Manage it in QFileSystemModel through a std::unique_ptr instead of as a direct class member so that we can control its destruction. In the QFileSystemModel destructor, signal the gather to terminate and wait one it for one second. If that fails, schedule the gatherer for later deletion through deleteLater(), and release it from the unique_ptr. The QFileInfoGatherer instance might then be alive with the QFileSystemModel destroyed. When it receives the DeferredDelete event, try again to abort the process and wait on the thread, this time for 5 seconds. If that also fails, then we have to make a choice. We cannot destroy the QThread object while it's still running, so we have to either wait indefinitely, terminate the thread, or accept a memory leak by ignoring the deferred delete event. If the QCoreApplication is shutting down, then we terminate the thread. To make this safe, explicitly control when termination is allowed in the thread - disallow it while the thread is holding a mutex, allow it while the thread is performing I/O operations. If the QCoreApplication is not shutting down, then we connect to the QThread::finished signal, and delete the object in response to that. This might or might not happen, in which case we have to accept that there's a memory leak. Pick-to: 6.7 6.6 Fixes: QTBUG-120062 Change-Id: I1e4243265879d61cf406b4eeb0b11b9d59b006ad Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFileInfoGatherer: port away from QPairAhmad Samir2023-12-065-12/+11
| | | | | | Task-number: QTBUG-115841 Change-Id: I06c39140fb9afbbe6352af1025387d1890ca2730 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QFileInfoGatherer: fix narrowing conversion warningsAhmad Samir2023-12-061-10/+11
| | | | | | | | | | | | | | | | | | | | | | Found by using -Wshorten-64-to-32 clang compiler flag, or adding that flag to the flags clangd uses. Drive-by changes: - Refactor a small while loop - Use reverse iterators - Move instead of copy while constructing a QList - Replace QPair by std::pair (see QTBUG-115841), and also for its CTAD, otherwise I'd have to spill the types out: updatedFiles.emplace_back(QPair<QString,QFileInfo>{translateDriveName(driveInfo), std::move(driveInfo)}); otherwise the clangd complains: Alias template 'QPair' requires template arguments; argument deduction only allowed for class templates Task-number: QTBUG-115841 Pick-to: 6.6 6.5 Change-Id: I942459f039f6db23f7c1928fe758c6dbf339cd2b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QStandardItem: store Qt::UserRole-1 in a static constexpr varAhmad Samir2023-11-141-4/+8
| | | | | Change-Id: I809135aed1883130891863e7c8650d0b3e7f3a35 Reviewed-by: David Faure <david.faure@kdab.com>
* QStandardItem: add note about reimplementing data/setData() wrt. flagsAhmad Samir2023-11-142-3/+16
| | | | | | | | | | | | Extend the unittests. Drive-by change: add missing include, otherwise static analyzers (clangd) complain. Fixes: QTBUG-105150 Pick-to: 6.6 6.5 5.15 Change-Id: I312133d5b35119e2e51002dfefe0e141c0708e3d Reviewed-by: David Faure <david.faure@kdab.com>
* QStandardItemModel: don't leak in mimeData()Christian Ehrlicher2023-11-121-3/+3
| | | | | | | | | | | When an invalid index is given to QStandardItemModel::mimeData() the function bails out with a warning and returns a nullptr. But the allocated data from QAIM::modelData() was not freed. Pick-to: 6.6 6.5 6.2 5.15 Task-number: QTBUG-116532 Change-Id: Ibce9d51ea09d45f1b0eb3ca980aaff141af5bf68 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QStandardItem: Fix reset parent in takeItem()Christian Ehrlicher2023-11-121-19/+21
| | | | | | | | | | | After the change for QTBUG-89145 the parent was not set to 0 when the item was not attached to a model. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-117900 Task-number: QTBUG-89145 Change-Id: I421e775130b03ce3eb2dd1dd05370e7391af087b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QFileSystemModel: remove incorrect ### Qt 7 commentMarc Mutz2023-08-161-1/+0
| | | | | | | | | | | | | QTimeZone is not trivially-copyable, so we shouldn't default arguments of that type (cf. QTBUG-98117), but continue overloading. Found in API-review. Task-number: QTBUG-98117 Pick-to: 6.6 Change-Id: I24e9d6c10512a50c172b5722c7d75bf74adf60a6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Normalize signal/slot signatures [2/2]: QPairMarc Mutz2023-08-071-2/+2
| | | | | | | | | | | | This is the result of running util/normalize. In this second patch, the tool replaces QPair with std::pair. This is a bit surprising, and suggests we should replace all QPair with std::pair in our headers soon. Pick-to: 6.6 Change-Id: Iea0a2fb460a5da66fb534b3787c97d8300a04ca9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Misc.: fix narrowing conversion warningsAhmad Samir2023-06-051-15/+10
| | | | | | | | | | | | | | | | Using: - range-for and iterator-based loops - QList constructor that takes a pair of iterators Found by using -Wshorten-64-to-32 clang compiler flag, or adding that flag to the flags clangd uses, e.g. adding this to clangd's config file (see https://clangd.llvm.org/config): CompileFlags: Add: [-Wshorten-64-to-32] Pick-to: 6.6 6.5 Change-Id: I13ae65e09ab59a59f9e5c189ea27e4e16527df2d Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Fix setting combo data with QSortFilterProxyModelFriedemann Kleint2023-04-191-2/+4
| | | | | | | | | | | | | | | | | | qtbase/c27d2a57a441f9a1ce760e71635bd4c96882249d caused the code to go through QStandardItemPrivate::setItemData() which does not handle the special treatment of Qt::EditRole completely. In the constructor of QStandardItemData; map Qt::EditRole to Qt::DisplayRole to fix this as is done in setData(). Adapt the existing tst_QStandardItemModel::getSetItemData() to check whether both roles are received in the dataChanged() signal. Pick-to: 6.5 Fixes: QTBUG-112326 Change-Id: I133d058bacc3388c612c5b4fb18b54f5ef5cb56f Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: David Faure <david.faure@kdab.com>
* QFileSystemModel: don't emit invalid indexesVolker Hilsheimer2023-04-111-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | A subclass of QFileSystemModel might override columnCount to return a value smalller than QFileSystemModelPrivate::NumColumns. In that case, constructing the bottomRight index for the dataChange signal would fail if we create it for column NumColumns - 1, and result in undefined behavior where the topLeft and bottomRight indices do not have the same parent. So ask for the columnCount of the parent index explicitly to construct the bottomRight index. The assert can be triggered via the "filesystemexplorer" example in qtdeclarative, which overrides columnCount to always return 1. As a drive-by name the variables correctly, bottom and top where mixed up. Pick-to: 6.5 Fixes: QTBUG-110632 Change-Id: I8a635ec733348d1eda2037c156ac0f7b09a2183d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Refactor QFileSystemModel: use named values for columnsVolker Hilsheimer2023-04-112-25/+35
| | | | | | | | | | | Hardcoded 0, 1, 2, 3 make it hard to follow the logic of this code. Replace those values with values in the already existing unnamed enum, and use everywhere. Pick-to: 6.5 6.2 Task-number: QTBUG-110632 Change-Id: I325ab9edb5f3f996e87c83be1ec7226d5453f2cc Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Doc: Remove duplicate wordsAndreas Eliasson2023-02-281-1/+1
| | | | | | Change-Id: Ia7a38a1035bd34d00f20351a0adc3927e473b2e7 Pick-to: 6.5 6.4 6.2 Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* QFileSystemModel: add lastModified() overload that takes a QTimeZoneAhmad Samir2023-01-064-9/+38
| | | | | | | | | | | | | | | | | | | | This is useful when sorting by time and using QTimeZone::UTC, since native filesystem API uses UTC, that means less conversions, which is potentially faster. Use UTC internally except for strings that are going to be shown in a GUI to the user, these should be in QTimeZone::LocalTime. [ChangeLog][QtGui][QFileSystemModel] Added lastModified() overload that takes a QTimeZone, this is useful when e.g. comparing file timestamps and all that's needed is time in UTC (this is faster as no time zone conversions is required). QTimeZone::UTC is used internally when sorting by time (using the sort() function), which should ideally make it faster too. Task-number: QTBUG-100349 Change-Id: I0e58f8eb7856b8da7d55db86ddd2c009ff83d970 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QFileInfoGatherer: Add missing emit keywordsLu YaNing2022-12-231-1/+1
| | | | | | | Add emit keyword to avoid misunderstanding Change-Id: Ib57edc7f195d2eaa101f03335f5cb90708fc42fd Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QStandardItemPrivate: remove const from return type in itemDataAnton Kudryavtsev2022-11-262-6/+5
| | | | | | | While touching code, port iterator-based loop to range-based for. Change-Id: I108ab4fa1e56c50f424a58984873906d37923d3d Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-033-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Gather file infos synchronously on no-thread buildsMikolaj Boc2022-10-211-0/+4
| | | | | | | | | | | | QFileInfoGatherer is implicitly dependent on threads - there are no compile guards but the file scan loop runs on a thread. Make it gather file infos sync if threads are not enabled so that signals are properly fired from it on filesystem scans. Fixes: QTBUG-85445 Backport-to: 6.4 5.15 Change-Id: I55f37497aa97bde2fc0fa2dece33c95acc870e99 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-114-7/+7
| | | | | | | | | | | | | | | | 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-34/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* qHash: Add seed argument for classes inheriting QStringMårten Nordheim2022-09-281-1/+4
| | | | | | | | | | | Pre-requisite for a fix for qHash. The classes inherits from QString and after the upcoming fix their single-arg qHash overload is no longer preferred since we want to use a seed. This has been the case since Qt 5. Pick-to: 6.2 6.4 Change-Id: I6e8601ab8d591742e2399d10521dec8cfa46f71a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Apply Q_CONSTINIT where beneficialSona Kurazyan2022-09-011-1/+1
| | | | | | | | | | Applied Q_CONSTINIT to variables with static storage duration, but skipped the POD types with core constant initializers. Task-number: QTBUG-100486 Change-Id: Iaabf824e9cb0f29a405a149912200d4e4b3573c1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFileSystemModelPrivate: de-inline ctor and dtorThiago Macieira2022-05-252-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | This class is dllexport'ed and has members that refer to classes that are only forward-declared in the header (such as QRegularExpression, used in std::vector). GCC and MSVC appear to emit the destructor at the point where it is used, which I guess is the vtable, which probably means where the constructor was inlined because I don't see any virtual overrides. Clang (at least in the form of ICX) appears to emit it at the class declaration point. C:\Qt\qt-everywhere-src-6.3.0\qtbase\src\gui\itemmodels/qfilesystemmodel_p.h(94,20): note: in instantiation of member function 'std::vector<QRegularExpression>::~vector' requested here class Q_GUI_EXPORT QFileSystemModelPrivate : public QAbstractItemModelPrivate ^ C:\Qt\qt-everywhere-src-6.3.0\qtbase\src\gui\itemmodels/qfilesystemmodel_p.h(94,20): note: in implicit destructor for 'QFileSystemModelPrivate' first required here C:\Qt\qt-everywhere-src-6.3.0\qtbase\src\gui\itemmodels/qfilesystemmodel_p.h(94,7): note: due to 'QFileSystemModelPrivate' being dllexported Fix by defining both the default ctor and the dtor out-of-line. Task-number: QTBUG-45582 Fixes: QTBUG-103605 Pick-to: 5.15 6.2 6.3 Change-Id: I77c8221eb2824c369feffffd16f08ee39004a825 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-168-304/+16
| | | | | | | | | | | | | 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>
* QtGui: replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-04-282-2/+2
| | | | | | Task-number: QTBUG-98434 Change-Id: I98c27030c783f968cbf38dc966ce486dc366b302 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtGui: use _L1 for for creating Latin-1 string literalsSona Kurazyan2022-04-282-17/+21
| | | | | | Task-number: QTBUG-98434 Change-Id: Idcb71c1d27125333a53b6bdd3e1af0d4c66617fa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtGui: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-133-26/+26
| | | | | | | | | Required for porting away from QLatin1Char/QLatin1String in scope of QTBUG-98434. Change-Id: I308d86cefcbfd126929b68f9a853d420840c965f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QStandardItemModel: use the right datatype for text alignmentGiuseppe D'Angelo2022-03-241-2/+2
| | | | | | | | Now that views can deal with Qt::Alignment returned by a model, use the right type. Change-Id: Ib6de5f7acbc76e9529451ddb494e808a41c59021 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
* Fix deprecated uses of QScopedPointerMårten Nordheim2022-03-081-2/+2
| | | | | | | | | By changing it to unique_ptr. Pick-to: 6.2 6.3 Change-Id: I91abb69445b537d4c95983ae735341882352b29d Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Miscellanea fixes for QT_TYPESAFE_FLAGS in our headersGiuseppe D'Angelo2022-03-071-9/+9
| | | | | | | | | | | | | | | | | | | | | In preparation for adding it to headersclean. Some remarks: * QStandardItemModel builds just fine (QFlags has comparison operators against literal zero); the warning we however get is about 0 converted to a null pointer constant. There's nothing we can do about that one (even <compare> gives such a warning). * Several code was depending on flags->int conversions. Add toInt(), but also cast again to the expected type to avoid warnings in case toInt() returns unsigned int. * Ported to explicit casts to bool rather than test(Any)Flag to minimize confusion for people unfamiliar with the test*Flag methods. Change-Id: I5be280ac33a0b38e2680096f0e79129fd55ba241 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Fix flags in QFileSystemModelAndreas Buhr2022-02-021-2/+3
| | | | | | | | | | | | | | | | In 63eea5e5c69434871eaef9d9dc7184d7e54d7276, the Qt::ItemNeverHasChildren flag was introduced. QFileSystemModel was modified to use this flag for items which are not directories, but only if the QFileSystemModel is not read-only and the directory is writable. This patch modifies QFileSystemModel to use the ItemNeverHasChildren flags also if the model is read-only and if the item is read-only. Amends 63eea5e5c69434871eaef9d9dc7184d7e54d7276 Change-Id: Ie7f7d58ecf7baade93f9f03d120da84d3c005d42 Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
* Eradicate Q_FOREVER from header filesMarc Mutz2021-12-281-1/+1
| | | | | | | | | The qgenericatomic.h occurrences are getting in the way of splitting up qglobal.h, so inline the define. Task-number: QTBUG-99313 Change-Id: I0d6e3553c5ed4ac9e426bef2fe07d2672d73c671 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix return type documentation of QFileSystemModel::fileName()hjk2021-11-151-1/+1
| | | | | | | Pick-to: 6.2 Pick-to: 5.15 Change-Id: I5de4214766eccd5b0086d1230b4267fb49e1b58f Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* gui: Fix typos in source code commentsJonas Kvinge2021-10-122-2/+2
| | | | | | Pick-to: 5.15 6.2 Change-Id: Ie53e5542a8f93856470982939ecd8ec90b323d69 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* QFileSystemModel: cache the name filters regexpsGiuseppe D'Angelo2021-08-042-12/+33
| | | | | | | | | | | | | | | | | | | | | In order to filter out file names based on the user's settings, QFileSystemModel used to have a loop that tested if a given file name matched one of the filters. The problem is that each filter (a wildcard) was converted to a QRegularExpression _inside_ the loop. This causes a quadratic behavior (number of files * number of filters). Instead, build the regexps once when the filters are set (or the case sensitivity is changed, as that affects the filtering), and simply _use_ them in the loop. Simplify and correct some related code as a drive by. Done-with: Jean-Michaël Celerier Fixes: QTBUG-95383 Pick-to: 6.2 6.1 5.15 Change-Id: I6bc336364c145bb05793a8f867545d7715d35832 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QDirIterator: add nextFileInfo()Marc Mutz2021-07-281-2/+1
| | | | | | | | | | | | | | | | | | | | | | | Before this change, next() was the only way to advance the iterator, whether the caller was ultimately interested in just the filePath() (good) or not (bad luck, had to call .fileInfo()). Add a new function, nextFileInfo(), with returns fileInfo() instead. Incidentally, the returned object has already been constructed as part of advance()ing the iterator, so the new function is faster than next() even if the result is ignored, because we're not calculating a QString result the caller may not be interested in. Use the new function around the code. Fix a couple of cases of next(); fileInfo().filePath() (just use next()'s return value) as a drive-by. [ChangeLog][QtCore][QDirIterator] Added nextFileInfo(), which is like next(), but returns fileInfo() instead of filePath(). Change-Id: I601220575961169b44139fc55b9eae6c3197afb4 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix auto completion in QFileDialog on WindowsVolker Hilsheimer2021-07-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amends c0b3c06a7d4f6a2f90742e8dc81c898082a70416. The QCompleter used by QFileDialog uses starts-with matching of the path parts, for all parts of the path. It uses the EditRole of the underlying model for the data to match. The path parts used for a path on Windows are "C:", "Users", "etc...", and then finally whatever input has been typed so far. If we try to match that against a starts-with rule against "Local Disk (C:)", then it will fail and the completer will never have anything to show. So, for the EditRole, return just the volume drive letter as we did before c0b3c06a7d4f6a2f90742e8dc81c898082a70416, not the volume name. Neither can be edited anyway. This happens to then match the native file dialog behavior, which doesn't complete "L" to "Local Disk (C:)" if the Computer contents (ie. volumes) are shown. Augment the QCompleter test case to cover that scenario (it already has everything set up for this particular combination, even though we are actually testing QFileSystemModel returning the correct data). Fixes: QTBUG-94799 Task-number: QTBUG-78043 Pick-to: 5.15 6.2 6.1 Change-Id: I14844d91601e9b16dc07cff2ca48713acb7cdd09 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* QFileSystemModel fails to locate a host from root's visible childrenDongmei Wang2021-05-201-2/+5
| | | | | | | | | | | | | | | | | | In QFileSystemModel, in some cases the hostname in a UNC path is converted to lower case and stored in the root node's visibleChildren. When QFileSystemModel sets the UNC path as the root path, it tries to get the row number for the host, but it didn't convert the hostname to lower case before getting the row number, which resulted in the host not found in the root node's visible children. As a result, it returns -1, an invalid row number. Change the behavior to find the node for the host using the host name case-insensitive and then get the row number. Fixes: QTBUG-71701 Pick-to: 5.15 6.0 6.1 Change-Id: Ib95c7b6d2bc22fd82f2789b7004b6fc82dfcb13b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Fix QStandardItemModel signals on takeChildLuca Beldi2021-05-111-2/+27
| | | | | | | | | | takeItem and takeChild do not signal the change correctly to the external world, this change fixes the problem Fixes: QTBUG-89145 Pick-to: 6.1 5.15 Change-Id: Ib4844ace53007068a2cd62eba64df99e6e45fdc0 Reviewed-by: David Faure <david.faure@kdab.com>