@@ -37,6 +37,8 enum GraphicsItemFlag{ | |||
|
37 | 37 | enum GraphicsItemChange{ |
|
38 | 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 | 39 | public slots: |
|
40 | bool hasOwner(QGraphicsItem* theWrappedObject) { return theWrappedObject->scene()!=NULL || theWrappedObject->parentItem()!=NULL; } | |
|
41 | ||
|
40 | 42 | void delete_QGraphicsItem(QGraphicsItem* obj) { delete obj; } |
|
41 | 43 | bool acceptDrops(QGraphicsItem* theWrappedObject) const; |
|
42 | 44 | bool acceptHoverEvents(QGraphicsItem* theWrappedObject) const; |
@@ -23,6 +23,8 enum ItemType{ | |||
|
23 | 23 | enum ChildIndicatorPolicy{ |
|
24 | 24 | ShowIndicator = QTreeWidgetItem::ShowIndicator, DontShowIndicator = QTreeWidgetItem::DontShowIndicator, DontShowIndicatorWhenChildless = QTreeWidgetItem::DontShowIndicatorWhenChildless}; |
|
25 | 25 | public slots: |
|
26 | bool hasOwner(QTreeWidgetItem* theWrappedObject) { return theWrappedObject->treeWidget()!=NULL || theWrappedObject->parent()!=NULL; } | |
|
27 | ||
|
26 | 28 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, QTreeWidgetItem* after, int type = Type); |
|
27 | 29 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, const QStringList& strings, int type = Type); |
|
28 | 30 | QTreeWidgetItem* new_QTreeWidgetItem(QTreeWidget* view, int type = Type); |
@@ -120,6 +120,11 void ShellHeaderGenerator::write(QTextStream &s, const AbstractMetaClass *meta_c | |||
|
120 | 120 | s << "void delete_" << meta_class->name() << "(" << meta_class->qualifiedCppName() << "* obj) { delete obj; } "; |
|
121 | 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 | 129 | AbstractMetaFunctionList functions = meta_class->queryFunctions( |
|
125 | 130 | AbstractMetaClass::NormalFunctions | AbstractMetaClass::WasVisible | AbstractMetaClass::WasPublic |
@@ -641,3 +641,19 QObject* PythonQtClassInfo::decorator() | |||
|
641 | 641 | } |
|
642 | 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 | 122 | //! set the parent class name of a wrapped CPP pointer |
|
123 | 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 | 128 | private: |
|
126 | 129 | //! resolve the parent class from either meta object or cpp parent class name |
|
127 | 130 | void resolveParentClassInfo(); |
@@ -46,16 +46,17 | |||
|
46 | 46 | #include "PythonQtClassInfo.h" |
|
47 | 47 | #include "PythonQtConversion.h" |
|
48 | 48 | |
|
49 | static void PythonQtWrapper_deleteObject(PythonQtWrapper* self) { | |
|
50 | if (self->_wrappedPtr) { | |
|
49 | static void PythonQtWrapper_deleteObject(PythonQtWrapper* self, bool force = false) { | |
|
51 | 50 |
|
|
51 | // is this a C++ wrapper? | |
|
52 | if (self->_wrappedPtr) { | |
|
52 | 53 | //mlabDebugConst("Python","c++ wrapper removed " << self->_wrappedPtr << " " << self->_obj->className() << " " << self->_info->wrappedClassName().latin1()); |
|
53 | 54 | |
|
54 | 55 | PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr); |
|
55 | 56 | // we own our qobject, so we delete it now: |
|
56 | 57 | delete self->_obj; |
|
57 | 58 | self->_obj = NULL; |
|
58 | if (self->_ownedByPythonQt) { | |
|
59 | if (force || self->_info->hasOwnerMethodButNoOwner(self->_wrappedPtr) || self->_ownedByPythonQt) { | |
|
59 | 60 | int type = self->_info->metaTypeId(); |
|
60 | 61 | if (self->_useQMetaTypeDestroy && type>=0) { |
|
61 | 62 | // use QMetaType to destroy the object |
@@ -84,8 +85,8 static void PythonQtWrapper_deleteObject(PythonQtWrapper* self) { | |||
|
84 | 85 | PythonQt::priv()->removeWrapperPointer(self->_objPointerCopy); |
|
85 | 86 | } |
|
86 | 87 | if (self->_obj) { |
|
87 | if (self->_ownedByPythonQt) { | |
|
88 | if (!self->_obj->parent()) { | |
|
88 | if (force || self->_ownedByPythonQt) { | |
|
89 | if (force || !self->_obj->parent()) { | |
|
89 | 90 | delete self->_obj; |
|
90 | 91 | } |
|
91 | 92 | } else { |
@@ -138,7 +139,7 static PyObject *PythonQtWrapper_help(PythonQtWrapper* type) | |||
|
138 | 139 | |
|
139 | 140 | static PyObject *PythonQtWrapper_delete(PythonQtWrapper * self) |
|
140 | 141 | { |
|
141 | PythonQtWrapper_deleteObject(self); | |
|
142 | PythonQtWrapper_deleteObject(self, true); | |
|
142 | 143 | Py_INCREF(Py_None); |
|
143 | 144 | return Py_None; |
|
144 | 145 | } |
General Comments 0
You need to be logged in to leave comments.
Login now