aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-04-22 16:18:23 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-04-22 18:22:22 -0300
commit59ccd4c744de0c3c41015a80798e31e8481df5b0 (patch)
treec983007a3f0057d1e0d5bae4aeb736bd0bb8ba3f /tests
parent3c68c1f03f14f233f11dc2918192078a36efd276 (diff)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/qtgui/qlayout_ref_test.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/tests/qtgui/qlayout_ref_test.py b/tests/qtgui/qlayout_ref_test.py
index a8e924f14..a6342718d 100644
--- a/tests/qtgui/qlayout_ref_test.py
+++ b/tests/qtgui/qlayout_ref_test.py
@@ -4,7 +4,7 @@
import unittest
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 QApplication, QPushButton, QLabel
@@ -42,26 +42,41 @@ class SaveReference(UsesQApplication):
# Check if doesn't mess around with previous widget refcount
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):
#QHBoxLayout.addWidget reference count
- self.checkLayoutReference(QHBoxLayout())
+ w = QWidget()
+ self.checkLayoutReference(QHBoxLayout(w))
def testVBoxReference(self):
#QVBoxLayout.addWidget reference count
- self.checkLayoutReference(QVBoxLayout())
+ w = QWidget()
+ self.checkLayoutReference(QVBoxLayout(w))
def testGridReference(self):
#QGridLayout.addWidget reference count
- self.checkLayoutReference(QGridLayout())
+ w = QWidget()
+ self.checkLayoutReference(QGridLayout(w))
def testFormReference(self):
#QFormLayout.addWidget reference count
- self.checkLayoutReference(QFormLayout())
+ w = QWidget()
+ self.checkLayoutReference(QFormLayout(w))
def testStackedReference(self):
#QStackedLayout.addWidget reference count
- self.checkLayoutReference(QStackedLayout())
-
+ w = QWidget()
+ self.checkLayoutReference(QStackedLayout(w))
class MultipleAdd(UsesQApplication):
'''Test case to check if refcount is incremented only once when multiple
@@ -73,12 +88,14 @@ class MultipleAdd(UsesQApplication):
#Acquire resources
super(MultipleAdd, self).setUp()
self.widget = QPushButton('click me')
- self.layout = QHBoxLayout()
+ self.win = QWidget()
+ self.layout = QHBoxLayout(self.win)
def tearDown(self):
#Release resources
del self.widget
del self.layout
+ del self.win
super(MultipleAdd, self).tearDown()
def testRefCount(self):
@@ -91,6 +108,5 @@ class MultipleAdd(UsesQApplication):
self.layout.addWidget(self.widget)
self.assertEqual(getrefcount(self.widget), 3)
-
if __name__ == '__main__':
unittest.main()