summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels/qfilesystemmodel_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QFileSystemModel: don't crash with setIconProvider(nullptr)Ahmad Samir2024-02-011-0/+7
| | | | | | | | | | | | | | | | | | | | 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>
* QFileSystem{Model,Watcher}: port to PMF signal/slot syntaxAhmad Samir2024-01-131-4/+4
| | | | | | | | | | | 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>
* Try harder to clean up the file info gatherer without blockingVolker Hilsheimer2023-12-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-061-1/+1
| | | | | | Task-number: QTBUG-115841 Change-Id: I06c39140fb9afbbe6352af1025387d1890ca2730 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Refactor QFileSystemModel: use named values for columnsVolker Hilsheimer2023-04-111-1/+7
| | | | | | | | | | | 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>
* QFileSystemModel: add lastModified() overload that takes a QTimeZoneAhmad Samir2023-01-061-1/+1
| | | | | | | | | | | | | | | | | | | | 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>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-2/+2
| | | | | | | | | | | | | | | | 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-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* QFileSystemModelPrivate: de-inline ctor and dtorThiago Macieira2022-05-251-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QtGui: replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-04-281-1/+1
| | | | | | Task-number: QTBUG-98434 Change-Id: I98c27030c783f968cbf38dc966ce486dc366b302 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QtGui: stop using QLatin1Char constructor for creating char literalsSona Kurazyan2022-04-131-4/+4
| | | | | | | | | 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>
* QFileSystemModel: cache the name filters regexpsGiuseppe D'Angelo2021-08-041-0/+4
| | | | | | | | | | | | | | | | | | | | | 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>
* Replace discouraged Q_MOVABLE_TYPE by Q_RELOCATABLE_TYPEAndreas Buhr2020-11-301-2/+2
| | | | | | | | | | | | | | 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>
* Move QFileSystemModel into QtGuiVolker Hilsheimer2020-08-251-0/+323
This requires a QAbstractFileIconProvider in QtGui, as the standard QFileIconProvider depends on QStyle, and cannot be moved out of QtWidgets. QAbstractFileIconProvider returns strings for file types, but returns no icons yet. Support for a default icon set might be added in a follow-up commit. Change-Id: Ib9d095cd612fdcf04db62f2e40709fcffe3dc2b7 Fixes: QTBUG-66177 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>