31 mWidthMethodComboBox->addItem( tr(
"Fixed Width" ),
false );
32 mWidthMethodComboBox->addItem( tr(
"Varying Width" ),
true );
41 mWidthStartFieldExpression->setLayer( layer );
42 mWidthEndFieldExpression->setLayer( layer );
43 mColorStartFieldExpression->setLayer( layer );
44 mColorEndFieldExpression->setLayer( layer );
47 << QgsUnitTypes::RenderUnit::RenderInches
48 << QgsUnitTypes::RenderUnit::RenderMapUnits
49 << QgsUnitTypes::RenderUnit::RenderMetersInMapUnits
50 << QgsUnitTypes::RenderUnit::RenderMillimeters
51 << QgsUnitTypes::RenderUnit::RenderPixels
52 << QgsUnitTypes::RenderUnit::RenderPoints );
55 << QgsUnitTypes::RenderUnit::RenderInches
56 << QgsUnitTypes::RenderUnit::RenderMapUnits
57 << QgsUnitTypes::RenderUnit::RenderMetersInMapUnits
58 << QgsUnitTypes::RenderUnit::RenderMillimeters
59 << QgsUnitTypes::RenderUnit::RenderPixels
60 << QgsUnitTypes::RenderUnit::RenderPoints );
62 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
63 this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
64 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
65 this, &QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget );
68 connect( mWidthMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
69 this, &QgsInterpolatedLineSymbolLayerWidget::apply );
70 connect( mDoubleSpinBoxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
71 this, &QgsInterpolatedLineSymbolLayerWidget::apply );
73 ,
this, &QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxWidthFromLayer );
75 ,
this, &QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxWidthFromLayer );
76 connect( mButtonLoadMinMaxValueWidth, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth );
77 connect( mLineEditWidthMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
78 connect( mLineEditWidthMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
79 connect( mDoubleSpinBoxMinWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
80 this, &QgsInterpolatedLineSymbolLayerWidget::apply );
81 connect( mDoubleSpinBoxMaxWidth, qOverload<double>( &QDoubleSpinBox::valueChanged ),
82 this, &QgsInterpolatedLineSymbolLayerWidget::apply );
88 whileBlocking( mWidthUnitSelectionFixed )->setUnit( mWidthUnitSelectionVarying->unit() );
93 whileBlocking( mWidthUnitSelectionVarying )->setUnit( mWidthUnitSelectionFixed->unit() );
96 connect( mCheckBoxAbsoluteValue, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
97 connect( mCheckBoxOutOfrange, &QCheckBox::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::apply );
100 connect( mColorMethodComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
101 this, &QgsInterpolatedLineSymbolLayerWidget::apply );
106 ,
this, &QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxColorFromLayer );
108 ,
this, &QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxColorFromLayer );
110 connect( mLineEditColorMinValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
111 connect( mLineEditColorMinValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
112 connect( mLineEditColorMaxValue, &QLineEdit::textChanged,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged );
113 connect( mLineEditColorMaxValue, &QLineEdit::textEdited,
this, &QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited );
114 connect( mButtonLoadMinMaxValueColor, &QPushButton::clicked,
this, &QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor );
121 if ( !layer || layer->
layerType() != QLatin1String(
"InterpolatedLine" ) )
132 setLineEditValue( mLineEditWidthMinValue, interpolatedWidth.
minimumValue() );
133 setLineEditValue( mLineEditWidthMaxValue, interpolatedWidth.
maximumValue() );
152 updateVisibleWidget();
163 void QgsInterpolatedLineSymbolLayerWidget::apply()
168 bool isExpression =
false;
169 QString fieldOrExpression = mWidthStartFieldExpression->currentField( &isExpression );
171 fieldOrExpression = mWidthEndFieldExpression->currentField( &isExpression );
175 if ( mWidthMethodComboBox->currentData().toBool() )
176 mLayer->
setWidthUnit( mWidthUnitSelectionVarying->unit() );
178 mLayer->
setWidthUnit( mWidthUnitSelectionFixed->unit() );
180 fieldOrExpression = mColorStartFieldExpression->currentField( &isExpression );
182 fieldOrExpression = mColorEndFieldExpression->currentField( &isExpression );
190 void QgsInterpolatedLineSymbolLayerWidget::updateVisibleWidget()
192 mFixedWidthWidget->setVisible( !mWidthMethodComboBox->currentData().toBool() );
193 mVaryingWidthWidget->setVisible( mWidthMethodComboBox->currentData().toBool() );
195 mFixedColorWidget->setVisible(
197 mVaryingColorWidget->setVisible(
201 void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueWidth()
203 reloadMinMaxWidthFromLayer();
204 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
205 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
209 void QgsInterpolatedLineSymbolLayerWidget::onReloadMinMaxValueColor()
211 reloadMinMaxColorFromLayer();
212 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
213 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
214 onColorMinMaxLineTextEdited();
217 void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxWidthFromLayer()
221 QgsExpression expressionStart( mWidthStartFieldExpression->expression() );
222 if ( !expressionStart.prepare( &expressionContext ) )
228 QgsExpression expressionEnd( mWidthEndFieldExpression->expression() );
229 if ( !expressionEnd.prepare( &expressionContext ) )
243 mMinimumForWidthFromLayer = std::numeric_limits<double>::max();
244 mMaximumForWidthFromLayer = -std::numeric_limits<double>::max();
248 double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
249 double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
251 if ( mCheckBoxAbsoluteValue->isChecked() )
253 startValue = fabs( startValue );
254 endValue = fabs( endValue );
257 if ( startValue < mMinimumForWidthFromLayer )
258 mMinimumForWidthFromLayer = startValue;
259 if ( startValue > mMaximumForWidthFromLayer )
260 mMaximumForWidthFromLayer = startValue;
262 if ( endValue < mMinimumForWidthFromLayer )
263 mMinimumForWidthFromLayer = endValue;
264 if ( endValue > mMaximumForWidthFromLayer )
265 mMaximumForWidthFromLayer = endValue;
268 if ( mLineEditWidthMinValue->text().isEmpty() && !std::isnan( mMinimumForWidthFromLayer ) )
270 setLineEditValue( mLineEditWidthMinValue, mMinimumForWidthFromLayer );
273 if ( mLineEditWidthMaxValue->text().isEmpty() && !std::isnan( mMaximumForWidthFromLayer ) )
275 setLineEditValue( mLineEditWidthMaxValue, mMaximumForWidthFromLayer );
281 void QgsInterpolatedLineSymbolLayerWidget::reloadMinMaxColorFromLayer()
285 QgsExpression expressionStart( mColorStartFieldExpression->expression() );
286 if ( !expressionStart.prepare( &expressionContext ) )
292 QgsExpression expressionEnd( mColorEndFieldExpression->expression() );
293 if ( !expressionEnd.prepare( &expressionContext ) )
307 mMinimumForColorFromLayer = std::numeric_limits<double>::max();
308 mMaximumForColorFromLayer = -std::numeric_limits<double>::max();
312 const double startValue = expressionStart.evaluate( &expressionContext ).toDouble();
313 const double endValue = expressionEnd.evaluate( &expressionContext ).toDouble();
315 if ( startValue < mMinimumForColorFromLayer )
316 mMinimumForColorFromLayer = startValue;
317 if ( startValue > mMaximumForColorFromLayer )
318 mMaximumForColorFromLayer = startValue;
320 if ( endValue < mMinimumForColorFromLayer )
321 mMinimumForColorFromLayer = endValue;
322 if ( endValue > mMaximumForColorFromLayer )
323 mMaximumForColorFromLayer = endValue;
326 bool minMaxColorChanged =
false;
327 if ( mLineEditColorMinValue->text().isEmpty() && !std::isnan( mMinimumForColorFromLayer ) )
329 setLineEditValue( mLineEditColorMinValue, mMinimumForColorFromLayer );
330 minMaxColorChanged =
true;
333 if ( mLineEditColorMaxValue->text().isEmpty() && !std::isnan( mMaximumForColorFromLayer ) )
335 setLineEditValue( mLineEditColorMaxValue, mMaximumForColorFromLayer );
336 minMaxColorChanged =
true;
339 if ( minMaxColorChanged )
340 onColorMinMaxLineTextEdited();
345 void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextChanged()
347 const double min = lineEditValue( mLineEditColorMinValue );
348 const double max = lineEditValue( mLineEditColorMaxValue );
349 whileBlocking( mColorRampShaderWidget )->setMinimumMaximum( min, max );
353 void QgsInterpolatedLineSymbolLayerWidget::onColorMinMaxLineTextEdited()
355 const double min = lineEditValue( mLineEditColorMinValue );
356 const double max = lineEditValue( mLineEditColorMaxValue );
357 whileBlocking( mColorRampShaderWidget )->setMinimumMaximumAndClassify( min, max );
379 interColor.
setColor( mColorButton->color() );
381 interColor.
setColor( colorRampShader );
387 double QgsInterpolatedLineSymbolLayerWidget::lineEditValue( QLineEdit *lineEdit )
389 if ( lineEdit->text().isEmpty() )
391 return std::numeric_limits<double>::quiet_NaN();
397 void QgsInterpolatedLineSymbolLayerWidget::setLineEditValue( QLineEdit *lineEdit,
double value )
400 if ( !std::isnan( value ) )
401 strValue = QLocale().toString( value );