aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/libsample/objecttypelayout.cpp
blob: 3fa02917c0c7e7c9ee40ce88aba5e07fda55d786 (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "objecttypelayout.h"

#include <iostream>

void ObjectTypeLayout::addObject(ObjectType *obj)
{
    if (obj->isLayoutType()) {
        auto *l = reinterpret_cast<ObjectTypeLayout*>(obj);
        if (l->parent()) {
            std::cerr << "[WARNING] ObjectTypeLayout::addObject: layout '"
                << l->objectName().cstring() << "' already has a parent.\n";
            return;
        }

        l->setParent(this);

        if (parent() && !parent()->isLayoutType())
            l->reparentChildren(parent());
    }

    m_objects.push_back(obj);
}

std::list<ObjectType*> ObjectTypeLayout::objects() const
{
    return m_objects;
}

void ObjectTypeLayout::reparentChildren(ObjectType *parent)
{
    for (auto *o : m_objects) {
        if (o->isLayoutType())
            reinterpret_cast<ObjectTypeLayout *>(o)->reparentChildren(parent);
        else
            o->setParent(parent);
    }
}