For now on, the c++ ownership is mandatory on QLayout family classes.
QLayouts class does not take ownership of widgets, only transfer
ownership to parentWidgets.
If you add a QWidget in a QLayout this widget does not have your
refcount incremented until this layout get a parent QWidget.
Reviewer: Hugo Parente Lima <hugo.lima@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
3c68c1f03f
commit
59ccd4c744
1 changed files with 25 additions and 9 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from sys import getrefcount
|
from sys import getrefcount
|
||||||
|
|
||||||
from PySide.QtGui import QHBoxLayout, QVBoxLayout, QGridLayout
|
from PySide.QtGui import QHBoxLayout, QVBoxLayout, QGridLayout, QWidget
|
||||||
from PySide.QtGui import QStackedLayout, QFormLayout
|
from PySide.QtGui import QStackedLayout, QFormLayout
|
||||||
from PySide.QtGui import QApplication, QPushButton, QLabel
|
from PySide.QtGui import QApplication, QPushButton, QLabel
|
||||||
|
|
||||||
|
|
@ -42,26 +42,41 @@ class SaveReference(UsesQApplication):
|
||||||
# Check if doesn't mess around with previous widget refcount
|
# Check if doesn't mess around with previous widget refcount
|
||||||
self.assertEqual(getrefcount(self.widget1), 3)
|
self.assertEqual(getrefcount(self.widget1), 3)
|
||||||
|
|
||||||
|
def testMoveLayout(self):
|
||||||
|
l = QHBoxLayout()
|
||||||
|
self.assertEqual(getrefcount(self.widget1), 2)
|
||||||
|
l.addWidget(self.widget1)
|
||||||
|
self.assertEqual(getrefcount(self.widget1), 2)
|
||||||
|
|
||||||
|
w = QWidget()
|
||||||
|
w.setLayout(l)
|
||||||
|
self.assertEqual(getrefcount(self.widget1), 3)
|
||||||
|
|
||||||
|
|
||||||
def testHBoxReference(self):
|
def testHBoxReference(self):
|
||||||
#QHBoxLayout.addWidget reference count
|
#QHBoxLayout.addWidget reference count
|
||||||
self.checkLayoutReference(QHBoxLayout())
|
w = QWidget()
|
||||||
|
self.checkLayoutReference(QHBoxLayout(w))
|
||||||
|
|
||||||
def testVBoxReference(self):
|
def testVBoxReference(self):
|
||||||
#QVBoxLayout.addWidget reference count
|
#QVBoxLayout.addWidget reference count
|
||||||
self.checkLayoutReference(QVBoxLayout())
|
w = QWidget()
|
||||||
|
self.checkLayoutReference(QVBoxLayout(w))
|
||||||
|
|
||||||
def testGridReference(self):
|
def testGridReference(self):
|
||||||
#QGridLayout.addWidget reference count
|
#QGridLayout.addWidget reference count
|
||||||
self.checkLayoutReference(QGridLayout())
|
w = QWidget()
|
||||||
|
self.checkLayoutReference(QGridLayout(w))
|
||||||
|
|
||||||
def testFormReference(self):
|
def testFormReference(self):
|
||||||
#QFormLayout.addWidget reference count
|
#QFormLayout.addWidget reference count
|
||||||
self.checkLayoutReference(QFormLayout())
|
w = QWidget()
|
||||||
|
self.checkLayoutReference(QFormLayout(w))
|
||||||
|
|
||||||
def testStackedReference(self):
|
def testStackedReference(self):
|
||||||
#QStackedLayout.addWidget reference count
|
#QStackedLayout.addWidget reference count
|
||||||
self.checkLayoutReference(QStackedLayout())
|
w = QWidget()
|
||||||
|
self.checkLayoutReference(QStackedLayout(w))
|
||||||
|
|
||||||
class MultipleAdd(UsesQApplication):
|
class MultipleAdd(UsesQApplication):
|
||||||
'''Test case to check if refcount is incremented only once when multiple
|
'''Test case to check if refcount is incremented only once when multiple
|
||||||
|
|
@ -73,12 +88,14 @@ class MultipleAdd(UsesQApplication):
|
||||||
#Acquire resources
|
#Acquire resources
|
||||||
super(MultipleAdd, self).setUp()
|
super(MultipleAdd, self).setUp()
|
||||||
self.widget = QPushButton('click me')
|
self.widget = QPushButton('click me')
|
||||||
self.layout = QHBoxLayout()
|
self.win = QWidget()
|
||||||
|
self.layout = QHBoxLayout(self.win)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
#Release resources
|
#Release resources
|
||||||
del self.widget
|
del self.widget
|
||||||
del self.layout
|
del self.layout
|
||||||
|
del self.win
|
||||||
super(MultipleAdd, self).tearDown()
|
super(MultipleAdd, self).tearDown()
|
||||||
|
|
||||||
def testRefCount(self):
|
def testRefCount(self):
|
||||||
|
|
@ -91,6 +108,5 @@ class MultipleAdd(UsesQApplication):
|
||||||
self.layout.addWidget(self.widget)
|
self.layout.addWidget(self.widget)
|
||||||
self.assertEqual(getrefcount(self.widget), 3)
|
self.assertEqual(getrefcount(self.widget), 3)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue