From fdfe3937e92531a5911734c67d7fffbe6d364b76 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Nov 2020 14:50:21 +0100 Subject: [PATCH] [keyboard] Tell the keyboard preview to update on config changes These calls to setLayout() and setVariant() got lost in the transition to Config object, in 5afe5413. Reported by Harald Sitter. --- src/modules/keyboard/KeyboardLayoutModel.cpp | 10 ++++++++ src/modules/keyboard/KeyboardLayoutModel.h | 7 ++++++ src/modules/keyboard/KeyboardPage.cpp | 25 ++++++++++++-------- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/modules/keyboard/KeyboardLayoutModel.cpp b/src/modules/keyboard/KeyboardLayoutModel.cpp index 8b5906699..8a7664d97 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.cpp +++ b/src/modules/keyboard/KeyboardLayoutModel.cpp @@ -198,6 +198,16 @@ KeyboardLayoutModel::item( const int& index ) const return m_layouts.at( index ); } +QString +KeyboardLayoutModel::key( int index ) const +{ + if ( index >= m_layouts.count() || index < 0 ) + { + return QString(); + } + return m_layouts.at( index ).first; +} + void KeyboardLayoutModel::init() { diff --git a/src/modules/keyboard/KeyboardLayoutModel.h b/src/modules/keyboard/KeyboardLayoutModel.h index 99b204573..c2306c001 100644 --- a/src/modules/keyboard/KeyboardLayoutModel.h +++ b/src/modules/keyboard/KeyboardLayoutModel.h @@ -118,6 +118,13 @@ public: int currentIndex() const; const QPair< QString, KeyboardGlobal::KeyboardInfo > item( const int& index ) const; + /** @brief xkb key for a given index (row) + * + * This is like calling data( QModelIndex( index ), KeyboardLayoutKeyRole ).toString(), + * but shorter and faster. Can return an empty string if index is invalid. + */ + QString key( int index ) const; + protected: QHash< int, QByteArray > roleNames() const override; diff --git a/src/modules/keyboard/KeyboardPage.cpp b/src/modules/keyboard/KeyboardPage.cpp index 7522056a3..e69ee579f 100644 --- a/src/modules/keyboard/KeyboardPage.cpp +++ b/src/modules/keyboard/KeyboardPage.cpp @@ -70,8 +70,9 @@ KeyboardPage::KeyboardPage( Config* config, QWidget* parent ) cDebug() << "Variants now" << model->rowCount() << model->currentIndex(); } - connect( - ui->buttonRestore, &QPushButton::clicked, [config = config] { config->keyboardModels()->setCurrentIndex(); } ); + connect( ui->buttonRestore, &QPushButton::clicked, [ config = config ] { + config->keyboardModels()->setCurrentIndex(); + } ); connect( ui->physicalModelSelector, QOverload< int >::of( &QComboBox::currentIndexChanged ), @@ -82,18 +83,22 @@ KeyboardPage::KeyboardPage( Config* config, QWidget* parent ) ui->physicalModelSelector, &QComboBox::setCurrentIndex ); - connect( ui->layoutSelector->selectionModel(), - &QItemSelectionModel::currentChanged, - [this]( const QModelIndex& current ) { m_config->keyboardLayouts()->setCurrentIndex( current.row() ); } ); - connect( config->keyboardLayouts(), &KeyboardLayoutModel::currentIndexChanged, [this]( int index ) { + connect( + ui->layoutSelector->selectionModel(), + &QItemSelectionModel::currentChanged, + [ this ]( const QModelIndex& current ) { m_config->keyboardLayouts()->setCurrentIndex( current.row() ); } ); + connect( config->keyboardLayouts(), &KeyboardLayoutModel::currentIndexChanged, [ this ]( int index ) { ui->layoutSelector->setCurrentIndex( m_config->keyboardLayouts()->index( index ) ); + m_keyboardPreview->setLayout( m_config->keyboardLayouts()->key( index ) ); } ); - connect( ui->variantSelector->selectionModel(), - &QItemSelectionModel::currentChanged, - [this]( const QModelIndex& current ) { m_config->keyboardVariants()->setCurrentIndex( current.row() ); } ); - connect( config->keyboardVariants(), &KeyboardVariantsModel::currentIndexChanged, [this]( int index ) { + connect( + ui->variantSelector->selectionModel(), + &QItemSelectionModel::currentChanged, + [ this ]( const QModelIndex& current ) { m_config->keyboardVariants()->setCurrentIndex( current.row() ); } ); + connect( config->keyboardVariants(), &KeyboardVariantsModel::currentIndexChanged, [ this ]( int index ) { ui->variantSelector->setCurrentIndex( m_config->keyboardVariants()->index( index ) ); + m_keyboardPreview->setVariant( m_config->keyboardVariants()->key( index ) ); } ); CALAMARES_RETRANSLATE_SLOT( &KeyboardPage::retranslate ) }