aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/designercore/include/modelfwd.h
blob: 91c533fe7b6a2950d5031a4c269b84bce44a52ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "../projectstorage/projectstoragefwd.h"
#include "qmldesignercorelib_exports.h"

#include <utils/smallstringview.h>
#include <utils/span.h>

namespace QmlDesigner {
using PropertyName = QByteArray;
using PropertyNameView = QByteArrayView;
using PropertyNameList = QList<PropertyName>;

template<std::size_t Size, const char Text[Size]>
class ByteArrayViewLiteral : public QByteArrayView
{
public:
    constexpr ByteArrayViewLiteral() noexcept
        : QByteArrayView{Text, Size - 1}
    {}

    const QByteArray &toByteArray() const noexcept
    {
        static auto b = QByteArray::fromRawData(Text, Size - 1);

        return b;
    }

    operator const QByteArray &() const noexcept { return toByteArray(); }
};

#define MakeCppPropertyViewLiteral(name, text) \
    constexpr char name##InternalString[] = text; \
    constexpr ByteArrayViewLiteral<sizeof(name##InternalString), name##InternalString> name{}; \
    /* */

#define MakeHeaderPropertyViewLiteral(name, text) \
    inline constexpr char name##InternalString[] = text; \
    inline constexpr ByteArrayViewLiteral<sizeof(name##InternalString), name##InternalString> name{}; \
    /* */

#define MakeFunctionPropertyViewLiteral(name, text) \
    static constexpr char name##InternalString[] = text; \
    static constexpr ByteArrayViewLiteral<sizeof(name##InternalString), name##InternalString> name{}; \
    /* */

using TypeName = QByteArray;
using TypeNameView = QByteArrayView;
using PropertyTypeList = QList<PropertyName>;
using IdName = QByteArray;
class Model;
class ModelNode;
class NonLockingMutex;
template<typename ProjectStorage, typename Mutex = NonLockingMutex>
class SourcePathCache;

struct ModelDeleter
{
    QMLDESIGNERCORE_EXPORT void operator()(class Model *model);
};

using ModelPointer = std::unique_ptr<class Model, ModelDeleter>;

constexpr bool useProjectStorage()
{
#ifdef QDS_USE_PROJECTSTORAGE
    return true;
#else
    return false;
#endif
}

#ifdef QDS_MODEL_USE_PROJECTSTORAGEINTERFACE
using ProjectStorageType = ProjectStorageInterface;
using PathCacheType = SourcePathCacheInterface;
#else
using ProjectStorageType = ProjectStorage;
using PathCacheType = SourcePathCache<ProjectStorageType, NonLockingMutex>;
#endif

struct ProjectStorageDependencies
{
    ProjectStorageType &storage;
    PathCacheType &cache;
};

enum class PropertyType {
    None,
    Variant,
    Node,
    NodeList,
    Binding,
    SignalHandler,
    SignalDeclaration
};

} // namespace QmlDesigner