From 74c349e6c6354bba3c7242eb9de2b6bbeb462ecd Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 4 Sep 2019 08:08:13 +0200 Subject: [PATCH] blocking of LayoutRequest events to QskControlPrivate --- src/controls/QskControlPrivate.cpp | 22 +++++++++++++++++----- src/controls/QskControlPrivate.h | 3 +++ src/controls/QskQuickItemPrivate.cpp | 24 +++++++----------------- src/controls/QskQuickItemPrivate.h | 7 ++----- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/controls/QskControlPrivate.cpp b/src/controls/QskControlPrivate.cpp index 265c9278..c981e94a 100644 --- a/src/controls/QskControlPrivate.cpp +++ b/src/controls/QskControlPrivate.cpp @@ -44,6 +44,7 @@ QskControlPrivate::QskControlPrivate() , autoLayoutChildren( false ) , focusPolicy( Qt::NoFocus ) , isWheelEnabled( false ) + , blockLayoutRequestEvents( true ) { } @@ -52,14 +53,25 @@ QskControlPrivate::~QskControlPrivate() delete [] explicitSizeHints; } +void QskControlPrivate::layoutConstraintChanged() +{ + if ( !blockLayoutRequestEvents ) + { + Inherited::layoutConstraintChanged(); + + /* + We don't send further LayoutRequest events until someone + actively requests a layout relevant information + */ + blockLayoutRequestEvents = true; + } +} + void QskControlPrivate::implicitSizeChanged() { - Q_Q( QskControl ); - if ( !q->explicitSizeHint( Qt::PreferredSize ).isValid() ) + if ( !q_func()->explicitSizeHint( Qt::PreferredSize ).isValid() ) { - // when we have no PreferredSize we fall back - // to the implicit size - + // when we have no explit size, the implicit size matters layoutConstraintChanged(); } } diff --git a/src/controls/QskControlPrivate.h b/src/controls/QskControlPrivate.h index 3da5af93..66b89f9b 100644 --- a/src/controls/QskControlPrivate.h +++ b/src/controls/QskControlPrivate.h @@ -35,6 +35,7 @@ class QskControlPrivate : public QskQuickItemPrivate QSizeF implicitSizeHint() const override final; void implicitSizeChanged() override final; + void layoutConstraintChanged() override final; private: Q_DECLARE_PUBLIC( QskControl ) @@ -51,6 +52,8 @@ class QskControlPrivate : public QskQuickItemPrivate uint focusPolicy : 4; bool isWheelEnabled : 1; + + mutable bool blockLayoutRequestEvents : 1; }; #endif diff --git a/src/controls/QskQuickItemPrivate.cpp b/src/controls/QskQuickItemPrivate.cpp index 6bae2311..cedebc49 100644 --- a/src/controls/QskQuickItemPrivate.cpp +++ b/src/controls/QskQuickItemPrivate.cpp @@ -26,7 +26,6 @@ QskQuickItemPrivate::QskQuickItemPrivate() , blockedImplicitSize( true ) , clearPreviousNodes( false ) , isInitiallyPainted( false ) - , blockLayoutRequestEvents( true ) { if ( controlFlags & QskQuickItem::DeferredLayout ) { @@ -55,8 +54,7 @@ QskQuickItemPrivate::~QskQuickItemPrivate() void QskQuickItemPrivate::mirrorChange() { - Q_Q( QskQuickItem ); - qskSendEventTo( q, QEvent::LayoutDirectionChange ); + qskSendEventTo( q_func(), QEvent::LayoutDirectionChange ); } void QskQuickItemPrivate::updateControlFlags( QskQuickItem::Flags flags ) @@ -83,18 +81,8 @@ void QskQuickItemPrivate::updateControlFlags( QskQuickItem::Flags flags ) void QskQuickItemPrivate::layoutConstraintChanged() { - if ( !blockLayoutRequestEvents ) - { - Q_Q( QskQuickItem ); - if ( auto item = q->parentItem() ) - qskSendEventTo( item, QEvent::LayoutRequest ); - - /* - We don't send further LayoutRequest events until someone - actively requests a layout relevant information - */ - blockLayoutRequestEvents = true; - } + if ( auto item = q_func()->parentItem() ) + qskSendEventTo( item, QEvent::LayoutRequest ); } void QskQuickItemPrivate::implicitSizeChanged() @@ -170,8 +158,6 @@ void QskQuickItemPrivate::setImplicitSize( qreal w, qreal h, bool doNotify ) if ( doNotify ) { - // calling implicitSizeChanged only once, TODO ... - if ( doWidth ) Inherited::implicitWidthChanged(); @@ -180,6 +166,10 @@ void QskQuickItemPrivate::setImplicitSize( qreal w, qreal h, bool doNotify ) } } +/* + In case of the application interferes by calling + setImplicitWidth or setImplicitHeight manually: + */ void QskQuickItemPrivate::implicitWidthChanged() { Inherited::implicitWidthChanged(); diff --git a/src/controls/QskQuickItemPrivate.h b/src/controls/QskQuickItemPrivate.h index 8c05fe03..19260d20 100644 --- a/src/controls/QskQuickItemPrivate.h +++ b/src/controls/QskQuickItemPrivate.h @@ -25,9 +25,8 @@ class QskQuickItemPrivate : public QQuickItemPrivate void updateControlFlags( QskQuickItem::Flags ); protected: - void layoutConstraintChanged(); + virtual void layoutConstraintChanged(); virtual void implicitSizeChanged(); - virtual QSizeF implicitSizeHint() const = 0; private: void cleanupNodes(); @@ -42,6 +41,7 @@ class QskQuickItemPrivate : public QQuickItemPrivate void updateImplicitSize( bool doNotify ); void setImplicitSize( qreal width, qreal height, bool doNotify ); + virtual QSizeF implicitSizeHint() const = 0; private: Q_DECLARE_PUBLIC( QskQuickItem ) @@ -56,9 +56,6 @@ class QskQuickItemPrivate : public QQuickItemPrivate bool clearPreviousNodes : 1; bool isInitiallyPainted : 1; - - protected: - mutable bool blockLayoutRequestEvents : 1; }; #endif