23#include "moc_qgsinterpolatedlinesymbollayerwidget.cpp"
25using namespace Qt::StringLiterals;
32 mWidthMethodComboBox->addItem( tr(
"Fixed Width" ),
false );
33 mWidthMethodComboBox->addItem( tr(
"Varying Width" ),
true );
42 mWidthStartFieldExpression->setLayer( layer );
43 mWidthEndFieldExpression->setLayer( layer );
44 mColorStartFieldExpression->setLayer( layer );
45 mColorEndFieldExpression->setLayer( layer );
47 mWidthUnitSelectionFixed->setUnits(
58 mWidthUnitSelectionVarying->setUnits(
69 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
70 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
73 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
74 connect( mDoubleSpinBoxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
77 connect( mButtonLoadMinMaxValueWidth, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth );
78 connect( mLineEditWidthMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
79 connect( mLineEditWidthMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
80 connect( mDoubleSpinBoxMinWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
81 connect( mDoubleSpinBoxMaxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
86 whileBlocking( mWidthUnitSelectionFixed )->setUnit( mWidthUnitSelectionVarying->unit() );
90 whileBlocking( mWidthUnitSelectionVarying )->setUnit( mWidthUnitSelectionFixed->unit() );
93 connect( mCheckBoxAbsoluteValue, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
94 connect( mCheckBoxOutOfrange, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
97 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
104 connect( mLineEditColorMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
105 connect( mLineEditColorMinValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
106 connect( mLineEditColorMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
107 connect( mLineEditColorMaxValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
108 connect( mButtonLoadMinMaxValueColor, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor );
114 if ( !layer || layer->
layerType() !=
"InterpolatedLine"_L1 )
125 setLineEditValue( mLineEditWidthMinValue, interpolatedWidth.
minimumValue() );
126 setLineEditValue( mLineEditWidthMaxValue, interpolatedWidth.
maximumValue() );
129 whileBlocking( mWidthUnitSelectionFixed )->setUnit( mLayer->widthUnit() );
130 whileBlocking( mWidthUnitSelectionVarying )->setUnit( mLayer->widthUnit() );
145 updateVisibleWidget();
156void QgsInterpolatedLineSymbolLayerWidget::apply()
161 bool isExpression =
false;
162 QString fieldOrExpression = mWidthStartFieldExpression->currentField( &isExpression );
164 fieldOrExpression = mWidthEndFieldExpression->currentField( &isExpression );
168 if ( mWidthMethodComboBox->currentData().toBool() )
169 mLayer->
setWidthUnit( mWidthUnitSelectionVarying->unit() );
171 mLayer->
setWidthUnit( mWidthUnitSelectionFixed->unit() );
173 fieldOrExpression = mColorStartFieldExpression->currentField( &isExpression );
175 fieldOrExpression = mColorEndFieldExpression->currentField( &isExpression );
183void QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget()
185 mFixedWidthWidget->setVisible( !mWidthMethodComboBox->currentData().toBool() );
186 mVaryingWidthWidget->setVisible( mWidthMethodComboBox->currentData().toBool() );
188 mFixedColorWidget->setVisible(
191 mVaryingColorWidget->setVisible(
196void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth()
198 reloadMinMaxWidthFromLayer();
199 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
200 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
204void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor()
206 reloadMinMaxColorFromLayer();
207 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
208 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
209 onColorMinMaxLineTextEdited();
212void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxWidthFromLayer()
216 QgsExpression expressionStart( mWidthStartFieldExpression->expression() );
217 if ( !expressionStart.prepare( &expressionContext ) )
223 QgsExpression expressionEnd( mWidthEndFieldExpression->expression() );
224 if ( !expressionEnd.prepare( &expressionContext ) )
238 mMinimumForWidthFromLayer = std::numeric_limits<double>::max();
239 mMaximumForWidthFromLayer = -std::numeric_limits<double>::max();
243 double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
244 double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
246 if ( mCheckBoxAbsoluteValue->isChecked() )
248 startValue = fabs( startValue );
249 endValue = fabs( endValue );
252 if ( startValue < mMinimumForWidthFromLayer )
253 mMinimumForWidthFromLayer = startValue;
254 if ( startValue > mMaximumForWidthFromLayer )
255 mMaximumForWidthFromLayer = startValue;
257 if ( endValue < mMinimumForWidthFromLayer )
258 mMinimumForWidthFromLayer = endValue;
259 if ( endValue > mMaximumForWidthFromLayer )
260 mMaximumForWidthFromLayer = endValue;
263 if ( mLineEditWidthMinValue->text().isEmpty() && !std::isnan( mMinimumForWidthFromLayer ) )
265 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
268 if ( mLineEditWidthMaxValue->text().isEmpty() && !std::isnan( mMaximumForWidthFromLayer ) )
270 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
276void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxColorFromLayer()
280 QgsExpression expressionStart( mColorStartFieldExpression->expression() );
281 if ( !expressionStart.prepare( &expressionContext ) )
287 QgsExpression expressionEnd( mColorEndFieldExpression->expression() );
288 if ( !expressionEnd.prepare( &expressionContext ) )
302 mMinimumForColorFromLayer = std::numeric_limits<double>::max();
303 mMaximumForColorFromLayer = -std::numeric_limits<double>::max();
307 const double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
308 const double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
310 if ( startValue < mMinimumForColorFromLayer )
311 mMinimumForColorFromLayer = startValue;
312 if ( startValue > mMaximumForColorFromLayer )
313 mMaximumForColorFromLayer = startValue;
315 if ( endValue < mMinimumForColorFromLayer )
316 mMinimumForColorFromLayer = endValue;
317 if ( endValue > mMaximumForColorFromLayer )
318 mMaximumForColorFromLayer = endValue;
321 bool minMaxColorChanged =
false;
322 if ( mLineEditColorMinValue->text().isEmpty() && !std::isnan( mMinimumForColorFromLayer ) )
324 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
325 minMaxColorChanged =
true;
328 if ( mLineEditColorMaxValue->text().isEmpty() && !std::isnan( mMaximumForColorFromLayer ) )
330 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
331 minMaxColorChanged =
true;
334 if ( minMaxColorChanged )
335 onColorMinMaxLineTextEdited();
340void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged()
342 const double min = lineEditValue( mLineEditColorMinValue );
343 const double max = lineEditValue( mLineEditColorMaxValue );
344 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( min, max );
348void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited()
350 const double min = lineEditValue( mLineEditColorMinValue );
351 const double max = lineEditValue( mLineEditColorMaxValue );
352 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( min, max );
358 QgsInterpolatedLineWidth interWidth;
373 QgsInterpolatedLineColor interColor;
374 interColor.
setColor( mColorButton->color() );
375 const QgsColorRampShader colorRampShader = mColorRampShaderWidget->shader();
376 interColor.
setColor( colorRampShader );
382double QgsInterpolatedLineSymbolLayerWidget::lineEditValue( QLineEdit *lineEdit )
384 if ( lineEdit->text().isEmpty() )
386 return std::numeric_limits<double>::quiet_NaN();
392void QgsInterpolatedLineSymbolLayerWidget::setLineEditValue( QLineEdit *lineEdit,
double value )
395 if ( !std::isnan( value ) )
396 strValue = QLocale().toString( value );
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ MetersInMapUnits
Meters value as Map units.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
@ Numeric
All numeric fields.
Defines color interpolation for rendering mesh datasets.
QgsInterpolatedLineColor::ColoringMethod coloringMethod() const
Returns the coloring method used.
QgsColorRampShader colorRampShader() const
Returns the color ramp shader.
void setColor(const QgsColorRampShader &colorRampShader)
Sets the color ramp to define the coloring.
QColor singleColor() const
Returns the single color that is used if SingleColor coloring mode is set.
void setColoringMethod(ColoringMethod coloringMethod)
Sets the coloring method used.
ColoringMethod
Defines how the color is defined.
@ ColorRamp
Render with a color ramp.
@ SingleColor
Render with a single color.
A symbol layer that represents vector layer line features as interpolated lines.
void setInterpolatedWidth(const QgsInterpolatedLineWidth &interpolatedLineWidth)
Sets the interpolated width used to render the width of lines, see QgsInterpolatedLineWidth.
void setInterpolatedColor(const QgsInterpolatedLineColor &interpolatedLineColor)
Sets the interpolated color used to render the colors of lines, see QgsInterpolatedLineColor.
void setWidthUnit(Qgis::RenderUnit strokeWidthUnit)
Sets the width unit.
Represents a width that can vary depending on values.
void setFixedStrokeWidth(double fixedWidth)
Sets the fixed width.
void setUseAbsoluteValue(bool useAbsoluteValue)
Sets whether absolute value are used as input.
double minimumValue() const
Returns the minimum value used to defined the variable width.
void setIgnoreOutOfRange(bool ignoreOutOfRange)
Sets whether the variable width ignores out of range value.
void setMaximumValue(double maximumValue)
Sets the maximum value used to defined the variable width.
bool useAbsoluteValue() const
Returns whether absolute value are used as input.
void setIsVariableWidth(bool isVariableWidth)
Returns whether the width is variable.
void setMinimumValue(double minimumValue)
Sets the minimum value used to defined the variable width.
double maximumWidth() const
Returns the maximum width used to defined the variable width.
void setMaximumWidth(double maximumWidth)
Sets the maximum width used to defined the variable width.
double maximumValue() const
Returns the maximum value used to defined the variable width.
void setMinimumWidth(double minimumWidth)
Sets the minimum width used to defined the variable width.
bool ignoreOutOfRange() const
Returns whether the variable width ignores out of range value.
double minimumWidth() const
Returns the minimum width used to defined the variable width.
double fixedStrokeWidth() const
Returns the fixed width.
bool isVariableWidth() const
Returns whether the width is variable.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
double maximumValue() const
Returns the minimum value for the raster shader.
double minimumValue() const
Returns the maximum value for the raster shader.
Abstract base class for symbol layers.
@ LineEndColorValue
End line color for interpolated line renderer.
@ LineStartColorValue
Start line color for interpolated line renderer.
@ LineEndWidthValue
End line width for interpolated line renderer.
@ LineStartWidthValue
Start line width for interpolated line renderer.
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
Represents a vector layer which manages a vector based dataset.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.