QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgssymbollayerwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerwidget.cpp - symbol layer widgets
3 
4  ---------------------
5  begin : November 2009
6  copyright : (C) 2009 by Martin Dobias
7  email : wonder dot sk at gmail dot com
8  ***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgssymbollayerwidget.h"
18 
19 #include "qgslinesymbollayer.h"
20 #include "qgsmarkersymbollayer.h"
21 #include "qgsfillsymbollayer.h"
23 #include "qgssymbolslistwidget.h"
25 
26 #include "characterwidget.h"
27 #include "qgsdashspacedialog.h"
29 #include "qgssvgcache.h"
30 #include "qgssymbollayerutils.h"
31 #include "qgscolorramp.h"
32 #include "qgscolorrampbutton.h"
34 #include "qgsproperty.h"
35 #include "qgsstyle.h" //for symbol selector dialog
36 #include "qgsmapcanvas.h"
37 #include "qgsapplication.h"
38 #include "qgsvectorlayer.h"
39 #include "qgssvgselectorwidget.h"
40 #include "qgslogger.h"
41 #include "qgssettings.h"
44 #include "qgsauxiliarystorage.h"
45 #include "qgsimagecache.h"
46 
47 #include <QAbstractButton>
48 #include <QButtonGroup>
49 #include <QColorDialog>
50 #include <QCursor>
51 #include <QDir>
52 #include <QFileDialog>
53 #include <QPainter>
54 #include <QStandardItemModel>
55 #include <QSvgRenderer>
56 #include <QMessageBox>
57 #include <QMenu>
58 #include <QAction>
59 #include <QInputDialog>
60 
62 {
63  if ( mContext.expressionContext() )
64  return *mContext.expressionContext();
65 
67 
69  if ( const QgsSymbolLayer *symbolLayer = const_cast< QgsSymbolLayerWidget * >( this )->symbolLayer() )
70  {
71  //cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols*
72  //color, but that's not accessible here). 99% of the time these will be the same anyway
74  }
75  expContext << symbolScope;
76  expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT, 1, true ) );
77  expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1, true ) );
78  expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, 1, true ) );
79  expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1, true ) );
80 
81  // additional scopes
82  const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
83  for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
84  {
85  expContext.appendScope( new QgsExpressionContextScope( scope ) );
86  }
87 
88  //TODO - show actual value
89  expContext.setOriginalValueVariable( QVariant() );
90 
91  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
95 
96  return expContext;
97 }
98 
100 {
101  mContext = context;
102  const auto unitSelectionWidgets = findChildren<QgsUnitSelectionWidget *>();
103  for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
104  {
105  unitWidget->setMapCanvas( mContext.mapCanvas() );
106  }
107 }
108 
110 {
111  return mContext;
112 }
113 
115 {
116  button->init( key, symbolLayer()->dataDefinedProperties(), QgsSymbolLayer::propertyDefinitions(), mVectorLayer, true );
118  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolLayerWidget::createAuxiliaryField );
119 
120  button->registerExpressionContextGenerator( this );
121 }
122 
123 void QgsSymbolLayerWidget::createAuxiliaryField()
124 {
125  // try to create an auxiliary layer if not yet created
126  if ( !mVectorLayer->auxiliaryLayer() )
127  {
128  QgsNewAuxiliaryLayerDialog dlg( mVectorLayer, this );
129  dlg.exec();
130  }
131 
132  // return if still not exists
133  if ( !mVectorLayer->auxiliaryLayer() )
134  return;
135 
136  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
137  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
139 
140  // create property in auxiliary storage if necessary
141  if ( !mVectorLayer->auxiliaryLayer()->exists( def ) )
142  {
143  QgsNewAuxiliaryFieldDialog dlg( def, mVectorLayer, true, this );
144  if ( dlg.exec() == QDialog::Accepted )
145  def = dlg.propertyDefinition();
146  }
147 
148  // return if still not exist
149  if ( !mVectorLayer->auxiliaryLayer()->exists( def ) )
150  return;
151 
152  // update property with join field name from auxiliary storage
153  QgsProperty property = button->toProperty();
154  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
155  property.setActive( true );
156  button->updateFieldLists();
157  button->setToProperty( property );
158  symbolLayer()->setDataDefinedProperty( key, button->toProperty() );
159 
160  emit changed();
161 }
162 
164 {
165  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
166  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
167  symbolLayer()->setDataDefinedProperty( key, button->toProperty() );
168  emit changed();
169 }
170 
172  : QgsSymbolLayerWidget( parent, vl )
173 {
174  mLayer = nullptr;
175 
176  setupUi( this );
177  connect( mCustomCheckBox, &QCheckBox::stateChanged, this, &QgsSimpleLineSymbolLayerWidget::mCustomCheckBox_stateChanged );
178  connect( mChangePatternButton, &QPushButton::clicked, this, &QgsSimpleLineSymbolLayerWidget::mChangePatternButton_clicked );
179  connect( mPenWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleLineSymbolLayerWidget::mPenWidthUnitWidget_changed );
180  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleLineSymbolLayerWidget::mOffsetUnitWidget_changed );
181  connect( mDashPatternUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleLineSymbolLayerWidget::mDashPatternUnitWidget_changed );
182  connect( mDrawInsideCheckBox, &QCheckBox::stateChanged, this, &QgsSimpleLineSymbolLayerWidget::mDrawInsideCheckBox_stateChanged );
189 
190  btnChangeColor->setAllowOpacity( true );
191  btnChangeColor->setColorDialogTitle( tr( "Select Line Color" ) );
192  btnChangeColor->setContext( QStringLiteral( "symbology" ) );
193 
194  mColorDDBtn->registerLinkedWidget( btnChangeColor );
195 
196  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconAllRings.svg" ) ), tr( "All Rings" ), QgsLineSymbolLayer::AllRings );
197  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconExteriorRing.svg" ) ), tr( "Exterior Ring Only" ), QgsLineSymbolLayer::ExteriorRingOnly );
198  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconInteriorRings.svg" ) ), tr( "Interior Rings Only" ), QgsLineSymbolLayer::InteriorRingsOnly );
199  connect( mRingFilterComboBox, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), this, [ = ]( int )
200  {
201  if ( mLayer )
202  {
203  mLayer->setRingFilter( static_cast< QgsLineSymbolLayer::RenderRingFilter >( mRingFilterComboBox->currentData().toInt() ) );
204  emit changed();
205  }
206  } );
207 
208  spinOffset->setClearValue( 0.0 );
209 
210  if ( vl && vl->geometryType() != QgsWkbTypes::PolygonGeometry )
211  {
212  //draw inside polygon checkbox only makes sense for polygon layers
213  mDrawInsideCheckBox->hide();
214  mRingFilterComboBox->hide();
215  mRingsLabel->hide();
216  }
217 
218  //make a temporary symbol for the size assistant preview
219  mAssistantPreviewSymbol.reset( new QgsLineSymbol() );
220 
221  if ( vectorLayer() )
222  mPenWidthDDBtn->setSymbol( mAssistantPreviewSymbol );
223 
224  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleLineSymbolLayerWidget::penWidthChanged );
225  connect( btnChangeColor, &QgsColorButton::colorChanged, this, &QgsSimpleLineSymbolLayerWidget::colorChanged );
226  connect( cboPenStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleLineSymbolLayerWidget::penStyleChanged );
227  connect( spinOffset, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleLineSymbolLayerWidget::offsetChanged );
228  connect( cboCapStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleLineSymbolLayerWidget::penStyleChanged );
229  connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleLineSymbolLayerWidget::penStyleChanged );
230 
232 
233  connect( this, &QgsSymbolLayerWidget::changed, this, &QgsSimpleLineSymbolLayerWidget::updateAssistantSymbol );
234 }
235 
236 void QgsSimpleLineSymbolLayerWidget::updateAssistantSymbol()
237 {
238  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
239  {
240  mAssistantPreviewSymbol->deleteSymbolLayer( i );
241  }
242  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
244  if ( ddWidth )
245  mAssistantPreviewSymbol->setDataDefinedWidth( ddWidth );
246 }
247 
248 
250 {
251  if ( !layer || layer->layerType() != QLatin1String( "SimpleLine" ) )
252  return;
253 
254  // layer type is correct, we can do the cast
255  mLayer = static_cast<QgsSimpleLineSymbolLayer *>( layer );
256 
257  // set units
258  mPenWidthUnitWidget->blockSignals( true );
259  mPenWidthUnitWidget->setUnit( mLayer->widthUnit() );
260  mPenWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
261  mPenWidthUnitWidget->blockSignals( false );
262  mOffsetUnitWidget->blockSignals( true );
263  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
264  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
265  mOffsetUnitWidget->blockSignals( false );
266  mDashPatternUnitWidget->blockSignals( true );
267  mDashPatternUnitWidget->setUnit( mLayer->customDashPatternUnit() );
268  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
269  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
270  mDashPatternUnitWidget->blockSignals( false );
271 
272  // set values
273  spinWidth->blockSignals( true );
274  spinWidth->setValue( mLayer->width() );
275  spinWidth->blockSignals( false );
276  btnChangeColor->blockSignals( true );
277  btnChangeColor->setColor( mLayer->color() );
278  btnChangeColor->blockSignals( false );
279  spinOffset->blockSignals( true );
280  spinOffset->setValue( mLayer->offset() );
281  spinOffset->blockSignals( false );
282  cboPenStyle->blockSignals( true );
283  cboJoinStyle->blockSignals( true );
284  cboCapStyle->blockSignals( true );
285  cboPenStyle->setPenStyle( mLayer->penStyle() );
286  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
287  cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
288  cboPenStyle->blockSignals( false );
289  cboJoinStyle->blockSignals( false );
290  cboCapStyle->blockSignals( false );
291 
292  //use a custom dash pattern?
293  bool useCustomDashPattern = mLayer->useCustomDashPattern();
294  mChangePatternButton->setEnabled( useCustomDashPattern );
295  label_3->setEnabled( !useCustomDashPattern );
296  cboPenStyle->setEnabled( !useCustomDashPattern );
297  mCustomCheckBox->blockSignals( true );
298  mCustomCheckBox->setCheckState( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
299  mCustomCheckBox->blockSignals( false );
300 
301  //make sure height of custom dash button looks good under different platforms
302  QSize size = mChangePatternButton->minimumSizeHint();
303  int fontHeight = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.4 );
304  mChangePatternButton->setMinimumSize( QSize( size.width(), std::max( size.height(), fontHeight ) ) );
305 
306  //draw inside polygon?
307  const bool drawInsidePolygon = mLayer->drawInsidePolygon();
308  whileBlocking( mDrawInsideCheckBox )->setCheckState( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
309 
310  whileBlocking( mRingFilterComboBox )->setCurrentIndex( mRingFilterComboBox->findData( mLayer->ringFilter() ) );
311 
313 
321 
322  updateAssistantSymbol();
323 }
324 
326 {
327  return mLayer;
328 }
329 
330 void QgsSimpleLineSymbolLayerWidget::penWidthChanged()
331 {
332  mLayer->setWidth( spinWidth->value() );
334  emit changed();
335 }
336 
337 void QgsSimpleLineSymbolLayerWidget::colorChanged( const QColor &color )
338 {
339  mLayer->setColor( color );
340  emit changed();
341 }
342 
343 void QgsSimpleLineSymbolLayerWidget::penStyleChanged()
344 {
345  mLayer->setPenStyle( cboPenStyle->penStyle() );
346  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
347  mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
349  emit changed();
350 }
351 
352 void QgsSimpleLineSymbolLayerWidget::offsetChanged()
353 {
354  mLayer->setOffset( spinOffset->value() );
356  emit changed();
357 }
358 
359 void QgsSimpleLineSymbolLayerWidget::mCustomCheckBox_stateChanged( int state )
360 {
361  bool checked = ( state == Qt::Checked );
362  mChangePatternButton->setEnabled( checked );
363  label_3->setEnabled( !checked );
364  cboPenStyle->setEnabled( !checked );
365 
366  mLayer->setUseCustomDashPattern( checked );
367  emit changed();
368 }
369 
370 void QgsSimpleLineSymbolLayerWidget::mChangePatternButton_clicked()
371 {
373  if ( panel && panel->dockMode() )
374  {
376  widget->setPanelTitle( tr( "Custom Dash Pattern" ) );
377  widget->setUnit( mDashPatternUnitWidget->unit() );
378  connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
379  {
382  } );
384  panel->openPanel( widget );
385  return;
386  }
387 
389  d.setUnit( mDashPatternUnitWidget->unit() );
390  if ( d.exec() == QDialog::Accepted )
391  {
392  mLayer->setCustomDashVector( d.dashDotVector() );
394  emit changed();
395  }
396 }
397 
398 void QgsSimpleLineSymbolLayerWidget::mPenWidthUnitWidget_changed()
399 {
400  if ( mLayer )
401  {
402  mLayer->setWidthUnit( mPenWidthUnitWidget->unit() );
403  mLayer->setWidthMapUnitScale( mPenWidthUnitWidget->getMapUnitScale() );
405  emit changed();
406  }
407 }
408 
409 void QgsSimpleLineSymbolLayerWidget::mOffsetUnitWidget_changed()
410 {
411  if ( mLayer )
412  {
413  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
414  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
415  emit changed();
416  }
417 }
418 
419 void QgsSimpleLineSymbolLayerWidget::mDashPatternUnitWidget_changed()
420 {
421  if ( mLayer )
422  {
423  mLayer->setCustomDashPatternUnit( mDashPatternUnitWidget->unit() );
424  mLayer->setCustomDashPatternMapUnitScale( mDashPatternUnitWidget->getMapUnitScale() );
426  emit changed();
427  }
428 }
429 
430 void QgsSimpleLineSymbolLayerWidget::mDrawInsideCheckBox_stateChanged( int state )
431 {
432  bool checked = ( state == Qt::Checked );
433  mLayer->setDrawInsidePolygon( checked );
434  emit changed();
435 }
436 
437 
439 {
440  if ( !mLayer )
441  {
442  return;
443  }
444  std::unique_ptr< QgsSimpleLineSymbolLayer > layerCopy( mLayer->clone() );
445  if ( !layerCopy )
446  {
447  return;
448  }
449  QColor color = qApp->palette().color( QPalette::WindowText );
450  layerCopy->setColor( color );
451  // reset offset, we don't want to show that in the preview
452  layerCopy->setOffset( 0 );
453  layerCopy->setUseCustomDashPattern( true );
454 
455  QSize currentIconSize;
456  //icon size is button size with a small margin
457 #ifdef Q_OS_WIN
458  currentIconSize = QSize( mChangePatternButton->width() - 10, mChangePatternButton->height() - 6 );
459 #else
460  currentIconSize = QSize( mChangePatternButton->width() - 10, mChangePatternButton->height() - 12 );
461 #endif
462 
463  if ( !currentIconSize.isValid() || currentIconSize.width() <= 0 || currentIconSize.height() <= 0 )
464  {
465  return;
466  }
467 
468  //create an icon pixmap
469  std::unique_ptr< QgsLineSymbol > previewSymbol = qgis::make_unique< QgsLineSymbol >( QgsSymbolLayerList() << layerCopy.release() );
470  const QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( previewSymbol.get(), currentIconSize );
471  mChangePatternButton->setIconSize( currentIconSize );
472  mChangePatternButton->setIcon( icon );
473 
474  // set tooltip
475  // create very large preview image
476 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
477  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 23 );
478 #else
479  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 23 );
480 #endif
481  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
482 
483  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( previewSymbol.get(), QSize( width, height ), height / 20 );
484  QByteArray data;
485  QBuffer buffer( &data );
486  pm.save( &buffer, "PNG", 100 );
487  mChangePatternButton->setToolTip( QStringLiteral( "<img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) ) );
488 }
489 
491 {
492  QgsSymbolLayerWidget::resizeEvent( event );
493  // redraw custom dash pattern icon -- the button size has changed
495 }
496 
497 
499 
500 
502  : QgsSymbolLayerWidget( parent, vl )
503 {
504  mLayer = nullptr;
505 
506  setupUi( this );
507  connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
508  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
509  connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
510  connect( mStrokeStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged );
511  connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
512  connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
513  connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
520 
521  btnChangeColorFill->setAllowOpacity( true );
522  btnChangeColorFill->setColorDialogTitle( tr( "Select Fill Color" ) );
523  btnChangeColorFill->setContext( QStringLiteral( "symbology" ) );
524  btnChangeColorFill->setShowNoColor( true );
525  btnChangeColorFill->setNoColorString( tr( "Transparent Fill" ) );
526  btnChangeColorStroke->setAllowOpacity( true );
527  btnChangeColorStroke->setColorDialogTitle( tr( "Select Stroke Color" ) );
528  btnChangeColorStroke->setContext( QStringLiteral( "symbology" ) );
529  btnChangeColorStroke->setShowNoColor( true );
530  btnChangeColorStroke->setNoColorString( tr( "Transparent Stroke" ) );
531 
532  mFillColorDDBtn->registerLinkedWidget( btnChangeColorFill );
533  mStrokeColorDDBtn->registerLinkedWidget( btnChangeColorStroke );
534 
535  spinOffsetX->setClearValue( 0.0 );
536  spinOffsetY->setClearValue( 0.0 );
537  spinAngle->setClearValue( 0.0 );
538 
539  //make a temporary symbol for the size assistant preview
540  mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );
541 
542  if ( vectorLayer() )
543  mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );
544 
545  int size = lstNames->iconSize().width();
546 
547 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
548  size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
549 #else
550  size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
551 #endif
552 
553  lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
554  lstNames->setIconSize( QSize( size, size ) );
555 
556  double markerSize = size * 0.8;
558  for ( QgsSimpleMarkerSymbolLayerBase::Shape shape : shapes )
559  {
560  QgsSimpleMarkerSymbolLayer *lyr = new QgsSimpleMarkerSymbolLayer( shape, markerSize );
562  lyr->setColor( QColor( 200, 200, 200 ) );
563  lyr->setStrokeColor( QColor( 0, 0, 0 ) );
564  QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderPixels, QSize( size, size ) );
565  QListWidgetItem *item = new QListWidgetItem( icon, QString(), lstNames );
566  item->setData( Qt::UserRole, static_cast< int >( shape ) );
567  item->setToolTip( QgsSimpleMarkerSymbolLayerBase::encodeShape( shape ) );
568  delete lyr;
569  }
570  // show at least 3 rows
571  lstNames->setMinimumHeight( lstNames->gridSize().height() * 3.1 );
572 
573  connect( lstNames, &QListWidget::currentRowChanged, this, &QgsSimpleMarkerSymbolLayerWidget::setShape );
574  connect( btnChangeColorStroke, &QgsColorButton::colorChanged, this, &QgsSimpleMarkerSymbolLayerWidget::setColorStroke );
576  connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::penJoinStyleChanged );
577  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::setSize );
578  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::setAngle );
579  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::setOffset );
580  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleMarkerSymbolLayerWidget::setOffset );
581  connect( this, &QgsSymbolLayerWidget::changed, this, &QgsSimpleMarkerSymbolLayerWidget::updateAssistantSymbol );
582 }
583 
585 {
586  if ( layer->layerType() != QLatin1String( "SimpleMarker" ) )
587  return;
588 
589  // layer type is correct, we can do the cast
590  mLayer = static_cast<QgsSimpleMarkerSymbolLayer *>( layer );
591 
592  // set values
594  for ( int i = 0; i < lstNames->count(); ++i )
595  {
596  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
597  {
598  lstNames->setCurrentRow( i );
599  break;
600  }
601  }
602  btnChangeColorStroke->blockSignals( true );
603  btnChangeColorStroke->setColor( mLayer->strokeColor() );
604  btnChangeColorStroke->blockSignals( false );
605  btnChangeColorFill->blockSignals( true );
606  btnChangeColorFill->setColor( mLayer->fillColor() );
607  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
608  btnChangeColorFill->blockSignals( false );
609  spinSize->blockSignals( true );
610  spinSize->setValue( mLayer->size() );
611  spinSize->blockSignals( false );
612  spinAngle->blockSignals( true );
613  spinAngle->setValue( mLayer->angle() );
614  spinAngle->blockSignals( false );
615  mStrokeStyleComboBox->blockSignals( true );
616  mStrokeStyleComboBox->setPenStyle( mLayer->strokeStyle() );
617  mStrokeStyleComboBox->blockSignals( false );
618  mStrokeWidthSpinBox->blockSignals( true );
619  mStrokeWidthSpinBox->setValue( mLayer->strokeWidth() );
620  mStrokeWidthSpinBox->blockSignals( false );
621  cboJoinStyle->blockSignals( true );
622  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
623  cboJoinStyle->blockSignals( false );
624 
625  // without blocking signals the value gets changed because of slot setOffset()
626  spinOffsetX->blockSignals( true );
627  spinOffsetX->setValue( mLayer->offset().x() );
628  spinOffsetX->blockSignals( false );
629  spinOffsetY->blockSignals( true );
630  spinOffsetY->setValue( mLayer->offset().y() );
631  spinOffsetY->blockSignals( false );
632 
633  mSizeUnitWidget->blockSignals( true );
634  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
635  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
636  mSizeUnitWidget->blockSignals( false );
637  mOffsetUnitWidget->blockSignals( true );
638  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
639  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
640  mOffsetUnitWidget->blockSignals( false );
641  mStrokeWidthUnitWidget->blockSignals( true );
642  mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
643  mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
644  mStrokeWidthUnitWidget->blockSignals( false );
645 
646  //anchor points
647  mHorizontalAnchorComboBox->blockSignals( true );
648  mVerticalAnchorComboBox->blockSignals( true );
649  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
650  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
651  mHorizontalAnchorComboBox->blockSignals( false );
652  mVerticalAnchorComboBox->blockSignals( false );
653 
665 
666  updateAssistantSymbol();
667 }
668 
670 {
671  return mLayer;
672 }
673 
674 void QgsSimpleMarkerSymbolLayerWidget::setShape()
675 {
676  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
677  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
678  emit changed();
679 }
680 
682 {
683  mLayer->setStrokeColor( color );
684  emit changed();
685 }
686 
688 {
689  mLayer->setColor( color );
690  emit changed();
691 }
692 
693 void QgsSimpleMarkerSymbolLayerWidget::penJoinStyleChanged()
694 {
695  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
696  emit changed();
697 }
698 
699 void QgsSimpleMarkerSymbolLayerWidget::setSize()
700 {
701  mLayer->setSize( spinSize->value() );
702  emit changed();
703 }
704 
705 void QgsSimpleMarkerSymbolLayerWidget::setAngle()
706 {
707  mLayer->setAngle( spinAngle->value() );
708  emit changed();
709 }
710 
711 void QgsSimpleMarkerSymbolLayerWidget::setOffset()
712 {
713  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
714  emit changed();
715 }
716 
717 void QgsSimpleMarkerSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged( int index )
718 {
719  Q_UNUSED( index )
720 
721  if ( mLayer )
722  {
723  mLayer->setStrokeStyle( mStrokeStyleComboBox->penStyle() );
724  emit changed();
725  }
726 }
727 
728 void QgsSimpleMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
729 {
730  if ( mLayer )
731  {
732  mLayer->setStrokeWidth( d );
733  emit changed();
734  }
735 }
736 
737 void QgsSimpleMarkerSymbolLayerWidget::mSizeUnitWidget_changed()
738 {
739  if ( mLayer )
740  {
741  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
742  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
743  emit changed();
744  }
745 }
746 
747 void QgsSimpleMarkerSymbolLayerWidget::mOffsetUnitWidget_changed()
748 {
749  if ( mLayer )
750  {
751  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
752  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
753  emit changed();
754  }
755 }
756 
757 void QgsSimpleMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
758 {
759  if ( mLayer )
760  {
761  mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
762  mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
763  emit changed();
764  }
765 }
766 
767 void QgsSimpleMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
768 {
769  if ( mLayer )
770  {
772  emit changed();
773  }
774 }
775 
776 void QgsSimpleMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
777 {
778  if ( mLayer )
779  {
781  emit changed();
782  }
783 }
784 
785 void QgsSimpleMarkerSymbolLayerWidget::updateAssistantSymbol()
786 {
787  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
788  {
789  mAssistantPreviewSymbol->deleteSymbolLayer( i );
790  }
791  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
793  if ( ddSize )
794  mAssistantPreviewSymbol->setDataDefinedSize( ddSize );
795 }
796 
797 
799 
801  : QgsSymbolLayerWidget( parent, vl )
802 {
803  mLayer = nullptr;
804 
805  setupUi( this );
806  connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleFillSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
807  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSimpleFillSymbolLayerWidget::mOffsetUnitWidget_changed );
812 
813  btnChangeColor->setAllowOpacity( true );
814  btnChangeColor->setColorDialogTitle( tr( "Select Fill Color" ) );
815  btnChangeColor->setContext( QStringLiteral( "symbology" ) );
816  btnChangeColor->setShowNoColor( true );
817  btnChangeColor->setNoColorString( tr( "Transparent Fill" ) );
818  btnChangeStrokeColor->setAllowOpacity( true );
819  btnChangeStrokeColor->setColorDialogTitle( tr( "Select Stroke Color" ) );
820  btnChangeStrokeColor->setContext( QStringLiteral( "symbology" ) );
821  btnChangeStrokeColor->setShowNoColor( true );
822  btnChangeStrokeColor->setNoColorString( tr( "Transparent Stroke" ) );
823 
824  spinOffsetX->setClearValue( 0.0 );
825  spinOffsetY->setClearValue( 0.0 );
826 
828  connect( cboFillStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleFillSymbolLayerWidget::setBrushStyle );
829  connect( btnChangeStrokeColor, &QgsColorButton::colorChanged, this, &QgsSimpleFillSymbolLayerWidget::setStrokeColor );
830  connect( spinStrokeWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleFillSymbolLayerWidget::strokeWidthChanged );
831  connect( cboStrokeStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleFillSymbolLayerWidget::strokeStyleChanged );
832  connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSimpleFillSymbolLayerWidget::strokeStyleChanged );
833  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleFillSymbolLayerWidget::offsetChanged );
834  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSimpleFillSymbolLayerWidget::offsetChanged );
835 
836  mFillColorDDBtn->registerLinkedWidget( btnChangeColor );
837  mStrokeColorDDBtn->registerLinkedWidget( btnChangeStrokeColor );
838 }
839 
841 {
842  if ( layer->layerType() != QLatin1String( "SimpleFill" ) )
843  return;
844 
845  // layer type is correct, we can do the cast
846  mLayer = static_cast<QgsSimpleFillSymbolLayer *>( layer );
847 
848  // set values
849  btnChangeColor->blockSignals( true );
850  btnChangeColor->setColor( mLayer->color() );
851  btnChangeColor->blockSignals( false );
852  cboFillStyle->blockSignals( true );
853  cboFillStyle->setBrushStyle( mLayer->brushStyle() );
854  cboFillStyle->blockSignals( false );
855  btnChangeStrokeColor->blockSignals( true );
856  btnChangeStrokeColor->setColor( mLayer->strokeColor() );
857  btnChangeStrokeColor->blockSignals( false );
858  cboStrokeStyle->blockSignals( true );
859  cboStrokeStyle->setPenStyle( mLayer->strokeStyle() );
860  cboStrokeStyle->blockSignals( false );
861  spinStrokeWidth->blockSignals( true );
862  spinStrokeWidth->setValue( mLayer->strokeWidth() );
863  spinStrokeWidth->blockSignals( false );
864  cboJoinStyle->blockSignals( true );
865  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
866  cboJoinStyle->blockSignals( false );
867  spinOffsetX->blockSignals( true );
868  spinOffsetX->setValue( mLayer->offset().x() );
869  spinOffsetX->blockSignals( false );
870  spinOffsetY->blockSignals( true );
871  spinOffsetY->setValue( mLayer->offset().y() );
872  spinOffsetY->blockSignals( false );
873 
874  mStrokeWidthUnitWidget->blockSignals( true );
875  mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
876  mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
877  mStrokeWidthUnitWidget->blockSignals( false );
878  mOffsetUnitWidget->blockSignals( true );
879  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
880  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
881  mOffsetUnitWidget->blockSignals( false );
882 
889 
890 }
891 
893 {
894  return mLayer;
895 }
896 
897 void QgsSimpleFillSymbolLayerWidget::setColor( const QColor &color )
898 {
899  mLayer->setColor( color );
900  emit changed();
901 }
902 
904 {
905  mLayer->setStrokeColor( color );
906  emit changed();
907 }
908 
909 void QgsSimpleFillSymbolLayerWidget::setBrushStyle()
910 {
911  mLayer->setBrushStyle( cboFillStyle->brushStyle() );
912  emit changed();
913 }
914 
915 void QgsSimpleFillSymbolLayerWidget::strokeWidthChanged()
916 {
917  mLayer->setStrokeWidth( spinStrokeWidth->value() );
918  emit changed();
919 }
920 
921 void QgsSimpleFillSymbolLayerWidget::strokeStyleChanged()
922 {
923  mLayer->setStrokeStyle( cboStrokeStyle->penStyle() );
924  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
925  emit changed();
926 }
927 
928 void QgsSimpleFillSymbolLayerWidget::offsetChanged()
929 {
930  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
931  emit changed();
932 }
933 
934 void QgsSimpleFillSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
935 {
936  if ( mLayer )
937  {
938  mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
939  mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
940  emit changed();
941  }
942 }
943 
944 void QgsSimpleFillSymbolLayerWidget::mOffsetUnitWidget_changed()
945 {
946  if ( mLayer )
947  {
948  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
949  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
950  emit changed();
951  }
952 }
953 
955 
957  : QgsSymbolLayerWidget( parent, vl )
958 {
959  mLayer = nullptr;
960 
961  setupUi( this );
962  connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsFilledMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
963  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsFilledMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
964  connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFilledMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
965  connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFilledMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
970 
971  spinOffsetX->setClearValue( 0.0 );
972  spinOffsetY->setClearValue( 0.0 );
973  spinAngle->setClearValue( 0.0 );
974 
975  //make a temporary symbol for the size assistant preview
976  mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );
977 
978  if ( vectorLayer() )
979  mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );
980 
981  int size = lstNames->iconSize().width();
982 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
983  size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 3 ) ) );
984 #else
985  size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
986 #endif
987  lstNames->setGridSize( QSize( size * 1.2, size * 1.2 ) );
988  lstNames->setIconSize( QSize( size, size ) );
989 
990  double markerSize = size * 0.8;
992  for ( QgsSimpleMarkerSymbolLayerBase::Shape shape : shapes )
993  {
994  QgsSimpleMarkerSymbolLayer *lyr = new QgsSimpleMarkerSymbolLayer( shape, markerSize );
996  lyr->setColor( QColor( 200, 200, 200 ) );
997  lyr->setStrokeColor( QColor( 0, 0, 0 ) );
998  QIcon icon = QgsSymbolLayerUtils::symbolLayerPreviewIcon( lyr, QgsUnitTypes::RenderPixels, QSize( size, size ) );
999  QListWidgetItem *item = new QListWidgetItem( icon, QString(), lstNames );
1000  item->setData( Qt::UserRole, static_cast< int >( shape ) );
1001  item->setToolTip( QgsSimpleMarkerSymbolLayerBase::encodeShape( shape ) );
1002  delete lyr;
1003  }
1004  // show at least 3 rows
1005  lstNames->setMinimumHeight( lstNames->gridSize().height() * 3.1 );
1006 
1007  connect( lstNames, &QListWidget::currentRowChanged, this, &QgsFilledMarkerSymbolLayerWidget::setShape );
1008  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFilledMarkerSymbolLayerWidget::setSize );
1009  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFilledMarkerSymbolLayerWidget::setAngle );
1010  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFilledMarkerSymbolLayerWidget::setOffset );
1011  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFilledMarkerSymbolLayerWidget::setOffset );
1012  connect( this, &QgsSymbolLayerWidget::changed, this, &QgsFilledMarkerSymbolLayerWidget::updateAssistantSymbol );
1013 }
1014 
1016 {
1017  if ( layer->layerType() != QLatin1String( "FilledMarker" ) )
1018  return;
1019 
1020  // layer type is correct, we can do the cast
1021  mLayer = static_cast<QgsFilledMarkerSymbolLayer *>( layer );
1022 
1023  // set values
1025  for ( int i = 0; i < lstNames->count(); ++i )
1026  {
1027  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
1028  {
1029  lstNames->setCurrentRow( i );
1030  break;
1031  }
1032  }
1033  whileBlocking( spinSize )->setValue( mLayer->size() );
1034  whileBlocking( spinAngle )->setValue( mLayer->angle() );
1035  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
1036  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
1037 
1038  mSizeUnitWidget->blockSignals( true );
1039  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
1040  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
1041  mSizeUnitWidget->blockSignals( false );
1042  mOffsetUnitWidget->blockSignals( true );
1043  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1044  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1045  mOffsetUnitWidget->blockSignals( false );
1046 
1047  //anchor points
1048  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1049  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
1050 
1057 
1058  updateAssistantSymbol();
1059 }
1060 
1062 {
1063  return mLayer;
1064 }
1065 
1066 void QgsFilledMarkerSymbolLayerWidget::setShape()
1067 {
1068  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
1069  emit changed();
1070 }
1071 
1072 void QgsFilledMarkerSymbolLayerWidget::setSize()
1073 {
1074  mLayer->setSize( spinSize->value() );
1075  emit changed();
1076 }
1077 
1078 void QgsFilledMarkerSymbolLayerWidget::setAngle()
1079 {
1080  mLayer->setAngle( spinAngle->value() );
1081  emit changed();
1082 }
1083 
1084 void QgsFilledMarkerSymbolLayerWidget::setOffset()
1085 {
1086  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1087  emit changed();
1088 }
1089 
1090 void QgsFilledMarkerSymbolLayerWidget::mSizeUnitWidget_changed()
1091 {
1092  if ( mLayer )
1093  {
1094  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
1095  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
1096  emit changed();
1097  }
1098 }
1099 
1100 void QgsFilledMarkerSymbolLayerWidget::mOffsetUnitWidget_changed()
1101 {
1102  if ( mLayer )
1103  {
1104  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1105  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1106  emit changed();
1107  }
1108 }
1109 
1110 void QgsFilledMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
1111 {
1112  if ( mLayer )
1113  {
1115  emit changed();
1116  }
1117 }
1118 
1119 void QgsFilledMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
1120 {
1121  if ( mLayer )
1122  {
1124  emit changed();
1125  }
1126 }
1127 
1128 void QgsFilledMarkerSymbolLayerWidget::updateAssistantSymbol()
1129 {
1130  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1131  {
1132  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1133  }
1134  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1136  if ( ddSize )
1137  mAssistantPreviewSymbol->setDataDefinedSize( ddSize );
1138 }
1139 
1140 
1142 
1144  : QgsSymbolLayerWidget( parent, vl )
1145 {
1146  mLayer = nullptr;
1147 
1148  setupUi( this );
1149  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsGradientFillSymbolLayerWidget::mOffsetUnitWidget_changed );
1150  connect( mSpinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::mSpinAngle_valueChanged );
1153 
1154  btnColorRamp->setShowGradientOnly( true );
1155 
1156  btnChangeColor->setAllowOpacity( true );
1157  btnChangeColor->setColorDialogTitle( tr( "Select Gradient Color" ) );
1158  btnChangeColor->setContext( QStringLiteral( "symbology" ) );
1159  btnChangeColor->setShowNoColor( true );
1160  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1161  btnChangeColor2->setAllowOpacity( true );
1162  btnChangeColor2->setColorDialogTitle( tr( "Select Gradient Color" ) );
1163  btnChangeColor2->setContext( QStringLiteral( "symbology" ) );
1164  btnChangeColor2->setShowNoColor( true );
1165  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1166 
1167  mStartColorDDBtn->registerLinkedWidget( btnChangeColor );
1168  mEndColorDDBtn->registerLinkedWidget( btnChangeColor2 );
1169 
1170  spinOffsetX->setClearValue( 0.0 );
1171  spinOffsetY->setClearValue( 0.0 );
1172  mSpinAngle->setClearValue( 0.0 );
1173 
1177  connect( cboGradientType, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGradientFillSymbolLayerWidget::setGradientType );
1178  connect( cboCoordinateMode, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGradientFillSymbolLayerWidget::setCoordinateMode );
1179  connect( cboGradientSpread, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGradientFillSymbolLayerWidget::setGradientSpread );
1180  connect( radioTwoColor, &QAbstractButton::toggled, this, &QgsGradientFillSymbolLayerWidget::colorModeChanged );
1181  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::offsetChanged );
1182  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::offsetChanged );
1183  connect( spinRefPoint1X, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1184  connect( spinRefPoint1Y, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1185  connect( checkRefPoint1Centroid, &QAbstractButton::toggled, this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1186  connect( spinRefPoint2X, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1187  connect( spinRefPoint2Y, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1188  connect( checkRefPoint2Centroid, &QAbstractButton::toggled, this, &QgsGradientFillSymbolLayerWidget::referencePointChanged );
1189 }
1190 
1192 {
1193  if ( layer->layerType() != QLatin1String( "GradientFill" ) )
1194  return;
1195 
1196  // layer type is correct, we can do the cast
1197  mLayer = static_cast<QgsGradientFillSymbolLayer *>( layer );
1198 
1199  // set values
1200  btnChangeColor->blockSignals( true );
1201  btnChangeColor->setColor( mLayer->color() );
1202  btnChangeColor->blockSignals( false );
1203  btnChangeColor2->blockSignals( true );
1204  btnChangeColor2->setColor( mLayer->color2() );
1205  btnChangeColor2->blockSignals( false );
1206 
1208  {
1209  radioTwoColor->setChecked( true );
1210  btnColorRamp->setEnabled( false );
1211  }
1212  else
1213  {
1214  radioColorRamp->setChecked( true );
1215  btnChangeColor->setEnabled( false );
1216  btnChangeColor2->setEnabled( false );
1217  }
1218 
1219  // set source color ramp
1220  if ( mLayer->colorRamp() )
1221  {
1222  btnColorRamp->blockSignals( true );
1223  btnColorRamp->setColorRamp( mLayer->colorRamp() );
1224  btnColorRamp->blockSignals( false );
1225  }
1226 
1227  cboGradientType->blockSignals( true );
1228  switch ( mLayer->gradientType() )
1229  {
1231  cboGradientType->setCurrentIndex( 0 );
1232  break;
1234  cboGradientType->setCurrentIndex( 1 );
1235  break;
1237  cboGradientType->setCurrentIndex( 2 );
1238  break;
1239  }
1240  cboGradientType->blockSignals( false );
1241 
1242  cboCoordinateMode->blockSignals( true );
1243  switch ( mLayer->coordinateMode() )
1244  {
1246  cboCoordinateMode->setCurrentIndex( 1 );
1247  checkRefPoint1Centroid->setEnabled( false );
1248  checkRefPoint2Centroid->setEnabled( false );
1249  break;
1251  default:
1252  cboCoordinateMode->setCurrentIndex( 0 );
1253  break;
1254  }
1255  cboCoordinateMode->blockSignals( false );
1256 
1257  cboGradientSpread->blockSignals( true );
1258  switch ( mLayer->gradientSpread() )
1259  {
1261  cboGradientSpread->setCurrentIndex( 0 );
1262  break;
1264  cboGradientSpread->setCurrentIndex( 1 );
1265  break;
1267  cboGradientSpread->setCurrentIndex( 2 );
1268  break;
1269  }
1270  cboGradientSpread->blockSignals( false );
1271 
1272  spinRefPoint1X->blockSignals( true );
1273  spinRefPoint1X->setValue( mLayer->referencePoint1().x() );
1274  spinRefPoint1X->blockSignals( false );
1275  spinRefPoint1Y->blockSignals( true );
1276  spinRefPoint1Y->setValue( mLayer->referencePoint1().y() );
1277  spinRefPoint1Y->blockSignals( false );
1278  checkRefPoint1Centroid->blockSignals( true );
1279  checkRefPoint1Centroid->setChecked( mLayer->referencePoint1IsCentroid() );
1281  {
1282  spinRefPoint1X->setEnabled( false );
1283  spinRefPoint1Y->setEnabled( false );
1284  }
1285  checkRefPoint1Centroid->blockSignals( false );
1286  spinRefPoint2X->blockSignals( true );
1287  spinRefPoint2X->setValue( mLayer->referencePoint2().x() );
1288  spinRefPoint2X->blockSignals( false );
1289  spinRefPoint2Y->blockSignals( true );
1290  spinRefPoint2Y->setValue( mLayer->referencePoint2().y() );
1291  spinRefPoint2Y->blockSignals( false );
1292  checkRefPoint2Centroid->blockSignals( true );
1293  checkRefPoint2Centroid->setChecked( mLayer->referencePoint2IsCentroid() );
1295  {
1296  spinRefPoint2X->setEnabled( false );
1297  spinRefPoint2Y->setEnabled( false );
1298  }
1299  checkRefPoint2Centroid->blockSignals( false );
1300 
1301  spinOffsetX->blockSignals( true );
1302  spinOffsetX->setValue( mLayer->offset().x() );
1303  spinOffsetX->blockSignals( false );
1304  spinOffsetY->blockSignals( true );
1305  spinOffsetY->setValue( mLayer->offset().y() );
1306  spinOffsetY->blockSignals( false );
1307  mSpinAngle->blockSignals( true );
1308  mSpinAngle->setValue( mLayer->angle() );
1309  mSpinAngle->blockSignals( false );
1310 
1311  mOffsetUnitWidget->blockSignals( true );
1312  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1313  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1314  mOffsetUnitWidget->blockSignals( false );
1315 
1328 }
1329 
1331 {
1332  return mLayer;
1333 }
1334 
1336 {
1337  mLayer->setColor( color );
1338  emit changed();
1339 }
1340 
1342 {
1343  mLayer->setColor2( color );
1344  emit changed();
1345 }
1346 
1347 void QgsGradientFillSymbolLayerWidget::colorModeChanged()
1348 {
1349  if ( radioTwoColor->isChecked() )
1350  {
1352  }
1353  else
1354  {
1356  }
1357  emit changed();
1358 }
1359 
1361 {
1362  if ( btnColorRamp->isNull() )
1363  return;
1364 
1365  mLayer->setColorRamp( btnColorRamp->colorRamp()->clone() );
1366  emit changed();
1367 }
1368 
1370 {
1371  switch ( index )
1372  {
1373  case 0:
1375  //set sensible default reference points
1376  spinRefPoint1X->setValue( 0.5 );
1377  spinRefPoint1Y->setValue( 0 );
1378  spinRefPoint2X->setValue( 0.5 );
1379  spinRefPoint2Y->setValue( 1 );
1380  break;
1381  case 1:
1383  //set sensible default reference points
1384  spinRefPoint1X->setValue( 0 );
1385  spinRefPoint1Y->setValue( 0 );
1386  spinRefPoint2X->setValue( 1 );
1387  spinRefPoint2Y->setValue( 1 );
1388  break;
1389  case 2:
1391  spinRefPoint1X->setValue( 0.5 );
1392  spinRefPoint1Y->setValue( 0.5 );
1393  spinRefPoint2X->setValue( 1 );
1394  spinRefPoint2Y->setValue( 1 );
1395  break;
1396  }
1397  emit changed();
1398 }
1399 
1401 {
1402 
1403  switch ( index )
1404  {
1405  case 0:
1406  //feature coordinate mode
1408  //allow choice of centroid reference positions
1409  checkRefPoint1Centroid->setEnabled( true );
1410  checkRefPoint2Centroid->setEnabled( true );
1411  break;
1412  case 1:
1413  //viewport coordinate mode
1415  //disable choice of centroid reference positions
1416  checkRefPoint1Centroid->setChecked( Qt::Unchecked );
1417  checkRefPoint1Centroid->setEnabled( false );
1418  checkRefPoint2Centroid->setChecked( Qt::Unchecked );
1419  checkRefPoint2Centroid->setEnabled( false );
1420  break;
1421  }
1422 
1423  emit changed();
1424 }
1425 
1427 {
1428  switch ( index )
1429  {
1430  case 0:
1432  break;
1433  case 1:
1435  break;
1436  case 2:
1438  break;
1439  }
1440 
1441  emit changed();
1442 }
1443 
1444 void QgsGradientFillSymbolLayerWidget::offsetChanged()
1445 {
1446  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1447  emit changed();
1448 }
1449 
1450 void QgsGradientFillSymbolLayerWidget::referencePointChanged()
1451 {
1452  mLayer->setReferencePoint1( QPointF( spinRefPoint1X->value(), spinRefPoint1Y->value() ) );
1453  mLayer->setReferencePoint1IsCentroid( checkRefPoint1Centroid->isChecked() );
1454  mLayer->setReferencePoint2( QPointF( spinRefPoint2X->value(), spinRefPoint2Y->value() ) );
1455  mLayer->setReferencePoint2IsCentroid( checkRefPoint2Centroid->isChecked() );
1456  emit changed();
1457 }
1458 
1459 void QgsGradientFillSymbolLayerWidget::mSpinAngle_valueChanged( double value )
1460 {
1461  mLayer->setAngle( value );
1462  emit changed();
1463 }
1464 
1465 void QgsGradientFillSymbolLayerWidget::mOffsetUnitWidget_changed()
1466 {
1467  if ( mLayer )
1468  {
1469  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1470  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1471  emit changed();
1472  }
1473 }
1474 
1476 
1478  : QgsSymbolLayerWidget( parent, vl )
1479 {
1480  mLayer = nullptr;
1481 
1482  setupUi( this );
1483  connect( mSpinBlurRadius, qgis::overload< int >::of( &QSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinBlurRadius_valueChanged );
1484  connect( mSpinMaxDistance, qgis::overload< double >::of( &QDoubleSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::mSpinMaxDistance_valueChanged );
1485  connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShapeburstFillSymbolLayerWidget::mDistanceUnitWidget_changed );
1486  connect( mRadioUseWholeShape, &QRadioButton::toggled, this, &QgsShapeburstFillSymbolLayerWidget::mRadioUseWholeShape_toggled );
1487  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsShapeburstFillSymbolLayerWidget::mOffsetUnitWidget_changed );
1488  connect( mIgnoreRingsCheckBox, &QCheckBox::stateChanged, this, &QgsShapeburstFillSymbolLayerWidget::mIgnoreRingsCheckBox_stateChanged );
1493 
1494  QButtonGroup *group1 = new QButtonGroup( this );
1495  group1->addButton( radioColorRamp );
1496  group1->addButton( radioTwoColor );
1497  QButtonGroup *group2 = new QButtonGroup( this );
1498  group2->addButton( mRadioUseMaxDistance );
1499  group2->addButton( mRadioUseWholeShape );
1500  btnChangeColor->setAllowOpacity( true );
1501  btnChangeColor->setColorDialogTitle( tr( "Select Gradient Color" ) );
1502  btnChangeColor->setContext( QStringLiteral( "symbology" ) );
1503  btnChangeColor->setShowNoColor( true );
1504  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1505  btnChangeColor2->setAllowOpacity( true );
1506  btnChangeColor2->setColorDialogTitle( tr( "Select Gradient Color" ) );
1507  btnChangeColor2->setContext( QStringLiteral( "symbology" ) );
1508  btnChangeColor2->setShowNoColor( true );
1509  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1510 
1511  mStartColorDDBtn->registerLinkedWidget( btnChangeColor );
1512  mEndColorDDBtn->registerLinkedWidget( btnChangeColor2 );
1513 
1514  spinOffsetX->setClearValue( 0.0 );
1515  spinOffsetY->setClearValue( 0.0 );
1516 
1517  btnColorRamp->setShowGradientOnly( true );
1518 
1519  connect( btnColorRamp, &QgsColorRampButton::colorRampChanged, this, &QgsShapeburstFillSymbolLayerWidget::applyColorRamp );
1520 
1523  connect( radioTwoColor, &QAbstractButton::toggled, this, &QgsShapeburstFillSymbolLayerWidget::colorModeChanged );
1524  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::offsetChanged );
1525  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsShapeburstFillSymbolLayerWidget::offsetChanged );
1526 
1527  connect( mBlurSlider, &QAbstractSlider::valueChanged, mSpinBlurRadius, &QSpinBox::setValue );
1528  connect( mSpinBlurRadius, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mBlurSlider, &QAbstractSlider::setValue );
1529 }
1530 
1532 {
1533  if ( layer->layerType() != QLatin1String( "ShapeburstFill" ) )
1534  return;
1535 
1536  // layer type is correct, we can do the cast
1537  mLayer = static_cast<QgsShapeburstFillSymbolLayer *>( layer );
1538 
1539  // set values
1540  btnChangeColor->blockSignals( true );
1541  btnChangeColor->setColor( mLayer->color() );
1542  btnChangeColor->blockSignals( false );
1543  btnChangeColor2->blockSignals( true );
1544  btnChangeColor2->setColor( mLayer->color2() );
1545  btnChangeColor2->blockSignals( false );
1546 
1548  {
1549  radioTwoColor->setChecked( true );
1550  btnColorRamp->setEnabled( false );
1551  }
1552  else
1553  {
1554  radioColorRamp->setChecked( true );
1555  btnChangeColor->setEnabled( false );
1556  btnChangeColor2->setEnabled( false );
1557  }
1558 
1559  mSpinBlurRadius->blockSignals( true );
1560  mBlurSlider->blockSignals( true );
1561  mSpinBlurRadius->setValue( mLayer->blurRadius() );
1562  mBlurSlider->setValue( mLayer->blurRadius() );
1563  mSpinBlurRadius->blockSignals( false );
1564  mBlurSlider->blockSignals( false );
1565 
1566  mSpinMaxDistance->blockSignals( true );
1567  mSpinMaxDistance->setValue( mLayer->maxDistance() );
1568  mSpinMaxDistance->blockSignals( false );
1569 
1570  mRadioUseWholeShape->blockSignals( true );
1571  mRadioUseMaxDistance->blockSignals( true );
1572  if ( mLayer->useWholeShape() )
1573  {
1574  mRadioUseWholeShape->setChecked( true );
1575  mSpinMaxDistance->setEnabled( false );
1576  mDistanceUnitWidget->setEnabled( false );
1577  }
1578  else
1579  {
1580  mRadioUseMaxDistance->setChecked( true );
1581  mSpinMaxDistance->setEnabled( true );
1582  mDistanceUnitWidget->setEnabled( true );
1583  }
1584  mRadioUseWholeShape->blockSignals( false );
1585  mRadioUseMaxDistance->blockSignals( false );
1586 
1587  mDistanceUnitWidget->blockSignals( true );
1588  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
1589  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
1590  mDistanceUnitWidget->blockSignals( false );
1591 
1592  mIgnoreRingsCheckBox->blockSignals( true );
1593  mIgnoreRingsCheckBox->setCheckState( mLayer->ignoreRings() ? Qt::Checked : Qt::Unchecked );
1594  mIgnoreRingsCheckBox->blockSignals( false );
1595 
1596  // set source color ramp
1597  if ( mLayer->colorRamp() )
1598  {
1599  btnColorRamp->blockSignals( true );
1600  btnColorRamp->setColorRamp( mLayer->colorRamp() );
1601  btnColorRamp->blockSignals( false );
1602  }
1603 
1604  spinOffsetX->blockSignals( true );
1605  spinOffsetX->setValue( mLayer->offset().x() );
1606  spinOffsetX->blockSignals( false );
1607  spinOffsetY->blockSignals( true );
1608  spinOffsetY->setValue( mLayer->offset().y() );
1609  spinOffsetY->blockSignals( false );
1610  mOffsetUnitWidget->blockSignals( true );
1611  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1612  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1613  mOffsetUnitWidget->blockSignals( false );
1614 
1621 }
1622 
1624 {
1625  return mLayer;
1626 }
1627 
1629 {
1630  if ( mLayer )
1631  {
1632  mLayer->setColor( color );
1633  emit changed();
1634  }
1635 }
1636 
1638 {
1639  if ( mLayer )
1640  {
1641  mLayer->setColor2( color );
1642  emit changed();
1643  }
1644 }
1645 
1646 void QgsShapeburstFillSymbolLayerWidget::colorModeChanged()
1647 {
1648  if ( !mLayer )
1649  {
1650  return;
1651  }
1652 
1653  if ( radioTwoColor->isChecked() )
1654  {
1656  }
1657  else
1658  {
1660  }
1661  emit changed();
1662 }
1663 
1664 void QgsShapeburstFillSymbolLayerWidget::mSpinBlurRadius_valueChanged( int value )
1665 {
1666  if ( mLayer )
1667  {
1668  mLayer->setBlurRadius( value );
1669  emit changed();
1670  }
1671 }
1672 
1673 void QgsShapeburstFillSymbolLayerWidget::mSpinMaxDistance_valueChanged( double value )
1674 {
1675  if ( mLayer )
1676  {
1677  mLayer->setMaxDistance( value );
1678  emit changed();
1679  }
1680 }
1681 
1682 void QgsShapeburstFillSymbolLayerWidget::mDistanceUnitWidget_changed()
1683 {
1684  if ( mLayer )
1685  {
1686  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
1687  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
1688  emit changed();
1689  }
1690 }
1691 
1692 void QgsShapeburstFillSymbolLayerWidget::mRadioUseWholeShape_toggled( bool value )
1693 {
1694  if ( mLayer )
1695  {
1696  mLayer->setUseWholeShape( value );
1697  mDistanceUnitWidget->setEnabled( !value );
1698  emit changed();
1699  }
1700 }
1701 
1702 void QgsShapeburstFillSymbolLayerWidget::applyColorRamp()
1703 {
1704  QgsColorRamp *ramp = btnColorRamp->colorRamp();
1705  if ( !ramp )
1706  return;
1707 
1708  mLayer->setColorRamp( ramp );
1709  emit changed();
1710 }
1711 
1712 void QgsShapeburstFillSymbolLayerWidget::offsetChanged()
1713 {
1714  if ( mLayer )
1715  {
1716  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1717  emit changed();
1718  }
1719 }
1720 
1721 void QgsShapeburstFillSymbolLayerWidget::mOffsetUnitWidget_changed()
1722 {
1723  if ( mLayer )
1724  {
1725  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1726  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1727  emit changed();
1728  }
1729 }
1730 
1731 
1732 void QgsShapeburstFillSymbolLayerWidget::mIgnoreRingsCheckBox_stateChanged( int state )
1733 {
1734  bool checked = ( state == Qt::Checked );
1735  mLayer->setIgnoreRings( checked );
1736  emit changed();
1737 }
1738 
1740 
1742  : QgsSymbolLayerWidget( parent, vl )
1743 {
1744  mLayer = nullptr;
1745 
1746  setupUi( this );
1747  connect( mIntervalUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsMarkerLineSymbolLayerWidget::mIntervalUnitWidget_changed );
1748  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsMarkerLineSymbolLayerWidget::mOffsetUnitWidget_changed );
1749  connect( mOffsetAlongLineUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsMarkerLineSymbolLayerWidget::mOffsetAlongLineUnitWidget_changed );
1750  connect( mAverageAngleUnit, &QgsUnitSelectionWidget::changed, this, &QgsMarkerLineSymbolLayerWidget::averageAngleUnitChanged );
1759 
1760  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconAllRings.svg" ) ), tr( "All Rings" ), QgsLineSymbolLayer::AllRings );
1761  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconExteriorRing.svg" ) ), tr( "Exterior Ring Only" ), QgsLineSymbolLayer::ExteriorRingOnly );
1762  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconInteriorRings.svg" ) ), tr( "Interior Rings Only" ), QgsLineSymbolLayer::InteriorRingsOnly );
1763  connect( mRingFilterComboBox, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), this, [ = ]( int )
1764  {
1765  if ( mLayer )
1766  {
1767  mLayer->setRingFilter( static_cast< QgsLineSymbolLayer::RenderRingFilter >( mRingFilterComboBox->currentData().toInt() ) );
1768  emit changed();
1769  }
1770  } );
1771 
1772  spinOffset->setClearValue( 0.0 );
1773 
1774 
1775  if ( vl && vl->geometryType() != QgsWkbTypes::PolygonGeometry )
1776  {
1777  mRingFilterComboBox->hide();
1778  mRingsLabel->hide();
1779  }
1780 
1781  mSpinAverageAngleLength->setClearValue( 4.0 );
1782 
1783  connect( spinInterval, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMarkerLineSymbolLayerWidget::setInterval );
1784  connect( mSpinOffsetAlongLine, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMarkerLineSymbolLayerWidget::setOffsetAlongLine );
1785  connect( chkRotateMarker, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setRotate );
1786  connect( spinOffset, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMarkerLineSymbolLayerWidget::setOffset );
1787  connect( mSpinAverageAngleLength, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMarkerLineSymbolLayerWidget::setAverageAngle );
1788  connect( radInterval, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1789  connect( radVertex, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1790  connect( radVertexLast, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1791  connect( radVertexFirst, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1792  connect( radCentralPoint, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1793  connect( radCurvePoint, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1794  connect( radSegmentCentralPoint, &QAbstractButton::clicked, this, &QgsMarkerLineSymbolLayerWidget::setPlacement );
1795 }
1796 
1798 {
1799  if ( layer->layerType() != QLatin1String( "MarkerLine" ) )
1800  return;
1801 
1802  // layer type is correct, we can do the cast
1803  mLayer = static_cast<QgsMarkerLineSymbolLayer *>( layer );
1804 
1805  // set values
1806  spinInterval->blockSignals( true );
1807  spinInterval->setValue( mLayer->interval() );
1808  spinInterval->blockSignals( false );
1809  mSpinOffsetAlongLine->blockSignals( true );
1810  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
1811  mSpinOffsetAlongLine->blockSignals( false );
1812  chkRotateMarker->blockSignals( true );
1813  chkRotateMarker->setChecked( mLayer->rotateSymbols() );
1814  chkRotateMarker->blockSignals( false );
1815  spinOffset->blockSignals( true );
1816  spinOffset->setValue( mLayer->offset() );
1817  spinOffset->blockSignals( false );
1819  radInterval->setChecked( true );
1821  radVertex->setChecked( true );
1823  radVertexLast->setChecked( true );
1825  radCentralPoint->setChecked( true );
1827  radCurvePoint->setChecked( true );
1829  radSegmentCentralPoint->setChecked( true );
1830  else
1831  radVertexFirst->setChecked( true );
1832 
1833  // set units
1834  mIntervalUnitWidget->blockSignals( true );
1835  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
1836  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
1837  mIntervalUnitWidget->blockSignals( false );
1838  mOffsetUnitWidget->blockSignals( true );
1839  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1840  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1841  mOffsetUnitWidget->blockSignals( false );
1842  mOffsetAlongLineUnitWidget->blockSignals( true );
1843  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
1844  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
1845  mOffsetAlongLineUnitWidget->blockSignals( false );
1846 
1847  whileBlocking( mAverageAngleUnit )->setUnit( mLayer->averageAngleUnit() );
1848  whileBlocking( mAverageAngleUnit )->setMapUnitScale( mLayer->averageAngleMapUnitScale() );
1849  whileBlocking( mSpinAverageAngleLength )->setValue( mLayer->averageAngleLength() );
1850 
1851  whileBlocking( mRingFilterComboBox )->setCurrentIndex( mRingFilterComboBox->findData( mLayer->ringFilter() ) );
1852 
1853  setPlacement(); // update gui
1854 
1860 }
1861 
1863 {
1864  return mLayer;
1865 }
1866 
1868 {
1869  mLayer->setInterval( val );
1870  emit changed();
1871 }
1872 
1874 {
1875  mLayer->setOffsetAlongLine( val );
1876  emit changed();
1877 }
1878 
1879 void QgsMarkerLineSymbolLayerWidget::setRotate()
1880 {
1881  mSpinAverageAngleLength->setEnabled( chkRotateMarker->isChecked() && ( radInterval->isChecked() || radCentralPoint->isChecked() ) );
1882  mAverageAngleUnit->setEnabled( mSpinAverageAngleLength->isEnabled() );
1883 
1884  mLayer->setRotateSymbols( chkRotateMarker->isChecked() );
1885  emit changed();
1886 }
1887 
1888 void QgsMarkerLineSymbolLayerWidget::setOffset()
1889 {
1890  mLayer->setOffset( spinOffset->value() );
1891  emit changed();
1892 }
1893 
1894 void QgsMarkerLineSymbolLayerWidget::setPlacement()
1895 {
1896  bool interval = radInterval->isChecked();
1897  spinInterval->setEnabled( interval );
1898  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
1899  mOffsetAlongLineUnitWidget->setEnabled( mSpinOffsetAlongLine->isEnabled() );
1900  mSpinAverageAngleLength->setEnabled( chkRotateMarker->isChecked() && ( radInterval->isChecked() || radCentralPoint->isChecked() ) );
1901  mAverageAngleUnit->setEnabled( mSpinAverageAngleLength->isEnabled() );
1902  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayer::Interval : QgsMarkerLineSymbolLayer::Vertex );
1903  if ( radInterval->isChecked() )
1905  else if ( radVertex->isChecked() )
1907  else if ( radVertexLast->isChecked() )
1909  else if ( radVertexFirst->isChecked() )
1911  else if ( radCurvePoint->isChecked() )
1913  else if ( radSegmentCentralPoint->isChecked() )
1915  else
1917 
1918  emit changed();
1919 }
1920 
1921 void QgsMarkerLineSymbolLayerWidget::mIntervalUnitWidget_changed()
1922 {
1923  if ( mLayer )
1924  {
1925  mLayer->setIntervalUnit( mIntervalUnitWidget->unit() );
1926  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
1927  emit changed();
1928  }
1929 }
1930 
1931 void QgsMarkerLineSymbolLayerWidget::mOffsetUnitWidget_changed()
1932 {
1933  if ( mLayer )
1934  {
1935  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1936  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1937  emit changed();
1938  }
1939 }
1940 
1941 void QgsMarkerLineSymbolLayerWidget::mOffsetAlongLineUnitWidget_changed()
1942 {
1943  if ( mLayer )
1944  {
1945  mLayer->setOffsetAlongLineUnit( mOffsetAlongLineUnitWidget->unit() );
1946  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
1947  }
1948  emit changed();
1949 }
1950 
1951 void QgsMarkerLineSymbolLayerWidget::averageAngleUnitChanged()
1952 {
1953  if ( mLayer )
1954  {
1955  mLayer->setAverageAngleUnit( mAverageAngleUnit->unit() );
1956  mLayer->setAverageAngleMapUnitScale( mAverageAngleUnit->getMapUnitScale() );
1957  }
1958  emit changed();
1959 }
1960 
1961 void QgsMarkerLineSymbolLayerWidget::setAverageAngle( double val )
1962 {
1963  if ( mLayer )
1964  {
1965  mLayer->setAverageAngleLength( val );
1966  emit changed();
1967  }
1968 }
1969 
1970 
1972 
1974  : QgsSymbolLayerWidget( parent, vl )
1975 {
1976  mLayer = nullptr;
1977 
1978  setupUi( this );
1979  connect( mIntervalUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsHashedLineSymbolLayerWidget::mIntervalUnitWidget_changed );
1980  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsHashedLineSymbolLayerWidget::mOffsetUnitWidget_changed );
1981  connect( mOffsetAlongLineUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsHashedLineSymbolLayerWidget::mOffsetAlongLineUnitWidget_changed );
1982  connect( mAverageAngleUnit, &QgsUnitSelectionWidget::changed, this, &QgsHashedLineSymbolLayerWidget::averageAngleUnitChanged );
1983  connect( mHashLengthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsHashedLineSymbolLayerWidget::hashLengthUnitWidgetChanged );
1994 
1995  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconAllRings.svg" ) ), tr( "All Rings" ), QgsLineSymbolLayer::AllRings );
1996  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconExteriorRing.svg" ) ), tr( "Exterior Ring Only" ), QgsLineSymbolLayer::ExteriorRingOnly );
1997  mRingFilterComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "mIconInteriorRings.svg" ) ), tr( "Interior Rings Only" ), QgsLineSymbolLayer::InteriorRingsOnly );
1998  connect( mRingFilterComboBox, qgis::overload< int >::of( &QComboBox::currentIndexChanged ), this, [ = ]( int )
1999  {
2000  if ( mLayer )
2001  {
2002  mLayer->setRingFilter( static_cast< QgsLineSymbolLayer::RenderRingFilter >( mRingFilterComboBox->currentData().toInt() ) );
2003  emit changed();
2004  }
2005  } );
2006 
2007  spinOffset->setClearValue( 0.0 );
2008 
2009 
2010  if ( vl && vl->geometryType() != QgsWkbTypes::PolygonGeometry )
2011  {
2012  mRingFilterComboBox->hide();
2013  mRingsLabel->hide();
2014  }
2015 
2016  mHashRotationSpinBox->setClearValue( 0 );
2017  mSpinAverageAngleLength->setClearValue( 4.0 );
2018 
2019  connect( spinInterval, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setInterval );
2020  connect( mSpinOffsetAlongLine, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setOffsetAlongLine );
2021  connect( mSpinHashLength, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setHashLength );
2022  connect( mHashRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setHashAngle );
2023  connect( chkRotateMarker, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setRotate );
2024  connect( spinOffset, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setOffset );
2025  connect( mSpinAverageAngleLength, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsHashedLineSymbolLayerWidget::setAverageAngle );
2026  connect( radInterval, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2027  connect( radVertex, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2028  connect( radVertexLast, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2029  connect( radVertexFirst, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2030  connect( radCentralPoint, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2031  connect( radCurvePoint, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2032  connect( radSegmentCentralPoint, &QAbstractButton::clicked, this, &QgsHashedLineSymbolLayerWidget::setPlacement );
2033 }
2034 
2036 {
2037  if ( layer->layerType() != QLatin1String( "HashLine" ) )
2038  return;
2039 
2040  // layer type is correct, we can do the cast
2041  mLayer = static_cast<QgsHashedLineSymbolLayer *>( layer );
2042 
2043  // set values
2044  spinInterval->blockSignals( true );
2045  spinInterval->setValue( mLayer->interval() );
2046  spinInterval->blockSignals( false );
2047  mSpinOffsetAlongLine->blockSignals( true );
2048  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
2049  mSpinOffsetAlongLine->blockSignals( false );
2050  whileBlocking( mSpinHashLength )->setValue( mLayer->hashLength() );
2051  whileBlocking( mHashRotationSpinBox )->setValue( mLayer->hashAngle() );
2052  chkRotateMarker->blockSignals( true );
2053  chkRotateMarker->setChecked( mLayer->rotateSymbols() );
2054  chkRotateMarker->blockSignals( false );
2055  spinOffset->blockSignals( true );
2056  spinOffset->setValue( mLayer->offset() );
2057  spinOffset->blockSignals( false );
2059  radInterval->setChecked( true );
2060  else if ( mLayer->placement() == QgsTemplatedLineSymbolLayerBase::Vertex )
2061  radVertex->setChecked( true );
2063  radVertexLast->setChecked( true );
2065  radCentralPoint->setChecked( true );
2067  radCurvePoint->setChecked( true );
2069  radSegmentCentralPoint->setChecked( true );
2070  else
2071  radVertexFirst->setChecked( true );
2072 
2073  // set units
2074  mIntervalUnitWidget->blockSignals( true );
2075  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
2076  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
2077  mIntervalUnitWidget->blockSignals( false );
2078  mOffsetUnitWidget->blockSignals( true );
2079  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2080  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2081  mOffsetUnitWidget->blockSignals( false );
2082  mOffsetAlongLineUnitWidget->blockSignals( true );
2083  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
2084  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
2085  mOffsetAlongLineUnitWidget->blockSignals( false );
2086  whileBlocking( mAverageAngleUnit )->setUnit( mLayer->averageAngleUnit() );
2087  whileBlocking( mAverageAngleUnit )->setMapUnitScale( mLayer->averageAngleMapUnitScale() );
2088  whileBlocking( mSpinAverageAngleLength )->setValue( mLayer->averageAngleLength() );
2089  whileBlocking( mHashLengthUnitWidget )->setUnit( mLayer->hashLengthUnit() );
2090  whileBlocking( mHashLengthUnitWidget )->setMapUnitScale( mLayer->hashLengthMapUnitScale() );
2091 
2092  whileBlocking( mRingFilterComboBox )->setCurrentIndex( mRingFilterComboBox->findData( mLayer->ringFilter() ) );
2093 
2094  setPlacement(); // update gui
2095 
2103 }
2104 
2106 {
2107  return mLayer;
2108 }
2109 
2110 void QgsHashedLineSymbolLayerWidget::setInterval( double val )
2111 {
2112  mLayer->setInterval( val );
2113  emit changed();
2114 }
2115 
2116 void QgsHashedLineSymbolLayerWidget::setOffsetAlongLine( double val )
2117 {
2118  mLayer->setOffsetAlongLine( val );
2119  emit changed();
2120 }
2121 
2122 void QgsHashedLineSymbolLayerWidget::setHashLength( double val )
2123 {
2124  mLayer->setHashLength( val );
2125  emit changed();
2126 }
2127 
2128 void QgsHashedLineSymbolLayerWidget::setHashAngle( double val )
2129 {
2130  mLayer->setHashAngle( val );
2131  emit changed();
2132 }
2133 
2134 void QgsHashedLineSymbolLayerWidget::setRotate()
2135 {
2136  mSpinAverageAngleLength->setEnabled( chkRotateMarker->isChecked() && ( radInterval->isChecked() || radCentralPoint->isChecked() ) );
2137  mAverageAngleUnit->setEnabled( mSpinAverageAngleLength->isEnabled() );
2138 
2139  mLayer->setRotateSymbols( chkRotateMarker->isChecked() );
2140  emit changed();
2141 }
2142 
2143 void QgsHashedLineSymbolLayerWidget::setOffset()
2144 {
2145  mLayer->setOffset( spinOffset->value() );
2146  emit changed();
2147 }
2148 
2149 void QgsHashedLineSymbolLayerWidget::setPlacement()
2150 {
2151  bool interval = radInterval->isChecked();
2152  spinInterval->setEnabled( interval );
2153  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
2154  mOffsetAlongLineUnitWidget->setEnabled( mSpinOffsetAlongLine->isEnabled() );
2155  mSpinAverageAngleLength->setEnabled( chkRotateMarker->isChecked() && ( radInterval->isChecked() || radCentralPoint->isChecked() ) );
2156  mAverageAngleUnit->setEnabled( mSpinAverageAngleLength->isEnabled() );
2157  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayer::Interval : QgsMarkerLineSymbolLayer::Vertex );
2158  if ( radInterval->isChecked() )
2160  else if ( radVertex->isChecked() )
2162  else if ( radVertexLast->isChecked() )
2164  else if ( radVertexFirst->isChecked() )
2166  else if ( radCurvePoint->isChecked() )
2168  else if ( radSegmentCentralPoint->isChecked() )
2170  else
2172 
2173  emit changed();
2174 }
2175 
2176 void QgsHashedLineSymbolLayerWidget::mIntervalUnitWidget_changed()
2177 {
2178  if ( mLayer )
2179  {
2180  mLayer->setIntervalUnit( mIntervalUnitWidget->unit() );
2181  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
2182  emit changed();
2183  }
2184 }
2185 
2186 void QgsHashedLineSymbolLayerWidget::mOffsetUnitWidget_changed()
2187 {
2188  if ( mLayer )
2189  {
2190  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2191  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2192  emit changed();
2193  }
2194 }
2195 
2196 void QgsHashedLineSymbolLayerWidget::mOffsetAlongLineUnitWidget_changed()
2197 {
2198  if ( mLayer )
2199  {
2200  mLayer->setOffsetAlongLineUnit( mOffsetAlongLineUnitWidget->unit() );
2201  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
2202  }
2203  emit changed();
2204 }
2205 
2206 void QgsHashedLineSymbolLayerWidget::hashLengthUnitWidgetChanged()
2207 {
2208  if ( mLayer )
2209  {
2210  mLayer->setHashLengthUnit( mHashLengthUnitWidget->unit() );
2211  mLayer->setHashLengthMapUnitScale( mHashLengthUnitWidget->getMapUnitScale() );
2212  }
2213  emit changed();
2214 }
2215 
2216 void QgsHashedLineSymbolLayerWidget::averageAngleUnitChanged()
2217 {
2218  if ( mLayer )
2219  {
2220  mLayer->setAverageAngleUnit( mAverageAngleUnit->unit() );
2221  mLayer->setAverageAngleMapUnitScale( mAverageAngleUnit->getMapUnitScale() );
2222  }
2223  emit changed();
2224 }
2225 
2226 void QgsHashedLineSymbolLayerWidget::setAverageAngle( double val )
2227 {
2228  if ( mLayer )
2229  {
2230  mLayer->setAverageAngleLength( val );
2231  emit changed();
2232  }
2233 }
2234 
2236 
2237 
2239  : QgsSymbolLayerWidget( parent, vl )
2240 {
2241  mLayer = nullptr;
2242 
2243  setupUi( this );
2244 
2245  mSvgSourceLineEdit->setLastPathSettingsKey( QStringLiteral( "/UI/lastSVGMarkerDir" ) );
2246 
2247  connect( mSvgSourceLineEdit, &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSvgMarkerSymbolLayerWidget::svgSourceChanged );
2248  connect( mChangeColorButton, &QgsColorButton::colorChanged, this, &QgsSvgMarkerSymbolLayerWidget::mChangeColorButton_colorChanged );
2249  connect( mChangeStrokeColorButton, &QgsColorButton::colorChanged, this, &QgsSvgMarkerSymbolLayerWidget::mChangeStrokeColorButton_colorChanged );
2250  connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
2251  connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
2252  connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
2253  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
2254  connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSvgMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
2255  connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSvgMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
2262  viewGroups->setHeaderHidden( true );
2263  mChangeColorButton->setAllowOpacity( true );
2264  mChangeColorButton->setColorDialogTitle( tr( "Select Fill color" ) );
2265  mChangeColorButton->setContext( QStringLiteral( "symbology" ) );
2266  mChangeStrokeColorButton->setAllowOpacity( true );
2267  mChangeStrokeColorButton->setColorDialogTitle( tr( "Select Stroke Color" ) );
2268  mChangeStrokeColorButton->setContext( QStringLiteral( "symbology" ) );
2269 
2270  mFillColorDDBtn->registerLinkedWidget( mChangeColorButton );
2271  mStrokeColorDDBtn->registerLinkedWidget( mChangeStrokeColorButton );
2272 
2273  spinOffsetX->setClearValue( 0.0 );
2274  spinOffsetY->setClearValue( 0.0 );
2275  spinAngle->setClearValue( 0.0 );
2276 
2277 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
2278  mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 4 ) ) );
2279 #else
2280  mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 4 ) ) );
2281 #endif
2282  viewImages->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );
2283 
2284  populateList();
2285 
2286  connect( viewImages->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSvgMarkerSymbolLayerWidget::setName );
2287  connect( viewGroups->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSvgMarkerSymbolLayerWidget::populateIcons );
2288  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setWidth );
2289  connect( spinHeight, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setHeight );
2290  connect( mLockAspectRatio, static_cast < void ( QgsRatioLockButton::* )( bool ) > ( &QgsRatioLockButton::lockChanged ), this, &QgsSvgMarkerSymbolLayerWidget::lockAspectRatioChanged );
2291  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setAngle );
2292  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
2293  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSvgMarkerSymbolLayerWidget::setOffset );
2294  connect( this, &QgsSymbolLayerWidget::changed, this, &QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol );
2295 
2296 
2297  //make a temporary symbol for the size assistant preview
2298  mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );
2299 
2300  if ( vectorLayer() )
2301  {
2302  mWidthDDBtn->setSymbol( mAssistantPreviewSymbol );
2303  mHeightDDBtn->setSymbol( mAssistantPreviewSymbol );
2304  }
2305 }
2306 
2307 #include <QTime>
2308 #include <QAbstractListModel>
2309 #include <QPixmapCache>
2310 #include <QStyle>
2311 
2312 
2314 {
2315  QAbstractItemModel *oldModel = viewGroups->model();
2317  viewGroups->setModel( g );
2318  delete oldModel;
2319 
2320  // Set the tree expanded at the first level
2321  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2322  for ( int i = 0; i < rows; i++ )
2323  {
2324  viewGroups->setExpanded( g->indexFromItem( g->item( i ) ), true );
2325  }
2326 
2327  // Initially load the icons in the List view without any grouping
2328  oldModel = viewImages->model();
2329  QgsSvgSelectorListModel *m = new QgsSvgSelectorListModel( viewImages, mIconSize );
2330  viewImages->setModel( m );
2331  delete oldModel;
2332 }
2333 
2334 void QgsSvgMarkerSymbolLayerWidget::populateIcons( const QModelIndex &idx )
2335 {
2336  QString path = idx.data( Qt::UserRole + 1 ).toString();
2337 
2338  QAbstractItemModel *oldModel = viewImages->model();
2339  QgsSvgSelectorListModel *m = new QgsSvgSelectorListModel( viewImages, path, mIconSize );
2340  viewImages->setModel( m );
2341  delete oldModel;
2342 
2343  connect( viewImages->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSvgMarkerSymbolLayerWidget::setName );
2344 }
2345 
2347 {
2348  if ( !layer )
2349  {
2350  return;
2351  }
2352 
2353  //activate gui for svg parameters only if supported by the svg file
2354  bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
2355  QColor defaultFill, defaultStroke;
2356  double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
2357  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
2358  QgsApplication::svgCache()->containsParams( layer->path(), hasFillParam, hasDefaultFillColor, defaultFill,
2359  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2360  hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
2361  hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
2362  hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
2363  mChangeColorButton->setEnabled( hasFillParam );
2364  mChangeColorButton->setAllowOpacity( hasFillOpacityParam );
2365  mChangeStrokeColorButton->setEnabled( hasStrokeParam );
2366  mChangeStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
2367  mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
2368 
2369  if ( hasFillParam )
2370  {
2371  QColor fill = layer->fillColor();
2372  double existingOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
2373  if ( hasDefaultFillColor )
2374  {
2375  fill = defaultFill;
2376  }
2377  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : existingOpacity );
2378  mChangeColorButton->setColor( fill );
2379  }
2380  if ( hasStrokeParam )
2381  {
2382  QColor stroke = layer->strokeColor();
2383  double existingOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
2384  if ( hasDefaultStrokeColor )
2385  {
2386  stroke = defaultStroke;
2387  }
2388  stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : existingOpacity );
2389  mChangeStrokeColorButton->setColor( stroke );
2390  }
2391 
2392  whileBlocking( mSvgSourceLineEdit )->setSource( layer->path() );
2393 
2394  mStrokeWidthSpinBox->blockSignals( true );
2395  mStrokeWidthSpinBox->setValue( hasDefaultStrokeWidth ? defaultStrokeWidth : layer->strokeWidth() );
2396  mStrokeWidthSpinBox->blockSignals( false );
2397 
2398  bool preservedAspectRatio = layer->preservedAspectRatio();
2399  spinHeight->blockSignals( true );
2400  if ( preservedAspectRatio )
2401  {
2402  spinHeight->setValue( layer->size() );
2403  }
2404  else
2405  {
2406  spinHeight->setValue( layer->size() * layer->fixedAspectRatio() );
2407  }
2408  spinHeight->setEnabled( layer->defaultAspectRatio() > 0.0 );
2409  spinHeight->blockSignals( false );
2410  whileBlocking( mLockAspectRatio )->setLocked( preservedAspectRatio );
2411 }
2412 
2413 void QgsSvgMarkerSymbolLayerWidget::updateAssistantSymbol()
2414 {
2415  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
2416  {
2417  mAssistantPreviewSymbol->deleteSymbolLayer( i );
2418  }
2419  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
2421  if ( ddSize )
2422  mAssistantPreviewSymbol->setDataDefinedSize( ddSize );
2423 }
2424 
2425 
2427 {
2428  if ( !layer )
2429  {
2430  return;
2431  }
2432 
2433  if ( layer->layerType() != QLatin1String( "SvgMarker" ) )
2434  return;
2435 
2436  // layer type is correct, we can do the cast
2437  mLayer = static_cast<QgsSvgMarkerSymbolLayer *>( layer );
2438 
2439  // set values
2440 
2441  QAbstractItemModel *m = viewImages->model();
2442  QItemSelectionModel *selModel = viewImages->selectionModel();
2443  for ( int i = 0; i < m->rowCount(); i++ )
2444  {
2445  QModelIndex idx( m->index( i, 0 ) );
2446  if ( m->data( idx ).toString() == mLayer->path() )
2447  {
2448  selModel->select( idx, QItemSelectionModel::SelectCurrent );
2449  selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent );
2450  setName( idx );
2451  break;
2452  }
2453  }
2454 
2455  spinWidth->blockSignals( true );
2456  spinWidth->setValue( mLayer->size() );
2457  spinWidth->blockSignals( false );
2458  spinAngle->blockSignals( true );
2459  spinAngle->setValue( mLayer->angle() );
2460  spinAngle->blockSignals( false );
2461 
2462  // without blocking signals the value gets changed because of slot setOffset()
2463  spinOffsetX->blockSignals( true );
2464  spinOffsetX->setValue( mLayer->offset().x() );
2465  spinOffsetX->blockSignals( false );
2466  spinOffsetY->blockSignals( true );
2467  spinOffsetY->setValue( mLayer->offset().y() );
2468  spinOffsetY->blockSignals( false );
2469 
2470  mSizeUnitWidget->blockSignals( true );
2471  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
2472  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
2473  mSizeUnitWidget->blockSignals( false );
2474  mStrokeWidthUnitWidget->blockSignals( true );
2475  mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
2476  mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
2477  mStrokeWidthUnitWidget->blockSignals( false );
2478  mOffsetUnitWidget->blockSignals( true );
2479  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2480  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2481  mOffsetUnitWidget->blockSignals( false );
2482 
2483  //anchor points
2484  mHorizontalAnchorComboBox->blockSignals( true );
2485  mVerticalAnchorComboBox->blockSignals( true );
2486  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
2487  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
2488  mHorizontalAnchorComboBox->blockSignals( false );
2489  mVerticalAnchorComboBox->blockSignals( false );
2490 
2491  setGuiForSvg( mLayer );
2492 
2503 
2504  updateAssistantSymbol();
2505 }
2506 
2508 {
2509  return mLayer;
2510 }
2511 
2513 {
2515  mSvgSourceLineEdit->setMessageBar( context.messageBar() );
2516 }
2517 
2518 void QgsSvgMarkerSymbolLayerWidget::setName( const QModelIndex &idx )
2519 {
2520  QString name = idx.data( Qt::UserRole ).toString();
2521  mLayer->setPath( name );
2522  whileBlocking( mSvgSourceLineEdit )->setSource( name );
2523 
2524  setGuiForSvg( mLayer );
2525  emit changed();
2526 }
2527 
2528 void QgsSvgMarkerSymbolLayerWidget::setWidth()
2529 {
2530  double defaultAspectRatio = mLayer->defaultAspectRatio();
2531  double fixedAspectRatio = 0.0;
2532  spinHeight->blockSignals( true );
2533  if ( defaultAspectRatio <= 0.0 )
2534  {
2535  spinHeight->setValue( spinWidth->value() );
2536  }
2537  else if ( mLockAspectRatio->locked() )
2538  {
2539  spinHeight->setValue( spinWidth->value() * defaultAspectRatio );
2540  }
2541  else
2542  {
2543  fixedAspectRatio = spinHeight->value() / spinWidth->value();
2544  }
2545  spinHeight->blockSignals( false );
2546  mLayer->setSize( spinWidth->value() );
2547  mLayer->setFixedAspectRatio( fixedAspectRatio );
2548  emit changed();
2549 }
2550 
2551 void QgsSvgMarkerSymbolLayerWidget::setHeight()
2552 {
2553  double defaultAspectRatio = mLayer->defaultAspectRatio();
2554  double fixedAspectRatio = 0.0;
2555  spinWidth->blockSignals( true );
2556  if ( defaultAspectRatio <= 0.0 )
2557  {
2558  spinWidth->setValue( spinHeight->value() );
2559  }
2560  else if ( mLockAspectRatio->locked() )
2561  {
2562  spinWidth->setValue( spinHeight->value() / defaultAspectRatio );
2563  }
2564  else
2565  {
2566  fixedAspectRatio = spinHeight->value() / spinWidth->value();
2567  }
2568  spinWidth->blockSignals( false );
2569  mLayer->setSize( spinWidth->value() );
2570  mLayer->setFixedAspectRatio( fixedAspectRatio );
2571  emit changed();
2572 }
2573 
2574 void QgsSvgMarkerSymbolLayerWidget::lockAspectRatioChanged( const bool locked )
2575 {
2576  //spinHeight->setEnabled( !locked );
2577  double defaultAspectRatio = mLayer->defaultAspectRatio();
2578  if ( defaultAspectRatio <= 0.0 )
2579  {
2580  whileBlocking( mLockAspectRatio )->setLocked( true );
2581  }
2582  else if ( locked )
2583  {
2584  mLayer->setFixedAspectRatio( 0.0 );
2585  setWidth();
2586  }
2587  else
2588  {
2589  mLayer->setFixedAspectRatio( spinHeight->value() / spinWidth->value() );
2590  }
2591  //emit changed();
2592 }
2593 
2594 void QgsSvgMarkerSymbolLayerWidget::setAngle()
2595 {
2596  mLayer->setAngle( spinAngle->value() );
2597  emit changed();
2598 }
2599 
2600 void QgsSvgMarkerSymbolLayerWidget::setOffset()
2601 {
2602  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2603  emit changed();
2604 }
2605 
2606 void QgsSvgMarkerSymbolLayerWidget::svgSourceChanged( const QString &text )
2607 {
2608  mLayer->setPath( text );
2609  setGuiForSvg( mLayer );
2610  emit changed();
2611 }
2612 
2613 void QgsSvgMarkerSymbolLayerWidget::mChangeColorButton_colorChanged( const QColor &color )
2614 {
2615  if ( !mLayer )
2616  {
2617  return;
2618  }
2619 
2620  mLayer->setFillColor( color );
2621  emit changed();
2622 }
2623 
2624 void QgsSvgMarkerSymbolLayerWidget::mChangeStrokeColorButton_colorChanged( const QColor &color )
2625 {
2626  if ( !mLayer )
2627  {
2628  return;
2629  }
2630 
2631  mLayer->setStrokeColor( color );
2632  emit changed();
2633 }
2634 
2635 void QgsSvgMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
2636 {
2637  if ( mLayer )
2638  {
2639  mLayer->setStrokeWidth( d );
2640  emit changed();
2641  }
2642 }
2643 
2644 void QgsSvgMarkerSymbolLayerWidget::mSizeUnitWidget_changed()
2645 {
2646  if ( mLayer )
2647  {
2648  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2649  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2650  emit changed();
2651  }
2652 }
2653 
2654 void QgsSvgMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
2655 {
2656  if ( mLayer )
2657  {
2658  mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
2659  mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
2660  emit changed();
2661  }
2662 }
2663 
2664 void QgsSvgMarkerSymbolLayerWidget::mOffsetUnitWidget_changed()
2665 {
2666  if ( mLayer )
2667  {
2668  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2669  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2670  emit changed();
2671  }
2672 }
2673 
2674 void QgsSvgMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
2675 {
2676  if ( mLayer )
2677  {
2679  emit changed();
2680  }
2681 }
2682 
2683 void QgsSvgMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
2684 {
2685  if ( mLayer )
2686  {
2688  emit changed();
2689  }
2690 }
2691 
2693 
2695 {
2696  mLayer = nullptr;
2697  setupUi( this );
2698  connect( mTextureWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSVGFillSymbolLayerWidget::mTextureWidthSpinBox_valueChanged );
2699  connect( mSvgSourceLineEdit, &QgsSvgSourceLineEdit::sourceChanged, this, &QgsSVGFillSymbolLayerWidget::svgSourceChanged );
2700  connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSVGFillSymbolLayerWidget::mRotationSpinBox_valueChanged );
2701  connect( mChangeColorButton, &QgsColorButton::colorChanged, this, &QgsSVGFillSymbolLayerWidget::mChangeColorButton_colorChanged );
2702  connect( mChangeStrokeColorButton, &QgsColorButton::colorChanged, this, &QgsSVGFillSymbolLayerWidget::mChangeStrokeColorButton_colorChanged );
2703  connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSVGFillSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
2704  connect( mTextureWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSVGFillSymbolLayerWidget::mTextureWidthUnitWidget_changed );
2705  connect( mSvgStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSVGFillSymbolLayerWidget::mSvgStrokeWidthUnitWidget_changed );
2710  mSvgTreeView->setHeaderHidden( true );
2711 
2712 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
2713  mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 4 ) ) );
2714 #else
2715  mIconSize = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 4 ) ) );
2716 #endif
2717  mSvgListView->setGridSize( QSize( mIconSize * 1.2, mIconSize * 1.2 ) );
2718 
2719  insertIcons();
2720 
2721  mRotationSpinBox->setClearValue( 0.0 );
2722 
2723  mChangeColorButton->setColorDialogTitle( tr( "Select Fill Color" ) );
2724  mChangeColorButton->setContext( QStringLiteral( "symbology" ) );
2725  mChangeStrokeColorButton->setColorDialogTitle( tr( "Select Stroke Color" ) );
2726  mChangeStrokeColorButton->setContext( QStringLiteral( "symbology" ) );
2727 
2728  mFilColorDDBtn->registerLinkedWidget( mChangeColorButton );
2729  mStrokeColorDDBtn->registerLinkedWidget( mChangeStrokeColorButton );
2730 
2731  connect( mSvgListView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSVGFillSymbolLayerWidget::setFile );
2732  connect( mSvgTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSVGFillSymbolLayerWidget::populateIcons );
2733 }
2734 
2736 {
2737  if ( !layer )
2738  {
2739  return;
2740  }
2741 
2742  if ( layer->layerType() != QLatin1String( "SVGFill" ) )
2743  {
2744  return;
2745  }
2746 
2747  mLayer = dynamic_cast<QgsSVGFillSymbolLayer *>( layer );
2748  if ( mLayer )
2749  {
2750  double width = mLayer->patternWidth();
2751  mTextureWidthSpinBox->blockSignals( true );
2752  mTextureWidthSpinBox->setValue( width );
2753  mTextureWidthSpinBox->blockSignals( false );
2754  whileBlocking( mSvgSourceLineEdit )->setSource( mLayer->svgFilePath() );
2755  mRotationSpinBox->blockSignals( true );
2756  mRotationSpinBox->setValue( mLayer->angle() );
2757  mRotationSpinBox->blockSignals( false );
2758  mTextureWidthUnitWidget->blockSignals( true );
2759  mTextureWidthUnitWidget->setUnit( mLayer->patternWidthUnit() );
2760  mTextureWidthUnitWidget->setMapUnitScale( mLayer->patternWidthMapUnitScale() );
2761  mTextureWidthUnitWidget->blockSignals( false );
2762  mSvgStrokeWidthUnitWidget->blockSignals( true );
2763  mSvgStrokeWidthUnitWidget->setUnit( mLayer->svgStrokeWidthUnit() );
2764  mSvgStrokeWidthUnitWidget->setMapUnitScale( mLayer->svgStrokeWidthMapUnitScale() );
2765  mSvgStrokeWidthUnitWidget->blockSignals( false );
2766  mChangeColorButton->blockSignals( true );
2767  mChangeColorButton->setColor( mLayer->svgFillColor() );
2768  mChangeColorButton->blockSignals( false );
2769  mChangeStrokeColorButton->blockSignals( true );
2770  mChangeStrokeColorButton->setColor( mLayer->svgStrokeColor() );
2771  mChangeStrokeColorButton->blockSignals( false );
2772  mStrokeWidthSpinBox->blockSignals( true );
2773  mStrokeWidthSpinBox->setValue( mLayer->svgStrokeWidth() );
2774  mStrokeWidthSpinBox->blockSignals( false );
2775  }
2776  updateParamGui( false );
2777 
2784 }
2785 
2787 {
2788  return mLayer;
2789 }
2790 
2792 {
2794  mSvgSourceLineEdit->setMessageBar( context.messageBar() );
2795 }
2796 
2797 void QgsSVGFillSymbolLayerWidget::mTextureWidthSpinBox_valueChanged( double d )
2798 {
2799  if ( mLayer )
2800  {
2801  mLayer->setPatternWidth( d );
2802  emit changed();
2803  }
2804 }
2805 
2806 void QgsSVGFillSymbolLayerWidget::svgSourceChanged( const QString &text )
2807 {
2808  if ( !mLayer )
2809  {
2810  return;
2811  }
2812 
2813  mLayer->setSvgFilePath( text );
2814  updateParamGui();
2815  emit changed();
2816 }
2817 
2818 void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex &item )
2819 {
2820  QString file = item.data( Qt::UserRole ).toString();
2821  mLayer->setSvgFilePath( file );
2822  whileBlocking( mSvgSourceLineEdit )->setSource( file );
2823 
2824  updateParamGui();
2825  emit changed();
2826 }
2827 
2829 {
2830  QAbstractItemModel *oldModel = mSvgTreeView->model();
2831  QgsSvgSelectorGroupsModel *g = new QgsSvgSelectorGroupsModel( mSvgTreeView );
2832  mSvgTreeView->setModel( g );
2833  delete oldModel;
2834 
2835  // Set the tree expanded at the first level
2836  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2837  for ( int i = 0; i < rows; i++ )
2838  {
2839  mSvgTreeView->setExpanded( g->indexFromItem( g->item( i ) ), true );
2840  }
2841 
2842  oldModel = mSvgListView->model();
2843  QgsSvgSelectorListModel *m = new QgsSvgSelectorListModel( mSvgListView, mIconSize );
2844  mSvgListView->setModel( m );
2845  delete oldModel;
2846 }
2847 
2848 void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex &idx )
2849 {
2850  QString path = idx.data( Qt::UserRole + 1 ).toString();
2851 
2852  QAbstractItemModel *oldModel = mSvgListView->model();
2853  QgsSvgSelectorListModel *m = new QgsSvgSelectorListModel( mSvgListView, path, mIconSize );
2854  mSvgListView->setModel( m );
2855  delete oldModel;
2856 
2857  connect( mSvgListView->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSVGFillSymbolLayerWidget::setFile );
2858 }
2859 
2860 
2861 void QgsSVGFillSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
2862 {
2863  if ( mLayer )
2864  {
2865  mLayer->setAngle( d );
2866  emit changed();
2867  }
2868 }
2869 
2871 {
2872  //activate gui for svg parameters only if supported by the svg file
2873  bool hasFillParam, hasFillOpacityParam, hasStrokeParam, hasStrokeWidthParam, hasStrokeOpacityParam;
2874  QColor defaultFill, defaultStroke;
2875  double defaultStrokeWidth, defaultFillOpacity, defaultStrokeOpacity;
2876  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultStrokeColor, hasDefaultStrokeWidth, hasDefaultStrokeOpacity;
2877  QgsApplication::svgCache()->containsParams( mSvgSourceLineEdit->source(), hasFillParam, hasDefaultFillColor, defaultFill,
2878  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2879  hasStrokeParam, hasDefaultStrokeColor, defaultStroke,
2880  hasStrokeWidthParam, hasDefaultStrokeWidth, defaultStrokeWidth,
2881  hasStrokeOpacityParam, hasDefaultStrokeOpacity, defaultStrokeOpacity );
2882  if ( resetValues )
2883  {
2884  QColor fill = mChangeColorButton->color();
2885  double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
2886  if ( hasDefaultFillColor )
2887  {
2888  fill = defaultFill;
2889  }
2890  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
2891  mChangeColorButton->setColor( fill );
2892  }
2893  mChangeColorButton->setEnabled( hasFillParam );
2894  mChangeColorButton->setAllowOpacity( hasFillOpacityParam );
2895  if ( resetValues )
2896  {
2897  QColor stroke = mChangeStrokeColorButton->color();
2898  double newOpacity = hasStrokeOpacityParam ? stroke.alphaF() : 1.0;
2899  if ( hasDefaultStrokeColor )
2900  {
2901  stroke = defaultStroke;
2902  }
2903  stroke.setAlphaF( hasDefaultStrokeOpacity ? defaultStrokeOpacity : newOpacity );
2904  mChangeStrokeColorButton->setColor( stroke );
2905  }
2906  mChangeStrokeColorButton->setEnabled( hasStrokeParam );
2907  mChangeStrokeColorButton->setAllowOpacity( hasStrokeOpacityParam );
2908  if ( hasDefaultStrokeWidth && resetValues )
2909  {
2910  mStrokeWidthSpinBox->setValue( defaultStrokeWidth );
2911  }
2912  mStrokeWidthSpinBox->setEnabled( hasStrokeWidthParam );
2913 }
2914 
2915 void QgsSVGFillSymbolLayerWidget::mChangeColorButton_colorChanged( const QColor &color )
2916 {
2917  if ( !mLayer )
2918  {
2919  return;
2920  }
2921 
2922  mLayer->setSvgFillColor( color );
2923  emit changed();
2924 }
2925 
2926 void QgsSVGFillSymbolLayerWidget::mChangeStrokeColorButton_colorChanged( const QColor &color )
2927 {
2928  if ( !mLayer )
2929  {
2930  return;
2931  }
2932 
2933  mLayer->setSvgStrokeColor( color );
2934  emit changed();
2935 }
2936 
2937 void QgsSVGFillSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
2938 {
2939  if ( mLayer )
2940  {
2941  mLayer->setSvgStrokeWidth( d );
2942  emit changed();
2943  }
2944 }
2945 
2946 void QgsSVGFillSymbolLayerWidget::mTextureWidthUnitWidget_changed()
2947 {
2948  if ( mLayer )
2949  {
2950  mLayer->setPatternWidthUnit( mTextureWidthUnitWidget->unit() );
2951  mLayer->setPatternWidthMapUnitScale( mTextureWidthUnitWidget->getMapUnitScale() );
2952  emit changed();
2953  }
2954 }
2955 
2956 void QgsSVGFillSymbolLayerWidget::mSvgStrokeWidthUnitWidget_changed()
2957 {
2958  if ( mLayer )
2959  {
2960  mLayer->setSvgStrokeWidthUnit( mSvgStrokeWidthUnitWidget->unit() );
2961  mLayer->setSvgStrokeWidthMapUnitScale( mSvgStrokeWidthUnitWidget->getMapUnitScale() );
2962  emit changed();
2963  }
2964 }
2965 
2967 
2969  QgsSymbolLayerWidget( parent, vl )
2970 {
2971  setupUi( this );
2972  connect( mAngleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLinePatternFillSymbolLayerWidget::mAngleSpinBox_valueChanged );
2973  connect( mDistanceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLinePatternFillSymbolLayerWidget::mDistanceSpinBox_valueChanged );
2974  connect( mOffsetSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLinePatternFillSymbolLayerWidget::mOffsetSpinBox_valueChanged );
2975  connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsLinePatternFillSymbolLayerWidget::mDistanceUnitWidget_changed );
2976  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsLinePatternFillSymbolLayerWidget::mOffsetUnitWidget_changed );
2981  mOffsetSpinBox->setClearValue( 0 );
2982  mAngleSpinBox->setClearValue( 0 );
2983 }
2984 
2986 {
2987  if ( layer->layerType() != QLatin1String( "LinePatternFill" ) )
2988  {
2989  return;
2990  }
2991 
2992  QgsLinePatternFillSymbolLayer *patternLayer = static_cast<QgsLinePatternFillSymbolLayer *>( layer );
2993  if ( patternLayer )
2994  {
2995  mLayer = patternLayer;
2996  mAngleSpinBox->blockSignals( true );
2997  mAngleSpinBox->setValue( mLayer->lineAngle() );
2998  mAngleSpinBox->blockSignals( false );
2999  mDistanceSpinBox->blockSignals( true );
3000  mDistanceSpinBox->setValue( mLayer->distance() );
3001  mDistanceSpinBox->blockSignals( false );
3002  mOffsetSpinBox->blockSignals( true );
3003  mOffsetSpinBox->setValue( mLayer->offset() );
3004  mOffsetSpinBox->blockSignals( false );
3005 
3006  //units
3007  mDistanceUnitWidget->blockSignals( true );
3008  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
3009  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
3010  mDistanceUnitWidget->blockSignals( false );
3011  mOffsetUnitWidget->blockSignals( true );
3012  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3013  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3014  mOffsetUnitWidget->blockSignals( false );
3015  }
3016 
3019 }
3020 
3022 {
3023  return mLayer;
3024 }
3025 
3026 void QgsLinePatternFillSymbolLayerWidget::mAngleSpinBox_valueChanged( double d )
3027 {
3028  if ( mLayer )
3029  {
3030  mLayer->setLineAngle( d );
3031  emit changed();
3032  }
3033 }
3034 
3035 void QgsLinePatternFillSymbolLayerWidget::mDistanceSpinBox_valueChanged( double d )
3036 {
3037  if ( mLayer )
3038  {
3039  mLayer->setDistance( d );
3040  emit changed();
3041  }
3042 }
3043 
3044 void QgsLinePatternFillSymbolLayerWidget::mOffsetSpinBox_valueChanged( double d )
3045 {
3046  if ( mLayer )
3047  {
3048  mLayer->setOffset( d );
3049  emit changed();
3050  }
3051 }
3052 
3053 void QgsLinePatternFillSymbolLayerWidget::mDistanceUnitWidget_changed()
3054 {
3055  if ( mLayer )
3056  {
3057  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
3058  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
3059  emit changed();
3060  }
3061 }
3062 
3063 void QgsLinePatternFillSymbolLayerWidget::mOffsetUnitWidget_changed()
3064 {
3065  if ( mLayer )
3066  {
3067  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
3068  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3069  emit changed();
3070  }
3071 }
3072 
3074 
3076  QgsSymbolLayerWidget( parent, vl )
3077 {
3078  setupUi( this );
3079  connect( mHorizontalDistanceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalDistanceSpinBox_valueChanged );
3080  connect( mVerticalDistanceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mVerticalDistanceSpinBox_valueChanged );
3081  connect( mHorizontalDisplacementSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalDisplacementSpinBox_valueChanged );
3082  connect( mVerticalDisplacementSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mVerticalDisplacementSpinBox_valueChanged );
3083  connect( mHorizontalOffsetSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalOffsetSpinBox_valueChanged );
3084  connect( mVerticalOffsetSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsPointPatternFillSymbolLayerWidget::mVerticalOffsetSpinBox_valueChanged );
3085  connect( mHorizontalDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalDistanceUnitWidget_changed );
3086  connect( mVerticalDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mVerticalDistanceUnitWidget_changed );
3087  connect( mHorizontalDisplacementUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalDisplacementUnitWidget_changed );
3088  connect( mVerticalDisplacementUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mVerticalDisplacementUnitWidget_changed );
3089  connect( mHorizontalOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mHorizontalOffsetUnitWidget_changed );
3090  connect( mVerticalOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsPointPatternFillSymbolLayerWidget::mVerticalOffsetUnitWidget_changed );
3103 }
3104 
3105 
3107 {
3108  if ( !layer || layer->layerType() != QLatin1String( "PointPatternFill" ) )
3109  {
3110  return;
3111  }
3112 
3113  mLayer = static_cast<QgsPointPatternFillSymbolLayer *>( layer );
3114  whileBlocking( mHorizontalDistanceSpinBox )->setValue( mLayer->distanceX() );
3115  whileBlocking( mVerticalDistanceSpinBox )->setValue( mLayer->distanceY() );
3116  whileBlocking( mHorizontalDisplacementSpinBox )->setValue( mLayer->displacementX() );
3117  whileBlocking( mVerticalDisplacementSpinBox )->setValue( mLayer->displacementY() );
3118  whileBlocking( mHorizontalOffsetSpinBox )->setValue( mLayer->offsetX() );
3119  whileBlocking( mVerticalOffsetSpinBox )->setValue( mLayer->offsetY() );
3120 
3121  mHorizontalDistanceUnitWidget->blockSignals( true );
3122  mHorizontalDistanceUnitWidget->setUnit( mLayer->distanceXUnit() );
3123  mHorizontalDistanceUnitWidget->setMapUnitScale( mLayer->distanceXMapUnitScale() );
3124  mHorizontalDistanceUnitWidget->blockSignals( false );
3125  mVerticalDistanceUnitWidget->blockSignals( true );
3126  mVerticalDistanceUnitWidget->setUnit( mLayer->distanceYUnit() );
3127  mVerticalDistanceUnitWidget->setMapUnitScale( mLayer->distanceYMapUnitScale() );
3128  mVerticalDistanceUnitWidget->blockSignals( false );
3129  mHorizontalDisplacementUnitWidget->blockSignals( true );
3130  mHorizontalDisplacementUnitWidget->setUnit( mLayer->displacementXUnit() );
3131  mHorizontalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementXMapUnitScale() );
3132  mHorizontalDisplacementUnitWidget->blockSignals( false );
3133  mVerticalDisplacementUnitWidget->blockSignals( true );
3134  mVerticalDisplacementUnitWidget->setUnit( mLayer->displacementYUnit() );
3135  mVerticalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementYMapUnitScale() );
3136  mVerticalDisplacementUnitWidget->blockSignals( false );
3137  mHorizontalOffsetUnitWidget->blockSignals( true );
3138  mHorizontalOffsetUnitWidget->setUnit( mLayer->offsetXUnit() );
3139  mHorizontalOffsetUnitWidget->setMapUnitScale( mLayer->offsetXMapUnitScale() );
3140  mHorizontalOffsetUnitWidget->blockSignals( false );
3141  mVerticalOffsetUnitWidget->blockSignals( true );
3142  mVerticalOffsetUnitWidget->setUnit( mLayer->offsetYUnit() );
3143  mVerticalOffsetUnitWidget->setMapUnitScale( mLayer->offsetYMapUnitScale() );
3144  mVerticalOffsetUnitWidget->blockSignals( false );
3145 
3146  registerDataDefinedButton( mHorizontalDistanceDDBtn, QgsSymbolLayer::PropertyDistanceX );
3148  registerDataDefinedButton( mHorizontalDisplacementDDBtn, QgsSymbolLayer::PropertyDisplacementX );
3152 }
3153 
3155 {
3156  return mLayer;
3157 }
3158 
3159 void QgsPointPatternFillSymbolLayerWidget::mHorizontalDistanceSpinBox_valueChanged( double d )
3160 {
3161  if ( mLayer )
3162  {
3163  mLayer->setDistanceX( d );
3164  emit changed();
3165  }
3166 }
3167 
3168 void QgsPointPatternFillSymbolLayerWidget::mVerticalDistanceSpinBox_valueChanged( double d )
3169 {
3170  if ( mLayer )
3171  {
3172  mLayer->setDistanceY( d );
3173  emit changed();
3174  }
3175 }
3176 
3177 void QgsPointPatternFillSymbolLayerWidget::mHorizontalDisplacementSpinBox_valueChanged( double d )
3178 {
3179  if ( mLayer )
3180  {
3181  mLayer->setDisplacementX( d );
3182  emit changed();
3183  }
3184 }
3185 
3186 void QgsPointPatternFillSymbolLayerWidget::mVerticalDisplacementSpinBox_valueChanged( double d )
3187 {
3188  if ( mLayer )
3189  {
3190  mLayer->setDisplacementY( d );
3191  emit changed();
3192  }
3193 }
3194 
3195 void QgsPointPatternFillSymbolLayerWidget::mHorizontalOffsetSpinBox_valueChanged( double d )
3196 {
3197  if ( mLayer )
3198  {
3199  mLayer->setOffsetX( d );
3200  emit changed();
3201  }
3202 }
3203 
3204 void QgsPointPatternFillSymbolLayerWidget::mVerticalOffsetSpinBox_valueChanged( double d )
3205 {
3206  if ( mLayer )
3207  {
3208  mLayer->setOffsetY( d );
3209  emit changed();
3210  }
3211 }
3212 
3213 void QgsPointPatternFillSymbolLayerWidget::mHorizontalDistanceUnitWidget_changed()
3214 {
3215  if ( mLayer )
3216  {
3217  mLayer->setDistanceXUnit( mHorizontalDistanceUnitWidget->unit() );
3218  mLayer->setDistanceXMapUnitScale( mHorizontalDistanceUnitWidget->getMapUnitScale() );
3219  emit changed();
3220  }
3221 }
3222 
3223 void QgsPointPatternFillSymbolLayerWidget::mVerticalDistanceUnitWidget_changed()
3224 {
3225  if ( mLayer )
3226  {
3227  mLayer->setDistanceYUnit( mVerticalDistanceUnitWidget->unit() );
3228  mLayer->setDistanceYMapUnitScale( mVerticalDistanceUnitWidget->getMapUnitScale() );
3229  emit changed();
3230  }
3231 }
3232 
3233 void QgsPointPatternFillSymbolLayerWidget::mHorizontalDisplacementUnitWidget_changed()
3234 {
3235  if ( mLayer )
3236  {
3237  mLayer->setDisplacementXUnit( mHorizontalDisplacementUnitWidget->unit() );
3238  mLayer->setDisplacementXMapUnitScale( mHorizontalDisplacementUnitWidget->getMapUnitScale() );
3239  emit changed();
3240  }
3241 }
3242 
3243 void QgsPointPatternFillSymbolLayerWidget::mVerticalDisplacementUnitWidget_changed()
3244 {
3245  if ( mLayer )
3246  {
3247  mLayer->setDisplacementYUnit( mVerticalDisplacementUnitWidget->unit() );
3248  mLayer->setDisplacementYMapUnitScale( mVerticalDisplacementUnitWidget->getMapUnitScale() );
3249  emit changed();
3250  }
3251 }
3252 
3253 void QgsPointPatternFillSymbolLayerWidget::mHorizontalOffsetUnitWidget_changed()
3254 {
3255  if ( mLayer )
3256  {
3257  mLayer->setOffsetXUnit( mHorizontalOffsetUnitWidget->unit() );
3258  mLayer->setOffsetXMapUnitScale( mHorizontalOffsetUnitWidget->getMapUnitScale() );
3259  emit changed();
3260  }
3261 }
3262 
3263 void QgsPointPatternFillSymbolLayerWidget::mVerticalOffsetUnitWidget_changed()
3264 {
3265  if ( mLayer )
3266  {
3267  mLayer->setOffsetYUnit( mVerticalOffsetUnitWidget->unit() );
3268  mLayer->setOffsetYMapUnitScale( mVerticalOffsetUnitWidget->getMapUnitScale() );
3269  emit changed();
3270  }
3271 }
3272 
3274 
3276  : QgsSymbolLayerWidget( parent, vl )
3277 {
3278  mLayer = nullptr;
3279 
3280  setupUi( this );
3281  connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsFontMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
3282  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsFontMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
3283  connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsFontMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
3284  connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFontMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
3285  connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFontMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
3286  connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFontMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
3293 
3294  widgetChar = new CharacterWidget();
3295  scrollArea->setWidget( widgetChar );
3296  scrollArea->setVerticalOnly( true );
3297 
3298  btnColor->setAllowOpacity( true );
3299  btnColor->setColorDialogTitle( tr( "Select Symbol Fill Color" ) );
3300  btnColor->setContext( QStringLiteral( "symbology" ) );
3301  btnStrokeColor->setAllowOpacity( true );
3302  btnStrokeColor->setColorDialogTitle( tr( "Select Symbol Stroke Color" ) );
3303  btnStrokeColor->setContext( QStringLiteral( "symbology" ) );
3304 
3305  mColorDDBtn->registerLinkedWidget( btnColor );
3306  mStrokeColorDDBtn->registerLinkedWidget( btnStrokeColor );
3307 
3308  spinOffsetX->setClearValue( 0.0 );
3309  spinOffsetY->setClearValue( 0.0 );
3310  spinAngle->setClearValue( 0.0 );
3311 
3312  //make a temporary symbol for the size assistant preview
3313  mAssistantPreviewSymbol.reset( new QgsMarkerSymbol() );
3314 
3315  if ( vectorLayer() )
3316  mSizeDDBtn->setSymbol( mAssistantPreviewSymbol );
3317 
3318  connect( cboFont, &QFontComboBox::currentFontChanged, this, &QgsFontMarkerSymbolLayerWidget::setFontFamily );
3319  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFontMarkerSymbolLayerWidget::setSize );
3320  connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFontMarkerSymbolLayerWidget::penJoinStyleChanged );
3323  connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsFontMarkerSymbolLayerWidget::penJoinStyleChanged );
3324  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFontMarkerSymbolLayerWidget::setAngle );
3325  connect( spinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFontMarkerSymbolLayerWidget::setOffset );
3326  connect( spinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsFontMarkerSymbolLayerWidget::setOffset );
3328  connect( mCharLineEdit, &QLineEdit::textChanged, this, &QgsFontMarkerSymbolLayerWidget::setCharacterFromText );
3329 
3330  connect( this, &QgsSymbolLayerWidget::changed, this, &QgsFontMarkerSymbolLayerWidget::updateAssistantSymbol );
3331 }
3332 
3334 {
3335  if ( layer->layerType() != QLatin1String( "FontMarker" ) )
3336  return;
3337 
3338  // layer type is correct, we can do the cast
3339  mLayer = static_cast<QgsFontMarkerSymbolLayer *>( layer );
3340 
3341  QFont layerFont( mLayer->fontFamily() );
3342  // set values
3343  whileBlocking( cboFont )->setCurrentFont( layerFont );
3344  whileBlocking( spinSize )->setValue( mLayer->size() );
3345  whileBlocking( btnColor )->setColor( mLayer->color() );
3346  whileBlocking( btnStrokeColor )->setColor( mLayer->strokeColor() );
3347  whileBlocking( mStrokeWidthSpinBox )->setValue( mLayer->strokeWidth() );
3348  whileBlocking( spinAngle )->setValue( mLayer->angle() );
3349 
3350  widgetChar->blockSignals( true );
3351  widgetChar->setFont( layerFont );
3352  if ( mLayer->character().length() == 1 )
3353  {
3354  widgetChar->setCharacter( mLayer->character().at( 0 ) );
3355  }
3356  widgetChar->blockSignals( false );
3357  whileBlocking( mCharLineEdit )->setText( mLayer->character() );
3358  mCharPreview->setFont( layerFont );
3359 
3360  //block
3361  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
3362  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
3363 
3364  mSizeUnitWidget->blockSignals( true );
3365  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
3366  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
3367  mSizeUnitWidget->blockSignals( false );
3368 
3369  mStrokeWidthUnitWidget->blockSignals( true );
3370  mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
3371  mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
3372  mStrokeWidthUnitWidget->blockSignals( false );
3373 
3374  mOffsetUnitWidget->blockSignals( true );
3375  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3376  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3377  mOffsetUnitWidget->blockSignals( false );
3378 
3379  whileBlocking( cboJoinStyle )->setPenJoinStyle( mLayer->penJoinStyle() );
3380 
3381  //anchor points
3382  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
3383  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
3384 
3395 
3396  updateAssistantSymbol();
3397 }
3398 
3400 {
3401  return mLayer;
3402 }
3403 
3405 {
3406  mLayer->setFontFamily( font.family() );
3407  widgetChar->setFont( font );
3408  mCharPreview->setFont( font );
3409  emit changed();
3410 }
3411 
3412 void QgsFontMarkerSymbolLayerWidget::setColor( const QColor &color )
3413 {
3414  mLayer->setColor( color );
3415  emit changed();
3416 }
3417 
3419 {
3420  mLayer->setStrokeColor( color );
3421  emit changed();
3422 }
3423 
3425 {
3426  mLayer->setSize( size );
3427  //widgetChar->updateSize(size);
3428  emit changed();
3429 }
3430 
3432 {
3433  mLayer->setAngle( angle );
3434  emit changed();
3435 }
3436 
3438 {
3439  mCharPreview->setText( text );
3440 
3441  if ( text.isEmpty() )
3442  return;
3443 
3444  // take the last character of a string for a better experience when users cycle through several characters on their keyboard
3445  QString character = text;
3446  if ( text.contains( QRegularExpression( QStringLiteral( "^0x[0-9a-fA-F]{1,4}$" ) ) ) )
3447  {
3448  bool ok = false;
3449  unsigned int value = text.toUInt( &ok, 0 );
3450  if ( ok )
3451  {
3452  character = QChar( value );
3453  mCharPreview->setText( character );
3454  }
3455  }
3456 
3457  if ( character != mLayer->character() )
3458  {
3459  mLayer->setCharacter( character );
3460  if ( mLayer->character().length() == 1 )
3461  {
3462  whileBlocking( widgetChar )->setCharacter( mLayer->character().at( 0 ) );
3463  }
3464  else
3465  {
3467  }
3468  emit changed();
3469  }
3470 }
3471 
3473 {
3474  if ( mLayer->character().length() > 1 || QGuiApplication::keyboardModifiers() & Qt::ControlModifier )
3475  {
3476  mCharLineEdit->insert( chr );
3477  return;
3478  }
3479 
3480  mLayer->setCharacter( chr );
3481  whileBlocking( mCharLineEdit )->setText( chr );
3482  mCharPreview->setText( chr );
3483  emit changed();
3484 }
3485 
3486 void QgsFontMarkerSymbolLayerWidget::setOffset()
3487 {
3488  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
3489  emit changed();
3490 }
3491 
3492 void QgsFontMarkerSymbolLayerWidget::penJoinStyleChanged()
3493 {
3494  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
3495  emit changed();
3496 }
3497 
3498 void QgsFontMarkerSymbolLayerWidget::mSizeUnitWidget_changed()
3499 {
3500  if ( mLayer )
3501  {
3502  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
3503  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
3504  emit changed();
3505  }
3506 }
3507 
3508 void QgsFontMarkerSymbolLayerWidget::mOffsetUnitWidget_changed()
3509 {
3510  if ( mLayer )
3511  {
3512  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
3513  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3514  emit changed();
3515  }
3516 }
3517 
3518 void QgsFontMarkerSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
3519 {
3520  if ( mLayer )
3521  {
3522  mLayer->setStrokeWidthUnit( mSizeUnitWidget->unit() );
3523  mLayer->setStrokeWidthMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
3524  emit changed();
3525  }
3526 }
3527 
3528 void QgsFontMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
3529 {
3530  if ( mLayer )
3531  {
3533  emit changed();
3534  }
3535 }
3536 
3537 void QgsFontMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
3538 {
3539  if ( mLayer )
3540  {
3542  emit changed();
3543  }
3544 }
3545 
3546 void QgsFontMarkerSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
3547 {
3548  if ( mLayer )
3549  {
3550  mLayer->setStrokeWidth( d );
3551  emit changed();
3552  }
3553 }
3554 
3555 void QgsFontMarkerSymbolLayerWidget::updateAssistantSymbol()
3556 {
3557  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
3558  {
3559  mAssistantPreviewSymbol->deleteSymbolLayer( i );
3560  }
3561  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
3563  if ( ddSize )
3564  mAssistantPreviewSymbol->setDataDefinedSize( ddSize );
3565 }
3566 
3568 
3569 
3571  : QgsSymbolLayerWidget( parent, vl )
3572 {
3573  mLayer = nullptr;
3574 
3575  setupUi( this );
3576  connect( mDrawInsideCheckBox, &QCheckBox::stateChanged, this, &QgsCentroidFillSymbolLayerWidget::mDrawInsideCheckBox_stateChanged );
3577  connect( mDrawAllPartsCheckBox, &QCheckBox::stateChanged, this, &QgsCentroidFillSymbolLayerWidget::mDrawAllPartsCheckBox_stateChanged );
3578 }
3579 
3581 {
3582  if ( layer->layerType() != QLatin1String( "CentroidFill" ) )
3583  return;
3584 
3585  // layer type is correct, we can do the cast
3586  mLayer = static_cast<QgsCentroidFillSymbolLayer *>( layer );
3587 
3588  // set values
3589  whileBlocking( mDrawInsideCheckBox )->setChecked( mLayer->pointOnSurface() );
3590  whileBlocking( mDrawAllPartsCheckBox )->setChecked( mLayer->pointOnAllParts() );
3591 }
3592 
3594 {
3595  return mLayer;
3596 }
3597 
3598 void QgsCentroidFillSymbolLayerWidget::mDrawInsideCheckBox_stateChanged( int state )
3599 {
3600  mLayer->setPointOnSurface( state == Qt::Checked );
3601  emit changed();
3602 }
3603 
3604 void QgsCentroidFillSymbolLayerWidget::mDrawAllPartsCheckBox_stateChanged( int state )
3605 {
3606  mLayer->setPointOnAllParts( state == Qt::Checked );
3607  emit changed();
3608 }
3609 
3611 
3613  : QgsSymbolLayerWidget( parent, vl )
3614 {
3615  mLayer = nullptr;
3616 
3617  setupUi( this );
3618 
3619  mImageSourceLineEdit->setLastPathSettingsKey( QStringLiteral( "/UI/lastRasterMarkerImageDir" ) );
3620 
3621  connect( mImageSourceLineEdit, &QgsImageSourceLineEdit::sourceChanged, this, &QgsRasterMarkerSymbolLayerWidget::imageSourceChanged );
3622  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterMarkerSymbolLayerWidget::mOffsetUnitWidget_changed );
3623  connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setAngle );
3624  connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterMarkerSymbolLayerWidget::mSizeUnitWidget_changed );
3625  connect( mWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setWidth );
3626  connect( mHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setHeight );
3627  connect( mLockAspectRatio, static_cast < void ( QgsRatioLockButton::* )( bool ) > ( &QgsRatioLockButton::lockChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setLockAspectRatio );
3628 
3633 
3634  mSpinOffsetX->setClearValue( 0.0 );
3635  mSpinOffsetY->setClearValue( 0.0 );
3636  mRotationSpinBox->setClearValue( 0.0 );
3637 
3638  connect( mSpinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setOffset );
3639  connect( mSpinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterMarkerSymbolLayerWidget::setOffset );
3640  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsRasterMarkerSymbolLayerWidget::setOpacity );
3641 
3642  connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
3643  connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
3644 }
3645 
3647 {
3648  if ( !layer )
3649  {
3650  return;
3651  }
3652 
3653  if ( layer->layerType() != QLatin1String( "RasterMarker" ) )
3654  return;
3655 
3656  // layer type is correct, we can do the cast
3657  mLayer = static_cast<QgsRasterMarkerSymbolLayer *>( layer );
3658 
3659  // set values
3660  whileBlocking( mImageSourceLineEdit )->setSource( mLayer->path() );
3661 
3662  whileBlocking( mWidthSpinBox )->setValue( mLayer->size() );
3663  bool preservedAspectRatio = mLayer->preservedAspectRatio();
3664  mHeightSpinBox->blockSignals( true );
3665  if ( preservedAspectRatio )
3666  {
3667  mHeightSpinBox->setValue( mLayer->size() );
3668  }
3669  else
3670  {
3671  mHeightSpinBox->setValue( mLayer->size() * mLayer->fixedAspectRatio() );
3672  }
3673  mHeightSpinBox->setEnabled( mLayer->defaultAspectRatio() > 0.0 );
3674  mHeightSpinBox->blockSignals( false );
3675  whileBlocking( mLockAspectRatio )->setLocked( preservedAspectRatio );
3676 
3677  whileBlocking( mRotationSpinBox )->setValue( mLayer->angle() );
3678  whileBlocking( mOpacityWidget )->setOpacity( mLayer->opacity() );
3679 
3680  whileBlocking( mSpinOffsetX )->setValue( mLayer->offset().x() );
3681  whileBlocking( mSpinOffsetY )->setValue( mLayer->offset().y() );
3682 
3683  mSizeUnitWidget->blockSignals( true );
3684  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
3685  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
3686  mSizeUnitWidget->blockSignals( false );
3687  mOffsetUnitWidget->blockSignals( true );
3688  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3689  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3690  mOffsetUnitWidget->blockSignals( false );
3691 
3692  //anchor points
3693  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
3694  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
3695 
3704 
3705  updatePreviewImage();
3706 }
3707 
3709 {
3710  return mLayer;
3711 }
3712 
3714 {
3716  mImageSourceLineEdit->setMessageBar( context.messageBar() );
3717 }
3718 
3719 void QgsRasterMarkerSymbolLayerWidget::imageSourceChanged( const QString &text )
3720 {
3721  mLayer->setPath( text );
3722  updatePreviewImage();
3723  emit changed();
3724 }
3725 
3726 void QgsRasterMarkerSymbolLayerWidget::updatePreviewImage()
3727 {
3728  bool fitsInCache = false;
3729  QImage image = QgsApplication::imageCache()->pathAsImage( mLayer->path(), QSize( 150, 150 ), true, 1.0, fitsInCache );
3730  if ( image.isNull() )
3731  {
3732  mLabelImagePreview->setPixmap( QPixmap() );
3733  return;
3734  }
3735 
3736  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
3737  previewImage.fill( Qt::transparent );
3738  QRect imageRect( ( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
3739  QPainter p;
3740  p.begin( &previewImage );
3741  //draw a checkerboard background
3742  uchar pixDataRGB[] = { 150, 150, 150, 150,
3743  100, 100, 100, 150,
3744  100, 100, 100, 150,
3745  150, 150, 150, 150
3746  };
3747  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
3748  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
3749  QBrush checkerBrush;
3750  checkerBrush.setTexture( pix );
3751  p.fillRect( imageRect, checkerBrush );
3752 
3753  if ( mLayer->opacity() < 1.0 )
3754  {
3755  p.setOpacity( mLayer->opacity() );
3756  }
3757 
3758  p.drawImage( imageRect.left(), imageRect.top(), image );
3759  p.end();
3760  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
3761 }
3762 
3763 void QgsRasterMarkerSymbolLayerWidget::setWidth()
3764 {
3765  double defaultAspectRatio = mLayer->defaultAspectRatio();
3766  double fixedAspectRatio = 0.0;
3767  mHeightSpinBox->blockSignals( true );
3768  if ( defaultAspectRatio <= 0.0 )
3769  {
3770  mHeightSpinBox->setValue( mWidthSpinBox->value() );
3771  }
3772  else if ( mLockAspectRatio->locked() )
3773  {
3774  mHeightSpinBox->setValue( mWidthSpinBox->value() * defaultAspectRatio );
3775  }
3776  else
3777  {
3778  fixedAspectRatio = mHeightSpinBox->value() / mWidthSpinBox->value();
3779  }
3780  mHeightSpinBox->blockSignals( false );
3781  mLayer->setSize( mWidthSpinBox->value() );
3782  mLayer->setFixedAspectRatio( fixedAspectRatio );
3783  emit changed();
3784 }
3785 
3786 void QgsRasterMarkerSymbolLayerWidget::setHeight()
3787 {
3788  double defaultAspectRatio = mLayer->defaultAspectRatio();
3789  double fixedAspectRatio = 0.0;
3790  mWidthSpinBox->blockSignals( true );
3791  if ( defaultAspectRatio <= 0.0 )
3792  {
3793  mWidthSpinBox->setValue( mHeightSpinBox->value() );
3794  }
3795  else if ( mLockAspectRatio->locked() )
3796  {
3797  mWidthSpinBox->setValue( mHeightSpinBox->value() / defaultAspectRatio );
3798  }
3799  else
3800  {
3801  fixedAspectRatio = mHeightSpinBox->value() / mWidthSpinBox->value();
3802  }
3803  mWidthSpinBox->blockSignals( false );
3804  mLayer->setSize( mWidthSpinBox->value() );
3805  mLayer->setFixedAspectRatio( fixedAspectRatio );
3806  emit changed();
3807 }
3808 
3809 void QgsRasterMarkerSymbolLayerWidget::setLockAspectRatio( const bool locked )
3810 {
3811  double defaultAspectRatio = mLayer->defaultAspectRatio();
3812  if ( defaultAspectRatio <= 0.0 )
3813  {
3814  whileBlocking( mLockAspectRatio )->setLocked( true );
3815  }
3816  else if ( locked )
3817  {
3818  mLayer->setFixedAspectRatio( 0.0 );
3819  setWidth();
3820  }
3821  else
3822  {
3823  mLayer->setFixedAspectRatio( mHeightSpinBox->value() / mWidthSpinBox->value() );
3824  }
3825 }
3826 
3827 void QgsRasterMarkerSymbolLayerWidget::setAngle()
3828 {
3829  mLayer->setAngle( mRotationSpinBox->value() );
3830  emit changed();
3831 }
3832 
3833 void QgsRasterMarkerSymbolLayerWidget::setOpacity( double value )
3834 {
3835  mLayer->setOpacity( value );
3836  emit changed();
3837  updatePreviewImage();
3838 }
3839 
3840 void QgsRasterMarkerSymbolLayerWidget::setOffset()
3841 {
3842  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
3843  emit changed();
3844 }
3845 
3846 void QgsRasterMarkerSymbolLayerWidget::mSizeUnitWidget_changed()
3847 {
3848  if ( mLayer )
3849  {
3850  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
3851  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
3852  emit changed();
3853  }
3854 }
3855 
3856 void QgsRasterMarkerSymbolLayerWidget::mOffsetUnitWidget_changed()
3857 {
3858  if ( mLayer )
3859  {
3860  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
3861  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3862  emit changed();
3863  }
3864 }
3865 
3866 void QgsRasterMarkerSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
3867 {
3868  if ( mLayer )
3869  {
3871  emit changed();
3872  }
3873 }
3874 
3875 void QgsRasterMarkerSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
3876 {
3877  if ( mLayer )
3878  {
3880  emit changed();
3881  }
3882 }
3883 
3885 
3887  : QgsSymbolLayerWidget( parent, vl )
3888 {
3889  mLayer = nullptr;
3890  setupUi( this );
3891 
3892  mImageSourceLineEdit->setLastPathSettingsKey( QStringLiteral( "/UI/lastRasterMarkerImageDir" ) );
3893  connect( mImageSourceLineEdit, &QgsImageSourceLineEdit::sourceChanged, this, &QgsRasterFillSymbolLayerWidget::imageSourceChanged );
3894 
3895  connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterFillSymbolLayerWidget::mOffsetUnitWidget_changed );
3896  connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::mRotationSpinBox_valueChanged );
3897  connect( mWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRasterFillSymbolLayerWidget::mWidthUnitWidget_changed );
3898  connect( mWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::mWidthSpinBox_valueChanged );
3899 
3904 
3905  mSpinOffsetX->setClearValue( 0.0 );
3906  mSpinOffsetY->setClearValue( 0.0 );
3907  mRotationSpinBox->setClearValue( 0.0 );
3908 
3909  connect( cboCoordinateMode, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterFillSymbolLayerWidget::setCoordinateMode );
3910  connect( mSpinOffsetX, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::offsetChanged );
3911  connect( mSpinOffsetY, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterFillSymbolLayerWidget::offsetChanged );
3912  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsRasterFillSymbolLayerWidget::opacityChanged );
3913 }
3914 
3915 
3917 {
3918  if ( !layer )
3919  {
3920  return;
3921  }
3922 
3923  if ( layer->layerType() != QLatin1String( "RasterFill" ) )
3924  {
3925  return;
3926  }
3927 
3928  mLayer = dynamic_cast<QgsRasterFillSymbolLayer *>( layer );
3929  if ( !mLayer )
3930  {
3931  return;
3932  }
3933 
3934  whileBlocking( mImageSourceLineEdit )->setSource( mLayer->imageFilePath() );
3935 
3936  cboCoordinateMode->blockSignals( true );
3937  switch ( mLayer->coordinateMode() )
3938  {
3940  cboCoordinateMode->setCurrentIndex( 1 );
3941  break;
3943  default:
3944  cboCoordinateMode->setCurrentIndex( 0 );
3945  break;
3946  }
3947  cboCoordinateMode->blockSignals( false );
3948  whileBlocking( mOpacityWidget )->setOpacity( mLayer->opacity() );
3949  whileBlocking( mRotationSpinBox )->setValue( mLayer->angle() );
3950 
3951  whileBlocking( mSpinOffsetX )->setValue( mLayer->offset().x() );
3952  whileBlocking( mSpinOffsetY )->setValue( mLayer->offset().y() );
3953  mOffsetUnitWidget->blockSignals( true );
3954  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3955  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3956  mOffsetUnitWidget->blockSignals( false );
3957 
3958  whileBlocking( mWidthSpinBox )->setValue( mLayer->width() );
3959  mWidthUnitWidget->blockSignals( true );
3960  mWidthUnitWidget->setUnit( mLayer->widthUnit() );
3961  mWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
3962  mWidthUnitWidget->blockSignals( false );
3963 
3964  updatePreviewImage();
3965 
3970 }
3971 
3973 {
3974  return mLayer;
3975 }
3976 
3977 void QgsRasterFillSymbolLayerWidget::imageSourceChanged( const QString &text )
3978 {
3979  mLayer->setImageFilePath( text );
3980  updatePreviewImage();
3981  emit changed();
3982 }
3983 
3984 void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
3985 {
3986  switch ( index )
3987  {
3988  case 0:
3989  //feature coordinate mode
3991  break;
3992  case 1:
3993  //viewport coordinate mode
3995  break;
3996  }
3997 
3998  emit changed();
3999 }
4000 
4001 void QgsRasterFillSymbolLayerWidget::opacityChanged( double value )
4002 {
4003  if ( !mLayer )
4004  {
4005  return;
4006  }
4007 
4008  mLayer->setOpacity( value );
4009  emit changed();
4010  updatePreviewImage();
4011 }
4012 
4013 void QgsRasterFillSymbolLayerWidget::offsetChanged()
4014 {
4015  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
4016  emit changed();
4017 }
4018 
4019 void QgsRasterFillSymbolLayerWidget::mOffsetUnitWidget_changed()
4020 {
4021  if ( !mLayer )
4022  {
4023  return;
4024  }
4025  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
4026  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
4027  emit changed();
4028 }
4029 
4030 void QgsRasterFillSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
4031 {
4032  if ( mLayer )
4033  {
4034  mLayer->setAngle( d );
4035  emit changed();
4036  }
4037 }
4038 
4039 void QgsRasterFillSymbolLayerWidget::mWidthUnitWidget_changed()
4040 {
4041  if ( !mLayer )
4042  {
4043  return;
4044  }
4045  mLayer->setWidthUnit( mWidthUnitWidget->unit() );
4046  mLayer->setWidthMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
4047  emit changed();
4048 }
4049 
4050 void QgsRasterFillSymbolLayerWidget::mWidthSpinBox_valueChanged( double d )
4051 {
4052  if ( !mLayer )
4053  {
4054  return;
4055  }
4056  mLayer->setWidth( d );
4057  emit changed();
4058 }
4059 
4060 void QgsRasterFillSymbolLayerWidget::updatePreviewImage()
4061 {
4062  bool fitsInCache = false;
4063  QImage image = QgsApplication::imageCache()->pathAsImage( mLayer->imageFilePath(), QSize( 150, 150 ), true, 1.0, fitsInCache );
4064  if ( image.isNull() )
4065  {
4066  mLabelImagePreview->setPixmap( QPixmap() );
4067  return;
4068  }
4069 
4070  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
4071  previewImage.fill( Qt::transparent );
4072  QRect imageRect( ( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
4073  QPainter p;
4074  p.begin( &previewImage );
4075  //draw a checkerboard background
4076  uchar pixDataRGB[] = { 150, 150, 150, 150,
4077  100, 100, 100, 150,
4078  100, 100, 100, 150,
4079  150, 150, 150, 150
4080  };
4081  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
4082  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
4083  QBrush checkerBrush;
4084  checkerBrush.setTexture( pix );
4085  p.fillRect( imageRect, checkerBrush );
4086 
4087  if ( mLayer->opacity() < 1.0 )
4088  {
4089  p.setOpacity( mLayer->opacity() );
4090  }
4091 
4092  p.drawImage( imageRect.left(), imageRect.top(), image );
4093  p.end();
4094  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
4095 }
4096 
4097 
4099  : QgsSymbolLayerWidget( parent, vl )
4100 
4101 {
4102  setupUi( this );
4103  modificationExpressionSelector->setMultiLine( true );
4104  modificationExpressionSelector->setLayer( const_cast<QgsVectorLayer *>( vl ) );
4105  modificationExpressionSelector->registerExpressionContextGenerator( this );
4106  cbxGeometryType->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPolygonLayer.svg" ) ), tr( "Polygon / MultiPolygon" ), QgsSymbol::Fill );
4107  cbxGeometryType->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconLineLayer.svg" ) ), tr( "LineString / MultiLineString" ), QgsSymbol::Line );
4108  cbxGeometryType->addItem( QgsApplication::getThemeIcon( QStringLiteral( "/mIconPointLayer.svg" ) ), tr( "Point / MultiPoint" ), QgsSymbol::Marker );
4109  connect( modificationExpressionSelector, &QgsExpressionLineEdit::expressionChanged, this, &QgsGeometryGeneratorSymbolLayerWidget::updateExpression );
4110  connect( cbxGeometryType, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsGeometryGeneratorSymbolLayerWidget::updateSymbolType );
4111 }
4112 
4114 {
4115  mLayer = static_cast<QgsGeometryGeneratorSymbolLayer *>( l );
4116  modificationExpressionSelector->setExpression( mLayer->geometryExpression() );
4117  cbxGeometryType->setCurrentIndex( cbxGeometryType->findData( mLayer->symbolType() ) );
4118 }
4119 
4121 {
4122  return mLayer;
4123 }
4124 
4125 void QgsGeometryGeneratorSymbolLayerWidget::updateExpression( const QString &string )
4126 {
4127  mLayer->setGeometryExpression( string );
4128 
4129  emit changed();
4130 }
4131 
4132 void QgsGeometryGeneratorSymbolLayerWidget::updateSymbolType()
4133 {
4134  mLayer->setSymbolType( static_cast<QgsSymbol::SymbolType>( cbxGeometryType->currentData().toInt() ) );
4135 
4136  emit symbolChanged();
4137 }
4138 
4139 //
4140 // QgsRandomMarkerFillSymbolLayerWidget
4141 //
4142 
4143 
4145  QgsSymbolLayerWidget( parent, vl )
4146 {
4147  setupUi( this );
4148 
4149  mCountMethodComboBox->addItem( tr( "Absolute Count" ), QgsRandomMarkerFillSymbolLayer::AbsoluteCount );
4150  mCountMethodComboBox->addItem( tr( "Density-based Count" ), QgsRandomMarkerFillSymbolLayer::DensityBasedCount );
4151 
4152  mPointCountSpinBox->setShowClearButton( true );
4153  mPointCountSpinBox->setClearValue( 100 );
4154  mSeedSpinBox->setShowClearButton( true );
4155  mSeedSpinBox->setClearValue( 0 );
4156 
4157  connect( mCountMethodComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRandomMarkerFillSymbolLayerWidget::countMethodChanged );
4158  connect( mPointCountSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsRandomMarkerFillSymbolLayerWidget::countChanged );
4159  connect( mDensityAreaSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRandomMarkerFillSymbolLayerWidget::densityAreaChanged );
4160  connect( mSeedSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsRandomMarkerFillSymbolLayerWidget::seedChanged );
4161  connect( mClipPointsCheckBox, &QCheckBox::toggled, this, [ = ]( bool checked )
4162  {
4163  if ( mLayer )
4164  {
4165  mLayer->setClipPoints( checked );
4166  emit changed();
4167  }
4168  } );
4169 
4172 
4173  connect( mDensityAreaUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsRandomMarkerFillSymbolLayerWidget::densityAreaUnitChanged );
4174 }
4175 
4177 {
4178  if ( !layer || layer->layerType() != QLatin1String( "RandomMarkerFill" ) )
4179  {
4180  return;
4181  }
4182 
4183  mLayer = static_cast<QgsRandomMarkerFillSymbolLayer *>( layer );
4184  whileBlocking( mPointCountSpinBox )->setValue( mLayer->pointCount() );
4185  whileBlocking( mSeedSpinBox )->setValue( mLayer->seed() );
4186  whileBlocking( mClipPointsCheckBox )->setChecked( mLayer->clipPoints() );
4187 
4188  bool showDensityBasedCountWidgets = false;
4189  switch ( mLayer->countMethod() )
4190  {
4192  showDensityBasedCountWidgets = true;
4193  break;
4195  break;
4196  }
4197  mDensityAreaLabel->setVisible( showDensityBasedCountWidgets );
4198  mDensityAreaSpinBox->setVisible( showDensityBasedCountWidgets );
4199  mDensityAreaUnitWidget->setVisible( showDensityBasedCountWidgets );
4200  mDensityAreaDdbtn->setVisible( showDensityBasedCountWidgets );
4201 
4202  whileBlocking( mCountMethodComboBox )->setCurrentIndex( mCountMethodComboBox->findData( mLayer->countMethod() ) );
4203  whileBlocking( mDensityAreaSpinBox )->setValue( mLayer->densityArea() );
4204  mDensityAreaUnitWidget->blockSignals( true );
4205  mDensityAreaUnitWidget->setUnit( mLayer->densityAreaUnit() );
4206  mDensityAreaUnitWidget->setMapUnitScale( mLayer->densityAreaUnitScale() );
4207  mDensityAreaUnitWidget->blockSignals( false );
4208 
4213 }
4214 
4216 {
4217  return mLayer;
4218 }
4219 
4220 void QgsRandomMarkerFillSymbolLayerWidget::countMethodChanged( int )
4221 {
4222 
4223  bool showDensityBasedCountWidgets = false;
4224  switch ( static_cast< QgsRandomMarkerFillSymbolLayer::CountMethod >( mCountMethodComboBox->currentData().toInt() ) )
4225  {
4227  showDensityBasedCountWidgets = true;
4228  break;
4230  break;
4231  }
4232  mDensityAreaLabel->setVisible( showDensityBasedCountWidgets );
4233  mDensityAreaSpinBox->setVisible( showDensityBasedCountWidgets );
4234  mDensityAreaUnitWidget->setVisible( showDensityBasedCountWidgets );
4235  mDensityAreaDdbtn->setVisible( showDensityBasedCountWidgets );
4236 
4237  if ( mLayer )
4238  {
4239  mLayer->setCountMethod( static_cast< QgsRandomMarkerFillSymbolLayer::CountMethod >( mCountMethodComboBox->currentData().toInt() ) );
4240  emit changed();
4241  }
4242 }
4243 
4244 void QgsRandomMarkerFillSymbolLayerWidget::countChanged( int d )
4245 {
4246  if ( mLayer )
4247  {
4248  mLayer->setPointCount( d );
4249  emit changed();
4250  }
4251 }
4252 
4253 void QgsRandomMarkerFillSymbolLayerWidget::densityAreaChanged( double d )
4254 {
4255  if ( mLayer )
4256  {
4257  mLayer->setDensityArea( d );
4258  emit changed();
4259  }
4260 }
4261 
4262 void QgsRandomMarkerFillSymbolLayerWidget::densityAreaUnitChanged()
4263 {
4264  if ( mLayer )
4265  {
4266  mLayer->setDensityAreaUnit( mDensityAreaUnitWidget->unit() );
4267  mLayer->setDensityAreaUnitScale( mDensityAreaUnitWidget->getMapUnitScale() );
4268  emit changed();
4269  }
4270 }
4271 
4272 void QgsRandomMarkerFillSymbolLayerWidget::seedChanged( int d )
4273 {
4274  if ( mLayer )
4275  {
4276  mLayer->setSeed( d );
4277  emit changed();
4278  }
4279 }
void setOffset(QPointF offset)
Sets the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered marker...
QColor color2() const
Returns the color used for the endpoint of the shapeburst fill.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
void setSvgStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the pattern&#39;s stroke.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the symbol placement.
double hashLength() const
Returns the length of hash symbols.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static QgsSvgCache * svgCache()
Returns the application&#39;s SVG cache, used for caching SVG images and handling parameter replacement w...
QgsUnitTypes::RenderUnit customDashPatternUnit() const
Returns the units for lengths used in the custom dash pattern.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Place symbols on the first vertex in the line.
Meters value as Map units.
Definition: qgsunittypes.h:154
void setDistance(double d)
Sets the distance between lines in the fill pattern.
Single variable definition for use within a QgsExpressionContextScope.
RenderRingFilter ringFilter() const
Returns the line symbol layer&#39;s ring filter, which controls which rings are rendered when the line sy...
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void symbolChanged()
Should be emitted whenever the sub symbol changed on this symbol layer configuration.
Gradient reference point 1 is centroid.
const QgsMapUnitScale & displacementYMapUnitScale() const
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
const QgsMapUnitScale & offsetXMapUnitScale() const
Returns the unit scale for the horizontal offset for rows in the pattern.
QgsMarkerLineSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsMarkerLineSymbolLayerWidget.
void setColorStroke(const QColor &color)
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to an icon.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol&#39;s offset.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setSymbolLayer(QgsSymbolLayer *layer) override
double fixedAspectRatio() const
Returns the marker aspect ratio between width and height to be used in rendering, if the value set is...
void setColorFill(const QColor &color)
void setPointCount(int count)
Sets the count of random points to render in the fill.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the marker&#39;s stroke join style (e.g., miter, bevel, etc).
QgsSymbolLayer * symbolLayer() override
QgsGradientFillSymbolLayer * mLayer
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the stroke width map unit scale.
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used for the gradient fill.
QgsRasterMarkerSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsRasterMarkerSymbolLayerWidget.
QString svgFilePath() const
Returns the path to the SVG file used to render the fill.
void setPatternWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the width of the SVG images in the pattern.
QColor strokeColor() const override
Gets stroke color.
double defaultAspectRatio() const
Returns the default marker aspect ratio between width and height, 0 if not yet calculated.
QVector< qreal > dashDotVector() const
Returns the dash pattern as a list of numbers.
void setSymbolLayer(QgsSymbolLayer *layer) override
bool dockMode()
Returns the dock mode state.
void setPlacement(Placement placement)
Sets the placement of the symbols.
void setSymbolLayer(QgsSymbolLayer *layer) override
Gradient reference point 1 x.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the fill&#39;s offset.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance between lines in the fill pattern.
QgsSymbolLayer * symbolLayer() override
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setSvgFillColor(const QColor &c)
Sets the fill color used for rendering the SVG content.
void setPatternWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the pattern&#39;s width.
QString fontFamily() const
Returns the font family name for the associated font which will be used to render the point...
void setUseCustomDashPattern(bool b)
Sets whether the line uses a custom dash pattern.
A model for displaying SVG files with a preview icon.
void setSymbolLayer(QgsSymbolLayer *layer) override
const QgsMapUnitScale & displacementXMapUnitScale() const
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:182
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
QString imageFilePath() const
The path to the raster image used for the fill.
QPointF offset() const
Returns the offset for the shapeburst fill.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)
Sets the unit for the width of the marker&#39;s stroke.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setStrokeStyle(Qt::PenStyle strokeStyle)
Sets the marker&#39;s stroke style (e.g., solid, dashed, etc)
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke...
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the offset of the shapeburst fill.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
GradientCoordinateMode coordinateMode() const
Coordinate mode for gradient. Controls how the gradient stops are positioned.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the line&#39;s offset.
QgsFontMarkerSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setReferencePoint1IsCentroid(bool isCentroid)
Sets the starting point of the gradient to be the feature centroid.
Qt::PenJoinStyle penJoinStyle() const
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the line pattern&#39;s offset.
GradientSpread gradientSpread() const
Gradient spread mode. Controls how the gradient behaves outside of the predefined stops...
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the fill&#39;s offset.
A symbol fill consisting of repeated parallel lines.
QgsSimpleFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsSimpleFillSymbolLayerWidget.
const QgsMapUnitScale & sizeMapUnitScale() const
Returns the map unit scale for the symbol&#39;s size.
QString geometryExpression() const
Gets the expression to generate this geometry.
void lockChanged(bool locked)
Emitted whenever the lock state changes.
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasStrokeParam, QColor &defaultStrokeColor, bool &hasStrokeWidthParam, double &defaultStrokeWidth, bool blocking=false) const
Tests if an svg file contains parameters for fill, stroke color, stroke width.
double angle() const
void setOffsetYMapUnitScale(const QgsMapUnitScale &scale)
Sets the unit scale for the vertical offset for rows in the pattern.
QgsLinePatternFillSymbolLayer * mLayer
void setColorRamp(QgsColorRamp *ramp)
Sets the color ramp used to draw the shapeburst fill.
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the image&#39;s width.
void setDisplacementYUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the vertical displacement between rows in the pattern.
static QgsImageCache * imageCache()
Returns the application&#39;s image cache, used for caching resampled versions of raster images...
QgsGradientFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsGradientFillSymbolLayerWidget.
A simple line symbol layer, which renders lines using a line in a variety of styles (e...
double averageAngleLength() const
Returns the length of line over which the line&#39;s direction is averaged when calculating individual sy...
void setOffset(QPointF offset)
Sets the offset for the shapeburst fill.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
QgsUnitTypes::RenderUnit patternWidthUnit() const
Returns the units for the width of the SVG images in the pattern.
Render both exterior and interior rings.
QgsSymbolLayer * symbolLayer() override
void setAngle(double angle)
Abstract base class for color ramps.
Definition: qgscolorramp.h:31
void sourceChanged(const QString &source)
Emitted whenever the file source is changed in the widget.
void setOffsetY(double offset)
Sets the vertical offset values for points in the pattern.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setUseWholeShape(bool useWholeShape)
Sets whether the shapeburst fill should be drawn using the entire shape.
A widget for displaying characters available in a preset font, and allowing users to select an indivi...
void setStrokeColor(const QColor &color) override
Sets the marker&#39;s stroke color.
Whether markers should be clipped to polygon boundaries.
void setCharacter(QChar character)
Sets the currently selected character in the widget.
void setSymbolLayer(QgsSymbolLayer *layer) override
const QgsMapUnitScale & hashLengthMapUnitScale() const
Returns the map unit scale for the hash length.
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the maximum distance to shade inside of the shape from the polygon&#39;s boundary...
void setColor(const QColor &color)
const QgsMapUnitScale & strokeWidthMapUnitScale() const
ShapeburstColorType colorType() const
Returns the color mode used for the shapeburst fill.
QgsUnitTypes::RenderUnit averageAngleUnit() const
Returns the unit for the length over which the line&#39;s direction is averaged when calculating individu...
void setSymbolLayer(QgsSymbolLayer *layer) override
QgsUnitTypes::RenderUnit offsetYUnit() const
Returns the units for the vertical offset for rows in the pattern.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void setStrokeColor(const QColor &c) override
Set stroke color.
void setStrokeWidth(double w)
Sets the width of the marker&#39;s stroke.
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
QgsSymbolLayer * symbolLayer() override
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the distance between lines in the fill pattern.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol&#39;s offset.
void setStrokeWidth(double width)
Set&#39;s the marker&#39;s stroke width.
VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
A widget to enter a custom dash space pattern for lines.
void setUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit type used for the dash space pattern (used to update interface labels) ...
bool useWholeShape() const
Returns whether the shapeburst fill is set to cover the entire shape.
void setOffsetUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units for the fill&#39;s offset.
void setDistanceXMapUnitScale(const QgsMapUnitScale &scale)
Base class for any widget that can be shown as a inline panel.
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the symbol&#39;s offset.
void setDensityAreaUnitScale(const QgsMapUnitScale &scale)
Sets the map scale for the density area.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the line&#39;s offset.
Line symbol.
Definition: qgssymbol.h:87
QColor strokeColor() const override
Returns the marker&#39;s stroke color.
A fill symbol layer which places markers at random locations within polygons.
QgsCentroidFillSymbolLayer * mLayer
QColor color2() const
Color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.
Place symbols on every vertex in the line.
void setReferencePoint2IsCentroid(bool isCentroid)
Sets the end point of the gradient to be the feature centroid.
const QgsMapUnitScale & averageAngleMapUnitScale() const
Returns the map unit scale for the length over which the line&#39;s direction is averaged when calculatin...
QgsUnitTypes::RenderUnit intervalUnit() const
Returns the units for the interval between symbols.
QgsSVGFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsSVGFillSymbolLayerWidget.
double interval() const
Returns the interval between individual symbols.
const QgsMapUnitScale & svgStrokeWidthMapUnitScale() const
Returns the map unit scale for the pattern&#39;s stroke.
static QString encodeShape(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Encodes a shape to its string representation.
void setPointOnAllParts(bool pointOnAllParts)
Sets whether a point is drawn for all parts or only on the biggest part of multi-part features...
Qt::PenJoinStyle penJoinStyle() const
Returns the stroke join style.
void setCharacterFromText(const QString &text)
Set the font marker character from a text string.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
Tiling is based on complete map viewport.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:218
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
void setInterval(double interval)
Sets the interval between individual symbols.
virtual double width() const
Returns the estimated width for the line symbol layer.
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:895
Name, eg shape name for simple markers.
void setStrokeWidth(double strokeWidth)
void setPatternWidth(double width)
Sets the width to render the SVG content as within the fill (i.e.
void setWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the line&#39;s width.
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1095
Gradient reference point 2 y.
static QList< QgsSimpleMarkerSymbolLayerBase::Shape > availableShapes()
Returns a list of all available shape types.
double lineAngle() const
Returns the angle for the parallel lines used to fill the symbol.
QgsShapeburstFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsShapeburstFillSymbolLayerWidget.
QgsUnitTypes::RenderUnit densityAreaUnit() const
Returns the units for the density area.
QString path() const
Returns the marker SVG path.
void setSymbolLayer(QgsSymbolLayer *layer) override
QColor strokeColor() const override
Gets stroke color.
void setGradientType(GradientType gradientType)
Place symbols at every virtual curve point in the line (used when rendering curved geometry types onl...
void clearCharacter()
Clears the currently selected character in the widget.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the stroke join style.
double strokeWidth() const
Returns the width of the marker&#39;s stroke.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the pattern&#39;s line offset.
void setPath(const QString &path)
Set the marker SVG path.
void setCustomDashPatternUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for lengths used in the custom dash pattern.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the line pattern&#39;s offset.
void setCoordinateMode(FillCoordinateMode mode)
Set the coordinate mode for fill.
virtual void setColor(const QColor &color)
The fill color.
double offsetY() const
Returns the vertical offset values for points in the pattern.
const QgsMapUnitScale & offsetYMapUnitScale() const
Returns the unit scale for the vertical offset between rows in the pattern.
Place symbols at the center of every line segment.
void setOffset(QPointF offset)
void setBlurRadius(int blurRadius)
Sets the blur radius, which controls the amount of blurring applied to the fill.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setAverageAngleUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the length over which the line&#39;s direction is averaged when calculating individual ...
void setSymbolLayer(QgsSymbolLayer *layer) override
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
QgsSymbolLayer * symbolLayer() override
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the stroke width unit.
HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
void setIgnoreRings(bool ignoreRings)
Sets whether the shapeburst fill should ignore polygon rings when calculating the buffered shading...
double offset() const
Returns the offset distance for lines within the fill, which is the distance to offset the parallel l...
A dialog to create a new auxiliary layer.
void setField(const QString &field)
Sets the field name the property references.
void setLineAngle(double a)
Sets the angle for the parallel lines used to fill the symbol.
const QgsMapUnitScale & distanceMapUnitScale() const
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the stroke width.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
CountMethod countMethod() const
Returns the count method used to randomly fill the polygon.
Raster marker symbol layer class.
A class for filling symbols with a repeated raster image.
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for symbols...
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
A cross platform button subclass used to represent a locked / unlocked ratio state.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
A dialog to enter a custom dash space pattern for lines.
A button for controlling property overrides which may apply to a widget.
void setIntervalUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the interval between symbols.
void setStrokeColor(const QColor &color) override
Set stroke color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolLayer * symbolLayer() override
QgsMarkerLineSymbolLayer * mLayer
void setColor2(const QColor &color2)
Sets the color for the endpoint of the shapeburst fill.
QgsRasterMarkerSymbolLayer * mLayer
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
QgsSimpleLineSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsSimpleLineSymbolLayerWidget.
void setColor(const QColor &color) override
The fill color.
QgsSimpleFillSymbolLayer * mLayer
void setWidth(const double width)
Sets the width for scaling the image used in the fill.
void setCountMethod(CountMethod method)
Sets the count method used to randomly fill the polygon.
double offsetX() const
Returns the horizontal offset values for points in the pattern.
QgsUnitTypes::RenderUnit displacementYUnit() const
Returns the units for the vertical displacement between rows in the pattern.
double opacity() const
Returns the marker opacity.
QgsUnitTypes::RenderUnit widthUnit() const
Returns the units for the line&#39;s width.
void setFixedAspectRatio(double ratio)
Set the marker aspect ratio between width and height to be used in rendering, if the value set is low...
void setReferencePoint1(QPointF referencePoint)
Starting point of gradient fill, in the range [0,0] - [1,1].
bool clipPoints() const
Returns true if point markers should be clipped to the polygon boundary.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget...
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map scale for the width of the marker&#39;s stroke.
QVector< qreal > customDashVector() const
Returns the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
QgsCentroidFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsCentroidFillSymbolLayerWidget.
void setSvgStrokeWidth(double w)
Sets the stroke width used for rendering the SVG content.
QgsRandomMarkerFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsRandomMarkerFillSymbolLayerWidget.
const QgsMapUnitScale & strokeWidthMapUnitScale() const
Returns the stroke width map unit scale.
void setDensityArea(double area)
Sets the density area used to count the number of points to randomly fill the polygon.
void resizeEvent(QResizeEvent *event) override
void setHashLengthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the hash length.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
double size() const
Returns the symbol size.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1...
void setOffsetXUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the horizontal offset between rows in the pattern.
bool preservedAspectRatio() const
Returns the preserved aspect ratio value, true if fixed aspect ratio has been lower or equal to 0...
Render the interior rings only.
virtual QgsSymbolLayer * symbolLayer()=0
void setSymbolLayer(QgsSymbolLayer *layer) override
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double densityArea() const
Returns the density area used to count the number of points to randomly fill the polygon.
const QgsMapUnitScale & strokeWidthMapUnitScale() const
Returns the map scale for the width of the marker&#39;s stroke.
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the image&#39;s width.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer&#39;s property collection, used for data defined overrides...
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
Line symbol layer type which draws repeating line sections along a line feature.
const QgsMapUnitScale & offsetMapUnitScale() const
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol&#39;s size.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the fill&#39;s offset.
QgsSvgMarkerSymbolLayer * mLayer
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
QgsShapeburstFillSymbolLayer * mLayer
void setStrokeStyle(Qt::PenStyle strokeStyle)
virtual QColor color() const
The fill color.
QgsSymbolLayer * symbolLayer() override
void setDistanceYMapUnitScale(const QgsMapUnitScale &scale)
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QColor fillColor() const override
Gets fill color.
Filename, eg for svg files.
void setRotateSymbols(bool rotate)
Sets whether the repeating symbols should be rotated to match their line segment orientation.
QgsFilledMarkerSymbolLayer * mLayer
void setSymbolType(QgsSymbol::SymbolType symbolType)
Set the type of symbol which should be created.
QgsUnitTypes::RenderUnit offsetXUnit() const
Returns the units for the horizontal offset for rows in the pattern.
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition: qgssymbol.h:52
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the stroke width unit.
void setSymbolLayer(QgsSymbolLayer *layer) override
QgsUnitTypes::RenderUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for symbols.
Shapeburst fill from edge distance.
bool ignoreRings() const
Returns whether the shapeburst fill is set to ignore polygon interior rings.
QgsUnitTypes::RenderUnit offsetUnit() const
Qt::PenJoinStyle penJoinStyle() const
Returns the pen join style used to render the line (e.g.
Character, eg for font marker symbol layers.
void setCharacter(QChar chr)
Set the font marker character from char.
double offset() const
Returns the line&#39;s offset.
Qt::PenJoinStyle penJoinStyle() const
Returns the marker&#39;s stroke join style (e.g., miter, bevel, etc).
QgsPointPatternFillSymbolLayer * mLayer
void setPenJoinStyle(Qt::PenJoinStyle style)
bool useCustomDashPattern() const
Returns true if the line uses a custom dash pattern.
QgsSimpleMarkerSymbolLayerBase::Shape shape() const
Returns the shape for the rendered marker symbol.
void setOpacity(double opacity)
Set the marker opacity.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
Definition: qgsproperty.h:229
QgsUnitTypes::RenderUnit svgStrokeWidthUnit() const
Returns the units for the stroke width.
QColor svgStrokeColor() const
Returns the stroke color used for rendering the SVG content.
QString path() const
Returns the marker raster image path.
QgsRasterFillSymbolLayer * mLayer
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setHashAngle(double angle)
Sets the angle to use when drawing the hashed lines sections, in degrees clockwise.
QgsSymbolLayer * symbolLayer() override
Tiling is based on feature bounding box.
void setDisplacementXMapUnitScale(const QgsMapUnitScale &scale)
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for symbols...
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
void setOffset(QPointF offset)
Sets the offset for the fill.
void setPath(const QString &path)
Set the marker raster image path.
void setSeed(unsigned long seed)
Sets the random number seed to use when generating points, or 0 if a truly random sequence will be us...
QgsSymbolLayer * symbolLayer() override
void setPenStyle(Qt::PenStyle style)
Sets the pen style used to render the line (e.g.
int pointCount() const
Returns the count of random points to render in the fill.
void widgetChanged()
Emitted when the widget state changes.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setSymbolLayer(QgsSymbolLayer *layer) override
void setMapUnitScale(const QgsMapUnitScale &scale) FINAL
QgsGeometryGeneratorSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsGeometryGeneratorSymbolLayerWidget.
void setColor(const QColor &color)
QgsSvgMarkerSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsSvgMarkerSymbolLayerWidget.
Qt::PenStyle strokeStyle() const
Returns the marker&#39;s stroke style (e.g., solid, dashed, etc)
Definition for a property.
Definition: qgsproperty.h:46
void setHashLengthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the length of hash symbols.
HorizontalAnchorPoint
Symbol horizontal anchor points.
QString character() const
Returns the character(s) used when rendering points.
void setSvgStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the stroke width.
Gradient reference point 1 y.
Place symbols at regular intervals.
void setStrokeColor(const QColor &strokeColor) override
Set stroke color.
void setFont(const QFont &font)
Sets the font to show in the widget.
void setOffset(QPointF offset)
Offset for gradient fill.
VerticalAnchorPoint
Symbol vertical anchor points.
void expressionChanged(const QString &expression)
Emitted when the expression is changed.
void setDistanceXUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the horizontal distance between points in the pattern.
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
void sourceChanged(const QString &source)
Emitted whenever the SVG source is changed in the widget.
QgsSimpleMarkerSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsSimpleMarkerSymbolLayerWidget.
Qt::BrushStyle brushStyle() const
Line angle, or angle of hash lines for hash line symbols.
void setFixedAspectRatio(double ratio)
Set the marker aspect ratio between width and height to be used in rendering, if the value set is low...
GradientType gradientType() const
Type of gradient, e.g., linear or radial.
const QgsMapUnitScale & distanceMapUnitScale() const
Returns the map unit scale for the pattern&#39;s line distance.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void changed()
Emitted when property definition changes.
A model for displaying SVG search paths.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key)
Registers a data defined override button.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the symbol&#39;s size.
double defaultAspectRatio() const
Returns the default marker aspect ratio between width and height, 0 if not yet calculated.
Marker symbol.
Definition: qgssymbol.h:86
A class for filling symbols with a repeated SVG file.
Stroke style (eg solid, dashed)
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the unit for the width of the marker&#39;s stroke.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
Fill symbol.
Definition: qgssymbol.h:88
double hashAngle() const
Returns the angle to use when drawing the hashed lines sections, in degrees clockwise.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:262
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the fill&#39;s offset.
QgsSimpleLineSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setContext(const QgsSymbolWidgetContext &context) override
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
const QgsMapUnitScale & intervalMapUnitScale() const
Returns the map unit scale for the interval between symbols.
void setShape(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Sets the rendered marker shape.
bool drawInsidePolygon() const
Returns true if the line should only be drawn inside polygons, and any portion of the line which fall...
QgsPointPatternFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsPointPatternFillSymbolLayerWidget.
QgsHashedLineSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsHashedLineSymbolLayerWidget.
void setGeometryExpression(const QString &exp)
Set the expression to generate this geometry.
void setGradientColorType(GradientColorType gradientColorType)
Line symbol layer type which draws repeating marker symbols along a line feature. ...
QgsFilledMarkerSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsFilledMarkerSymbolLayerWidget.
Points (e.g., for font sizes)
Definition: qgsunittypes.h:151
QColor svgFillColor() const
Returns the fill color used for rendering the SVG content.
bool preservedAspectRatio() const
Returns the preserved aspect ratio value, true if fixed aspect ratio has been lower or equal to 0...
void setWidthUnit(const QgsUnitTypes::RenderUnit unit)
Sets the units for the image&#39;s width.
QgsSvgMarkerSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSimpleMarkerSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsUnitTypes::RenderUnit distanceXUnit() const
Returns the units for the horizontal distance between points in the pattern.
void updateParamGui(bool resetValues=true)
Enables or disables svg fill color, stroke color and stroke width based on whether the svg file suppo...
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the symbol&#39;s size.
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for lengths used in the custom dash pattern.
QgsUnitTypes::RenderUnit displacementXUnit() const
Returns the units for the horizontal displacement between rows in the pattern.
The point count is part of a marker density count.
const QgsMapUnitScale & densityAreaUnitScale() const
Returns the map scale for the density area.
const QgsMapUnitScale & distanceXMapUnitScale() const
const QgsMapUnitScale & patternWidthMapUnitScale() const
Returns the map unit scale for the pattern&#39;s width.
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
void setSvgFilePath(const QString &svgPath)
Sets the path to the SVG file to render in the fill.
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the interval between symbols.
QgsSymbolLayer * symbolLayer() override
Qt::PenStyle penStyle() const
Returns the pen style used to render the line (e.g.
Qt::PenStyle strokeStyle() const
const QgsMapUnitScale & offsetMapUnitScale() const
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the width of the fill&#39;s stroke.
QgsSymbolLayer * symbolLayer() override
void setSymbolLayer(QgsSymbolLayer *layer) override
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr)
Returns a pixmap preview for a color ramp.
double strokeWidth() const
Returns the marker&#39;s stroke width.
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
int propertyKey() const
Returns the property key linked to the button.
GradientColorType gradientColorType() const
Gradient color mode, controls how gradient color stops are created.
Distance between lines, or length of lines for hash line symbols.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the line&#39;s offset.
virtual void setSize(double size)
Sets the symbol size.
void setRingFilter(QgsLineSymbolLayer::RenderRingFilter filter)
Sets the line symbol layer&#39;s ring filter, which controls which rings are rendered when the line symbo...
void setStrokeColor(const QColor &color)
const QgsMapUnitScale & distanceYMapUnitScale() const
QColor fillColor() const override
Gets fill color.
FillCoordinateMode coordinateMode() const
Coordinate mode for fill.
QgsMessageBar * messageBar() const
Returns the message bar associated with the widget.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
QgsFontMarkerSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsFontMarkerSymbolLayerWidget.
void setColorStroke(const QColor &color)
Set stroke color.
double patternWidth() const
Returns the width of the rendered SVG content within the fill (i.e.
const QgsMapUnitScale & widthMapUnitScale() const
Returns the map unit scale for the image&#39;s width.
unsigned long seed() const
Returns the random number seed to use when generating points, or 0 if a truly random sequence will be...
QgsLinePatternFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsLinePatternFillSymbolLayerWidget.
void setOffsetX(double offset)
Sets the horizontal offset values for points in the pattern.
void setDisplacementXUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the horizontal displacement between rows in the pattern.
QgsSymbol::SymbolType symbolType() const
Access the symbol type.
Secondary color (eg for gradient fills)
void setDrawInsidePolygon(bool drawInsidePolygon)
Sets whether the line should only be drawn inside polygons, and any portion of the line which falls o...
double maxDistance() const
Returns the maximum distance from the shape&#39;s boundary which is shaded.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setCustomDashVector(const QVector< qreal > &vector)
Sets the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ren...
void setDisplacementYMapUnitScale(const QgsMapUnitScale &scale)
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units for the stroke width.
void setFontFamily(const QString &family)
Sets the font family for the font which will be used to render the point.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
bool pointOnAllParts() const
Returns whether a point is drawn for all parts or only on the biggest part of multi-part features...
void setCharacter(QString chr)
Sets the character(s) used when rendering points.
void setMaxDistance(double maxDistance)
Sets the maximum distance to shape inside of the shape from the polygon&#39;s boundary.
QgsRasterFillSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsRasterFillSymbolLayerWidget.
void setOffsetYUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the vertical offset for rows in the pattern.
double opacity() const
Returns the opacity for the raster image used in the fill.
void setColor2(const QColor &color2)
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
The point count is used as an absolute count of markers.
void setOffsetXMapUnitScale(const QgsMapUnitScale &scale)
Sets the unit scale for the horizontal offset for rows in the pattern.
void setAngle(double angle)
Sets the rotation angle for the marker.
Placement placement() const
Returns the placement of the symbols.
Place symbols on the last vertex in the line.
const QgsMapUnitScale & widthMapUnitScale() const
QgsSimpleLineSymbolLayer * mLayer
const QgsMapUnitScale & customDashPatternMapUnitScale() const
Returns the map unit scale for lengths used in the custom dash pattern.
Length to average symbol angles over.
QgsSymbolLayer * symbolLayer() override
QgsSymbolLayer * symbolLayer() override
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setOffsetAlongLineUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit used for calculating the offset along line for symbols.
Render the exterior ring only.
void setBrushStyle(Qt::BrushStyle style)
QgsColorRamp * colorRamp()
Returns the color ramp used for the gradient fill.
double svgStrokeWidth() const
Returns the stroke width used for rendering the SVG content.
void setFillColor(const QColor &color) override
Set fill color.
static bool shapeIsFilled(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Returns true if a symbol shape has a fill.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the fill&#39;s offset.
void setAverageAngleLength(double length)
Sets the length of line over which the line&#39;s direction is averaged when calculating individual symbo...
QColor strokeColor() const override
Gets stroke color.
const QgsMapUnitScale & strokeWidthMapUnitScale() const
int blurRadius() const
Returns the blur radius, which controls the amount of blurring applied to the fill.
QgsFontMarkerSymbolLayer * mLayer
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the offset for the shapeburst fill.
Place symbols at the mid point of the line.
Shapeburst blur radius.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
void setOffset(double offset)
Sets the offset distance for lines within the fill, which is the distance to offset the parallel line...
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units for the width of the fill&#39;s stroke.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the line&#39;s offset.
void setOpacity(double opacity)
Sets the opacity for the raster image used in the fill.
double fixedAspectRatio() const
Returns the marker aspect ratio between width and height to be used in rendering, if the value set is...
void setAverageAngleMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the length over which the line&#39;s direction is averaged when calculating i...
void setSvgStrokeColor(const QColor &c)
Sets the stroke color used for rendering the SVG content.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Units for gradient fill offset.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the pattern&#39;s line offset.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
double distance() const
Returns the distance between lines in the fill pattern.
QPointF offset() const
Returns the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered mar...
Filled marker symbol layer, consisting of a shape which is rendered using a QgsFillSymbol.
void setColorType(ShapeburstColorType colorType)
Sets the color mode to use for the shapeburst fill.
void setHashLength(double length)
Sets the length of hash symbols.
Fill style (eg solid, dots)
Represents a vector layer which manages a vector based data sets.
void setDistanceYUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the vertical distance between points in the pattern.
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false)
Returns the specified path rendered as an image.
Qt::PenCapStyle penCapStyle() const
Returns the pen cap style used to render the line (e.g.
void updateFieldLists()
Updates list of fields.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the symbol&#39;s offset.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
void setSymbolLayer(QgsSymbolLayer *layer) override
void applyColorRamp()
Applies the color ramp passed on by the color ramp button.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout)...
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
double width() const
Returns the width used for scaling the image used in the fill.
QgsColorRamp * colorRamp()
Returns the color ramp used for the shapeburst fill.
QgsFilledMarkerSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
const QgsMapUnitScale & offsetMapUnitScale() const
Gradient reference point 2 is centroid.
void setGradientSpread(GradientSpread gradientSpread)
void setGuiForSvg(const QgsSvgMarkerSymbolLayer *layer)
double offsetAlongLine() const
Returns the offset along the line for the symbol placement.
void characterSelected(QChar character)
Emitted when a character is selected in the widget.
QgsSimpleMarkerSymbolLayer * mLayer
void setCoordinateMode(GradientCoordinateMode coordinateMode)
void setReferencePoint2(QPointF referencePoint)
End point of gradient fill, in the range [0,0] - [1,1].
QgsPropertyDefinition propertyDefinition() const
Returns the underlying property definition.
Gradient reference point 2 x.
void setDensityAreaUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the density area.
void setUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit type used for the dash space pattern (used to update interface labels) ...
QgsSVGFillSymbolLayer * mLayer
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the pattern&#39;s line distance.
void setClipPoints(bool clipped)
Sets whether point markers should be clipped to the polygon boundary.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
QgsUnitTypes::RenderUnit distanceYUnit() const
Returns the units for the vertical distance between points in the pattern.
Property
Data definable properties.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
QgsSymbolLayer * symbolLayer() override
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
A dialog to create a new auxiliary field.
void setPointOnSurface(bool pointOnSurface)
QgsUnitTypes::RenderUnit hashLengthUnit() const
Returns the units for the length of hash symbols.
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...
void setOffset(double offset)
Sets the line&#39;s offset.
Horizontal distance between points.
QPointF offset() const
Returns the offset for the fill.
virtual QString layerType() const =0
Returns a string that represents this layer type.
bool rotateSymbols() const
Returns true if the repeating symbols be rotated to match their line segment orientation.
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the unit for the maximum distance to shade inside of the shape from the polygon&#39;s boundary...
Vertical distance between points.