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 "qresource.h"
5#include "qresource_iterator_p.h"
6
7#include <QtCore/qvariant.h>
8
9QT_BEGIN_NAMESPACE
10
11QResourceFileEngineIterator::QResourceFileEngineIterator(const QString &path, QDir::Filters filters,
12 const QStringList &filterNames)
13 : QAbstractFileEngineIterator(path, filters, filterNames),
14 index(-1)
15{
16}
17
18QResourceFileEngineIterator::QResourceFileEngineIterator(const QString &path,
19 QDirListing::IteratorFlags filters,
20 const QStringList &filterNames)
21 : QAbstractFileEngineIterator(path, filters, filterNames),
22 index(-1)
23{
24}
25
26QResourceFileEngineIterator::~QResourceFileEngineIterator()
27{
28}
29
30bool QResourceFileEngineIterator::advance()
31{
32 if (index == -1) {
33 // Lazy initialization of the iterator
34 QResource resource(path());
35 if (!resource.isValid())
36 return false;
37
38 // Initialize and move to the first entry.
39 entries = resource.children();
40 if (entries.isEmpty())
41 return false;
42
43 index = 0;
44 return true;
45 }
46
47 if (index < entries.size() - 1) {
48 ++index;
49 return true;
50 }
51
52 return false;
53}
54
55QString QResourceFileEngineIterator::currentFileName() const
56{
57 if (index < 0 || index > entries.size())
58 return QString();
59 return entries.at(i: index);
60}
61
62QFileInfo QResourceFileEngineIterator::currentFileInfo() const
63{
64 m_fileInfo = QFileInfo(currentFilePath());
65 return m_fileInfo;
66}
67
68QT_END_NAMESPACE
69

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