summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qdir.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QDir: deprecate QDir::Filter::Modified flagAhmad Samir2025-08-101-3/+1
| | | | | | | | | I didn't find any usage of it in Qt code. [ChangeLog][QtCore][QDir] Deprecated QDir::Filter::Modified flag. Change-Id: I800fa6b177c2697c9621307d04090b566290012b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: add some API docs to checkNonDirListingFlags()Ahmad Samir2025-08-101-0/+6
| | | | | Change-Id: I6825fd32dd177d034d4f20a10674ffde96835c34 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDirListing: port away from private QDirListing ctor, [1]: QDirAhmad Samir2025-08-091-10/+110
| | | | | | | | | Convert the values of a QDir::Filters that can be represented by QDirListing::IteratorFlags, and check the rest of the filters separately in QDir. Change-Id: Ib3cc8b04a2903111cf863b07d239d5a02f8397ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Mark qdir.cpp as security-criticalMatthias Rauter2025-06-181-0/+1
| | | | | | | | | | | | | QDir parses strings representing file paths. These strings may come from untrusted sources, and even existing paths could be crafted to trigger potential bugs in QDir. Therefore, this file is marked as security-critical. QUIP: 23 Pick-to: 6.10 6.9 6.8 Task-number: QTBUG-135187 Change-Id: I817ad336ddc978c4cba1f385d60017f3a8f8e4fd Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QDir: add mkpath/mkdir overloads taking std::optional<Permissions>Ahmad Samir2025-02-271-42/+31
| | | | | | | | | | | | | | | | | | | | | | | | | std::optional: - it's already used in private API in QFileSystemEngine and QAbstractFileEngine and its subclasses, so there is no extra overhead - less code duplication as it lets the existing overloads call the new ones with std::nullopt to make it use the platform default permissions - adding a new enumerator, e.g. "PlatormDefault", wouldn't work: - 0x0 is ambiguous with setting the permissions to nothing - the new enumerator mustn't set any other permission bits, so it'll have to be > std::numeric_limits<short>::max(), which is potentially BiC as the underlying type of the enum will become int [ChangeLog][QtCore][QDir] Added mkdir() method that takes a std::optional<QFile::Permissions>; the new method transparently replaces the older mkdir() overloads. [ChangeLog][QtCore][QDir] Added mkpath() method that takes a std::optional<QFile::Permissions>; this new method transparently replaces the older mkpath() overload. Task-number: QTBUG-132633 Change-Id: Ic2cd1e01e6ad1a2b6d3a6180c41b6a0b260a4e55 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: improve mkdir/mkpath API docsAhmad Samir2025-02-271-21/+38
| | | | | | | Pick-to: 6.9 6.8 6.5 Task-number: QTBUG-132633 Change-Id: Iafe4a20bacbbf55d19377e8cd04f940d4f2a66f6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QUrl: avoid going up from the drive path on Windows file URLsThiago Macieira2025-02-041-12/+29
| | | | | | | | | | | | | | | On Windows, using a URL of "file:///c:/" as a base to be resolved with "../" should not result in the Windows drive being removed. [ChangeLog][QtCore][QUrl] Fixed a bug (regression from 6.7) where resolving a base URL of an absolute file path containing a Windows drive could result in said drive being removed (e.g., resolving "file:///c:/" with "../" would result in "file:///"). Fixes: QTBUG-133402 Pick-to: 6.9 6.8 Change-Id: I58286b9c5e5d02363f0efffdb06f983b560340df Reviewed-by: David Faure <david.faure@kdab.com>
* Create qdoc macros for C++ class docs 1.2: member-swap(), simplified phrasingMarc Mutz2024-11-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have some patterns for how to document certain functions, but we also vary the sentences a lot, and you have to look up one documentation piece and copy it, essentially. If we ever want to change them, we end up with shotgun surgery. So apply DRY to the documentation and start a collection of macros to help with repetitive C++ class documentation tasks. The first macro is for member-swap(), and this second patch is for documentation that used the simplified phrasing ("Swaps this X with \a other."), which this patch adopts as the text for \memberswap, too, because it doesn't repeat the macro argument, making it easier to find a grammatically-fitting argument than in the traditional phrasing. This doesn't change the documentation, except as follows: * standardizes on simpified instead of traditional phrasing for docs that already use the \memberswap macro * adds the "very fast and never fails" blurb, if it was missing * changes the function's argument name to `other`, as required by the macro. Task-number: QTBUG-129573 Pick-to: 6.8 6.7 6.5 6.2 Change-Id: I1123e783ce0da76c5997ff74007d77504ac5b334 Reviewed-by: Topi Reiniö <topi.reinio@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QFileSystemEngine: split dir creation into mkdir/mkpathAhmad Samir2024-10-251-3/+3
| | | | | | | | | | | | | Split the logic of createDirectory() into mkdir and mkpath. This matches QDir::mkdir()/mkpath(). "mkdir()" won't confuse the compiler about which method to call, because libc's mkdir() is either used via QT_MKDIR which expands to "::mkdir" or directly as ::mdkir(), whereas the static QFileSystemEngine::mkdir() is always called with full scope. Change-Id: I31b67727cce23f1bc560432d40231a24dc560d5b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFileSystemEngine: add rmpath()Ahmad Samir2024-10-101-2/+2
| | | | | | | | | | | | | | | | | removeDirectory() acts in two mode, rmdir (one entry) and rmpath (the entry and all empty parent directories). This is irregular behavior, and API with a very specific use-case (in unittests, where you create a dir tree and want to cleanup after the test finishes). So, split the code into rmdir() and rmpath(), which matches QDir::rmdir() and QDir::rmpath(). On Unix, a further optimization pointed out by Thiago in review, remove the stat() call, ::rmdir() will fail with ENOTDIR if we try to remove anything that isn't a dir. Change-Id: I1bbb6e6c1ce49ba6d73d3c510b449223498612fb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: refactor PathNormalization enumAhmad Samir2024-10-041-19/+8
| | | | | | | | | | | | | | | | | | AllowUncPaths (and the whole enum) is private API that is always enabled only on Windows (build-time decision). So, remove it and change the unittests to match reality. Now DefaultNormalization on Windows implies handling UNC paths. This was suggested in code review by Thiago; since this is a hot code path, the goal is letting the compiler keep the flags parameter to qt_normalizePathSegments() in a register, by keeping the PathNormalization enum as small as possible. Drive-by change: since those lines in the unittest are changed anyway, take the chance and use u""_s syntax. Change-Id: I3dcf30d888a0ea9f8898e260e65c5f85655296d5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: change qt_normalizePathSegments to preserve trailing '/'sAhmad Samir2024-10-041-26/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ... for local URLs too. For example normalizing "/Users/sam/troll/qt4.0/.." by following the alogrithm at https://www.ietf.org/rfc/rfc3986.html#section-5.2.4: - replace "/.." with a "/" in the input buffer, then remove the previous path segment from the output buffer up to, and including, the previous "/" - next iteration will find the input buffer starting with a "/" which is moved to the output buffer; the final result would be: "/Users/sam/troll/" Remove the KeepLocalTrailingSlash enumerator, it's become redundant with this change. De-duplicate a row in tst_QDir. [ChangeLog][Important Behavior Change] Aligned how QDir and QUrl normalize paths with respect to preserving a trailing slash. That is, QDir::cleanPath("/b/.") and QUrl("file:///b/.).toString(QUrl::NormalizePathSegments) will return "/b/" and "file:///b/" respectively. For more details see: https://www.ietf.org/rfc/rfc3986.html#section-5.2.4 Task-number: QTBUG-128940 Change-Id: Id5a4bdab14e7312a60b1b54de07e5d9f3e8aa40a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Darwin: Teach QFileSystemEngine how to resolve case-sensitivityTor Arne Vestbø2024-10-021-1/+8
| | | | | | | | | | | | | Both APFS and HFS+ can be both case-sensitive and case-insensitive (the default), and the mounted file system may be any other file system than these two as well, so hard-coding to case-sensitive is not sufficient. Pick-to: 6.8 Task-number: QTBUG-28246 Task-number: QTBUG-31103 Change-Id: Ibdb902df3f169b016a519f67ad5a79e6afb6aae3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: qt_normalizePathSegments: replace a while loop with an ifAhmad Samir2024-09-201-2/+4
| | | | | | | | 'out' is at the first dot, so we only need to backtrack to the first preceding slash, before removing the previous path segment. Change-Id: I2e0be0583d4e9e984305a52f50a51801461077ba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: qt_normalizePathSegments: remove a redundant while loopAhmad Samir2024-09-201-3/+1
| | | | | | | | | | | | | | | | | This loop backtracked multiple '/'s for local URLs, but for such URLs, only the first slash is copied to the output stream; from the first if-block in the do-while loop: if (in[0] == u'/') { *out++ = *in++; while (in < end && in[0] == u'/') { if (isRemote) *out++ = *in++; else ++in; Change-Id: I09b79e3b859ecc7f8c20b2cf9c3ce3c2035668a7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: use .html link to an RFCAhmad Samir2024-09-201-3/+3
| | | | | Change-Id: I7a8ccd149b706e7822011cb40d86bd977bddabbe Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QUrl: Keep one trailing slash when normalizing "file:///b/."Ulf Hermann2024-09-191-3/+23
| | | | | | | | | | | | | Removing the slash would be a drastic change in behavior. We can expect many people to rely on the trailing slash to string-append further path segments without inserting an extra slash. Amends commit e7bcf41c0b23d83cfb31f966454945c705589a99. Pick-to: 6.8 6.7 6.5 Fixes: QTBUG-128940 Change-Id: I71dfc957f383e4648b3b47a40aeb796d7237fb00 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QUrl::resolved: switch to using qt_normalizePathSegmentsThiago Macieira2024-09-131-1/+1
| | | | | | | | | | | | | | | | Commit 4b1547adc9b195e6acc90471fc48dec7ee0c429d rewrote mergePathSegments() but got one thing wrong: that ".." on a "//" should only remove one slash, not all of them. That behavior was introduced by commit eaf4438b3511c8380b9b691b656a87a60e342e2 to match what browsers do. QUrl will use the local file behavior if the URL scheme is "file", unlike the browsers. Task-number: QTBUG-120396 Pick-to: 6.5 6.7 6.8 6.8.0 Change-Id: I8a96935cf6c742259c9dfffd17e8fd3cfde46e25 Reviewed-by: David Faure <david.faure@kdab.com>
* QDir: change qt_{cleanPath,normalizePathSegments} to returning boolThiago Macieira2024-09-131-24/+15
| | | | | | | | | | | Since qt_normalizePathSegments very often modifies the path, pass that as pointer, and return a boolean with whether the path is attempting to go up above the root. Pick-to: 6.8 Change-Id: I851fcb94db4606a6bd97fffd81910930dea8222a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* Replace qt_normalizePathSegments algorithm with QUrl's removeDotsFromPathThiago Macieira2024-09-131-137/+142
| | | | | | | | | | | | | | Commit 4b1547adc9b195e6acc90471fc48dec7ee0c429d rewrote the latter for simplicity and performance, so copy it over with intent to merging the two together. In this copy, however, we keep the behavior introduced by commit eaf4438b3511c8380b9b691b656a87a60e342e2, which made the normalization match the behavior found in browsers, but didn't apply to QUrl::resolved (that's the next commit) Task-number: QTBUG-120396 Pick-to: 6.5 6.7 6.8 6.8.0 Change-Id: I2670423f6c6a5339771ffffdf15ebad46fd25cb4 Reviewed-by: David Faure <david.faure@kdab.com>
* QDirListing: add flags to handle entries filteringAhmad Samir2024-06-271-6/+7
| | | | | | | | | | | | | | | | | | By extending IteratorFlag so that it replaces both QDir::Filter and QDirIterator::IteratorFlag enums, but with better defaults (based on how QDir/Iterator is used in 15-20 years worth of code in Qt and KDE). Make the QDirListing(QDir ~~) ctor private, also change it to use QDirIterator::IteratatorFlags; it will be used to port existing code. If QDir is ported to use QDirListing::IteratorFlags, instead of QDir::Filters, a public QDirListing(QDir) constructor can then be added. Pick-to: 6.8 Fixes: QTBUG-125504 Task-number: QTBUG-125859 Change-Id: Ide4ff8279f554029ac30d0579b0e8373ed4337f7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: replace a QScopedArrayPointer with a QVLAMarc Mutz2024-05-151-2/+3
| | | | | | | | | | | | | | | | | | | | | QDirSortItem contains three implicitly-shared members (two QStrings and one QFileInfo), so the mere default-initialization of the QDirSortItem[n] array with which we initialize the QScopedArrayPointer will take quite some time. Using QVarLengthArray, OTOH, delays construction until we have the data to initialize the sort items, saving n default constructor and n move assignment operator calls, plus the memory allocation for the case where we have less than 65 elements to sort. This code precedes the start of the public history, but the emplacement won't work before 905bc6293354a0d3ee832b6dd3f632a647f809f3 introduced the QDirSortItem ctor, so not picking back further than that. Pick-to: 6.7 Change-Id: I262217eabaded2a6aef08b87fc6369812bc8958a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFileSystemEngine: make factory functions return unique_ptr<QABFE>Ahmad Samir2024-03-211-2/+1
| | | | | | | | | | | | | | | | This makes the ownership of the returned pointer clearer. It also matches reality, some call sites were already storing the pointer in a unique_ptr. Also shorten the function name to "createLegacyEngine", you have to read its docs anyway to figure out what it does. Drive-by changes: less magic numbers; use sliced(); return nullptr instead of `0`. Change-Id: I637759b4160b28b15adf5f6548de336887338dab Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Bootstrap: remove QDirListing/QDirIteratorThiago Macieira2024-03-131-0/+6
| | | | | | | | | | Bootstrapped tools don't usually need to list directories; they should operate on file lists passed to it by the build system instead. This may deserve a QT_FEATURE. Change-Id: I01ec3c774d9943adb903fffd17b7ecfba2702fc5 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Replace some QString::fromUtf16() with QStringView::toString()Thiago Macieira2024-03-041-1/+1
| | | | | | | | | | | | | | The QStringView counterpart is somewhat faster because it doesn't go through the UTF-16 codec in QUtf16::convertToUnicode(), which tries to detect the BOM. I've included QString::fromWCharArray in this because: a) it's used extensively in Windows code b) wide chars in memory probably don't have BOMs anyway Change-Id: I01ec3c774d9943adb903fffd17b815be4d2ab8ba Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Port to QDirListingAhmad Samir2024-03-031-21/+16
| | | | | | | | | | | 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>
* QFileInfo and QDir: use new \compares commandRym Bouabid2024-02-211-0/+1
| | | | | | | | ... to describe the comparison operators provided by these classes. Task-number: QTBUG-120303 Change-Id: I611a1801eb038586bfe57be9b502b6f17f3d5742 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QDir: Use new comparison helper macrosRym Bouabid2024-02-131-12/+13
| | | | | | | | | | | | QDir had operator==() and operator!=() defined as public member functions, so use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of these methods and replace them with a hidden friend. Use QTestPrivate::testEqualityOperators() helper function in unit-tests. Task-number: QTBUG-120303 Change-Id: I86c2ba18b8b114efd9f62fc2fd628bc9065b04b2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Replace ushort*/uint* with char16_t*/char32_t* in private API [1]Ahmad Samir2023-03-151-4/+4
| | | | | | | Task-number: QTBUG-110403 Pick-to: 6.5 Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: point at fetchmore example for QDir usageVolker Hilsheimer2023-03-011-1/+2
| | | | | | | | The Find Files example is gone. Pick-to: 6.5 Change-Id: I63bc33c3b9db7c8bfcf07fbcee0182a492c01dbd Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
* QDir: when sorting use the cached filename if it was assigned toAhmad Samir2023-02-171-3/+7
| | | | | | | | | After commit b5a54d488cfc94a3, we now use QCollator and so no toLower() when caching the filename, we can re-use it from the cache after sorting. Change-Id: I8602a11c6f68cfe61db3ec6330596066cd257dab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix few QFileInfo and QDir callsAssam Boudjelthia2023-02-141-1/+4
| | | | | | | | | | | | | | Return the file engine impl of QFileInfo::completeBaseName() and QDir::absolutePath() and QFileInfo::fileName() (based on QAbstractFileEngine::BaseName) if the file engine impl is valid. Amends f77668ffec48d8aaad7c74069c6f3e770a305ae1. Pick-to: 6.5 6.4 6.2 5.15 Task-number: QTBUG-98974 Change-Id: I28a8c75a6f25e30012b0791c12dbde51bfe8f62c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: use QCollator when doing locale-aware sortingAhmad Samir2023-02-101-19/+49
| | | | | | | | And don't use toLower() as QString::compare() and QCollator::compare() can compare case-insensitively. Change-Id: I999d787cb77e10a101da75d1bf0a5baf096a5c9b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir::entryList: don't fill a QFileInfo cache if we just want namesDavid Faure2023-02-071-7/+19
| | | | | | | | | | This improves the performance of tst_QDir_10000::iDontWantAnyStat (QDir::entryList Unsorted) from 9.7ms to 7.2ms, i.e. the same as iDontWantAnyStatIterator (QDirIterator). Change-Id: I3faf8af1a55575df97912b1ce720492c8fd903c9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Docs:Android: Add docs notes about support for content UrisNicholas Bennett2023-01-241-0/+7
| | | | | | | | | | | Add some details about the support of Qt apis (QFile, QDir, QFileInfo) for Android content uris. Fixes: QTBUG-99664 Task-number: QTBUG-98974 Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I4b884623702ccad116d47049e34ccddfe21f83ca Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* Make const functions in QDir re-entrant by protecting mutable variablesØystein Heskestad2023-01-161-53/+71
| | | | | | | | | | | | | | | | | | QDir caches data in mutable variables. Because of no protection, two threads calling for instance QDir::count on two independent but shared copies of a QDir object caused a data race. Running the tst_QDir_tree and tst_QDir_10000 three times with and without this change show no change beyond the difference between each result. For instance tst_QDir_tree::thousandFiles:"src" took 36/35/37 ms before the change and 35/35/35 ms after. This makes sense because the time to handle mutexes is very little compared the time to make file operations. Fixes: QTBUG-105753 Change-Id: I6886f84521410f88cce2b25f0cce8cfc3fea1a0b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: Refactor separate cache clearing functions into a single functionØystein Heskestad2023-01-161-23/+11
| | | | | | Task-number: QTBUG-105753 Change-Id: I7f3473ce21e71ccd04ff9f2575244167b5c3e3a4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: when sorting by Type, cache the suffix in QDirSortItem's ctorAhmad Samir2023-01-061-35/+42
| | | | | | | | | | | | | | The predicate passed to e.g. a std::sort shouldn't modify the objects it's called on, so move filling the cache to the QDirSortItem constructor where possible. While that can't be done in all cases, e.g. filename_cache is used as the tie-breaker when two items have the same time or type ...etc, so it's only assigned to _if_ needed, we can at least move some stuff out of the predicate to the QDirSortItem c'tor. Drive-by change: replace comment with asserts Change-Id: I0199797ab8e261fe3c0fcb791cfc69b23b6fdc48 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: when sorting by time, get last modification times as UTC directlyAhmad Samir2022-12-231-10/+2
| | | | | | | | | | | | | PASS : tst_QDir_10000::sorted_byTime() RESULT : tst_QDir_10000::sorted_byTime(): 345 msecs per iteration (total: 345, iterations: 1) PASS : tst_QDir_10000::sorted_byTime() RESULT : tst_QDir_10000::sorted_byTime(): 0.000015 msecs per iteration (total: 54, iterations: 262144) Change-Id: I7976c8668aa821d2b7ed3f774f29bdf1ba4a99d1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Return the QFileInfo::baseName/QDir::dirName() from fileEngine implAssam Boudjelthia2022-12-191-1/+3
| | | | | | | | | | Get those values from the file engine instead, this is relevant especially on Android for content uris. Pick-to: 6.5 6.4 6.2 Task-number: QTBUG-98974 Change-Id: I65fe4c59e5f1feed0dcf14cc8988b4a40d9d979e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Adapt corelib to use QTimeZone in place of Qt::TimeSpecEdward Welbourne2022-12-091-2/+2
| | | | | | | | | This saves (mostly in corelib/time/) some complications that used to arise from needing different code-paths for different time-specs. Task-number: QTBUG-108199 Change-Id: I5dbd09859fce7599f1ba761f8a0bfc4633d0bef9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 QDir's implementation to use Q_D() and d_func()Edward Welbourne2022-11-011-28/+28
| | | | | | | | | | | It had the d_func()s it needed, but wasn't using them. This prepares the way for QEDSP-ification. Pick-to: 6.4 Task-number: QTBUG-105753 Change-Id: I8b7ba79818f27ae6a2281b276b95b94673f05648 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Mention limitation of QDir::drives() on WindowsTimothée Keller2022-10-201-1/+2
| | | | | | | | | Added comment to clarify returned drives from QDir::drives() Task-number: QTBUG-106896 Pick-to: 5.15 6.2 6.4 Change-Id: I7cf9642b11f9000a5e6382a2b29070ab2cd6442e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDir: use QFileInfo::exists() directlyAhmad Samir2022-10-141-3/+3
| | | | | | | | | static QFile::exists() calls static QFileInfo::exists(). Mention QFileInfo::exists in the QDir docs details. Change-Id: I35ba9b00f33376a4ceb2f27ab587d368a95e4fe5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Port QDir to qsizetype [3/3]: APIMarc Mutz2022-09-071-2/+7
| | | | | | | | | | | | | | | | [ChangeLog][QtCore][QDir] The count() function now returns, and the indexing operator now takes, qsizetype (was: uint and int, respectively). [ChangeLog][Potentially Source-Incompatible Changes][QDir] The count() function now returns qsizetype (was: uint). Task-number: QTBUG-103525 Change-Id: Ib84af36f6a95d9a0d1090a2d6fb973a4e363550c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port QDir to qsizetype [2/3]: implementationMarc Mutz2022-08-261-23/+23
| | | | | | | | | | | | | | | | Port ints that should be qsizetype. None of these are likely to cause bugs, because both path lengths and number of directory entries are usually limited by the OS, not by INT_MAX. As a drive-by, replace length() with size() and port some functions from QString to QStringView. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: I79eb6d580631346a1e77eb1c7a73a3880943794e Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Extract header qtresource.h from qglobal.hSona Kurazyan2022-08-251-53/+0
| | | | | | Task-number: QTBUG-99313 Change-Id: I4dd219dcb9181bf23feb6639821764cd5dc19a24 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port QDir to qsizetype [1/3]: indexed to ranged loopsMarc Mutz2022-08-211-4/+4
| | | | | | | | | | | Indexed for loops are prone to int/qsizetype mismatches, so use ranged for loops where possible. Pick-to: 6.4 6.3 6.2 Task-number: QTBUG-103525 Change-Id: Ia3e97a6b2924f92d3f7fb1a7ae075b59188006e9 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>