diff --git a/examples/layouts/StackLayoutPage.cpp b/examples/layouts/StackLayoutPage.cpp index 59d10f98..5132eaa9 100644 --- a/examples/layouts/StackLayoutPage.cpp +++ b/examples/layouts/StackLayoutPage.cpp @@ -35,7 +35,7 @@ namespace for ( int i = 0; i < itemCount(); i += 2 ) { - if ( auto control = qobject_cast< QskControl* >( itemAtIndex( i ) ) ) + if ( auto control = qskControlCast( itemAtIndex( i ) ) ) control->setFixedSize( 200, 200 ); } } diff --git a/src/controls/QskControl.cpp b/src/controls/QskControl.cpp index b157cac0..d3b2c461 100644 --- a/src/controls/QskControl.cpp +++ b/src/controls/QskControl.cpp @@ -1965,9 +1965,9 @@ QSizeF QskControl::contentsSizeHint() const const auto children = childItems(); for ( const auto child : children ) { - if ( auto* control = qobject_cast< const QskControl* >( child ) ) + if ( auto control = qskControlCast( child ) ) { - if ( !QQuickItemPrivate::get( control )->isTransparentForPositioner() ) + if ( !control->isTransparentForPositioner() ) { const QSizeF hint = control->sizeHint(); diff --git a/src/controls/QskControl.h b/src/controls/QskControl.h index 79054e2b..8f58b835 100644 --- a/src/controls/QskControl.h +++ b/src/controls/QskControl.h @@ -313,6 +313,16 @@ inline QSizeF QskControl::preferredSize() const return explicitSizeHint( Qt::PreferredSize ); } +inline QskControl* qskControlCast( QObject* object ) +{ + return qobject_cast< QskControl* >( object ); +} + +inline const QskControl* qskControlCast( const QObject* object ) +{ + return qobject_cast< const QskControl* >( object ); +} + Q_DECLARE_OPERATORS_FOR_FLAGS( QskControl::Flags ) Q_DECLARE_METATYPE( QskControl::Flags ) diff --git a/src/controls/QskDirtyItemFilter.cpp b/src/controls/QskDirtyItemFilter.cpp index 0b9052ab..672b14ba 100644 --- a/src/controls/QskDirtyItemFilter.cpp +++ b/src/controls/QskDirtyItemFilter.cpp @@ -15,7 +15,7 @@ static inline bool qskIsUpdateBlocked( const QQuickItem* item ) { if ( !item->isVisible() ) { - if ( const auto control = qobject_cast< const QskControl* >( item ) ) + if ( const auto control = qskControlCast( item ) ) return control->testControlFlag( QskControl::DeferredUpdate ); } @@ -25,7 +25,7 @@ static inline bool qskIsUpdateBlocked( const QQuickItem* item ) but we have not yet found a performant way to send update notifications when an item enters/leaves the window. TODO ... */ - else if ( const auto control = qobject_cast< const QskControl* >( item ) ) + else if ( const auto control = qskControlCast( item ) ) { const QRectF itemRect( item->mapToScene( QPointF() ), item->size() ); const QRectF sceneRect( 0, 0, item->window()->width(), item->window()->height() ); diff --git a/src/controls/QskFocusIndicator.cpp b/src/controls/QskFocusIndicator.cpp index d966860e..522ffe71 100644 --- a/src/controls/QskFocusIndicator.cpp +++ b/src/controls/QskFocusIndicator.cpp @@ -14,7 +14,7 @@ QSK_SUBCONTROL( QskFocusIndicator, Panel ) static inline QRectF qskFocusIndicatorRect( const QQuickItem* item ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) return control->focusIndicatorRect(); const QVariant v = item->property( "focusIndicatorRect" ); @@ -216,7 +216,7 @@ QVector< QMetaObject::Connection > QskFocusIndicator::connectItem( const QQuickI c += QObject::connect( sender, &QQuickItem::heightChanged, this, method ); c += QObject::connect( sender, &QQuickItem::visibleChanged, this, method ); - if ( const auto control = qobject_cast< const QskControl* >( sender ) ) + if ( const auto control = qskControlCast( sender ) ) { c += QObject::connect( control, &QskControl::focusIndicatorRectChanged, this, method ); } diff --git a/src/controls/QskQuick.cpp b/src/controls/QskQuick.cpp index 7c1cb3df..4d4278f7 100644 --- a/src/controls/QskQuick.cpp +++ b/src/controls/QskQuick.cpp @@ -29,7 +29,7 @@ QRectF qskItemGeometry( const QQuickItem* item ) void qskSetItemGeometry( QQuickItem* item, const QRectF& rect ) { - if ( auto control = qobject_cast< QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) { control->setGeometry( rect ); } diff --git a/src/controls/QskSetup.cpp b/src/controls/QskSetup.cpp index 0716f89f..31941613 100644 --- a/src/controls/QskSetup.cpp +++ b/src/controls/QskSetup.cpp @@ -276,7 +276,7 @@ void QskSetup::inheritLocale( QObject* object, const QLocale& locale ) bool QskSetup::eventFilter( QObject* object, QEvent* event ) { - if ( auto control = qobject_cast< QskControl* >( object ) ) + if ( auto control = qskControlCast( object ) ) { /* Qt::FocusPolicy has always been there with widgets, got lost with diff --git a/src/controls/QskSkinTransition.cpp b/src/controls/QskSkinTransition.cpp index b1cbd8b4..5b217909 100644 --- a/src/controls/QskSkinTransition.cpp +++ b/src/controls/QskSkinTransition.cpp @@ -260,7 +260,7 @@ namespace if ( !item->isVisible() ) return; - if ( auto control = qobject_cast< QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) { if ( control->isInitiallyPainted() && ( skin == control->effectiveSkin() ) ) { diff --git a/src/controls/QskWindow.cpp b/src/controls/QskWindow.cpp index 3f3bc080..cddece5b 100644 --- a/src/controls/QskWindow.cpp +++ b/src/controls/QskWindow.cpp @@ -409,10 +409,10 @@ QSize QskWindow::effectivePreferredSize() const const bool doWidth = constraint.width() < 0; const bool doHeight = constraint.height() < 0; - const QList< QQuickItem* > children = contentItem()->childItems(); + const auto children = contentItem()->childItems(); for ( auto child : children ) { - if ( QskControl* control = qobject_cast< QskControl* >( child ) ) + if ( auto control = qskControlCast( child ) ) { const QSizeF itemConstraint = control->sizeHint(); if ( doWidth ) diff --git a/src/dialogs/QskDialogSubWindow.cpp b/src/dialogs/QskDialogSubWindow.cpp index 56815948..ff37d03d 100644 --- a/src/dialogs/QskDialogSubWindow.cpp +++ b/src/dialogs/QskDialogSubWindow.cpp @@ -458,7 +458,7 @@ QSizeF QskDialogSubWindow::contentsSizeHint() const h = hint.height(); } - if ( auto* control = qobject_cast< const QskControl* >( m_data->contentItem ) ) + if ( auto* control = qskControlCast( m_data->contentItem ) ) { const auto hint = control->sizeHint(); diff --git a/src/layouts/QskLayoutBox.cpp b/src/layouts/QskLayoutBox.cpp index 447485bd..48cbcde2 100644 --- a/src/layouts/QskLayoutBox.cpp +++ b/src/layouts/QskLayoutBox.cpp @@ -42,8 +42,7 @@ void QskLayoutBox::setActive( bool on ) for ( int i = 0; i < itemCount(); ++i ) { - QQuickItem* item = itemAtIndex( i ); - if ( item ) + if( auto item = itemAtIndex( i ) ) setItemActive( item, on ); } @@ -66,8 +65,7 @@ int QskLayoutBox::itemCount() const QQuickItem* QskLayoutBox::itemAtIndex( int index ) const { - QskLayoutItem* layoutItem = m_data->engine.layoutItemAt( index ); - if ( layoutItem ) + if ( auto layoutItem = m_data->engine.layoutItemAt( index ) ) return layoutItem->item(); return nullptr; @@ -85,12 +83,12 @@ void QskLayoutBox::insertItemInternal( QskLayoutItem* layoutItem, int index ) { // check if item is already inserted ??? - QQuickItem* item = layoutItem->item(); + auto item = layoutItem->item(); if ( index > itemCount() ) index = -1; // append - QskLayoutEngine& engine = this->engine(); + auto& engine = this->engine(); if ( item ) { @@ -142,9 +140,9 @@ void QskLayoutBox::insertItemInternal( QskLayoutItem* layoutItem, int index ) void QskLayoutBox::removeAt( int index ) { - QskLayoutEngine& engine = this->engine(); + auto& engine = this->engine(); - QskLayoutItem* layoutItem = engine.layoutItemAt( index ); + auto layoutItem = engine.layoutItemAt( index ); if ( layoutItem == nullptr ) return; @@ -303,7 +301,7 @@ void QskLayoutBox::setItemActive( const QQuickItem* item, bool on ) // QskControl sends QEvent::LayoutRequest - const bool hasLayoutRequests = qobject_cast< const QskControl* >( item ); + const bool hasLayoutRequests = qskControlCast( item ); if ( !hasLayoutRequests ) { if ( on ) diff --git a/src/layouts/QskLayoutConstraint.cpp b/src/layouts/QskLayoutConstraint.cpp index 0685bf1f..58ad250f 100644 --- a/src/layouts/QskLayoutConstraint.cpp +++ b/src/layouts/QskLayoutConstraint.cpp @@ -56,10 +56,9 @@ static inline qreal qskAdjustedValue( return value; } - bool QskLayoutConstraint::hasDynamicConstraint( const QQuickItem* item ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) { const auto& policy = control->sizePolicy(); return ( policy.horizontalPolicy() == QskSizePolicy::Constrained ) || @@ -72,7 +71,7 @@ bool QskLayoutConstraint::hasDynamicConstraint( const QQuickItem* item ) qreal QskLayoutConstraint::heightForWidth( const QQuickItem* item, qreal width ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) return control->heightForWidth( width ); return qskHintFor( item, "heightForWidth", width ); @@ -80,7 +79,7 @@ qreal QskLayoutConstraint::heightForWidth( const QQuickItem* item, qreal width ) qreal QskLayoutConstraint::widthForHeight( const QQuickItem* item, qreal height ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) return control->widthForHeight( height ); return qskHintFor( item, "widthForHeight", height ); @@ -89,7 +88,7 @@ qreal QskLayoutConstraint::widthForHeight( const QQuickItem* item, qreal height QSizeF QskLayoutConstraint::effectiveConstraint( const QQuickItem* item, Qt::SizeHint whichHint ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) return control->effectiveSizeHint( whichHint ); QSizeF constraint( -1.0, -1.0 ); // no hint @@ -149,7 +148,7 @@ QskSizePolicy QskLayoutConstraint::sizePolicy( const QQuickItem* item ) { if ( item ) { - if ( auto control = qobject_cast< const QskControl* >( item ) ) + if ( auto control = qskControlCast( item ) ) return control->sizePolicy(); const QVariant v = item->property( "sizePolicy" ); diff --git a/src/layouts/QskLayoutItem.cpp b/src/layouts/QskLayoutItem.cpp index d4927370..0f80d067 100644 --- a/src/layouts/QskLayoutItem.cpp +++ b/src/layouts/QskLayoutItem.cpp @@ -212,7 +212,7 @@ Qt::Orientation QskLayoutItem::dynamicConstraintOrientation() const { Qt::Orientation orientation = Qt::Vertical; - if ( auto control = qobject_cast< const QskControl* >( m_item ) ) + if ( auto control = qskControlCast( m_item ) ) { const auto policy = control->sizePolicy().horizontalPolicy();