From 91f050927284db0bc16d360c996437bb5865c30f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 7 Sep 2019 15:18:58 +0200 Subject: [PATCH] [locale] Refactor lambdas to plain methods - Lengthy lambda's doing UI stuff -- that doesn't change -- are easier to read as plain methods. --- src/modules/locale/LocalePage.cpp | 78 ++++++++++++++++--------------- src/modules/locale/LocalePage.h | 3 ++ 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/modules/locale/LocalePage.cpp b/src/modules/locale/LocalePage.cpp index 4a48ecde8..c84cd924e 100644 --- a/src/modules/locale/LocalePage.cpp +++ b/src/modules/locale/LocalePage.cpp @@ -99,43 +99,8 @@ LocalePage::LocalePage( QWidget* parent ) setLayout( mainLayout ); - connect( m_regionCombo, - static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), - [this]( int currentIndex ) - { - Q_UNUSED( currentIndex ) - QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations(); - if ( !regions.contains( m_regionCombo->currentData().toString() ) ) - return; - - m_zoneCombo->blockSignals( true ); - - m_zoneCombo->clear(); - - const QList< LocaleGlobal::Location > zones = regions.value( m_regionCombo->currentData().toString() ); - for ( const LocaleGlobal::Location& zone : zones ) - { - m_zoneCombo->addItem( LocaleGlobal::Location::pretty( zone.zone ), zone.zone ); - } - - m_zoneCombo->model()->sort( 0 ); - - m_zoneCombo->blockSignals( false ); - - m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() ); - } ); - - connect( m_zoneCombo, - static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), - [this]( int currentIndex ) - { - Q_UNUSED( currentIndex ) - if ( !m_blockTzWidgetSet ) - m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(), - m_zoneCombo->currentData().toString() ); - - updateGlobalStorage(); - } ); + connect( m_regionCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::regionChanged ); + connect( m_zoneCombo, QOverload< int >::of( &QComboBox::currentIndexChanged ), this, &LocalePage::zoneChanged ); connect( m_tzWidget, &TimeZoneWidget::locationChanged, [this]( LocaleGlobal::Location location ) @@ -517,3 +482,42 @@ LocalePage::updateGlobalStorage() m_selectedLocaleConfiguration = newLocale; updateLocaleLabels(); } + + +void +LocalePage::regionChanged( int currentIndex ) +{ + Q_UNUSED( currentIndex ) + QHash< QString, QList< LocaleGlobal::Location > > regions = LocaleGlobal::getLocations(); + if ( !regions.contains( m_regionCombo->currentData().toString() ) ) + { + return; + } + + m_zoneCombo->blockSignals( true ); + + m_zoneCombo->clear(); + + const QList< LocaleGlobal::Location > zones = regions.value( m_regionCombo->currentData().toString() ); + for ( const LocaleGlobal::Location& zone : zones ) + { + m_zoneCombo->addItem( LocaleGlobal::Location::pretty( zone.zone ), zone.zone ); + } + + m_zoneCombo->model()->sort( 0 ); + + m_zoneCombo->blockSignals( false ); + + m_zoneCombo->currentIndexChanged( m_zoneCombo->currentIndex() ); +} + +void +LocalePage::zoneChanged( int currentIndex ) +{ + Q_UNUSED( currentIndex ) + if ( !m_blockTzWidgetSet ) + m_tzWidget->setCurrentLocation( m_regionCombo->currentData().toString(), + m_zoneCombo->currentData().toString() ); + + updateGlobalStorage(); +} diff --git a/src/modules/locale/LocalePage.h b/src/modules/locale/LocalePage.h index 20ad444c9..9aa7bf4f8 100644 --- a/src/modules/locale/LocalePage.h +++ b/src/modules/locale/LocalePage.h @@ -65,6 +65,9 @@ private: void updateGlobalStorage(); void updateLocaleLabels(); + void regionChanged( int currentIndex ); + void zoneChanged( int currentIndex ); + TimeZoneWidget* m_tzWidget; QComboBox* m_regionCombo; QComboBox* m_zoneCombo;