Fix setLayout method that was causing segfault when itemAt wasn't implemented.
Reviewer: Hugo Parente <hugo.lima@openbossa.org>
Renato Araújo <renato.filho@openbossa.org>
This commit is contained in:
parent
5a8efeb9df
commit
16913eedce
4 changed files with 43 additions and 12 deletions
|
|
@ -28,7 +28,7 @@ inline void addLayoutOwnership(QLayout* layout, QWidget* widget)
|
||||||
|
|
||||||
inline void addLayoutOwnership(QLayout* layout, QLayout* other)
|
inline void addLayoutOwnership(QLayout* layout, QLayout* other)
|
||||||
{
|
{
|
||||||
//transfer all children widgetes from other to layout parent widget
|
//transfer all children widgets from other to layout parent widget
|
||||||
QWidget* parent = layout->parentWidget();
|
QWidget* parent = layout->parentWidget();
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
//keep the reference while the layout is orphan
|
//keep the reference while the layout is orphan
|
||||||
|
|
@ -39,7 +39,11 @@ inline void addLayoutOwnership(QLayout* layout, QLayout* other)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0, i_max=other->count(); i < i_max; i++) {
|
for (int i=0, i_max=other->count(); i < i_max; i++) {
|
||||||
addLayoutOwnership(layout, other->itemAt(i));
|
QLayoutItem* item = layout->itemAt(i);
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
|
addLayoutOwnership(layout, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QLayout*>::toPython(layout));
|
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QLayout*>::toPython(layout));
|
||||||
|
|
|
||||||
|
|
@ -12,20 +12,19 @@ static inline void qwidgetReparentLayout(QWidget *parent, QLayout *layout)
|
||||||
{
|
{
|
||||||
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(parent));
|
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(parent));
|
||||||
|
|
||||||
for (int i=0; i < layout->count(); i++)
|
for (int i=0; i < layout->count(); i++) {
|
||||||
{
|
|
||||||
QLayoutItem* item = layout->itemAt(i);
|
QLayoutItem* item = layout->itemAt(i);
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
QWidget* w = item->widget();
|
QWidget* w = item->widget();
|
||||||
if (w)
|
if (w) {
|
||||||
{
|
|
||||||
QWidget* pw = w->parentWidget();
|
QWidget* pw = w->parentWidget();
|
||||||
if (pw != parent) {
|
if (pw != parent) {
|
||||||
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
|
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
|
||||||
Shiboken::setParent(pyParent, pyChild);
|
Shiboken::setParent(pyParent, pyChild);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
QLayout* l = item->layout();
|
QLayout* l = item->layout();
|
||||||
if (l)
|
if (l)
|
||||||
qwidgetReparentLayout(parent, l);
|
qwidgetReparentLayout(parent, l);
|
||||||
|
|
@ -58,6 +57,9 @@ static inline void qwidgetSetLayout(QWidget *self, QLayout *layout)
|
||||||
|
|
||||||
if (oldParent != self) {
|
if (oldParent != self) {
|
||||||
qwidgetReparentLayout(self, layout);
|
qwidgetReparentLayout(self, layout);
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return;
|
||||||
|
|
||||||
self->setLayout(layout);
|
self->setLayout(layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3371,6 +3371,7 @@
|
||||||
<modify-function signature="setLayout(QLayout *)">
|
<modify-function signature="setLayout(QLayout *)">
|
||||||
<inject-code class="target" position="beginning">
|
<inject-code class="target" position="beginning">
|
||||||
qwidgetSetLayout(%CPPSELF, %1);
|
qwidgetSetLayout(%CPPSELF, %1);
|
||||||
|
// %FUNCTION_NAME() - disable generation of function call.
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
<modify-function signature="enabledChange(bool)" remove="all"/>
|
<modify-function signature="enabledChange(bool)" remove="all"/>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,22 @@ class MyLayout(QLayout):
|
||||||
def add(self, item):
|
def add(self, item):
|
||||||
self._list.append(item)
|
self._list.append(item)
|
||||||
|
|
||||||
|
class MissingItemAtLayout(QLayout):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QLayout.__init__(self, parent)
|
||||||
|
self._list = []
|
||||||
|
|
||||||
|
def addItem(self, item):
|
||||||
|
self.add(item)
|
||||||
|
|
||||||
|
def addWidget(self, widget):
|
||||||
|
self.add(QWidgetItem(widget))
|
||||||
|
|
||||||
|
def count(self):
|
||||||
|
return len(self._list)
|
||||||
|
|
||||||
|
def add(self, item):
|
||||||
|
self._list.append(item)
|
||||||
|
|
||||||
#Test if a layout implemented in python, the QWidget.setLayout works
|
#Test if a layout implemented in python, the QWidget.setLayout works
|
||||||
#fine because this implement som layout functions used in glue code of
|
#fine because this implement som layout functions used in glue code of
|
||||||
|
|
@ -71,5 +86,14 @@ class QLayoutTest(UsesQApplication):
|
||||||
|
|
||||||
self.assertEqual(sys.getrefcount(b), 2)
|
self.assertEqual(sys.getrefcount(b), 2)
|
||||||
|
|
||||||
|
def testMissingFunctions(self):
|
||||||
|
w = QWidget()
|
||||||
|
b = QPushButton("test")
|
||||||
|
l = MissingItemAtLayout()
|
||||||
|
|
||||||
|
l.addWidget(b)
|
||||||
|
|
||||||
|
self.assertRaises(RuntimeError, w.setLayout, l)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue