@@ -37,6 +37,8 enum GraphicsItemFlag{ | |||||
37 | enum GraphicsItemChange{ |
|
37 | enum GraphicsItemChange{ | |
38 | ItemPositionChange = QGraphicsItem::ItemPositionChange, ItemMatrixChange = QGraphicsItem::ItemMatrixChange, ItemVisibleChange = QGraphicsItem::ItemVisibleChange, ItemEnabledChange = QGraphicsItem::ItemEnabledChange, ItemSelectedChange = QGraphicsItem::ItemSelectedChange, ItemParentChange = QGraphicsItem::ItemParentChange, ItemChildAddedChange = QGraphicsItem::ItemChildAddedChange, ItemChildRemovedChange = QGraphicsItem::ItemChildRemovedChange, ItemTransformChange = QGraphicsItem::ItemTransformChange, ItemPositionHasChanged = QGraphicsItem::ItemPositionHasChanged, ItemTransformHasChanged = QGraphicsItem::ItemTransformHasChanged, ItemSceneChange = QGraphicsItem::ItemSceneChange, ItemVisibleHasChanged = QGraphicsItem::ItemVisibleHasChanged, ItemEnabledHasChanged = QGraphicsItem::ItemEnabledHasChanged, ItemSelectedHasChanged = QGraphicsItem::ItemSelectedHasChanged, ItemParentHasChanged = QGraphicsItem::ItemParentHasChanged, ItemSceneHasChanged = QGraphicsItem::ItemSceneHasChanged, ItemCursorChange = QGraphicsItem::ItemCursorChange, ItemCursorHasChanged = QGraphicsItem::ItemCursorHasChanged, ItemToolTipChange = QGraphicsItem::ItemToolTipChange, ItemToolTipHasChanged = QGraphicsItem::ItemToolTipHasChanged, ItemFlagsChange = QGraphicsItem::ItemFlagsChange, ItemFlagsHaveChanged = QGraphicsItem::ItemFlagsHaveChanged, ItemZValueChange = QGraphicsItem::ItemZValueChange, ItemZValueHasChanged = QGraphicsItem::ItemZValueHasChanged}; |
|
38 | ItemPositionChange = QGraphicsItem::ItemPositionChange, ItemMatrixChange = QGraphicsItem::ItemMatrixChange, ItemVisibleChange = QGraphicsItem::ItemVisibleChange, ItemEnabledChange = QGraphicsItem::ItemEnabledChange, ItemSelectedChange = QGraphicsItem::ItemSelectedChange, ItemParentChange = QGraphicsItem::ItemParentChange, ItemChildAddedChange = QGraphicsItem::ItemChildAddedChange, ItemChildRemovedChange = QGraphicsItem::ItemChildRemovedChange, ItemTransformChange = QGraphicsItem::ItemTransformChange, ItemPositionHasChanged = QGraphicsItem::ItemPositionHasChanged, ItemTransformHasChanged = QGraphicsItem::ItemTransformHasChanged, ItemSceneChange = QGraphicsItem::ItemSceneChange, ItemVisibleHasChanged = QGraphicsItem::ItemVisibleHasChanged, ItemEnabledHasChanged = QGraphicsItem::ItemEnabledHasChanged, ItemSelectedHasChanged = QGraphicsItem::ItemSelectedHasChanged, ItemParentHasChanged = QGraphicsItem::ItemParentHasChanged, ItemSceneHasChanged = QGraphicsItem::ItemSceneHasChanged, ItemCursorChange = QGraphicsItem::ItemCursorChange, ItemCursorHasChanged = QGraphicsItem::ItemCursorHasChanged, ItemToolTipChange = QGraphicsItem::ItemToolTipChange, ItemToolTipHasChanged = QGraphicsItem::ItemToolTipHasChanged, ItemFlagsChange = QGraphicsItem::ItemFlagsChange, ItemFlagsHaveChanged = QGraphicsItem::ItemFlagsHaveChanged, ItemZValueChange = QGraphicsItem::ItemZValueChange, ItemZValueHasChanged = QGraphicsItem::ItemZValueHasChanged}; | |
39 | public slots: |
|
39 | public slots: | |
|
40 | bool hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; } | |||
|
41 | ||||
40 | void delete_QGraphicsItem(QGraphicsItem* obj) { delete obj; } |
|
42 | void delete_QGraphicsItem(QGraphicsItem* obj) { delete obj; } | |
41 | bool acceptDrops(QGraphicsItem* theWrappedObject) const; |
|
43 | bool acceptDrops(QGraphicsItem* theWrappedObject) const; | |
42 | bool acceptHoverEvents(QGraphicsItem* theWrappedObject) const; |
|
44 | bool acceptHoverEvents(QGraphicsItem* theWrappedObject) const; |
@@ -23,6 +23,8 enum ItemType{ | |||||
23 | enum ChildIndicatorPolicy{ |
|
23 | enum ChildIndicatorPolicy{ | |
24 | ShowIndicator = QTreeWidgetItem::ShowIndicator, DontShowIndicator = QTreeWidgetItem::DontShowIndicator, DontShowIndicatorWhenChildless = QTreeWidgetItem::DontShowIndicatorWhenChildless}; |
|
24 | ShowIndicator = QTreeWidgetItem::ShowIndicator, DontShowIndicator = QTreeWidgetItem::DontShowIndicator, DontShowIndicatorWhenChildless = QTreeWidgetItem::DontShowIndicatorWhenChildless}; | |
25 | public slots: |
|
25 | public slots: | |
|
26 | bool hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; } | |||
|
27 | ||||
26 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type); |
|
28 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type); | |
27 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, const QStringList& strings, int type = Type); |
|
29 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, const QStringList& strings, int type = Type); | |
28 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, int type = Type); |
|
30 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, int type = Type); |
@@ -120,6 +120,11 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c | |||||
120 | s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } "; |
|
120 | s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } "; | |
121 | s << endl; |
|
121 | s << endl; | |
122 | } |
|
122 | } | |
|
123 | if (meta_class->name()=="QTreeWidgetItem") { | |||
|
124 | s << "bool hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; }" << endl; | |||
|
125 | } else if (meta_class->name()=="QGraphicsItem") { | |||
|
126 | s << "bool hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; }" << endl; | |||
|
127 | } | |||
123 |
|
128 | |||
124 | AbstractMetaFunctionList functions = meta_class->queryFunctions( |
|
129 | AbstractMetaFunctionList functions = meta_class->queryFunctions( | |
125 | AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasVisible | AbstractMetaClass::WasPublic |
|
130 | AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasVisible | AbstractMetaClass::WasPublic |
@@ -641,3 +641,19 QObject* PythonQtClassInfo::decorator() | |||||
641 | } |
|
641 | } | |
642 | return _decoratorProvider; |
|
642 | return _decoratorProvider; | |
643 | } |
|
643 | } | |
|
644 | ||||
|
645 | bool PythonQtClassInfo::hasOwnerMethodButNoOwner(void* object) | |||
|
646 | { | |||
|
647 | PythonQtMemberInfo info = member("hasOwner"); | |||
|
648 | if (info._type == PythonQtMemberInfo::Slot) { | |||
|
649 | void* obj = object; | |||
|
650 | bool result = false; | |||
|
651 | void* args[2]; | |||
|
652 | args[0] = &result; | |||
|
653 | args[1] = &obj; | |||
|
654 | info._slot->decorator()->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args); | |||
|
655 | return !result; | |||
|
656 | } else { | |||
|
657 | return false; | |||
|
658 | } | |||
|
659 | } |
@@ -122,6 +122,9 public: | |||||
122 | //! set the parent class name of a wrapped CPP pointer |
|
122 | //! set the parent class name of a wrapped CPP pointer | |
123 | void setWrappedParentClassName(const QByteArray& name) { _wrappedParentClassName = name; _parentClassInfo = NULL; _parentClassInfoResolved = false; } |
|
123 | void setWrappedParentClassName(const QByteArray& name) { _wrappedParentClassName = name; _parentClassInfo = NULL; _parentClassInfoResolved = false; } | |
124 |
|
124 | |||
|
125 | //! check if the special method "hasOwner" is implemented and if it returns false, which means that the object may be destroyed | |||
|
126 | bool hasOwnerMethodButNoOwner(void* object); | |||
|
127 | ||||
125 | private: |
|
128 | private: | |
126 | //! resolve the parent class from either meta object or cpp parent class name |
|
129 | //! resolve the parent class from either meta object or cpp parent class name | |
127 | void resolveParentClassInfo(); |
|
130 | void resolveParentClassInfo(); |
@@ -46,16 +46,17 | |||||
46 | #include "PythonQtClassInfo.h" |
|
46 | #include "PythonQtClassInfo.h" | |
47 | #include "PythonQtConversion.h" |
|
47 | #include "PythonQtConversion.h" | |
48 |
|
48 | |||
49 | static void PythonQtWrapper_deleteObject(PythonQtWrapper* self) { |
|
49 | static void PythonQtWrapper_deleteObject(PythonQtWrapper* self, bool force = false) { | |
50 | if (self->_wrappedPtr) { |
|
|||
51 |
|
|
50 | ||
|
51 | // is this a C++ wrapper? | |||
|
52 | if (self->_wrappedPtr) { | |||
52 | //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1()); |
|
53 | //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1()); | |
53 |
|
54 | |||
54 | PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr); |
|
55 | PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr); | |
55 | // we own our qobject, so we delete it now: |
|
56 | // we own our qobject, so we delete it now: | |
56 | delete self->_obj; |
|
57 | delete self->_obj; | |
57 | self->_obj = NULL; |
|
58 | self->_obj = NULL; | |
58 | if (self->_ownedByPythonQt) { |
|
59 | if (force || self->_info->hasOwnerMethodButNoOwner(self->_wrappedPtr) || self->_ownedByPythonQt) { | |
59 | int type = self->_info->metaTypeId(); |
|
60 | int type = self->_info->metaTypeId(); | |
60 | if (self->_useQMetaTypeDestroy && type>=0) { |
|
61 | if (self->_useQMetaTypeDestroy && type>=0) { | |
61 | // use QMetaType to destroy the object |
|
62 | // use QMetaType to destroy the object | |
@@ -84,8 +85,8 static void PythonQtWrapper_deleteObject(PythonQtWrapper* self) { | |||||
84 | PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy); |
|
85 | PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy); | |
85 | } |
|
86 | } | |
86 | if (self->_obj) { |
|
87 | if (self->_obj) { | |
87 | if (self->_ownedByPythonQt) { |
|
88 | if (force || self->_ownedByPythonQt) { | |
88 | if (!self->_obj->parent()) { |
|
89 | if (force || !self->_obj->parent()) { | |
89 | delete self->_obj; |
|
90 | delete self->_obj; | |
90 | } |
|
91 | } | |
91 | } else { |
|
92 | } else { | |
@@ -138,7 +139,7 static PyObject *PythonQtWrapper_help(PythonQtWrapper* type) | |||||
138 |
|
139 | |||
139 | static PyObject *PythonQtWrapper_delete(PythonQtWrapper * self) |
|
140 | static PyObject *PythonQtWrapper_delete(PythonQtWrapper * self) | |
140 | { |
|
141 | { | |
141 | PythonQtWrapper_deleteObject(self); |
|
142 | PythonQtWrapper_deleteObject(self, true); | |
142 | Py_INCREF(Py_None); |
|
143 | Py_INCREF(Py_None); | |
143 | return Py_None; |
|
144 | return Py_None; | |
144 | } |
|
145 | } |
General Comments 0
You need to be logged in to leave comments.
Login now