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
5#ifndef QDIRLISTING_H
6#define QDIRLISTING_H
7
8#include <QtCore/qfiledevice.h>
9#include <QtCore/qflags.h>
10#include <QtCore/qtclasshelpermacros.h>
11#include <QtCore/qtcoreexports.h>
12#include <QtCore/qdatetime.h>
13
14#include <iterator>
15#include <memory>
16
17QT_BEGIN_NAMESPACE
18
19class QDirListingPrivate;
20class QFileInfo;
21class QDir;
22class QTimeZone;
23
25{
26public:
27 enum class IteratorFlag {
28 Default = 0x000000,
29 ExcludeFiles = 0x000004,
30 ExcludeDirs = 0x000008,
31 ExcludeSpecial = 0x000010,
32 ResolveSymlinks = 0x000020,
35 IncludeHidden = 0x000040,
36 IncludeDotAndDotDot = 0x000080,
37 CaseSensitive = 0x000100,
38 Recursive = 0x000400,
39 FollowDirSymlinks = 0x000800,
40 };
41 Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag)
42
43 Q_CORE_EXPORT explicit QDirListing(const QString &path,
47
48 QDirListing(QDirListing &&other) noexcept
49 : d{std::exchange(other.d, nullptr)} {}
51
52 void swap(QDirListing &other) noexcept { qt_ptr_swap(d, other.d); }
53
55
56 Q_CORE_EXPORT QString iteratorPath() const;
57 Q_CORE_EXPORT IteratorFlags iteratorFlags() const;
58 Q_CORE_EXPORT QStringList nameFilters() const;
59
61 {
62 friend class QDirListing;
63 QDirListingPrivate *dirListPtr = nullptr;
64 public:
65 Q_CORE_EXPORT QString fileName() const;
72 Q_CORE_EXPORT bool isDir() const;
73 Q_CORE_EXPORT bool isFile() const;
74 Q_CORE_EXPORT bool isSymLink() const;
75 Q_CORE_EXPORT bool exists() const;
76 Q_CORE_EXPORT bool isHidden() const;
77 Q_CORE_EXPORT bool isReadable() const;
78 Q_CORE_EXPORT bool isWritable() const;
79 Q_CORE_EXPORT bool isExecutable() const;
80 Q_CORE_EXPORT QFileInfo fileInfo() const;
84 Q_CORE_EXPORT qint64 size() const;
85
86 QDateTime birthTime(const QTimeZone &tz) const
87 { return fileTime(QFileDevice::FileBirthTime, tz); }
88 QDateTime metadataChangeTime(const QTimeZone &tz) const
89 { return fileTime(QFileDevice::FileMetadataChangeTime, tz); }
90 QDateTime lastModified(const QTimeZone &tz) const
91 { return fileTime(QFileDevice::FileModificationTime, tz); }
92 QDateTime lastRead(const QTimeZone &tz) const
93 { return fileTime(QFileDevice::FileAccessTime, tz); }
94 Q_CORE_EXPORT QDateTime fileTime(QFileDevice::FileTime type, const QTimeZone &tz) const;
95 };
96
98 {
99 friend constexpr bool operator==(sentinel, sentinel) noexcept { return true; }
100 friend constexpr bool operator!=(sentinel, sentinel) noexcept { return false; }
101 };
102
104 {
106 friend class QDirListing;
107 explicit const_iterator(QDirListingPrivate *dp) { dirEntry.dirListPtr = dp; }
108 DirEntry dirEntry;
109 public:
110 using iterator_category = std::input_iterator_tag;
111 using value_type = DirEntry;
113 using pointer = const value_type *;
114 using reference = const value_type &;
115
116 const_iterator() = default;
117 const_iterator(const_iterator &&) noexcept = default;
118 const_iterator &operator=(const_iterator &&) noexcept = default;
119
120 reference operator*() const { return dirEntry; }
121 pointer operator->() const { return &dirEntry; }
122 const_iterator &operator++() { dirEntry = next(dirEntry); return *this; }
123 void operator++(int) { ++*this; }; // [iterator.concept.winc]/14 not required to return sth
124 private:
125 bool atEnd() const noexcept { return dirEntry.dirListPtr == nullptr; }
126 friend bool operator==(const const_iterator &lhs, sentinel) noexcept { return lhs.atEnd(); }
127#ifndef __cpp_impl_three_way_comparison
128 friend bool operator!=(const const_iterator &lhs, sentinel) noexcept
129 { return !operator==(lhs, sentinel{}); }
130 friend bool operator==(sentinel, const const_iterator &rhs) noexcept
131 { return operator==(rhs, sentinel{}); }
132 friend bool operator!=(sentinel, const const_iterator &rhs) noexcept
133 { return !operator==(sentinel{}, rhs); }
134#endif // __cpp_impl_three_way_comparison
135 };
136
138 const_iterator cbegin() const { return begin(); }
139 sentinel end() const { return {}; }
140 sentinel cend() const { return end(); }
141
142 // Qt compatibility
143 const_iterator constBegin() const { return begin(); }
144 sentinel constEnd() const { return end(); }
145
146private:
148
150
151 // Private constructor that is used in deprecated code paths.
152 // `uint` instead of QDir::Filters and QDirIterator::IteratorFlags
153 // because qdir.h can't be included here; qdiriterator.h can't included
154 // either, because it includes qdir.h
156 uint qdirIteratorFlags = 0); // QDirIterator::NoIteratorFlags == 0x0
157
159 friend class QDir;
160 friend class QDirPrivate;
162 friend class QAbstractFileEngine;
163 friend class QFileInfoGatherer;
164};
165
166Q_DECLARE_OPERATORS_FOR_FLAGS(QDirListing::IteratorFlags)
167
168QT_END_NAMESPACE
169
170#endif // QDIRLISTING_H
\inmodule QtCore\reentrant
Definition qdatastream.h:47
\inmodule QtCore
Definition qdirlisting.h:61
QDateTime birthTime(const QTimeZone &tz) const
Definition qdirlisting.h:86
QDateTime metadataChangeTime(const QTimeZone &tz) const
Definition qdirlisting.h:88
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.
Definition qdirlisting.h:92
QDateTime lastModified(const QTimeZone &tz) const
Definition qdirlisting.h:90
const_iterator(const_iterator &&) noexcept=default
reference operator*() const
Returns a {const QDirListing::DirEntry &} of the directory entry this iterator points to.
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
Definition qdirlisting.h:98
friend constexpr bool operator==(sentinel, sentinel) noexcept
Definition qdirlisting.h:99
friend constexpr bool operator!=(sentinel, sentinel) noexcept
sentinel cend() const
IteratorFlag
This enum class describes flags that can be used to configure the behavior of QDirListing.
Definition qdirlisting.h:27
const_iterator cbegin() const
QDirListing(QDirListing &&other) noexcept
Definition qdirlisting.h:48
const_iterator constBegin() const
sentinel constEnd() const
sentinel end() const
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
Emulated const pointer to QVariant based on a pointer.
Definition qvariant.h:859
QVariantPointer is a template class that emulates a pointer to QVariant based on a pointer.
Definition qvariant.h:872
QVariantPointer(const Pointer *pointer)
Constructs a QVariantPointer from the given pointer.
Definition qvariant.h:877
QVariantRef< Pointer > operator*() const
Dereferences the QVariantPointer to a QVariantRef.
Definition qvariant.h:878
Pointer operator->() const
Dereferences and returns the pointer.
Definition qvariant.h:879
The QVariantRef acts as a non-const reference to a QVariant.
Definition qvariant.h:835
operator QVariant() const
Resolves the QVariantRef to an actual QVariant.
QVariantRef & operator=(const QVariantRef &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
Definition qvariant.h:847
QVariantRef & operator=(const QVariant &value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
~QVariantRef()=default
QVariantRef(const QVariantRef &)=default
QVariantRef(QVariantRef &&)=default
friend void swap(QVariantRef a, QVariantRef b)
Definition qvariant.h:850
QVariantRef & operator=(QVariantRef &&value)
Assigns a new value to the value pointed to by the pointer this QVariantRef refers to.
Definition qvariant.h:848
QVariantRef(const Pointer *reference)
Creates a QVariantRef from an pointer.
Definition qvariant.h:840
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
Definition qcompare.h:24
static QString appendSlashIfNeeded(const QString &path)
#define Q_MK_GET(cvref)
Definition qvariant.h:647
T qvariant_cast(QVariant &&v)
Definition qvariant.h:770
T qvariant_cast(const QVariant &)
Definition qvariant.h:753
void swap(QVariant &value1, QVariant &value2) noexcept
Definition qvariant.h:748