invalidation on changes of visisbility added

This commit is contained in:
Uwe Rathmann 2019-09-14 15:40:20 +02:00
parent 4c156706a5
commit 1e733c4e5c
4 changed files with 57 additions and 20 deletions

View File

@ -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() )

View File

@ -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;
};

View File

@ -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 ???

View File

@ -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;