QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include "qgssvgselectorwidget.h"
38 
39 #include "qgslogger.h"
40 #include "qgssizescalewidget.h"
41 
42 #include <QAbstractButton>
43 #include <QColorDialog>
44 #include <QCursor>
45 #include <QDir>
46 #include <QFileDialog>
47 #include <QPainter>
48 #include <QSettings>
49 #include <QStandardItemModel>
50 #include <QSvgRenderer>
51 #include <QMessageBox>
52 
53 static QgsExpressionContext _getExpressionContext( const void* context )
54 {
55  const QgsSymbolLayerV2Widget* widget = ( const QgsSymbolLayerV2Widget* ) context;
56 
57  if ( widget->expressionContext() )
58  return QgsExpressionContext( *widget->expressionContext() );
59 
60  QgsExpressionContext expContext;
64 
65  if ( widget->mapCanvas() )
66  {
69  }
70  else
71  {
73  }
74 
75  const QgsVectorLayer* layer = widget->vectorLayer();
76  if ( layer )
77  expContext << QgsExpressionContextUtils::layerScope( layer );
78 
80  if ( const QgsSymbolLayerV2* symbolLayer = const_cast< QgsSymbolLayerV2Widget* >( widget )->symbolLayer() )
81  {
82  //cheat a bit - set the symbol color variable to match the symbol layer's color (when we should really be using the *symbols*
83  //color, but that's not accessible here). 99% of the time these will be the same anyway
85  }
86  expContext << symbolScope;
91 
92  //TODO - show actual value
93  expContext.setOriginalValueVariable( QVariant() );
97 
98  return expContext;
99 }
100 
102 {
103  mMapCanvas = canvas;
104  Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
105  {
106  unitWidget->setMapCanvas( mMapCanvas );
107  }
108  Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
109  {
110  if ( ddButton->assistant() )
111  ddButton->assistant()->setMapCanvas( mMapCanvas );
112  }
113 }
114 
116 {
117  return mMapCanvas;
118 }
119 
121 {
122  const QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
123  button->init( mVectorLayer, dd, type, description );
124  button->setProperty( "propertyName", propertyName );
125  connect( button, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty() ) );
126  connect( button, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty() ) );
127 
129 }
130 
132 {
133  QgsDataDefinedButton* button = qobject_cast<QgsDataDefinedButton*>( sender() );
134  const QString propertyName( button->property( "propertyName" ).toString() );
135 
136  QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
137  if ( !dd )
138  {
139  dd = new QgsDataDefined();
140  symbolLayer()->setDataDefinedProperty( propertyName, dd );
141  }
142  button->updateDataDefined( dd );
143 
144  emit changed();
145 }
146 
148 {
149  QString label = entryName;
150  if ( entryName == "size" )
151  {
152  label = tr( "Size" );
153  QgsMarkerSymbolLayerV2 * layer = dynamic_cast<QgsMarkerSymbolLayerV2 *>( symbolLayer() );
154  if ( layer )
155  {
156  switch ( layer->scaleMethod() )
157  {
159  label += " (" + tr( "area" ) + ')';
160  break;
162  label += " (" + tr( "diameter" ) + ')';
163  break;
164  }
165  }
166  }
167  return label;
168 }
169 
171  : QgsSymbolLayerV2Widget( parent, vl )
172 {
173  mLayer = nullptr;
174 
175  setupUi( this );
176  mPenWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
178  mDashPatternUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
179 
180  btnChangeColor->setAllowAlpha( true );
181  btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
182  btnChangeColor->setContext( "symbology" );
183 
184  spinOffset->setClearValue( 0.0 );
185 
186  if ( vl && vl->geometryType() != QGis::Polygon )
187  {
188  //draw inside polygon checkbox only makes sense for polygon layers
189  mDrawInsideCheckBox->hide();
190  }
191 
192  //make a temporary symbol for the size assistant preview
193  mAssistantPreviewSymbol = new QgsLineSymbolV2();
194 
195  if ( mVectorLayer )
196  mPenWidthDDBtn->setAssistant( tr( "Width Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
197 
198 
199  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
200  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
201  connect( cboPenStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
202  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
203  connect( cboCapStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
204  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
205 
207 
208  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
209 }
210 
212 {
213  delete mAssistantPreviewSymbol;
214 }
215 
216 void QgsSimpleLineSymbolLayerV2Widget::updateAssistantSymbol()
217 {
218  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
219  {
220  mAssistantPreviewSymbol->deleteSymbolLayer( i );
221  }
222  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
223  QgsDataDefined* ddWidth = mLayer->getDataDefinedProperty( "width" );
224  if ( ddWidth )
225  mAssistantPreviewSymbol->setDataDefinedWidth( *ddWidth );
226 }
227 
228 
230 {
231  if ( !layer || layer->layerType() != "SimpleLine" )
232  return;
233 
234  // layer type is correct, we can do the cast
235  mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>( layer );
236 
237  // set units
238  mPenWidthUnitWidget->blockSignals( true );
239  mPenWidthUnitWidget->setUnit( mLayer->widthUnit() );
240  mPenWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
241  mPenWidthUnitWidget->blockSignals( false );
242  mOffsetUnitWidget->blockSignals( true );
243  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
244  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
245  mOffsetUnitWidget->blockSignals( false );
246  mDashPatternUnitWidget->blockSignals( true );
247  mDashPatternUnitWidget->setUnit( mLayer->customDashPatternUnit() );
248  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
249  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
250  mDashPatternUnitWidget->blockSignals( false );
251 
252  // set values
253  spinWidth->blockSignals( true );
254  spinWidth->setValue( mLayer->width() );
255  spinWidth->blockSignals( false );
256  btnChangeColor->blockSignals( true );
257  btnChangeColor->setColor( mLayer->color() );
258  btnChangeColor->blockSignals( false );
259  spinOffset->blockSignals( true );
260  spinOffset->setValue( mLayer->offset() );
261  spinOffset->blockSignals( false );
262  cboPenStyle->blockSignals( true );
263  cboJoinStyle->blockSignals( true );
264  cboCapStyle->blockSignals( true );
265  cboPenStyle->setPenStyle( mLayer->penStyle() );
266  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
267  cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
268  cboPenStyle->blockSignals( false );
269  cboJoinStyle->blockSignals( false );
270  cboCapStyle->blockSignals( false );
271 
272  //use a custom dash pattern?
273  bool useCustomDashPattern = mLayer->useCustomDashPattern();
274  mChangePatternButton->setEnabled( useCustomDashPattern );
275  label_3->setEnabled( !useCustomDashPattern );
276  cboPenStyle->setEnabled( !useCustomDashPattern );
277  mCustomCheckBox->blockSignals( true );
278  mCustomCheckBox->setCheckState( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
279  mCustomCheckBox->blockSignals( false );
280 
281  //draw inside polygon?
282  bool drawInsidePolygon = mLayer->drawInsidePolygon();
283  mDrawInsideCheckBox->blockSignals( true );
284  mDrawInsideCheckBox->setCheckState( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
285  mDrawInsideCheckBox->blockSignals( false );
286 
288 
296 
297  updateAssistantSymbol();
298 }
299 
301 {
302  return mLayer;
303 }
304 
306 {
307  mLayer->setWidth( spinWidth->value() );
309  emit changed();
310 }
311 
313 {
314  mLayer->setColor( color );
316  emit changed();
317 }
318 
320 {
321  mLayer->setPenStyle( cboPenStyle->penStyle() );
322  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
323  mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
324  emit changed();
325 }
326 
328 {
329  mLayer->setOffset( spinOffset->value() );
331  emit changed();
332 }
333 
335 {
336  bool checked = ( state == Qt::Checked );
337  mChangePatternButton->setEnabled( checked );
338  label_3->setEnabled( !checked );
339  cboPenStyle->setEnabled( !checked );
340 
341  mLayer->setUseCustomDashPattern( checked );
342  emit changed();
343 }
344 
346 {
348  if ( d.exec() == QDialog::Accepted )
349  {
350  mLayer->setCustomDashVector( d.dashDotVector() );
352  emit changed();
353  }
354 }
355 
357 {
358  if ( mLayer )
359  {
360  mLayer->setWidthUnit( mPenWidthUnitWidget->unit() );
361  mLayer->setWidthMapUnitScale( mPenWidthUnitWidget->getMapUnitScale() );
362  emit changed();
363  }
364 }
365 
367 {
368  if ( mLayer )
369  {
370  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
371  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
372  emit changed();
373  }
374 }
375 
377 {
378  if ( mLayer )
379  {
380  mLayer->setCustomDashPatternUnit( mDashPatternUnitWidget->unit() );
381  mLayer->setCustomDashPatternMapUnitScale( mDashPatternUnitWidget->getMapUnitScale() );
382  emit changed();
383  }
384 }
385 
387 {
388  bool checked = ( state == Qt::Checked );
389  mLayer->setDrawInsidePolygon( checked );
390  emit changed();
391 }
392 
393 
395 {
396  if ( !mLayer )
397  {
398  return;
399  }
400  QgsSimpleLineSymbolLayerV2* layerCopy = mLayer->clone();
401  if ( !layerCopy )
402  {
403  return;
404  }
405  layerCopy->setUseCustomDashPattern( true );
406  QIcon buttonIcon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( layerCopy, QgsSymbolV2::MM, mChangePatternButton->iconSize() );
407  mChangePatternButton->setIcon( buttonIcon );
408  delete layerCopy;
409 }
410 
411 
413 
414 
416  : QgsSymbolLayerV2Widget( parent, vl )
417 {
418  mLayer = nullptr;
419 
420  setupUi( this );
423  mOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
424 
425  btnChangeColorFill->setAllowAlpha( true );
426  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
427  btnChangeColorFill->setContext( "symbology" );
428  btnChangeColorFill->setShowNoColor( true );
429  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
430  btnChangeColorBorder->setAllowAlpha( true );
431  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
432  btnChangeColorBorder->setContext( "symbology" );
433  btnChangeColorBorder->setShowNoColor( true );
434  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
435 
436  spinOffsetX->setClearValue( 0.0 );
437  spinOffsetY->setClearValue( 0.0 );
438 
439  //make a temporary symbol for the size assistant preview
440  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
441 
442  if ( mVectorLayer )
443  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
444 
445  QSize size = lstNames->iconSize();
446  double markerSize = DEFAULT_POINT_SIZE * 2;
448  {
449  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( shape, markerSize );
450  lyr->setColor( QColor( 200, 200, 200 ) );
451  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
453  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
454  item->setData( Qt::UserRole, static_cast< int >( shape ) );
456  delete lyr;
457  }
458 
459  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setName() ) );
460  connect( btnChangeColorBorder, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
461  connect( btnChangeColorFill, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorFill( const QColor& ) ) );
462  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
463  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
464  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
465  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
466  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
467  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
468 }
469 
471 {
472  delete mAssistantPreviewSymbol;
473 }
474 
476 {
477  if ( layer->layerType() != "SimpleMarker" )
478  return;
479 
480  // layer type is correct, we can do the cast
481  mLayer = static_cast<QgsSimpleMarkerSymbolLayerV2*>( layer );
482 
483  // set values
485  for ( int i = 0; i < lstNames->count(); ++i )
486  {
487  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
488  {
489  lstNames->setCurrentRow( i );
490  break;
491  }
492  }
493  btnChangeColorBorder->blockSignals( true );
494  btnChangeColorBorder->setColor( mLayer->borderColor() );
495  btnChangeColorBorder->blockSignals( false );
496  btnChangeColorFill->blockSignals( true );
497  btnChangeColorFill->setColor( mLayer->fillColor() );
498  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
499  btnChangeColorFill->blockSignals( false );
500  spinSize->blockSignals( true );
501  spinSize->setValue( mLayer->size() );
502  spinSize->blockSignals( false );
503  spinAngle->blockSignals( true );
504  spinAngle->setValue( mLayer->angle() );
505  spinAngle->blockSignals( false );
506  mOutlineStyleComboBox->blockSignals( true );
507  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
508  mOutlineStyleComboBox->blockSignals( false );
509  mOutlineWidthSpinBox->blockSignals( true );
510  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
511  mOutlineWidthSpinBox->blockSignals( false );
512  cboJoinStyle->blockSignals( true );
513  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
514  cboJoinStyle->blockSignals( false );
515 
516  // without blocking signals the value gets changed because of slot setOffset()
517  spinOffsetX->blockSignals( true );
518  spinOffsetX->setValue( mLayer->offset().x() );
519  spinOffsetX->blockSignals( false );
520  spinOffsetY->blockSignals( true );
521  spinOffsetY->setValue( mLayer->offset().y() );
522  spinOffsetY->blockSignals( false );
523 
524  mSizeUnitWidget->blockSignals( true );
525  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
526  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
527  mSizeUnitWidget->blockSignals( false );
528  mOffsetUnitWidget->blockSignals( true );
529  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
530  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
531  mOffsetUnitWidget->blockSignals( false );
532  mOutlineWidthUnitWidget->blockSignals( true );
533  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
534  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
535  mOutlineWidthUnitWidget->blockSignals( false );
536 
537  //anchor points
538  mHorizontalAnchorComboBox->blockSignals( true );
539  mVerticalAnchorComboBox->blockSignals( true );
540  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
541  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
542  mHorizontalAnchorComboBox->blockSignals( false );
543  mVerticalAnchorComboBox->blockSignals( false );
544 
545  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
546  "<b>pentagon</b>|<b>hexagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
547  "<b>star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
548  "<b>circle</b>|<b>cross</b>|<b>cross_fill</b>|<b>x</b>|"
549  "<b>line</b>|<b>arrowhead</b>|<b>cross2</b>|<b>semi_circle</b>|<b>third_circle</b>|<b>quarter_circle</b>|"
550  "<b>quarter_square</b>|<b>half_square</b>|<b>diagonal_half_square</b>|<b>right_half_triangle</b>|<b>left_half_triangle</b>]" ) );
559  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
560  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
561 
562  updateAssistantSymbol();
563 }
564 
566 {
567  return mLayer;
568 }
569 
571 {
572  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
573  btnChangeColorFill->setEnabled( QgsSimpleMarkerSymbolLayerBase::shapeIsFilled( mLayer->shape() ) );
574  emit changed();
575 }
576 
578 {
579  mLayer->setBorderColor( color );
580  emit changed();
581 }
582 
584 {
585  mLayer->setColor( color );
586  emit changed();
587 }
588 
589 void QgsSimpleMarkerSymbolLayerV2Widget::penJoinStyleChanged()
590 {
591  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
592  emit changed();
593 }
594 
596 {
597  mLayer->setSize( spinSize->value() );
598  emit changed();
599 }
600 
602 {
603  mLayer->setAngle( spinAngle->value() );
604  emit changed();
605 }
606 
608 {
609  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
610  emit changed();
611 }
612 
614 {
615  Q_UNUSED( index );
616 
617  if ( mLayer )
618  {
619  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
620  emit changed();
621  }
622 }
623 
625 {
626  if ( mLayer )
627  {
628  mLayer->setOutlineWidth( d );
629  emit changed();
630  }
631 }
632 
634 {
635  if ( mLayer )
636  {
637  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
638  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
639  emit changed();
640  }
641 }
642 
644 {
645  if ( mLayer )
646  {
647  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
648  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
649  emit changed();
650  }
651 }
652 
654 {
655  if ( mLayer )
656  {
657  mLayer->setOutlineWidthUnit( mOutlineWidthUnitWidget->unit() );
658  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
659  emit changed();
660  }
661 }
662 
664 {
665  if ( mLayer )
666  {
668  emit changed();
669  }
670 }
671 
673 {
674  if ( mLayer )
675  {
677  emit changed();
678  }
679 }
680 
681 void QgsSimpleMarkerSymbolLayerV2Widget::updateAssistantSymbol()
682 {
683  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
684  {
685  mAssistantPreviewSymbol->deleteSymbolLayer( i );
686  }
687  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
688  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
689  if ( ddSize )
690  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
691 }
692 
693 
695 
697  : QgsSymbolLayerV2Widget( parent, vl )
698 {
699  mLayer = nullptr;
700 
701  setupUi( this );
702  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
704 
705  btnChangeColor->setAllowAlpha( true );
706  btnChangeColor->setColorDialogTitle( tr( "Select fill color" ) );
707  btnChangeColor->setContext( "symbology" );
708  btnChangeColor->setShowNoColor( true );
709  btnChangeColor->setNoColorString( tr( "Transparent fill" ) );
710  btnChangeBorderColor->setAllowAlpha( true );
711  btnChangeBorderColor->setColorDialogTitle( tr( "Select border color" ) );
712  btnChangeBorderColor->setContext( "symbology" );
713  btnChangeBorderColor->setShowNoColor( true );
714  btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );
715 
716  spinOffsetX->setClearValue( 0.0 );
717  spinOffsetY->setClearValue( 0.0 );
718 
719  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
720  connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
721  connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
722  connect( spinBorderWidth, SIGNAL( valueChanged( double ) ), this, SLOT( borderWidthChanged() ) );
723  connect( cboBorderStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
724  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
725  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
726  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
727 }
728 
730 {
731  if ( layer->layerType() != "SimpleFill" )
732  return;
733 
734  // layer type is correct, we can do the cast
735  mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>( layer );
736 
737  // set values
738  btnChangeColor->blockSignals( true );
739  btnChangeColor->setColor( mLayer->color() );
740  btnChangeColor->blockSignals( false );
741  cboFillStyle->blockSignals( true );
742  cboFillStyle->setBrushStyle( mLayer->brushStyle() );
743  cboFillStyle->blockSignals( false );
744  btnChangeBorderColor->blockSignals( true );
745  btnChangeBorderColor->setColor( mLayer->borderColor() );
746  btnChangeBorderColor->blockSignals( false );
747  cboBorderStyle->blockSignals( true );
748  cboBorderStyle->setPenStyle( mLayer->borderStyle() );
749  cboBorderStyle->blockSignals( false );
750  spinBorderWidth->blockSignals( true );
751  spinBorderWidth->setValue( mLayer->borderWidth() );
752  spinBorderWidth->blockSignals( false );
753  cboJoinStyle->blockSignals( true );
754  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
755  cboJoinStyle->blockSignals( false );
756  spinOffsetX->blockSignals( true );
757  spinOffsetX->setValue( mLayer->offset().x() );
758  spinOffsetX->blockSignals( false );
759  spinOffsetY->blockSignals( true );
760  spinOffsetY->setValue( mLayer->offset().y() );
761  spinOffsetY->blockSignals( false );
762 
763  mBorderWidthUnitWidget->blockSignals( true );
764  mBorderWidthUnitWidget->setUnit( mLayer->borderWidthUnit() );
765  mBorderWidthUnitWidget->setMapUnitScale( mLayer->borderWidthMapUnitScale() );
766  mBorderWidthUnitWidget->blockSignals( false );
767  mOffsetUnitWidget->blockSignals( true );
768  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
769  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
770  mOffsetUnitWidget->blockSignals( false );
771 
778 
779 }
780 
782 {
783  return mLayer;
784 }
785 
787 {
788  mLayer->setColor( color );
789  emit changed();
790 }
791 
793 {
794  mLayer->setBorderColor( color );
795  emit changed();
796 }
797 
799 {
800  mLayer->setBrushStyle( cboFillStyle->brushStyle() );
801  emit changed();
802 }
803 
805 {
806  mLayer->setBorderWidth( spinBorderWidth->value() );
807  emit changed();
808 }
809 
811 {
812  mLayer->setBorderStyle( cboBorderStyle->penStyle() );
813  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
814  emit changed();
815 }
816 
818 {
819  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
820  emit changed();
821 }
822 
824 {
825  if ( mLayer )
826  {
827  mLayer->setBorderWidthUnit( mBorderWidthUnitWidget->unit() );
828  mLayer->setBorderWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
829  emit changed();
830  }
831 }
832 
834 {
835  if ( mLayer )
836  {
837  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
838  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
839  emit changed();
840  }
841 }
842 
844 
846  : QgsSymbolLayerV2Widget( parent, vl )
847 {
848  mLayer = nullptr;
849 
850  setupUi( this );
853 
854  spinOffsetX->setClearValue( 0.0 );
855  spinOffsetY->setClearValue( 0.0 );
856 
857  //make a temporary symbol for the size assistant preview
858  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
859 
860  if ( mVectorLayer )
861  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
862 
863  QSize size = lstNames->iconSize();
864  double markerSize = DEFAULT_POINT_SIZE * 2;
866  {
868  continue;
869 
870  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( shape, markerSize );
871  lyr->setColor( QColor( 200, 200, 200 ) );
872  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
874  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
875  item->setData( Qt::UserRole, static_cast< int >( shape ) );
877  delete lyr;
878  }
879 
880  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setShape() ) );
881  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
882  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
883  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
884  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
885  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
886 }
887 
889 {
890  delete mAssistantPreviewSymbol;
891 }
892 
894 {
895  if ( layer->layerType() != "FilledMarker" )
896  return;
897 
898  // layer type is correct, we can do the cast
899  mLayer = static_cast<QgsFilledMarkerSymbolLayer*>( layer );
900 
901  // set values
903  for ( int i = 0; i < lstNames->count(); ++i )
904  {
905  if ( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape >( lstNames->item( i )->data( Qt::UserRole ).toInt() ) == shape )
906  {
907  lstNames->setCurrentRow( i );
908  break;
909  }
910  }
911  whileBlocking( spinSize )->setValue( mLayer->size() );
912  whileBlocking( spinAngle )->setValue( mLayer->angle() );
913  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
914  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
915 
916  mSizeUnitWidget->blockSignals( true );
917  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
918  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
919  mSizeUnitWidget->blockSignals( false );
920  mOffsetUnitWidget->blockSignals( true );
921  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
922  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
923  mOffsetUnitWidget->blockSignals( false );
924 
925  //anchor points
926  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
927  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
928 
929  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
930  "<b>pentagon</b>|<b>hexagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
931  "<b>star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
932  "<b>circle</b>|<b>cross</b>|<b>cross_fill</b>|<b>x</b>|"
933  "<b>line</b>|<b>arrowhead</b>|<b>cross2</b>|<b>semi_circle</b>|<b>third_circle</b>|<b>quarter_circle</b>|"
934  "<b>quarter_square</b>|<b>half_square</b>|<b>diagonal_half_square</b>|<b>right_half_triangle</b>|<b>left_half_triangle</b>]" ) );
938  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
939  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
940 
941  updateAssistantSymbol();
942 }
943 
945 {
946  return mLayer;
947 }
948 
949 void QgsFilledMarkerSymbolLayerWidget::setShape()
950 {
951  mLayer->setShape( static_cast< QgsSimpleMarkerSymbolLayerBase::Shape>( lstNames->currentItem()->data( Qt::UserRole ).toInt() ) );
952  emit changed();
953 }
954 
955 void QgsFilledMarkerSymbolLayerWidget::setSize()
956 {
957  mLayer->setSize( spinSize->value() );
958  emit changed();
959 }
960 
961 void QgsFilledMarkerSymbolLayerWidget::setAngle()
962 {
963  mLayer->setAngle( spinAngle->value() );
964  emit changed();
965 }
966 
967 void QgsFilledMarkerSymbolLayerWidget::setOffset()
968 {
969  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
970  emit changed();
971 }
972 
973 void QgsFilledMarkerSymbolLayerWidget::on_mSizeUnitWidget_changed()
974 {
975  if ( mLayer )
976  {
977  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
978  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
979  emit changed();
980  }
981 }
982 
983 void QgsFilledMarkerSymbolLayerWidget::on_mOffsetUnitWidget_changed()
984 {
985  if ( mLayer )
986  {
987  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
988  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
989  emit changed();
990  }
991 }
992 
993 void QgsFilledMarkerSymbolLayerWidget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
994 {
995  if ( mLayer )
996  {
998  emit changed();
999  }
1000 }
1001 
1002 void QgsFilledMarkerSymbolLayerWidget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
1003 {
1004  if ( mLayer )
1005  {
1007  emit changed();
1008  }
1009 }
1010 
1011 void QgsFilledMarkerSymbolLayerWidget::updateAssistantSymbol()
1012 {
1013  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1014  {
1015  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1016  }
1017  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1018  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
1019  if ( ddSize )
1020  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
1021 }
1022 
1023 
1025 
1027  : QgsSymbolLayerV2Widget( parent, vl )
1028 {
1029  mLayer = nullptr;
1030 
1031  setupUi( this );
1032  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1033 
1034  cboGradientColorRamp->setShowGradientOnly( true );
1035  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1036 
1037  btnChangeColor->setAllowAlpha( true );
1038  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1039  btnChangeColor->setContext( "symbology" );
1040  btnChangeColor->setShowNoColor( true );
1041  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1042  btnChangeColor2->setAllowAlpha( true );
1043  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1044  btnChangeColor2->setContext( "symbology" );
1045  btnChangeColor2->setShowNoColor( true );
1046  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1047 
1048  spinOffsetX->setClearValue( 0.0 );
1049  spinOffsetY->setClearValue( 0.0 );
1050 
1051  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1052  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1053  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1054  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
1055  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
1056  connect( cboGradientType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientType( int ) ) );
1057  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
1058  connect( cboGradientSpread, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientSpread( int ) ) );
1059  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1060  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1061  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1062  connect( spinRefPoint1X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1063  connect( spinRefPoint1Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1064  connect( checkRefPoint1Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
1065  connect( spinRefPoint2X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1066  connect( spinRefPoint2Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
1067  connect( checkRefPoint2Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
1068 }
1069 
1071 {
1072  if ( layer->layerType() != "GradientFill" )
1073  return;
1074 
1075  // layer type is correct, we can do the cast
1076  mLayer = static_cast<QgsGradientFillSymbolLayerV2*>( layer );
1077 
1078  // set values
1079  btnChangeColor->blockSignals( true );
1080  btnChangeColor->setColor( mLayer->color() );
1081  btnChangeColor->blockSignals( false );
1082  btnChangeColor2->blockSignals( true );
1083  btnChangeColor2->setColor( mLayer->color2() );
1084  btnChangeColor2->blockSignals( false );
1085 
1087  {
1088  radioTwoColor->setChecked( true );
1089  cboGradientColorRamp->setEnabled( false );
1090  }
1091  else
1092  {
1093  radioColorRamp->setChecked( true );
1094  btnChangeColor->setEnabled( false );
1095  btnChangeColor2->setEnabled( false );
1096  }
1097 
1098  // set source color ramp
1099  if ( mLayer->colorRamp() )
1100  {
1101  cboGradientColorRamp->blockSignals( true );
1102  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1103  cboGradientColorRamp->blockSignals( false );
1104  }
1105 
1106  cboGradientType->blockSignals( true );
1107  switch ( mLayer->gradientType() )
1108  {
1110  cboGradientType->setCurrentIndex( 0 );
1111  break;
1113  cboGradientType->setCurrentIndex( 1 );
1114  break;
1116  cboGradientType->setCurrentIndex( 2 );
1117  break;
1118  }
1119  cboGradientType->blockSignals( false );
1120 
1121  cboCoordinateMode->blockSignals( true );
1122  switch ( mLayer->coordinateMode() )
1123  {
1125  cboCoordinateMode->setCurrentIndex( 1 );
1126  checkRefPoint1Centroid->setEnabled( false );
1127  checkRefPoint2Centroid->setEnabled( false );
1128  break;
1130  default:
1131  cboCoordinateMode->setCurrentIndex( 0 );
1132  break;
1133  }
1134  cboCoordinateMode->blockSignals( false );
1135 
1136  cboGradientSpread->blockSignals( true );
1137  switch ( mLayer->gradientSpread() )
1138  {
1140  cboGradientSpread->setCurrentIndex( 0 );
1141  break;
1143  cboGradientSpread->setCurrentIndex( 1 );
1144  break;
1146  cboGradientSpread->setCurrentIndex( 2 );
1147  break;
1148  }
1149  cboGradientSpread->blockSignals( false );
1150 
1151  spinRefPoint1X->blockSignals( true );
1152  spinRefPoint1X->setValue( mLayer->referencePoint1().x() );
1153  spinRefPoint1X->blockSignals( false );
1154  spinRefPoint1Y->blockSignals( true );
1155  spinRefPoint1Y->setValue( mLayer->referencePoint1().y() );
1156  spinRefPoint1Y->blockSignals( false );
1157  checkRefPoint1Centroid->blockSignals( true );
1158  checkRefPoint1Centroid->setChecked( mLayer->referencePoint1IsCentroid() );
1160  {
1161  spinRefPoint1X->setEnabled( false );
1162  spinRefPoint1Y->setEnabled( false );
1163  }
1164  checkRefPoint1Centroid->blockSignals( false );
1165  spinRefPoint2X->blockSignals( true );
1166  spinRefPoint2X->setValue( mLayer->referencePoint2().x() );
1167  spinRefPoint2X->blockSignals( false );
1168  spinRefPoint2Y->blockSignals( true );
1169  spinRefPoint2Y->setValue( mLayer->referencePoint2().y() );
1170  spinRefPoint2Y->blockSignals( false );
1171  checkRefPoint2Centroid->blockSignals( true );
1172  checkRefPoint2Centroid->setChecked( mLayer->referencePoint2IsCentroid() );
1174  {
1175  spinRefPoint2X->setEnabled( false );
1176  spinRefPoint2Y->setEnabled( false );
1177  }
1178  checkRefPoint2Centroid->blockSignals( false );
1179 
1180  spinOffsetX->blockSignals( true );
1181  spinOffsetX->setValue( mLayer->offset().x() );
1182  spinOffsetX->blockSignals( false );
1183  spinOffsetY->blockSignals( true );
1184  spinOffsetY->setValue( mLayer->offset().y() );
1185  spinOffsetY->blockSignals( false );
1186  mSpinAngle->blockSignals( true );
1187  mSpinAngle->setValue( mLayer->angle() );
1188  mSpinAngle->blockSignals( false );
1189 
1190  mOffsetUnitWidget->blockSignals( true );
1191  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1192  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1193  mOffsetUnitWidget->blockSignals( false );
1194 
1203  registerDataDefinedButton( mRefPoint1CentroidDDBtn, "reference1_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1206  registerDataDefinedButton( mRefPoint2CentroidDDBtn, "reference2_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1207 }
1208 
1210 {
1211  return mLayer;
1212 }
1213 
1215 {
1216  mLayer->setColor( color );
1217  emit changed();
1218 }
1219 
1221 {
1222  mLayer->setColor2( color );
1223  emit changed();
1224 }
1225 
1227 {
1228  if ( radioTwoColor->isChecked() )
1229  {
1231  }
1232  else
1233  {
1235  }
1236  emit changed();
1237 }
1238 
1240 {
1241  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1242  if ( !ramp )
1243  return;
1244 
1245  mLayer->setColorRamp( ramp );
1246  emit changed();
1247 }
1248 
1250 {
1251  switch ( index )
1252  {
1253  case 0:
1255  //set sensible default reference points
1256  spinRefPoint1X->setValue( 0.5 );
1257  spinRefPoint1Y->setValue( 0 );
1258  spinRefPoint2X->setValue( 0.5 );
1259  spinRefPoint2Y->setValue( 1 );
1260  break;
1261  case 1:
1263  //set sensible default reference points
1264  spinRefPoint1X->setValue( 0 );
1265  spinRefPoint1Y->setValue( 0 );
1266  spinRefPoint2X->setValue( 1 );
1267  spinRefPoint2Y->setValue( 1 );
1268  break;
1269  case 2:
1271  spinRefPoint1X->setValue( 0.5 );
1272  spinRefPoint1Y->setValue( 0.5 );
1273  spinRefPoint2X->setValue( 1 );
1274  spinRefPoint2Y->setValue( 1 );
1275  break;
1276  }
1277  emit changed();
1278 }
1279 
1281 {
1282 
1283  switch ( index )
1284  {
1285  case 0:
1286  //feature coordinate mode
1288  //allow choice of centroid reference positions
1289  checkRefPoint1Centroid->setEnabled( true );
1290  checkRefPoint2Centroid->setEnabled( true );
1291  break;
1292  case 1:
1293  //viewport coordinate mode
1295  //disable choice of centroid reference positions
1296  checkRefPoint1Centroid->setChecked( Qt::Unchecked );
1297  checkRefPoint1Centroid->setEnabled( false );
1298  checkRefPoint2Centroid->setChecked( Qt::Unchecked );
1299  checkRefPoint2Centroid->setEnabled( false );
1300  break;
1301  }
1302 
1303  emit changed();
1304 }
1305 
1307 {
1308  switch ( index )
1309  {
1310  case 0:
1312  break;
1313  case 1:
1315  break;
1316  case 2:
1318  break;
1319  }
1320 
1321  emit changed();
1322 }
1323 
1325 {
1326  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1327  emit changed();
1328 }
1329 
1331 {
1332  mLayer->setReferencePoint1( QPointF( spinRefPoint1X->value(), spinRefPoint1Y->value() ) );
1333  mLayer->setReferencePoint1IsCentroid( checkRefPoint1Centroid->isChecked() );
1334  mLayer->setReferencePoint2( QPointF( spinRefPoint2X->value(), spinRefPoint2Y->value() ) );
1335  mLayer->setReferencePoint2IsCentroid( checkRefPoint2Centroid->isChecked() );
1336  emit changed();
1337 }
1338 
1340 {
1341  mLayer->setAngle( value );
1342  emit changed();
1343 }
1344 
1346 {
1347  if ( mLayer )
1348  {
1349  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1350  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1351  emit changed();
1352  }
1353 }
1354 
1356 
1358  : QgsSymbolLayerV2Widget( parent, vl )
1359 {
1360  mLayer = nullptr;
1361 
1362  setupUi( this );
1363  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1364  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1365 
1366  QButtonGroup* group1 = new QButtonGroup( this );
1367  group1->addButton( radioColorRamp );
1368  group1->addButton( radioTwoColor );
1369  QButtonGroup* group2 = new QButtonGroup( this );
1370  group2->addButton( mRadioUseMaxDistance );
1371  group2->addButton( mRadioUseWholeShape );
1372  btnChangeColor->setAllowAlpha( true );
1373  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1374  btnChangeColor->setContext( "symbology" );
1375  btnChangeColor->setShowNoColor( true );
1376  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1377  btnChangeColor2->setAllowAlpha( true );
1378  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1379  btnChangeColor2->setContext( "symbology" );
1380  btnChangeColor2->setShowNoColor( true );
1381  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1382 
1383  spinOffsetX->setClearValue( 0.0 );
1384  spinOffsetY->setClearValue( 0.0 );
1385 
1386  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1387 
1388  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1389  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
1390  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
1391 
1392  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1393  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1394  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1395  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1396  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1397 
1398  connect( mBlurSlider, SIGNAL( valueChanged( int ) ), mSpinBlurRadius, SLOT( setValue( int ) ) );
1399  connect( mSpinBlurRadius, SIGNAL( valueChanged( int ) ), mBlurSlider, SLOT( setValue( int ) ) );
1400 }
1401 
1403 {
1404  if ( layer->layerType() != "ShapeburstFill" )
1405  return;
1406 
1407  // layer type is correct, we can do the cast
1408  mLayer = static_cast<QgsShapeburstFillSymbolLayerV2*>( layer );
1409 
1410  // set values
1411  btnChangeColor->blockSignals( true );
1412  btnChangeColor->setColor( mLayer->color() );
1413  btnChangeColor->blockSignals( false );
1414  btnChangeColor2->blockSignals( true );
1415  btnChangeColor2->setColor( mLayer->color2() );
1416  btnChangeColor2->blockSignals( false );
1417 
1419  {
1420  radioTwoColor->setChecked( true );
1421  cboGradientColorRamp->setEnabled( false );
1422  }
1423  else
1424  {
1425  radioColorRamp->setChecked( true );
1426  btnChangeColor->setEnabled( false );
1427  btnChangeColor2->setEnabled( false );
1428  }
1429 
1430  mSpinBlurRadius->blockSignals( true );
1431  mBlurSlider->blockSignals( true );
1432  mSpinBlurRadius->setValue( mLayer->blurRadius() );
1433  mBlurSlider->setValue( mLayer->blurRadius() );
1434  mSpinBlurRadius->blockSignals( false );
1435  mBlurSlider->blockSignals( false );
1436 
1437  mSpinMaxDistance->blockSignals( true );
1438  mSpinMaxDistance->setValue( mLayer->maxDistance() );
1439  mSpinMaxDistance->blockSignals( false );
1440 
1441  mRadioUseWholeShape->blockSignals( true );
1442  mRadioUseMaxDistance->blockSignals( true );
1443  if ( mLayer->useWholeShape() )
1444  {
1445  mRadioUseWholeShape->setChecked( true );
1446  mSpinMaxDistance->setEnabled( false );
1447  mDistanceUnitWidget->setEnabled( false );
1448  }
1449  else
1450  {
1451  mRadioUseMaxDistance->setChecked( true );
1452  mSpinMaxDistance->setEnabled( true );
1453  mDistanceUnitWidget->setEnabled( true );
1454  }
1455  mRadioUseWholeShape->blockSignals( false );
1456  mRadioUseMaxDistance->blockSignals( false );
1457 
1458  mDistanceUnitWidget->blockSignals( true );
1459  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
1460  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
1461  mDistanceUnitWidget->blockSignals( false );
1462 
1463  mIgnoreRingsCheckBox->blockSignals( true );
1464  mIgnoreRingsCheckBox->setCheckState( mLayer->ignoreRings() ? Qt::Checked : Qt::Unchecked );
1465  mIgnoreRingsCheckBox->blockSignals( false );
1466 
1467  // set source color ramp
1468  if ( mLayer->colorRamp() )
1469  {
1470  cboGradientColorRamp->blockSignals( true );
1471  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1472  cboGradientColorRamp->blockSignals( false );
1473  }
1474 
1475  spinOffsetX->blockSignals( true );
1476  spinOffsetX->setValue( mLayer->offset().x() );
1477  spinOffsetX->blockSignals( false );
1478  spinOffsetY->blockSignals( true );
1479  spinOffsetY->setValue( mLayer->offset().y() );
1480  spinOffsetY->blockSignals( false );
1481  mOffsetUnitWidget->blockSignals( true );
1482  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1483  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1484  mOffsetUnitWidget->blockSignals( false );
1485 
1488  registerDataDefinedButton( mBlurRadiusDDBtn, "blur_radius", QgsDataDefinedButton::Int, tr( "Integer between 0 and 18" ) );
1489  registerDataDefinedButton( mShadeWholeShapeDDBtn, "use_whole_shape", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1492 }
1493 
1495 {
1496  return mLayer;
1497 }
1498 
1500 {
1501  if ( mLayer )
1502  {
1503  mLayer->setColor( color );
1504  emit changed();
1505  }
1506 }
1507 
1509 {
1510  if ( mLayer )
1511  {
1512  mLayer->setColor2( color );
1513  emit changed();
1514  }
1515 }
1516 
1518 {
1519  if ( !mLayer )
1520  {
1521  return;
1522  }
1523 
1524  if ( radioTwoColor->isChecked() )
1525  {
1527  }
1528  else
1529  {
1531  }
1532  emit changed();
1533 }
1534 
1536 {
1537  if ( mLayer )
1538  {
1539  mLayer->setBlurRadius( value );
1540  emit changed();
1541  }
1542 }
1543 
1545 {
1546  if ( mLayer )
1547  {
1548  mLayer->setMaxDistance( value );
1549  emit changed();
1550  }
1551 }
1552 
1554 {
1555  if ( mLayer )
1556  {
1557  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
1558  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
1559  emit changed();
1560  }
1561 }
1562 
1564 {
1565  if ( mLayer )
1566  {
1567  mLayer->setUseWholeShape( value );
1568  mDistanceUnitWidget->setEnabled( !value );
1569  emit changed();
1570  }
1571 }
1572 
1574 {
1575  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1576  if ( !ramp )
1577  return;
1578 
1579  mLayer->setColorRamp( ramp );
1580  emit changed();
1581 }
1582 
1584 {
1585  if ( mLayer )
1586  {
1587  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1588  emit changed();
1589  }
1590 }
1591 
1593 {
1594  if ( mLayer )
1595  {
1596  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1597  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1598  emit changed();
1599  }
1600 }
1601 
1602 
1604 {
1605  bool checked = ( state == Qt::Checked );
1606  mLayer->setIgnoreRings( checked );
1607  emit changed();
1608 }
1609 
1611 
1613  : QgsSymbolLayerV2Widget( parent, vl )
1614 {
1615  mLayer = nullptr;
1616 
1617  setupUi( this );
1618  mIntervalUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1619  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1620  mOffsetAlongLineUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1621 
1622  spinOffset->setClearValue( 0.0 );
1623 
1624  connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
1625  connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
1626  connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
1627  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1628  connect( radInterval, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1629  connect( radVertex, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1630  connect( radVertexLast, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1631  connect( radVertexFirst, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1632  connect( radCentralPoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1633  connect( radCurvePoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1634 }
1635 
1637 {
1638  if ( layer->layerType() != "MarkerLine" )
1639  return;
1640 
1641  // layer type is correct, we can do the cast
1642  mLayer = static_cast<QgsMarkerLineSymbolLayerV2*>( layer );
1643 
1644  // set values
1645  spinInterval->blockSignals( true );
1646  spinInterval->setValue( mLayer->interval() );
1647  spinInterval->blockSignals( false );
1648  mSpinOffsetAlongLine->blockSignals( true );
1649  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
1650  mSpinOffsetAlongLine->blockSignals( false );
1651  chkRotateMarker->blockSignals( true );
1652  chkRotateMarker->setChecked( mLayer->rotateMarker() );
1653  chkRotateMarker->blockSignals( false );
1654  spinOffset->blockSignals( true );
1655  spinOffset->setValue( mLayer->offset() );
1656  spinOffset->blockSignals( false );
1658  radInterval->setChecked( true );
1660  radVertex->setChecked( true );
1662  radVertexLast->setChecked( true );
1664  radCentralPoint->setChecked( true );
1666  radCurvePoint->setChecked( true );
1667  else
1668  radVertexFirst->setChecked( true );
1669 
1670  // set units
1671  mIntervalUnitWidget->blockSignals( true );
1672  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
1673  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
1674  mIntervalUnitWidget->blockSignals( false );
1675  mOffsetUnitWidget->blockSignals( true );
1676  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1677  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1678  mOffsetUnitWidget->blockSignals( false );
1679  mOffsetAlongLineUnitWidget->blockSignals( true );
1680  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
1681  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
1682  mOffsetAlongLineUnitWidget->blockSignals( false );
1683 
1684  setPlacement(); // update gui
1685 
1688  registerDataDefinedButton( mPlacementDDBtn, "placement", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>vertex</b>|<b>lastvertex</b>|<b>firstvertex</b>|<b>centerpoint</b>]" ) );
1689  registerDataDefinedButton( mOffsetAlongLineDDBtn, "offset_along_line", QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
1690 }
1691 
1693 {
1694  return mLayer;
1695 }
1696 
1698 {
1699  mLayer->setInterval( val );
1700  emit changed();
1701 }
1702 
1704 {
1705  mLayer->setOffsetAlongLine( val );
1706  emit changed();
1707 }
1708 
1710 {
1711  mLayer->setRotateMarker( chkRotateMarker->isChecked() );
1712  emit changed();
1713 }
1714 
1716 {
1717  mLayer->setOffset( spinOffset->value() );
1718  emit changed();
1719 }
1720 
1722 {
1723  bool interval = radInterval->isChecked();
1724  spinInterval->setEnabled( interval );
1725  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
1726  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
1727  if ( radInterval->isChecked() )
1729  else if ( radVertex->isChecked() )
1731  else if ( radVertexLast->isChecked() )
1733  else if ( radVertexFirst->isChecked() )
1735  else if ( radCurvePoint->isChecked() )
1737  else
1739 
1740  emit changed();
1741 }
1742 
1744 {
1745  if ( mLayer )
1746  {
1747  mLayer->setIntervalUnit( mIntervalUnitWidget->unit() );
1748  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
1749  emit changed();
1750  }
1751 }
1752 
1754 {
1755  if ( mLayer )
1756  {
1757  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1758  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1759  emit changed();
1760  }
1761 }
1762 
1764 {
1765  if ( mLayer )
1766  {
1767  mLayer->setOffsetAlongLineUnit( mOffsetAlongLineUnitWidget->unit() );
1768  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
1769  }
1770  emit changed();
1771 }
1772 
1774 
1775 
1777  : QgsSymbolLayerV2Widget( parent, vl )
1778 {
1779  mLayer = nullptr;
1780 
1781  setupUi( this );
1783  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1784  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1785  viewGroups->setHeaderHidden( true );
1786  mChangeColorButton->setAllowAlpha( true );
1787  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
1788  mChangeColorButton->setContext( "symbology" );
1789  mChangeBorderColorButton->setAllowAlpha( true );
1790  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
1791  mChangeBorderColorButton->setContext( "symbology" );
1792 
1793  spinOffsetX->setClearValue( 0.0 );
1794  spinOffsetY->setClearValue( 0.0 );
1795 
1796  populateList();
1797 
1798  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1799  connect( viewGroups->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
1800  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
1801  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
1802  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1803  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1804  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
1805 
1806  //make a temporary symbol for the size assistant preview
1807  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
1808  if ( mVectorLayer )
1809  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
1810 }
1811 
1813 {
1814  delete mAssistantPreviewSymbol;
1815 }
1816 
1817 #include <QTime>
1818 #include <QAbstractListModel>
1819 #include <QPixmapCache>
1820 #include <QStyle>
1821 
1822 
1824 {
1825  QAbstractItemModel* oldModel = viewGroups->model();
1827  viewGroups->setModel( g );
1828  delete oldModel;
1829 
1830  // Set the tree expanded at the first level
1831  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
1832  for ( int i = 0; i < rows; i++ )
1833  {
1834  viewGroups->setExpanded( g->indexFromItem( g->item( i ) ), true );
1835  }
1836 
1837  // Initally load the icons in the List view without any grouping
1838  oldModel = viewImages->model();
1839  QgsSvgSelectorListModel* m = new QgsSvgSelectorListModel( viewImages );
1840  viewImages->setModel( m );
1841  delete oldModel;
1842 }
1843 
1845 {
1846  QString path = idx.data( Qt::UserRole + 1 ).toString();
1847 
1848  QAbstractItemModel* oldModel = viewImages->model();
1849  QgsSvgSelectorListModel* m = new QgsSvgSelectorListModel( viewImages, path );
1850  viewImages->setModel( m );
1851  delete oldModel;
1852 
1853  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1854 }
1855 
1857 {
1858  if ( !layer )
1859  {
1860  return;
1861  }
1862 
1863  //activate gui for svg parameters only if supported by the svg file
1864  bool hasFillParam, hasFillOpacityParam, hasOutlineParam, hasOutlineWidthParam, hasOutlineOpacityParam;
1865  QColor defaultFill, defaultOutline;
1866  double defaultOutlineWidth, defaultFillOpacity, defaultOutlineOpacity;
1867  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultOutlineColor, hasDefaultOutlineWidth, hasDefaultOutlineOpacity;
1868  QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, hasDefaultFillColor, defaultFill,
1869  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
1870  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
1871  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth,
1872  hasOutlineOpacityParam, hasDefaultOutlineOpacity, defaultOutlineOpacity );
1873  mChangeColorButton->setEnabled( hasFillParam );
1874  mChangeColorButton->setAllowAlpha( hasFillOpacityParam );
1875  mChangeBorderColorButton->setEnabled( hasOutlineParam );
1876  mChangeBorderColorButton->setAllowAlpha( hasOutlineOpacityParam );
1877  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
1878 
1879  if ( hasFillParam )
1880  {
1881  QColor fill = layer->fillColor();
1882  double existingOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
1883  if ( hasDefaultFillColor )
1884  {
1885  fill = defaultFill;
1886  }
1887  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : existingOpacity );
1888  mChangeColorButton->setColor( fill );
1889  }
1890  if ( hasOutlineParam )
1891  {
1892  QColor outline = layer->outlineColor();
1893  double existingOpacity = hasOutlineOpacityParam ? outline.alphaF() : 1.0;
1894  if ( hasDefaultOutlineColor )
1895  {
1896  outline = defaultOutline;
1897  }
1898  outline.setAlphaF( hasDefaultOutlineOpacity ? defaultOutlineOpacity : existingOpacity );
1899  mChangeBorderColorButton->setColor( outline );
1900  }
1901 
1902  mFileLineEdit->blockSignals( true );
1903  mFileLineEdit->setText( layer->path() );
1904  mFileLineEdit->blockSignals( false );
1905 
1906  mBorderWidthSpinBox->blockSignals( true );
1907  mBorderWidthSpinBox->setValue( hasDefaultOutlineWidth ? defaultOutlineWidth : layer->outlineWidth() );
1908  mBorderWidthSpinBox->blockSignals( false );
1909 }
1910 
1911 void QgsSvgMarkerSymbolLayerV2Widget::updateAssistantSymbol()
1912 {
1913  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1914  {
1915  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1916  }
1917  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1918  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
1919  if ( ddSize )
1920  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
1921 }
1922 
1923 
1925 {
1926  if ( !layer )
1927  {
1928  return;
1929  }
1930 
1931  if ( layer->layerType() != "SvgMarker" )
1932  return;
1933 
1934  // layer type is correct, we can do the cast
1935  mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>( layer );
1936 
1937  // set values
1938 
1939  QAbstractItemModel* m = viewImages->model();
1940  QItemSelectionModel* selModel = viewImages->selectionModel();
1941  for ( int i = 0; i < m->rowCount(); i++ )
1942  {
1943  QModelIndex idx( m->index( i, 0 ) );
1944  if ( m->data( idx ).toString() == mLayer->path() )
1945  {
1946  selModel->select( idx, QItemSelectionModel::SelectCurrent );
1947  selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent );
1948  setName( idx );
1949  break;
1950  }
1951  }
1952 
1953  spinSize->blockSignals( true );
1954  spinSize->setValue( mLayer->size() );
1955  spinSize->blockSignals( false );
1956  spinAngle->blockSignals( true );
1957  spinAngle->setValue( mLayer->angle() );
1958  spinAngle->blockSignals( false );
1959 
1960  // without blocking signals the value gets changed because of slot setOffset()
1961  spinOffsetX->blockSignals( true );
1962  spinOffsetX->setValue( mLayer->offset().x() );
1963  spinOffsetX->blockSignals( false );
1964  spinOffsetY->blockSignals( true );
1965  spinOffsetY->setValue( mLayer->offset().y() );
1966  spinOffsetY->blockSignals( false );
1967 
1968  mSizeUnitWidget->blockSignals( true );
1969  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
1970  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
1971  mSizeUnitWidget->blockSignals( false );
1972  mBorderWidthUnitWidget->blockSignals( true );
1973  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
1974  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
1975  mBorderWidthUnitWidget->blockSignals( false );
1976  mOffsetUnitWidget->blockSignals( true );
1977  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1978  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1979  mOffsetUnitWidget->blockSignals( false );
1980 
1981  //anchor points
1982  mHorizontalAnchorComboBox->blockSignals( true );
1983  mVerticalAnchorComboBox->blockSignals( true );
1984  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1985  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
1986  mHorizontalAnchorComboBox->blockSignals( false );
1987  mVerticalAnchorComboBox->blockSignals( false );
1988 
1989  setGuiForSvg( mLayer );
1990 
1998  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
1999  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
2000 
2001  updateAssistantSymbol();
2002 }
2003 
2005 {
2006  return mLayer;
2007 }
2008 
2010 {
2011  QString name = idx.data( Qt::UserRole ).toString();
2012  mLayer->setPath( name );
2013  mFileLineEdit->setText( name );
2014 
2015  setGuiForSvg( mLayer );
2016  emit changed();
2017 }
2018 
2020 {
2021  mLayer->setSize( spinSize->value() );
2022  emit changed();
2023 }
2024 
2026 {
2027  mLayer->setAngle( spinAngle->value() );
2028  emit changed();
2029 }
2030 
2032 {
2033  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2034  emit changed();
2035 }
2036 
2038 {
2039  QSettings s;
2040  QString file = QFileDialog::getOpenFileName( nullptr,
2041  tr( "Select SVG file" ),
2042  s.value( "/UI/lastSVGMarkerDir", QDir::homePath() ).toString(),
2043  tr( "SVG files" ) + " (*.svg)" );
2044  QFileInfo fi( file );
2045  if ( file.isEmpty() || !fi.exists() )
2046  {
2047  return;
2048  }
2049  mFileLineEdit->setText( file );
2050  mLayer->setPath( file );
2051  s.setValue( "/UI/lastSVGMarkerDir", fi.absolutePath() );
2052  setGuiForSvg( mLayer );
2053  emit changed();
2054 }
2055 
2057 {
2058  if ( !QFileInfo( text ).exists() )
2059  {
2060  return;
2061  }
2062  mLayer->setPath( text );
2063  setGuiForSvg( mLayer );
2064  emit changed();
2065 }
2066 
2068 {
2069  if ( !QFileInfo( mFileLineEdit->text() ).exists() )
2070  {
2071  QUrl url( mFileLineEdit->text() );
2072  if ( !url.isValid() )
2073  {
2074  return;
2075  }
2076  }
2077 
2078  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2079  mLayer->setPath( mFileLineEdit->text() );
2081 
2082  setGuiForSvg( mLayer );
2083  emit changed();
2084 }
2085 
2087 {
2088  if ( !mLayer )
2089  {
2090  return;
2091  }
2092 
2093  mLayer->setFillColor( color );
2094  emit changed();
2095 }
2096 
2098 {
2099  if ( !mLayer )
2100  {
2101  return;
2102  }
2103 
2104  mLayer->setOutlineColor( color );
2105  emit changed();
2106 }
2107 
2109 {
2110  if ( mLayer )
2111  {
2112  mLayer->setOutlineWidth( d );
2113  emit changed();
2114  }
2115 }
2116 
2118 {
2119  if ( mLayer )
2120  {
2121  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2122  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2123  emit changed();
2124  }
2125 }
2126 
2128 {
2129  if ( mLayer )
2130  {
2131  mLayer->setOutlineWidthUnit( mBorderWidthUnitWidget->unit() );
2132  mLayer->setOutlineWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
2133  emit changed();
2134  }
2135 }
2136 
2138 {
2139  if ( mLayer )
2140  {
2141  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2142  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2143  emit changed();
2144  }
2145 }
2146 
2148 {
2149  if ( mLayer )
2150  {
2152  emit changed();
2153  }
2154 }
2155 
2157 {
2158  if ( mLayer )
2159  {
2161  emit changed();
2162  }
2163 }
2164 
2166 
2168 {
2169  mLayer = nullptr;
2170  setupUi( this );
2171  mTextureWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2172  mSvgOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2173  mSvgTreeView->setHeaderHidden( true );
2174  insertIcons();
2175 
2176  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
2177  mChangeColorButton->setContext( "symbology" );
2178  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
2179  mChangeBorderColorButton->setContext( "symbology" );
2180 
2181  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2182  connect( mSvgTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
2183 }
2184 
2186 {
2187  if ( !layer )
2188  {
2189  return;
2190  }
2191 
2192  if ( layer->layerType() != "SVGFill" )
2193  {
2194  return;
2195  }
2196 
2197  mLayer = dynamic_cast<QgsSVGFillSymbolLayer*>( layer );
2198  if ( mLayer )
2199  {
2200  double width = mLayer->patternWidth();
2201  mTextureWidthSpinBox->blockSignals( true );
2202  mTextureWidthSpinBox->setValue( width );
2203  mTextureWidthSpinBox->blockSignals( false );
2204  mSVGLineEdit->setText( mLayer->svgFilePath() );
2205  mRotationSpinBox->blockSignals( true );
2206  mRotationSpinBox->setValue( mLayer->angle() );
2207  mRotationSpinBox->blockSignals( false );
2208  mTextureWidthUnitWidget->blockSignals( true );
2209  mTextureWidthUnitWidget->setUnit( mLayer->patternWidthUnit() );
2210  mTextureWidthUnitWidget->setMapUnitScale( mLayer->patternWidthMapUnitScale() );
2211  mTextureWidthUnitWidget->blockSignals( false );
2212  mSvgOutlineWidthUnitWidget->blockSignals( true );
2213  mSvgOutlineWidthUnitWidget->setUnit( mLayer->svgOutlineWidthUnit() );
2214  mSvgOutlineWidthUnitWidget->setMapUnitScale( mLayer->svgOutlineWidthMapUnitScale() );
2215  mSvgOutlineWidthUnitWidget->blockSignals( false );
2216  mChangeColorButton->blockSignals( true );
2217  mChangeColorButton->setColor( mLayer->svgFillColor() );
2218  mChangeColorButton->blockSignals( false );
2219  mChangeBorderColorButton->blockSignals( true );
2220  mChangeBorderColorButton->setColor( mLayer->svgOutlineColor() );
2221  mChangeBorderColorButton->blockSignals( false );
2222  mBorderWidthSpinBox->blockSignals( true );
2223  mBorderWidthSpinBox->setValue( mLayer->svgOutlineWidth() );
2224  mBorderWidthSpinBox->blockSignals( false );
2225  }
2226  updateParamGui( false );
2227 
2234 }
2235 
2237 {
2238  return mLayer;
2239 }
2240 
2241 void QgsSVGFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2242 {
2243  QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select SVG texture file" ), QDir::homePath(), tr( "SVG file" ) + " (*.svg);;" + tr( "All files" ) + " (*.*)" );
2244  if ( !filePath.isNull() )
2245  {
2246  mSVGLineEdit->setText( filePath );
2247  emit changed();
2248  }
2249 }
2250 
2251 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthSpinBox_valueChanged( double d )
2252 {
2253  if ( mLayer )
2254  {
2255  mLayer->setPatternWidth( d );
2256  emit changed();
2257  }
2258 }
2259 
2260 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_textEdited( const QString & text )
2261 {
2262  if ( !mLayer )
2263  {
2264  return;
2265  }
2266 
2267  QFileInfo fi( text );
2268  if ( !fi.exists() )
2269  {
2270  return;
2271  }
2272  mLayer->setSvgFilePath( text );
2273  updateParamGui();
2274  emit changed();
2275 }
2276 
2277 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_editingFinished()
2278 {
2279  if ( !mLayer )
2280  {
2281  return;
2282  }
2283 
2284  QFileInfo fi( mSVGLineEdit->text() );
2285  if ( !fi.exists() )
2286  {
2287  QUrl url( mSVGLineEdit->text() );
2288  if ( !url.isValid() )
2289  {
2290  return;
2291  }
2292  }
2293 
2294  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2295  mLayer->setSvgFilePath( mSVGLineEdit->text() );
2297 
2298  updateParamGui();
2299  emit changed();
2300 }
2301 
2302 void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex& item )
2303 {
2304  QString file = item.data( Qt::UserRole ).toString();
2305  mLayer->setSvgFilePath( file );
2306  mSVGLineEdit->setText( file );
2307 
2308  updateParamGui();
2309  emit changed();
2310 }
2311 
2313 {
2314  QAbstractItemModel* oldModel = mSvgTreeView->model();
2315  QgsSvgSelectorGroupsModel* g = new QgsSvgSelectorGroupsModel( mSvgTreeView );
2316  mSvgTreeView->setModel( g );
2317  delete oldModel;
2318 
2319  // Set the tree expanded at the first level
2320  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2321  for ( int i = 0; i < rows; i++ )
2322  {
2323  mSvgTreeView->setExpanded( g->indexFromItem( g->item( i ) ), true );
2324  }
2325 
2326  oldModel = mSvgListView->model();
2327  QgsSvgSelectorListModel* m = new QgsSvgSelectorListModel( mSvgListView );
2328  mSvgListView->setModel( m );
2329  delete oldModel;
2330 }
2331 
2332 void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
2333 {
2334  QString path = idx.data( Qt::UserRole + 1 ).toString();
2335 
2336  QAbstractItemModel* oldModel = mSvgListView->model();
2337  QgsSvgSelectorListModel* m = new QgsSvgSelectorListModel( mSvgListView, path );
2338  mSvgListView->setModel( m );
2339  delete oldModel;
2340 
2341  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2342 }
2343 
2344 
2345 void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2346 {
2347  if ( mLayer )
2348  {
2349  mLayer->setAngle( d );
2350  emit changed();
2351  }
2352 }
2353 
2355 {
2356  //activate gui for svg parameters only if supported by the svg file
2357  bool hasFillParam, hasFillOpacityParam, hasOutlineParam, hasOutlineWidthParam, hasOutlineOpacityParam;
2358  QColor defaultFill, defaultOutline;
2359  double defaultOutlineWidth, defaultFillOpacity, defaultOutlineOpacity;
2360  bool hasDefaultFillColor, hasDefaultFillOpacity, hasDefaultOutlineColor, hasDefaultOutlineWidth, hasDefaultOutlineOpacity;
2361  QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, hasDefaultFillColor, defaultFill,
2362  hasFillOpacityParam, hasDefaultFillOpacity, defaultFillOpacity,
2363  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
2364  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth,
2365  hasOutlineOpacityParam, hasDefaultOutlineOpacity, defaultOutlineOpacity );
2366  if ( resetValues )
2367  {
2368  QColor fill = mChangeColorButton->color();
2369  double newOpacity = hasFillOpacityParam ? fill.alphaF() : 1.0;
2370  if ( hasDefaultFillColor )
2371  {
2372  fill = defaultFill;
2373  }
2374  fill.setAlphaF( hasDefaultFillOpacity ? defaultFillOpacity : newOpacity );
2375  mChangeColorButton->setColor( fill );
2376  }
2377  mChangeColorButton->setEnabled( hasFillParam );
2378  mChangeColorButton->setAllowAlpha( hasFillOpacityParam );
2379  if ( resetValues )
2380  {
2381  QColor outline = mChangeBorderColorButton->color();
2382  double newOpacity = hasOutlineOpacityParam ? outline.alphaF() : 1.0;
2383  if ( hasDefaultOutlineColor )
2384  {
2385  outline = defaultOutline;
2386  }
2387  outline.setAlphaF( hasDefaultOutlineOpacity ? defaultOutlineOpacity : newOpacity );
2388  mChangeBorderColorButton->setColor( outline );
2389  }
2390  mChangeBorderColorButton->setEnabled( hasOutlineParam );
2391  mChangeBorderColorButton->setAllowAlpha( hasOutlineOpacityParam );
2392  if ( hasDefaultOutlineWidth && resetValues )
2393  {
2394  mBorderWidthSpinBox->setValue( defaultOutlineWidth );
2395  }
2396  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
2397 }
2398 
2399 void QgsSVGFillSymbolLayerWidget::on_mChangeColorButton_colorChanged( const QColor& color )
2400 {
2401  if ( !mLayer )
2402  {
2403  return;
2404  }
2405 
2406  mLayer->setSvgFillColor( color );
2407  emit changed();
2408 }
2409 
2410 void QgsSVGFillSymbolLayerWidget::on_mChangeBorderColorButton_colorChanged( const QColor& color )
2411 {
2412  if ( !mLayer )
2413  {
2414  return;
2415  }
2416 
2417  mLayer->setSvgOutlineColor( color );
2418  emit changed();
2419 }
2420 
2421 void QgsSVGFillSymbolLayerWidget::on_mBorderWidthSpinBox_valueChanged( double d )
2422 {
2423  if ( mLayer )
2424  {
2425  mLayer->setSvgOutlineWidth( d );
2426  emit changed();
2427  }
2428 }
2429 
2430 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthUnitWidget_changed()
2431 {
2432  if ( mLayer )
2433  {
2434  mLayer->setPatternWidthUnit( mTextureWidthUnitWidget->unit() );
2435  mLayer->setPatternWidthMapUnitScale( mTextureWidthUnitWidget->getMapUnitScale() );
2436  emit changed();
2437  }
2438 }
2439 
2440 void QgsSVGFillSymbolLayerWidget::on_mSvgOutlineWidthUnitWidget_changed()
2441 {
2442  if ( mLayer )
2443  {
2444  mLayer->setSvgOutlineWidthUnit( mSvgOutlineWidthUnitWidget->unit() );
2445  mLayer->setSvgOutlineWidthMapUnitScale( mSvgOutlineWidthUnitWidget->getMapUnitScale() );
2446  emit changed();
2447  }
2448 }
2449 
2451 
2453  QgsSymbolLayerV2Widget( parent, vl ), mLayer( nullptr )
2454 {
2455  setupUi( this );
2456  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2457  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2458  mOffsetSpinBox->setClearValue( 0 );
2459 }
2460 
2462 {
2463  if ( layer->layerType() != "LinePatternFill" )
2464  {
2465  return;
2466  }
2467 
2468  QgsLinePatternFillSymbolLayer* patternLayer = static_cast<QgsLinePatternFillSymbolLayer*>( layer );
2469  if ( patternLayer )
2470  {
2471  mLayer = patternLayer;
2472  mAngleSpinBox->blockSignals( true );
2473  mAngleSpinBox->setValue( mLayer->lineAngle() );
2474  mAngleSpinBox->blockSignals( false );
2475  mDistanceSpinBox->blockSignals( true );
2476  mDistanceSpinBox->setValue( mLayer->distance() );
2477  mDistanceSpinBox->blockSignals( false );
2478  mOffsetSpinBox->blockSignals( true );
2479  mOffsetSpinBox->setValue( mLayer->offset() );
2480  mOffsetSpinBox->blockSignals( false );
2481 
2482  //units
2483  mDistanceUnitWidget->blockSignals( true );
2484  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
2485  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
2486  mDistanceUnitWidget->blockSignals( false );
2487  mOffsetUnitWidget->blockSignals( true );
2488  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2489  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2490  mOffsetUnitWidget->blockSignals( false );
2491  }
2492 
2495 }
2496 
2498 {
2499  return mLayer;
2500 }
2501 
2502 void QgsLinePatternFillSymbolLayerWidget::on_mAngleSpinBox_valueChanged( double d )
2503 {
2504  if ( mLayer )
2505  {
2506  mLayer->setLineAngle( d );
2507  emit changed();
2508  }
2509 }
2510 
2511 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
2512 {
2513  if ( mLayer )
2514  {
2515  mLayer->setDistance( d );
2516  emit changed();
2517  }
2518 }
2519 
2520 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetSpinBox_valueChanged( double d )
2521 {
2522  if ( mLayer )
2523  {
2524  mLayer->setOffset( d );
2525  emit changed();
2526  }
2527 }
2528 
2529 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceUnitWidget_changed()
2530 {
2531  if ( mLayer )
2532  {
2533  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
2534  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
2535  emit changed();
2536  }
2537 }
2538 
2539 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2540 {
2541  if ( mLayer )
2542  {
2543  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2544  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2545  emit changed();
2546  }
2547 }
2548 
2550 
2552  QgsSymbolLayerV2Widget( parent, vl ), mLayer( nullptr )
2553 {
2554  setupUi( this );
2555  mHorizontalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2556  mVerticalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2557  mHorizontalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2558  mVerticalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2559 }
2560 
2561 
2563 {
2564  if ( !layer || layer->layerType() != "PointPatternFill" )
2565  {
2566  return;
2567  }
2568 
2569  mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
2570  mHorizontalDistanceSpinBox->blockSignals( true );
2571  mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
2572  mHorizontalDistanceSpinBox->blockSignals( false );
2573  mVerticalDistanceSpinBox->blockSignals( true );
2574  mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
2575  mVerticalDistanceSpinBox->blockSignals( false );
2576  mHorizontalDisplacementSpinBox->blockSignals( true );
2577  mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
2578  mHorizontalDisplacementSpinBox->blockSignals( false );
2579  mVerticalDisplacementSpinBox->blockSignals( true );
2580  mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
2581  mVerticalDisplacementSpinBox->blockSignals( false );
2582 
2583  mHorizontalDistanceUnitWidget->blockSignals( true );
2584  mHorizontalDistanceUnitWidget->setUnit( mLayer->distanceXUnit() );
2585  mHorizontalDistanceUnitWidget->setMapUnitScale( mLayer->distanceXMapUnitScale() );
2586  mHorizontalDistanceUnitWidget->blockSignals( false );
2587  mVerticalDistanceUnitWidget->blockSignals( true );
2588  mVerticalDistanceUnitWidget->setUnit( mLayer->distanceYUnit() );
2589  mVerticalDistanceUnitWidget->setMapUnitScale( mLayer->distanceYMapUnitScale() );
2590  mVerticalDistanceUnitWidget->blockSignals( false );
2591  mHorizontalDisplacementUnitWidget->blockSignals( true );
2592  mHorizontalDisplacementUnitWidget->setUnit( mLayer->displacementXUnit() );
2593  mHorizontalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementXMapUnitScale() );
2594  mHorizontalDisplacementUnitWidget->blockSignals( false );
2595  mVerticalDisplacementUnitWidget->blockSignals( true );
2596  mVerticalDisplacementUnitWidget->setUnit( mLayer->displacementYUnit() );
2597  mVerticalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementYMapUnitScale() );
2598  mVerticalDisplacementUnitWidget->blockSignals( false );
2599 
2600  registerDataDefinedButton( mHorizontalDistanceDDBtn, "distance_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2602  registerDataDefinedButton( mHorizontalDisplacementDDBtn, "displacement_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2603  registerDataDefinedButton( mVerticalDisplacementDDBtn, "displacement_y", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2604 }
2605 
2607 {
2608  return mLayer;
2609 }
2610 
2611 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged( double d )
2612 {
2613  if ( mLayer )
2614  {
2615  mLayer->setDistanceX( d );
2616  emit changed();
2617  }
2618 }
2619 
2620 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged( double d )
2621 {
2622  if ( mLayer )
2623  {
2624  mLayer->setDistanceY( d );
2625  emit changed();
2626  }
2627 }
2628 
2629 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged( double d )
2630 {
2631  if ( mLayer )
2632  {
2633  mLayer->setDisplacementX( d );
2634  emit changed();
2635  }
2636 }
2637 
2638 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged( double d )
2639 {
2640  if ( mLayer )
2641  {
2642  mLayer->setDisplacementY( d );
2643  emit changed();
2644  }
2645 }
2646 
2647 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceUnitWidget_changed()
2648 {
2649  if ( mLayer )
2650  {
2651  mLayer->setDistanceXUnit( mHorizontalDistanceUnitWidget->unit() );
2652  mLayer->setDistanceXMapUnitScale( mHorizontalDistanceUnitWidget->getMapUnitScale() );
2653  emit changed();
2654  }
2655 }
2656 
2657 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceUnitWidget_changed()
2658 {
2659  if ( mLayer )
2660  {
2661  mLayer->setDistanceYUnit( mVerticalDistanceUnitWidget->unit() );
2662  mLayer->setDistanceYMapUnitScale( mVerticalDistanceUnitWidget->getMapUnitScale() );
2663  emit changed();
2664  }
2665 }
2666 
2667 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementUnitWidget_changed()
2668 {
2669  if ( mLayer )
2670  {
2671  mLayer->setDisplacementXUnit( mHorizontalDisplacementUnitWidget->unit() );
2672  mLayer->setDisplacementXMapUnitScale( mHorizontalDisplacementUnitWidget->getMapUnitScale() );
2673  emit changed();
2674  }
2675 }
2676 
2677 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementUnitWidget_changed()
2678 {
2679  if ( mLayer )
2680  {
2681  mLayer->setDisplacementYUnit( mVerticalDisplacementUnitWidget->unit() );
2682  mLayer->setDisplacementYMapUnitScale( mVerticalDisplacementUnitWidget->getMapUnitScale() );
2683  emit changed();
2684  }
2685 }
2686 
2688 
2690  : QgsSymbolLayerV2Widget( parent, vl )
2691 {
2692  mLayer = nullptr;
2693 
2694  setupUi( this );
2696  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2697  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2699  scrollArea->setWidget( widgetChar );
2700 
2701  btnColor->setAllowAlpha( true );
2702  btnColor->setColorDialogTitle( tr( "Select symbol fill color" ) );
2703  btnColor->setContext( "symbology" );
2704  btnBorderColor->setAllowAlpha( true );
2705  btnBorderColor->setColorDialogTitle( tr( "Select symbol outline color" ) );
2706  btnBorderColor->setContext( "symbology" );
2707 
2708  spinOffsetX->setClearValue( 0.0 );
2709  spinOffsetY->setClearValue( 0.0 );
2710 
2711  //make a temporary symbol for the size assistant preview
2712  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
2713 
2714  if ( mVectorLayer )
2715  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
2716 
2717  connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
2718  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
2719  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
2720  connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
2721  connect( btnBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
2722  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
2723  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle( double ) ) );
2724  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2725  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2726  connect( widgetChar, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
2727  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
2728 }
2729 
2731 {
2732  delete mAssistantPreviewSymbol;
2733 }
2734 
2736 {
2737  if ( layer->layerType() != "FontMarker" )
2738  return;
2739 
2740  // layer type is correct, we can do the cast
2741  mLayer = static_cast<QgsFontMarkerSymbolLayerV2*>( layer );
2742 
2743  QFont layerFont( mLayer->fontFamily() );
2744  // set values
2745  whileBlocking( cboFont )->setCurrentFont( layerFont );
2746  whileBlocking( spinSize )->setValue( mLayer->size() );
2747  whileBlocking( btnColor )->setColor( mLayer->color() );
2748  whileBlocking( btnBorderColor )->setColor( mLayer->outlineColor() );
2749  whileBlocking( mBorderWidthSpinBox )->setValue( mLayer->outlineWidth() );
2750  whileBlocking( spinAngle )->setValue( mLayer->angle() );
2751 
2752  widgetChar->blockSignals( true );
2753  widgetChar->updateFont( layerFont );
2755  widgetChar->blockSignals( false );
2756 
2757  //block
2758  whileBlocking( spinOffsetX )->setValue( mLayer->offset().x() );
2759  whileBlocking( spinOffsetY )->setValue( mLayer->offset().y() );
2760 
2761  mSizeUnitWidget->blockSignals( true );
2762  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
2763  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
2764  mSizeUnitWidget->blockSignals( false );
2765 
2766  mBorderWidthUnitWidget->blockSignals( true );
2767  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
2768  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
2769  mBorderWidthUnitWidget->blockSignals( false );
2770 
2771  mOffsetUnitWidget->blockSignals( true );
2772  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2773  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2774  mOffsetUnitWidget->blockSignals( false );
2775 
2776  whileBlocking( cboJoinStyle )->setPenJoinStyle( mLayer->penJoinStyle() );
2777 
2778  //anchor points
2779  whileBlocking( mHorizontalAnchorComboBox )->setCurrentIndex( mLayer->horizontalAnchorPoint() );
2780  whileBlocking( mVerticalAnchorComboBox )->setCurrentIndex( mLayer->verticalAnchorPoint() );
2781 
2789  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
2790  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
2792 
2793  updateAssistantSymbol();
2794 }
2795 
2797 {
2798  return mLayer;
2799 }
2800 
2802 {
2803  mLayer->setFontFamily( font.family() );
2804  widgetChar->updateFont( font );
2805  emit changed();
2806 }
2807 
2809 {
2810  mLayer->setColor( color );
2811  emit changed();
2812 }
2813 
2815 {
2816  mLayer->setOutlineColor( color );
2817  emit changed();
2818 }
2819 
2821 {
2822  mLayer->setSize( size );
2823  //widgetChar->updateSize(size);
2824  emit changed();
2825 }
2826 
2828 {
2829  mLayer->setAngle( angle );
2830  emit changed();
2831 }
2832 
2834 {
2835  mLayer->setCharacter( chr );
2836  emit changed();
2837 }
2838 
2840 {
2841  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2842  emit changed();
2843 }
2844 
2845 void QgsFontMarkerSymbolLayerV2Widget::penJoinStyleChanged()
2846 {
2847  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
2848  emit changed();
2849 }
2850 
2852 {
2853  if ( mLayer )
2854  {
2855  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2856  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2857  emit changed();
2858  }
2859 }
2860 
2862 {
2863  if ( mLayer )
2864  {
2865  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2866  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2867  emit changed();
2868  }
2869 }
2870 
2872 {
2873  if ( mLayer )
2874  {
2875  mLayer->setOutlineWidthUnit( mSizeUnitWidget->unit() );
2876  mLayer->setOutlineWidthMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2877  emit changed();
2878  }
2879 }
2880 
2882 {
2883  if ( mLayer )
2884  {
2886  emit changed();
2887  }
2888 }
2889 
2891 {
2892  if ( mLayer )
2893  {
2895  emit changed();
2896  }
2897 }
2898 
2900 {
2901  if ( mLayer )
2902  {
2903  mLayer->setOutlineWidth( d );
2904  emit changed();
2905  }
2906 }
2907 
2908 void QgsFontMarkerSymbolLayerV2Widget::updateAssistantSymbol()
2909 {
2910  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
2911  {
2912  mAssistantPreviewSymbol->deleteSymbolLayer( i );
2913  }
2914  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
2915  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
2916  if ( ddSize )
2917  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
2918 }
2919 
2921 
2922 
2924  : QgsSymbolLayerV2Widget( parent, vl )
2925 {
2926  mLayer = nullptr;
2927 
2928  setupUi( this );
2929 }
2930 
2932 {
2933  if ( layer->layerType() != "CentroidFill" )
2934  return;
2935 
2936  // layer type is correct, we can do the cast
2937  mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
2938 
2939  // set values
2940  whileBlocking( mDrawInsideCheckBox )->setChecked( mLayer->pointOnSurface() );
2941  whileBlocking( mDrawAllPartsCheckBox )->setChecked( mLayer->pointOnAllParts() );
2942 }
2943 
2945 {
2946  return mLayer;
2947 }
2948 
2949 void QgsCentroidFillSymbolLayerV2Widget::on_mDrawInsideCheckBox_stateChanged( int state )
2950 {
2951  mLayer->setPointOnSurface( state == Qt::Checked );
2952  emit changed();
2953 }
2954 
2955 void QgsCentroidFillSymbolLayerV2Widget::on_mDrawAllPartsCheckBox_stateChanged( int state )
2956 {
2957  mLayer->setPointOnAllParts( state == Qt::Checked );
2958  emit changed();
2959 }
2960 
2962 
2964  : QgsSymbolLayerV2Widget( parent, vl )
2965 {
2966  mLayer = nullptr;
2967  setupUi( this );
2968 
2970  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2971 
2972  mSpinOffsetX->setClearValue( 0.0 );
2973  mSpinOffsetY->setClearValue( 0.0 );
2974 
2975  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
2976  connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2977  connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2978 }
2979 
2981 {
2982  if ( !layer )
2983  {
2984  return;
2985  }
2986 
2987  if ( layer->layerType() != "RasterFill" )
2988  {
2989  return;
2990  }
2991 
2992  mLayer = dynamic_cast<QgsRasterFillSymbolLayer*>( layer );
2993  if ( !mLayer )
2994  {
2995  return;
2996  }
2997 
2998  mImageLineEdit->blockSignals( true );
2999  mImageLineEdit->setText( mLayer->imageFilePath() );
3000  mImageLineEdit->blockSignals( false );
3001 
3002  cboCoordinateMode->blockSignals( true );
3003  switch ( mLayer->coordinateMode() )
3004  {
3006  cboCoordinateMode->setCurrentIndex( 1 );
3007  break;
3009  default:
3010  cboCoordinateMode->setCurrentIndex( 0 );
3011  break;
3012  }
3013  cboCoordinateMode->blockSignals( false );
3014  mSpinTransparency->blockSignals( true );
3015  mSpinTransparency->setValue( mLayer->alpha() * 100.0 );
3016  mSpinTransparency->blockSignals( false );
3017  mSliderTransparency->blockSignals( true );
3018  mSliderTransparency->setValue( mLayer->alpha() * 100.0 );
3019  mSliderTransparency->blockSignals( false );
3020  mRotationSpinBox->blockSignals( true );
3021  mRotationSpinBox->setValue( mLayer->angle() );
3022  mRotationSpinBox->blockSignals( false );
3023 
3024  mSpinOffsetX->blockSignals( true );
3025  mSpinOffsetX->setValue( mLayer->offset().x() );
3026  mSpinOffsetX->blockSignals( false );
3027  mSpinOffsetY->blockSignals( true );
3028  mSpinOffsetY->setValue( mLayer->offset().y() );
3029  mSpinOffsetY->blockSignals( false );
3030  mOffsetUnitWidget->blockSignals( true );
3031  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
3032  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
3033  mOffsetUnitWidget->blockSignals( false );
3034 
3035  mWidthSpinBox->blockSignals( true );
3036  mWidthSpinBox->setValue( mLayer->width() );
3037  mWidthSpinBox->blockSignals( false );
3038  mWidthUnitWidget->blockSignals( true );
3039  mWidthUnitWidget->setUnit( mLayer->widthUnit() );
3040  mWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
3041  mWidthUnitWidget->blockSignals( false );
3042  updatePreviewImage();
3043 
3048 }
3049 
3051 {
3052  return mLayer;
3053 }
3054 
3055 void QgsRasterFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
3056 {
3057  QSettings s;
3058  QString openDir;
3059  QString lineEditText = mImageLineEdit->text();
3060  if ( !lineEditText.isEmpty() )
3061  {
3062  QFileInfo openDirFileInfo( lineEditText );
3063  openDir = openDirFileInfo.path();
3064  }
3065 
3066  if ( openDir.isEmpty() )
3067  {
3068  openDir = s.value( "/UI/lastRasterFillImageDir", QDir::homePath() ).toString();
3069  }
3070 
3071  //show file dialog
3072  QString filePath = QFileDialog::getOpenFileName( nullptr, tr( "Select image file" ), openDir );
3073  if ( !filePath.isNull() )
3074  {
3075  //check if file exists
3076  QFileInfo fileInfo( filePath );
3077  if ( !fileInfo.exists() || !fileInfo.isReadable() )
3078  {
3079  QMessageBox::critical( nullptr, "Invalid file", "Error, file does not exist or is not readable" );
3080  return;
3081  }
3082 
3083  s.setValue( "/UI/lastRasterFillImageDir", fileInfo.absolutePath() );
3084  mImageLineEdit->setText( filePath );
3085  on_mImageLineEdit_editingFinished();
3086  }
3087 }
3088 
3089 void QgsRasterFillSymbolLayerWidget::on_mImageLineEdit_editingFinished()
3090 {
3091  if ( !mLayer )
3092  {
3093  return;
3094  }
3095 
3096  QFileInfo fi( mImageLineEdit->text() );
3097  if ( !fi.exists() )
3098  {
3099  QUrl url( mImageLineEdit->text() );
3100  if ( !url.isValid() )
3101  {
3102  return;
3103  }
3104  }
3105 
3106  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
3107  mLayer->setImageFilePath( mImageLineEdit->text() );
3108  updatePreviewImage();
3110 
3111  emit changed();
3112 }
3113 
3114 void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
3115 {
3116  switch ( index )
3117  {
3118  case 0:
3119  //feature coordinate mode
3121  break;
3122  case 1:
3123  //viewport coordinate mode
3125  break;
3126  }
3127 
3128  emit changed();
3129 }
3130 
3131 void QgsRasterFillSymbolLayerWidget::on_mSpinTransparency_valueChanged( int value )
3132 {
3133  if ( !mLayer )
3134  {
3135  return;
3136  }
3137 
3138  mLayer->setAlpha( value / 100.0 );
3139  emit changed();
3140  updatePreviewImage();
3141 }
3142 
3143 void QgsRasterFillSymbolLayerWidget::offsetChanged()
3144 {
3145  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
3146  emit changed();
3147 }
3148 
3149 void QgsRasterFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
3150 {
3151  if ( !mLayer )
3152  {
3153  return;
3154  }
3155  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
3156  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3157  emit changed();
3158 }
3159 
3160 void QgsRasterFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
3161 {
3162  if ( mLayer )
3163  {
3164  mLayer->setAngle( d );
3165  emit changed();
3166  }
3167 }
3168 
3169 void QgsRasterFillSymbolLayerWidget::on_mWidthUnitWidget_changed()
3170 {
3171  if ( !mLayer )
3172  {
3173  return;
3174  }
3175  mLayer->setWidthUnit( mWidthUnitWidget->unit() );
3176  mLayer->setWidthMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
3177  emit changed();
3178 }
3179 
3180 void QgsRasterFillSymbolLayerWidget::on_mWidthSpinBox_valueChanged( double d )
3181 {
3182  if ( !mLayer )
3183  {
3184  return;
3185  }
3186  mLayer->setWidth( d );
3187  emit changed();
3188 }
3189 
3190 
3191 void QgsRasterFillSymbolLayerWidget::updatePreviewImage()
3192 {
3193  if ( !mLayer )
3194  {
3195  return;
3196  }
3197 
3198  QImage image( mLayer->imageFilePath() );
3199  if ( image.isNull() )
3200  {
3201  mLabelImagePreview->setPixmap( QPixmap() );
3202  return;
3203  }
3204 
3205  if ( image.height() > 150 || image.width() > 150 )
3206  {
3207  image = image.scaled( 150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation );
3208  }
3209 
3210  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
3211  previewImage.fill( Qt::transparent );
3212  QRect imageRect(( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
3213  QPainter p;
3214  p.begin( &previewImage );
3215  //draw a checkerboard background
3216  uchar pixDataRGB[] = { 150, 150, 150, 150,
3217  100, 100, 100, 150,
3218  100, 100, 100, 150,
3219  150, 150, 150, 150
3220  };
3221  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
3222  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
3223  QBrush checkerBrush;
3224  checkerBrush.setTexture( pix );
3225  p.fillRect( imageRect, checkerBrush );
3226 
3227  if ( mLayer->alpha() < 1.0 )
3228  {
3229  p.setOpacity( mLayer->alpha() );
3230  }
3231 
3232  p.drawImage( imageRect.left(), imageRect.top(), image );
3233  p.end();
3234  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
3235 }
3236 
3237 
3239  : QgsSymbolLayerV2Widget( parent, vl )
3240  , mLayer( nullptr )
3241 {
3242  setupUi( this );
3243  modificationExpressionSelector->setLayer( const_cast<QgsVectorLayer*>( vl ) );
3244  modificationExpressionSelector->loadFieldNames();
3245  modificationExpressionSelector->setExpressionContext( _getExpressionContext( this ) );
3246  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPolygonLayer.svg" ), tr( "Polygon / MultiPolygon" ), QgsSymbolV2::Fill );
3247  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconLineLayer.svg" ), tr( "LineString / MultiLineString" ), QgsSymbolV2::Line );
3248  cbxGeometryType->addItem( QgsApplication::getThemeIcon( "/mIconPointLayer.svg" ), tr( "Point / MultiPoint" ), QgsSymbolV2::Marker );
3249  connect( modificationExpressionSelector, SIGNAL( expressionParsed( bool ) ), this, SLOT( updateExpression() ) );
3250  connect( cbxGeometryType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateSymbolType() ) );
3251 }
3252 
3254 {
3255  mLayer = static_cast<QgsGeometryGeneratorSymbolLayerV2*>( l );
3256 
3258  modificationExpressionSelector->setExpressionContext( *mPresetExpressionContext );
3259  modificationExpressionSelector->setExpressionText( mLayer->geometryExpression() );
3260  cbxGeometryType->setCurrentIndex( cbxGeometryType->findData( mLayer->symbolType() ) );
3261 }
3262 
3264 {
3265  return mLayer;
3266 }
3267 
3268 void QgsGeometryGeneratorSymbolLayerWidget::updateExpression()
3269 {
3270  mLayer->setGeometryExpression( modificationExpressionSelector->expressionText() );
3271 
3272  emit changed();
3273 }
3274 
3275 void QgsGeometryGeneratorSymbolLayerWidget::updateSymbolType()
3276 {
3277  mLayer->setSymbolType( static_cast<QgsSymbolV2::SymbolType>( cbxGeometryType->itemData( cbxGeometryType->currentIndex() ).toInt() ) );
3278 
3279  emit symbolChanged();
3280 }
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
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 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
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
A model for displaying SVG files with a preview icon.
const QgsMapUnitScale & displacementXMapUnitScale() const
void setDistanceYUnit(QgsSymbolV2::OutputUnit unit)
QStandardItem * invisibleRootItem() const
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.
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.
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 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.
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.
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.
QModelIndex indexFromItem(const QStandardItem *item) 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)
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)
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
QStandardItem * item(int row, int column) const
void setOutlineWidth(double width)
Set outline width.
bool blockSignals(bool block)
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
A model for displaying SVG search paths.
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
void setPenStyle(Qt::PenStyle style)
QVariant data(int role) const
void setPlacement(Placement p)
The placement of the markers.
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()
QgsSvgMarkerSymbolLayerV2 * mLayer
QgsSymbolV2::OutputUnit offsetUnit() const
static QString fillStyleDesc()
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)
virtual int rowCount(const QModelIndex &parent) const
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.
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)
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.
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
bool rotateMarker() const
Shall the marker be rotated.
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)
void setSvgOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QPointF offset() const
Returns the offset for the fill.
QgsRasterFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
virtual QgsSymbolLayerV2 * symbolLayer() override
QString geometryExpression() const
Get the expression to generate this geometry.
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.
void setOutlineColor(const QColor &color) override
Set outline color.
void setBorderStyle(Qt::PenStyle borderStyle)
QgsLinePatternFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)