1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#ifndef QLAYOUT_HELP_FUNCTIONS
#define QLAYOUT_HELP_FUNCTIONS
void addLayoutOwnership(QLayout* layout, QLayoutItem* item);
inline QByteArray retrieveObjectName(PyObject* obj)
{
Shiboken::AutoDecRef objName(PyObject_Str(obj));
return PyString_AsString(objName);
}
inline void addLayoutOwnership(QLayout* layout, QWidget* widget)
{
//transfer ownership to parent widget
QWidget* parent = layout->parentWidget();
if (!parent) {
//keep the reference while the layout is orphan
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(layout));
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(widget));
Shiboken::keepReference(reinterpret_cast<SbkObject*>(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true);
} else {
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) {
//keep the reference while the layout is orphan
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QLayout*>::toPython(layout));
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(other));
Shiboken::keepReference(reinterpret_cast<SbkObject*>(pyParent.object()), retrieveObjectName(pyParent).data(), pyChild, true);
return;
}
for (int i=0, i_max=other->count(); i < i_max; i++) {
addLayoutOwnership(layout, other->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
|