From fc63f316b45c79f8532c37d9bf0a7c468e11161d Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Tue, 20 Mar 2018 14:57:29 +0100 Subject: [PATCH] focus tab chain update fixed, when re-inserting am item at the end, that had already been inserted before --- examples/layouts/TestRectangle.cpp | 1 + src/layouts/QskLayout.cpp | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/layouts/TestRectangle.cpp b/examples/layouts/TestRectangle.cpp index 60d094f6..71d59307 100644 --- a/examples/layouts/TestRectangle.cpp +++ b/examples/layouts/TestRectangle.cpp @@ -17,4 +17,5 @@ TestRectangle::TestRectangle( const char* colorName, QQuickItem* parent ): setPreferredSize( 10, 10 ); setSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Minimum ); + setFocusPolicy( Qt::TabFocus ); // for checking the focus tab chain } diff --git a/src/layouts/QskLayout.cpp b/src/layouts/QskLayout.cpp index bbaa5cb5..d7c824ef 100644 --- a/src/layouts/QskLayout.cpp +++ b/src/layouts/QskLayout.cpp @@ -104,17 +104,33 @@ void QskLayout::insertItemInternal( QskLayoutItem* layoutItem, int index ) if ( item->parentItem() != this ) item->setParentItem( this ); - if ( index >= 0 ) - { - // to have a proper focus tab chain + /* + Re-ordering the child items to have a a proper focus tab chain + */ + bool reordered = false; + + if ( ( index >= 0 ) && ( index < itemCount() - 1 ) ) + { for ( int i = index; i < engine.itemCount(); i++ ) { - QskLayoutItem* layoutItem = engine.layoutItemAt( index ); + auto layoutItem = engine.layoutItemAt( i ); if ( layoutItem && 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 );