1// Copyright (C) 2021 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 QQMLDOMMOCK_P_H
5#define QQMLDOMMOCK_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 "qqmldomitem_p.h"
19#include "qqmldomconstants_p.h"
20#include "qqmldomelements_p.h"
21#include "qqmldomcomments_p.h"
22
23#include <QtQml/private/qqmljsast_p.h>
24#include <QtQml/private/qqmljsengine_p.h>
25
26#include <QtCore/QCborValue>
27#include <QtCore/QCborMap>
28#include <QtCore/QMutexLocker>
29#include <QtCore/QPair>
30
31#include <functional>
32#include <limits>
33
34QT_BEGIN_NAMESPACE
35
36namespace QQmlJS {
37namespace Dom {
38
39// mainly for debugging purposes
40class MockObject final : public CommentableDomElement
41{
42public:
43 constexpr static DomType kindValue = DomType::MockObject;
44 DomType kind() const override { return kindValue; }
45
46 MockObject(Path pathFromOwner = Path(), QMap<QString, MockObject> subObjects = {},
47 QMap<QString, QCborValue> subValues = {})
48 : CommentableDomElement(pathFromOwner), subObjects(subObjects), subValues(subValues)
49 {
50 }
51
52 MockObject copy() const;
53 std::pair<QString, MockObject> asStringPair() const;
54
55 bool iterateDirectSubpaths(DomItem &self, DirectVisitor) override;
56
57 QMap<QString, MockObject> subObjects;
58 QMap<QString, QCborValue> subValues;
59};
60
61// mainly for debugging purposes
62class MockOwner final : public OwningItem
63{
64protected:
65 std::shared_ptr<OwningItem> doCopy(DomItem &self) const override;
66
67public:
68 constexpr static DomType kindValue = DomType::MockOwner;
69 DomType kind() const override { return kindValue; }
70
71 MockOwner(Path pathFromTop = Path(), int derivedFrom = 0,
72 QMap<QString, MockObject> subObjects = {}, QMap<QString, QCborValue> subValues = {},
73 QMap<QString, QMap<QString, MockObject>> subMaps = {},
74 QMap<QString, QMultiMap<QString, MockObject>> subMultiMaps = {},
75 QMap<QString, QList<MockObject>> subLists = {})
76 : OwningItem(derivedFrom),
77 pathFromTop(pathFromTop),
78 subObjects(subObjects),
79 subValues(subValues),
80 subMaps(subMaps),
81 subMultiMaps(subMultiMaps),
82 subLists(subLists)
83 {
84 }
85
86 MockOwner(Path pathFromTop, int derivedFrom, QDateTime dataRefreshedAt,
87 QMap<QString, MockObject> subObjects = {}, QMap<QString, QCborValue> subValues = {})
88 : OwningItem(derivedFrom, dataRefreshedAt),
89 pathFromTop(pathFromTop),
90 subObjects(subObjects),
91 subValues(subValues)
92 {
93 }
94
95 MockOwner(const MockOwner &o);
96
97 std::shared_ptr<MockOwner> makeCopy(DomItem &self) const;
98 Path canonicalPath(DomItem &self) const override;
99
100 bool iterateDirectSubpaths(DomItem &self, DirectVisitor) override;
101
102 Path pathFromTop;
103 QMap<QString, MockObject> subObjects;
104 QMap<QString, QCborValue> subValues;
105 QMap<QString, QMap<QString, MockObject>> subMaps;
106 QMap<QString, QMultiMap<QString, MockObject>> subMultiMaps;
107 QMap<QString, QList<MockObject>> subLists;
108};
109
110} // end namespace Dom
111} // end namespace QQmlJS
112QT_END_NAMESPACE
113#endif // QQMLDOMELEMENTS_P_H
114

source code of qtdeclarative/src/qmldom/qqmldommock_p.h