20#include "moc_qgsvectorfieldsettingswidget.cpp"
27 QVector<QgsDoubleSpinBox *> widgets;
33 << mMinimumShaftSpinBox
34 << mMaximumShaftSpinBox
35 << mScaleShaftByFactorOfSpinBox
36 << mShaftLengthSpinBox
37 << mWindBarbLengthSpinBox
38 << mWindBarbMagnitudeMultiplierSpinBox;
41 for (
const auto &widget : std::as_const( widgets ) )
44 widget->setSpecialValueText( QString() );
45 widget->setValue( widget->minimum() );
48 mShaftLengthComboBox->setCurrentIndex( -1 );
53 mXSpacingSpinBox->setClearValue( 10.0 );
54 mYSpacingSpinBox->setClearValue( 10.0 );
55 mStreamlinesDensitySpinBox->setClearValue( 15.0 );
56 mTracesParticlesCountSpinBox->setClearValue( 1000 );
57 mTracesMaxLengthSpinBox->setClearValue( 100.0 );
59 mWindBarbLengthSpinBox->setClearValue( 10.0 );
60 mWindBarbMagnitudeMultiplierSpinBox->setValue( 1.0 );
61 mWindBarbMagnitudeMultiplierSpinBox->setClearValue( 1.0 );
64 connect( mColoringMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsVectorFieldSettingsWidget::onColoringMethodChanged );
66 connect( mColorRampShaderMinimumSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsVectorFieldSettingsWidget::onColorRampMinMaxChanged );
67 connect( mColorRampShaderMaximumSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsVectorFieldSettingsWidget::onColorRampMinMaxChanged );
73 connect( mShaftLengthComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), mShaftOptionsStackedWidget, &QStackedWidget::setCurrentIndex );
77 connect( mColorRampShaderLoadButton, &QPushButton::clicked,
this, &QgsVectorFieldSettingsWidget::loadColorRampShader );
79 onColoringMethodChanged();
81 for (
const auto &widget : std::as_const( widgets ) )
89 populateSymbologies();
91 connect( mSymbologyVectorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsVectorFieldSettingsWidget::onSymbologyChanged );
96 connect( mStreamlinesSeedingMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsVectorFieldSettingsWidget::onStreamLineSeedingMethodChanged );
97 onStreamLineSeedingMethodChanged( 0 );
114 connect( mWindBarbUnitsComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsVectorFieldSettingsWidget::onWindBarbUnitsChanged );
115 onWindBarbUnitsChanged( 0 );
121 settings.setSymbology( currentSymbology() );
127 settings.setColor( mColorWidget->color() );
128 settings.setLineWidth( mLineWidthSpinBox->value() );
130 settings.setColorRampShader( mColorRampShaderWidget->shader() );
133 double val = filterValue( mMinMagSpinBox, -1 );
136 val = filterValue( mMaxMagSpinBox, -1 );
147 bool enabled = mDisplayVectorsOnGridGroupBox->isChecked();
148 settings.setOnUserDefinedGrid( enabled );
149 settings.setUserGridCellWidth( mXSpacingSpinBox->value() );
150 settings.setUserGridCellHeight( mYSpacingSpinBox->value() );
156 val = filterValue( mMinimumShaftSpinBox, arrowSettings.
minShaftLength() );
159 val = filterValue( mMaximumShaftSpinBox, arrowSettings.
maxShaftLength() );
162 val = filterValue( mScaleShaftByFactorOfSpinBox, arrowSettings.
scaleFactor() );
168 settings.setArrowsSettings( arrowSettings );
174 streamlineSettings.
setSeedingDensity( mStreamlinesDensitySpinBox->value() / 100 );
176 settings.setStreamLinesSettings( streamlineSettings );
183 settings.setTracesSettings( tracesSettings );
187 windBarbSettings.
setShaftLength( mWindBarbLengthSpinBox->value() );
191 settings.setWindBarbSettings( windBarbSettings );
198 mSupportsInterpolation = supported;
199 populateSymbologies();
204 mHasMagnitude = hasMagnitude;
209 mMagnitudeMinimum = minimum;
210 mMagnitudeMaximum = maximum;
211 mHasMagnitudeRange =
true;
216 const int symbologyIndex = mSymbologyVectorComboBox->findData(
static_cast< int >(
settings.symbology() ) );
218 mSymbologyVectorComboBox->setCurrentIndex( symbologyIndex >= 0 ? symbologyIndex : mSymbologyVectorComboBox->findData(
static_cast< int >(
Qgis::VectorFieldSymbology::Arrows ) ) );
224 mColorWidget->setColor(
settings.color() );
225 mLineWidthSpinBox->setValue(
settings.lineWidth() );
226 mColoringMethodComboBox->setCurrentIndex( mColoringMethodComboBox->findData(
settings.coloringMethod() ) );
227 mColorRampShaderWidget->setFromShader(
settings.colorRampShader() );
228 mColorRampShaderMinimumSpinBox->setValue(
settings.colorRampShader().minimumValue() );
229 mColorRampShaderMaximumSpinBox->setValue(
settings.colorRampShader().maximumValue() );
234 mMinMagSpinBox->setValue(
settings.filterMin() );
238 mMaxMagSpinBox->setValue(
settings.filterMax() );
246 mDisplayVectorsOnGridGroupBox->setVisible( mSupportsInterpolation );
247 mDisplayVectorsOnGridGroupBox->setChecked(
settings.isOnUserDefinedGrid() && mSupportsInterpolation );
248 mXSpacingSpinBox->setValue(
settings.userGridCellWidth() );
249 mYSpacingSpinBox->setValue(
settings.userGridCellHeight() );
252 mShaftLengthComboBox->setCurrentIndex(
static_cast< int >( arrowSettings.
shaftLengthMethod() ) );
256 mScaleShaftByFactorOfSpinBox->setValue( arrowSettings.
scaleFactor() );
262 mStreamlinesSeedingMethodComboBox->setCurrentIndex(
static_cast< int >( streamlinesSettings.
seedingMethod() ) );
263 mStreamlinesDensitySpinBox->setValue( streamlinesSettings.
seedingDensity() * 100 );
270 mTracesParticlesCountSpinBox->setValue( tracesSettings.
particlesCount() );
274 mWindBarbLengthSpinBox->setValue( windBarbSettings.
shaftLength() );
275 mWindBarbUnitsComboBox->setCurrentIndex(
static_cast<int>( windBarbSettings.
magnitudeUnits() ) );
279 applyMagnitudeSupport();
282void QgsVectorFieldSettingsWidget::applyMagnitudeSupport()
287 const bool showMagnitudeFilter = mHasMagnitude && !isTraces;
288 mMagnitudeFilterGroupBox->setVisible( showMagnitudeFilter );
292 mColoringMethodLabel->setVisible( mHasMagnitude );
293 mColoringMethodComboBox->setVisible( mHasMagnitude );
294 mShaftLengthComboBox->setEnabled( mHasMagnitude );
296 if ( !mHasMagnitude )
298 mMinMagSpinBox->clear();
299 mMaxMagSpinBox->clear();
305void QgsVectorFieldSettingsWidget::onSymbologyChanged()
317 applyMagnitudeSupport();
319 mDisplayVectorsOnGridGroupBox->setEnabled(
326void QgsVectorFieldSettingsWidget::populateSymbologies()
328 const QVariant previous = mSymbologyVectorComboBox->currentData();
330 const QSignalBlocker blocker( mSymbologyVectorComboBox );
331 mSymbologyVectorComboBox->clear();
335 if ( mSupportsInterpolation )
343 const int previousIndex = previous.isValid() ? mSymbologyVectorComboBox->findData( previous ) : -1;
344 mSymbologyVectorComboBox->setCurrentIndex( previousIndex >= 0 ? previousIndex : 0 );
352void QgsVectorFieldSettingsWidget::onStreamLineSeedingMethodChanged(
int currentIndex )
355 mStreamlinesDensityLabel->setEnabled( enabled );
356 mStreamlinesDensitySpinBox->setEnabled( enabled );
358 mDisplayVectorsOnGridGroupBox->setEnabled( !enabled );
361void QgsVectorFieldSettingsWidget::onWindBarbUnitsChanged(
int currentIndex )
371void QgsVectorFieldSettingsWidget::onColoringMethodChanged()
377 if ( mColorRampShaderWidget->shader().colorRampItemList().isEmpty() )
378 loadColorRampShader();
383void QgsVectorFieldSettingsWidget::onColorRampMinMaxChanged()
385 mColorRampShaderWidget->setMinimumMaximumAndClassify( filterValue( mColorRampShaderMinimumSpinBox, 0 ), filterValue( mColorRampShaderMaximumSpinBox, 0 ) );
388void QgsVectorFieldSettingsWidget::loadColorRampShader()
390 if ( !mHasMagnitudeRange )
393 mColorRampShaderWidget->setMinimumMaximumAndClassify( mMagnitudeMinimum, mMagnitudeMaximum );
394 whileBlocking( mColorRampShaderMinimumSpinBox )->setValue( mMagnitudeMinimum );
395 whileBlocking( mColorRampShaderMaximumSpinBox )->setValue( mMagnitudeMaximum );
398double QgsVectorFieldSettingsWidget::filterValue(
const QgsDoubleSpinBox *spinBox,
double errVal )
const
400 if ( spinBox->value() == spinBox->
clearValue() )
403 return spinBox->value();
VectorFieldSeedingMethod
Method used to define start points that are used to draw streamlines.
@ Gridded
Seeds start points on data grid or user regular grid.
@ Random
Seeds start points randomly.
VectorFieldSymbology
Defines the symbology of vector field rendering.
@ WindBarbs
Displaying vector dataset with wind barbs.
@ Arrows
Displaying vector dataset with arrows.
@ Traces
Displaying vector dataset with particle traces.
@ Streamlines
Displaying vector dataset with streamlines.
WindSpeedUnit
Wind speed units.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ MetersInMapUnits
Meters value as Map units.
VectorFieldArrowScalingMethod
Algorithm to transform vector magnitude to length of arrow on the device in pixels.
@ Fixed
Use fixed length fixedShaftLength() regardless of vector's magnitude.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
@ MinimumValue
Reset value to minimum().
ColoringMethod
Defines how the color is defined.
@ ColorRamp
Render with a color ramp.
@ SingleColor
Render with a single color.
Represents a mesh renderer settings for vector datasets displayed with arrows.
void setFixedShaftLength(double fixedShaftLength)
Sets fixed length (in millimeters).
double minShaftLength() const
Returns mininimum shaft length (in millimeters).
Qgis::VectorFieldArrowScalingMethod shaftLengthMethod() const
Returns method used for drawing arrows.
void setMinShaftLength(double minShaftLength)
Sets mininimum shaft length (in millimeters).
double arrowHeadLengthRatio() const
Returns ratio of the head length of the arrow (range 0-1).
void setShaftLengthMethod(Qgis::VectorFieldArrowScalingMethod shaftLengthMethod)
Sets method used for drawing arrows.
void setScaleFactor(double scaleFactor)
Sets scale factor.
double fixedShaftLength() const
Returns fixed arrow length (in millimeters).
void setArrowHeadWidthRatio(double arrowHeadWidthRatio)
Sets ratio of the head width of the arrow (range 0-1).
void setMaxShaftLength(double maxShaftLength)
Sets maximum shaft length (in millimeters).
double arrowHeadWidthRatio() const
Returns ratio of the head width of the arrow (range 0-1).
double maxShaftLength() const
Returns maximum shaft length (in millimeters).
double scaleFactor() const
Returns scale factor.
void setArrowHeadLengthRatio(double arrowHeadLengthRatio)
Sets ratio of the head length of the arrow (range 0-1).
Represents a renderer settings for vector datasets.
Represents a streamline renderer settings for vector datasets displayed by streamlines.
void setSeedingMethod(const Qgis::VectorFieldSeedingMethod &seedingMethod)
Sets the method used for seeding start points of strealines.
Qgis::VectorFieldSeedingMethod seedingMethod() const
Returns the method used for seeding start points of strealines.
double seedingDensity() const
Returns the density used for seeding start points.
void setSeedingDensity(double seedingDensity)
Sets the density used for seeding start points.
Represents a trace renderer settings for vector datasets displayed by particle traces.
Qgis::RenderUnit maximumTailLengthUnit() const
Returns the maximum tail length unit.
int particlesCount() const
Returns particles count.
void setMaximumTailLengthUnit(Qgis::RenderUnit maximumTailLengthUnit)
Sets the maximum tail length unit.
double maximumTailLength() const
Returns the maximum tail length.
void setParticlesCount(int value)
Sets particles count.
void setMaximumTailLength(double maximumTailLength)
Sets the maximums tail length.
Represents a mesh renderer settings for vector datasets displayed with wind barbs.
Qgis::WindSpeedUnit magnitudeUnits() const
Returns the units that the data are in.
double shaftLength() const
Returns the shaft length (in millimeters).
void setMagnitudeMultiplier(double magnitudeMultiplier)
Sets a multiplier for the magnitude to convert it to knots.
void setMagnitudeUnits(Qgis::WindSpeedUnit units)
Sets the units that the data are in.
double magnitudeMultiplier() const
Returns the multiplier for the magnitude to convert it to knots, according to the units set with setM...
void setShaftLength(double shaftLength)
Sets the shaft length (in millimeters).
void setShaftLengthUnits(Qgis::RenderUnit shaftLengthUnit)
Sets the units for the shaft length.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.