QskControl::maybeUnresized() added

This commit is contained in:
Uwe Rathmann 2019-06-23 12:53:38 +02:00
parent 309106965d
commit b1f56594bc
6 changed files with 49 additions and 12 deletions

View File

@ -210,7 +210,9 @@ class QskControlPrivate final : public QQuickItemPrivate
#if 0 #if 0
// can we do something useful with overloading ??? // can we do something useful with overloading ???
QSGTransformNode* createTransformNode() override; QSGTransformNode* createTransformNode() override;
void transformChanged() override;
#endif #endif
void implicitWidthChanged() override; void implicitWidthChanged() override;
@ -227,12 +229,13 @@ class QskControlPrivate final : public QQuickItemPrivate
sizeof( QQuickItemPrivate::ExtraData ) -> 184 sizeof( QQuickItemPrivate::ExtraData ) -> 184
sizeof( QQuickItemPrivate ) -> 320 sizeof( QQuickItemPrivate ) -> 320
( these numbers include pointers to optional extra data, but not
the size for the extra data. So the effective memory footprint,
is often even worse ).
sizeof( QskControlPrivate ) -> sizeof( QQuickItemPrivate ) + 32 sizeof( QskControlPrivate ) -> sizeof( QQuickItemPrivate ) + 32
sizeof( QskSkinnable::PrivateData ) -> 40 sizeof( QskSkinnable::PrivateData ) -> 40
( these numbers include pointers to optional extra data, that might
increase the effective memory footprint, when being accurate ).
It might be possible to save some bytes, but in the end QskControl It might be possible to save some bytes, but in the end QskControl
is heavy simply because of deriving from QQuickItem. So without is heavy simply because of deriving from QQuickItem. So without
patching Qt the only way to limit the memory footprint of an application patching Qt the only way to limit the memory footprint of an application
@ -1648,6 +1651,26 @@ void QskControl::componentComplete()
Inherited::componentComplete(); Inherited::componentComplete();
} }
bool QskControl::maybeUnresized() const
{
Q_D( const QskControl );
if ( d->width <= 0.0 && d->height <= 0.0 )
{
/*
Unfortunately the list of items to-be-polished is not processed
in top/down order and we might run into updatePolish() before
having a proper size. But when the parentItem() is waiting
for to-be-polished, we assume, that we will be resized then
and run into another updatePolish() then.
*/
if ( d->polishOnResize && qskIsPolishScheduled( parentItem() ) )
return true;
}
return false;
}
void QskControl::releaseResources() void QskControl::releaseResources()
{ {
Inherited::releaseResources(); Inherited::releaseResources();
@ -1847,7 +1870,7 @@ void QskControl::updatePolish()
d->blockedPolish = false; d->blockedPolish = false;
if ( d->autoLayoutChildren ) if ( d->autoLayoutChildren && !maybeUnresized() )
{ {
const QRectF rect = layoutRect(); const QRectF rect = layoutRect();
@ -1951,6 +1974,16 @@ QskControl* QskControl::owningControl() const
return const_cast< QskControl* >( this ); return const_cast< QskControl* >( this );
} }
QRectF QskControl::layoutRect() const
{
Q_D( const QskControl );
if ( d->width <= 0.0 && d->height <= 0.0 )
return QRectF();
return layoutRectForSize( size() );
}
QRectF QskControl::layoutRectForSize( const QSizeF& size ) const QRectF QskControl::layoutRectForSize( const QSizeF& size ) const
{ {
const QRectF r( 0.0, 0.0, size.width(), size.height() ); const QRectF r( 0.0, 0.0, size.width(), size.height() );

View File

@ -260,6 +260,8 @@ class QSK_EXPORT QskControl : public QQuickItem, public QskSkinnable
virtual void aboutToShow(); // called in updatePolish virtual void aboutToShow(); // called in updatePolish
virtual void updateLayout(); // called in updatePolish virtual void updateLayout(); // called in updatePolish
bool maybeUnresized() const;
private: private:
// don't use boundingRect - it seems to be deprecated // don't use boundingRect - it seems to be deprecated
QRectF boundingRect() const override final { return rect(); } QRectF boundingRect() const override final { return rect(); }
@ -322,11 +324,6 @@ inline QSizeF QskControl::preferredSize() const
return explicitSizeHint( Qt::PreferredSize ); return explicitSizeHint( Qt::PreferredSize );
} }
inline QRectF QskControl::layoutRect() const
{
return layoutRectForSize( size() );
}
inline QskControl* qskControlCast( QObject* object ) inline QskControl* qskControlCast( QObject* object )
{ {
return qobject_cast< QskControl* >( object ); return qobject_cast< QskControl* >( object );

View File

@ -246,6 +246,9 @@ bool QskTabView::event( QEvent* event )
void QskTabView::updateLayout() void QskTabView::updateLayout()
{ {
if ( maybeUnresized() )
return;
m_data->tabBar->setGeometry( subControlRect( TabBar ) ); m_data->tabBar->setGeometry( subControlRect( TabBar ) );
#if 1 #if 1

View File

@ -404,7 +404,8 @@ void QskGridBox::invalidate()
void QskGridBox::updateLayout() void QskGridBox::updateLayout()
{ {
m_data->engine.setGeometries( layoutRect() ); if ( !maybeUnresized() )
m_data->engine.setGeometries( layoutRect() );
} }
QSizeF QskGridBox::contentsSizeHint() const QSizeF QskGridBox::contentsSizeHint() const

View File

@ -198,7 +198,8 @@ void QskLinearBox::invalidate()
void QskLinearBox::updateLayout() void QskLinearBox::updateLayout()
{ {
m_data->engine.setGeometries( layoutRect() ); if ( !maybeUnresized() )
m_data->engine.setGeometries( layoutRect() );
} }
QSizeF QskLinearBox::contentsSizeHint() const QSizeF QskLinearBox::contentsSizeHint() const
@ -479,7 +480,6 @@ void QskLinearBox::insertItem(
item->stackAfter( children.last() ); item->stackAfter( children.last() );
} }
qskSetItemActive( this, item, true ); qskSetItemActive( this, item, true );
#if 1 #if 1

View File

@ -408,6 +408,9 @@ QRectF QskStackBox::geometryForItemAt( int index ) const
void QskStackBox::updateLayout() void QskStackBox::updateLayout()
{ {
if ( maybeUnresized() )
return;
const auto idx = m_data->currentIndex; const auto idx = m_data->currentIndex;
if ( idx >= 0 ) if ( idx >= 0 )