Refactor action choice handling with QButtonGroup.

This should improve the situation when unselecting an action without
selecting another one. Unselection can only happen when switching from
a device that supports the currently chosen action to a device that
doesn't support it, so the action gets hidden and unselected.
This commit is contained in:
Teo Mrnjavac 2016-01-08 15:38:01 +01:00
parent 53c27208f1
commit 85a6f2068a

View File

@ -183,7 +183,7 @@ ChoicePage::setupChoices()
m_alongsideButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionAlongside, m_alongsideButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionAlongside,
CalamaresUtils::Original, CalamaresUtils::Original,
iconSize ) ); iconSize ) );
grp->addButton( m_alongsideButton->buttonWidget() ); grp->addButton( m_alongsideButton->buttonWidget(), Alongside );
m_eraseButton = createEraseButton(); m_eraseButton = createEraseButton();
@ -191,7 +191,7 @@ ChoicePage::setupChoices()
m_eraseButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionEraseAuto, m_eraseButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionEraseAuto,
CalamaresUtils::Original, CalamaresUtils::Original,
iconSize ) ); iconSize ) );
grp->addButton( m_eraseButton->buttonWidget() ); grp->addButton( m_eraseButton->buttonWidget(), Erase );
m_replaceButton = new PrettyRadioButton; m_replaceButton = new PrettyRadioButton;
@ -199,7 +199,7 @@ ChoicePage::setupChoices()
m_replaceButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionReplaceOs, m_replaceButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::PartitionReplaceOs,
CalamaresUtils::Original, CalamaresUtils::Original,
iconSize ) ); iconSize ) );
grp->addButton( m_replaceButton->buttonWidget() ); grp->addButton( m_replaceButton->buttonWidget(), Replace );
m_itemsLayout->addWidget( m_alongsideButton ); m_itemsLayout->addWidget( m_alongsideButton );
m_itemsLayout->addWidget( m_replaceButton ); m_itemsLayout->addWidget( m_replaceButton );
@ -216,51 +216,34 @@ ChoicePage::setupChoices()
CalamaresUtils::Original, CalamaresUtils::Original,
iconSize ) ); iconSize ) );
m_itemsLayout->addWidget( m_somethingElseButton ); m_itemsLayout->addWidget( m_somethingElseButton );
grp->addButton( m_somethingElseButton->buttonWidget() ); grp->addButton( m_somethingElseButton->buttonWidget(), Manual );
m_itemsLayout->addStretch(); m_itemsLayout->addStretch();
connect( m_alongsideButton->buttonWidget(), &QRadioButton::toggled, connect( grp, static_cast< void( QButtonGroup::* )( int, bool ) >( &QButtonGroup::buttonToggled ),
this, [ this ]( bool checked ) this, [ this, grp ]( int id, bool checked )
{ {
if ( checked ) if ( checked ) // An action was picked.
{ {
m_choice = Alongside; m_choice = static_cast< Choice >( id );
setNextEnabled( true ); if ( m_choice == Replace )
{
setNextEnabled( false );
}
else
{
setNextEnabled( true );
}
emit actionChosen(); emit actionChosen();
} }
} ); else // An action was unpicked, either on its own or because of another selection.
connect( m_eraseButton->buttonWidget(), &QRadioButton::toggled,
this, [ this ]( bool checked )
{
if ( checked )
{ {
m_choice = Erase; if ( grp->checkedButton() == nullptr ) // If no other action is chosen, we must
setNextEnabled( true ); { // set m_choice to NoChoice and reset previews.
emit actionChosen(); m_choice == NoChoice;
} setNextEnabled( false );
} ); emit actionChosen();
}
connect( m_replaceButton->buttonWidget(), &QRadioButton::toggled,
this, [ this ]( bool checked )
{
if ( checked )
{
m_choice = Replace;
setNextEnabled( false );
emit actionChosen();
}
} );
connect( m_somethingElseButton->buttonWidget(), &QRadioButton::toggled,
this, [ this ]( bool checked )
{
if ( checked )
{
m_choice = Manual;
setNextEnabled( true );
emit actionChosen();
} }
} ); } );