1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qfsfileengine_iterator_p.h"
5#include "qfileinfo_p.h"
6#include "qvariant.h"
7
8#ifndef QT_NO_FILESYSTEMITERATOR
9
10QT_BEGIN_NAMESPACE
11
12QFSFileEngineIterator::QFSFileEngineIterator(QDir::Filters filters, const QStringList &filterNames)
13 : QAbstractFileEngineIterator(filters, filterNames)
14 , done(false)
15{
16}
17
18QFSFileEngineIterator::~QFSFileEngineIterator()
19{
20}
21
22bool QFSFileEngineIterator::hasNext() const
23{
24 if (!done && !nativeIterator) {
25 nativeIterator.reset(other: new QFileSystemIterator(QFileSystemEntry(path()),
26 filters(), nameFilters()));
27 advance();
28 }
29
30 return !done;
31}
32
33QString QFSFileEngineIterator::next()
34{
35 if (!hasNext())
36 return QString();
37
38 advance();
39 return currentFilePath();
40}
41
42void QFSFileEngineIterator::advance() const
43{
44 currentInfo = nextInfo;
45
46 QFileSystemEntry entry;
47 QFileSystemMetaData data;
48 if (nativeIterator->advance(fileEntry&: entry, metaData&: data)) {
49 nextInfo = QFileInfo(new QFileInfoPrivate(entry, data));
50 } else {
51 done = true;
52 nativeIterator.reset();
53 }
54}
55
56QString QFSFileEngineIterator::currentFileName() const
57{
58 return currentInfo.fileName();
59}
60
61QFileInfo QFSFileEngineIterator::currentFileInfo() const
62{
63 return currentInfo;
64}
65
66QT_END_NAMESPACE
67
68#endif // QT_NO_FILESYSTEMITERATOR
69

source code of qtbase/src/corelib/io/qfsfileengine_iterator.cpp