-
Notifications
You must be signed in to change notification settings - Fork 1
/
PtrPropertyHelpers.h
124 lines (105 loc) · 5.79 KB
/
PtrPropertyHelpers.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once
#include <QObject>
#include <memory>
#include "HelpersCommon.h"
#define PTR_GETTER(type, name) \
public: \
type* MAKE_GETTER_NAME(name)() const { return m_##name; }
#define PTR_SETTER(type, name) \
public: \
void set_##name(type* name) { \
if (m_##name != name) { \
m_##name = name; \
Q_EMIT name##Changed(); \
} \
}
#define SMART_PTR_GETTER(type, name) \
public: \
type* MAKE_GETTER_NAME(name)() const { return m_##name.get(); }
#define SMART_PTR_SETTER(type, name) \
public: \
void set_##name(type name) { \
m_##name = std::move(name); \
Q_EMIT name##Changed(); \
}
#define W_PTR_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type* name READ MAKE_GETTER_NAME(name) WRITE set_##name NOTIFY name##Changed) \
\
MEMBER(type*, name) \
PTR_GETTER(type, name) \
PTR_SETTER(type, name) \
NOTIFIER(name) \
private:
#define R_PTR_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type* name READ MAKE_GETTER_NAME(name) NOTIFY name##Changed) \
\
MEMBER(type*, name) \
PTR_GETTER(type, name) \
PTR_SETTER(type, name) \
NOTIFIER(name) \
private:
#define C_PTR_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type* name READ MAKE_GETTER_NAME(name) CONSTANT) \
\
MEMBER(type*, name) \
PTR_GETTER(type, name) \
private:
#define W_PTR_PROPERTY_DEFAULT(type, name, defaultValue) \
protected: \
Q_PROPERTY(type* name READ MAKE_GETTER_NAME(name) WRITE set_##name NOTIFY name##Changed) \
\
MEMBER_DEFAULT(type*, name, defaultValue) \
PTR_GETTER(type, name) \
PTR_SETTER(type, name) \
NOTIFIER(name) \
private:
#define UNIQUE_PTR_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type* name READ get_##name NOTIFY name##Changed) \
\
MEMBER(std::unique_ptr<type>, name) \
SMART_PTR_GETTER(type, name) \
SMART_PTR_SETTER(std::unique_ptr<type>&, name) \
NOTIFIER(name) \
private:
#define UNIQUE_PTR_PROPERTY_INIT(type, name) \
protected: \
Q_PROPERTY(type* name READ get_##name NOTIFY name##Changed) \
\
MEMBER_DEFAULT(std::unique_ptr<type>, name, std::make_unique<type>()) \
SMART_PTR_GETTER(type, name) \
SMART_PTR_SETTER(std::unique_ptr<type>&, name) \
NOTIFIER(name) \
private:
#define SHARED_PTR_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type* name READ get_##name NOTIFY name##Changed) \
\
MEMBER(std::shared_ptr<type>, name) \
SMART_PTR_GETTER(type, name) \
SMART_PTR_SETTER(std::unique_ptr<type>&, name) \
NOTIFIER(name) \
private:
#define SHARED_PTR_PROPERTY_INIT(type, name) \
protected: \
Q_PROPERTY(type* name READ get_##name NOTIFY name##Changed) \
\
MEMBER_DEFAULT(std::shared_ptr<type>, name, std::make_shared<type>()) \
SMART_PTR_GETTER(type, name) \
SMART_PTR_SETTER(std::shared_ptr<type>, name) \
NOTIFIER(name) \
private:
class _QmlPtrProperty_ : public QObject {
Q_OBJECT
W_PTR_PROPERTY(int, var1)
R_PTR_PROPERTY(bool, var2)
C_PTR_PROPERTY(QString, test)
W_PTR_PROPERTY_DEFAULT(QString, var4, nullptr)
UNIQUE_PTR_PROPERTY(QString, test2)
UNIQUE_PTR_PROPERTY_INIT(QString, test3)
SHARED_PTR_PROPERTY(QString, test4)
SHARED_PTR_PROPERTY_INIT(QString, test5)
};