From 2a8960cd0ff5f7b4472935cd5601bc193baa2a3b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 12 Feb 2019 07:30:34 -0500 Subject: [PATCH] [partition] Ensure combobox pre-selects consistently - Match the selected item in the combobox with a given default, which should be whatever is selected from the available set of choices. --- src/modules/partition/gui/ChoicePage.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index ee7905c33..7c980cf49 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -201,15 +201,21 @@ ChoicePage::init( PartitionCoreModule* core ) /** @brief Creates a combobox with the given choices in it. * + * Pre-selects the choice given by @p dflt. * No texts are set -- that happens later by the translator functions. */ static inline QComboBox* -createCombo( const QSet< SwapChoice >& s ) +createCombo( const QSet< SwapChoice >& s, SwapChoice dflt ) { QComboBox* box = new QComboBox; for ( SwapChoice c : { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap, SwapChoice::ReuseSwap, SwapChoice::SwapFile } ) if ( s.contains( c ) ) box->addItem( QString(), c ); + + int dfltIndex = box->findData( dflt ); + if ( dfltIndex >= 0 ) + box->setCurrentIndex( dfltIndex ); + return box; } @@ -270,7 +276,7 @@ ChoicePage::setupChoices() // .. TODO: only if enabled in the config if ( m_availableSwapChoices.count() > 1 ) { - m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices ); + m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices, m_eraseSwapChoice ); m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox ); }