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