QGIS API Documentation  2.12.0-Lyon
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"
22 
23 #include "characterwidget.h"
24 #include "qgsdashspacedialog.h"
27 #include "qgssvgcache.h"
28 #include "qgssymbollayerv2utils.h"
29 #include "qgsvectorcolorrampv2.h"
31 #include "qgsdatadefined.h"
32 #include "qgsstylev2.h" //for symbol selector dialog
33 #include "qgsmapcanvas.h"
34 #include "qgsapplication.h"
35 
36 #include "qgslogger.h"
37 #include "qgssizescalewidget.h"
38 
39 #include <QAbstractButton>
40 #include <QColorDialog>
41 #include <QCursor>
42 #include <QDir>
43 #include <QFileDialog>
44 #include <QPainter>
45 #include <QSettings>
46 #include <QStandardItemModel>
47 #include <QSvgRenderer>
48 #include <QMessageBox>
49 
50 static QgsExpressionContext _getExpressionContext( const void* context )
51 {
52  const QgsSymbolLayerV2Widget* widget = ( const QgsSymbolLayerV2Widget* ) context;
53 
54  if ( widget->expressionContext() )
55  return QgsExpressionContext( *widget->expressionContext() );
56 
57  QgsExpressionContext expContext;
61 
62  if ( widget->mapCanvas() )
63  {
66  }
67  else
68  {
70  }
71 
72  const QgsVectorLayer* layer = widget->vectorLayer();
73  if ( layer )
74  expContext << QgsExpressionContextUtils::layerScope( layer );
75 
76  //TODO - show actual value
77  expContext.setOriginalValueVariable( QVariant() );
79 
80  return expContext;
81 }
82 
84 {
85  mMapCanvas = canvas;
86  Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
87  {
88  unitWidget->setMapCanvas( mMapCanvas );
89  }
90  Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
91  {
92  if ( ddButton->assistant() )
93  ddButton->assistant()->setMapCanvas( mMapCanvas );
94  }
95 }
96 
98 {
99  return mMapCanvas;
100 }
101 
103 {
104  const QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
105  button->init( mVectorLayer, dd, type, description );
106  button->setProperty( "propertyName", propertyName );
107  connect( button, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty() ) );
108  connect( button, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty() ) );
109 
111 }
112 
114 {
115  QgsDataDefinedButton* button = qobject_cast<QgsDataDefinedButton*>( sender() );
116  const QString propertyName( button->property( "propertyName" ).toString() );
117 
118  QgsDataDefined* dd = symbolLayer()->getDataDefinedProperty( propertyName );
119  if ( !dd )
120  {
121  dd = new QgsDataDefined();
122  symbolLayer()->setDataDefinedProperty( propertyName, dd );
123  }
124  button->updateDataDefined( dd );
125 
126  emit changed();
127 }
128 
130 {
131  QString label = entryName;
132  if ( entryName == "size" )
133  {
134  label = tr( "Size" );
135  QgsMarkerSymbolLayerV2 * layer = dynamic_cast<QgsMarkerSymbolLayerV2 *>( symbolLayer() );
136  if ( layer )
137  {
138  switch ( layer->scaleMethod() )
139  {
141  label += " (" + tr( "area" ) + ")";
142  break;
144  label += " (" + tr( "diameter" ) + ")";
145  break;
146  }
147  }
148  }
149  return label;
150 }
151 
153  : QgsSymbolLayerV2Widget( parent, vl )
154 {
155  mLayer = NULL;
156 
157  setupUi( this );
158  mPenWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
160  mDashPatternUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
161 
162  btnChangeColor->setAllowAlpha( true );
163  btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
164  btnChangeColor->setContext( "symbology" );
165 
166  spinOffset->setClearValue( 0.0 );
167 
168  if ( vl && vl->geometryType() != QGis::Polygon )
169  {
170  //draw inside polygon checkbox only makes sense for polygon layers
171  mDrawInsideCheckBox->hide();
172  }
173 
174  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
175  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
176  connect( cboPenStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
177  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
178  connect( cboCapStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
179  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
181 
182 }
183 
185 {
186  if ( !layer || layer->layerType() != "SimpleLine" )
187  return;
188 
189  // layer type is correct, we can do the cast
190  mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>( layer );
191 
192  // set units
193  mPenWidthUnitWidget->blockSignals( true );
194  mPenWidthUnitWidget->setUnit( mLayer->widthUnit() );
195  mPenWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
196  mPenWidthUnitWidget->blockSignals( false );
197  mOffsetUnitWidget->blockSignals( true );
198  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
199  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
200  mOffsetUnitWidget->blockSignals( false );
201  mDashPatternUnitWidget->blockSignals( true );
202  mDashPatternUnitWidget->setUnit( mLayer->customDashPatternUnit() );
203  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
204  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
205  mDashPatternUnitWidget->blockSignals( false );
206 
207  // set values
208  spinWidth->blockSignals( true );
209  spinWidth->setValue( mLayer->width() );
210  spinWidth->blockSignals( false );
211  btnChangeColor->blockSignals( true );
212  btnChangeColor->setColor( mLayer->color() );
213  btnChangeColor->blockSignals( false );
214  spinOffset->blockSignals( true );
215  spinOffset->setValue( mLayer->offset() );
216  spinOffset->blockSignals( false );
217  cboPenStyle->blockSignals( true );
218  cboJoinStyle->blockSignals( true );
219  cboCapStyle->blockSignals( true );
220  cboPenStyle->setPenStyle( mLayer->penStyle() );
221  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
222  cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
223  cboPenStyle->blockSignals( false );
224  cboJoinStyle->blockSignals( false );
225  cboCapStyle->blockSignals( false );
226 
227  //use a custom dash pattern?
228  bool useCustomDashPattern = mLayer->useCustomDashPattern();
229  mChangePatternButton->setEnabled( useCustomDashPattern );
230  label_3->setEnabled( !useCustomDashPattern );
231  cboPenStyle->setEnabled( !useCustomDashPattern );
232  mCustomCheckBox->blockSignals( true );
233  mCustomCheckBox->setCheckState( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
234  mCustomCheckBox->blockSignals( false );
235 
236  //draw inside polygon?
237  bool drawInsidePolygon = mLayer->drawInsidePolygon();
238  mDrawInsideCheckBox->blockSignals( true );
239  mDrawInsideCheckBox->setCheckState( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
240  mDrawInsideCheckBox->blockSignals( false );
241 
243 
251 }
252 
254 {
255  return mLayer;
256 }
257 
259 {
260  mLayer->setWidth( spinWidth->value() );
262  emit changed();
263 }
264 
266 {
267  mLayer->setColor( color );
269  emit changed();
270 }
271 
273 {
274  mLayer->setPenStyle( cboPenStyle->penStyle() );
275  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
276  mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
277  emit changed();
278 }
279 
281 {
282  mLayer->setOffset( spinOffset->value() );
284  emit changed();
285 }
286 
288 {
289  bool checked = ( state == Qt::Checked );
290  mChangePatternButton->setEnabled( checked );
291  label_3->setEnabled( !checked );
292  cboPenStyle->setEnabled( !checked );
293 
294  mLayer->setUseCustomDashPattern( checked );
295  emit changed();
296 }
297 
299 {
301  if ( d.exec() == QDialog::Accepted )
302  {
303  mLayer->setCustomDashVector( d.dashDotVector() );
305  emit changed();
306  }
307 }
308 
310 {
311  if ( mLayer )
312  {
313  mLayer->setWidthUnit( mPenWidthUnitWidget->unit() );
314  mLayer->setWidthMapUnitScale( mPenWidthUnitWidget->getMapUnitScale() );
315  emit changed();
316  }
317 }
318 
320 {
321  if ( mLayer )
322  {
323  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
324  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
325  emit changed();
326  }
327 }
328 
330 {
331  if ( mLayer )
332  {
333  mLayer->setCustomDashPatternUnit( mDashPatternUnitWidget->unit() );
334  mLayer->setCustomDashPatternMapUnitScale( mDashPatternUnitWidget->getMapUnitScale() );
335  emit changed();
336  }
337 }
338 
340 {
341  bool checked = ( state == Qt::Checked );
342  mLayer->setDrawInsidePolygon( checked );
343  emit changed();
344 }
345 
346 
348 {
349  if ( !mLayer )
350  {
351  return;
352  }
353  QgsSimpleLineSymbolLayerV2* layerCopy = dynamic_cast<QgsSimpleLineSymbolLayerV2*>( mLayer->clone() );
354  if ( !layerCopy )
355  {
356  return;
357  }
358  layerCopy->setUseCustomDashPattern( true );
359  QIcon buttonIcon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( layerCopy, QgsSymbolV2::MM, mChangePatternButton->iconSize() );
360  mChangePatternButton->setIcon( buttonIcon );
361  delete layerCopy;
362 }
363 
364 
366 
367 
369  : QgsSymbolLayerV2Widget( parent, vl )
370 {
371  mLayer = NULL;
372 
373  setupUi( this );
376  mOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
377 
378  btnChangeColorFill->setAllowAlpha( true );
379  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
380  btnChangeColorFill->setContext( "symbology" );
381  btnChangeColorFill->setShowNoColor( true );
382  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
383  btnChangeColorBorder->setAllowAlpha( true );
384  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
385  btnChangeColorBorder->setContext( "symbology" );
386  btnChangeColorBorder->setShowNoColor( true );
387  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
388 
389  spinOffsetX->setClearValue( 0.0 );
390  spinOffsetY->setClearValue( 0.0 );
391 
392  //make a temporary symbol for the size assistant preview
393  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
394 
395  if ( mVectorLayer )
396  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
397 
398  QSize size = lstNames->iconSize();
399  QStringList names;
400  names << "circle" << "rectangle" << "diamond" << "pentagon" << "cross" << "cross2" << "triangle"
401  << "equilateral_triangle" << "star" << "regular_star" << "arrow" << "line" << "arrowhead" << "filled_arrowhead";
402  double markerSize = DEFAULT_POINT_SIZE * 2;
403  for ( int i = 0; i < names.count(); ++i )
404  {
405  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( names[i], QColor( 200, 200, 200 ), QColor( 0, 0, 0 ), markerSize );
407  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
408  item->setData( Qt::UserRole, names[i] );
409  delete lyr;
410  }
411 
412  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setName() ) );
413  connect( btnChangeColorBorder, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
414  connect( btnChangeColorFill, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorFill( const QColor& ) ) );
415  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
416  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
417  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
418  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
419  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
420 }
421 
423 {
424  delete mAssistantPreviewSymbol;
425 }
426 
428 {
429  if ( layer->layerType() != "SimpleMarker" )
430  return;
431 
432  // layer type is correct, we can do the cast
433  mLayer = static_cast<QgsSimpleMarkerSymbolLayerV2*>( layer );
434 
435  // set values
436  QString name = mLayer->name();
437  for ( int i = 0; i < lstNames->count(); ++i )
438  {
439  if ( lstNames->item( i )->data( Qt::UserRole ).toString() == name )
440  {
441  lstNames->setCurrentRow( i );
442  break;
443  }
444  }
445  btnChangeColorBorder->blockSignals( true );
446  btnChangeColorBorder->setColor( mLayer->borderColor() );
447  btnChangeColorBorder->blockSignals( false );
448  btnChangeColorFill->blockSignals( true );
449  btnChangeColorFill->setColor( mLayer->color() );
450  btnChangeColorFill->blockSignals( false );
451  spinSize->blockSignals( true );
452  spinSize->setValue( mLayer->size() );
453  spinSize->blockSignals( false );
454  spinAngle->blockSignals( true );
455  spinAngle->setValue( mLayer->angle() );
456  spinAngle->blockSignals( false );
457  mOutlineStyleComboBox->blockSignals( true );
458  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
459  mOutlineStyleComboBox->blockSignals( false );
460  mOutlineWidthSpinBox->blockSignals( true );
461  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
462  mOutlineWidthSpinBox->blockSignals( false );
463 
464  // without blocking signals the value gets changed because of slot setOffset()
465  spinOffsetX->blockSignals( true );
466  spinOffsetX->setValue( mLayer->offset().x() );
467  spinOffsetX->blockSignals( false );
468  spinOffsetY->blockSignals( true );
469  spinOffsetY->setValue( mLayer->offset().y() );
470  spinOffsetY->blockSignals( false );
471 
472  mSizeUnitWidget->blockSignals( true );
473  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
474  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
475  mSizeUnitWidget->blockSignals( false );
476  mOffsetUnitWidget->blockSignals( true );
477  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
478  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
479  mOffsetUnitWidget->blockSignals( false );
480  mOutlineWidthUnitWidget->blockSignals( true );
481  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
482  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
483  mOutlineWidthUnitWidget->blockSignals( false );
484 
485  //anchor points
486  mHorizontalAnchorComboBox->blockSignals( true );
487  mVerticalAnchorComboBox->blockSignals( true );
488  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
489  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
490  mHorizontalAnchorComboBox->blockSignals( false );
491  mVerticalAnchorComboBox->blockSignals( false );
492 
493  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
494  "<b>pentagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
495  "<b>star</b>|<b>regular_star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
496  "<b>circle</b>|<b>cross</b>|<b>x</b>|"
497  "<b>cross2</b>|<b>line</b>|<b>arrowhead</b>]" ) );
505  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
506  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
507 
508  updateAssistantSymbol();
509 }
510 
512 {
513  return mLayer;
514 }
515 
517 {
518  mLayer->setName( lstNames->currentItem()->data( Qt::UserRole ).toString() );
519  emit changed();
520 }
521 
523 {
524  mLayer->setBorderColor( color );
525  emit changed();
526 }
527 
529 {
530  mLayer->setColor( color );
531  emit changed();
532 }
533 
535 {
536  mLayer->setSize( spinSize->value() );
537  emit changed();
538 }
539 
541 {
542  mLayer->setAngle( spinAngle->value() );
543  emit changed();
544 }
545 
547 {
548  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
549  emit changed();
550 }
551 
553 {
554  Q_UNUSED( index );
555 
556  if ( mLayer )
557  {
558  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
559  emit changed();
560  }
561 }
562 
564 {
565  if ( mLayer )
566  {
567  mLayer->setOutlineWidth( d );
568  emit changed();
569  }
570 }
571 
573 {
574  if ( mLayer )
575  {
576  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
577  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
578  emit changed();
579  }
580 }
581 
583 {
584  if ( mLayer )
585  {
586  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
587  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
588  emit changed();
589  }
590 }
591 
593 {
594  if ( mLayer )
595  {
596  mLayer->setOutlineWidthUnit( mOutlineWidthUnitWidget->unit() );
597  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
598  emit changed();
599  }
600 }
601 
603 {
604  if ( mLayer )
605  {
607  emit changed();
608  }
609 }
610 
612 {
613  if ( mLayer )
614  {
616  emit changed();
617  }
618 }
619 
620 void QgsSimpleMarkerSymbolLayerV2Widget::updateAssistantSymbol()
621 {
622  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
623  {
624  mAssistantPreviewSymbol->deleteSymbolLayer( i );
625  }
626  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
627  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
628  if ( ddSize )
629  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
630 }
631 
632 
634 
636  : QgsSymbolLayerV2Widget( parent, vl )
637 {
638  mLayer = NULL;
639 
640  setupUi( this );
641  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
643 
644  btnChangeColor->setAllowAlpha( true );
645  btnChangeColor->setColorDialogTitle( tr( "Select fill color" ) );
646  btnChangeColor->setContext( "symbology" );
647  btnChangeColor->setShowNoColor( true );
648  btnChangeColor->setNoColorString( tr( "Transparent fill" ) );
649  btnChangeBorderColor->setAllowAlpha( true );
650  btnChangeBorderColor->setColorDialogTitle( tr( "Select border color" ) );
651  btnChangeBorderColor->setContext( "symbology" );
652  btnChangeBorderColor->setShowNoColor( true );
653  btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );
654 
655  spinOffsetX->setClearValue( 0.0 );
656  spinOffsetY->setClearValue( 0.0 );
657 
658  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
659  connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
660  connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
661  connect( spinBorderWidth, SIGNAL( valueChanged( double ) ), this, SLOT( borderWidthChanged() ) );
662  connect( cboBorderStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
663  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
664  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
665  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
666 }
667 
669 {
670  if ( layer->layerType() != "SimpleFill" )
671  return;
672 
673  // layer type is correct, we can do the cast
674  mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>( layer );
675 
676  // set values
677  btnChangeColor->blockSignals( true );
678  btnChangeColor->setColor( mLayer->color() );
679  btnChangeColor->blockSignals( false );
680  cboFillStyle->blockSignals( true );
681  cboFillStyle->setBrushStyle( mLayer->brushStyle() );
682  cboFillStyle->blockSignals( false );
683  btnChangeBorderColor->blockSignals( true );
684  btnChangeBorderColor->setColor( mLayer->borderColor() );
685  btnChangeBorderColor->blockSignals( false );
686  cboBorderStyle->blockSignals( true );
687  cboBorderStyle->setPenStyle( mLayer->borderStyle() );
688  cboBorderStyle->blockSignals( false );
689  spinBorderWidth->blockSignals( true );
690  spinBorderWidth->setValue( mLayer->borderWidth() );
691  spinBorderWidth->blockSignals( false );
692  cboJoinStyle->blockSignals( true );
693  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
694  cboJoinStyle->blockSignals( false );
695  spinOffsetX->blockSignals( true );
696  spinOffsetX->setValue( mLayer->offset().x() );
697  spinOffsetX->blockSignals( false );
698  spinOffsetY->blockSignals( true );
699  spinOffsetY->setValue( mLayer->offset().y() );
700  spinOffsetY->blockSignals( false );
701 
702  mBorderWidthUnitWidget->blockSignals( true );
703  mBorderWidthUnitWidget->setUnit( mLayer->borderWidthUnit() );
704  mBorderWidthUnitWidget->setMapUnitScale( mLayer->borderWidthMapUnitScale() );
705  mBorderWidthUnitWidget->blockSignals( false );
706  mOffsetUnitWidget->blockSignals( true );
707  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
708  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
709  mOffsetUnitWidget->blockSignals( false );
710 
717 
718 }
719 
721 {
722  return mLayer;
723 }
724 
726 {
727  mLayer->setColor( color );
728  emit changed();
729 }
730 
732 {
733  mLayer->setBorderColor( color );
734  emit changed();
735 }
736 
738 {
739  mLayer->setBrushStyle( cboFillStyle->brushStyle() );
740  emit changed();
741 }
742 
744 {
745  mLayer->setBorderWidth( spinBorderWidth->value() );
746  emit changed();
747 }
748 
750 {
751  mLayer->setBorderStyle( cboBorderStyle->penStyle() );
752  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
753  emit changed();
754 }
755 
757 {
758  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
759  emit changed();
760 }
761 
763 {
764  if ( mLayer )
765  {
766  mLayer->setBorderWidthUnit( mBorderWidthUnitWidget->unit() );
767  mLayer->setBorderWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
768  emit changed();
769  }
770 }
771 
773 {
774  if ( mLayer )
775  {
776  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
777  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
778  emit changed();
779  }
780 }
781 
783 
785  : QgsSymbolLayerV2Widget( parent, vl )
786 {
787  mLayer = NULL;
788 
789  setupUi( this );
791 
792  cboGradientColorRamp->setShowGradientOnly( true );
793  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
794 
795  btnChangeColor->setAllowAlpha( true );
796  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
797  btnChangeColor->setContext( "symbology" );
798  btnChangeColor->setShowNoColor( true );
799  btnChangeColor->setNoColorString( tr( "Transparent" ) );
800  btnChangeColor2->setAllowAlpha( true );
801  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
802  btnChangeColor2->setContext( "symbology" );
803  btnChangeColor2->setShowNoColor( true );
804  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
805 
806  spinOffsetX->setClearValue( 0.0 );
807  spinOffsetY->setClearValue( 0.0 );
808 
809  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
810  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
811  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
812  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
813  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
814  connect( cboGradientType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientType( int ) ) );
815  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
816  connect( cboGradientSpread, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientSpread( int ) ) );
817  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
818  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
819  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
820  connect( spinRefPoint1X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
821  connect( spinRefPoint1Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
822  connect( checkRefPoint1Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
823  connect( spinRefPoint2X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
824  connect( spinRefPoint2Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
825  connect( checkRefPoint2Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
826 }
827 
829 {
830  if ( layer->layerType() != "GradientFill" )
831  return;
832 
833  // layer type is correct, we can do the cast
834  mLayer = static_cast<QgsGradientFillSymbolLayerV2*>( layer );
835 
836  // set values
837  btnChangeColor->blockSignals( true );
838  btnChangeColor->setColor( mLayer->color() );
839  btnChangeColor->blockSignals( false );
840  btnChangeColor2->blockSignals( true );
841  btnChangeColor2->setColor( mLayer->color2() );
842  btnChangeColor2->blockSignals( false );
843 
845  {
846  radioTwoColor->setChecked( true );
847  cboGradientColorRamp->setEnabled( false );
848  }
849  else
850  {
851  radioColorRamp->setChecked( true );
852  btnChangeColor->setEnabled( false );
853  btnChangeColor2->setEnabled( false );
854  }
855 
856  // set source color ramp
857  if ( mLayer->colorRamp() )
858  {
859  cboGradientColorRamp->blockSignals( true );
860  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
861  cboGradientColorRamp->blockSignals( false );
862  }
863 
864  cboGradientType->blockSignals( true );
865  switch ( mLayer->gradientType() )
866  {
868  cboGradientType->setCurrentIndex( 0 );
869  break;
871  cboGradientType->setCurrentIndex( 1 );
872  break;
874  cboGradientType->setCurrentIndex( 2 );
875  break;
876  }
877  cboGradientType->blockSignals( false );
878 
879  cboCoordinateMode->blockSignals( true );
880  switch ( mLayer->coordinateMode() )
881  {
883  cboCoordinateMode->setCurrentIndex( 1 );
884  checkRefPoint1Centroid->setEnabled( false );
885  checkRefPoint2Centroid->setEnabled( false );
886  break;
888  default:
889  cboCoordinateMode->setCurrentIndex( 0 );
890  break;
891  }
892  cboCoordinateMode->blockSignals( false );
893 
894  cboGradientSpread->blockSignals( true );
895  switch ( mLayer->gradientSpread() )
896  {
898  cboGradientSpread->setCurrentIndex( 0 );
899  break;
901  cboGradientSpread->setCurrentIndex( 1 );
902  break;
904  cboGradientSpread->setCurrentIndex( 2 );
905  break;
906  }
907  cboGradientSpread->blockSignals( false );
908 
909  spinRefPoint1X->blockSignals( true );
910  spinRefPoint1X->setValue( mLayer->referencePoint1().x() );
911  spinRefPoint1X->blockSignals( false );
912  spinRefPoint1Y->blockSignals( true );
913  spinRefPoint1Y->setValue( mLayer->referencePoint1().y() );
914  spinRefPoint1Y->blockSignals( false );
915  checkRefPoint1Centroid->blockSignals( true );
916  checkRefPoint1Centroid->setChecked( mLayer->referencePoint1IsCentroid() );
918  {
919  spinRefPoint1X->setEnabled( false );
920  spinRefPoint1Y->setEnabled( false );
921  }
922  checkRefPoint1Centroid->blockSignals( false );
923  spinRefPoint2X->blockSignals( true );
924  spinRefPoint2X->setValue( mLayer->referencePoint2().x() );
925  spinRefPoint2X->blockSignals( false );
926  spinRefPoint2Y->blockSignals( true );
927  spinRefPoint2Y->setValue( mLayer->referencePoint2().y() );
928  spinRefPoint2Y->blockSignals( false );
929  checkRefPoint2Centroid->blockSignals( true );
930  checkRefPoint2Centroid->setChecked( mLayer->referencePoint2IsCentroid() );
932  {
933  spinRefPoint2X->setEnabled( false );
934  spinRefPoint2Y->setEnabled( false );
935  }
936  checkRefPoint2Centroid->blockSignals( false );
937 
938  spinOffsetX->blockSignals( true );
939  spinOffsetX->setValue( mLayer->offset().x() );
940  spinOffsetX->blockSignals( false );
941  spinOffsetY->blockSignals( true );
942  spinOffsetY->setValue( mLayer->offset().y() );
943  spinOffsetY->blockSignals( false );
944  mSpinAngle->blockSignals( true );
945  mSpinAngle->setValue( mLayer->angle() );
946  mSpinAngle->blockSignals( false );
947 
948  mOffsetUnitWidget->blockSignals( true );
949  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
950  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
951  mOffsetUnitWidget->blockSignals( false );
952 
961  registerDataDefinedButton( mRefPoint1CentroidDDBtn, "reference1_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
964  registerDataDefinedButton( mRefPoint2CentroidDDBtn, "reference2_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
965 }
966 
968 {
969  return mLayer;
970 }
971 
973 {
974  mLayer->setColor( color );
975  emit changed();
976 }
977 
979 {
980  mLayer->setColor2( color );
981  emit changed();
982 }
983 
985 {
986  if ( radioTwoColor->isChecked() )
987  {
989  }
990  else
991  {
993  }
994  emit changed();
995 }
996 
998 {
999  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1000  if ( ramp == NULL )
1001  return;
1002 
1003  mLayer->setColorRamp( ramp );
1004  emit changed();
1005 }
1006 
1008 {
1009  switch ( index )
1010  {
1011  case 0:
1013  //set sensible default reference points
1014  spinRefPoint1X->setValue( 0.5 );
1015  spinRefPoint1Y->setValue( 0 );
1016  spinRefPoint2X->setValue( 0.5 );
1017  spinRefPoint2Y->setValue( 1 );
1018  break;
1019  case 1:
1021  //set sensible default reference points
1022  spinRefPoint1X->setValue( 0 );
1023  spinRefPoint1Y->setValue( 0 );
1024  spinRefPoint2X->setValue( 1 );
1025  spinRefPoint2Y->setValue( 1 );
1026  break;
1027  case 2:
1029  spinRefPoint1X->setValue( 0.5 );
1030  spinRefPoint1Y->setValue( 0.5 );
1031  spinRefPoint2X->setValue( 1 );
1032  spinRefPoint2Y->setValue( 1 );
1033  break;
1034  }
1035  emit changed();
1036 }
1037 
1039 {
1040 
1041  switch ( index )
1042  {
1043  case 0:
1044  //feature coordinate mode
1046  //allow choice of centroid reference positions
1047  checkRefPoint1Centroid->setEnabled( true );
1048  checkRefPoint2Centroid->setEnabled( true );
1049  break;
1050  case 1:
1051  //viewport coordinate mode
1053  //disable choice of centroid reference positions
1054  checkRefPoint1Centroid->setChecked( Qt::Unchecked );
1055  checkRefPoint1Centroid->setEnabled( false );
1056  checkRefPoint2Centroid->setChecked( Qt::Unchecked );
1057  checkRefPoint2Centroid->setEnabled( false );
1058  break;
1059  }
1060 
1061  emit changed();
1062 }
1063 
1065 {
1066  switch ( index )
1067  {
1068  case 0:
1070  break;
1071  case 1:
1073  break;
1074  case 2:
1076  break;
1077  }
1078 
1079  emit changed();
1080 }
1081 
1083 {
1084  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1085  emit changed();
1086 }
1087 
1089 {
1090  mLayer->setReferencePoint1( QPointF( spinRefPoint1X->value(), spinRefPoint1Y->value() ) );
1091  mLayer->setReferencePoint1IsCentroid( checkRefPoint1Centroid->isChecked() );
1092  mLayer->setReferencePoint2( QPointF( spinRefPoint2X->value(), spinRefPoint2Y->value() ) );
1093  mLayer->setReferencePoint2IsCentroid( checkRefPoint2Centroid->isChecked() );
1094  emit changed();
1095 }
1096 
1098 {
1099  mLayer->setAngle( value );
1100  emit changed();
1101 }
1102 
1104 {
1105  if ( mLayer )
1106  {
1107  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1108  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1109  emit changed();
1110  }
1111 }
1112 
1114 
1116  : QgsSymbolLayerV2Widget( parent, vl )
1117 {
1118  mLayer = NULL;
1119 
1120  setupUi( this );
1121  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1122  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1123 
1124  btnChangeColor->setAllowAlpha( true );
1125  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1126  btnChangeColor->setContext( "symbology" );
1127  btnChangeColor->setShowNoColor( true );
1128  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1129  btnChangeColor2->setAllowAlpha( true );
1130  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1131  btnChangeColor2->setContext( "symbology" );
1132  btnChangeColor2->setShowNoColor( true );
1133  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1134 
1135  spinOffsetX->setClearValue( 0.0 );
1136  spinOffsetY->setClearValue( 0.0 );
1137 
1138  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1139 
1140  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1141  connect( cboGradientColorRamp, SIGNAL( sourceRampEdited() ), this, SLOT( applyColorRamp() ) );
1142  connect( mButtonEditRamp, SIGNAL( clicked() ), cboGradientColorRamp, SLOT( editSourceRamp() ) );
1143 
1144  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1145  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1146  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1147  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1148  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1149 
1150  connect( mBlurSlider, SIGNAL( valueChanged( int ) ), mSpinBlurRadius, SLOT( setValue( int ) ) );
1151  connect( mSpinBlurRadius, SIGNAL( valueChanged( int ) ), mBlurSlider, SLOT( setValue( int ) ) );
1152 }
1153 
1155 {
1156  if ( layer->layerType() != "ShapeburstFill" )
1157  return;
1158 
1159  // layer type is correct, we can do the cast
1160  mLayer = static_cast<QgsShapeburstFillSymbolLayerV2*>( layer );
1161 
1162  // set values
1163  btnChangeColor->blockSignals( true );
1164  btnChangeColor->setColor( mLayer->color() );
1165  btnChangeColor->blockSignals( false );
1166  btnChangeColor2->blockSignals( true );
1167  btnChangeColor2->setColor( mLayer->color2() );
1168  btnChangeColor2->blockSignals( false );
1169 
1171  {
1172  radioTwoColor->setChecked( true );
1173  cboGradientColorRamp->setEnabled( false );
1174  }
1175  else
1176  {
1177  radioColorRamp->setChecked( true );
1178  btnChangeColor->setEnabled( false );
1179  btnChangeColor2->setEnabled( false );
1180  }
1181 
1182  mSpinBlurRadius->blockSignals( true );
1183  mBlurSlider->blockSignals( true );
1184  mSpinBlurRadius->setValue( mLayer->blurRadius() );
1185  mBlurSlider->setValue( mLayer->blurRadius() );
1186  mSpinBlurRadius->blockSignals( false );
1187  mBlurSlider->blockSignals( false );
1188 
1189  mSpinMaxDistance->blockSignals( true );
1190  mSpinMaxDistance->setValue( mLayer->maxDistance() );
1191  mSpinMaxDistance->blockSignals( false );
1192 
1193  mRadioUseWholeShape->blockSignals( true );
1194  mRadioUseMaxDistance->blockSignals( true );
1195  if ( mLayer->useWholeShape() )
1196  {
1197  mRadioUseWholeShape->setChecked( true );
1198  mSpinMaxDistance->setEnabled( false );
1199  mDistanceUnitWidget->setEnabled( false );
1200  }
1201  else
1202  {
1203  mRadioUseMaxDistance->setChecked( true );
1204  mSpinMaxDistance->setEnabled( true );
1205  mDistanceUnitWidget->setEnabled( true );
1206  }
1207  mRadioUseWholeShape->blockSignals( false );
1208  mRadioUseMaxDistance->blockSignals( false );
1209 
1210  mDistanceUnitWidget->blockSignals( true );
1211  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
1212  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
1213  mDistanceUnitWidget->blockSignals( false );
1214 
1215  mIgnoreRingsCheckBox->blockSignals( true );
1216  mIgnoreRingsCheckBox->setCheckState( mLayer->ignoreRings() ? Qt::Checked : Qt::Unchecked );
1217  mIgnoreRingsCheckBox->blockSignals( false );
1218 
1219  // set source color ramp
1220  if ( mLayer->colorRamp() )
1221  {
1222  cboGradientColorRamp->blockSignals( true );
1223  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1224  cboGradientColorRamp->blockSignals( false );
1225  }
1226 
1227  spinOffsetX->blockSignals( true );
1228  spinOffsetX->setValue( mLayer->offset().x() );
1229  spinOffsetX->blockSignals( false );
1230  spinOffsetY->blockSignals( true );
1231  spinOffsetY->setValue( mLayer->offset().y() );
1232  spinOffsetY->blockSignals( false );
1233  mOffsetUnitWidget->blockSignals( true );
1234  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1235  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1236  mOffsetUnitWidget->blockSignals( false );
1237 
1240  registerDataDefinedButton( mBlurRadiusDDBtn, "blur_radius", QgsDataDefinedButton::Int, tr( "Integer between 0 and 18" ) );
1241  registerDataDefinedButton( mShadeWholeShapeDDBtn, "use_whole_shape", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1244 }
1245 
1247 {
1248  return mLayer;
1249 }
1250 
1252 {
1253  if ( mLayer )
1254  {
1255  mLayer->setColor( color );
1256  emit changed();
1257  }
1258 }
1259 
1261 {
1262  if ( mLayer )
1263  {
1264  mLayer->setColor2( color );
1265  emit changed();
1266  }
1267 }
1268 
1270 {
1271  if ( !mLayer )
1272  {
1273  return;
1274  }
1275 
1276  if ( radioTwoColor->isChecked() )
1277  {
1279  }
1280  else
1281  {
1283  }
1284  emit changed();
1285 }
1286 
1288 {
1289  if ( mLayer )
1290  {
1291  mLayer->setBlurRadius( value );
1292  emit changed();
1293  }
1294 }
1295 
1297 {
1298  if ( mLayer )
1299  {
1300  mLayer->setMaxDistance( value );
1301  emit changed();
1302  }
1303 }
1304 
1306 {
1307  if ( mLayer )
1308  {
1309  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
1310  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
1311  emit changed();
1312  }
1313 }
1314 
1316 {
1317  if ( mLayer )
1318  {
1319  mLayer->setUseWholeShape( value );
1320  mDistanceUnitWidget->setEnabled( !value );
1321  emit changed();
1322  }
1323 }
1324 
1326 {
1327  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1328  if ( ramp == NULL )
1329  return;
1330 
1331  mLayer->setColorRamp( ramp );
1332  emit changed();
1333 }
1334 
1336 {
1337  if ( mLayer )
1338  {
1339  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1340  emit changed();
1341  }
1342 }
1343 
1345 {
1346  if ( mLayer )
1347  {
1348  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1349  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1350  emit changed();
1351  }
1352 }
1353 
1354 
1356 {
1357  bool checked = ( state == Qt::Checked );
1358  mLayer->setIgnoreRings( checked );
1359  emit changed();
1360 }
1361 
1363 
1365  : QgsSymbolLayerV2Widget( parent, vl )
1366 {
1367  mLayer = NULL;
1368 
1369  setupUi( this );
1370  mIntervalUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1371  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1372  mOffsetAlongLineUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1373 
1374  spinOffset->setClearValue( 0.0 );
1375 
1376  connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
1377  connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
1378  connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
1379  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1380  connect( radInterval, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1381  connect( radVertex, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1382  connect( radVertexLast, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1383  connect( radVertexFirst, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1384  connect( radCentralPoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1385  connect( radCurvePoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1386 }
1387 
1389 {
1390  if ( layer->layerType() != "MarkerLine" )
1391  return;
1392 
1393  // layer type is correct, we can do the cast
1394  mLayer = static_cast<QgsMarkerLineSymbolLayerV2*>( layer );
1395 
1396  // set values
1397  spinInterval->blockSignals( true );
1398  spinInterval->setValue( mLayer->interval() );
1399  spinInterval->blockSignals( false );
1400  mSpinOffsetAlongLine->blockSignals( true );
1401  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
1402  mSpinOffsetAlongLine->blockSignals( false );
1403  chkRotateMarker->blockSignals( true );
1404  chkRotateMarker->setChecked( mLayer->rotateMarker() );
1405  chkRotateMarker->blockSignals( false );
1406  spinOffset->blockSignals( true );
1407  spinOffset->setValue( mLayer->offset() );
1408  spinOffset->blockSignals( false );
1410  radInterval->setChecked( true );
1412  radVertex->setChecked( true );
1414  radVertexLast->setChecked( true );
1416  radCentralPoint->setChecked( true );
1418  radCurvePoint->setChecked( true );
1419  else
1420  radVertexFirst->setChecked( true );
1421 
1422  // set units
1423  mIntervalUnitWidget->blockSignals( true );
1424  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
1425  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
1426  mIntervalUnitWidget->blockSignals( false );
1427  mOffsetUnitWidget->blockSignals( true );
1428  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1429  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1430  mOffsetUnitWidget->blockSignals( false );
1431  mOffsetAlongLineUnitWidget->blockSignals( true );
1432  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
1433  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
1434  mOffsetAlongLineUnitWidget->blockSignals( false );
1435 
1436  setPlacement(); // update gui
1437 
1440  registerDataDefinedButton( mPlacementDDBtn, "placement", QgsDataDefinedButton::String, tr( "string " ) + QLatin1String( "[<b>vertex</b>|<b>lastvertex</b>|<b>firstvertex</b>|<b>centerpoint</b>]" ) );
1441  registerDataDefinedButton( mOffsetAlongLineDDBtn, "offset_along_line", QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
1442 }
1443 
1445 {
1446  return mLayer;
1447 }
1448 
1450 {
1451  mLayer->setInterval( val );
1452  emit changed();
1453 }
1454 
1456 {
1457  mLayer->setOffsetAlongLine( val );
1458  emit changed();
1459 }
1460 
1462 {
1463  mLayer->setRotateMarker( chkRotateMarker->isChecked() );
1464  emit changed();
1465 }
1466 
1468 {
1469  mLayer->setOffset( spinOffset->value() );
1470  emit changed();
1471 }
1472 
1474 {
1475  bool interval = radInterval->isChecked();
1476  spinInterval->setEnabled( interval );
1477  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
1478  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
1479  if ( radInterval->isChecked() )
1481  else if ( radVertex->isChecked() )
1483  else if ( radVertexLast->isChecked() )
1485  else if ( radVertexFirst->isChecked() )
1487  else if ( radCurvePoint->isChecked() )
1489  else
1491 
1492  emit changed();
1493 }
1494 
1496 {
1497  if ( mLayer )
1498  {
1499  mLayer->setIntervalUnit( mIntervalUnitWidget->unit() );
1500  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
1501  emit changed();
1502  }
1503 }
1504 
1506 {
1507  if ( mLayer )
1508  {
1509  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
1510  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1511  emit changed();
1512  }
1513 }
1514 
1516 {
1517  if ( mLayer )
1518  {
1519  mLayer->setOffsetAlongLineUnit( mOffsetAlongLineUnitWidget->unit() );
1520  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
1521  }
1522  emit changed();
1523 }
1524 
1526 
1527 
1529  : QgsSymbolLayerV2Widget( parent, vl )
1530 {
1531  mLayer = NULL;
1532 
1533  setupUi( this );
1535  mBorderWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1536  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
1537  viewGroups->setHeaderHidden( true );
1538 
1539  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
1540  mChangeColorButton->setContext( "symbology" );
1541  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
1542  mChangeColorButton->setContext( "symbology" );
1543 
1544  spinOffsetX->setClearValue( 0.0 );
1545  spinOffsetY->setClearValue( 0.0 );
1546 
1547  populateList();
1548 
1549  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1550  connect( viewGroups->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
1551  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
1552  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
1553  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1554  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1555  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
1556 
1557  //make a temporary symbol for the size assistant preview
1558  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
1559  if ( mVectorLayer )
1560  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
1561 }
1562 
1564 {
1565  delete mAssistantPreviewSymbol;
1566 }
1567 
1568 #include <QTime>
1569 #include <QAbstractListModel>
1570 #include <QPixmapCache>
1571 #include <QStyle>
1572 
1574 {
1575  public:
1577  {
1579  }
1580 
1581  // Constructor to create model for icons in a specific path
1583  {
1585  }
1586 
1587  int rowCount( const QModelIndex & parent = QModelIndex() ) const override
1588  {
1589  Q_UNUSED( parent );
1590  return mSvgFiles.count();
1591  }
1592 
1593  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const override
1594  {
1595  QString entry = mSvgFiles.at( index.row() );
1596 
1597  if ( role == Qt::DecorationRole ) // icon
1598  {
1599  QPixmap pixmap;
1600  if ( !QPixmapCache::find( entry, pixmap ) )
1601  {
1602  // render SVG file
1603  QColor fill, outline;
1604  double outlineWidth;
1605  bool fillParam, outlineParam, outlineWidthParam;
1606  bool hasDefaultFillColor = false, hasDefaultOutlineColor = false, hasDefaultOutlineWidth = false;
1607  QgsSvgCache::instance()->containsParams( entry, fillParam, hasDefaultFillColor, fill,
1608  outlineParam, hasDefaultOutlineColor, outline,
1609  outlineWidthParam, hasDefaultOutlineWidth, outlineWidth );
1610 
1611  //if defaults not set in symbol, use these values
1612  if ( !hasDefaultFillColor )
1613  fill = QColor( 200, 200, 200 );
1614  if ( !hasDefaultOutlineColor )
1615  outline = Qt::black;
1616  if ( !hasDefaultOutlineWidth )
1617  outlineWidth = 0.6;
1618 
1619  bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
1620  const QImage& img = QgsSvgCache::instance()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
1621  pixmap = QPixmap::fromImage( img );
1622  QPixmapCache::insert( entry, pixmap );
1623  }
1624 
1625  return pixmap;
1626  }
1627  else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
1628  {
1629  return entry;
1630  }
1631 
1632  return QVariant();
1633  }
1634 
1635  protected:
1637 };
1638 
1640 {
1641  public:
1643  {
1645  QStandardItem *parentItem = invisibleRootItem();
1646 
1647  for ( int i = 0; i < svgPaths.size(); i++ )
1648  {
1649  QDir dir( svgPaths[i] );
1650  QStandardItem *baseGroup;
1651 
1652  if ( dir.path().contains( QgsApplication::pkgDataPath() ) )
1653  {
1654  baseGroup = new QStandardItem( QString( "App Symbols" ) );
1655  }
1656  else if ( dir.path().contains( QgsApplication::qgisSettingsDirPath() ) )
1657  {
1658  baseGroup = new QStandardItem( QString( "User Symbols" ) );
1659  }
1660  else
1661  {
1662  baseGroup = new QStandardItem( dir.dirName() );
1663  }
1664  baseGroup->setData( QVariant( svgPaths[i] ) );
1665  baseGroup->setEditable( false );
1666  baseGroup->setCheckable( false );
1667  baseGroup->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
1668  baseGroup->setToolTip( dir.path() );
1669  parentItem->appendRow( baseGroup );
1670  createTree( baseGroup );
1671  QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
1672  }
1673  }
1674  private:
1675  void createTree( QStandardItem* &parentGroup )
1676  {
1677  QDir parentDir( parentGroup->data().toString() );
1678  Q_FOREACH ( const QString& item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
1679  {
1680  QStandardItem* group = new QStandardItem( item );
1681  group->setData( QVariant( parentDir.path() + "/" + item ) );
1682  group->setEditable( false );
1683  group->setCheckable( false );
1684  group->setToolTip( parentDir.path() + "/" + item );
1685  group->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
1686  parentGroup->appendRow( group );
1687  createTree( group );
1688  }
1689  }
1690 };
1691 
1693 {
1694  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( viewGroups );
1695  viewGroups->setModel( g );
1696  // Set the tree expanded at the first level
1697  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
1698  for ( int i = 0; i < rows; i++ )
1699  {
1700  viewGroups->setExpanded( g->indexFromItem( g->item( i ) ), true );
1701  }
1702 
1703  // Initally load the icons in the List view without any grouping
1704  QgsSvgListModel* m = new QgsSvgListModel( viewImages );
1705  viewImages->setModel( m );
1706 }
1707 
1709 {
1710  QString path = idx.data( Qt::UserRole + 1 ).toString();
1711 
1712  QgsSvgListModel* m = new QgsSvgListModel( viewImages, path );
1713  viewImages->setModel( m );
1714 
1715  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1716  emit changed();
1717 }
1718 
1720 {
1721  if ( !layer )
1722  {
1723  return;
1724  }
1725 
1726  //activate gui for svg parameters only if supported by the svg file
1727  bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
1728  QColor defaultFill, defaultOutline;
1729  double defaultOutlineWidth;
1730  bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
1731  QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, hasDefaultFillColor, defaultFill,
1732  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
1733  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
1734  mChangeColorButton->setEnabled( hasFillParam );
1735  mChangeBorderColorButton->setEnabled( hasOutlineParam );
1736  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
1737 
1738  if ( hasFillParam )
1739  {
1740  if ( layer->fillColor().isValid() )
1741  {
1742  mChangeColorButton->setColor( layer->fillColor() );
1743  }
1744  else if ( hasDefaultFillColor )
1745  {
1746  mChangeColorButton->setColor( defaultFill );
1747  }
1748  }
1749  if ( hasOutlineParam )
1750  {
1751  if ( layer->outlineColor().isValid() )
1752  {
1753  mChangeBorderColorButton->setColor( layer->outlineColor() );
1754  }
1755  else if ( hasDefaultOutlineColor )
1756  {
1757  mChangeBorderColorButton->setColor( defaultOutline );
1758  }
1759  }
1760 
1761  mFileLineEdit->blockSignals( true );
1762  mFileLineEdit->setText( layer->path() );
1763  mFileLineEdit->blockSignals( false );
1764 
1765  mBorderWidthSpinBox->blockSignals( true );
1766  mBorderWidthSpinBox->setValue( layer->outlineWidth() );
1767  mBorderWidthSpinBox->blockSignals( false );
1768 }
1769 
1770 void QgsSvgMarkerSymbolLayerV2Widget::updateAssistantSymbol()
1771 {
1772  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
1773  {
1774  mAssistantPreviewSymbol->deleteSymbolLayer( i );
1775  }
1776  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
1777  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
1778  if ( ddSize )
1779  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
1780 }
1781 
1782 
1784 {
1785  if ( !layer )
1786  {
1787  return;
1788  }
1789 
1790  if ( layer->layerType() != "SvgMarker" )
1791  return;
1792 
1793  // layer type is correct, we can do the cast
1794  mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>( layer );
1795 
1796  // set values
1797 
1798  QAbstractItemModel* m = viewImages->model();
1799  QItemSelectionModel* selModel = viewImages->selectionModel();
1800  for ( int i = 0; i < m->rowCount(); i++ )
1801  {
1802  QModelIndex idx( m->index( i, 0 ) );
1803  if ( m->data( idx ).toString() == mLayer->path() )
1804  {
1805  selModel->select( idx, QItemSelectionModel::SelectCurrent );
1806  selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent );
1807  setName( idx );
1808  break;
1809  }
1810  }
1811 
1812  spinSize->blockSignals( true );
1813  spinSize->setValue( mLayer->size() );
1814  spinSize->blockSignals( false );
1815  spinAngle->blockSignals( true );
1816  spinAngle->setValue( mLayer->angle() );
1817  spinAngle->blockSignals( false );
1818 
1819  // without blocking signals the value gets changed because of slot setOffset()
1820  spinOffsetX->blockSignals( true );
1821  spinOffsetX->setValue( mLayer->offset().x() );
1822  spinOffsetX->blockSignals( false );
1823  spinOffsetY->blockSignals( true );
1824  spinOffsetY->setValue( mLayer->offset().y() );
1825  spinOffsetY->blockSignals( false );
1826 
1827  mSizeUnitWidget->blockSignals( true );
1828  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
1829  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
1830  mSizeUnitWidget->blockSignals( false );
1831  mBorderWidthUnitWidget->blockSignals( true );
1832  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
1833  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
1834  mBorderWidthUnitWidget->blockSignals( false );
1835  mOffsetUnitWidget->blockSignals( true );
1836  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1837  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1838  mOffsetUnitWidget->blockSignals( false );
1839 
1840  //anchor points
1841  mHorizontalAnchorComboBox->blockSignals( true );
1842  mVerticalAnchorComboBox->blockSignals( true );
1843  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1844  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
1845  mHorizontalAnchorComboBox->blockSignals( false );
1846  mVerticalAnchorComboBox->blockSignals( false );
1847 
1848  setGuiForSvg( mLayer );
1849 
1857  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
1858  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
1859 
1860  updateAssistantSymbol();
1861 }
1862 
1864 {
1865  return mLayer;
1866 }
1867 
1869 {
1870  QString name = idx.data( Qt::UserRole ).toString();
1871  mLayer->setPath( name );
1872  mFileLineEdit->setText( name );
1873 
1874  setGuiForSvg( mLayer );
1875  emit changed();
1876 }
1877 
1879 {
1880  mLayer->setSize( spinSize->value() );
1881  emit changed();
1882 }
1883 
1885 {
1886  mLayer->setAngle( spinAngle->value() );
1887  emit changed();
1888 }
1889 
1891 {
1892  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1893  emit changed();
1894 }
1895 
1897 {
1898  QSettings s;
1900  tr( "Select SVG file" ),
1901  s.value( "/UI/lastSVGMarkerDir" ).toString(),
1902  tr( "SVG files" ) + " (*.svg)" );
1903  QFileInfo fi( file );
1904  if ( file.isEmpty() || !fi.exists() )
1905  {
1906  return;
1907  }
1908  mFileLineEdit->setText( file );
1909  mLayer->setPath( file );
1910  s.setValue( "/UI/lastSVGMarkerDir", fi.absolutePath() );
1911  emit changed();
1912 }
1913 
1915 {
1916  if ( !QFileInfo( text ).exists() )
1917  {
1918  return;
1919  }
1920  mLayer->setPath( text );
1921  setGuiForSvg( mLayer );
1922  emit changed();
1923 }
1924 
1926 {
1927  if ( !QFileInfo( mFileLineEdit->text() ).exists() )
1928  {
1929  QUrl url( mFileLineEdit->text() );
1930  if ( !url.isValid() )
1931  {
1932  return;
1933  }
1934  }
1935 
1936  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1937  mLayer->setPath( mFileLineEdit->text() );
1939 
1940  setGuiForSvg( mLayer );
1941  emit changed();
1942 }
1943 
1945 {
1946  if ( !mLayer )
1947  {
1948  return;
1949  }
1950 
1951  mLayer->setFillColor( color );
1952  emit changed();
1953 }
1954 
1956 {
1957  if ( !mLayer )
1958  {
1959  return;
1960  }
1961 
1962  mLayer->setOutlineColor( color );
1963  emit changed();
1964 }
1965 
1967 {
1968  if ( mLayer )
1969  {
1970  mLayer->setOutlineWidth( d );
1971  emit changed();
1972  }
1973 }
1974 
1976 {
1977  if ( mLayer )
1978  {
1979  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
1980  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
1981  emit changed();
1982  }
1983 }
1984 
1986 {
1987  if ( mLayer )
1988  {
1989  mLayer->setOutlineWidthUnit( mBorderWidthUnitWidget->unit() );
1990  mLayer->setOutlineWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
1991  emit changed();
1992  }
1993 }
1994 
1996 {
1997  if ( mLayer )
1998  {
1999  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2000  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2001  emit changed();
2002  }
2003 }
2004 
2006 {
2007  if ( mLayer )
2008  {
2010  emit changed();
2011  }
2012 }
2013 
2015 {
2016  if ( mLayer )
2017  {
2019  emit changed();
2020  }
2021 }
2022 
2024 
2026 {
2027  mLayer = 0;
2028  setupUi( this );
2029  mTextureWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2030  mSvgOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2031  mSvgTreeView->setHeaderHidden( true );
2032  insertIcons();
2033 
2034  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
2035  mChangeColorButton->setContext( "symbology" );
2036  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
2037  mChangeBorderColorButton->setContext( "symbology" );
2038 
2039  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2040  connect( mSvgTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
2041 }
2042 
2044 {
2045  if ( !layer )
2046  {
2047  return;
2048  }
2049 
2050  if ( layer->layerType() != "SVGFill" )
2051  {
2052  return;
2053  }
2054 
2055  mLayer = dynamic_cast<QgsSVGFillSymbolLayer*>( layer );
2056  if ( mLayer )
2057  {
2058  double width = mLayer->patternWidth();
2059  mTextureWidthSpinBox->blockSignals( true );
2060  mTextureWidthSpinBox->setValue( width );
2061  mTextureWidthSpinBox->blockSignals( false );
2062  mSVGLineEdit->setText( mLayer->svgFilePath() );
2063  mRotationSpinBox->blockSignals( true );
2064  mRotationSpinBox->setValue( mLayer->angle() );
2065  mRotationSpinBox->blockSignals( false );
2066  mTextureWidthUnitWidget->blockSignals( true );
2067  mTextureWidthUnitWidget->setUnit( mLayer->patternWidthUnit() );
2068  mTextureWidthUnitWidget->setMapUnitScale( mLayer->patternWidthMapUnitScale() );
2069  mTextureWidthUnitWidget->blockSignals( false );
2070  mSvgOutlineWidthUnitWidget->blockSignals( true );
2071  mSvgOutlineWidthUnitWidget->setUnit( mLayer->svgOutlineWidthUnit() );
2072  mSvgOutlineWidthUnitWidget->setMapUnitScale( mLayer->svgOutlineWidthMapUnitScale() );
2073  mSvgOutlineWidthUnitWidget->blockSignals( false );
2074  mChangeColorButton->blockSignals( true );
2075  mChangeColorButton->setColor( mLayer->svgFillColor() );
2076  mChangeColorButton->blockSignals( false );
2077  mChangeBorderColorButton->blockSignals( true );
2078  mChangeBorderColorButton->setColor( mLayer->svgOutlineColor() );
2079  mChangeBorderColorButton->blockSignals( false );
2080  mBorderWidthSpinBox->blockSignals( true );
2081  mBorderWidthSpinBox->setValue( mLayer->svgOutlineWidth() );
2082  mBorderWidthSpinBox->blockSignals( false );
2083  }
2084  updateParamGui( false );
2085 
2092 }
2093 
2095 {
2096  return mLayer;
2097 }
2098 
2099 void QgsSVGFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2100 {
2101  QString filePath = QFileDialog::getOpenFileName( 0, tr( "Select SVG texture file" ), QString(), tr( "SVG file" ) + " (*.svg);;" + tr( "All files" ) + " (*.*)" );
2102  if ( !filePath.isNull() )
2103  {
2104  mSVGLineEdit->setText( filePath );
2105  emit changed();
2106  }
2107 }
2108 
2109 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthSpinBox_valueChanged( double d )
2110 {
2111  if ( mLayer )
2112  {
2113  mLayer->setPatternWidth( d );
2114  emit changed();
2115  }
2116 }
2117 
2118 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_textEdited( const QString & text )
2119 {
2120  if ( !mLayer )
2121  {
2122  return;
2123  }
2124 
2125  QFileInfo fi( text );
2126  if ( !fi.exists() )
2127  {
2128  return;
2129  }
2130  mLayer->setSvgFilePath( text );
2131  updateParamGui();
2132  emit changed();
2133 }
2134 
2135 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_editingFinished()
2136 {
2137  if ( !mLayer )
2138  {
2139  return;
2140  }
2141 
2142  QFileInfo fi( mSVGLineEdit->text() );
2143  if ( !fi.exists() )
2144  {
2145  QUrl url( mSVGLineEdit->text() );
2146  if ( !url.isValid() )
2147  {
2148  return;
2149  }
2150  }
2151 
2152  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2153  mLayer->setSvgFilePath( mSVGLineEdit->text() );
2155 
2156  updateParamGui();
2157  emit changed();
2158 }
2159 
2160 void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex& item )
2161 {
2162  QString file = item.data( Qt::UserRole ).toString();
2163  mLayer->setSvgFilePath( file );
2164  mSVGLineEdit->setText( file );
2165 
2166  updateParamGui();
2167  emit changed();
2168 }
2169 
2171 {
2172  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( mSvgTreeView );
2173  mSvgTreeView->setModel( g );
2174  // Set the tree expanded at the first level
2175  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2176  for ( int i = 0; i < rows; i++ )
2177  {
2178  mSvgTreeView->setExpanded( g->indexFromItem( g->item( i ) ), true );
2179  }
2180 
2181  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView );
2182  mSvgListView->setModel( m );
2183 }
2184 
2185 void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
2186 {
2187  QString path = idx.data( Qt::UserRole + 1 ).toString();
2188 
2189  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView, path );
2190  mSvgListView->setModel( m );
2191 
2192  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2193  emit changed();
2194 }
2195 
2196 
2197 void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2198 {
2199  if ( mLayer )
2200  {
2201  mLayer->setAngle( d );
2202  emit changed();
2203  }
2204 }
2205 
2207 {
2208  //activate gui for svg parameters only if supported by the svg file
2209  bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
2210  QColor defaultFill, defaultOutline;
2211  double defaultOutlineWidth;
2212  bool hasDefaultFillColor, hasDefaultOutlineColor, hasDefaultOutlineWidth;
2213  QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, hasDefaultFillColor, defaultFill,
2214  hasOutlineParam, hasDefaultOutlineColor, defaultOutline,
2215  hasOutlineWidthParam, hasDefaultOutlineWidth, defaultOutlineWidth );
2216  if ( hasDefaultFillColor && resetValues )
2217  {
2218  mChangeColorButton->setColor( defaultFill );
2219  }
2220  mChangeColorButton->setEnabled( hasFillParam );
2221  if ( hasDefaultOutlineColor && resetValues )
2222  {
2223  mChangeBorderColorButton->setColor( defaultOutline );
2224  }
2225  mChangeBorderColorButton->setEnabled( hasOutlineParam );
2226  if ( hasDefaultOutlineWidth && resetValues )
2227  {
2228  mBorderWidthSpinBox->setValue( defaultOutlineWidth );
2229  }
2230  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
2231 }
2232 
2233 void QgsSVGFillSymbolLayerWidget::on_mChangeColorButton_colorChanged( const QColor& color )
2234 {
2235  if ( !mLayer )
2236  {
2237  return;
2238  }
2239 
2240  mLayer->setSvgFillColor( color );
2241  emit changed();
2242 }
2243 
2244 void QgsSVGFillSymbolLayerWidget::on_mChangeBorderColorButton_colorChanged( const QColor& color )
2245 {
2246  if ( !mLayer )
2247  {
2248  return;
2249  }
2250 
2251  mLayer->setSvgOutlineColor( color );
2252  emit changed();
2253 }
2254 
2255 void QgsSVGFillSymbolLayerWidget::on_mBorderWidthSpinBox_valueChanged( double d )
2256 {
2257  if ( mLayer )
2258  {
2259  mLayer->setSvgOutlineWidth( d );
2260  emit changed();
2261  }
2262 }
2263 
2264 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthUnitWidget_changed()
2265 {
2266  if ( mLayer )
2267  {
2268  mLayer->setPatternWidthUnit( mTextureWidthUnitWidget->unit() );
2269  mLayer->setPatternWidthMapUnitScale( mTextureWidthUnitWidget->getMapUnitScale() );
2270  emit changed();
2271  }
2272 }
2273 
2274 void QgsSVGFillSymbolLayerWidget::on_mSvgOutlineWidthUnitWidget_changed()
2275 {
2276  if ( mLayer )
2277  {
2278  mLayer->setSvgOutlineWidthUnit( mSvgOutlineWidthUnitWidget->unit() );
2279  mLayer->setSvgOutlineWidthMapUnitScale( mSvgOutlineWidthUnitWidget->getMapUnitScale() );
2280  emit changed();
2281  }
2282 }
2283 
2285 
2287  QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
2288 {
2289  setupUi( this );
2290  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2291  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2292  mOffsetSpinBox->setClearValue( 0 );
2293 }
2294 
2296 {
2297  if ( layer->layerType() != "LinePatternFill" )
2298  {
2299  return;
2300  }
2301 
2302  QgsLinePatternFillSymbolLayer* patternLayer = static_cast<QgsLinePatternFillSymbolLayer*>( layer );
2303  if ( patternLayer )
2304  {
2305  mLayer = patternLayer;
2306  mAngleSpinBox->blockSignals( true );
2307  mAngleSpinBox->setValue( mLayer->lineAngle() );
2308  mAngleSpinBox->blockSignals( false );
2309  mDistanceSpinBox->blockSignals( true );
2310  mDistanceSpinBox->setValue( mLayer->distance() );
2311  mDistanceSpinBox->blockSignals( false );
2312  mOffsetSpinBox->blockSignals( true );
2313  mOffsetSpinBox->setValue( mLayer->offset() );
2314  mOffsetSpinBox->blockSignals( false );
2315 
2316  //units
2317  mDistanceUnitWidget->blockSignals( true );
2318  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
2319  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
2320  mDistanceUnitWidget->blockSignals( false );
2321  mOffsetUnitWidget->blockSignals( true );
2322  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2323  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2324  mOffsetUnitWidget->blockSignals( false );
2325  }
2326 
2329 }
2330 
2332 {
2333  return mLayer;
2334 }
2335 
2336 void QgsLinePatternFillSymbolLayerWidget::on_mAngleSpinBox_valueChanged( double d )
2337 {
2338  if ( mLayer )
2339  {
2340  mLayer->setLineAngle( d );
2341  emit changed();
2342  }
2343 }
2344 
2345 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
2346 {
2347  if ( mLayer )
2348  {
2349  mLayer->setDistance( d );
2350  emit changed();
2351  }
2352 }
2353 
2354 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetSpinBox_valueChanged( double d )
2355 {
2356  if ( mLayer )
2357  {
2358  mLayer->setOffset( d );
2359  emit changed();
2360  }
2361 }
2362 
2363 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceUnitWidget_changed()
2364 {
2365  if ( mLayer )
2366  {
2367  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
2368  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
2369  emit changed();
2370  }
2371 }
2372 
2373 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2374 {
2375  if ( mLayer )
2376  {
2377  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2378  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2379  emit changed();
2380  }
2381 }
2382 
2384 
2386  QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
2387 {
2388  setupUi( this );
2389  mHorizontalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2390  mVerticalDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2391  mHorizontalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2392  mVerticalDisplacementUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2393 }
2394 
2395 
2397 {
2398  if ( !layer || layer->layerType() != "PointPatternFill" )
2399  {
2400  return;
2401  }
2402 
2403  mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
2404  mHorizontalDistanceSpinBox->blockSignals( true );
2405  mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
2406  mHorizontalDistanceSpinBox->blockSignals( false );
2407  mVerticalDistanceSpinBox->blockSignals( true );
2408  mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
2409  mVerticalDistanceSpinBox->blockSignals( false );
2410  mHorizontalDisplacementSpinBox->blockSignals( true );
2411  mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
2412  mHorizontalDisplacementSpinBox->blockSignals( false );
2413  mVerticalDisplacementSpinBox->blockSignals( true );
2414  mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
2415  mVerticalDisplacementSpinBox->blockSignals( false );
2416 
2417  mHorizontalDistanceUnitWidget->blockSignals( true );
2418  mHorizontalDistanceUnitWidget->setUnit( mLayer->distanceXUnit() );
2419  mHorizontalDistanceUnitWidget->setMapUnitScale( mLayer->distanceXMapUnitScale() );
2420  mHorizontalDistanceUnitWidget->blockSignals( false );
2421  mVerticalDistanceUnitWidget->blockSignals( true );
2422  mVerticalDistanceUnitWidget->setUnit( mLayer->distanceYUnit() );
2423  mVerticalDistanceUnitWidget->setMapUnitScale( mLayer->distanceYMapUnitScale() );
2424  mVerticalDistanceUnitWidget->blockSignals( false );
2425  mHorizontalDisplacementUnitWidget->blockSignals( true );
2426  mHorizontalDisplacementUnitWidget->setUnit( mLayer->displacementXUnit() );
2427  mHorizontalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementXMapUnitScale() );
2428  mHorizontalDisplacementUnitWidget->blockSignals( false );
2429  mVerticalDisplacementUnitWidget->blockSignals( true );
2430  mVerticalDisplacementUnitWidget->setUnit( mLayer->displacementYUnit() );
2431  mVerticalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementYMapUnitScale() );
2432  mVerticalDisplacementUnitWidget->blockSignals( false );
2433 
2434  registerDataDefinedButton( mHorizontalDistanceDDBtn, "distance_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2436  registerDataDefinedButton( mHorizontalDisplacementDDBtn, "displacement_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2437  registerDataDefinedButton( mVerticalDisplacementDDBtn, "displacement_y", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2438 }
2439 
2441 {
2442  return mLayer;
2443 }
2444 
2445 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged( double d )
2446 {
2447  if ( mLayer )
2448  {
2449  mLayer->setDistanceX( d );
2450  emit changed();
2451  }
2452 }
2453 
2454 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged( double d )
2455 {
2456  if ( mLayer )
2457  {
2458  mLayer->setDistanceY( d );
2459  emit changed();
2460  }
2461 }
2462 
2463 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged( double d )
2464 {
2465  if ( mLayer )
2466  {
2467  mLayer->setDisplacementX( d );
2468  emit changed();
2469  }
2470 }
2471 
2472 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged( double d )
2473 {
2474  if ( mLayer )
2475  {
2476  mLayer->setDisplacementY( d );
2477  emit changed();
2478  }
2479 }
2480 
2481 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceUnitWidget_changed()
2482 {
2483  if ( mLayer )
2484  {
2485  mLayer->setDistanceXUnit( mHorizontalDistanceUnitWidget->unit() );
2486  mLayer->setDistanceXMapUnitScale( mHorizontalDistanceUnitWidget->getMapUnitScale() );
2487  emit changed();
2488  }
2489 }
2490 
2491 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceUnitWidget_changed()
2492 {
2493  if ( mLayer )
2494  {
2495  mLayer->setDistanceYUnit( mVerticalDistanceUnitWidget->unit() );
2496  mLayer->setDistanceYMapUnitScale( mVerticalDistanceUnitWidget->getMapUnitScale() );
2497  emit changed();
2498  }
2499 }
2500 
2501 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementUnitWidget_changed()
2502 {
2503  if ( mLayer )
2504  {
2505  mLayer->setDisplacementXUnit( mHorizontalDisplacementUnitWidget->unit() );
2506  mLayer->setDisplacementXMapUnitScale( mHorizontalDisplacementUnitWidget->getMapUnitScale() );
2507  emit changed();
2508  }
2509 }
2510 
2511 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementUnitWidget_changed()
2512 {
2513  if ( mLayer )
2514  {
2515  mLayer->setDisplacementYUnit( mVerticalDisplacementUnitWidget->unit() );
2516  mLayer->setDisplacementYMapUnitScale( mVerticalDisplacementUnitWidget->getMapUnitScale() );
2517  emit changed();
2518  }
2519 }
2520 
2522 
2524  : QgsSymbolLayerV2Widget( parent, vl )
2525 {
2526  mLayer = NULL;
2527 
2528  setupUi( this );
2530  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2532  scrollArea->setWidget( widgetChar );
2533 
2534  btnColor->setAllowAlpha( true );
2535  btnColor->setColorDialogTitle( tr( "Select symbol color" ) );
2536  btnColor->setContext( "symbology" );
2537 
2538  spinOffsetX->setClearValue( 0.0 );
2539  spinOffsetY->setClearValue( 0.0 );
2540 
2541  //make a temporary symbol for the size assistant preview
2542  mAssistantPreviewSymbol = new QgsMarkerSymbolV2();
2543 
2544  if ( mVectorLayer )
2545  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mVectorLayer, mAssistantPreviewSymbol ) );
2546 
2547  connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
2548  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
2549  connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
2550  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle( double ) ) );
2551  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2552  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2553  connect( widgetChar, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
2554  connect( this, SIGNAL( changed() ), this, SLOT( updateAssistantSymbol() ) );
2555 }
2556 
2558 {
2559  delete mAssistantPreviewSymbol;
2560 }
2561 
2563 {
2564  if ( layer->layerType() != "FontMarker" )
2565  return;
2566 
2567  // layer type is correct, we can do the cast
2568  mLayer = static_cast<QgsFontMarkerSymbolLayerV2*>( layer );
2569 
2570  QFont layerFont( mLayer->fontFamily() );
2571  // set values
2572  cboFont->blockSignals( true );
2573  cboFont->setCurrentFont( layerFont );
2574  cboFont->blockSignals( false );
2575  spinSize->blockSignals( true );
2576  spinSize->setValue( mLayer->size() );
2577  spinSize->blockSignals( false );
2578  btnColor->blockSignals( true );
2579  btnColor->setColor( mLayer->color() );
2580  btnColor->blockSignals( false );
2581  spinAngle->blockSignals( true );
2582  spinAngle->setValue( mLayer->angle() );
2583  spinAngle->blockSignals( false );
2584 
2585  widgetChar->blockSignals( true );
2586  widgetChar->updateFont( layerFont );
2588  widgetChar->blockSignals( false );
2589 
2590  //block
2591  spinOffsetX->blockSignals( true );
2592  spinOffsetX->setValue( mLayer->offset().x() );
2593  spinOffsetX->blockSignals( false );
2594  spinOffsetY->blockSignals( true );
2595  spinOffsetY->setValue( mLayer->offset().y() );
2596  spinOffsetY->blockSignals( false );
2597 
2598  mSizeUnitWidget->blockSignals( true );
2599  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
2600  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
2601  mSizeUnitWidget->blockSignals( false );
2602 
2603  mOffsetUnitWidget->blockSignals( true );
2604  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2605  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2606  mOffsetUnitWidget->blockSignals( false );
2607 
2608  //anchor points
2609  mHorizontalAnchorComboBox->blockSignals( true );
2610  mVerticalAnchorComboBox->blockSignals( true );
2611  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
2612  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
2613  mHorizontalAnchorComboBox->blockSignals( false );
2614  mVerticalAnchorComboBox->blockSignals( false );
2615 
2620  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
2621  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
2623 
2624  updateAssistantSymbol();
2625 }
2626 
2628 {
2629  return mLayer;
2630 }
2631 
2633 {
2634  mLayer->setFontFamily( font.family() );
2635  widgetChar->updateFont( font );
2636  emit changed();
2637 }
2638 
2640 {
2641  mLayer->setColor( color );
2642  emit changed();
2643 }
2644 
2646 {
2647  mLayer->setSize( size );
2648  //widgetChar->updateSize(size);
2649  emit changed();
2650 }
2651 
2653 {
2654  mLayer->setAngle( angle );
2655  emit changed();
2656 }
2657 
2659 {
2660  mLayer->setCharacter( chr );
2661  emit changed();
2662 }
2663 
2665 {
2666  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2667  emit changed();
2668 }
2669 
2671 {
2672  if ( mLayer )
2673  {
2674  mLayer->setSizeUnit( mSizeUnitWidget->unit() );
2675  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2676  emit changed();
2677  }
2678 }
2679 
2681 {
2682  if ( mLayer )
2683  {
2684  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2685  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2686  emit changed();
2687  }
2688 }
2689 
2691 {
2692  if ( mLayer )
2693  {
2695  emit changed();
2696  }
2697 }
2698 
2700 {
2701  if ( mLayer )
2702  {
2704  emit changed();
2705  }
2706 }
2707 
2708 void QgsFontMarkerSymbolLayerV2Widget::updateAssistantSymbol()
2709 {
2710  for ( int i = mAssistantPreviewSymbol->symbolLayerCount() - 1 ; i >= 0; --i )
2711  {
2712  mAssistantPreviewSymbol->deleteSymbolLayer( i );
2713  }
2714  mAssistantPreviewSymbol->appendSymbolLayer( mLayer->clone() );
2715  QgsDataDefined* ddSize = mLayer->getDataDefinedProperty( "size" );
2716  if ( ddSize )
2717  mAssistantPreviewSymbol->setDataDefinedSize( *ddSize );
2718 }
2719 
2721 
2722 
2724  : QgsSymbolLayerV2Widget( parent, vl )
2725 {
2726  mLayer = NULL;
2727 
2728  setupUi( this );
2729 }
2730 
2732 {
2733  if ( layer->layerType() != "CentroidFill" )
2734  return;
2735 
2736  // layer type is correct, we can do the cast
2737  mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
2738 
2739  // set values
2740  mDrawInsideCheckBox->blockSignals( true );
2741  mDrawInsideCheckBox->setChecked( mLayer->pointOnSurface() );
2742  mDrawInsideCheckBox->blockSignals( false );
2743 }
2744 
2746 {
2747  return mLayer;
2748 }
2749 
2751 {
2752  mLayer->setPointOnSurface( state == Qt::Checked );
2753  emit changed();
2754 }
2755 
2757 
2759  : QgsSymbolLayerV2Widget( parent, vl )
2760 {
2761  mLayer = 0;
2762  setupUi( this );
2763 
2765  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
2766 
2767  mSpinOffsetX->setClearValue( 0.0 );
2768  mSpinOffsetY->setClearValue( 0.0 );
2769 
2770  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
2771  connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2772  connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2773 }
2774 
2776 {
2777  if ( !layer )
2778  {
2779  return;
2780  }
2781 
2782  if ( layer->layerType() != "RasterFill" )
2783  {
2784  return;
2785  }
2786 
2787  mLayer = dynamic_cast<QgsRasterFillSymbolLayer*>( layer );
2788  if ( !mLayer )
2789  {
2790  return;
2791  }
2792 
2793  mImageLineEdit->blockSignals( true );
2794  mImageLineEdit->setText( mLayer->imageFilePath() );
2795  mImageLineEdit->blockSignals( false );
2796 
2797  cboCoordinateMode->blockSignals( true );
2798  switch ( mLayer->coordinateMode() )
2799  {
2801  cboCoordinateMode->setCurrentIndex( 1 );
2802  break;
2804  default:
2805  cboCoordinateMode->setCurrentIndex( 0 );
2806  break;
2807  }
2808  cboCoordinateMode->blockSignals( false );
2809  mSpinTransparency->blockSignals( true );
2810  mSpinTransparency->setValue( mLayer->alpha() * 100.0 );
2811  mSpinTransparency->blockSignals( false );
2812  mSliderTransparency->blockSignals( true );
2813  mSliderTransparency->setValue( mLayer->alpha() * 100.0 );
2814  mSliderTransparency->blockSignals( false );
2815  mRotationSpinBox->blockSignals( true );
2816  mRotationSpinBox->setValue( mLayer->angle() );
2817  mRotationSpinBox->blockSignals( false );
2818 
2819  mSpinOffsetX->blockSignals( true );
2820  mSpinOffsetX->setValue( mLayer->offset().x() );
2821  mSpinOffsetX->blockSignals( false );
2822  mSpinOffsetY->blockSignals( true );
2823  mSpinOffsetY->setValue( mLayer->offset().y() );
2824  mSpinOffsetY->blockSignals( false );
2825  mOffsetUnitWidget->blockSignals( true );
2826  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2827  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2828  mOffsetUnitWidget->blockSignals( false );
2829 
2830  mWidthSpinBox->blockSignals( true );
2831  mWidthSpinBox->setValue( mLayer->width() );
2832  mWidthSpinBox->blockSignals( false );
2833  mWidthUnitWidget->blockSignals( true );
2834  mWidthUnitWidget->setUnit( mLayer->widthUnit() );
2835  mWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
2836  mWidthUnitWidget->blockSignals( false );
2837  updatePreviewImage();
2838 
2843 }
2844 
2846 {
2847  return mLayer;
2848 }
2849 
2850 void QgsRasterFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2851 {
2852  QSettings s;
2853  QString openDir;
2854  QString lineEditText = mImageLineEdit->text();
2855  if ( !lineEditText.isEmpty() )
2856  {
2857  QFileInfo openDirFileInfo( lineEditText );
2858  openDir = openDirFileInfo.path();
2859  }
2860 
2861  if ( openDir.isEmpty() )
2862  {
2863  openDir = s.value( "/UI/lastRasterFillImageDir", "" ).toString();
2864  }
2865 
2866  //show file dialog
2867  QString filePath = QFileDialog::getOpenFileName( 0, tr( "Select image file" ), openDir );
2868  if ( !filePath.isNull() )
2869  {
2870  //check if file exists
2871  QFileInfo fileInfo( filePath );
2872  if ( !fileInfo.exists() || !fileInfo.isReadable() )
2873  {
2874  QMessageBox::critical( 0, "Invalid file", "Error, file does not exist or is not readable" );
2875  return;
2876  }
2877 
2878  s.setValue( "/UI/lastRasterFillImageDir", fileInfo.absolutePath() );
2879  mImageLineEdit->setText( filePath );
2880  on_mImageLineEdit_editingFinished();
2881  }
2882 }
2883 
2884 void QgsRasterFillSymbolLayerWidget::on_mImageLineEdit_editingFinished()
2885 {
2886  if ( !mLayer )
2887  {
2888  return;
2889  }
2890 
2891  QFileInfo fi( mImageLineEdit->text() );
2892  if ( !fi.exists() )
2893  {
2894  QUrl url( mImageLineEdit->text() );
2895  if ( !url.isValid() )
2896  {
2897  return;
2898  }
2899  }
2900 
2901  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2902  mLayer->setImageFilePath( mImageLineEdit->text() );
2903  updatePreviewImage();
2905 
2906  emit changed();
2907 }
2908 
2909 void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
2910 {
2911  switch ( index )
2912  {
2913  case 0:
2914  //feature coordinate mode
2916  break;
2917  case 1:
2918  //viewport coordinate mode
2920  break;
2921  }
2922 
2923  emit changed();
2924 }
2925 
2926 void QgsRasterFillSymbolLayerWidget::on_mSpinTransparency_valueChanged( int value )
2927 {
2928  if ( !mLayer )
2929  {
2930  return;
2931  }
2932 
2933  mLayer->setAlpha( value / 100.0 );
2934  emit changed();
2935  updatePreviewImage();
2936 }
2937 
2938 void QgsRasterFillSymbolLayerWidget::offsetChanged()
2939 {
2940  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
2941  emit changed();
2942 }
2943 
2944 void QgsRasterFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2945 {
2946  if ( !mLayer )
2947  {
2948  return;
2949  }
2950  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
2951  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2952  emit changed();
2953 }
2954 
2955 void QgsRasterFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2956 {
2957  if ( mLayer )
2958  {
2959  mLayer->setAngle( d );
2960  emit changed();
2961  }
2962 }
2963 
2964 void QgsRasterFillSymbolLayerWidget::on_mWidthUnitWidget_changed()
2965 {
2966  if ( !mLayer )
2967  {
2968  return;
2969  }
2970  mLayer->setWidthUnit( mWidthUnitWidget->unit() );
2971  mLayer->setWidthMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2972  emit changed();
2973 }
2974 
2975 void QgsRasterFillSymbolLayerWidget::on_mWidthSpinBox_valueChanged( double d )
2976 {
2977  if ( !mLayer )
2978  {
2979  return;
2980  }
2981  mLayer->setWidth( d );
2982  emit changed();
2983 }
2984 
2985 
2986 void QgsRasterFillSymbolLayerWidget::updatePreviewImage()
2987 {
2988  if ( !mLayer )
2989  {
2990  return;
2991  }
2992 
2993  QImage image( mLayer->imageFilePath() );
2994  if ( image.isNull() )
2995  {
2996  mLabelImagePreview->setPixmap( QPixmap() );
2997  return;
2998  }
2999 
3000  if ( image.height() > 150 || image.width() > 150 )
3001  {
3002  image = image.scaled( 150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation );
3003  }
3004 
3005  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
3006  previewImage.fill( Qt::transparent );
3007  QRect imageRect(( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
3008  QPainter p;
3009  p.begin( &previewImage );
3010  //draw a checkerboard background
3011  uchar pixDataRGB[] = { 150, 150, 150, 150,
3012  100, 100, 100, 150,
3013  100, 100, 100, 150,
3014  150, 150, 150, 150
3015  };
3016  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
3017  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
3018  QBrush checkerBrush;
3019  checkerBrush.setTexture( pix );
3020  p.fillRect( imageRect, checkerBrush );
3021 
3022  if ( mLayer->alpha() < 1.0 )
3023  {
3024  p.setOpacity( mLayer->alpha() );
3025  }
3026 
3027  p.drawImage( imageRect.left(), imageRect.top(), image );
3028  p.end();
3029  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
3030 }
void setIntervalUnit(QgsSymbolV2::OutputUnit unit)
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
VerticalAnchorPoint verticalAnchorPoint() const
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's boundary...
void setOutlineStyle(Qt::PenStyle outlineStyle)
QgsSymbolV2::OutputUnit outlineWidthUnit() const
void setMaxDistance(double maxDistance)
Sets the maximum distance to shape inside of the shape from the polygon'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
static QString gradientSpreadDesc()
static unsigned index
QgsSymbolV2::OutputUnit distanceYUnit() const
virtual int rowCount(const QModelIndex &parent) const =0
virtual QgsSymbolLayerV2 * symbolLayer() override
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 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
QgsSVGFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=NULL)
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.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
QgsSvgListModel(QObject *parent, const QString &path)
virtual QgsSymbolLayerV2 * symbolLayer() override
void setCoordinateMode(GradientCoordinateMode coordinateMode)
virtual double width() const
QgsMarkerLineSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QgsGradientFillSymbolLayerV2 * mLayer
QgsSymbolV2::OutputUnit distanceXUnit() const
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
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
QgsSymbolV2::OutputUnit offsetUnit() const
QgsSimpleMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
void setDistanceYUnit(QgsSymbolV2::OutputUnit unit)
QStandardItem * invisibleRootItem() const
QString svgFilePath() const
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.
QgsLinePatternFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=NULL)
QgsSymbolLayerV2 * clone() const override
void setOutlineColor(const QColor &c) override
Set outline color.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
void setCustomDashPatternUnit(QgsSymbolV2::OutputUnit unit)
double svgOutlineWidth() const
void updateFont(const QFont &font)
[0]
QObject * sender() const
QgsLinePatternFillSymbolLayer * mLayer
QgsGradientFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
void setPointOnSurface(bool pointOnSurface)
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:60
Calculate scale by the diameter.
Definition: qgssymbolv2.h:81
const T & at(int i) const
void setOffset(QPointF offset)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
const QgsMapUnitScale & widthMapUnitScale() const
Returns the map unit scale for the image's width.
virtual QgsSymbolLayerV2 * symbolLayer() override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
QgsFontMarkerSymbolLayerV2 * mLayer
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QVector< qreal > customDashVector() const
const QgsMapUnitScale & intervalMapUnitScale() const
void setPenJoinStyle(Qt::PenJoinStyle style)
QgsSymbolLayerV2 * clone() const override
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
void setVerticalAnchorPoint(VerticalAnchorPoint v)
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
GradientCoordinateMode coordinateMode() const
Coordinate mode for gradient.
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
const QPixmap * icon() const
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
QColor fillColor() const override
Get fill color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setSvgOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void on_mVerticalAnchorComboBox_currentIndexChanged(int index)
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()
QgsFontMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
void setMapUnitScale(const QgsMapUnitScale &scale) override
QString tr(const char *sourceText, const char *disambiguation, int n)
QgsSymbolLayerV2 * clone() const override
QgsCentroidFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
void setColorRamp(QgsVectorColorRampV2 *ramp)
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:107
const QgsVectorLayer * mVectorLayer
Qt::PenStyle penStyle() const
void setWidthUnit(QgsSymbolV2::OutputUnit unit)
void setPatternWidth(double width)
QgsRasterFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=NULL)
int size() const
virtual void setData(const QVariant &value, int role)
void init(const QgsVectorLayer *vl, const QgsDataDefined *datadefined=0, const QgsDataDefinedButton::DataTypes &datatypes=AnyType, const QString &description=QString())
Initialize a newly constructed data defined button (useful if button already included from form layou...
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)
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 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.
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)
QgsSymbolV2::OutputUnit distanceUnit() const
Returns the unit for the maximum distance to shade inside of the shape from the polygon'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
QgsSymbolLayerV2 * clone() const override
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
QgsShapeburstFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
The output shall be in millimeters.
Definition: qgssymbolv2.h:57
double offsetAlongLine() const
Returns the offset along the line for the marker placement.
int count(const T &value) const
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit u)
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
void setWidth(const double width)
Sets the width for scaling the image used in the fill.
QModelIndex indexFromItem(const QStandardItem *item) const
QString path() const
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the fill's offset.
void setPenJoinStyle(Qt::PenJoinStyle style)
void setBrushStyle(Qt::BrushStyle style)
void setReferencePoint1IsCentroid(bool isCentroid)
Sets the starting point of the gradient to be the feature centroid.
QgsSimpleLineSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
static QString double180RotDesc()
void setFontFamily(const QString &family)
void setPath(const QString &path)
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)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
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'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.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
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:58
QString imageFilePath() const
The path to the raster image used for the fill.
void setSizeUnit(QgsSymbolV2::OutputUnit unit)
void setOverrideCursor(const QCursor &cursor)
void setDistanceYMapUnitScale(const QgsMapUnitScale &scale)
static QgsExpressionContext _getExpressionContext(const void *context)
const QgsMapUnitScale & sizeMapUnitScale() const
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbolv2.h:122
void restoreOverrideCursor()
QgsSymbolV2::OutputUnit distanceUnit() const
ShapeburstColorType colorType() const
Returns the color mode used for the shapeburst fill.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
QgsSymbolV2::OutputUnit borderWidthUnit() const
QGis::GeometryType geometryType() const
Returns point, line or polygon.
virtual QColor color() const
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
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)
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)
QgsSimpleFillSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
QgsSymbolV2::ScaleMethod scaleMethod() const
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.
const QgsMapUnitScale & displacementYMapUnitScale() const
virtual QgsSymbolLayerV2 * symbolLayer() override
QgsSvgMarkerSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=NULL)
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)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
QgsCentroidFillSymbolLayerV2 * mLayer
QColor svgOutlineColor() const
QStandardItem * item(int row, int column) const
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
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
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
void setBorderColor(const QColor &borderColor)
void on_mFileLineEdit_textEdited(const QString &text)
virtual QgsSymbolLayerV2 * symbolLayer() override
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:361
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.
QgsSymbolV2::OutputUnit outlineWidthUnit() const
QgsSvgListModel(QObject *parent)
A class for svg fill patterns.
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units for the fill's offset.
void setMapUnitScale(const QgsMapUnitScale &scale) override
QVariant value(const QString &key, const QVariant &defaultValue) const
void setBorderColor(const QColor &color)
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the fill's offset.
const QgsMapUnitScale & distanceMapUnitScale() const
void setGradientColorType(GradientColorType gradientColorType)
const QgsMapUnitScale & offsetMapUnitScale() const
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
void setCharacter(const QChar &character)
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:429
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
const QgsMapUnitScale & outlineWidthMapUnitScale() const
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
const QgsMapUnitScale & widthMapUnitScale() const
FillCoordinateMode coordinateMode() const
Coordinate mode for fill.
void setDisplacementYUnit(QgsSymbolV2::OutputUnit unit)
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.
Qt::PenJoinStyle penJoinStyle() const
QgsSvgMarkerSymbolLayerV2 * mLayer
QgsPointPatternFillSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=NULL)
static QString fillStyleDesc()
QPixmap * find(const QString &key)
void setColorRamp(QgsVectorColorRampV2 *ramp)
Sets the color ramp used to draw the shapeburst fill.
void setOffset(const QPointF &offset)
Sets the offset for the fill.
const QgsMapUnitScale & offsetMapUnitScale() const
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
virtual int rowCount(const QModelIndex &parent) const
void on_mHorizontalAnchorComboBox_currentIndexChanged(int index)
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 QStringList svgPaths()
Returns the pathes to svg directories.
virtual void setColor(const QColor &color)
virtual QgsSymbolLayerV2 * symbolLayer()=0
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.
QgsSvgGroupsModel(QObject *parent)
void setCurrentIndex(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
bool setProperty(const char *name, const QVariant &value)
void setMapUnitScale(const QgsMapUnitScale &scale) override
Calculate scale by the area.
Definition: qgssymbolv2.h:80
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setColor2(const QColor &color2)
QgsShapeburstFillSymbolLayerV2 * mLayer
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'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'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)
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)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSize(double size)
static QString customDashDesc()
QObject * parent() const
void setAngle(double angle)
Represents a vector layer which manages a vector based data sets.
bool begin(QPaintDevice *device)
QPointF offset() const
void setReferencePoint2(QPointF referencePoint)
End point of gradient fill, in the range [0,0] - [1,1].
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...
const QgsMapUnitScale & svgOutlineWidthMapUnitScale() const
QString toString() const
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
const QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QColor outlineColor() const override
Get outline color.
void setCheckable(bool checkable)
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's offset.
static QString double0to1Desc()
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QgsSVGFillSymbolLayer * mLayer
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Qt::PenJoinStyle penJoinStyle() const
QgsSimpleFillSymbolLayerV2 * mLayer
static QString colorAlphaDesc()
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Units for gradient fill offset.
QgsSymbolV2::OutputUnit offsetUnit() const
void setName(const QModelIndex &idx)
bool isValid() const
Qt::PenCapStyle penCapStyle() const
double maxDistance() const
Returns the maximum distance from the shape's boundary which is shaded.
void setSvgOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setName(const QString &name)
double alpha() const
The opacity for the raster image used in the fill.
virtual QgsSymbolLayerV2 * symbolLayer() override
virtual Q_DECL_DEPRECATED void setDataDefinedProperty(const QString &property, const QString &expressionString)
Sets a data defined expression for a property.
void setBorderStyle(Qt::PenStyle borderStyle)