diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index e8a938629..3f1b7b2c3 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -37,6 +37,21 @@ #include #include +static QPersistentModelIndex +findLayout( const KeyboardLayoutModel* klm, const QString& currentLayout ) +{ + QPersistentModelIndex currentLayoutItem; + + for ( int i = 0; i < klm->rowCount(); ++i ) + { + QModelIndex idx = klm->index( i ); + if ( idx.isValid() && + idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout ) + currentLayoutItem = idx; + } + + return currentLayoutItem; +} KeyboardPage::KeyboardPage( QWidget* parent ) : QWidget() @@ -160,14 +175,13 @@ KeyboardPage::init() // Block signals ui->listLayout->blockSignals( true ); - QPersistentModelIndex currentLayoutItem; - - for ( int i = 0; i < klm->rowCount(); ++i ) + QPersistentModelIndex currentLayoutItem = findLayout( klm, currentLayout ); + if ( !currentLayoutItem.isValid() && ( + ( currentLayout == "latin" ) + || ( currentLayout == "pc" ) ) ) { - QModelIndex idx = klm->index( i ); - if ( idx.isValid() && - idx.data( KeyboardLayoutModel::KeyboardLayoutKeyRole ).toString() == currentLayout ) - currentLayoutItem = idx; + currentLayout = "us"; + currentLayoutItem = findLayout( klm, currentLayout ); } // Set current layout and variant @@ -341,4 +355,3 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi m_selectedLayout = layout; m_selectedVariant = variant; } -