From b1f56594bc4995a63a7195809b7d6e3c3d4bfae1 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Sun, 23 Jun 2019 12:53:38 +0200 Subject: [PATCH] QskControl::maybeUnresized() added --- src/controls/QskControl.cpp | 41 ++++++++++++++++++++++++++++++++---- src/controls/QskControl.h | 7 ++---- src/controls/QskTabView.cpp | 3 +++ src/layouts/QskGridBox.cpp | 3 ++- src/layouts/QskLinearBox.cpp | 4 ++-- src/layouts/QskStackBox.cpp | 3 +++ 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index 01899f36..17c408a9 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -210,7 +210,9 @@ class QskControlPrivate final : public QQuickItemPrivate #if 0 // can we do something useful with overloading ??? + QSGTransformNode* createTransformNode() override; + void transformChanged() override; #endif void implicitWidthChanged() override; @@ -227,12 +229,13 @@ class QskControlPrivate final : public QQuickItemPrivate sizeof( QQuickItemPrivate::ExtraData ) -> 184 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( 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 is heavy simply because of deriving from QQuickItem. So without patching Qt the only way to limit the memory footprint of an application @@ -1648,6 +1651,26 @@ void QskControl::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() { Inherited::releaseResources(); @@ -1847,7 +1870,7 @@ void QskControl::updatePolish() d->blockedPolish = false; - if ( d->autoLayoutChildren ) + if ( d->autoLayoutChildren && !maybeUnresized() ) { const QRectF rect = layoutRect(); @@ -1951,6 +1974,16 @@ QskControl* QskControl::owningControl() const 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 { const QRectF r( 0.0, 0.0, size.width(), size.height() ); diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index 82111ce4..90015314 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -260,6 +260,8 @@ class QSK_EXPORT QskControl : public QQuickItem, public QskSkinnable virtual void aboutToShow(); // called in updatePolish virtual void updateLayout(); // called in updatePolish + bool maybeUnresized() const; + private: // don't use boundingRect - it seems to be deprecated QRectF boundingRect() const override final { return rect(); } @@ -322,11 +324,6 @@ inline QSizeF QskControl::preferredSize() const return explicitSizeHint( Qt::PreferredSize ); } -inline QRectF QskControl::layoutRect() const -{ - return layoutRectForSize( size() ); -} - inline QskControl* qskControlCast( QObject* object ) { return qobject_cast< QskControl* >( object ); diff --git a/src/controls/QskTabView.cpp b/src/controls/QskTabView.cpp index 8cfd3bb5..17bcf5c6 100644 --- a/src/controls/QskTabView.cpp +++ b/src/controls/QskTabView.cpp @@ -246,6 +246,9 @@ bool QskTabView::event( QEvent* event ) void QskTabView::updateLayout() { + if ( maybeUnresized() ) + return; + m_data->tabBar->setGeometry( subControlRect( TabBar ) ); #if 1 diff --git a/src/layouts/QskGridBox.cpp b/src/layouts/QskGridBox.cpp index 7ca49191..691bd9dd 100644 --- a/src/layouts/QskGridBox.cpp +++ b/src/layouts/QskGridBox.cpp @@ -404,7 +404,8 @@ void QskGridBox::invalidate() void QskGridBox::updateLayout() { - m_data->engine.setGeometries( layoutRect() ); + if ( !maybeUnresized() ) + m_data->engine.setGeometries( layoutRect() ); } QSizeF QskGridBox::contentsSizeHint() const diff --git a/src/layouts/QskLinearBox.cpp b/src/layouts/QskLinearBox.cpp index a04dd137..9bd72397 100644 --- a/src/layouts/QskLinearBox.cpp +++ b/src/layouts/QskLinearBox.cpp @@ -198,7 +198,8 @@ void QskLinearBox::invalidate() void QskLinearBox::updateLayout() { - m_data->engine.setGeometries( layoutRect() ); + if ( !maybeUnresized() ) + m_data->engine.setGeometries( layoutRect() ); } QSizeF QskLinearBox::contentsSizeHint() const @@ -479,7 +480,6 @@ void QskLinearBox::insertItem( item->stackAfter( children.last() ); } - qskSetItemActive( this, item, true ); #if 1 diff --git a/src/layouts/QskStackBox.cpp b/src/layouts/QskStackBox.cpp index 5eb1d6c4..46c7be3e 100644 --- a/src/layouts/QskStackBox.cpp +++ b/src/layouts/QskStackBox.cpp @@ -408,6 +408,9 @@ QRectF QskStackBox::geometryForItemAt( int index ) const void QskStackBox::updateLayout() { + if ( maybeUnresized() ) + return; + const auto idx = m_data->currentIndex; if ( idx >= 0 )