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 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | QResourceFileEngineIterator::QResourceFileEngineIterator(QDir::Filters filters, |
12 | const QStringList &filterNames) |
13 | : QAbstractFileEngineIterator(filters, filterNames), index(-1) |
14 | { |
15 | } |
16 | |
17 | QResourceFileEngineIterator::~QResourceFileEngineIterator() |
18 | { |
19 | } |
20 | |
21 | QString QResourceFileEngineIterator::next() |
22 | { |
23 | if (!hasNext()) |
24 | return QString(); |
25 | ++index; |
26 | return currentFilePath(); |
27 | } |
28 | |
29 | bool 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 | |
45 | QString QResourceFileEngineIterator::currentFileName() const |
46 | { |
47 | if (index <= 0 || index > entries.size()) |
48 | return QString(); |
49 | return entries.at(i: index - 1); |
50 | } |
51 | |
52 | QT_END_NAMESPACE |
53 |