diff options
author | Renato Filho <renato.filho@openbossa.org> | 2010-04-19 17:57:08 -0300 |
---|---|---|
committer | Renato Filho <renato.filho@openbossa.org> | 2010-04-22 18:21:52 -0300 |
commit | 1ec8bf6f1e745eea07c450b24dd1e6f6fb60f7db (patch) | |
tree | 5b1e62a0d5a6d5dd52968a79db79ea7a27c16693 /PySide/QtGui/glue | |
parent | 2c937c64420c414a33f76c8df8f1f72592469576 (diff) |
Fixed QLayout family return policy.
Reviewer: Hugo Parente Lima <hugo.lima@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide/QtGui/glue')
-rw-r--r-- | PySide/QtGui/glue/qlayout_help_functions.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/PySide/QtGui/glue/qlayout_help_functions.h b/PySide/QtGui/glue/qlayout_help_functions.h new file mode 100644 index 000000000..186e0ecd2 --- /dev/null +++ b/PySide/QtGui/glue/qlayout_help_functions.h @@ -0,0 +1,51 @@ +#ifndef QLAYOUT_HELP_FUNCTIONS +#define QLAYOUT_HELP_FUNCTIONS + +void addLayoutOwnership(QLayout *layout, QLayoutItem *item); + +inline void addLayoutOwnership(QLayout *layout, QWidget *widget) +{ + //transfer ownership to parent widget + QWidget *parent = layout->parentWidget(); + if (!parent) + return; + + Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(parent)); + Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(widget)); + Shiboken::setParent(pyParent, pyChild); +} + +inline void addLayoutOwnership(QLayout *layout, QLayout *other) +{ + //transfer all children widgetes from other to layout parent widget + QWidget *parent = layout->parentWidget(); + if (!parent) + return; + + for (int i=0, i_max=layout->count(); i < i_max; i++) { + addLayoutOwnership(layout, layout->itemAt(i)); + } + + Shiboken::AutoDecRef pyParent(Shiboken::Converter<QLayout*>::toPython(layout)); + Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(other)); + Shiboken::setParent(pyParent, pyChild); + +} + +inline void addLayoutOwnership(QLayout *layout, QLayoutItem *item) +{ + QWidget *w = item->widget(); + if (w) + addLayoutOwnership(layout, w); + else { + QLayout *l = item->layout(); + if (l) + addLayoutOwnership(layout, l); + } + + Shiboken::AutoDecRef pyParent(Shiboken::Converter<QLayout*>::toPython(layout)); + Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayoutItem*>::toPython(item)); + Shiboken::setParent(pyParent, pyChild); +} + +#endif |