aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtGui/glue/qlayout_help_functions.h
blob: cea0b5611b6ee407a7ff92e7f317d16a1cca5d5c (plain)
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
#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=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