QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskIndexedLayoutBox.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskIndexedLayoutBox.h"
7#include "QskQuick.h"
8
9class QskIndexedLayoutBox::PrivateData
10{
11 public:
12 PrivateData()
13 : autoAddChildren( true )
14 , blockChildAddedRemoved( false )
15 {
16 }
17
18 bool autoAddChildren : 1;
19 bool blockChildAddedRemoved : 1;
20};
21
23 : QskBox( false, parent )
24 , m_data( new PrivateData() )
25{
26 // classBegin/componentComplete -> setActive( false/true ) ?
27}
28
32
34{
35 if ( on != m_data->autoAddChildren )
36 {
37 m_data->autoAddChildren = on;
39 }
40}
41
43{
44 return m_data->autoAddChildren;
45}
46
48 QQuickItem::ItemChange change, const QQuickItem::ItemChangeData& value )
49{
50 switch ( change )
51 {
52 case QQuickItem::ItemChildAddedChange:
53 {
54 if ( m_data->autoAddChildren && !m_data->blockChildAddedRemoved )
55 {
56 if ( qskPlacementPolicy( value.item ).isEffective() )
57 autoAddItem( value.item );
58 }
59
60 break;
61 }
62 case QQuickItem::ItemChildRemovedChange:
63 {
64 if ( !m_data->blockChildAddedRemoved )
65 autoRemoveItem( value.item );
66
67 break;
68 }
69#if 1
70 case QQuickItem::ItemSceneChange:
71 {
72 // when changing the window we should run into polish anyway
73 if ( value.window )
74 polish();
75
76 break;
77 }
78#endif
79
80 default:
81 {
82 break;
83 }
84 }
85
86 Inherited::itemChange( change, value );
87}
88
89void QskIndexedLayoutBox::reparentItem( QQuickItem* item )
90{
91 if ( item->parent() == nullptr )
92 item->setParent( this );
93
94 if ( item->parentItem() != this )
95 {
96 m_data->blockChildAddedRemoved = true;
97 item->setParentItem( this );
98 m_data->blockChildAddedRemoved = false;
99 }
100}
101
102void QskIndexedLayoutBox::unparentItem( QQuickItem* item )
103{
104 if ( item->parentItem() == this )
105 {
106 m_data->blockChildAddedRemoved = true;
107 item->setParentItem( nullptr );
108 m_data->blockChildAddedRemoved = false;
109 }
110}
111
112#include "moc_QskIndexedLayoutBox.cpp"
void itemChange(ItemChange, const ItemChangeData &) override
void itemChange(ItemChange, const ItemChangeData &) override
void setAutoAddChildren(bool on=true)
En/Disable auto appending of children.
QskIndexedLayoutBox(QQuickItem *parent=nullptr)
Constructor.
bool autoAddChildren
Flag controlling whether to automatically append children to the layout.
~QskIndexedLayoutBox() override
Destructor.
void autoAddChildrenChanged()
constexpr bool isEffective() const noexcept