-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConstRefPropertyHelpers.h
62 lines (51 loc) · 2.81 KB
/
ConstRefPropertyHelpers.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
#pragma once
#include <QObject>
#include "HelpersCommon.h"
#define CONST_SETTER(type, name) \
public: \
void set_##name(const type& name) { \
if (m_##name != name) { \
m_##name = name; \
Q_EMIT name##Changed(); \
} \
}
#define CONST_GETTER(type, name) \
public: \
const type& MAKE_GETTER_NAME(name)() const { return m_##name; }
#define W_CREF_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ MAKE_GETTER_NAME(name) WRITE set_##name NOTIFY name##Changed) \
private: \
MEMBER(type, name) \
CONST_GETTER(type, name) \
CONST_SETTER(type, name) \
NOTIFIER(name)
#define R_CREF_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ MAKE_GETTER_NAME(name) NOTIFY name##Changed) \
MEMBER(type, name) \
CONST_GETTER(type, name) \
CONST_SETTER(type, name) \
NOTIFIER(name) \
private:
#define C_CREF_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ MAKE_GETTER_NAME(name) CONSTANT) \
MEMBER(type, name) \
CONST_GETTER(type, name) \
private:
#define W_CREF_PROPERTY_DEFAULT(type, name, defaultValue) \
protected: \
Q_PROPERTY(type name READ MAKE_GETTER_NAME(name) WRITE set_##name NOTIFY name##Changed) \
private: \
MEMBER_DEFAULT(type, name, defaultValue) \
CONST_GETTER(type, name) \
CONST_SETTER(type, name) \
NOTIFIER(name)
class Test : public QObject {
Q_OBJECT
W_CREF_PROPERTY(QString, var1)
R_CREF_PROPERTY(QString, var2)
C_CREF_PROPERTY(QString, var3)
W_CREF_PROPERTY_DEFAULT(QString, var4, QStringLiteral("test"))
};