Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdirlisting.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2024 Ahmad Samir <a.samirh78@gmail.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QDIRLISTING_H
7#define QDIRLISTING_H
8
9#include <QtCore/qtdeprecationmarkers.h>
10#include <QtCore/qfiledevice.h>
11#include <QtCore/qflags.h>
12#include <QtCore/qtmetamacros.h>
13#include <QtCore/qtclasshelpermacros.h>
14#include <QtCore/qtcoreexports.h>
15#include <QtCore/qdatetime.h>
16
17#include <iterator>
18#include <utility>
19
20QT_BEGIN_NAMESPACE
21
22class QDirListingPrivate;
23class QFileInfo;
24class QDebug;
25class QDir;
26class QTimeZone;
27
29{
30 Q_GADGET_EXPORT(Q_CORE_EXPORT)
31public:
32 enum class IteratorFlag {
33 Default = 0x000000,
34 ExcludeFiles = 0x000004,
35 ExcludeDirs = 0x000008,
36#if QT_DEPRECATED_SINCE(6, 14)
37 ExcludeSpecial QT_DEPRECATED_VERSION_X_6_14("Use ExcludeOther instead.") = 0x000010,
38#endif
39 ExcludeOther = 0x000010,
40 ResolveSymlinks = 0x000020,
43 IncludeHidden = 0x000040,
45 CaseSensitive = 0x000100,
46 Recursive = 0x000400,
49 NoNameFiltersForDirs = 0x040000, // used internally
50 };
51 Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)
53
54 Q_CORE_EXPORT explicit QDirListing(const QString &path,
58
59 QDirListing(QDirListing &&other) noexcept
60 : d{std::exchange(other.d, nullptr)} {}
62
63 void swap(QDirListing &other) noexcept { qt_ptr_swap(d, other.d); }
64
66
67 Q_CORE_EXPORT QString iteratorPath() const;
68 Q_CORE_EXPORT IteratorFlags iteratorFlags() const;
69 Q_CORE_EXPORT QStringList nameFilters() const;
70
72 {
73 friend class QDirListing;
74 QDirListingPrivate *dirListPtr = nullptr;
75 public:
76 Q_CORE_EXPORT QString fileName() const;
83 Q_CORE_EXPORT bool isDir() const;
84 Q_CORE_EXPORT bool isFile() const;
85 Q_CORE_EXPORT bool isSymLink() const;
86 Q_CORE_EXPORT bool exists() const;
87 Q_CORE_EXPORT bool isHidden() const;
88 Q_CORE_EXPORT bool isReadable() const;
89 Q_CORE_EXPORT bool isWritable() const;
90 Q_CORE_EXPORT bool isExecutable() const;
91 Q_CORE_EXPORT QFileInfo fileInfo() const;
95 Q_CORE_EXPORT qint64 size() const;
96
97 QDateTime birthTime(const QTimeZone &tz) const
98 { return fileTime(QFileDevice::FileBirthTime, tz); }
99 QDateTime metadataChangeTime(const QTimeZone &tz) const
100 { return fileTime(QFileDevice::FileMetadataChangeTime, tz); }
101 QDateTime lastModified(const QTimeZone &tz) const
102 { return fileTime(QFileDevice::FileModificationTime, tz); }
103 QDateTime lastRead(const QTimeZone &tz) const
104 { return fileTime(QFileDevice::FileAccessTime, tz); }
105 Q_CORE_EXPORT QDateTime fileTime(QFileDevice::FileTime type, const QTimeZone &tz) const;
106 };
107
109 {
110 friend constexpr bool operator==(sentinel, sentinel) noexcept { return true; }
111 friend constexpr bool operator!=(sentinel, sentinel) noexcept { return false; }
112 };
113
115 {
117 friend class QDirListing;
118 explicit const_iterator(QDirListingPrivate *dp) { dirEntry.dirListPtr = dp; }
119 DirEntry dirEntry;
120 public:
121 using iterator_category = std::input_iterator_tag;
124 using pointer = const value_type *;
125 using reference = const value_type &;
126
127 const_iterator() = default;
128 const_iterator(const_iterator &&) noexcept = default;
129 const_iterator &operator=(const_iterator &&) noexcept = default;
130
131 reference operator*() const { return dirEntry; }
132 pointer operator->() const { return &dirEntry; }
133 const_iterator &operator++() { dirEntry = next(dirEntry); return *this; }
134 void operator++(int) { ++*this; } // [iterator.concept.winc]/14 not required to return sth
135 private:
136 bool atEnd() const noexcept { return dirEntry.dirListPtr == nullptr; }
137 friend bool operator==(const const_iterator &lhs, sentinel) noexcept { return lhs.atEnd(); }
138#ifndef __cpp_impl_three_way_comparison
139 friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
140 { return !operator==(lhs, sentinel{}); }
141 friend bool operator==(sentinel, const const_iterator &rhs) noexcept
142 { return operator==(rhs, sentinel{}); }
143 friend bool operator!=(sentinel, const const_iterator &rhs) noexcept
144 { return !operator==(sentinel{}, rhs); }
145#endif // __cpp_impl_three_way_comparison
146 };
147
149 const_iterator cbegin() const { return begin(); }
150 sentinel end() const { return {}; }
151 sentinel cend() const { return end(); }
152
153 // Qt compatibility
154 const_iterator constBegin() const { return begin(); }
155 sentinel constEnd() const { return end(); }
156
157private:
159
161
163};
164
165Q_DECLARE_OPERATORS_FOR_FLAGS(QDirListing::IteratorFlags)
166
167QT_END_NAMESPACE
168
169#endif // QDIRLISTING_H
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtCore
Definition qdirlisting.h:72
QDateTime birthTime(const QTimeZone &tz) const
Definition qdirlisting.h:97
QDateTime metadataChangeTime(const QTimeZone &tz) const
Definition qdirlisting.h:99
Q_CORE_EXPORT bool isReadable() const
Q_CORE_EXPORT bool isHidden() const
Q_CORE_EXPORT bool isWritable() const
Q_CORE_EXPORT bool isExecutable() const
Q_CORE_EXPORT bool isFile() const
Q_CORE_EXPORT bool exists() const
Q_CORE_EXPORT bool isSymLink() const
Q_CORE_EXPORT bool isDir() const
QDateTime lastRead(const QTimeZone &tz) const
See the QFileInfo methods with the same names.
QDateTime lastModified(const QTimeZone &tz) const
const_iterator(const_iterator &&) noexcept=default
reference operator*() const
Returns a {const QDirListing::DirEntry &} of the directory entry this iterator points to.
const value_type * pointer
std::input_iterator_tag iterator_category
const value_type & reference
friend bool operator==(sentinel, const const_iterator &rhs) noexcept
const_iterator & operator=(const_iterator &&) noexcept=default
pointer operator->() const
Returns a {const QDirListing::DirEntry *} to the directory entry this iterator points to.
friend bool operator!=(sentinel, const const_iterator &rhs) noexcept
friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
const_iterator & operator++()
Pre-increment operator.
friend bool operator==(const const_iterator &lhs, sentinel) noexcept
\typealias QDirListing::const_iterator::reference
friend constexpr bool operator==(sentinel, sentinel) noexcept
friend constexpr bool operator!=(sentinel, sentinel) noexcept
sentinel cend() const
const_iterator cbegin() const
QDirListing(QDirListing &&other) noexcept
Definition qdirlisting.h:59
const_iterator constBegin() const
sentinel constEnd() const
sentinel end() const
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qpoint.h:232
\inmodule QtCore\reentrant
Definition qpoint.h:30
\inmodule QtCore
Definition qvariant.h:68
Combined button and popup list for selecting options.
T qvariant_cast_qmetatype_converted(const QVariant &v, QMetaType targetType)
Definition qvariant.h:938
static QString appendSlashIfNeeded(const QString &path)
#define Q_MK_GET(cvref)
Definition qvariant.h:812
T qvariant_cast(QVariant &&v)
Definition qvariant.h:961
T qvariant_cast(const QVariant &)
Definition qvariant.h:946
void swap(QVariant &value1, QVariant &value2) noexcept
Definition qvariant.h:925