Fixes QtGui type system to use 'reference-count' tag setModel methods.
Various setModel methods where changed from the incorrect parenting tag to the proper 'reference-count' tag. The return value of QAbstractItemView.model() was defined to have 'default' ownership, otherwise the Qt heuristics from the generator would set the returned pointer as a child belonging to the QAbstractItemView instance. The test case for this was expanded and changed to a more meaningful name. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
This commit is contained in:
parent
fb265bc5c4
commit
16b2d0e370
3 changed files with 92 additions and 47 deletions
|
|
@ -1189,6 +1189,13 @@
|
||||||
</object-type>
|
</object-type>
|
||||||
<object-type name="QAbstractGraphicsShapeItem"/>
|
<object-type name="QAbstractGraphicsShapeItem"/>
|
||||||
<object-type name="QAbstractItemView">
|
<object-type name="QAbstractItemView">
|
||||||
|
<modify-function signature="model() const">
|
||||||
|
<modify-argument index="return">
|
||||||
|
<!-- Defining ownership as "default" avoids the object to be automatically
|
||||||
|
set as parent of the returned pointer. -->
|
||||||
|
<define-ownership class="target" owner="default"/>
|
||||||
|
</modify-argument>
|
||||||
|
</modify-function>
|
||||||
<modify-function signature="setIndexWidget(const QModelIndex &, QWidget *)">
|
<modify-function signature="setIndexWidget(const QModelIndex &, QWidget *)">
|
||||||
<modify-argument index="2">
|
<modify-argument index="2">
|
||||||
<parent index="this" action="add"/>
|
<parent index="this" action="add"/>
|
||||||
|
|
@ -1289,7 +1296,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
|
|
@ -1422,7 +1429,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
|
|
@ -1493,7 +1500,7 @@
|
||||||
<object-type name="QColumnView">
|
<object-type name="QColumnView">
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
||||||
|
|
@ -1842,7 +1849,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
||||||
|
|
@ -1922,7 +1929,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
<modify-function signature="setSelectionModel(QItemSelectionModel*)">
|
||||||
|
|
@ -2703,7 +2710,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModel(QAbstractItemModel *)">
|
<modify-function signature="setModel(QAbstractItemModel *)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setPopup(QAbstractItemView *)">
|
<modify-function signature="setPopup(QAbstractItemView *)">
|
||||||
|
|
@ -3065,7 +3072,7 @@
|
||||||
</extra-includes>
|
</extra-includes>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
|
|
@ -3520,7 +3527,7 @@
|
||||||
<modify-function signature="isItemSelected(const QTableWidgetItem*)const" remove="all"/>
|
<modify-function signature="isItemSelected(const QTableWidgetItem*)const" remove="all"/>
|
||||||
<modify-function signature="setModel(QAbstractItemModel*)">
|
<modify-function signature="setModel(QAbstractItemModel*)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="mimeData(const QList<QTableWidgetItem*>)const" remove="all"/>
|
<modify-function signature="mimeData(const QList<QTableWidgetItem*>)const" remove="all"/>
|
||||||
|
|
@ -3773,7 +3780,7 @@
|
||||||
<modify-function signature="setModel(QAbstractItemModel *)">
|
<modify-function signature="setModel(QAbstractItemModel *)">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<no-null-pointer/>
|
<no-null-pointer/>
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="activated(int)">>
|
<modify-function signature="activated(int)">>
|
||||||
|
|
@ -4253,7 +4260,7 @@
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="setModelData(QWidget*,QAbstractItemModel*,QModelIndex)const">
|
<modify-function signature="setModelData(QWidget*,QAbstractItemModel*,QModelIndex)const">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<parent index="this" action="add"/>
|
<reference-count action="add"/>
|
||||||
</modify-argument>
|
</modify-argument>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
</object-type>
|
</object-type>
|
||||||
|
|
|
||||||
75
tests/qtgui/keep_reference_test.py
Executable file
75
tests/qtgui/keep_reference_test.py
Executable file
|
|
@ -0,0 +1,75 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from sys import getrefcount
|
||||||
|
from helper import UsesQApplication
|
||||||
|
from PySide.QtCore import QAbstractTableModel, QVariant
|
||||||
|
from PySide.QtGui import QTableView
|
||||||
|
|
||||||
|
class TestModel(QAbstractTableModel):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QAbstractTableModel.__init__(self, parent)
|
||||||
|
def rowCount(self, parent):
|
||||||
|
return 0
|
||||||
|
def columnCount(self, parent):
|
||||||
|
return 0
|
||||||
|
def data(self, index, role):
|
||||||
|
return QVariant()
|
||||||
|
|
||||||
|
class KeepReferenceTest(UsesQApplication):
|
||||||
|
|
||||||
|
def testModelWithoutParent(self):
|
||||||
|
view = QTableView()
|
||||||
|
model = TestModel()
|
||||||
|
view.setModel(model)
|
||||||
|
samemodel = view.model()
|
||||||
|
self.assertEqual(model, samemodel)
|
||||||
|
|
||||||
|
def testModelWithParent(self):
|
||||||
|
view = QTableView()
|
||||||
|
model = TestModel(self.app)
|
||||||
|
view.setModel(model)
|
||||||
|
samemodel = view.model()
|
||||||
|
self.assertEqual(model, samemodel)
|
||||||
|
|
||||||
|
def testReferenceCounting(self):
|
||||||
|
'''Tests reference count of model object referred by view objects.'''
|
||||||
|
model1 = TestModel()
|
||||||
|
refcount1 = getrefcount(model1)
|
||||||
|
view1 = QTableView()
|
||||||
|
view1.setModel(model1)
|
||||||
|
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
|
||||||
|
|
||||||
|
view2 = QTableView()
|
||||||
|
view2.setModel(model1)
|
||||||
|
self.assertEqual(getrefcount(view2.model()), refcount1 + 2)
|
||||||
|
|
||||||
|
model2 = TestModel()
|
||||||
|
view2.setModel(model2)
|
||||||
|
self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
|
||||||
|
|
||||||
|
def testReferenceCountingWhenDeletingReferrer(self):
|
||||||
|
'''Tests reference count of model object referred by deceased view object.'''
|
||||||
|
model = TestModel()
|
||||||
|
refcount1 = getrefcount(model)
|
||||||
|
view = QTableView()
|
||||||
|
view.setModel(model)
|
||||||
|
self.assertEqual(getrefcount(view.model()), refcount1 + 1)
|
||||||
|
|
||||||
|
del view
|
||||||
|
self.assertEqual(getrefcount(model), refcount1)
|
||||||
|
|
||||||
|
def testReferreedObjectSurvivalAfterContextEnd(self):
|
||||||
|
'''Model object assigned to a view object must survive after getting out of context.'''
|
||||||
|
def createModelAndSetToView(view):
|
||||||
|
model = TestModel()
|
||||||
|
model.setObjectName('created model')
|
||||||
|
view.setModel(model)
|
||||||
|
view = QTableView()
|
||||||
|
createModelAndSetToView(view)
|
||||||
|
model = view.model()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from helper import UsesQApplication
|
|
||||||
from PySide.QtCore import QAbstractTableModel, QVariant
|
|
||||||
from PySide.QtGui import QTableView
|
|
||||||
|
|
||||||
class TestModel(QAbstractTableModel):
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
QAbstractTableModel.__init__(self, parent)
|
|
||||||
def rowCount(self, parent):
|
|
||||||
return 0
|
|
||||||
def columnCount(self, parent):
|
|
||||||
return 0
|
|
||||||
def data(self, index, role):
|
|
||||||
return QVariant()
|
|
||||||
|
|
||||||
class ParentPolicyTest(UsesQApplication):
|
|
||||||
|
|
||||||
def testModelWithoutParent(self):
|
|
||||||
view = QTableView()
|
|
||||||
model = TestModel()
|
|
||||||
view.setModel(model)
|
|
||||||
samemodel = view.model()
|
|
||||||
self.assertEqual(model, samemodel)
|
|
||||||
|
|
||||||
def testModelWithParent(self):
|
|
||||||
view = QTableView()
|
|
||||||
model = TestModel(self.app)
|
|
||||||
view.setModel(model)
|
|
||||||
samemodel = view.model()
|
|
||||||
self.assertEqual(model, samemodel)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue