@@ -753,13 +753,17 void* PythonQtClassInfo::castDownIfPossible(void* ptr, PythonQtClassInfo** resul | |||
|
753 | 753 | return resultPtr; |
|
754 | 754 | } |
|
755 | 755 | |
|
756 |
PyObject* PythonQtClassInfo::findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool |
|
|
756 | PyObject* PythonQtClassInfo::findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum) | |
|
757 | 757 | { |
|
758 |
isLocalEnum |
|
|
758 | if (isLocalEnum) { | |
|
759 | *isLocalEnum = true; | |
|
760 | } | |
|
759 | 761 | int scopePos = name.lastIndexOf("::"); |
|
760 | 762 | if (scopePos != -1) { |
|
761 |
isLocalEnum |
|
|
762 | // slit into scope and enum name | |
|
763 | if (isLocalEnum) { | |
|
764 | *isLocalEnum = false; | |
|
765 | } | |
|
766 | // split into scope and enum name | |
|
763 | 767 | QByteArray enumScope = name.mid(0,scopePos); |
|
764 | 768 | QByteArray enumName = name.mid(scopePos+2); |
|
765 | 769 | PythonQtClassInfo* info = PythonQt::priv()->getClassInfo(enumScope); |
@@ -195,7 +195,7 public: | |||
|
195 | 195 | void* castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo); |
|
196 | 196 | |
|
197 | 197 | //! returns if the localScope has an enum of that type name or if the enum contains a :: scope, if that class contails the enum |
|
198 |
static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool |
|
|
198 | static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum = NULL); | |
|
199 | 199 | |
|
200 | 200 | private: |
|
201 | 201 | void createEnumWrappers(); |
@@ -254,10 +254,92 return Py_None; | |||
|
254 | 254 | return object; |
|
255 | 255 | } |
|
256 | 256 | |
|
257 |
|
|
|
257 | void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject) | |
|
258 | { | |
|
259 | void* ptr = alreadyAllocatedCPPObject; | |
|
260 | ||
|
261 | static int penId = QMetaType::type("QPen"); | |
|
262 | static int brushId = QMetaType::type("QBrush"); | |
|
263 | static int cursorId = QMetaType::type("QCursor"); | |
|
264 | static int colorId = QMetaType::type("QColor"); | |
|
265 | static PyObject* qtGlobalColorEnum = PythonQtClassInfo::findEnumWrapper("Qt::GlobalColor", NULL); | |
|
266 | if (typeId == cursorId) { | |
|
267 | static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper("Qt::CursorShape", NULL); | |
|
268 | if ((PyObject*)obj->ob_type == qtCursorShapeEnum) { | |
|
269 | Qt::CursorShape val = (Qt::CursorShape)PyInt_AS_LONG(obj); | |
|
270 | if (!ptr) { | |
|
271 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QCursor(), ptr); | |
|
272 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
273 | } | |
|
274 | *((QCursor*)ptr) = QCursor(val); | |
|
275 | return ptr; | |
|
276 | } | |
|
277 | } else if (typeId == penId) { | |
|
278 | // brushes can be created from QColor and from Qt::GlobalColor (and from brushes, but that's the default) | |
|
279 | static PyObject* qtColorClass = PythonQt::priv()->getClassInfo("QColor")->pythonQtClassWrapper(); | |
|
280 | if ((PyObject*)obj->ob_type == qtGlobalColorEnum) { | |
|
281 | Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG(obj); | |
|
282 | if (!ptr) { | |
|
283 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QPen(), ptr); | |
|
284 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
285 | } | |
|
286 | *((QPen*)ptr) = QPen(QColor(val)); | |
|
287 | return ptr; | |
|
288 | } else if ((PyObject*)obj->ob_type == qtColorClass) { | |
|
289 | if (!ptr) { | |
|
290 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QPen(), ptr); | |
|
291 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
292 | } | |
|
293 | *((QPen*)ptr) = QPen(*((QColor*)((PythonQtInstanceWrapper*)obj)->_wrappedPtr)); | |
|
294 | return ptr; | |
|
295 | } | |
|
296 | } else if (typeId == brushId) { | |
|
297 | // brushes can be created from QColor and from Qt::GlobalColor (and from brushes, but that's the default) | |
|
298 | static PyObject* qtColorClass = PythonQt::priv()->getClassInfo("QColor")->pythonQtClassWrapper(); | |
|
299 | if ((PyObject*)obj->ob_type == qtGlobalColorEnum) { | |
|
300 | Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG(obj); | |
|
301 | if (!ptr) { | |
|
302 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QBrush(), ptr); | |
|
303 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
304 | } | |
|
305 | *((QBrush*)ptr) = QBrush(QColor(val)); | |
|
306 | return ptr; | |
|
307 | } else if ((PyObject*)obj->ob_type == qtColorClass) { | |
|
308 | if (!ptr) { | |
|
309 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QBrush(), ptr); | |
|
310 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
311 | } | |
|
312 | *((QBrush*)ptr) = QBrush(*((QColor*)((PythonQtInstanceWrapper*)obj)->_wrappedPtr)); | |
|
313 | return ptr; | |
|
314 | } | |
|
315 | } else if (typeId == colorId) { | |
|
316 | // colors can be created from Qt::GlobalColor (and from colors, but that's the default) | |
|
317 | if ((PyObject*)obj->ob_type == qtGlobalColorEnum) { | |
|
318 | Qt::GlobalColor val = (Qt::GlobalColor)PyInt_AS_LONG(obj); | |
|
319 | if (!ptr) { | |
|
320 | PythonQtValueStorage_ADD_VALUE(global_variantStorage, QVariant, QColor(), ptr); | |
|
321 | ptr = (void*)((QVariant*)ptr)->constData(); | |
|
322 | } | |
|
323 | *((QColor*)ptr) = QColor(val); | |
|
324 | return ptr; | |
|
325 | } | |
|
326 | } | |
|
327 | return NULL; | |
|
328 | } | |
|
329 | ||
|
330 | void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* /*classInfo*/, void* alreadyAllocatedCPPObject) | |
|
258 | 331 | { |
|
259 | 332 | bool ok = false; |
|
260 | 333 | void* ptr = NULL; |
|
334 | ||
|
335 | // autoconversion of QPen/QBrush/QCursor/QColor from different type | |
|
336 | if (!info.isPointer && !strict) { | |
|
337 | ptr = handlePythonToQtAutoConversion(info.typeId, obj, alreadyAllocatedCPPObject); | |
|
338 | if (ptr) { | |
|
339 | return ptr; | |
|
340 | } | |
|
341 | } | |
|
342 | ||
|
261 | 343 |
|
|
262 | 344 | // if we have a Qt wrapper object and if we do not need a QVariant, we do the following: |
|
263 | 345 | // (the Variant case is handled below in a switch) |
@@ -152,6 +152,9 public: | |||
|
152 | 152 | protected: |
|
153 | 153 | static QHash<int, PythonQtConvertMetaTypeToPythonCB*> _metaTypeToPythonConverters; |
|
154 | 154 | static QHash<int, PythonQtConvertPythonToMetaTypeCB*> _pythonToMetaTypeConverters; |
|
155 | ||
|
156 | //! handle automatic conversion of some special types (QColor, QBrush, ...) | |
|
157 | static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject); | |
|
155 | 158 | |
|
156 | 159 | //! converts the list of pointers of given type to Python |
|
157 | 160 | static PyObject* ConvertQListOfPointerTypeToPythonList(QList<void*>* list, const QByteArray& type); |
@@ -135,7 +135,7 void PythonQtMethodInfo::fillParameterInfo(ParameterInfo& type, const QByteArray | |||
|
135 | 135 | if (type.typeId == PythonQtMethodInfo::Unknown || type.typeId >= QMetaType::User) { |
|
136 | 136 | bool isLocalEnum; |
|
137 | 137 | // TODOXXX: make use of this flag! |
|
138 | type.enumWrapper = PythonQtClassInfo::findEnumWrapper(type.name, classInfo, isLocalEnum); | |
|
138 | type.enumWrapper = PythonQtClassInfo::findEnumWrapper(type.name, classInfo, &isLocalEnum); | |
|
139 | 139 | } |
|
140 | 140 | } else { |
|
141 | 141 | type.typeId = QMetaType::Void; |
General Comments 0
You need to be logged in to leave comments.
Login now