Skip to content

Commit

Permalink
style(ColorWidget): Remplace if/else with switch
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Aug 22, 2024
1 parent 3b7a3c0 commit dac3d30
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions src/gui/qgscolorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,18 +1485,20 @@ void QgsColorSliderWidget::setComponent( const QgsColorWidget::ColorComponent co
QgsColorWidget::setComponent( component );
mRampWidget->setComponent( component );
mSpinBox->setMaximum( convertRealToDisplay( static_cast<float>( componentRange() ) ) );
if ( componentUnit( component ) == ComponentUnit::Degree )
{
mSpinBox->setSuffix( QChar( 176 ) );
}
else if ( componentUnit( component ) == ComponentUnit::Percent )
{
mSpinBox->setSuffix( tr( "%" ) );
}
else

switch ( componentUnit( component ) )
{
//clear suffix
mSpinBox->setSuffix( QString() );
case ComponentUnit::Degree:
mSpinBox->setSuffix( QChar( 176 ) );
break;

case ComponentUnit::Percent:
mSpinBox->setSuffix( tr( "%" ) );
break;

case ComponentUnit::Scaled0to255:
//clear suffix
mSpinBox->setSuffix( QString() );
}
}

Expand Down Expand Up @@ -1543,34 +1545,36 @@ void QgsColorSliderWidget::rampChanged( float value )

float QgsColorSliderWidget::convertRealToDisplay( const float realValue ) const
{
if ( componentUnit( mComponent ) == ComponentUnit::Percent )
{
return realValue * 100.f;
}
else if ( componentUnit( mComponent ) == ComponentUnit::Degree )
{
return realValue * HUE_MAX;
}
else
switch ( componentUnit( mComponent ) )
{
return realValue * 255.f;
case ComponentUnit::Percent:
return realValue * 100.f;

case ComponentUnit::Degree:
return realValue * HUE_MAX;

case ComponentUnit::Scaled0to255:
return realValue * 255.f;
}

BUILTIN_UNREACHABLE
}

float QgsColorSliderWidget::convertDisplayToReal( const float displayValue ) const
{
if ( componentUnit( mComponent ) == ComponentUnit::Percent )
{
return displayValue / 100.f;
}
else if ( componentUnit( mComponent ) == ComponentUnit::Degree )
switch ( componentUnit( mComponent ) )
{
return displayValue / HUE_MAX;
}
else
{
return displayValue / 255.f;
case ComponentUnit::Percent:
return displayValue / 100.f;

case ComponentUnit::Degree:
return displayValue / HUE_MAX;

case ComponentUnit::Scaled0to255:
return displayValue / 255.f;
}

BUILTIN_UNREACHABLE
}

//
Expand Down

0 comments on commit dac3d30

Please sign in to comment.