-
Notifications
You must be signed in to change notification settings - Fork 5
/
propertyhelpers.h
52 lines (48 loc) · 3.14 KB
/
propertyhelpers.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
#ifndef PROPERTY_HELPERS_H
#define PROPERTY_HELPERS_H
#include <QObject>
#define WRITABLE_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ get_##name WRITE set_##name NOTIFY name##Changed) \
type m_##name; \
\
public: \
type get_##name() const { return m_##name; } \
public Q_SLOTS: \
bool set_##name(type name) \
{ \
bool ret= false; \
if((ret= m_##name != name)) \
{ \
m_##name= name; \
emit name##Changed(m_##name); \
} \
return ret; \
} \
Q_SIGNALS: \
void name##Changed(type name); \
\
private:
#define READONLY_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ get_##name NOTIFY name##Changed) \
type m_##name; \
\
public: \
type get_##name() const { return m_##name; } \
public Q_SLOTS: \
bool update_##name(type name) \
{ \
bool ret= false; \
if((ret= m_##name != name)) \
{ \
m_##name= name; \
emit name##Changed(m_##name); \
} \
return ret; \
} \
Q_SIGNALS: \
void name##Changed(type name); \
\
private:
#endif // PROPERTY_HELPERS_H