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( {
56 mWidthUnitSelectionVarying->setUnits( {
65 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
66 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
69 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
70 connect( mDoubleSpinBoxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
73 connect( mButtonLoadMinMaxValueWidth, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth );
74 connect( mLineEditWidthMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
75 connect( mLineEditWidthMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
76 connect( mDoubleSpinBoxMinWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
77 connect( mDoubleSpinBoxMaxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
85 connect( mCheckBoxAbsoluteValue, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
86 connect( mCheckBoxOutOfrange, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
89 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
96 connect( mLineEditColorMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
97 connect( mLineEditColorMinValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
98 connect( mLineEditColorMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
99 connect( mLineEditColorMaxValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
100 connect( mButtonLoadMinMaxValueColor, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor );
106 if ( !layer || layer->
layerType() !=
"InterpolatedLine"_L1 )
117 setLineEditValue( mLineEditWidthMinValue, interpolatedWidth.
minimumValue() );
118 setLineEditValue( mLineEditWidthMaxValue, interpolatedWidth.
maximumValue() );
121 whileBlocking( mWidthUnitSelectionFixed )->setUnit( mLayer->widthUnit() );
122 whileBlocking( mWidthUnitSelectionVarying )->setUnit( mLayer->widthUnit() );
137 updateVisibleWidget();
148void QgsInterpolatedLineSymbolLayerWidget::apply()
153 bool isExpression =
false;
154 QString fieldOrExpression = mWidthStartFieldExpression->currentField( &isExpression );
156 fieldOrExpression = mWidthEndFieldExpression->currentField( &isExpression );
160 if ( mWidthMethodComboBox->currentData().toBool() )
161 mLayer->
setWidthUnit( mWidthUnitSelectionVarying->unit() );
163 mLayer->
setWidthUnit( mWidthUnitSelectionFixed->unit() );
165 fieldOrExpression = mColorStartFieldExpression->currentField( &isExpression );
167 fieldOrExpression = mColorEndFieldExpression->currentField( &isExpression );
175void QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget()
177 mFixedWidthWidget->setVisible( !mWidthMethodComboBox->currentData().toBool() );
178 mVaryingWidthWidget->setVisible( mWidthMethodComboBox->currentData().toBool() );
184void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth()
186 reloadMinMaxWidthFromLayer();
187 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
188 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
192void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor()
194 reloadMinMaxColorFromLayer();
195 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
196 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
197 onColorMinMaxLineTextEdited();
200void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxWidthFromLayer()
204 QgsExpression expressionStart( mWidthStartFieldExpression->expression() );
205 if ( !expressionStart.prepare( &expressionContext ) )
211 QgsExpression expressionEnd( mWidthEndFieldExpression->expression() );
212 if ( !expressionEnd.prepare( &expressionContext ) )
226 mMinimumForWidthFromLayer = std::numeric_limits<double>::max();
227 mMaximumForWidthFromLayer = -std::numeric_limits<double>::max();
231 double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
232 double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
234 if ( mCheckBoxAbsoluteValue->isChecked() )
236 startValue = fabs( startValue );
237 endValue = fabs( endValue );
240 if ( startValue < mMinimumForWidthFromLayer )
241 mMinimumForWidthFromLayer = startValue;
242 if ( startValue > mMaximumForWidthFromLayer )
243 mMaximumForWidthFromLayer = startValue;
245 if ( endValue < mMinimumForWidthFromLayer )
246 mMinimumForWidthFromLayer = endValue;
247 if ( endValue > mMaximumForWidthFromLayer )
248 mMaximumForWidthFromLayer = endValue;
251 if ( mLineEditWidthMinValue->text().isEmpty() && !std::isnan( mMinimumForWidthFromLayer ) )
253 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
256 if ( mLineEditWidthMaxValue->text().isEmpty() && !std::isnan( mMaximumForWidthFromLayer ) )
258 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
264void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxColorFromLayer()
268 QgsExpression expressionStart( mColorStartFieldExpression->expression() );
269 if ( !expressionStart.prepare( &expressionContext ) )
275 QgsExpression expressionEnd( mColorEndFieldExpression->expression() );
276 if ( !expressionEnd.prepare( &expressionContext ) )
290 mMinimumForColorFromLayer = std::numeric_limits<double>::max();
291 mMaximumForColorFromLayer = -std::numeric_limits<double>::max();
295 const double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
296 const double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
298 if ( startValue < mMinimumForColorFromLayer )
299 mMinimumForColorFromLayer = startValue;
300 if ( startValue > mMaximumForColorFromLayer )
301 mMaximumForColorFromLayer = startValue;
303 if ( endValue < mMinimumForColorFromLayer )
304 mMinimumForColorFromLayer = endValue;
305 if ( endValue > mMaximumForColorFromLayer )
306 mMaximumForColorFromLayer = endValue;
309 bool minMaxColorChanged =
false;
310 if ( mLineEditColorMinValue->text().isEmpty() && !std::isnan( mMinimumForColorFromLayer ) )
312 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
313 minMaxColorChanged =
true;
316 if ( mLineEditColorMaxValue->text().isEmpty() && !std::isnan( mMaximumForColorFromLayer ) )
318 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
319 minMaxColorChanged =
true;
322 if ( minMaxColorChanged )
323 onColorMinMaxLineTextEdited();
328void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged()
330 const double min = lineEditValue( mLineEditColorMinValue );
331 const double max = lineEditValue( mLineEditColorMaxValue );
332 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( min, max );
336void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited()
338 const double min = lineEditValue( mLineEditColorMinValue );
339 const double max = lineEditValue( mLineEditColorMaxValue );
340 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( min, max );
346 QgsInterpolatedLineWidth interWidth;
361 QgsInterpolatedLineColor interColor;
362 interColor.
setColor( mColorButton->color() );
363 const QgsColorRampShader colorRampShader = mColorRampShaderWidget->shader();
364 interColor.
setColor( colorRampShader );
370double QgsInterpolatedLineSymbolLayerWidget::lineEditValue( QLineEdit *lineEdit )
372 if ( lineEdit->text().isEmpty() )
374 return std::numeric_limits<double>::quiet_NaN();
380void QgsInterpolatedLineSymbolLayerWidget::setLineEditValue( QLineEdit *lineEdit,
double value )
383 if ( !std::isnan( value ) )
384 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.