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(QDir::Filters filters,
12 const QStringList &filterNames)
13 : QAbstractFileEngineIterator(filters, filterNames), index(-1)
14{
15}
16
17QResourceFileEngineIterator::~QResourceFileEngineIterator()
18{
19}
20
21QString QResourceFileEngineIterator::next()
22{
23 if (!hasNext())
24 return QString();
25 ++index;
26 return currentFilePath();
27}
28
29bool QResourceFileEngineIterator::hasNext() const
30{
31 if (index == -1) {
32 // Lazy initialization of the iterator
33 QResource resource(path());
34 if (!resource.isValid())
35 return false;
36
37 // Initialize and move to the next entry.
38 entries = resource.children();
39 index = 0;
40 }
41
42 return index < entries.size();
43}
44
45QString QResourceFileEngineIterator::currentFileName() const
46{
47 if (index <= 0 || index > entries.size())
48 return QString();
49 return entries.at(i: index - 1);
50}
51
52QT_END_NAMESPACE
53

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