QGIS API Documentation  2.17.0-Master (0497e4a)
qgssymbollayerv2widget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2widget.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 "qgssymbollayerv2widget.h"
18 
19 #include "qgslinesymbollayerv2.h"
20 #include "qgsmarkersymbollayerv2.h"
21 #include "qgsfillsymbollayerv2.h"
23 #include "qgssymbolslistwidget.h"
24 
25 #include "characterwidget.h"
26 #include "qgsdashspacedialog.h"
29 #include "qgssvgcache.h"
30 #include "qgssymbollayerv2utils.h"
31 #include "qgsvectorcolorrampv2.h"
33 #include "qgsdatadefined.h"
34 #include "qgsstylev2.h" //for symbol selector dialog
35 #include "qgsmapcanvas.h"
36 #include "qgsapplication.h"
37 
38 #include "qgslogger.h"
39 #include "qgssizescalewidget.h"
40 
41 #include <QAbstractButton>
42 #include <QColorDialog>
43 #include <QCursor>
44 #include <QDir>
45 #include <QFileDialog>
46 #include <QPainter>
47 #include <QSettings>
48 #include <QStandardItemModel>
49 #include <QSvgRenderer>
50 #include <QMessageBox>
51 
52 static QgsExpressionContext _getExpressionContext( const void* context )
53 {
54  const QgsSymbolLayerV2Widget* widget = ( const QgsSymbolLayerV2Widget* ) context;
55 
56  if ( widget->expressionContext() )
57  return QgsExpressionContext( *widget->expressionContext() );
58 
59  QgsExpressionContext expContext;
63 
64  if ( widget->mapCanvas() )
65  {
68  }
69  else
70  {
72  }
73 
74  const QgsVectorLayer* layer = widget->vectorLayer();
75  if ( layer )
76  expContext << QgsExpressionContextUtils::layerScope( layer );
77 
79  if ( const QgsSymbolLayerV2* symbolLayer = const_cast< QgsSymbolLayerV2Widget* >( widget )->symbolLayer() )
80  {
81  //cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols*
82  //color, but that's not accessible here). 99% of the time these will be the same anyway
83  symbolScope->setVariable( QgsExpressionContext::EXPR_SYMBOL_COLOR, symbolLayer->color() );
84  }
85  expContext << symbolScope;
90 
91  //TODO - show actual value
92  expContext.setOriginalValueVariable( QVariant() );
96 
97  return expContext;
98 }
99 
101 {
102  mMapCanvas = canvas;
103  Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
104  {
105  unitWidget->setMapCanvas( mMapCanvas );
106  }
107  Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
108  {
109  if ( ddButton->assistant() )
110  ddButton->assistant()->setMapCanvas( mMapCanvas );
111  }
112 }
113 
115 {
116  return mMapCanvas;
117 }
118 
120 {
121  const QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
122  button->init( mVectorLayer, dd, type, description );
123  button->setProperty( "propertyName", propertyName );
124  connect( button, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty() ) );
125  connect( button, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty() ) );
126 
128 }
129 
131 {
132  QgsDataDefinedButton* button = qobject_cast<QgsDataDefinedButton*>( sender() );
133  const QString propertyName( button->property( "propertyName" ).toString() );
134 
135  QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
136  if ( !dd )
137  {
138  dd = new QgsDataDefined();
139  symbolLayer()->setDataDefinedProperty( propertyName, dd );
140  }
141  button->updateDataDefined( dd );
142 
143  emit changed();
144 }
145 
147 {
148  QString label = entryName;
149  if ( entryName == "size" )
150  {
151  label = tr( "Size" );
152  QgsMarkerSymbolLayerV2 * layer = dynamic_cast<QgsMarkerSymbolLayerV2 *>( symbolLayer() );
153  if ( layer )
154  {
155  switch ( layer->scaleMethod() )
156  {
158  label += " (" + tr( "area" ) + ')';
159  break;
161  label += " (" + tr( "diameter" ) + ')';
162  break;
163  }
164  }
165  }
166  return label;
167 }
168 
170  : QgsSymbolLayerV2Widget( parent, vl )
171 {
172  mLayer = nullptr;
173 
174  setupUi( this );
175  mPenWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
177  mDashPatternUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
178 
179  btnChangeColor->setAllowAlpha( true );
180  btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
181  btnChangeColor->setContext( "symbology" );
182 
183  spinOffset->setClearValue( 0.0 );
184 
185  if ( vl && vl->geometryType() != QGis::Polygon )
186  {
187  //draw inside polygon checkbox only makes sense for polygon layers
188  mDrawInsideCheckBox->hide();
189  }
190 
191  //make a temporary symbol for the size assistant preview
192  mAssistantPreviewSymbol = new QgsLineSymbolV2();
193 
194  if ( mVectorLayer )
195  mPenWidthDDBtn->setAssistant( tr( "Width Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
196 
197 
198  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
199  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
200  connect( cboPenStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
201  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
202  connect( cboCapStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
203  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
204 
206 
207  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
208 }
209 
211 {
212  delete mAssistantPreviewSymbol;
213 }
214 
215 void QgsSimpleLineSymbolLayerV2Widget::updateAssistantSymbol()
216 {
217  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
218  {
219  mAssistantPreviewSymbol->deleteSymbolLayer( i );
220  }
221  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
222  QgsDataDefined* ddWidth = mLayer->getDataDefinedProperty( "width" );
223  if ( ddWidth )
224  mAssistantPreviewSymbol->setDataDefinedWidth( *ddWidth );
225 }
226 
227 
229 {
230  if ( !layer || layer->layerType() != "SimpleLine" )
231  return;
232 
233  // layer type is correct, we can do the cast
234  mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>( layer );
235 
236  // set units
237  mPenWidthUnitWidget->blockSignals( true );
238  mPenWidthUnitWidget->setUnit( mLayer->widthUnit() );
239  mPenWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
240  mPenWidthUnitWidget->blockSignals( false );
241  mOffsetUnitWidget->blockSignals( true );
242  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
243  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
244  mOffsetUnitWidget->blockSignals( false );
245  mDashPatternUnitWidget->blockSignals( true );
246  mDashPatternUnitWidget->setUnit( mLayer->customDashPatternUnit() );
247  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
248  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
249  mDashPatternUnitWidget->blockSignals( false );
250 
251  // set values
252  spinWidth->blockSignals( true );
253  spinWidth->setValue( mLayer->width() );
254  spinWidth->blockSignals( false );
255  btnChangeColor->blockSignals( true );
256  btnChangeColor->setColor( mLayer->color() );
257  btnChangeColor->blockSignals( false );
258  spinOffset->blockSignals( true );
259  spinOffset->setValue( mLayer->offset() );
260  spinOffset->blockSignals( false );
261  cboPenStyle->blockSignals( true );
262  cboJoinStyle->blockSignals( true );
263  cboCapStyle->blockSignals( true );
264  cboPenStyle->setPenStyle( mLayer->penStyle() );
265  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
266  cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
267  cboPenStyle->blockSignals( false );
268  cboJoinStyle->blockSignals( false );
269  cboCapStyle->blockSignals( false );
270 
271  //use a custom dash pattern?
272  bool useCustomDashPattern = mLayer->useCustomDashPattern();
273  mChangePatternButton->setEnabled( useCustomDashPattern );
274  label_3->setEnabled( !useCustomDashPattern );
275  cboPenStyle->setEnabled( !useCustomDashPattern );
276  mCustomCheckBox->blockSignals( true );
277  mCustomCheckBox->setCheckState( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
278  mCustomCheckBox->blockSignals( false );
279 
280  //draw inside polygon?
281  bool drawInsidePolygon = mLayer->drawInsidePolygon();
282  mDrawInsideCheckBox->blockSignals( true );
283  mDrawInsideCheckBox->setCheckState( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
284  mDrawInsideCheckBox->blockSignals( false );
285 
287 
295 
296  updateAssistantSymbol();
297 }
298 
300 {
301  return mLayer;
302 }
303 
305 {
306  mLayer->setWidth( spinWidth->value() );
308  emit changed();
309 }
310 
312 {
313  mLayer->setColor( color );
315  emit changed();
316 }
317 
319 {
320  mLayer->setPenStyle( cboPenStyle->penStyle() );
321  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
322  mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
323  emit changed();
324 }
325 
327 {
328  mLayer->setOffset( spinOffset->value() );
330  emit changed();
331 }
332 
334 {
335  bool checked = ( state == Qt::Checked );
336  mChangePatternButton->setEnabled( checked );
337  label_3->setEnabled( !checked );
338  cboPenStyle->setEnabled( !checked );
339 
340  mLayer->setUseCustomDashPattern( checked );
341  emit changed();
342 }
343 
345 {
347  if ( d.exec() == QDialog::Accepted )
348  {
349  mLayer->setCustomDashVector( d.dashDotVector() );
351  emit changed();
352  }
353 }
354 
356 {
357  if ( mLayer )
358  {
359  mLayer->setWidthUnit( mPenWidthUnitWidget->unit() );
360  mLayer->setWidthMapUnitScale( mPenWidthUnitWidget->getMapUnitScale() );
361  emit changed();
362  }
363 }
364 
366 {
367  if ( mLayer )
368  {
369  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
370  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
371  emit changed();
372  }
373 }
374 
376 {
377  if ( mLayer )
378  {
379  mLayer->setCustomDashPatternUnit( mDashPatternUnitWidget->unit() );
380  mLayer->setCustomDashPatternMapUnitScale( mDashPatternUnitWidget->getMapUnitScale() );
381  emit changed();
382  }
383 }
384 
386 {
387  bool checked = ( state == Qt::Checked );
388  mLayer->setDrawInsidePolygon( checked );
389  emit changed();
390 }
391 
392 
394 {
395  if ( !mLayer )
396  {
397  return;
398  }
399  QgsSimpleLineSymbolLayerV2* layerCopy = mLayer->clone();
400  if ( !layerCopy )
401  {
402  return;
403  }
404  layerCopy->setUseCustomDashPattern( true );
405  QIcon buttonIcon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( layerCopy, QgsSymbolV2::MM, mChangePatternButton->iconSize() );
406  mChangePatternButton->setIcon( buttonIcon );
407  delete layerCopy;
408 }
409 
410 
412 
413 
415  : QgsSymbolLayerV2Widget( parent, vl )
416 {
417  mLayer = nullptr;
418 
419  setupUi( this );
422  mOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
423 
424  btnChangeColorFill->setAllowAlpha( true );
425  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
426  btnChangeColorFill->setContext( "symbology" );
427  btnChangeColorFill->setShowNoColor( true );
428  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
429  btnChangeColorBorder->setAllowAlpha( true );
430  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
431  btnChangeColorBorder->setContext( "symbology" );
432  btnChangeColorBorder->setShowNoColor( true );
433  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
434 
435  spinOffsetX->setClearValue( 0.0 );
436  spinOffsetY->setClearValue( 0.0 );
437 
438  //make a temporary symbol for the size assistant preview
439  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
440 
441  if ( mVectorLayer )
442  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
443 
444  QSize size = lstNames->iconSize();
445  double markerSize = DEFAULT_POINT_SIZE * 2;
447  {
448  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( shape, markerSize );
449  lyr->setColor( QColor( 200, 200, 200 ) );
450  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
452  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
453  item->setData( Qt::UserRole, static_cast< int >( shape ) );
455  delete lyr;
456  }
457 
458  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setName() ) );
459  connect( btnChangeColorBorder, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
460  connect( btnChangeColorFill, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorFill( const QColor& ) ) );
461  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
462  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
463  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
464  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
465  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
466  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
467 }
468 
470 {
471  delete mAssistantPreviewSymbol;
472 }
473 
475 {
476  if ( layer->layerType() != "SimpleMarker" )
477  return;
478 
479  // layer type is correct, we can do the cast
480  mLayer = static_cast<QgsSimpleMarkerSymbolLayerV2*>( layer );
481 
482  // set values
484  for ( int i = 0; i < lstNames->count(); ++i )
485  {
486  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
487  {
488  lstNames->setCurrentRow( i );
489  break;
490  }
491  }
492  btnChangeColorBorder->blockSignals( true );
493  btnChangeColorBorder->setColor( mLayer->borderColor() );
494  btnChangeColorBorder->blockSignals( false );
495  btnChangeColorFill->blockSignals( true );
496  btnChangeColorFill->setColor( mLayer->fillColor() );
497  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
498  btnChangeColorFill->blockSignals( false );
499  spinSize->blockSignals( true );
500  spinSize->setValue( mLayer->size() );
501  spinSize->blockSignals( false );
502  spinAngle->blockSignals( true );
503  spinAngle->setValue( mLayer->angle() );
504  spinAngle->blockSignals( false );
505  mOutlineStyleComboBox->blockSignals( true );
506  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
507  mOutlineStyleComboBox->blockSignals( false );
508  mOutlineWidthSpinBox->blockSignals( true );
509  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
510  mOutlineWidthSpinBox->blockSignals( false );
511  cboJoinStyle->blockSignals( true );
512  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
513  cboJoinStyle->blockSignals( false );
514 
515  // without blocking signals the value gets changed because of slot setOffset()
516  spinOffsetX->blockSignals( true );
517  spinOffsetX->setValue( mLayer->offset().x() );
518  spinOffsetX->blockSignals( false );
519  spinOffsetY->blockSignals( true );
520  spinOffsetY->setValue( mLayer->offset().y() );
521  spinOffsetY->blockSignals( false );
522 
523  mSizeUnitWidget->blockSignals( true );
524  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
525  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
526  mSizeUnitWidget->blockSignals( false );
527  mOffsetUnitWidget->blockSignals( true );
528  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
529  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
530  mOffsetUnitWidget->blockSignals( false );
531  mOutlineWidthUnitWidget->blockSignals( true );
532  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
533  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
534  mOutlineWidthUnitWidget->blockSignals( false );
535 
536  //anchor points
537  mHorizontalAnchorComboBox->blockSignals( true );
538  mVerticalAnchorComboBox->blockSignals( true );
539  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
540  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
541  mHorizontalAnchorComboBox->blockSignals( false );
542  mVerticalAnchorComboBox->blockSignals( false );
543 
544  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
545  "<b>pentagon</b>|<b>hexagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
546  "<b>star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
547  "<b>circle</b>|<b>cross</b>|<b>cross_fill</b>|<b>x</b>|"
548  "<b>line</b>|<b>arrowhead</b>|<b>cross2</b>|<b>semi_circle</b>|<b>third_circle</b>|<b>quarter_circle</b>|"
549  "<b>quarter_square</b>|<b>half_square</b>|<b>diagonal_half_square</b>|<b>right_half_triangle</b>|<b>left_half_triangle</b>]" ) );
558  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
559  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
560 
561  updateAssistantSymbol();
562 }
563 
565 {
566  return mLayer;
567 }
568 
570 {
571  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
572  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
573  emit changed();
574 }
575 
577 {
578  mLayer->setBorderColor( color );
579  emit changed();
580 }
581 
583 {
584  mLayer->setColor( color );
585  emit changed();
586 }
587 
588 void QgsSimpleMarkerSymbolLayerV2Widget::penJoinStyleChanged()
589 {
590  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
591  emit changed();
592 }
593 
595 {
596  mLayer->setSize( spinSize->value() );
597  emit changed();
598 }
599 
601 {
602  mLayer->setAngle( spinAngle->value() );
603  emit changed();
604 }
605 
607 {
608  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
609  emit changed();
610 }
611 
613 {
614  Q_UNUSED( index );
615 
616  if ( mLayer )
617  {
618  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
619  emit changed();
620  }
621 }
622 
624 {
625  if ( mLayer )
626  {
627  mLayer->setOutlineWidth( d );
628  emit changed();
629  }
630 }
631 
633 {
634  if ( mLayer )
635  {
636  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
637  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
638  emit changed();
639  }
640 }
641 
643 {
644  if ( mLayer )
645  {
646  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
647  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
648  emit changed();
649  }
650 }
651 
653 {
654  if ( mLayer )
655  {
656  mLayer->setOutlineWidthUnit( mOutlineWidthUnitWidget->unit() );
657  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
658  emit changed();
659  }
660 }
661 
663 {
664  if ( mLayer )
665  {
667  emit changed();
668  }
669 }
670 
672 {
673  if ( mLayer )
674  {
676  emit changed();
677  }
678 }
679 
680 void QgsSimpleMarkerSymbolLayerV2Widget::updateAssistantSymbol()
681 {
682  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
683  {
684  mAssistantPreviewSymbol->deleteSymbolLayer( i );
685  }
686  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
687  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
688  if ( ddSize )
689  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
690 }
691 
692 
694 
696  : QgsSymbolLayerV2Widget( parent, vl )
697 {
698  mLayer = nullptr;
699 
700  setupUi( this );
701  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
703 
704  btnChangeColor->setAllowAlpha( true );
705  btnChangeColor->setColorDialogTitle( tr( "Select fill color" ) );
706  btnChangeColor->setContext( "symbology" );
707  btnChangeColor->setShowNoColor( true );
708  btnChangeColor->setNoColorString( tr( "Transparent fill" ) );
709  btnChangeBorderColor->setAllowAlpha( true );
710  btnChangeBorderColor->setColorDialogTitle( tr( "Select border color" ) );
711  btnChangeBorderColor->setContext( "symbology" );
712  btnChangeBorderColor->setShowNoColor( true );
713  btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );
714 
715  spinOffsetX->setClearValue( 0.0 );
716  spinOffsetY->setClearValue( 0.0 );
717 
718  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
719  connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
720  connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
721  connect( spinBorderWidth, SIGNAL( valueChanged( double ) ), this, SLOT( borderWidthChanged() ) );
722  connect( cboBorderStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
723  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
724  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
725  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
726 }
727 
729 {
730  if ( layer->layerType() != "SimpleFill" )
731  return;
732 
733  // layer type is correct, we can do the cast
734  mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>( layer );
735 
736  // set values
737  btnChangeColor->blockSignals( true );
738  btnChangeColor->setColor( mLayer->color() );
739  btnChangeColor->blockSignals( false );
740  cboFillStyle->blockSignals( true );
741  cboFillStyle->setBrushStyle( mLayer->brushStyle() );
742  cboFillStyle->blockSignals( false );
743  btnChangeBorderColor->blockSignals( true );
744  btnChangeBorderColor->setColor( mLayer->borderColor() );
745  btnChangeBorderColor->blockSignals( false );
746  cboBorderStyle->blockSignals( true );
747  cboBorderStyle->setPenStyle( mLayer->borderStyle() );
748  cboBorderStyle->blockSignals( false );
749  spinBorderWidth->blockSignals( true );
750  spinBorderWidth->setValue( mLayer->borderWidth() );
751  spinBorderWidth->blockSignals( false );
752  cboJoinStyle->blockSignals( true );
753  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
754  cboJoinStyle->blockSignals( false );
755  spinOffsetX->blockSignals( true );
756  spinOffsetX->setValue( mLayer->offset().x() );
757  spinOffsetX->blockSignals( false );
758  spinOffsetY->blockSignals( true );
759  spinOffsetY->setValue( mLayer->offset().y() );
760  spinOffsetY->blockSignals( false );
761 
762  mBorderWidthUnitWidget->blockSignals( true );
763  mBorderWidthUnitWidget->setUnit( mLayer->borderWidthUnit() );
764  mBorderWidthUnitWidget->setMapUnitScale( mLayer->borderWidthMapUnitScale() );
765  mBorderWidthUnitWidget->blockSignals( false );
766  mOffsetUnitWidget->blockSignals( true );
767  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
768  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
769  mOffsetUnitWidget->blockSignals( false );
770 
777 
778 }
779 
781 {
782  return mLayer;
783 }
784 
786 {
787  mLayer->setColor( color );
788  emit changed();
789 }
790 
792 {
793  mLayer->setBorderColor( color );
794  emit changed();
795 }
796 
798 {
799  mLayer->setBrushStyle( cboFillStyle->brushStyle() );
800  emit changed();
801 }
802 
804 {
805  mLayer->setBorderWidth( spinBorderWidth->value() );
806  emit changed();
807 }
808 
810 {
811  mLayer->setBorderStyle( cboBorderStyle->penStyle() );
812  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
813  emit changed();
814 }
815 
817 {
818  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
819  emit changed();
820 }
821 
823 {
824  if ( mLayer )
825  {
826  mLayer->setBorderWidthUnit( mBorderWidthUnitWidget->unit() );
827  mLayer->setBorderWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
828  emit changed();
829  }
830 }
831 
833 {
834  if ( mLayer )
835  {
836  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
837  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
838  emit changed();
839  }
840 }
841 
843 
845  : QgsSymbolLayerV2Widget( parent, vl )
846 {
847  mLayer = nullptr;
848 
849  setupUi( this );
852 
853  spinOffsetX->setClearValue( 0.0 );
854  spinOffsetY->setClearValue( 0.0 );
855 
856  //make a temporary symbol for the size assistant preview
857  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
858 
859  if ( mVectorLayer )
860  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
861 
862  QSize size = lstNames->iconSize();
863  double markerSize = DEFAULT_POINT_SIZE * 2;
865  {
867  continue;
868 
869  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( shape, markerSize );
870  lyr->setColor( QColor( 200, 200, 200 ) );
871  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
873  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
874  item->setData( Qt::UserRole, static_cast< int >( shape ) );
876  delete lyr;
877  }
878 
879  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setShape() ) );
880  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
881  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
882  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
883  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
884  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
885 }
886 
888 {
889  delete mAssistantPreviewSymbol;
890 }
891 
893 {
894  if ( layer->layerType() != "FilledMarker" )
895  return;
896 
897  // layer type is correct, we can do the cast
898  mLayer = static_cast<QgsFilledMarkerSymbolLayer*>( layer );
899 
900  // set values
902  for ( int i = 0; i < lstNames->count(); ++i )
903  {
904  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
905  {
906  lstNames->setCurrentRow( i );
907  break;
908  }
909  }
910  whileBlocking( spinSize )->setValue( mLayer->size() );
911  whileBlocking( spinAngle )->setValue( mLayer->angle() );
912  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
913  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
914 
915  mSizeUnitWidget->blockSignals( true );
916  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
917  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
918  mSizeUnitWidget->blockSignals( false );
919  mOffsetUnitWidget->blockSignals( true );
920  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
921  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
922  mOffsetUnitWidget->blockSignals( false );
923 
924  //anchor points
925  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
926  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
927 
928  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
929  "<b>pentagon</b>|<b>hexagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
930  "<b>star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
931  "<b>circle</b>|<b>cross</b>|<b>cross_fill</b>|<b>x</b>|"
932  "<b>line</b>|<b>arrowhead</b>|<b>cross2</b>|<b>semi_circle</b>|<b>third_circle</b>|<b>quarter_circle</b>|"
933  "<b>quarter_square</b>|<b>half_square</b>|<b>diagonal_half_square</b>|<b>right_half_triangle</b>|<b>left_half_triangle</b>]" ) );
937  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
938  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
939 
940  updateAssistantSymbol();
941 }
942 
944 {
945  return mLayer;
946 }
947 
948 void QgsFilledMarkerSymbolLayerWidget::setShape()
949 {
950  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
951  emit changed();
952 }
953 
954 void QgsFilledMarkerSymbolLayerWidget::setSize()
955 {
956  mLayer->setSize( spinSize->value() );
957  emit changed();
958 }
959 
960 void QgsFilledMarkerSymbolLayerWidget::setAngle()
961 {
962  mLayer->setAngle( spinAngle->value() );
963  emit changed();
964 }
965 
966 void QgsFilledMarkerSymbolLayerWidget::setOffset()
967 {
968  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
969  emit changed();
970 }
971 
972 void QgsFilledMarkerSymbolLayerWidget::on_mSizeUnitWidget_changed()
973 {
974  if ( mLayer )
975  {
976  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
977  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
978  emit changed();
979  }
980 }
981 
982 void QgsFilledMarkerSymbolLayerWidget::on_mOffsetUnitWidget_changed()
983 {
984  if ( mLayer )
985  {
986  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
987  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
988  emit changed();
989  }
990 }
991 
992 void QgsFilledMarkerSymbolLayerWidget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
993 {
994  if ( mLayer )
995  {
997  emit changed();
998  }
999 }
1000 
1001 void QgsFilledMarkerSymbolLayerWidget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
1002 {
1003  if ( mLayer )
1004  {
1006  emit changed();
1007  }
1008 }
1009 
1010 void QgsFilledMarkerSymbolLayerWidget::updateAssistantSymbol()
1011 {
1012  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1013  {
1014  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1015  }
1016  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1017  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
1018  if ( ddSize )
1019  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
1020 }
1021 
1022 
1024 
1026  : QgsSymbolLayerV2Widget( parent, vl )
1027 {
1028  mLayer = nullptr;
1029 
1030  setupUi( this );
1031  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1032 
1033  cboGradientColorRamp->setShowGradientOnly( true );
1034  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1035 
1036  btnChangeColor->setAllowAlpha( true );
1037  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1038  btnChangeColor->setContext( "symbology" );
1039  btnChangeColor->setShowNoColor( true );
1040  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1041  btnChangeColor2->setAllowAlpha( true );
1042  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1043  btnChangeColor2->setContext( "symbology" );
1044  btnChangeColor2->setShowNoColor( true );
1045  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1046 
1047  spinOffsetX->setClearValue( 0.0 );
1048  spinOffsetY->setClearValue( 0.0 );
1049 
1050  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1051  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1052  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1053  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
1054  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
1055  connect( cboGradientType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientType( int ) ) );
1056  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
1057  connect( cboGradientSpread, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientSpread( int ) ) );
1058  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1059  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1060  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1061  connect( spinRefPoint1X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1062  connect( spinRefPoint1Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1063  connect( checkRefPoint1Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
1064  connect( spinRefPoint2X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1065  connect( spinRefPoint2Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1066  connect( checkRefPoint2Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
1067 }
1068 
1070 {
1071  if ( layer->layerType() != "GradientFill" )
1072  return;
1073 
1074  // layer type is correct, we can do the cast
1075  mLayer = static_cast<QgsGradientFillSymbolLayerV2*>( layer );
1076 
1077  // set values
1078  btnChangeColor->blockSignals( true );
1079  btnChangeColor->setColor( mLayer->color() );
1080  btnChangeColor->blockSignals( false );
1081  btnChangeColor2->blockSignals( true );
1082  btnChangeColor2->setColor( mLayer->color2() );
1083  btnChangeColor2->blockSignals( false );
1084 
1086  {
1087  radioTwoColor->setChecked( true );
1088  cboGradientColorRamp->setEnabled( false );
1089  }
1090  else
1091  {
1092  radioColorRamp->setChecked( true );
1093  btnChangeColor->setEnabled( false );
1094  btnChangeColor2->setEnabled( false );
1095  }
1096 
1097  // set source color ramp
1098  if ( mLayer->colorRamp() )
1099  {
1100  cboGradientColorRamp->blockSignals( true );
1101  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1102  cboGradientColorRamp->blockSignals( false );
1103  }
1104 
1105  cboGradientType->blockSignals( true );
1106  switch ( mLayer->gradientType() )
1107  {
1109  cboGradientType->setCurrentIndex( 0 );
1110  break;
1112  cboGradientType->setCurrentIndex( 1 );
1113  break;
1115  cboGradientType->setCurrentIndex( 2 );
1116  break;
1117  }
1118  cboGradientType->blockSignals( false );
1119 
1120  cboCoordinateMode->blockSignals( true );
1121  switch ( mLayer->coordinateMode() )
1122  {
1124  cboCoordinateMode->setCurrentIndex( 1 );
1125  checkRefPoint1Centroid->setEnabled( false );
1126  checkRefPoint2Centroid->setEnabled( false );
1127  break;
1129  default:
1130  cboCoordinateMode->setCurrentIndex( 0 );
1131  break;
1132  }
1133  cboCoordinateMode->blockSignals( false );
1134 
1135  cboGradientSpread->blockSignals( true );
1136  switch ( mLayer->gradientSpread() )
1137  {
1139  cboGradientSpread->setCurrentIndex( 0 );
1140  break;
1142  cboGradientSpread->setCurrentIndex( 1 );
1143  break;
1145  cboGradientSpread->setCurrentIndex( 2 );
1146  break;
1147  }
1148  cboGradientSpread->blockSignals( false );
1149 
1150  spinRefPoint1X->blockSignals( true );
1151  spinRefPoint1X->setValue( mLayer->referencePoint1().x() );
1152  spinRefPoint1X->blockSignals( false );
1153  spinRefPoint1Y->blockSignals( true );
1154  spinRefPoint1Y->setValue( mLayer->referencePoint1().y() );
1155  spinRefPoint1Y->blockSignals( false );
1156  checkRefPoint1Centroid->blockSignals( true );
1157  checkRefPoint1Centroid->setChecked( mLayer->referencePoint1IsCentroid() );
1159  {
1160  spinRefPoint1X->setEnabled( false );
1161  spinRefPoint1Y->setEnabled( false );
1162  }
1163  checkRefPoint1Centroid->blockSignals( false );
1164  spinRefPoint2X->blockSignals( true );
1165  spinRefPoint2X->setValue( mLayer->referencePoint2().x() );
1166  spinRefPoint2X->blockSignals( false );
1167  spinRefPoint2Y->blockSignals( true );
1168  spinRefPoint2Y->setValue( mLayer->referencePoint2().y() );
1169  spinRefPoint2Y->blockSignals( false );
1170  checkRefPoint2Centroid->blockSignals( true );
1171  checkRefPoint2Centroid->setChecked( mLayer->referencePoint2IsCentroid() );
1173  {
1174  spinRefPoint2X->setEnabled( false );
1175  spinRefPoint2Y->setEnabled( false );
1176  }
1177  checkRefPoint2Centroid->blockSignals( false );
1178 
1179  spinOffsetX->blockSignals( true );
1180  spinOffsetX->setValue( mLayer->offset().x() );
1181  spinOffsetX->blockSignals( false );
1182  spinOffsetY->blockSignals( true );
1183  spinOffsetY->setValue( mLayer->offset().y() );
1184  spinOffsetY->blockSignals( false );
1185  mSpinAngle->blockSignals( true );
1186  mSpinAngle->setValue( mLayer->angle() );
1187  mSpinAngle->blockSignals( false );
1188 
1189  mOffsetUnitWidget->blockSignals( true );
1190  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1191  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1192  mOffsetUnitWidget->blockSignals( false );
1193 
1202  registerDataDefinedButton( mRefPoint1CentroidDDBtn, "reference1_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1205  registerDataDefinedButton( mRefPoint2CentroidDDBtn, "reference2_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1206 }
1207 
1209 {
1210  return mLayer;
1211 }
1212 
1214 {
1215  mLayer->setColor( color );
1216  emit changed();
1217 }
1218 
1220 {
1221  mLayer->setColor2( color );
1222  emit changed();
1223 }
1224 
1226 {
1227  if ( radioTwoColor->isChecked() )
1228  {
1230  }
1231  else
1232  {
1234  }
1235  emit changed();
1236 }
1237 
1239 {
1240  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1241  if ( !ramp )
1242  return;
1243 
1244  mLayer->setColorRamp( ramp );
1245  emit changed();
1246 }
1247 
1249 {
1250  switch ( index )
1251  {
1252  case 0:
1254  //set sensible default reference points
1255  spinRefPoint1X->setValue( 0.5 );
1256  spinRefPoint1Y->setValue( 0 );
1257  spinRefPoint2X->setValue( 0.5 );
1258  spinRefPoint2Y->setValue( 1 );
1259  break;
1260  case 1:
1262  //set sensible default reference points
1263  spinRefPoint1X->setValue( 0 );
1264  spinRefPoint1Y->setValue( 0 );
1265  spinRefPoint2X->setValue( 1 );
1266  spinRefPoint2Y->setValue( 1 );
1267  break;
1268  case 2:
1270  spinRefPoint1X->setValue( 0.5 );
1271  spinRefPoint1Y->setValue( 0.5 );
1272  spinRefPoint2X->setValue( 1 );
1273  spinRefPoint2Y->setValue( 1 );
1274  break;
1275  }
1276  emit changed();
1277 }
1278 
1280 {
1281 
1282  switch ( index )
1283  {
1284  case 0:
1285  //feature coordinate mode
1287  //allow choice of centroid reference positions
1288  checkRefPoint1Centroid->setEnabled( true );
1289  checkRefPoint2Centroid->setEnabled( true );
1290  break;
1291  case 1:
1292  //viewport coordinate mode
1294  //disable choice of centroid reference positions
1295  checkRefPoint1Centroid->setChecked( Qt::Unchecked );
1296  checkRefPoint1Centroid->setEnabled( false );
1297  checkRefPoint2Centroid->setChecked( Qt::Unchecked );
1298  checkRefPoint2Centroid->setEnabled( false );
1299  break;
1300  }
1301 
1302  emit changed();
1303 }
1304 
1306 {
1307  switch ( index )
1308  {
1309  case 0:
1311  break;
1312  case 1:
1314  break;
1315  case 2:
1317  break;
1318  }
1319 
1320  emit changed();
1321 }
1322 
1324 {
1325  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1326  emit changed();
1327 }
1328 
1330 {
1331  mLayer->setReferencePoint1( QPointF( spinRefPoint1X->value(), spinRefPoint1Y->value() ) );
1332  mLayer->setReferencePoint1IsCentroid( checkRefPoint1Centroid->isChecked() );
1333  mLayer->setReferencePoint2( QPointF( spinRefPoint2X->value(), spinRefPoint2Y->value() ) );
1334  mLayer->setReferencePoint2IsCentroid( checkRefPoint2Centroid->isChecked() );
1335  emit changed();
1336 }
1337 
1339 {
1340  mLayer->setAngle( value );
1341  emit changed();
1342 }
1343 
1345 {
1346  if ( mLayer )
1347  {
1348  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1349  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1350  emit changed();
1351  }
1352 }
1353 
1355 
1357  : QgsSymbolLayerV2Widget( parent, vl )
1358 {
1359  mLayer = nullptr;
1360 
1361  setupUi( this );
1362  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1363  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1364 
1365  QButtonGroup* group1 = new QButtonGroup( this );
1366  group1->addButton( radioColorRamp );
1367  group1->addButton( radioTwoColor );
1368  QButtonGroup* group2 = new QButtonGroup( this );
1369  group2->addButton( mRadioUseMaxDistance );
1370  group2->addButton( mRadioUseWholeShape );
1371  btnChangeColor->setAllowAlpha( true );
1372  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1373  btnChangeColor->setContext( "symbology" );
1374  btnChangeColor->setShowNoColor( true );
1375  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1376  btnChangeColor2->setAllowAlpha( true );
1377  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1378  btnChangeColor2->setContext( "symbology" );
1379  btnChangeColor2->setShowNoColor( true );
1380  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1381 
1382  spinOffsetX->setClearValue( 0.0 );
1383  spinOffsetY->setClearValue( 0.0 );
1384 
1385  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1386 
1387  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1388  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
1389  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
1390 
1391  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1392  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1393  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1394  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1395  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1396 
1397  connect( mBlurSlider, SIGNAL( valueChanged( int ) ), mSpinBlurRadius, SLOT( setValue( int ) ) );
1398  connect( mSpinBlurRadius, SIGNAL( valueChanged( int ) ), mBlurSlider, SLOT( setValue( int ) ) );
1399 }
1400 
1402 {
1403  if ( layer->layerType() != "ShapeburstFill" )
1404  return;
1405 
1406  // layer type is correct, we can do the cast
1407  mLayer = static_cast<QgsShapeburstFillSymbolLayerV2*>( layer );
1408 
1409  // set values
1410  btnChangeColor->blockSignals( true );
1411  btnChangeColor->setColor( mLayer->color() );
1412  btnChangeColor->blockSignals( false );
1413  btnChangeColor2->blockSignals( true );
1414  btnChangeColor2->setColor( mLayer->color2() );
1415  btnChangeColor2->blockSignals( false );
1416 
1418  {
1419  radioTwoColor->setChecked( true );
1420  cboGradientColorRamp->setEnabled( false );
1421  }
1422  else
1423  {
1424  radioColorRamp->setChecked( true );
1425  btnChangeColor->setEnabled( false );
1426  btnChangeColor2->setEnabled( false );
1427  }
1428 
1429  mSpinBlurRadius->blockSignals( true );
1430  mBlurSlider->blockSignals( true );
1431  mSpinBlurRadius->setValue( mLayer->blurRadius() );
1432  mBlurSlider->setValue( mLayer->blurRadius() );
1433  mSpinBlurRadius->blockSignals( false );
1434  mBlurSlider->blockSignals( false );
1435 
1436  mSpinMaxDistance->blockSignals( true );
1437  mSpinMaxDistance->setValue( mLayer->maxDistance() );
1438  mSpinMaxDistance->blockSignals( false );
1439 
1440  mRadioUseWholeShape->blockSignals( true );
1441  mRadioUseMaxDistance->blockSignals( true );
1442  if ( mLayer->useWholeShape() )
1443  {
1444  mRadioUseWholeShape->setChecked( true );
1445  mSpinMaxDistance->setEnabled( false );
1446  mDistanceUnitWidget->setEnabled( false );
1447  }
1448  else
1449  {
1450  mRadioUseMaxDistance->setChecked( true );
1451  mSpinMaxDistance->setEnabled( true );
1452  mDistanceUnitWidget->setEnabled( true );
1453  }
1454  mRadioUseWholeShape->blockSignals( false );
1455  mRadioUseMaxDistance->blockSignals( false );
1456 
1457  mDistanceUnitWidget->blockSignals( true );
1458  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
1459  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
1460  mDistanceUnitWidget->blockSignals( false );
1461 
1462  mIgnoreRingsCheckBox->blockSignals( true );
1463  mIgnoreRingsCheckBox->setCheckState( mLayer->ignoreRings() ? Qt::Checked : Qt::Unchecked );
1464  mIgnoreRingsCheckBox->blockSignals( false );
1465 
1466  // set source color ramp
1467  if ( mLayer->colorRamp() )
1468  {
1469  cboGradientColorRamp->blockSignals( true );
1470  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1471  cboGradientColorRamp->blockSignals( false );
1472  }
1473 
1474  spinOffsetX->blockSignals( true );
1475  spinOffsetX->setValue( mLayer->offset().x() );
1476  spinOffsetX->blockSignals( false );
1477  spinOffsetY->blockSignals( true );
1478  spinOffsetY->setValue( mLayer->offset().y() );
1479  spinOffsetY->blockSignals( false );
1480  mOffsetUnitWidget->blockSignals( true );
1481  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1482  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1483  mOffsetUnitWidget->blockSignals( false );
1484 
1487  registerDataDefinedButton( mBlurRadiusDDBtn, "blur_radius", QgsDataDefinedButton::Int, tr( "Integer between 0 and 18" ) );
1488  registerDataDefinedButton( mShadeWholeShapeDDBtn, "use_whole_shape", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1491 }
1492 
1494 {
1495  return mLayer;
1496 }
1497 
1499 {
1500  if ( mLayer )
1501  {
1502  mLayer->setColor( color );
1503  emit changed();
1504  }
1505 }
1506 
1508 {
1509  if ( mLayer )
1510  {
1511  mLayer->setColor2( color );
1512  emit changed();
1513  }
1514 }
1515 
1517 {
1518  if ( !mLayer )
1519  {
1520  return;
1521  }
1522 
1523  if ( radioTwoColor->isChecked() )
1524  {
1526  }
1527  else
1528  {
1530  }
1531  emit changed();
1532 }
1533 
1535 {
1536  if ( mLayer )
1537  {
1538  mLayer->setBlurRadius( value );
1539  emit changed();
1540  }
1541 }
1542 
1544 {
1545  if ( mLayer )
1546  {
1547  mLayer->setMaxDistance( value );
1548  emit changed();
1549  }
1550 }
1551 
1553 {
1554  if ( mLayer )
1555  {
1556  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
1557  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
1558  emit changed();
1559  }
1560 }
1561 
1563 {
1564  if ( mLayer )
1565  {
1566  mLayer->setUseWholeShape( value );
1567  mDistanceUnitWidget->setEnabled( !value );
1568  emit changed();
1569  }
1570 }
1571 
1573 {
1574  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1575  if ( !ramp )
1576  return;
1577 
1578  mLayer->setColorRamp( ramp );
1579  emit changed();
1580 }
1581 
1583 {
1584  if ( mLayer )
1585  {
1586  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1587  emit changed();
1588  }
1589 }
1590 
1592 {
1593  if ( mLayer )
1594  {
1595  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1596  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1597  emit changed();
1598  }
1599 }
1600 
1601 
1603 {
1604  bool checked = ( state == Qt::Checked );
1605  mLayer->setIgnoreRings( checked );
1606  emit changed();
1607 }
1608 
1610 
1612  : QgsSymbolLayerV2Widget( parent, vl )
1613 {
1614  mLayer = nullptr;
1615 
1616  setupUi( this );
1617  mIntervalUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1618  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1619  mOffsetAlongLineUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1620 
1621  spinOffset->setClearValue( 0.0 );
1622 
1623  connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
1624  connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
1625  connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
1626  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1627  connect( radInterval, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1628  connect( radVertex, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1629  connect( radVertexLast, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1630  connect( radVertexFirst, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1631  connect( radCentralPoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1632  connect( radCurvePoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1633 }
1634 
1636 {
1637  if ( layer->layerType() != "MarkerLine" )
1638  return;
1639 
1640  // layer type is correct, we can do the cast
1641  mLayer = static_cast<QgsMarkerLineSymbolLayerV2*>( layer );
1642 
1643  // set values
1644  spinInterval->blockSignals( true );
1645  spinInterval->setValue( mLayer->interval() );
1646  spinInterval->blockSignals( false );
1647  mSpinOffsetAlongLine->blockSignals( true );
1648  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
1649  mSpinOffsetAlongLine->blockSignals( false );
1650  chkRotateMarker->blockSignals( true );
1651  chkRotateMarker->setChecked( mLayer->rotateMarker() );
1652  chkRotateMarker->blockSignals( false );
1653  spinOffset->blockSignals( true );
1654  spinOffset->setValue( mLayer->offset() );
1655  spinOffset->blockSignals( false );
1657  radInterval->setChecked( true );
1659  radVertex->setChecked( true );
1661  radVertexLast->setChecked( true );
1663  radCentralPoint->setChecked( true );
1665  radCurvePoint->setChecked( true );
1666  else
1667  radVertexFirst->setChecked( true );
1668 
1669  // set units
1670  mIntervalUnitWidget->blockSignals( true );
1671  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
1672  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
1673  mIntervalUnitWidget->blockSignals( false );
1674  mOffsetUnitWidget->blockSignals( true );
1675  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1676  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1677  mOffsetUnitWidget->blockSignals( false );
1678  mOffsetAlongLineUnitWidget->blockSignals( true );
1679  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
1680  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
1681  mOffsetAlongLineUnitWidget->blockSignals( false );
1682 
1683  setPlacement(); // update gui
1684 
1687  registerDataDefinedButton( mPlacementDDBtn, "placement", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>vertex</b>|<b>lastvertex</b>|<b>firstvertex</b>|<b>centerpoint</b>]" ) );
1688  registerDataDefinedButton( mOffsetAlongLineDDBtn, "offset_along_line", QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
1689 }
1690 
1692 {
1693  return mLayer;
1694 }
1695 
1697 {
1698  mLayer->setInterval( val );
1699  emit changed();
1700 }
1701 
1703 {
1704  mLayer->setOffsetAlongLine( val );
1705  emit changed();
1706 }
1707 
1709 {
1710  mLayer->setRotateMarker( chkRotateMarker->isChecked() );
1711  emit changed();
1712 }
1713 
1715 {
1716  mLayer->setOffset( spinOffset->value() );
1717  emit changed();
1718 }
1719 
1721 {
1722  bool interval = radInterval->isChecked();
1723  spinInterval->setEnabled( interval );
1724  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
1725  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
1726  if ( radInterval->isChecked() )
1728  else if ( radVertex->isChecked() )
1730  else if ( radVertexLast->isChecked() )
1732  else if ( radVertexFirst->isChecked() )
1734  else if ( radCurvePoint->isChecked() )
1736  else
1738 
1739  emit changed();
1740 }
1741 
1743 {
1744  if ( mLayer )
1745  {
1746  mLayer->setIntervalUnit( mIntervalUnitWidget->unit() );
1747  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
1748  emit changed();
1749  }
1750 }
1751 
1753 {
1754  if ( mLayer )
1755  {
1756  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1757  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1758  emit changed();
1759  }
1760 }
1761 
1763 {
1764  if ( mLayer )
1765  {
1766  mLayer->setOffsetAlongLineUnit( mOffsetAlongLineUnitWidget->unit() );
1767  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
1768  }
1769  emit changed();
1770 }
1771 
1773 
1774 
1776  : QgsSymbolLayerV2Widget( parent, vl )
1777 {
1778  mLayer = nullptr;
1779 
1780  setupUi( this );
1782  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1783  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1784  viewGroups->setHeaderHidden( true );
1785  mChangeColorButton->setAllowAlpha( true );
1786  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
1787  mChangeColorButton->setContext( "symbology" );
1788  mChangeBorderColorButton->setAllowAlpha( true );
1789  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
1790  mChangeBorderColorButton->setContext( "symbology" );
1791 
1792  spinOffsetX->setClearValue( 0.0 );
1793  spinOffsetY->setClearValue( 0.0 );
1794 
1795  populateList();
1796 
1797  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1798  connect( viewGroups->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
1799  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
1800  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
1801  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1802  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1803  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
1804 
1805  //make a temporary symbol for the size assistant preview
1806  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
1807  if ( mVectorLayer )
1808  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
1809 }
1810 
1812 {
1813  delete mAssistantPreviewSymbol;
1814 }
1815 
1816 #include <QTime>
1817 #include <QAbstractListModel>
1818 #include <QPixmapCache>
1819 #include <QStyle>
1820 
1821 
1823 {
1824  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( viewGroups );
1825  viewGroups->setModel( g );
1826  // Set the tree expanded at the first level
1827  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
1828  for ( int i = 0; i < rows; i++ )
1829  {
1830  viewGroups->setExpanded( g->indexFromItem( g->item( i ) ), true );
1831  }
1832 
1833  // Initally load the icons in the List view without any grouping
1834  QgsSvgListModel* m = new QgsSvgListModel( viewImages );
1835  viewImages->setModel( m );
1836 }
1837 
1839 {
1840  QString path = idx.data( Qt::UserRole + 1 ).toString();
1841 
1842  QgsSvgListModel* m = new QgsSvgListModel( viewImages, path );
1843  viewImages->setModel( m );
1844 
1845  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1846  emit changed();
1847 }
1848 
1850 {
1851  if ( !layer )
1852  {
1853  return;
1854  }
1855 
1856  //activate gui for svg parameters only if supported by the svg file
1857  bool hasFillParam, hasFillOpacityParam, hasOutlineParam, hasOutlineWidthParam, hasOutlineOpacityParam;
1858  QColor defaultFill, defaultOutline;
1859  double defaultOutlineWidth, defaultFillOpacity, defaultOutlineOpacity;
1860  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultOutlineColor, hasDefaultOutlineWidth, hasDefaultOutlineOpacity;
1861  QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, hasDefaultFillColor, defaultFill,
1862  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
1863  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
1864  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth,
1865  hasOutlineOpacityParam, hasDefaultOutlineOpacity, defaultOutlineOpacity );
1866  mChangeColorButton->setEnabled( hasFillParam );
1867  mChangeColorButton->setAllowAlpha( hasFillOpacityParam );
1868  mChangeBorderColorButton->setEnabled( hasOutlineParam );
1869  mChangeBorderColorButton->setAllowAlpha( hasOutlineOpacityParam );
1870  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
1871 
1872  if ( hasFillParam )
1873  {
1874  QColor fill = layer->fillColor();
1875  double existingOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
1876  if ( hasDefaultFillColor )
1877  {
1878  fill = defaultFill;
1879  }
1880  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : existingOpacity );
1881  mChangeColorButton->setColor( fill );
1882  }
1883  if ( hasOutlineParam )
1884  {
1885  QColor outline = layer->outlineColor();
1886  double existingOpacity = hasOutlineOpacityParam ? outline.alphaF() : 1.0;
1887  if ( hasDefaultOutlineColor )
1888  {
1889  outline = defaultOutline;
1890  }
1891  outline.setAlphaF( hasDefaultOutlineOpacity ? defaultOutlineOpacity : existingOpacity );
1892  mChangeBorderColorButton->setColor( outline );
1893  }
1894 
1895  mFileLineEdit->blockSignals( true );
1896  mFileLineEdit->setText( layer->path() );
1897  mFileLineEdit->blockSignals( false );
1898 
1899  mBorderWidthSpinBox->blockSignals( true );
1900  mBorderWidthSpinBox->setValue( hasDefaultOutlineWidth ? defaultOutlineWidth : layer->outlineWidth() );
1901  mBorderWidthSpinBox->blockSignals( false );
1902 }
1903 
1904 void QgsSvgMarkerSymbolLayerV2Widget::updateAssistantSymbol()
1905 {
1906  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1907  {
1908  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1909  }
1910  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1911  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
1912  if ( ddSize )
1913  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
1914 }
1915 
1916 
1918 {
1919  if ( !layer )
1920  {
1921  return;
1922  }
1923 
1924  if ( layer->layerType() != "SvgMarker" )
1925  return;
1926 
1927  // layer type is correct, we can do the cast
1928  mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>( layer );
1929 
1930  // set values
1931 
1932  QAbstractItemModel* m = viewImages->model();
1933  QItemSelectionModel* selModel = viewImages->selectionModel();
1934  for ( int i = 0; i < m->rowCount(); i++ )
1935  {
1936  QModelIndex idx( m->index( i, 0 ) );
1937  if ( m->data( idx ).toString() == mLayer->path() )
1938  {
1939  selModel->select( idx, QItemSelectionModel::SelectCurrent );
1940  selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent );
1941  setName( idx );
1942  break;
1943  }
1944  }
1945 
1946  spinSize->blockSignals( true );
1947  spinSize->setValue( mLayer->size() );
1948  spinSize->blockSignals( false );
1949  spinAngle->blockSignals( true );
1950  spinAngle->setValue( mLayer->angle() );
1951  spinAngle->blockSignals( false );
1952 
1953  // without blocking signals the value gets changed because of slot setOffset()
1954  spinOffsetX->blockSignals( true );
1955  spinOffsetX->setValue( mLayer->offset().x() );
1956  spinOffsetX->blockSignals( false );
1957  spinOffsetY->blockSignals( true );
1958  spinOffsetY->setValue( mLayer->offset().y() );
1959  spinOffsetY->blockSignals( false );
1960 
1961  mSizeUnitWidget->blockSignals( true );
1962  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
1963  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
1964  mSizeUnitWidget->blockSignals( false );
1965  mBorderWidthUnitWidget->blockSignals( true );
1966  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
1967  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
1968  mBorderWidthUnitWidget->blockSignals( false );
1969  mOffsetUnitWidget->blockSignals( true );
1970  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1971  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1972  mOffsetUnitWidget->blockSignals( false );
1973 
1974  //anchor points
1975  mHorizontalAnchorComboBox->blockSignals( true );
1976  mVerticalAnchorComboBox->blockSignals( true );
1977  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1978  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
1979  mHorizontalAnchorComboBox->blockSignals( false );
1980  mVerticalAnchorComboBox->blockSignals( false );
1981 
1982  setGuiForSvg( mLayer );
1983 
1991  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
1992  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
1993 
1994  updateAssistantSymbol();
1995 }
1996 
1998 {
1999  return mLayer;
2000 }
2001 
2003 {
2004  QString name = idx.data( Qt::UserRole ).toString();
2005  mLayer->setPath( name );
2006  mFileLineEdit->setText( name );
2007 
2008  setGuiForSvg( mLayer );
2009  emit changed();
2010 }
2011 
2013 {
2014  mLayer->setSize( spinSize->value() );
2015  emit changed();
2016 }
2017 
2019 {
2020  mLayer->setAngle( spinAngle->value() );
2021  emit changed();
2022 }
2023 
2025 {
2026  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2027  emit changed();
2028 }
2029 
2031 {
2032  QSettings s;
2033  QString file = QFileDialog::getOpenFileName( nullptr,
2034  tr( "Select SVG file" ),
2035  s.value( "/UI/lastSVGMarkerDir", QDir::homePath() ).toString(),
2036  tr( "SVG files" ) + " (*.svg)" );
2037  QFileInfo fi( file );
2038  if ( file.isEmpty() || !fi.exists() )
2039  {
2040  return;
2041  }
2042  mFileLineEdit->setText( file );
2043  mLayer->setPath( file );
2044  s.setValue( "/UI/lastSVGMarkerDir", fi.absolutePath() );
2045  setGuiForSvg( mLayer );
2046  emit changed();
2047 }
2048 
2050 {
2051  if ( !QFileInfo( text ).exists() )
2052  {
2053  return;
2054  }
2055  mLayer->setPath( text );
2056  setGuiForSvg( mLayer );
2057  emit changed();
2058 }
2059 
2061 {
2062  if ( !QFileInfo( mFileLineEdit->text() ).exists() )
2063  {
2064  QUrl url( mFileLineEdit->text() );
2065  if ( !url.isValid() )
2066  {
2067  return;
2068  }
2069  }
2070 
2071  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2072  mLayer->setPath( mFileLineEdit->text() );
2074 
2075  setGuiForSvg( mLayer );
2076  emit changed();
2077 }
2078 
2080 {
2081  if ( !mLayer )
2082  {
2083  return;
2084  }
2085 
2086  mLayer->setFillColor( color );
2087  emit changed();
2088 }
2089 
2091 {
2092  if ( !mLayer )
2093  {
2094  return;
2095  }
2096 
2097  mLayer->setOutlineColor( color );
2098  emit changed();
2099 }
2100 
2102 {
2103  if ( mLayer )
2104  {
2105  mLayer->setOutlineWidth( d );
2106  emit changed();
2107  }
2108 }
2109 
2111 {
2112  if ( mLayer )
2113  {
2114  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2115  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2116  emit changed();
2117  }
2118 }
2119 
2121 {
2122  if ( mLayer )
2123  {
2124  mLayer->setOutlineWidthUnit( mBorderWidthUnitWidget->unit() );
2125  mLayer->setOutlineWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
2126  emit changed();
2127  }
2128 }
2129 
2131 {
2132  if ( mLayer )
2133  {
2134  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2135  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2136  emit changed();
2137  }
2138 }
2139 
2141 {
2142  if ( mLayer )
2143  {
2145  emit changed();
2146  }
2147 }
2148 
2150 {
2151  if ( mLayer )
2152  {
2154  emit changed();
2155  }
2156 }
2157 
2159 
2161 {
2162  mLayer = nullptr;
2163  setupUi( this );
2164  mTextureWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2165  mSvgOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2166  mSvgTreeView->setHeaderHidden( true );
2167  insertIcons();
2168 
2169  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
2170  mChangeColorButton->setContext( "symbology" );
2171  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
2172  mChangeBorderColorButton->setContext( "symbology" );
2173 
2174  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2175  connect( mSvgTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
2176 }
2177 
2179 {
2180  if ( !layer )
2181  {
2182  return;
2183  }
2184 
2185  if ( layer->layerType() != "SVGFill" )
2186  {
2187  return;
2188  }
2189 
2190  mLayer = dynamic_cast<QgsSVGFillSymbolLayer*>( layer );
2191  if ( mLayer )
2192  {
2193  double width = mLayer->patternWidth();
2194  mTextureWidthSpinBox->blockSignals( true );
2195  mTextureWidthSpinBox->setValue( width );
2196  mTextureWidthSpinBox->blockSignals( false );
2197  mSVGLineEdit->setText( mLayer->svgFilePath() );
2198  mRotationSpinBox->blockSignals( true );
2199  mRotationSpinBox->setValue( mLayer->angle() );
2200  mRotationSpinBox->blockSignals( false );
2201  mTextureWidthUnitWidget->blockSignals( true );
2202  mTextureWidthUnitWidget->setUnit( mLayer->patternWidthUnit() );
2203  mTextureWidthUnitWidget->setMapUnitScale( mLayer->patternWidthMapUnitScale() );
2204  mTextureWidthUnitWidget->blockSignals( false );
2205  mSvgOutlineWidthUnitWidget->blockSignals( true );
2206  mSvgOutlineWidthUnitWidget->setUnit( mLayer->svgOutlineWidthUnit() );
2207  mSvgOutlineWidthUnitWidget->setMapUnitScale( mLayer->svgOutlineWidthMapUnitScale() );
2208  mSvgOutlineWidthUnitWidget->blockSignals( false );
2209  mChangeColorButton->blockSignals( true );
2210  mChangeColorButton->setColor( mLayer->svgFillColor() );
2211  mChangeColorButton->blockSignals( false );
2212  mChangeBorderColorButton->blockSignals( true );
2213  mChangeBorderColorButton->setColor( mLayer->svgOutlineColor() );
2214  mChangeBorderColorButton->blockSignals( false );
2215  mBorderWidthSpinBox->blockSignals( true );
2216  mBorderWidthSpinBox->setValue( mLayer->svgOutlineWidth() );
2217  mBorderWidthSpinBox->blockSignals( false );
2218  }
2219  updateParamGui( false );
2220 
2227 }
2228 
2230 {
2231  return mLayer;
2232 }
2233 
2234 void QgsSVGFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2235 {
2236  QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select SVG texture file" ), QDir::homePath(), tr( "SVG file" ) + " (*.svg);;" + tr( "All files" ) + " (*.*)" );
2237  if ( !filePath.isNull() )
2238  {
2239  mSVGLineEdit->setText( filePath );
2240  emit changed();
2241  }
2242 }
2243 
2244 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthSpinBox_valueChanged( double d )
2245 {
2246  if ( mLayer )
2247  {
2248  mLayer->setPatternWidth( d );
2249  emit changed();
2250  }
2251 }
2252 
2253 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_textEdited( const QString & text )
2254 {
2255  if ( !mLayer )
2256  {
2257  return;
2258  }
2259 
2260  QFileInfo fi( text );
2261  if ( !fi.exists() )
2262  {
2263  return;
2264  }
2265  mLayer->setSvgFilePath( text );
2266  updateParamGui();
2267  emit changed();
2268 }
2269 
2270 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_editingFinished()
2271 {
2272  if ( !mLayer )
2273  {
2274  return;
2275  }
2276 
2277  QFileInfo fi( mSVGLineEdit->text() );
2278  if ( !fi.exists() )
2279  {
2280  QUrl url( mSVGLineEdit->text() );
2281  if ( !url.isValid() )
2282  {
2283  return;
2284  }
2285  }
2286 
2287  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2288  mLayer->setSvgFilePath( mSVGLineEdit->text() );
2290 
2291  updateParamGui();
2292  emit changed();
2293 }
2294 
2295 void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex& item )
2296 {
2297  QString file = item.data( Qt::UserRole ).toString();
2298  mLayer->setSvgFilePath( file );
2299  mSVGLineEdit->setText( file );
2300 
2301  updateParamGui();
2302  emit changed();
2303 }
2304 
2306 {
2307  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( mSvgTreeView );
2308  mSvgTreeView->setModel( g );
2309  // Set the tree expanded at the first level
2310  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2311  for ( int i = 0; i < rows; i++ )
2312  {
2313  mSvgTreeView->setExpanded( g->indexFromItem( g->item( i ) ), true );
2314  }
2315 
2316  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView );
2317  mSvgListView->setModel( m );
2318 }
2319 
2320 void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
2321 {
2322  QString path = idx.data( Qt::UserRole + 1 ).toString();
2323 
2324  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView, path );
2325  mSvgListView->setModel( m );
2326 
2327  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2328  emit changed();
2329 }
2330 
2331 
2332 void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2333 {
2334  if ( mLayer )
2335  {
2336  mLayer->setAngle( d );
2337  emit changed();
2338  }
2339 }
2340 
2342 {
2343  //activate gui for svg parameters only if supported by the svg file
2344  bool hasFillParam, hasFillOpacityParam, hasOutlineParam, hasOutlineWidthParam, hasOutlineOpacityParam;
2345  QColor defaultFill, defaultOutline;
2346  double defaultOutlineWidth, defaultFillOpacity, defaultOutlineOpacity;
2347  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultOutlineColor, hasDefaultOutlineWidth, hasDefaultOutlineOpacity;
2348  QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, hasDefaultFillColor, defaultFill,
2349  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2350  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
2351  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth,
2352  hasOutlineOpacityParam, hasDefaultOutlineOpacity, defaultOutlineOpacity );
2353  if ( resetValues )
2354  {
2355  QColor fill = mChangeColorButton->color();
2356  double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
2357  if ( hasDefaultFillColor )
2358  {
2359  fill = defaultFill;
2360  }
2361  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
2362  mChangeColorButton->setColor( fill );
2363  }
2364  mChangeColorButton->setEnabled( hasFillParam );
2365  mChangeColorButton->setAllowAlpha( hasFillOpacityParam );
2366  if ( resetValues )
2367  {
2368  QColor outline = mChangeBorderColorButton->color();
2369  double newOpacity = hasOutlineOpacityParam ? outline.alphaF() : 1.0;
2370  if ( hasDefaultOutlineColor )
2371  {
2372  outline = defaultOutline;
2373  }
2374  outline.setAlphaF( hasDefaultOutlineOpacity ? defaultOutlineOpacity : newOpacity );
2375  mChangeBorderColorButton->setColor( outline );
2376  }
2377  mChangeBorderColorButton->setEnabled( hasOutlineParam );
2378  mChangeBorderColorButton->setAllowAlpha( hasOutlineOpacityParam );
2379  if ( hasDefaultOutlineWidth && resetValues )
2380  {
2381  mBorderWidthSpinBox->setValue( defaultOutlineWidth );
2382  }
2383  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
2384 }
2385 
2386 void QgsSVGFillSymbolLayerWidget::on_mChangeColorButton_colorChanged( const QColor& color )
2387 {
2388  if ( !mLayer )
2389  {
2390  return;
2391  }
2392 
2393  mLayer->setSvgFillColor( color );
2394  emit changed();
2395 }
2396 
2397 void QgsSVGFillSymbolLayerWidget::on_mChangeBorderColorButton_colorChanged( const QColor& color )
2398 {
2399  if ( !mLayer )
2400  {
2401  return;
2402  }
2403 
2404  mLayer->setSvgOutlineColor( color );
2405  emit changed();
2406 }
2407 
2408 void QgsSVGFillSymbolLayerWidget::on_mBorderWidthSpinBox_valueChanged( double d )
2409 {
2410  if ( mLayer )
2411  {
2412  mLayer->setSvgOutlineWidth( d );
2413  emit changed();
2414  }
2415 }
2416 
2417 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthUnitWidget_changed()
2418 {
2419  if ( mLayer )
2420  {
2421  mLayer->setPatternWidthUnit( mTextureWidthUnitWidget->unit() );
2422  mLayer->setPatternWidthMapUnitScale( mTextureWidthUnitWidget->getMapUnitScale() );
2423  emit changed();
2424  }
2425 }
2426 
2427 void QgsSVGFillSymbolLayerWidget::on_mSvgOutlineWidthUnitWidget_changed()
2428 {
2429  if ( mLayer )
2430  {
2431  mLayer->setSvgOutlineWidthUnit( mSvgOutlineWidthUnitWidget->unit() );
2432  mLayer->setSvgOutlineWidthMapUnitScale( mSvgOutlineWidthUnitWidget->getMapUnitScale() );
2433  emit changed();
2434  }
2435 }
2436 
2438 
2440  QgsSymbolLayerV2Widget( parent, vl ), mLayer( nullptr )
2441 {
2442  setupUi( this );
2443  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2444  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2445  mOffsetSpinBox->setClearValue( 0 );
2446 }
2447 
2449 {
2450  if ( layer->layerType() != "LinePatternFill" )
2451  {
2452  return;
2453  }
2454 
2455  QgsLinePatternFillSymbolLayer* patternLayer = static_cast<QgsLinePatternFillSymbolLayer*>( layer );
2456  if ( patternLayer )
2457  {
2458  mLayer = patternLayer;
2459  mAngleSpinBox->blockSignals( true );
2460  mAngleSpinBox->setValue( mLayer->lineAngle() );
2461  mAngleSpinBox->blockSignals( false );
2462  mDistanceSpinBox->blockSignals( true );
2463  mDistanceSpinBox->setValue( mLayer->distance() );
2464  mDistanceSpinBox->blockSignals( false );
2465  mOffsetSpinBox->blockSignals( true );
2466  mOffsetSpinBox->setValue( mLayer->offset() );
2467  mOffsetSpinBox->blockSignals( false );
2468 
2469  //units
2470  mDistanceUnitWidget->blockSignals( true );
2471  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
2472  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
2473  mDistanceUnitWidget->blockSignals( false );
2474  mOffsetUnitWidget->blockSignals( true );
2475  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2476  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2477  mOffsetUnitWidget->blockSignals( false );
2478  }
2479 
2482 }
2483 
2485 {
2486  return mLayer;
2487 }
2488 
2489 void QgsLinePatternFillSymbolLayerWidget::on_mAngleSpinBox_valueChanged( double d )
2490 {
2491  if ( mLayer )
2492  {
2493  mLayer->setLineAngle( d );
2494  emit changed();
2495  }
2496 }
2497 
2498 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
2499 {
2500  if ( mLayer )
2501  {
2502  mLayer->setDistance( d );
2503  emit changed();
2504  }
2505 }
2506 
2507 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetSpinBox_valueChanged( double d )
2508 {
2509  if ( mLayer )
2510  {
2511  mLayer->setOffset( d );
2512  emit changed();
2513  }
2514 }
2515 
2516 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceUnitWidget_changed()
2517 {
2518  if ( mLayer )
2519  {
2520  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
2521  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
2522  emit changed();
2523  }
2524 }
2525 
2526 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2527 {
2528  if ( mLayer )
2529  {
2530  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2531  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2532  emit changed();
2533  }
2534 }
2535 
2537 
2539  QgsSymbolLayerV2Widget( parent, vl ), mLayer( nullptr )
2540 {
2541  setupUi( this );
2542  mHorizontalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2543  mVerticalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2544  mHorizontalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2545  mVerticalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2546 }
2547 
2548 
2550 {
2551  if ( !layer || layer->layerType() != "PointPatternFill" )
2552  {
2553  return;
2554  }
2555 
2556  mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
2557  mHorizontalDistanceSpinBox->blockSignals( true );
2558  mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
2559  mHorizontalDistanceSpinBox->blockSignals( false );
2560  mVerticalDistanceSpinBox->blockSignals( true );
2561  mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
2562  mVerticalDistanceSpinBox->blockSignals( false );
2563  mHorizontalDisplacementSpinBox->blockSignals( true );
2564  mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
2565  mHorizontalDisplacementSpinBox->blockSignals( false );
2566  mVerticalDisplacementSpinBox->blockSignals( true );
2567  mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
2568  mVerticalDisplacementSpinBox->blockSignals( false );
2569 
2570  mHorizontalDistanceUnitWidget->blockSignals( true );
2571  mHorizontalDistanceUnitWidget->setUnit( mLayer->distanceXUnit() );
2572  mHorizontalDistanceUnitWidget->setMapUnitScale( mLayer->distanceXMapUnitScale() );
2573  mHorizontalDistanceUnitWidget->blockSignals( false );
2574  mVerticalDistanceUnitWidget->blockSignals( true );
2575  mVerticalDistanceUnitWidget->setUnit( mLayer->distanceYUnit() );
2576  mVerticalDistanceUnitWidget->setMapUnitScale( mLayer->distanceYMapUnitScale() );
2577  mVerticalDistanceUnitWidget->blockSignals( false );
2578  mHorizontalDisplacementUnitWidget->blockSignals( true );
2579  mHorizontalDisplacementUnitWidget->setUnit( mLayer->displacementXUnit() );
2580  mHorizontalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementXMapUnitScale() );
2581  mHorizontalDisplacementUnitWidget->blockSignals( false );
2582  mVerticalDisplacementUnitWidget->blockSignals( true );
2583  mVerticalDisplacementUnitWidget->setUnit( mLayer->displacementYUnit() );
2584  mVerticalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementYMapUnitScale() );
2585  mVerticalDisplacementUnitWidget->blockSignals( false );
2586 
2587  registerDataDefinedButton( mHorizontalDistanceDDBtn, "distance_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2589  registerDataDefinedButton( mHorizontalDisplacementDDBtn, "displacement_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2590  registerDataDefinedButton( mVerticalDisplacementDDBtn, "displacement_y", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2591 }
2592 
2594 {
2595  return mLayer;
2596 }
2597 
2598 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged( double d )
2599 {
2600  if ( mLayer )
2601  {
2602  mLayer->setDistanceX( d );
2603  emit changed();
2604  }
2605 }
2606 
2607 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged( double d )
2608 {
2609  if ( mLayer )
2610  {
2611  mLayer->setDistanceY( d );
2612  emit changed();
2613  }
2614 }
2615 
2616 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged( double d )
2617 {
2618  if ( mLayer )
2619  {
2620  mLayer->setDisplacementX( d );
2621  emit changed();
2622  }
2623 }
2624 
2625 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged( double d )
2626 {
2627  if ( mLayer )
2628  {
2629  mLayer->setDisplacementY( d );
2630  emit changed();
2631  }
2632 }
2633 
2634 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceUnitWidget_changed()
2635 {
2636  if ( mLayer )
2637  {
2638  mLayer->setDistanceXUnit( mHorizontalDistanceUnitWidget->unit() );
2639  mLayer->setDistanceXMapUnitScale( mHorizontalDistanceUnitWidget->getMapUnitScale() );
2640  emit changed();
2641  }
2642 }
2643 
2644 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceUnitWidget_changed()
2645 {
2646  if ( mLayer )
2647  {
2648  mLayer->setDistanceYUnit( mVerticalDistanceUnitWidget->unit() );
2649  mLayer->setDistanceYMapUnitScale( mVerticalDistanceUnitWidget->getMapUnitScale() );
2650  emit changed();
2651  }
2652 }
2653 
2654 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementUnitWidget_changed()
2655 {
2656  if ( mLayer )
2657  {
2658  mLayer->setDisplacementXUnit( mHorizontalDisplacementUnitWidget->unit() );
2659  mLayer->setDisplacementXMapUnitScale( mHorizontalDisplacementUnitWidget->getMapUnitScale() );
2660  emit changed();
2661  }
2662 }
2663 
2664 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementUnitWidget_changed()
2665 {
2666  if ( mLayer )
2667  {
2668  mLayer->setDisplacementYUnit( mVerticalDisplacementUnitWidget->unit() );
2669  mLayer->setDisplacementYMapUnitScale( mVerticalDisplacementUnitWidget->getMapUnitScale() );
2670  emit changed();
2671  }
2672 }
2673 
2675 
2677  : QgsSymbolLayerV2Widget( parent, vl )
2678 {
2679  mLayer = nullptr;
2680 
2681  setupUi( this );
2683  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2684  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2686  scrollArea->setWidget( widgetChar );
2687 
2688  btnColor->setAllowAlpha( true );
2689  btnColor->setColorDialogTitle( tr( "Select symbol fill color" ) );
2690  btnColor->setContext( "symbology" );
2691  btnBorderColor->setAllowAlpha( true );
2692  btnBorderColor->setColorDialogTitle( tr( "Select symbol outline color" ) );
2693  btnBorderColor->setContext( "symbology" );
2694 
2695  spinOffsetX->setClearValue( 0.0 );
2696  spinOffsetY->setClearValue( 0.0 );
2697 
2698  //make a temporary symbol for the size assistant preview
2699  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
2700 
2701  if ( mVectorLayer )
2702  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
2703 
2704  connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
2705  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
2706  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
2707  connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
2708  connect( btnBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
2709  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
2710  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle( double ) ) );
2711  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2712  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2713  connect( widgetChar, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
2714  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
2715 }
2716 
2718 {
2719  delete mAssistantPreviewSymbol;
2720 }
2721 
2723 {
2724  if ( layer->layerType() != "FontMarker" )
2725  return;
2726 
2727  // layer type is correct, we can do the cast
2728  mLayer = static_cast<QgsFontMarkerSymbolLayerV2*>( layer );
2729 
2730  QFont layerFont( mLayer->fontFamily() );
2731  // set values
2732  whileBlocking( cboFont )->setCurrentFont( layerFont );
2733  whileBlocking( spinSize )->setValue( mLayer->size() );
2734  whileBlocking( btnColor )->setColor( mLayer->color() );
2735  whileBlocking( btnBorderColor )->setColor( mLayer->outlineColor() );
2736  whileBlocking( mBorderWidthSpinBox )->setValue( mLayer->outlineWidth() );
2737  whileBlocking( spinAngle )->setValue( mLayer->angle() );
2738 
2739  widgetChar->blockSignals( true );
2740  widgetChar->updateFont( layerFont );
2742  widgetChar->blockSignals( false );
2743 
2744  //block
2745  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
2746  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
2747 
2748  mSizeUnitWidget->blockSignals( true );
2749  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
2750  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
2751  mSizeUnitWidget->blockSignals( false );
2752 
2753  mBorderWidthUnitWidget->blockSignals( true );
2754  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
2755  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
2756  mBorderWidthUnitWidget->blockSignals( false );
2757 
2758  mOffsetUnitWidget->blockSignals( true );
2759  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2760  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2761  mOffsetUnitWidget->blockSignals( false );
2762 
2763  whileBlocking( cboJoinStyle )->setPenJoinStyle( mLayer->penJoinStyle() );
2764 
2765  //anchor points
2766  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
2767  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
2768 
2776  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
2777  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
2779 
2780  updateAssistantSymbol();
2781 }
2782 
2784 {
2785  return mLayer;
2786 }
2787 
2789 {
2790  mLayer->setFontFamily( font.family() );
2791  widgetChar->updateFont( font );
2792  emit changed();
2793 }
2794 
2796 {
2797  mLayer->setColor( color );
2798  emit changed();
2799 }
2800 
2802 {
2803  mLayer->setOutlineColor( color );
2804  emit changed();
2805 }
2806 
2808 {
2809  mLayer->setSize( size );
2810  //widgetChar->updateSize(size);
2811  emit changed();
2812 }
2813 
2815 {
2816  mLayer->setAngle( angle );
2817  emit changed();
2818 }
2819 
2821 {
2822  mLayer->setCharacter( chr );
2823  emit changed();
2824 }
2825 
2827 {
2828  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2829  emit changed();
2830 }
2831 
2832 void QgsFontMarkerSymbolLayerV2Widget::penJoinStyleChanged()
2833 {
2834  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
2835  emit changed();
2836 }
2837 
2839 {
2840  if ( mLayer )
2841  {
2842  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2843  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2844  emit changed();
2845  }
2846 }
2847 
2849 {
2850  if ( mLayer )
2851  {
2852  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2853  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2854  emit changed();
2855  }
2856 }
2857 
2859 {
2860  if ( mLayer )
2861  {
2862  mLayer->setOutlineWidthUnit( mSizeUnitWidget->unit() );
2863  mLayer->setOutlineWidthMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2864  emit changed();
2865  }
2866 }
2867 
2869 {
2870  if ( mLayer )
2871  {
2873  emit changed();
2874  }
2875 }
2876 
2878 {
2879  if ( mLayer )
2880  {
2882  emit changed();
2883  }
2884 }
2885 
2887 {
2888  if ( mLayer )
2889  {
2890  mLayer->setOutlineWidth( d );
2891  emit changed();
2892  }
2893 }
2894 
2895 void QgsFontMarkerSymbolLayerV2Widget::updateAssistantSymbol()
2896 {
2897  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
2898  {
2899  mAssistantPreviewSymbol->deleteSymbolLayer( i );
2900  }
2901  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
2902  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
2903  if ( ddSize )
2904  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
2905 }
2906 
2908 
2909 
2911  : QgsSymbolLayerV2Widget( parent, vl )
2912 {
2913  mLayer = nullptr;
2914 
2915  setupUi( this );
2916 }
2917 
2919 {
2920  if ( layer->layerType() != "CentroidFill" )
2921  return;
2922 
2923  // layer type is correct, we can do the cast
2924  mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
2925 
2926  // set values
2927  whileBlocking( mDrawInsideCheckBox )->setChecked( mLayer->pointOnSurface() );
2928  whileBlocking( mDrawAllPartsCheckBox )->setChecked( mLayer->pointOnAllParts() );
2929 }
2930 
2932 {
2933  return mLayer;
2934 }
2935 
2936 void QgsCentroidFillSymbolLayerV2Widget::on_mDrawInsideCheckBox_stateChanged( int state )
2937 {
2938  mLayer->setPointOnSurface( state == Qt::Checked );
2939  emit changed();
2940 }
2941 
2942 void QgsCentroidFillSymbolLayerV2Widget::on_mDrawAllPartsCheckBox_stateChanged( int state )
2943 {
2944  mLayer->setPointOnAllParts( state == Qt::Checked );
2945  emit changed();
2946 }
2947 
2949 
2951  : QgsSymbolLayerV2Widget( parent, vl )
2952 {
2953  mLayer = nullptr;
2954  setupUi( this );
2955 
2957  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2958 
2959  mSpinOffsetX->setClearValue( 0.0 );
2960  mSpinOffsetY->setClearValue( 0.0 );
2961 
2962  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
2963  connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2964  connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2965 }
2966 
2968 {
2969  if ( !layer )
2970  {
2971  return;
2972  }
2973 
2974  if ( layer->layerType() != "RasterFill" )
2975  {
2976  return;
2977  }
2978 
2979  mLayer = dynamic_cast<QgsRasterFillSymbolLayer*>( layer );
2980  if ( !mLayer )
2981  {
2982  return;
2983  }
2984 
2985  mImageLineEdit->blockSignals( true );
2986  mImageLineEdit->setText( mLayer->imageFilePath() );
2987  mImageLineEdit->blockSignals( false );
2988 
2989  cboCoordinateMode->blockSignals( true );
2990  switch ( mLayer->coordinateMode() )
2991  {
2993  cboCoordinateMode->setCurrentIndex( 1 );
2994  break;
2996  default:
2997  cboCoordinateMode->setCurrentIndex( 0 );
2998  break;
2999  }
3000  cboCoordinateMode->blockSignals( false );
3001  mSpinTransparency->blockSignals( true );
3002  mSpinTransparency->setValue( mLayer->alpha() * 100.0 );
3003  mSpinTransparency->blockSignals( false );
3004  mSliderTransparency->blockSignals( true );
3005  mSliderTransparency->setValue( mLayer->alpha() * 100.0 );
3006  mSliderTransparency->blockSignals( false );
3007  mRotationSpinBox->blockSignals( true );
3008  mRotationSpinBox->setValue( mLayer->angle() );
3009  mRotationSpinBox->blockSignals( false );
3010 
3011  mSpinOffsetX->blockSignals( true );
3012  mSpinOffsetX->setValue( mLayer->offset().x() );
3013  mSpinOffsetX->blockSignals( false );
3014  mSpinOffsetY->blockSignals( true );
3015  mSpinOffsetY->setValue( mLayer->offset().y() );
3016  mSpinOffsetY->blockSignals( false );
3017  mOffsetUnitWidget->blockSignals( true );
3018  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3019  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3020  mOffsetUnitWidget->blockSignals( false );
3021 
3022  mWidthSpinBox->blockSignals( true );
3023  mWidthSpinBox->setValue( mLayer->width() );
3024  mWidthSpinBox->blockSignals( false );
3025  mWidthUnitWidget->blockSignals( true );
3026  mWidthUnitWidget->setUnit( mLayer->widthUnit() );
3027  mWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
3028  mWidthUnitWidget->blockSignals( false );
3029  updatePreviewImage();
3030 
3035 }
3036 
3038 {
3039  return mLayer;
3040 }
3041 
3042 void QgsRasterFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
3043 {
3044  QSettings s;
3045  QString openDir;
3046  QString lineEditText = mImageLineEdit->text();
3047  if ( !lineEditText.isEmpty() )
3048  {
3049  QFileInfo openDirFileInfo( lineEditText );
3050  openDir = openDirFileInfo.path();
3051  }
3052 
3053  if ( openDir.isEmpty() )
3054  {
3055  openDir = s.value( "/UI/lastRasterFillImageDir", QDir::homePath() ).toString();
3056  }
3057 
3058  //show file dialog
3059  QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select image file" ), openDir );
3060  if ( !filePath.isNull() )
3061  {
3062  //check if file exists
3063  QFileInfo fileInfo( filePath );
3064  if ( !fileInfo.exists() || !fileInfo.isReadable() )
3065  {
3066  QMessageBox::critical( nullptr, "Invalid file", "Error, file does not exist or is not readable" );
3067  return;
3068  }
3069 
3070  s.setValue( "/UI/lastRasterFillImageDir", fileInfo.absolutePath() );
3071  mImageLineEdit->setText( filePath );
3072  on_mImageLineEdit_editingFinished();
3073  }
3074 }
3075 
3076 void QgsRasterFillSymbolLayerWidget::on_mImageLineEdit_editingFinished()
3077 {
3078  if ( !mLayer )
3079  {
3080  return;
3081  }
3082 
3083  QFileInfo fi( mImageLineEdit->text() );
3084  if ( !fi.exists() )
3085  {
3086  QUrl url( mImageLineEdit->text() );
3087  if ( !url.isValid() )
3088  {
3089  return;
3090  }
3091  }
3092 
3093  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
3094  mLayer->setImageFilePath( mImageLineEdit->text() );
3095  updatePreviewImage();
3097 
3098  emit changed();
3099 }
3100 
3101 void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
3102 {
3103  switch ( index )
3104  {
3105  case 0:
3106  //feature coordinate mode
3108  break;
3109  case 1:
3110  //viewport coordinate mode
3112  break;
3113  }
3114 
3115  emit changed();
3116 }
3117 
3118 void QgsRasterFillSymbolLayerWidget::on_mSpinTransparency_valueChanged( int value )
3119 {
3120  if ( !mLayer )
3121  {
3122  return;
3123  }
3124 
3125  mLayer->setAlpha( value / 100.0 );
3126  emit changed();
3127  updatePreviewImage();
3128 }
3129 
3130 void QgsRasterFillSymbolLayerWidget::offsetChanged()
3131 {
3132  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
3133  emit changed();
3134 }
3135 
3136 void QgsRasterFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
3137 {
3138  if ( !mLayer )
3139  {
3140  return;
3141  }
3142  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
3143  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3144  emit changed();
3145 }
3146 
3147 void QgsRasterFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
3148 {
3149  if ( mLayer )
3150  {
3151  mLayer->setAngle( d );
3152  emit changed();
3153  }
3154 }
3155 
3156 void QgsRasterFillSymbolLayerWidget::on_mWidthUnitWidget_changed()
3157 {
3158  if ( !mLayer )
3159  {
3160  return;
3161  }
3162  mLayer->setWidthUnit( mWidthUnitWidget->unit() );
3163  mLayer->setWidthMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3164  emit changed();
3165 }
3166 
3167 void QgsRasterFillSymbolLayerWidget::on_mWidthSpinBox_valueChanged( double d )
3168 {
3169  if ( !mLayer )
3170  {
3171  return;
3172  }
3173  mLayer->setWidth( d );
3174  emit changed();
3175 }
3176 
3177 
3178 void QgsRasterFillSymbolLayerWidget::updatePreviewImage()
3179 {
3180  if ( !mLayer )
3181  {
3182  return;
3183  }
3184 
3185  QImage image( mLayer->imageFilePath() );
3186  if ( image.isNull() )
3187  {
3188  mLabelImagePreview->setPixmap( QPixmap() );
3189  return;
3190  }
3191 
3192  if ( image.height() > 150 || image.width() > 150 )
3193  {
3194  image = image.scaled( 150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation );
3195  }
3196 
3197  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
3198  previewImage.fill( Qt::transparent );
3199  QRect imageRect(( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
3200  QPainter p;
3201  p.begin( &previewImage );
3202  //draw a checkerboard background
3203  uchar pixDataRGB[] = { 150, 150, 150, 150,
3204  100, 100, 100, 150,
3205  100, 100, 100, 150,
3206  150, 150, 150, 150
3207  };
3208  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
3209  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
3210  QBrush checkerBrush;
3211  checkerBrush.setTexture( pix );
3212  p.fillRect( imageRect, checkerBrush );
3213 
3214  if ( mLayer->alpha() < 1.0 )
3215  {
3216  p.setOpacity( mLayer->alpha() );
3217  }
3218 
3219  p.drawImage( imageRect.left(), imageRect.top(), image );
3220  p.end();
3221  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
3222 }
3223 
3224 
3226 
3227 QgsSvgListModel::QgsSvgListModel( QObject* parent ) : QAbstractListModel( parent )
3228 {
3230 }
3231 
3232 QgsSvgListModel::QgsSvgListModel( QObject* parent, const QString& path ) : QAbstractListModel( parent )
3233 {
3234  mSvgFiles = QgsSymbolLayerV2Utils::listSvgFilesAt( path );
3235 }
3236 
3237 int QgsSvgListModel::rowCount( const QModelIndex& parent ) const
3238 {
3239  Q_UNUSED( parent );
3240  return mSvgFiles.count();
3241 }
3242 
3243 QVariant QgsSvgListModel::data( const QModelIndex& index, int role ) const
3244 {
3245  QString entry = mSvgFiles.at( index.row() );
3246 
3247  if ( role == Qt::DecorationRole ) // icon
3248  {
3249  QPixmap pixmap;
3250  if ( !QPixmapCache::find( entry, pixmap ) )
3251  {
3252  // render SVG file
3253  QColor fill, outline;
3254  double outlineWidth, fillOpacity, outlineOpacity;
3255  bool fillParam, fillOpacityParam, outlineParam, outlineWidthParam, outlineOpacityParam;
3256  bool hasDefaultFillColor = false, hasDefaultFillOpacity = false, hasDefaultOutlineColor = false,
3257  hasDefaultOutlineWidth = false, hasDefaultOutlineOpacity = false;
3258  QgsSvgCache::instance()->containsParams( entry, fillParam, hasDefaultFillColor, fill,
3259  fillOpacityParam, hasDefaultFillOpacity, fillOpacity,
3260  outlineParam, hasDefaultOutlineColor, outline,
3261  outlineWidthParam, hasDefaultOutlineWidth, outlineWidth,
3262  outlineOpacityParam, hasDefaultOutlineOpacity, outlineOpacity );
3263 
3264  //if defaults not set in symbol, use these values
3265  if ( !hasDefaultFillColor )
3266  fill = QColor( 200, 200, 200 );
3267  fill.setAlphaF( hasDefaultFillOpacity ? fillOpacity : 1.0 );
3268  if ( !hasDefaultOutlineColor )
3269  outline = Qt::black;
3270  outline.setAlphaF( hasDefaultOutlineOpacity ? outlineOpacity : 1.0 );
3271  if ( !hasDefaultOutlineWidth )
3272  outlineWidth = 0.6;
3273 
3274  bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
3275  const QImage& img = QgsSvgCache::instance()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
3276  pixmap = QPixmap::fromImage( img );
3277  QPixmapCache::insert( entry, pixmap );
3278  }
3279 
3280  return pixmap;
3281  }
3282  else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
3283  {
3284  return entry;
3285  }
3286 
3287  return QVariant();
3288 }
3289 
3290 
3291 QgsSvgGroupsModel::QgsSvgGroupsModel( QObject* parent ) : QStandardItemModel( parent )
3292 {
3294  QStandardItem *parentItem = invisibleRootItem();
3295 
3296  for ( int i = 0; i < svgPaths.size(); i++ )
3297  {
3298  QDir dir( svgPaths[i] );
3299  QStandardItem *baseGroup;
3300 
3301  if ( dir.path().contains( QgsApplication::pkgDataPath() ) )
3302  {
3303  baseGroup = new QStandardItem( QString( "App Symbols" ) );
3304  }
3305  else if ( dir.path().contains( QgsApplication::qgisSettingsDirPath() ) )
3306  {
3307  baseGroup = new QStandardItem( QString( "User Symbols" ) );
3308  }
3309  else
3310  {
3311  baseGroup = new QStandardItem( dir.dirName() );
3312  }
3313  baseGroup->setData( QVariant( svgPaths[i] ) );
3314  baseGroup->setEditable( false );
3315  baseGroup->setCheckable( false );
3316  baseGroup->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
3317  baseGroup->setToolTip( dir.path() );
3318  parentItem->appendRow( baseGroup );
3319  createTree( baseGroup );
3320  QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
3321  }
3322 }
3323 
3324 void QgsSvgGroupsModel::createTree( QStandardItem*& parentGroup )
3325 {
3326  QDir parentDir( parentGroup->data().toString() );
3327  Q_FOREACH ( const QString& item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3328  {
3329  QStandardItem* group = new QStandardItem( item );
3330  group->setData( QVariant( parentDir.path() + '/' + item ) );
3331  group->setEditable( false );
3332  group->setCheckable( false );
3333  group->setToolTip( parentDir.path() + '/' + item );
3334  group->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
3335  parentGroup->appendRow( group );
3336  createTree( group );
3337  }
3338 }
3339 
3340 
3342 
3343 
3344 
3345 
3346 
3347 
3349  : QgsSymbolLayerV2Widget( parent, vl )
3350  , mLayer( nullptr )
3351 {
3352  setupUi( this );
3353  modificationExpressionSelector->setLayer( const_cast<QgsVectorLayer*>( vl ) );
3354  modificationExpressionSelector->loadFieldNames();
3355  modificationExpressionSelector->setExpressionContext( _getExpressionContext( this ) );
3356  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPolygonLayer.svg" ), tr( "Polygon / MultiPolygon" ), QgsSymbolV2::Fill );
3357  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconLineLayer.svg" ), tr( "LineString / MultiLineString" ), QgsSymbolV2::Line );
3358  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPointLayer.svg" ), tr( "Point / MultiPoint" ), QgsSymbolV2::Marker );
3359  connect( modificationExpressionSelector, SIGNAL( expressionParsed( bool ) ), this, SLOT( updateExpression() ) );
3360  connect( cbxGeometryType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateSymbolType() ) );
3361 }
3362 
3364 {
3365  mLayer = static_cast<QgsGeometryGeneratorSymbolLayerV2*>( l );
3366 
3368  modificationExpressionSelector->setExpressionContext( *mPresetExpressionContext );
3369  modificationExpressionSelector->setExpressionText( mLayer->geometryExpression() );
3370  cbxGeometryType->setCurrentIndex( cbxGeometryType->findData( mLayer->symbolType() ) );
3371 }
3372 
3374 {
3375  return mLayer;
3376 }
3377 
3378 void QgsGeometryGeneratorSymbolLayerWidget::updateExpression()
3379 {
3380  mLayer->setGeometryExpression( modificationExpressionSelector->expressionText() );
3381 
3382  emit changed();
3383 }
3384 
3385 void QgsGeometryGeneratorSymbolLayerWidget::updateSymbolType()
3386 {
3387  mLayer->setSymbolType( static_cast<QgsSymbolV2::SymbolType>( cbxGeometryType->itemData( cbxGeometryType->currentIndex() ).toInt() ) );
3388 
3389  emit symbolChanged();
3390 }
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
void symbolChanged()
Should be emitted whenever the sub symbol changed on this symbol layer configuration.
void setBorderWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QgsVectorColorRampV2 * colorRamp()
Color ramp used for the gradient fill, only used if the gradient color type is set to ColorRamp...
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
QgsSymbolV2::OutputUnit offsetUnit() const
void setDistanceUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit for the maximum distance to shade inside of the shape from the polygon&#39;s boundary...
void setOutlineStyle(Qt::PenStyle outlineStyle)
Sets the marker&#39;s outline style (eg solid, dashed, etc)
QgsShapeburstFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
Qt::PenCapStyle penCapStyle() const
bool isReadable() const
QgsSymbolV2::SymbolType symbolType() const
Access the symbol type.
void setOutlineColor(const QColor &color) override
Set outline color.
void setMaxDistance(double maxDistance)
Sets the maximum distance to shape inside of the shape from the polygon&#39;s boundary.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setToolTip(const QString &toolTip)
QgsVectorColorRampV2 * colorRamp()
Returns the color ramp used for the shapeburst fill.
void setGuiForSvg(const QgsSvgMarkerSymbolLayerV2 *layer)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
Single variable definition for use within a QgsExpressionContextScope.
static QString gradientSpreadDesc()
static unsigned index
const QgsMapUnitScale & displacementYMapUnitScale() const
virtual int rowCount(const QModelIndex &parent) const=0
virtual QgsSymbolLayerV2 * symbolLayer() override
bool ignoreRings() const
Returns whether the shapeburst fill is set to ignore polygon interior rings.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set outline join style.
void setReferencePoint1(QPointF referencePoint)
Starting point of gradient fill, in the range [0,0] - [1,1].
void setSymbolType(QgsSymbolV2::SymbolType symbolType)
Set the type of symbol which should be created.
void setReferencePoint2IsCentroid(bool isCentroid)
Sets the end point of the gradient to be the feature centroid.
void setSvgOutlineWidth(double w)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QPointF offset() const
Returns the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered mar...
const QgsMapUnitScale & borderWidthMapUnitScale() const
void setupUi(QWidget *widget)
Placement placement() const
The placement of the markers.
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Returns the map scale for the width of the marker&#39;s outline.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
QString path() const
void setIcon(const QIcon &icon)
void on_mHorizontalAnchorComboBox_currentIndexChanged(int index)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
virtual QgsSymbolLayerV2 * symbolLayer() override
virtual QgsSymbolLayerV2 * symbolLayer() override
A container class for data source field mapping or expression.
Qt::PenStyle outlineStyle() const
Returns the marker&#39;s outline style (eg solid, dashed, etc)
QgsFilledMarkerSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsFilledMarkerSymbolLayerWidget.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
virtual QgsSymbolLayerV2 * symbolLayer() override
void setCoordinateMode(GradientCoordinateMode coordinateMode)
QgsGradientFillSymbolLayerV2 * mLayer
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user&#39;s home dir.
qreal alphaF() const
void setSvgFillColor(const QColor &c)
void setPatternWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
Qt::PenJoinStyle penJoinStyle() const
virtual QgsSymbolLayerV2 * symbolLayer() override
QgsSymbolV2::OutputUnit distanceUnit() const
Returns the unit for the maximum distance to shade inside of the shape from the polygon&#39;s boundary...
static QString doublePosDesc()
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QgsSimpleLineSymbolLayerV2 * mLayer
const QgsMapUnitScale & displacementXMapUnitScale() const
void setDistanceYUnit(QgsSymbolV2::OutputUnit unit)
QgsFontMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
QString imageFilePath() const
The path to the raster image used for the fill.
static QString colorNoAlphaDesc()
virtual QgsSymbolLayerV2 * symbolLayer() override
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
void addButton(QAbstractButton *button)
QgsSymbolV2::OutputUnit sizeUnit() const
Returns the units for the symbol&#39;s size.
Qt::BrushStyle brushStyle() const
void setOutlineColor(const QColor &c) override
Set outline color.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
GradientCoordinateMode coordinateMode() const
Coordinate mode for gradient.
double size() const
Returns the symbol size.
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
GradientType gradientType() const
Type of gradient, eg linear or radial.
QgsSimpleFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
void updateFont(const QFont &font)
[0]
QObject * sender() const
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
Set outline width map unit scale.
QgsLinePatternFillSymbolLayer * mLayer
Qt::PenStyle penStyle() const
QgsCentroidFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setPointOnSurface(bool pointOnSurface)
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
const QgsMapUnitScale & sizeMapUnitScale() const
Returns the map unit scale for the symbol&#39;s size.
void setIgnoreRings(bool ignoreRings)
Sets whether the shapeburst fill should ignore polygon rings when calculating the buffered shading...
QgsSymbolV2::OutputUnit widthUnit() const
Returns the units for the image&#39;s width.
The output shall be in pixels.
Definition: qgssymbolv2.h:70
Calculate scale by the diameter.
Definition: qgssymbolv2.h:93
void setOffset(QPointF offset)
Sets the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered marker...
QPointF offset() const
Returns the offset for the shapeburst fill.
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
QgsGradientFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
virtual QgsSymbolLayerV2 * symbolLayer() override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
QgsFontMarkerSymbolLayerV2 * mLayer
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setCharacter(QChar character)
void setOutlineWidth(double w)
Sets the width of the marker&#39;s outline.
void setPenJoinStyle(Qt::PenJoinStyle style)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
Line symbol.
Definition: qgssymbolv2.h:82
static QString lineStyleDesc()
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void containsParams(const QString &path, bool &hasFillParam, QColor &defaultFillColor, bool &hasOutlineParam, QColor &defaultOutlineColor, bool &hasOutlineWidthParam, double &defaultOutlineWidth) const
Tests if an svg file contains parameters for fill, outline color, outline width.
void setDistanceXMapUnitScale(const QgsMapUnitScale &scale)
const QPixmap * icon() const
const QgsMapUnitScale & offsetMapUnitScale() const
ShapeburstColorType colorType() const
Returns the color mode used for the shapeburst fill.
QColor fillColor() const override
Get fill color.
void setColorBorder(const QColor &color)
Set outline color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol&#39;s offset.
void setSvgOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void on_mVerticalAnchorComboBox_currentIndexChanged(int index)
void setPointOnAllParts(bool pointOnAllParts)
Sets whether a point is drawn for all parts or only on the biggest part of multi-part features...
void setIntervalMapUnitScale(const QgsMapUnitScale &scale)
virtual QgsDataDefined * getDataDefinedProperty(const QString &property) const
Returns the data defined property corresponding to the specified property key.
static QStringList listSvgFilesAt(const QString &directory)
Return a list of svg files at the specified directory.
QgsSymbolV2::OutputUnit borderWidthUnit() const
static QString horizontalAnchorDesc()
void setMapUnitScale(const QgsMapUnitScale &scale) override
QString homePath()
void setShape(Shape shape)
Sets the rendered marker shape.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setColorRamp(QgsVectorColorRampV2 *ramp)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
void setVariable(const QString &name, const QVariant &value)
Convenience method for setting a variable in the context scope by name and value. ...
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
const QgsVectorLayer * mVectorLayer
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
QgsPointPatternFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
QgsSymbolV2::OutputUnit svgOutlineWidthUnit() const
void setPatternWidth(double width)
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Marker symbol.
Definition: qgssymbolv2.h:81
const QgsMapUnitScale & offsetAlongLineMapUnitScale() const
Returns the map unit scale used for calculating the offset in map units along line for markers...
static QList< Shape > availableShapes()
Returns a list of all available shape types.
int size() const
virtual void setData(const QVariant &value, int role)
void on_mChangeBorderColorButton_colorChanged(const QColor &color)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the symbol&#39;s offset.
bool isNull() const
void setSvgOutlineColor(const QColor &c)
void setOffsetAlongLine(double offsetAlongLine)
Sets the the offset along the line for the marker placement.
const QgsMapUnitScale & offsetMapUnitScale() const
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setInterval(double interval)
The interval between individual markers.
The QgsMapSettings class contains configuration for rendering of the map.
void setDistanceUnit(QgsSymbolV2::OutputUnit unit)
virtual QgsSymbolLayerV2 * symbolLayer() override
int width() const
static QgsSvgCache * instance()
Definition: qgssvgcache.cpp:97
void setDrawInsidePolygon(bool drawInsidePolygon)
void setGradientType(GradientType gradientType)
void setValue(const QString &key, const QVariant &value)
const QgsMapUnitScale & offsetMapUnitScale() const
QSize size() const
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setRotateMarker(bool rotate)
Shall the marker be rotated.
const QImage & svgAsImage(const QString &file, double size, const QColor &fill, const QColor &outline, double outlineWidth, double widthScaleFactor, double rasterScaleFactor, bool &fitsInCache)
Get SVG as QImage.
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
virtual double width() const
const char * name() const
QgsSimpleLineSymbolLayerV2 * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
GradientSpread gradientSpread() const
Gradient spread mode.
QgsSymbolV2::OutputUnit offsetAlongLineUnit() const
Returns the unit used for calculating the offset along line for markers.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
QgsSymbolV2::OutputUnit distanceXUnit() const
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
The output shall be in millimeters.
Definition: qgssymbolv2.h:67
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit u)
Sets the unit for the width of the marker&#39;s outline.
A class for filling symbols with a repeated raster image.
void setOffset(QPointF offset)
Sets the offset for the shapeburst fill.
qreal x() const
qreal y() const
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
void setColor(const QColor &color) override
The fill color.
A dialog to enter a custom dash space pattern for lines.
void on_mChangeColorButton_colorChanged(const QColor &color)
void setBorderColor(const QColor &color)
void setOffset(double offset)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
bool appendSymbolLayer(QgsSymbolLayerV2 *layer)
Append symbol layer at the end of the list Ownership will be transferred.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setMapUnitScale(const QgsMapUnitScale &scale) override
QgsSymbolV2::OutputUnit patternWidthUnit() const
QVariant property(const char *name) const
virtual QgsSymbolLayerV2 * symbolLayer() override
static QString penJoinStyleDesc()
virtual QgsSymbolLayerV2 * symbolLayer() override
QgsMarkerLineSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setWidth(const double width)
Sets the width for scaling the image used in the fill.
QString path() const
void fill(uint pixelValue)
void setPenJoinStyle(Qt::PenJoinStyle style)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setBrushStyle(Qt::BrushStyle style)
void setReferencePoint1IsCentroid(bool isCentroid)
Sets the starting point of the gradient to be the feature centroid.
const QgsMapUnitScale & intervalMapUnitScale() const
static QString double180RotDesc()
double interval() const
The interval between individual markers.
void setFontFamily(const QString &family)
const QgsMapUnitScale & widthMapUnitScale() const
void setPath(const QString &path)
const QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void setToolTip(const QString &toolTip)
static QString gradientTypeDesc()
void setBlurRadius(int blurRadius)
Sets the blur radius, which controls the amount of blurring applied to the fill.
void registerDataDefinedButton(QgsDataDefinedButton *button, const QString &propertyName, QgsDataDefinedButton::DataType type, const QString &description)
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
void appendRow(const QList< QStandardItem * > &items)
static QStringList listSvgFiles()
Return a list of all available svg files.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
virtual void setWidth(double width)
static QgsStyleV2 * defaultStyle()
return default application-wide style
Definition: qgsstylev2.cpp:51
void setWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the image&#39;s width.
void setFillColor(const QColor &color) override
Set fill color.
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
bool isEmpty() const
QColor outlineColor() const override
Get outline color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void on_mVerticalAnchorComboBox_currentIndexChanged(int index)
void setAngle(double angle)
int row() const
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the fill&#39;s offset.
The output shall be in map unitx.
Definition: qgssymbolv2.h:68
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the symbol&#39;s size.
QgsSymbolV2::OutputUnit distanceYUnit() const
void setOverrideCursor(const QCursor &cursor)
void setDistanceYMapUnitScale(const QgsMapUnitScale &scale)
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
void setGeometryExpression(const QString &exp)
Set the expression to generate this geometry.
static QgsExpressionContext _getExpressionContext(const void *context)
QColor color2() const
Color for endpoint of gradient, only used if the gradient color type is set to SimpleTwoColor.
QgsFilledMarkerSymbolLayer * mLayer
double alpha() const
The opacity for the raster image used in the fill.
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:134
void restoreOverrideCursor()
QColor borderColor() const
Returns the marker&#39;s border color.
QVector< qreal > customDashVector() const
static QString encodeShape(Shape shape)
Encodes a shape to its string representation.
HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
bool useWholeShape() const
Returns whether the shapeburst fill is set to cover the entire shape.
virtual QVariant data(const QModelIndex &index, int role) const=0
void setOffsetAlongLineMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for calculating the offset in map units along line for markers...
const QgsMapUnitScale & svgOutlineWidthMapUnitScale() const
QGis::GeometryType geometryType() const
Returns point, line or polygon.
Qt::PenJoinStyle penJoinStyle() const
Get outline join style.
void setDisplacementXUnit(QgsSymbolV2::OutputUnit unit)
void setCoordinateMode(const FillCoordinateMode mode)
Set the coordinate mode for fill.
QgsPointPatternFillSymbolLayer * mLayer
const QgsMapUnitScale & customDashPatternMapUnitScale() const
QgsSvgMarkerSymbolLayerV2 * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setOffsetAlongLineUnit(QgsSymbolV2::OutputUnit unit)
Sets the unit used for calculating the offset along line for markers.
QgsDataDefinedAssistant * assistant()
Returns the assistant used to defined the data defined object properties, if set. ...
Single scope for storing variables and functions for use within a QgsExpressionContext.
void on_mHorizontalAnchorComboBox_currentIndexChanged(int index)
virtual QColor color() const
The fill color.
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units for the symbol&#39;s offset.
virtual QgsSymbolLayerV2 * symbolLayer() override
void setBorderWidthUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
void setPenCapStyle(Qt::PenCapStyle style)
double maxDistance() const
Returns the maximum distance from the shape&#39;s boundary which is shaded.
QgsRasterFillSymbolLayer * mLayer
QgsMarkerLineSymbolLayerV2 * mLayer
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the symbol&#39;s offset.
void setCustomDashVector(const QVector< qreal > &vector)
void setDisplacementXMapUnitScale(const QgsMapUnitScale &scale)
void setOffset(QPointF offset)
Sets the offset for the fill.
void setColor2(const QColor &color2)
Sets the color for the endpoint of the shapeburst fill.
A button for defining data source field mappings or expressions.
virtual QgsSymbolLayerV2 * symbolLayer() override
const QgsMapUnitScale & distanceMapUnitScale() const
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void populateIcons(const QModelIndex &idx)
void setColorType(ShapeburstColorType colorType)
Sets the color mode to use for the shapeburst fill.
void setDistanceXUnit(QgsSymbolV2::OutputUnit unit)
bool exists() const
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
QgsCentroidFillSymbolLayerV2 * mLayer
void setOutlineWidth(double width)
Set outline width.
bool blockSignals(bool block)
static QString pkgDataPath()
Returns the common root path of all application data directories.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QgsSymbolV2::OutputUnit displacementXUnit() const
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units used for the offset of the shapeburst fill.
bool pointOnAllParts() const
Returns whether a point is drawn for all parts or only on the biggest part of multi-part features...
const QFont & font() const
virtual void setData(int role, const QVariant &value)
void setOffset(QPointF offset)
Offset for gradient fill.
void registerGetExpressionContextCallback(ExpressionContextCallback fnGetExpressionContext, const void *context)
Register callback function for retrieving the expression context for the button.
virtual QString layerType() const =0
Returns a string that represents this layer type.
void setBorderColor(const QColor &borderColor)
void on_mFileLineEdit_textEdited(const QString &text)
double outlineWidth() const
Get outline width.
virtual QgsSymbolLayerV2 * symbolLayer() override
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map scale for the width of the marker&#39;s outline.
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:486
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Sets the units used for the offset for the shapeburst fill.
QgsSimpleMarkerSymbolLayerV2 * mLayer
QgsSymbolV2::OutputUnit intervalUnit() const
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void setOffset(QPointF offset)
void setTexture(const QPixmap &pixmap)
static QString gradientCoordModeDesc()
const QgsMapUnitScale & distanceMapUnitScale() const
void setDataDefinedWidth(const QgsDataDefined &dd)
Set data defined width for whole symbol (including all symbol layers).
A class for svg fill patterns.
QgsSimpleLineSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setMapUnitScale(const QgsMapUnitScale &scale) override
QVariant value(const QString &key, const QVariant &defaultValue) const
void setBorderColor(const QColor &color)
Sets the marker&#39;s border color.
const QgsMapUnitScale & outlineWidthMapUnitScale() const
Get outline width map unit scale.
QgsSymbolV2::OutputUnit outlineWidthUnit() const
Get outline width unit.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:333
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the fill&#39;s offset.
VerticalAnchorPoint
Symbol vertical anchor points.
QgsSymbolV2::ScaleMethod scaleMethod() const
Returns the method to use for scaling the marker&#39;s size.
void setGradientColorType(GradientColorType gradientColorType)
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
Shape shape() const
Returns the shape for the rendered marker symbol.
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
Definition: qgsmapcanvas.h:455
QString dirName() const
void setPenStyle(Qt::PenStyle style)
QVariant data(int role) const
void setPlacement(Placement p)
The placement of the markers.
QStyle * style()
void updateParamGui(bool resetValues=true)
Enables or disables svg fill color, border color and border width based on whether the svg file suppo...
QgsSymbolV2::OutputUnit offsetUnit() const
QgsExpressionContext * mPresetExpressionContext
Optional preset expression context.
void setDisplacementYUnit(QgsSymbolV2::OutputUnit unit)
QgsSvgMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
const QgsMapUnitScale & distanceXMapUnitScale() const
const QgsMapUnitScale & patternWidthMapUnitScale() const
QString family() const
void setCustomDashPatternMapUnitScale(const QgsMapUnitScale &scale)
void setSvgFilePath(const QString &svgPath)
void setUseWholeShape(bool useWholeShape)
Sets whether the shapeburst fill should be drawn using the entire shape.
static QString verticalAnchorDesc()
const QChar at(int position) const
QgsSvgMarkerSymbolLayerV2 * mLayer
QgsSymbolV2::OutputUnit offsetUnit() const
static QString fillStyleDesc()
QPixmap * find(const QString &key)
void setColorRamp(QgsVectorColorRampV2 *ramp)
Sets the color ramp used to draw the shapeburst fill.
Fill symbol.
Definition: qgssymbolv2.h:83
const QgsMapUnitScale & distanceYMapUnitScale() const
FillCoordinateMode coordinateMode() const
Coordinate mode for fill.
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void on_mHorizontalAnchorComboBox_currentIndexChanged(int index)
const QgsMapUnitScale & widthMapUnitScale() const
Returns the map unit scale for the image&#39;s width.
double outlineWidth() const
Returns the width of the marker&#39;s outline.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the marker&#39;s outline join style (eg miter, bevel, etc).
QgsSimpleMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
virtual QgsSymbolLayerV2 * symbolLayer() override
QColor color2() const
Returns the color used for the endpoint of the shapeburst fill.
void setDisplacementYMapUnitScale(const QgsMapUnitScale &scale)
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
QgsSymbolV2::OutputUnit offsetUnit() const
void setAlpha(const double alpha)
Sets the opacity for the raster image used in the fill.
QColor fillColor() const override
Get fill color.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
static QStringList svgPaths()
Returns the pathes to svg directories.
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units for the fill&#39;s offset.
void setAlphaF(qreal alpha)
virtual void setColor(const QColor &color)
The fill color.
virtual QgsSymbolLayerV2 * symbolLayer()=0
QgsSymbolV2::OutputUnit customDashPatternUnit() const
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
Qt::PenJoinStyle penJoinStyle() const
Returns the marker&#39;s outline join style (eg miter, bevel, etc).
bool setProperty(const char *name, const QVariant &value)
Abstract base class for marker symbol layers.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
Set outline width unit.
Calculate scale by the area.
Definition: qgssymbolv2.h:92
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setColor2(const QColor &color2)
QgsSymbolV2::OutputUnit outlineWidthUnit() const
QgsSVGFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
QgsShapeburstFillSymbolLayerV2 * mLayer
HorizontalAnchorPoint
Symbol horizontal anchor points.
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
const QgsMapUnitScale & offsetMapUnitScale() const
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
virtual Q_DECL_DEPRECATED QString dataDefinedPropertyLabel(const QString &entryName)
Get label for data defined entry.
void setWidthUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units for the image&#39;s width.
void setPatternWidthUnit(QgsSymbolV2::OutputUnit unit)
void setGradientSpread(GradientSpread gradientSpread)
bool insert(const QString &key, const QPixmap &pixmap)
QString absolutePath() const
Widget displaying a combobox allowing the user to choose between millimeter and map units If the user...
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolV2::OutputUnit outlineWidthUnit() const
Returns the unit for the width of the marker&#39;s outline.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSize(double size)
Sets the symbol size.
void init(const QgsVectorLayer *vl, const QgsDataDefined *datadefined=nullptr, const QgsDataDefinedButton::DataTypes &datatypes=AnyType, const QString &description=QString())
Initialize a newly constructed data defined button (useful if button already included from form layou...
Filled marker symbol layer, consisting of a shape which is rendered using a QgsFillSymbolV2.
static QString customDashDesc()
QObject * parent() const
void setAngle(double angle)
Sets the rotation angle for the marker.
Qt::PenStyle borderStyle() const
int blurRadius() const
Returns the blur radius, which controls the amount of blurring applied to the fill.
Represents a vector layer which manages a vector based data sets.
bool begin(QPaintDevice *device)
QgsSymbolV2::OutputUnit displacementYUnit() const
void setReferencePoint2(QPointF referencePoint)
End point of gradient fill, in the range [0,0] - [1,1].
QgsSymbolV2::OutputUnit distanceUnit() const
Abstract base class for color ramps.
void updateDataDefined(QgsDataDefined *dd) const
Updates a QgsDataDefined with the current settings from the button.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
QgsGeometryGeneratorSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void setBorderWidth(double borderWidth)
GradientColorType gradientColorType() const
Gradient color mode, controls how gradient color stops are created.
QgsFontMarkerSymbolLayerV2 * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbolV2 *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbolV2 to an expression context.
QString toString() const
double width() const
Returns the width used for scaling the image used in the fill.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol&#39;s size.
QColor outlineColor() const override
Get outline color.
QgsFilledMarkerSymbolLayer * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setCheckable(bool checkable)
QgsSimpleMarkerSymbolLayerV2 * clone() const override
Shall be reimplemented by subclasses to create a deep copy of the instance.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
Qt::PenJoinStyle penJoinStyle() const
virtual QVariant data(int role) const
bool rotateMarker() const
Shall the marker be rotated.
void setEditable(bool editable)
void setOffsetUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units for the fill&#39;s offset.
VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
static bool shapeIsFilled(Shape shape)
Returns true if a symbol shape has a fill.
static QString double0to1Desc()
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an outline...
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QgsSVGFillSymbolLayer * mLayer
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
QgsSimpleFillSymbolLayerV2 * mLayer
static QString colorAlphaDesc()
const QgsMapUnitScale & offsetMapUnitScale() const
QgsSymbolV2::OutputUnit widthUnit() const
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Units for gradient fill offset.
void setName(const QModelIndex &idx)