-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqqmlhelpers.h
114 lines (106 loc) · 6.38 KB
/
qqmlhelpers.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
#ifndef QQMLHELPERS_H
#define QQMLHELPERS_H
#include <QObject>
#define QML_WRITABLE_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ get_##name WRITE set_##name NOTIFY name##Changed) \
private: \
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 QML_READONLY_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ get_##name NOTIFY name##Changed) \
private: \
type m_##name; \
\
public: \
type get_##name() const { return m_##name; } \
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:
#define QML_CONSTANT_PROPERTY(type, name) \
protected: \
Q_PROPERTY(type name READ get_##name CONSTANT) \
private: \
type m_##name; \
\
public: \
type get_##name() const { return m_##name; } \
\
private:
#define QML_LIST_PROPERTY(CLASS, NAME, TYPE) \
public: \
static int NAME##_count(QQmlListProperty<TYPE>* prop) \
{ \
CLASS* instance= qobject_cast<CLASS*>(prop->object); \
return (instance != NULL ? instance->m_##NAME.count() : 0); \
} \
static void NAME##_clear(QQmlListProperty<TYPE>* prop) \
{ \
CLASS* instance= qobject_cast<CLASS*>(prop->object); \
if(instance != NULL) \
{ \
instance->m_##NAME.clear(); \
} \
} \
static void NAME##_append(QQmlListProperty<TYPE>* prop, TYPE* obj) \
{ \
CLASS* instance= qobject_cast<CLASS*>(prop->object); \
if(instance != NULL && obj != NULL) \
{ \
instance->m_##NAME.append(obj); \
} \
} \
static TYPE* NAME##_at(QQmlListProperty<TYPE>* prop, int idx) \
{ \
CLASS* instance= qobject_cast<CLASS*>(prop->object); \
return (instance != NULL ? instance->m_##NAME.at(idx) : NULL); \
} \
QList<TYPE*> get_##NAME##s(void) const { return m_##NAME; } \
\
private: \
QList<TYPE*> m_##NAME;
#define QML_ENUM_CLASS(name, ...) \
class name : public QObject \
{ \
Q_GADGET \
public: \
enum Type \
{ \
__VA_ARGS__ \
}; \
Q_ENUMS(Type) \
};
class QmlProperty : public QObject
{
Q_OBJECT
}; // NOTE : to avoid "no suitable class found" MOC note
#endif // QQMLHELPERS_H