Fixed QMainWindow ownership control.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Hugo Parente Lima <hugo.pl@gmail.com>
This commit is contained in:
parent
da39716cc9
commit
d82b8dbd8d
3 changed files with 21 additions and 5 deletions
|
|
@ -2134,6 +2134,7 @@
|
||||||
<replace from="$FUNCTION_GET_OLD" to="centralWidget" />
|
<replace from="$FUNCTION_GET_OLD" to="centralWidget" />
|
||||||
<replace from="$CHILD_TYPE" to="QWidget" />
|
<replace from="$CHILD_TYPE" to="QWidget" />
|
||||||
<replace from="$PYARG" to="%PYARG_1" />
|
<replace from="$PYARG" to="%PYARG_1" />
|
||||||
|
<replace from="$CPPARG" to="%1" />
|
||||||
</insert-template>
|
</insert-template>
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
|
|
@ -2144,6 +2145,7 @@
|
||||||
<replace from="$FUNCTION_GET_OLD" to="menuBar" />
|
<replace from="$FUNCTION_GET_OLD" to="menuBar" />
|
||||||
<replace from="$CHILD_TYPE" to="QMenuBar" />
|
<replace from="$CHILD_TYPE" to="QMenuBar" />
|
||||||
<replace from="$PYARG" to="%PYARG_1" />
|
<replace from="$PYARG" to="%PYARG_1" />
|
||||||
|
<replace from="$CPPARG" to="%1" />
|
||||||
</insert-template>
|
</insert-template>
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
|
|
@ -2154,6 +2156,7 @@
|
||||||
<replace from="$FUNCTION_GET_OLD" to="menuWidget" />
|
<replace from="$FUNCTION_GET_OLD" to="menuWidget" />
|
||||||
<replace from="$CHILD_TYPE" to="QWidget" />
|
<replace from="$CHILD_TYPE" to="QWidget" />
|
||||||
<replace from="$PYARG" to="%PYARG_1" />
|
<replace from="$PYARG" to="%PYARG_1" />
|
||||||
|
<replace from="$CPPARG" to="%1" />
|
||||||
</insert-template>
|
</insert-template>
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
|
|
@ -2164,6 +2167,7 @@
|
||||||
<replace from="$FUNCTION_GET_OLD" to="statusBar" />
|
<replace from="$FUNCTION_GET_OLD" to="statusBar" />
|
||||||
<replace from="$CHILD_TYPE" to="QStatusBar" />
|
<replace from="$CHILD_TYPE" to="QStatusBar" />
|
||||||
<replace from="$PYARG" to="%PYARG_1" />
|
<replace from="$PYARG" to="%PYARG_1" />
|
||||||
|
<replace from="$CPPARG" to="%1" />
|
||||||
</insert-template>
|
</insert-template>
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,10 @@
|
||||||
<typesystem>
|
<typesystem>
|
||||||
<template name="replace_child">
|
<template name="replace_child">
|
||||||
$CHILD_TYPE* oldChild = %CPPSELF.$FUNCTION_GET_OLD();
|
$CHILD_TYPE* oldChild = %CPPSELF.$FUNCTION_GET_OLD();
|
||||||
if (oldChild) {
|
if (oldChild && (oldChild != $CPPARG)) {
|
||||||
Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[$CHILD_TYPE*](oldChild));
|
Shiboken::AutoDecRef pyChild(%CONVERTTOPYTHON[$CHILD_TYPE*](oldChild));
|
||||||
Shiboken::Object::setParent(NULL, pyChild);
|
Shiboken::Object::setParent(0, pyChild);
|
||||||
|
Shiboken::Object::releaseOwnership(pyChild);
|
||||||
}
|
}
|
||||||
Shiboken::Object::setParent(%PYSELF, $PYARG);
|
Shiboken::Object::setParent(%PYSELF, $PYARG);
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
|
import weakref
|
||||||
|
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
from PySide import QtCore
|
from PySide import QtCore
|
||||||
|
|
@ -34,14 +35,19 @@ class TestMainWindow(UsesQApplication):
|
||||||
QtCore.QTimer.singleShot(1000, self.app.quit)
|
QtCore.QTimer.singleShot(1000, self.app.quit)
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
|
|
||||||
|
def objDel(self, obj):
|
||||||
|
self.app.quit()
|
||||||
|
|
||||||
def testRefCountToNull(self):
|
def testRefCountToNull(self):
|
||||||
w = QtGui.QMainWindow()
|
w = QtGui.QMainWindow()
|
||||||
c = QtGui.QWidget()
|
c = QtGui.QWidget()
|
||||||
self.assertEqual(sys.getrefcount(c), 2)
|
self.assertEqual(sys.getrefcount(c), 2)
|
||||||
w.setCentralWidget(c)
|
w.setCentralWidget(c)
|
||||||
self.assertEqual(sys.getrefcount(c), 3)
|
self.assertEqual(sys.getrefcount(c), 3)
|
||||||
|
wr = weakref.ref(c, self.objDel)
|
||||||
w.setCentralWidget(None)
|
w.setCentralWidget(None)
|
||||||
self.assertEqual(sys.getrefcount(c), 2)
|
c = None
|
||||||
|
self.app.exec_()
|
||||||
|
|
||||||
def testRefCountToAnother(self):
|
def testRefCountToAnother(self):
|
||||||
w = QtGui.QMainWindow()
|
w = QtGui.QMainWindow()
|
||||||
|
|
@ -52,9 +58,14 @@ class TestMainWindow(UsesQApplication):
|
||||||
|
|
||||||
c2 = QtGui.QWidget()
|
c2 = QtGui.QWidget()
|
||||||
w.setCentralWidget(c2)
|
w.setCentralWidget(c2)
|
||||||
self.assertEqual(sys.getrefcount(c), 2)
|
|
||||||
self.assertEqual(sys.getrefcount(c2), 3)
|
self.assertEqual(sys.getrefcount(c2), 3)
|
||||||
|
|
||||||
|
wr = weakref.ref(c, self.objDel)
|
||||||
|
w.setCentralWidget(None)
|
||||||
|
c = None
|
||||||
|
|
||||||
|
self.app.exec_()
|
||||||
|
|
||||||
def testSignalDisconect(self):
|
def testSignalDisconect(self):
|
||||||
w = QtGui.QMainWindow()
|
w = QtGui.QMainWindow()
|
||||||
b = MyButton("button")
|
b = MyButton("button")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue