@@ -154,3 +154,151 QString PythonQtStdDecorators::tr(QObject* obj, const QByteArray& text, const QB | |||||
154 | return QCoreApplication::translate(obj->metaObject()->className(), text.constData(), ambig.constData(), QCoreApplication::CodecForTr, n); |
|
154 | return QCoreApplication::translate(obj->metaObject()->className(), text.constData(), ambig.constData(), QCoreApplication::CodecForTr, n); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
|
157 | QObject* PythonQtStdDecorators::findChild(QObject* parent, PyObject* type, const QString& name) | |||
|
158 | { | |||
|
159 | const QMetaObject* meta = NULL; | |||
|
160 | const char* typeName = NULL; | |||
|
161 | ||||
|
162 | if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { | |||
|
163 | meta = ((PythonQtClassWrapper*)type)->classInfo()->metaObject(); | |||
|
164 | } else if (PyObject_TypeCheck(type, &PythonQtInstanceWrapper_Type)) { | |||
|
165 | meta = ((PythonQtInstanceWrapper*)type)->classInfo()->metaObject(); | |||
|
166 | } else if (PyString_Check(type)) { | |||
|
167 | typeName = PyString_AsString(type); | |||
|
168 | } | |||
|
169 | ||||
|
170 | if (!typeName && !meta) | |||
|
171 | return NULL; | |||
|
172 | ||||
|
173 | return findChild(parent, typeName, meta, name); | |||
|
174 | } | |||
|
175 | ||||
|
176 | QList<QObject*> PythonQtStdDecorators::findChildren(QObject* parent, PyObject* type, const QString& name) | |||
|
177 | { | |||
|
178 | const QMetaObject* meta = NULL; | |||
|
179 | const char* typeName = NULL; | |||
|
180 | ||||
|
181 | if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { | |||
|
182 | meta = ((PythonQtClassWrapper*)type)->classInfo()->metaObject(); | |||
|
183 | } else if (PyObject_TypeCheck(type, &PythonQtInstanceWrapper_Type)) { | |||
|
184 | meta = ((PythonQtInstanceWrapper*)type)->classInfo()->metaObject(); | |||
|
185 | } else if (PyString_Check(type)) { | |||
|
186 | typeName = PyString_AsString(type); | |||
|
187 | } | |||
|
188 | ||||
|
189 | QList<QObject*> list; | |||
|
190 | ||||
|
191 | if (!typeName && !meta) | |||
|
192 | return list; | |||
|
193 | ||||
|
194 | findChildren(parent, typeName, meta, name, list); | |||
|
195 | ||||
|
196 | return list; | |||
|
197 | } | |||
|
198 | ||||
|
199 | QList<QObject*> PythonQtStdDecorators::findChildren(QObject* parent, PyObject* type, const QRegExp& regExp) | |||
|
200 | { | |||
|
201 | const QMetaObject* meta = NULL; | |||
|
202 | const char* typeName = NULL; | |||
|
203 | ||||
|
204 | if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { | |||
|
205 | meta = ((PythonQtClassWrapper*)type)->classInfo()->metaObject(); | |||
|
206 | } else if (PyObject_TypeCheck(type, &PythonQtInstanceWrapper_Type)) { | |||
|
207 | meta = ((PythonQtInstanceWrapper*)type)->classInfo()->metaObject(); | |||
|
208 | } else if (PyString_Check(type)) { | |||
|
209 | typeName = PyString_AsString(type); | |||
|
210 | } | |||
|
211 | ||||
|
212 | QList<QObject*> list; | |||
|
213 | ||||
|
214 | if (!typeName && !meta) | |||
|
215 | return list; | |||
|
216 | ||||
|
217 | findChildren(parent, typeName, meta, regExp, list); | |||
|
218 | ||||
|
219 | return list; | |||
|
220 | } | |||
|
221 | ||||
|
222 | QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name) | |||
|
223 | { | |||
|
224 | const QObjectList &children = parent->children(); | |||
|
225 | ||||
|
226 | int i; | |||
|
227 | for (i = 0; i < children.size(); ++i) { | |||
|
228 | QObject* obj = children.at(i); | |||
|
229 | ||||
|
230 | if (!obj) | |||
|
231 | return NULL; | |||
|
232 | ||||
|
233 | // Skip if the name doesn't match. | |||
|
234 | if (!name.isNull() && obj->objectName() != name) | |||
|
235 | continue; | |||
|
236 | ||||
|
237 | if ((typeName && obj->inherits(typeName)) || | |||
|
238 | (meta && meta->cast(obj))) | |||
|
239 | return obj; | |||
|
240 | } | |||
|
241 | ||||
|
242 | for (i = 0; i < children.size(); ++i) { | |||
|
243 | QObject* obj = findChild(children.at(i), typeName, meta, name); | |||
|
244 | ||||
|
245 | if (obj != NULL) | |||
|
246 | return obj; | |||
|
247 | } | |||
|
248 | ||||
|
249 | return NULL; | |||
|
250 | } | |||
|
251 | ||||
|
252 | int PythonQtStdDecorators::findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList<QObject*>& list) | |||
|
253 | { | |||
|
254 | const QObjectList& children = parent->children(); | |||
|
255 | int i; | |||
|
256 | ||||
|
257 | for (i = 0; i < children.size(); ++i) { | |||
|
258 | QObject* obj = children.at(i); | |||
|
259 | ||||
|
260 | if (!obj) | |||
|
261 | return -1; | |||
|
262 | ||||
|
263 | // Skip if the name doesn't match. | |||
|
264 | if (!name.isNull() && obj->objectName() != name) | |||
|
265 | continue; | |||
|
266 | ||||
|
267 | if ((typeName && obj->inherits(typeName)) || | |||
|
268 | (meta && meta->cast(obj))) { | |||
|
269 | list += obj; | |||
|
270 | } | |||
|
271 | ||||
|
272 | if (findChildren(obj, typeName, meta, name, list) < 0) | |||
|
273 | return -1; | |||
|
274 | } | |||
|
275 | ||||
|
276 | return 0; | |||
|
277 | } | |||
|
278 | ||||
|
279 | int PythonQtStdDecorators::findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegExp& regExp, QList<QObject*>& list) | |||
|
280 | { | |||
|
281 | const QObjectList& children = parent->children(); | |||
|
282 | int i; | |||
|
283 | ||||
|
284 | for (i = 0; i < children.size(); ++i) { | |||
|
285 | QObject* obj = children.at(i); | |||
|
286 | ||||
|
287 | if (!obj) | |||
|
288 | return -1; | |||
|
289 | ||||
|
290 | // Skip if the name doesn't match. | |||
|
291 | if (regExp.indexIn(obj->objectName()) == -1) | |||
|
292 | continue; | |||
|
293 | ||||
|
294 | if ((typeName && obj->inherits(typeName)) || | |||
|
295 | (meta && meta->cast(obj))) { | |||
|
296 | list += obj; | |||
|
297 | } | |||
|
298 | ||||
|
299 | if (findChildren(obj, typeName, meta, regExp, list) < 0) | |||
|
300 | return -1; | |||
|
301 | } | |||
|
302 | ||||
|
303 | return 0; | |||
|
304 | } |
@@ -71,6 +71,9 public slots: | |||||
71 | void setParent(QObject* o, QObject* parent); |
|
71 | void setParent(QObject* o, QObject* parent); | |
72 |
|
72 | |||
73 | const QObjectList* children(QObject* o); |
|
73 | const QObjectList* children(QObject* o); | |
|
74 | QObject* findChild(QObject* parent, PyObject* type, const QString& name = QString()); | |||
|
75 | QList<QObject*> findChildren(QObject* parent, PyObject* type, const QString& name= QString()); | |||
|
76 | QList<QObject*> findChildren(QObject* parent, PyObject* type, const QRegExp& regExp); | |||
74 |
|
77 | |||
75 | double static_Qt_qAbs(double a) { return qAbs(a); } |
|
78 | double static_Qt_qAbs(double a) { return qAbs(a); } | |
76 | double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); } |
|
79 | double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); } | |
@@ -96,7 +99,10 public slots: | |||||
96 | QByteArray static_Qt_SIGNAL(const QByteArray& s) { return QByteArray("2") + s; } |
|
99 | QByteArray static_Qt_SIGNAL(const QByteArray& s) { return QByteArray("2") + s; } | |
97 | QByteArray static_Qt_SLOT(const QByteArray& s) { return QByteArray("1") + s; } |
|
100 | QByteArray static_Qt_SLOT(const QByteArray& s) { return QByteArray("1") + s; } | |
98 |
|
101 | |||
99 | //TODO: add findChild/findChildren/children/... |
|
102 | private: | |
|
103 | QObject* findChild(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name); | |||
|
104 | int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList<QObject*>& list); | |||
|
105 | int findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QRegExp& regExp, QList<QObject*>& list); | |||
100 | }; |
|
106 | }; | |
101 |
|
107 | |||
102 |
|
108 |
General Comments 0
You need to be logged in to leave comments.
Login now