1// Copyright (C) 2019 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#ifndef QQMLDIRDATA_P_H
5#define QQMLDIRDATA_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qqmltypeloader_p.h>
19
20QT_BEGIN_NAMESPACE
21
22class Q_AUTOTEST_EXPORT QQmlQmldirData : public QQmlTypeLoader::Blob
23{
24private:
25 friend class QQmlTypeLoader;
26
27 QQmlQmldirData(const QUrl &, QQmlTypeLoader *);
28
29public:
30 const QString &content() const;
31 QV4::CompiledData::Location importLocation(Blob *blob) const;
32
33 template<typename Callback>
34 bool processImports(Blob *blob, const Callback &callback) const
35 {
36 bool result = true;
37 const auto range = m_imports.equal_range(key: blob);
38 for (auto it = range.first; it != range.second; ++it) {
39 // Do we need to resolve this import?
40 if ((it->import->priority == 0) || (it->import->priority > it->priority)) {
41 // This is the (current) best resolution for this import
42 if (!callback(it->import))
43 result = false;
44 it->import->priority = it->priority;
45 }
46 }
47 return result;
48 }
49
50 void setPriority(Blob *, PendingImportPtr, int);
51
52protected:
53 void dataReceived(const SourceCodeData &) override;
54 void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *) override;
55
56private:
57 struct PrioritizedImport {
58 PendingImportPtr import;
59 int priority = 0;
60 };
61
62 QString m_content;
63 QMultiHash<Blob *, PrioritizedImport> m_imports;
64};
65
66QT_END_NAMESPACE
67
68#endif // QQMLDIRDATA_P_H
69

source code of qtdeclarative/src/qml/qml/qqmldirdata_p.h