diff --git a/src/layouts/QskGridBox.cpp b/src/layouts/QskGridBox.cpp index 18d0dbf8..fcd1169e 100644 --- a/src/layouts/QskGridBox.cpp +++ b/src/layouts/QskGridBox.cpp @@ -10,9 +10,6 @@ static void qskSetItemActive( QObject* receiver, const QQuickItem* item, bool on ) { - if ( ( item == nullptr ) || ( qskControlCast( item ) != nullptr ) ) - return; - /* For QQuickItems not being derived from QskControl we manually send QEvent::LayoutRequest events. @@ -32,15 +29,11 @@ static void qskSetItemActive( QObject* receiver, const QQuickItem* item, bool on QObject::connect( item, &QQuickItem::implicitHeightChanged, receiver, sendLayoutRequest ); - - QObject::connect( item, &QQuickItem::visibleChanged, - receiver, sendLayoutRequest ); } else { QObject::disconnect( item, &QQuickItem::implicitWidthChanged, receiver, nullptr ); QObject::disconnect( item, &QQuickItem::implicitHeightChanged, receiver, nullptr ); - QObject::disconnect( item, &QQuickItem::visibleChanged, receiver, nullptr ); } } @@ -92,6 +85,13 @@ QskGridBox::QskGridBox( QQuickItem* parent ) QskGridBox::~QskGridBox() { + auto& engine = m_data->engine; + + for ( int i = 0; i < engine.count(); i++ ) + { + if ( auto item = engine.itemAt( i ) ) + setItemActive( item, false ); + } } int QskGridBox::addItem( QQuickItem* item, @@ -144,7 +144,7 @@ int QskGridBox::addItem( QQuickItem* item, if ( item->parentItem() != this ) item->setParentItem( this ); - qskSetItemActive( this, item, true ); + setItemActive( item, true ); index = engine.insertItem( item, itemGrid ); } @@ -174,7 +174,7 @@ void QskGridBox::removeAt( int index ) auto& engine = m_data->engine; if ( auto item = engine.itemAt( index ) ) - qskSetItemActive( this, item, false ); + setItemActive( item, false ); engine.removeAt( index ); @@ -195,7 +195,7 @@ void QskGridBox::clear( bool autoDelete ) { if ( auto item = itemAtIndex( i ) ) { - qskSetItemActive( this, item, false ); + setItemActive( item, false ); if( autoDelete && ( item->parent() == this ) ) delete item; @@ -352,6 +352,23 @@ void QskGridBox::invalidate() polish(); } +void QskGridBox::setItemActive( QQuickItem* item, bool on ) +{ + if ( on ) + { + QObject::connect( item, &QQuickItem::visibleChanged, + this, &QskGridBox::invalidate ); + } + else + { + QObject::disconnect( item, &QQuickItem::visibleChanged, + this, &QskGridBox::invalidate ); + } + + if ( qskControlCast( item ) == nullptr ) + qskSetItemActive( this, item, on ); +} + void QskGridBox::updateLayout() { if ( !maybeUnresized() ) diff --git a/src/layouts/QskGridBox.h b/src/layouts/QskGridBox.h index e2786457..49ea4821 100644 --- a/src/layouts/QskGridBox.h +++ b/src/layouts/QskGridBox.h @@ -122,6 +122,8 @@ class QSK_EXPORT QskGridBox : public QskBox QSizeF layoutSizeHint( Qt::SizeHint, const QSizeF& ) const override; private: + void setItemActive( QQuickItem*, bool ); + class PrivateData; std::unique_ptr< PrivateData > m_data; }; diff --git a/src/layouts/QskLinearBox.cpp b/src/layouts/QskLinearBox.cpp index 1eee1a8f..9b1aa07b 100644 --- a/src/layouts/QskLinearBox.cpp +++ b/src/layouts/QskLinearBox.cpp @@ -10,9 +10,6 @@ static void qskSetItemActive( QObject* receiver, const QQuickItem* item, bool on ) { - if ( ( item == nullptr ) || ( qskControlCast( item ) != nullptr ) ) - return; - /* For QQuickItems not being derived from QskControl we manually send QEvent::LayoutRequest events. @@ -32,15 +29,11 @@ static void qskSetItemActive( QObject* receiver, const QQuickItem* item, bool on QObject::connect( item, &QQuickItem::implicitHeightChanged, receiver, sendLayoutRequest ); - - QObject::connect( item, &QQuickItem::visibleChanged, - receiver, sendLayoutRequest ); } else { QObject::disconnect( item, &QQuickItem::implicitWidthChanged, receiver, nullptr ); QObject::disconnect( item, &QQuickItem::implicitHeightChanged, receiver, nullptr ); - QObject::disconnect( item, &QQuickItem::visibleChanged, receiver, nullptr ); } } @@ -73,6 +66,13 @@ QskLinearBox::QskLinearBox( Qt::Orientation orientation, uint dimension, QQuickI QskLinearBox::~QskLinearBox() { + auto& engine = m_data->engine; + + for ( int i = 0; i < engine.count(); i++ ) + { + if ( auto item = engine.itemAt( i ) ) + setItemActive( item, false ); + } } int QskLinearBox::count() const @@ -112,7 +112,7 @@ void QskLinearBox::removeItemInternal( int index, bool unparent ) if ( item ) { - qskSetItemActive( this, engine.itemAt( index ), false ); + setItemActive( item, false ); if ( !unparent ) { @@ -144,7 +144,7 @@ void QskLinearBox::clear( bool autoDelete ) if( item ) { - qskSetItemActive( this, item, false ); + setItemActive( item, false ); if( autoDelete && ( item->parent() == this ) ) delete item; @@ -180,6 +180,23 @@ void QskLinearBox::invalidate() polish(); } +void QskLinearBox::setItemActive( QQuickItem* item, bool on ) +{ + if ( on ) + { + QObject::connect( item, &QQuickItem::visibleChanged, + this, &QskLinearBox::invalidate ); + } + else + { + QObject::disconnect( item, &QQuickItem::visibleChanged, + this, &QskLinearBox::invalidate ); + } + + if ( qskControlCast( item ) == nullptr ) + qskSetItemActive( this, item, on ); +} + void QskLinearBox::updateLayout() { if ( !maybeUnresized() ) @@ -435,7 +452,7 @@ int QskLinearBox::insertItem( int index, QQuickItem* item ) item->stackAfter( children.last() ); } - qskSetItemActive( this, item, true ); + setItemActive( item, true ); #if 1 // Is there a way to block consecutive calls ??? diff --git a/src/layouts/QskLinearBox.h b/src/layouts/QskLinearBox.h index 0542c96d..746d8ac5 100644 --- a/src/layouts/QskLinearBox.h +++ b/src/layouts/QskLinearBox.h @@ -114,6 +114,7 @@ class QSK_EXPORT QskLinearBox : public QskIndexedLayoutBox void autoRemoveItem( QQuickItem* ) override final; private: + void setItemActive( QQuickItem*, bool ); void removeItemInternal( int index, bool autoDelete ); class PrivateData;