focus tab chain update fixed, when re-inserting am item at the end, that had already been

inserted before
This commit is contained in:
Uwe Rathmann 2018-03-20 14:57:29 +01:00
parent c88ae44687
commit fc63f316b4
2 changed files with 21 additions and 4 deletions

View File

@ -17,4 +17,5 @@ TestRectangle::TestRectangle( const char* colorName, QQuickItem* parent ):
setPreferredSize( 10, 10 ); setPreferredSize( 10, 10 );
setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum ); setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum );
setFocusPolicy( Qt::TabFocus ); // for checking the focus tab chain
} }

View File

@ -104,17 +104,33 @@ void QskLayout::insertItemInternal( QskLayoutItem* layoutItem, int index )
if ( item->parentItem() != this ) if ( item->parentItem() != this )
item->setParentItem( this ); item->setParentItem( this );
if ( index >= 0 ) /*
{ Re-ordering the child items to have a a proper focus tab chain
// to have a proper focus tab chain */
bool reordered = false;
if ( ( index >= 0 ) && ( index < itemCount() - 1 ) )
{
for ( int i = index; i < engine.itemCount(); i++ ) for ( int i = index; i < engine.itemCount(); i++ )
{ {
QskLayoutItem* layoutItem = engine.layoutItemAt( index ); auto layoutItem = engine.layoutItemAt( i );
if ( layoutItem && layoutItem->item() ) if ( layoutItem && layoutItem->item() )
{
item->stackBefore( layoutItem->item() ); item->stackBefore( layoutItem->item() );
reordered = true;
break;
}
} }
} }
if ( !reordered )
{
const auto children = childItems();
if ( item != children.last() )
item->stackAfter( children.last() );
}
} }
engine.insertLayoutItem( layoutItem, index ); engine.insertLayoutItem( layoutItem, index );