Skip to content

Commit

Permalink
return magnitude multiplier based on units set
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros authored and wonder-sk committed May 7, 2024
1 parent 07de0c9 commit eee787f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ Represents a mesh renderer settings for vector datasets displayed with wind barb

double magnitudeMultiplier() const;
%Docstring
Returns the multiplier for the magnitude to convert it to knots
Returns the multiplier for the magnitude to convert it to knots, according to the units set with :py:func:`~QgsMeshRendererVectorWindBarbSettings.setMagnitudeUnits`
A custom multiplier can be set with :py:func:`~QgsMeshRendererVectorWindBarbSettings.setMagnitudeMultiplier` for the case when units are set to OtherUnit
%End

void setMagnitudeMultiplier( double magnitudeMultiplier );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ Represents a mesh renderer settings for vector datasets displayed with wind barb

double magnitudeMultiplier() const;
%Docstring
Returns the multiplier for the magnitude to convert it to knots
Returns the multiplier for the magnitude to convert it to knots, according to the units set with :py:func:`~QgsMeshRendererVectorWindBarbSettings.setMagnitudeUnits`
A custom multiplier can be set with :py:func:`~QgsMeshRendererVectorWindBarbSettings.setMagnitudeMultiplier` for the case when units are set to OtherUnit
%End

void setMagnitudeMultiplier( double magnitudeMultiplier );
Expand Down
17 changes: 16 additions & 1 deletion src/core/mesh/qgsmeshrenderersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,22 @@ QDomElement QgsMeshRendererVectorWindBarbSettings::writeXml( QDomDocument &doc )

double QgsMeshRendererVectorWindBarbSettings::magnitudeMultiplier() const
{
return mMagnitudeMultiplier;
switch ( mMagnitudeUnits )
{
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::Knots:
return 1.0;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::MetersPerSecond:
return 3600.0 / 1852.0;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::KilometersPerHour:
return 1.0 / 1.852;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::MilesPerHour:
return 1.609344 / 1.852;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::FeetPerSecond:
return 3600.0 / 1.852 / 5280.0 * 1.609344 ;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::OtherUnit:
return mMagnitudeMultiplier;
}
return 1.0; // should not reach
}

void QgsMeshRendererVectorWindBarbSettings::setMagnitudeMultiplier( double magnitudeMultiplier )
Expand Down
3 changes: 2 additions & 1 deletion src/core/mesh/qgsmeshrenderersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ class CORE_EXPORT QgsMeshRendererVectorWindBarbSettings
};

/**
* Returns the multiplier for the magnitude to convert it to knots
* Returns the multiplier for the magnitude to convert it to knots, according to the units set with setMagnitudeUnits()
* A custom multiplier can be set with setMagnitudeMultiplier() for the case when units are set to OtherUnit
*/
double magnitudeMultiplier() const;

Expand Down
28 changes: 5 additions & 23 deletions src/gui/mesh/qgsmeshrenderervectorsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ QgsMeshRendererVectorSettingsWidget::QgsMeshRendererVectorSettingsWidget( QWidge
mTracesMaxLengthSpinBox->setClearValue( 100.0 );

mWindBarbLengthSpinBox->setClearValue( 10.0 );
mWindBarbMagnitudeMultiplierSpinBox->setValue( 1.0 );
mWindBarbMagnitudeMultiplierSpinBox->setClearValue( 1.0 );

connect( mColorWidget, &QgsColorButton::colorChanged, this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
Expand Down Expand Up @@ -293,9 +294,9 @@ void QgsMeshRendererVectorSettingsWidget::syncToLayer( )
// Wind Barb settings
const QgsMeshRendererVectorWindBarbSettings windBarbSettings = settings.windBarbSettings();
mWindBarbLengthSpinBox->setValue( windBarbSettings.shaftLength() );
mWindBarbMagnitudeMultiplierSpinBox->setValue( windBarbSettings.magnitudeMultiplier() );
mWindBarbUnitsComboBox->setCurrentIndex( static_cast<int>( windBarbSettings.magnitudeUnits() ) );
onWindBarbUnitsChanged( static_cast<int>( windBarbSettings.magnitudeUnits() ) );
if ( windBarbSettings.magnitudeUnits() == QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::OtherUnit )
mWindBarbMagnitudeMultiplierSpinBox->setValue( windBarbSettings.magnitudeMultiplier() );
}

void QgsMeshRendererVectorSettingsWidget::onSymbologyChanged( int currentIndex )
Expand Down Expand Up @@ -333,30 +334,11 @@ void QgsMeshRendererVectorSettingsWidget::onWindBarbUnitsChanged( int currentInd
{
const QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit units =
static_cast<QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit>( currentIndex );
double multiplier;
switch ( units )
{
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::Knots:
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::OtherUnit:
multiplier = 1.0;
break;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::MetersPerSecond:
multiplier = 3600.0 / 1852.0;
break;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::KilometersPerHour:
multiplier = 1.852;
break;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::MilesPerHour:
multiplier = 1.609344 / 1.852;
break;
case QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::FeetPerSecond:
multiplier = 3600.0 / 1.852 / 5280.0 * 1.609344 ;
break;
}

mWindBarbMagnitudeMultiplierLabel->setVisible( units == QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::OtherUnit );
mWindBarbMagnitudeMultiplierSpinBox->setVisible( units == QgsMeshRendererVectorWindBarbSettings::WindSpeedUnit::OtherUnit );
mWindBarbMagnitudeMultiplierSpinBox->setValue( multiplier );

emit widgetChanged();
}

void QgsMeshRendererVectorSettingsWidget::onColoringMethodChanged()
Expand Down

0 comments on commit eee787f

Please sign in to comment.