Skip to content

Commit 9887756

Browse files
committed
Added remove##ITEM##At method and added support from using from QML
1 parent 803f7a0 commit 9887756

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

src/JObject.h

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@
1111
// t: type, x: property name
1212
#define PropertyPrivateSet(t, x) private: t _##x; \
1313
public: t x() const {return _##x;} \
14-
private: void x(const t& v){_##x = v;}
14+
private: void x(const t& v){_##x = v; notify##x(v);}
1515

1616

1717
// t: type, x: property name
1818
#define PropertyProtectedSet(t, x) private: t _##x; \
1919
public: t x() const {return _##x;} \
20-
protected: void x(const t& v){_##x = v;}
20+
protected: void x(const t& v){_##x = v; notify##x(v);}
2121

2222
// t: type, x: property name
2323
#define PropertyPublicSet(t, x) private: t _##x; \
2424
public: t x() const {return _##x;} \
25-
void x(const t& v){_##x = v;}
25+
void x(const t& v){_##x = v; notify##x(v);}
2626

2727

2828
// t: type, x: property name
29-
#define MetaPropertyPrivateSet_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
29+
#define MetaPropertyPrivateSet_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
30+
private: Q_PROPERTY(QVariantList x READ x WRITE x NOTIFY notify##x) \
3031
PropertyPrivateSet(QVariantList, x) \
3132
void append##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
33+
void insert##t(int ind, const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
3234
void remove##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
3335
public: \
3436
int count##x()const {return _##x.length();} \
@@ -37,9 +39,11 @@
3739

3840

3941
// t: type, x: property name
40-
#define MetaPropertyProtectedSet_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
42+
#define MetaPropertyProtectedSet_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
43+
private: Q_PROPERTY(QVariantList x READ x WRITE x NOTIFY notify##x) \
4144
PropertyProtectedSet(QVariantList, x) \
4245
void append##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
46+
void insert##t(int ind, const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
4347
void remove##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
4448
public: \
4549
int count##x()const {return _##x.length();} \
@@ -48,10 +52,12 @@
4852

4953

5054
// t: type, x: property name
51-
#define MetaPropertyPublicSet_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
55+
#define MetaPropertyPublicSet_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
56+
private: Q_PROPERTY(QVariantList x READ x WRITE x NOTIFY notify##x) \
5257
PropertyPublicSet(QVariantList, x) \
5358
public: \
5459
void append##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
60+
void insert##t(int ind, const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
5561
void remove##x(const t& i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
5662
int count##x()const {return _##x.length();} \
5763
t item##x##At(int i) {return _##x.at(i).value<t>();}
@@ -90,66 +96,81 @@
9096
public: void x(QObject* v){_##x = v;}
9197

9298
// t: type, x: property name
93-
#define MetaPropertyPrivateSet(t, x) private: Q_PROPERTY(t x READ x WRITE x) \
99+
#define MetaPropertyPrivateSet(t, x) Q_SIGNALS: void notify##x(const t& i); \
100+
private: Q_PROPERTY(t x READ x WRITE x NOTIFY notify##x) \
94101
PropertyPrivateSet(t, x)
95102

96103

97104
// t: type, x: property name
98-
#define MetaPropertyProtectedSet(t, x) private: Q_PROPERTY(t x READ x WRITE x) \
105+
#define MetaPropertyProtectedSet(t, x) Q_SIGNALS: void notify##x(const t& i); \
106+
private: Q_PROPERTY(t x READ x WRITE x NOTIFY notify##x) \
99107
PropertyProtectedSet(t, x)
100108

101109
// t: type, x: property name
102-
#define MetaPropertyPublicSet(t, x) private: Q_PROPERTY(t x READ x WRITE x) \
110+
#define MetaPropertyPublicSet(t, x) Q_SIGNALS: void notify##x(const t& i); \
111+
private: Q_PROPERTY(t x READ x WRITE x NOTIFY notify##x) \
103112
PropertyPublicSet(t, x)
104113

105114
// t: type, x: property name
106-
#define MetaPropertyPrivateSet_Ptr(t, x) private: Q_PROPERTY(QObject* x READ x WRITE x) \
115+
#define MetaPropertyPrivateSet_Ptr(t, x) Q_SIGNALS: void notify##x(QObject* i); \
116+
private: Q_PROPERTY(QObject* x READ x WRITE x NOTIFY notify##x) \
107117
PropertyPrivateSet_Ptr_O(t, x) \
108118
public: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);}
109119

110120

111121
// t: type, x: property name
112-
#define MetaPropertyProtectedSet_Ptr(t, x) private: Q_PROPERTY(QObject* x READ x WRITE x) \
122+
#define MetaPropertyProtectedSet_Ptr(t, x) Q_SIGNALS: void notify##x(QObject* i); \
123+
private: Q_PROPERTY(QObject* x READ x WRITE x) \
113124
PropertyProtectedSet_Ptr_O(t, x) \
114125
public: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);}
115126

116127

117128
// t: type, x: property name
118-
#define MetaPropertyPublicSet_Ptr(t, x) private: Q_PROPERTY(QObject* x READ x WRITE x) \
129+
#define MetaPropertyPublicSet_Ptr(t, x) Q_SIGNALS: void notify##x(QObject* i); \
130+
private: Q_PROPERTY(QObject* x READ x WRITE x) \
119131
PropertyPublicSet_Ptr_O(t, x) \
120132
public: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);}
121133

122134
// t: type, x: property name
123-
#define MetaPropertyPrivateSet_Ptr_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
135+
#define MetaPropertyPrivateSet_Ptr_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
136+
private: Q_PROPERTY(QVariantList x READ x WRITE x) \
124137
PropertyPrivateSet(QVariantList, x) \
125138
private: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);} \
126139
void append##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
140+
void insert##t(int ind, t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
127141
void remove##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
128-
public: int count##t()const {return _##x.length();} \
129-
t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
130-
bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
142+
t* remove##t##At(int ind){t* i = _##x.at(ind).value<t*>(); QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);} return i;} \
143+
public: Q_INVOKABLE int count##t()const {return _##x.length();} \
144+
Q_INVOKABLE t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
145+
Q_INVOKABLE bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
131146

132147

133148
// t: type, x: property name
134-
#define MetaPropertyProtectedSet_Ptr_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
149+
#define MetaPropertyProtectedSet_Ptr_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
150+
private: Q_PROPERTY(QVariantList x READ x WRITE x) \
135151
PropertyProtectedSet(QVariantList, x) \
136152
protected: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);} \
137153
void append##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
154+
void insert##t(int ind, t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
138155
void remove##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
139-
public: int count##t()const {return _##x.length();} \
140-
t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
141-
bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
156+
t* remove##t##At(int ind){t* i = _##x.at(ind).value<t*>(); QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);} return i;} \
157+
public: Q_INVOKABLE int count##t()const {return _##x.length();} \
158+
Q_INVOKABLE t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
159+
Q_INVOKABLE bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
142160

143161

144162
// t: type, x: property name
145-
#define MetaPropertyPublicSet_Ptr_List(t, x) private: Q_PROPERTY(QVariantList x READ x WRITE x) \
163+
#define MetaPropertyPublicSet_Ptr_List(t, x) Q_SIGNALS: void notify##x(const QVariantList& i); \
164+
private: Q_PROPERTY(QVariantList x READ x WRITE x) \
146165
PropertyPublicSet(QVariantList, x) \
147166
public: Q_INVOKABLE void _type##x(const QString& prop){registerPtrProperty(prop, &t::staticMetaObject);} \
148-
void append##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
149-
void remove##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
150-
int count##t()const {return _##x.length();} \
151-
t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
152-
bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
167+
Q_INVOKABLE void append##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.append(v);}} \
168+
Q_INVOKABLE void insert##t(int ind, t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.insert(ind,v);}} \
169+
Q_INVOKABLE void remove##t(t* i){QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);}} \
170+
Q_INVOKABLE t* remove##t##At(int ind){t* i = _##x.at(ind).value<t*>(); QVariant v = QVariant::fromValue(i); if (v.isValid()) { _##x.removeAll(v);} return i;} \
171+
Q_INVOKABLE int count##t()const {return _##x.length();} \
172+
Q_INVOKABLE t* item##t##At(int i) {return _##x.at(i).value<t*>();} \
173+
Q_INVOKABLE bool item##t##Exist(t* i) const {QVariant v = QVariant::fromValue(i); if (v.isValid()) { return _##x.contains(v);} else return false;}
153174

154175

155176
/**

0 commit comments

Comments
 (0)