[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.
This commit is contained in:
parent
5f20eedb6e
commit
2a8960cd0f
@ -201,15 +201,21 @@ ChoicePage::init( PartitionCoreModule* core )
|
|||||||
|
|
||||||
/** @brief Creates a combobox with the given choices in it.
|
/** @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.
|
* No texts are set -- that happens later by the translator functions.
|
||||||
*/
|
*/
|
||||||
static inline QComboBox*
|
static inline QComboBox*
|
||||||
createCombo( const QSet< SwapChoice >& s )
|
createCombo( const QSet< SwapChoice >& s, SwapChoice dflt )
|
||||||
{
|
{
|
||||||
QComboBox* box = new QComboBox;
|
QComboBox* box = new QComboBox;
|
||||||
for ( SwapChoice c : { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap, SwapChoice::ReuseSwap, SwapChoice::SwapFile } )
|
for ( SwapChoice c : { SwapChoice::NoSwap, SwapChoice::SmallSwap, SwapChoice::FullSwap, SwapChoice::ReuseSwap, SwapChoice::SwapFile } )
|
||||||
if ( s.contains( c ) )
|
if ( s.contains( c ) )
|
||||||
box->addItem( QString(), c );
|
box->addItem( QString(), c );
|
||||||
|
|
||||||
|
int dfltIndex = box->findData( dflt );
|
||||||
|
if ( dfltIndex >= 0 )
|
||||||
|
box->setCurrentIndex( dfltIndex );
|
||||||
|
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +276,7 @@ ChoicePage::setupChoices()
|
|||||||
// .. TODO: only if enabled in the config
|
// .. TODO: only if enabled in the config
|
||||||
if ( m_availableSwapChoices.count() > 1 )
|
if ( m_availableSwapChoices.count() > 1 )
|
||||||
{
|
{
|
||||||
m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices );
|
m_eraseSwapChoiceComboBox = createCombo( m_availableSwapChoices, m_eraseSwapChoice );
|
||||||
m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox );
|
m_eraseButton->addOptionsComboBox( m_eraseSwapChoiceComboBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user