qskControlCast added

This commit is contained in:
Uwe Rathmann 2019-04-26 11:56:09 +02:00
parent 91c16e8076
commit 98a7fff0a4
13 changed files with 36 additions and 29 deletions

View File

@ -35,7 +35,7 @@ namespace
for ( int i = 0; i < itemCount(); i += 2 ) 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 ); control->setFixedSize( 200, 200 );
} }
} }

View File

@ -1965,9 +1965,9 @@ QSizeF QskControl::contentsSizeHint() const
const auto children = childItems(); const auto children = childItems();
for ( const auto child : children ) 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(); const QSizeF hint = control->sizeHint();

View File

@ -313,6 +313,16 @@ inline QSizeF QskControl::preferredSize() const
return explicitSizeHint( Qt::PreferredSize ); 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_OPERATORS_FOR_FLAGS( QskControl::Flags )
Q_DECLARE_METATYPE( QskControl::Flags ) Q_DECLARE_METATYPE( QskControl::Flags )

View File

@ -15,7 +15,7 @@ static inline bool qskIsUpdateBlocked( const QQuickItem* item )
{ {
if ( !item->isVisible() ) if ( !item->isVisible() )
{ {
if ( const auto control = qobject_cast< const QskControl* >( item ) ) if ( const auto control = qskControlCast( item ) )
return control->testControlFlag( QskControl::DeferredUpdate ); 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 but we have not yet found a performant way to send update notifications
when an item enters/leaves the window. TODO ... 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 itemRect( item->mapToScene( QPointF() ), item->size() );
const QRectF sceneRect( 0, 0, item->window()->width(), item->window()->height() ); const QRectF sceneRect( 0, 0, item->window()->width(), item->window()->height() );

View File

@ -14,7 +14,7 @@ QSK_SUBCONTROL( QskFocusIndicator, Panel )
static inline QRectF qskFocusIndicatorRect( const QQuickItem* item ) static inline QRectF qskFocusIndicatorRect( const QQuickItem* item )
{ {
if ( auto control = qobject_cast< const QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
return control->focusIndicatorRect(); return control->focusIndicatorRect();
const QVariant v = item->property( "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::heightChanged, this, method );
c += QObject::connect( sender, &QQuickItem::visibleChanged, 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 ); c += QObject::connect( control, &QskControl::focusIndicatorRectChanged, this, method );
} }

View File

@ -29,7 +29,7 @@ QRectF qskItemGeometry( const QQuickItem* item )
void qskSetItemGeometry( QQuickItem* item, const QRectF& rect ) void qskSetItemGeometry( QQuickItem* item, const QRectF& rect )
{ {
if ( auto control = qobject_cast< QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
{ {
control->setGeometry( rect ); control->setGeometry( rect );
} }

View File

@ -276,7 +276,7 @@ void QskSetup::inheritLocale( QObject* object, const QLocale& locale )
bool QskSetup::eventFilter( QObject* object, QEvent* event ) 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 Qt::FocusPolicy has always been there with widgets, got lost with

View File

@ -260,7 +260,7 @@ namespace
if ( !item->isVisible() ) if ( !item->isVisible() )
return; return;
if ( auto control = qobject_cast< QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
{ {
if ( control->isInitiallyPainted() && ( skin == control->effectiveSkin() ) ) if ( control->isInitiallyPainted() && ( skin == control->effectiveSkin() ) )
{ {

View File

@ -409,10 +409,10 @@ QSize QskWindow::effectivePreferredSize() const
const bool doWidth = constraint.width() < 0; const bool doWidth = constraint.width() < 0;
const bool doHeight = constraint.height() < 0; const bool doHeight = constraint.height() < 0;
const QList< QQuickItem* > children = contentItem()->childItems(); const auto children = contentItem()->childItems();
for ( auto child : children ) for ( auto child : children )
{ {
if ( QskControl* control = qobject_cast< QskControl* >( child ) ) if ( auto control = qskControlCast( child ) )
{ {
const QSizeF itemConstraint = control->sizeHint(); const QSizeF itemConstraint = control->sizeHint();
if ( doWidth ) if ( doWidth )

View File

@ -458,7 +458,7 @@ QSizeF QskDialogSubWindow::contentsSizeHint() const
h = hint.height(); 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(); const auto hint = control->sizeHint();

View File

@ -42,8 +42,7 @@ void QskLayoutBox::setActive( bool on )
for ( int i = 0; i < itemCount(); ++i ) for ( int i = 0; i < itemCount(); ++i )
{ {
QQuickItem* item = itemAtIndex( i ); if( auto item = itemAtIndex( i ) )
if ( item )
setItemActive( item, on ); setItemActive( item, on );
} }
@ -66,8 +65,7 @@ int QskLayoutBox::itemCount() const
QQuickItem* QskLayoutBox::itemAtIndex( int index ) const QQuickItem* QskLayoutBox::itemAtIndex( int index ) const
{ {
QskLayoutItem* layoutItem = m_data->engine.layoutItemAt( index ); if ( auto layoutItem = m_data->engine.layoutItemAt( index ) )
if ( layoutItem )
return layoutItem->item(); return layoutItem->item();
return nullptr; return nullptr;
@ -85,12 +83,12 @@ void QskLayoutBox::insertItemInternal( QskLayoutItem* layoutItem, int index )
{ {
// check if item is already inserted ??? // check if item is already inserted ???
QQuickItem* item = layoutItem->item(); auto item = layoutItem->item();
if ( index > itemCount() ) if ( index > itemCount() )
index = -1; // append index = -1; // append
QskLayoutEngine& engine = this->engine(); auto& engine = this->engine();
if ( item ) if ( item )
{ {
@ -142,9 +140,9 @@ void QskLayoutBox::insertItemInternal( QskLayoutItem* layoutItem, int index )
void QskLayoutBox::removeAt( 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 ) if ( layoutItem == nullptr )
return; return;
@ -303,7 +301,7 @@ void QskLayoutBox::setItemActive( const QQuickItem* item, bool on )
// QskControl sends QEvent::LayoutRequest // QskControl sends QEvent::LayoutRequest
const bool hasLayoutRequests = qobject_cast< const QskControl* >( item ); const bool hasLayoutRequests = qskControlCast( item );
if ( !hasLayoutRequests ) if ( !hasLayoutRequests )
{ {
if ( on ) if ( on )

View File

@ -56,10 +56,9 @@ static inline qreal qskAdjustedValue(
return value; return value;
} }
bool QskLayoutConstraint::hasDynamicConstraint( const QQuickItem* item ) bool QskLayoutConstraint::hasDynamicConstraint( const QQuickItem* item )
{ {
if ( auto control = qobject_cast< const QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
{ {
const auto& policy = control->sizePolicy(); const auto& policy = control->sizePolicy();
return ( policy.horizontalPolicy() == QskSizePolicy::Constrained ) || return ( policy.horizontalPolicy() == QskSizePolicy::Constrained ) ||
@ -72,7 +71,7 @@ bool QskLayoutConstraint::hasDynamicConstraint( const QQuickItem* item )
qreal QskLayoutConstraint::heightForWidth( const QQuickItem* item, qreal width ) 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 control->heightForWidth( width );
return qskHintFor( item, "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 ) 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 control->widthForHeight( height );
return qskHintFor( item, "widthForHeight", height ); return qskHintFor( item, "widthForHeight", height );
@ -89,7 +88,7 @@ qreal QskLayoutConstraint::widthForHeight( const QQuickItem* item, qreal height
QSizeF QskLayoutConstraint::effectiveConstraint( QSizeF QskLayoutConstraint::effectiveConstraint(
const QQuickItem* item, Qt::SizeHint whichHint ) const QQuickItem* item, Qt::SizeHint whichHint )
{ {
if ( auto control = qobject_cast< const QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
return control->effectiveSizeHint( whichHint ); return control->effectiveSizeHint( whichHint );
QSizeF constraint( -1.0, -1.0 ); // no hint QSizeF constraint( -1.0, -1.0 ); // no hint
@ -149,7 +148,7 @@ QskSizePolicy QskLayoutConstraint::sizePolicy( const QQuickItem* item )
{ {
if ( item ) if ( item )
{ {
if ( auto control = qobject_cast< const QskControl* >( item ) ) if ( auto control = qskControlCast( item ) )
return control->sizePolicy(); return control->sizePolicy();
const QVariant v = item->property( "sizePolicy" ); const QVariant v = item->property( "sizePolicy" );

View File

@ -212,7 +212,7 @@ Qt::Orientation QskLayoutItem::dynamicConstraintOrientation() const
{ {
Qt::Orientation orientation = Qt::Vertical; 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(); const auto policy = control->sizePolicy().horizontalPolicy();