removeItem fixed

This commit is contained in:
Uwe Rathmann 2019-12-03 17:21:56 +01:00
parent 90c515be42
commit 49eb15da83
6 changed files with 31 additions and 23 deletions

View File

@ -11,12 +11,12 @@ class QskIndexedLayoutBox::PrivateData
public: public:
PrivateData() PrivateData()
: autoAddChildren( true ) : autoAddChildren( true )
, blockChildAdded( false ) , blockChildAddedRemoved( false )
{ {
} }
bool autoAddChildren : 1; bool autoAddChildren : 1;
bool blockChildAdded : 1; bool blockChildAddedRemoved : 1;
}; };
QskIndexedLayoutBox::QskIndexedLayoutBox( QQuickItem* parent ) QskIndexedLayoutBox::QskIndexedLayoutBox( QQuickItem* parent )
@ -51,7 +51,7 @@ void QskIndexedLayoutBox::itemChange(
{ {
case QQuickItem::ItemChildAddedChange: case QQuickItem::ItemChildAddedChange:
{ {
if ( m_data->autoAddChildren && !m_data->blockChildAdded ) if ( m_data->autoAddChildren && !m_data->blockChildAddedRemoved )
{ {
if ( !qskIsTransparentForPositioner( value.item ) ) if ( !qskIsTransparentForPositioner( value.item ) )
autoAddItem( value.item ); autoAddItem( value.item );
@ -61,7 +61,9 @@ void QskIndexedLayoutBox::itemChange(
} }
case QQuickItem::ItemChildRemovedChange: case QQuickItem::ItemChildRemovedChange:
{ {
if ( !m_data->blockChildAddedRemoved )
autoRemoveItem( value.item ); autoRemoveItem( value.item );
break; break;
} }
#if 1 #if 1
@ -91,9 +93,19 @@ void QskIndexedLayoutBox::reparentItem( QQuickItem* item )
if ( item->parentItem() != this ) if ( item->parentItem() != this )
{ {
m_data->blockChildAdded = true; m_data->blockChildAddedRemoved = true;
item->setParentItem( this ); item->setParentItem( this );
m_data->blockChildAdded = false; m_data->blockChildAddedRemoved = false;
}
}
void QskIndexedLayoutBox::unparentItem( QQuickItem* item )
{
if ( item->parentItem() == this )
{
m_data->blockChildAddedRemoved = true;
item->setParentItem( nullptr );
m_data->blockChildAddedRemoved = false;
} }
} }

View File

@ -29,7 +29,9 @@ class QSK_EXPORT QskIndexedLayoutBox : public QskBox
protected: protected:
void itemChange( ItemChange, const ItemChangeData& ) override; void itemChange( ItemChange, const ItemChangeData& ) override;
void reparentItem( QQuickItem* ); void reparentItem( QQuickItem* );
void unparentItem( QQuickItem* );
private: private:
virtual void autoAddItem( QQuickItem* ) = 0; virtual void autoAddItem( QQuickItem* ) = 0;

View File

@ -97,7 +97,7 @@ int QskLinearBox::indexOf( const QQuickItem* item ) const
void QskLinearBox::removeAt( int index ) void QskLinearBox::removeAt( int index )
{ {
removeItemInternal( index, false ); removeItemInternal( index, true );
} }
void QskLinearBox::removeItemInternal( int index, bool unparent ) void QskLinearBox::removeItemInternal( int index, bool unparent )
@ -114,11 +114,8 @@ void QskLinearBox::removeItemInternal( int index, bool unparent )
{ {
setItemActive( item, false ); setItemActive( item, false );
if ( !unparent ) if ( unparent )
{ unparentItem( item );
if ( item->parentItem() == this )
item->setParentItem( nullptr );
}
} }
resetImplicitSize(); resetImplicitSize();
@ -149,7 +146,7 @@ void QskLinearBox::clear( bool autoDelete )
if( autoDelete && ( item->parent() == this ) ) if( autoDelete && ( item->parent() == this ) )
delete item; delete item;
else else
item->setParentItem( nullptr ); unparentItem( item );
} }
} }
@ -164,7 +161,7 @@ void QskLinearBox::autoAddItem( QQuickItem* item )
void QskLinearBox::autoRemoveItem( QQuickItem* item ) void QskLinearBox::autoRemoveItem( QQuickItem* item )
{ {
removeItemInternal( indexOf( item ), true ); removeItemInternal( indexOf( item ), false );
} }
void QskLinearBox::activate() void QskLinearBox::activate()

View File

@ -117,7 +117,7 @@ class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox
void autoRemoveItem( QQuickItem* ) override final; void autoRemoveItem( QQuickItem* ) override final;
void setItemActive( QQuickItem*, bool ); void setItemActive( QQuickItem*, bool );
void removeItemInternal( int index, bool autoDelete ); void removeItemInternal( int index, bool unparent );
class PrivateData; class PrivateData;
std::unique_ptr< PrivateData > m_data; std::unique_ptr< PrivateData > m_data;

View File

@ -253,7 +253,7 @@ void QskStackBox::insertItem(
void QskStackBox::removeAt( int index ) void QskStackBox::removeAt( int index )
{ {
removeItemInternal( index, false ); removeItemInternal( index, true );
} }
void QskStackBox::removeItemInternal( int index, bool unparent ) void QskStackBox::removeItemInternal( int index, bool unparent )
@ -261,13 +261,10 @@ void QskStackBox::removeItemInternal( int index, bool unparent )
if ( index < 0 || index >= m_data->items.count() ) if ( index < 0 || index >= m_data->items.count() )
return; return;
if ( !unparent ) if ( unparent )
{ {
if ( auto item = m_data->items[ index ] ) if ( auto item = m_data->items[ index ] )
{ unparentItem( item );
if ( item->parentItem() == this )
item->setParentItem( nullptr );
}
} }
m_data->items.removeAt( index ); m_data->items.removeAt( index );
@ -291,7 +288,7 @@ void QskStackBox::autoAddItem( QQuickItem* item )
void QskStackBox::autoRemoveItem( QQuickItem* item ) void QskStackBox::autoRemoveItem( QQuickItem* item )
{ {
removeItemInternal( indexOf( item ), true ); removeItemInternal( indexOf( item ), false );
} }
void QskStackBox::clear( bool autoDelete ) void QskStackBox::clear( bool autoDelete )

View File

@ -81,7 +81,7 @@ class QSK_EXPORT QskStackBox : public QskIndexedLayoutBox
void autoAddItem( QQuickItem* ) override final; void autoAddItem( QQuickItem* ) override final;
void autoRemoveItem( QQuickItem* ) override final; void autoRemoveItem( QQuickItem* ) override final;
void removeItemInternal( int index, bool autoDelete ); void removeItemInternal( int index, bool unparent );
class PrivateData; class PrivateData;
std::unique_ptr< PrivateData > m_data; std::unique_ptr< PrivateData > m_data;