aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtGui/glue
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-04 16:16:20 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-10-04 17:10:40 -0300
commit7f4e85f6501aa58623244303cdaf6e129c02af4d (patch)
tree02e91e77b7f9dd43cb3df205c937e7d659635892 /PySide/QtGui/glue
parent73fea931819ee1f6a32c50c9d67a9c292e69d45a (diff)
Fixed QWidget setLayout rules.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide/QtGui/glue')
-rw-r--r--PySide/QtGui/glue/qwidget_glue.h30
1 files changed, 23 insertions, 7 deletions
diff --git a/PySide/QtGui/glue/qwidget_glue.h b/PySide/QtGui/glue/qwidget_glue.h
index 948852240..6be651840 100644
--- a/PySide/QtGui/glue/qwidget_glue.h
+++ b/PySide/QtGui/glue/qwidget_glue.h
@@ -17,11 +17,13 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout)
{
QLayoutItem *item = layout->itemAt(i);
QWidget *w = item->widget();
-
if (w)
{
- Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
- Shiboken::setParent(pyParent, pyChild);
+ QWidget* pw = w->parentWidget();
+ if (pw != parent) {
+ Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
+ Shiboken::setParent(pyParent, pyChild);
+ }
}
else
{
@@ -33,7 +35,6 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout)
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(layout));
Shiboken::setParent(pyParent, pyChild);
-
//remove previous references
Shiboken::keepReference(reinterpret_cast<Shiboken::SbkBaseWrapper*>(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None);
}
@@ -41,9 +42,24 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout)
static inline void
qwidgetSetLayout(QWidget *self, QLayout *layout)
{
- if (self->layout())
+ if (!layout || self->layout())
return;
- qwidgetReparentLayout(self, layout);
- self->setLayout(layout);
+ QObject* oldParent = layout->parent();
+ if (oldParent && oldParent != self) {
+ if (oldParent->isWidgetType()) {
+ // remove old parent policy
+ Shiboken::AutoDecRef pyLayout(Shiboken::Converter<QLayout*>::toPython(layout));
+ Shiboken::setParent(Py_None, pyLayout);
+ } else {
+ PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent",
+ qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName()));
+ return;
+ }
+ }
+
+ if (oldParent != self) {
+ qwidgetReparentLayout(self, layout);
+ self->setLayout(layout);
+ }
}