QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
32 #include "qgsstylev2.h" //for symbol selector dialog
33 
34 #include "qgsapplication.h"
35 
36 #include "qgslogger.h"
37 
38 #include <QAbstractButton>
39 #include <QColorDialog>
40 #include <QCursor>
41 #include <QDir>
42 #include <QFileDialog>
43 #include <QPainter>
44 #include <QSettings>
45 #include <QStandardItemModel>
46 #include <QSvgRenderer>
47 #include <QMessageBox>
48 
49 void QgsSymbolLayerV2Widget::registerDataDefinedButton( QgsDataDefinedButton * button, const QString & propertyName, QgsDataDefinedButton::DataType type, const QString & description )
50 {
51  QgsDataDefined dd( symbolLayer()->dataDefinedProperty( propertyName ) );
52  button->init( mVectorLayer, &dd, type, description );
53  button->setProperty( "propertyName", propertyName );
54  connect( button, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty() ) );
55  connect( button, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty() ) );
56 }
57 
59 {
60  QgsDataDefinedButton* button = qobject_cast<QgsDataDefinedButton*>( sender() );
61  const QString propertyName( button->property( "propertyName" ).toString() );
62  if ( button->isActive() )
63  symbolLayer()->setDataDefinedProperty( propertyName, button->currentDefinition() );
64  else
65  symbolLayer()->removeDataDefinedProperty( propertyName );
66  emit changed();
67 }
68 
69 QString QgsSymbolLayerV2Widget::dataDefinedPropertyLabel( const QString &entryName )
70 {
71  QString label = entryName;
72  if ( entryName == "size" )
73  {
74  label = tr( "Size" );
75  QgsMarkerSymbolLayerV2 * layer = dynamic_cast<QgsMarkerSymbolLayerV2 *>( symbolLayer() );
76  if ( layer )
77  {
78  switch ( layer->scaleMethod() )
79  {
81  label += " (" + tr( "area" ) + ")";
82  break;
84  label += " (" + tr( "diameter" ) + ")";
85  break;
86  }
87  }
88  }
89  return label;
90 }
91 
93  : QgsSymbolLayerV2Widget( parent, vl )
94 {
95  mLayer = NULL;
96 
97  setupUi( this );
98  mPenWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
99  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
100  mDashPatternUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
101 
102  btnChangeColor->setAllowAlpha( true );
103  btnChangeColor->setColorDialogTitle( tr( "Select line color" ) );
104  btnChangeColor->setContext( "symbology" );
105 
106  spinOffset->setClearValue( 0.0 );
107 
108  if ( vl && vl->geometryType() != QGis::Polygon )
109  {
110  //draw inside polygon checkbox only makes sense for polygon layers
111  mDrawInsideCheckBox->hide();
112  }
113 
114  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
115  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( colorChanged( const QColor& ) ) );
116  connect( cboPenStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
117  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
118  connect( cboCapStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
119  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penStyleChanged() ) );
121 
122 }
123 
125 {
126  if ( !layer || layer->layerType() != "SimpleLine" )
127  return;
128 
129  // layer type is correct, we can do the cast
130  mLayer = static_cast<QgsSimpleLineSymbolLayerV2*>( layer );
131 
132  // set units
133  mPenWidthUnitWidget->blockSignals( true );
134  mPenWidthUnitWidget->setUnit( mLayer->widthUnit() );
135  mPenWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
136  mPenWidthUnitWidget->blockSignals( false );
137  mOffsetUnitWidget->blockSignals( true );
138  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
139  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
140  mOffsetUnitWidget->blockSignals( false );
141  mDashPatternUnitWidget->blockSignals( true );
142  mDashPatternUnitWidget->setUnit( mLayer->customDashPatternUnit() );
143  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
144  mDashPatternUnitWidget->setMapUnitScale( mLayer->customDashPatternMapUnitScale() );
145  mDashPatternUnitWidget->blockSignals( false );
146 
147  // set values
148  spinWidth->blockSignals( true );
149  spinWidth->setValue( mLayer->width() );
150  spinWidth->blockSignals( false );
151  btnChangeColor->blockSignals( true );
152  btnChangeColor->setColor( mLayer->color() );
153  btnChangeColor->blockSignals( false );
154  spinOffset->blockSignals( true );
155  spinOffset->setValue( mLayer->offset() );
156  spinOffset->blockSignals( false );
157  cboPenStyle->blockSignals( true );
158  cboJoinStyle->blockSignals( true );
159  cboCapStyle->blockSignals( true );
160  cboPenStyle->setPenStyle( mLayer->penStyle() );
161  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
162  cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
163  cboPenStyle->blockSignals( false );
164  cboJoinStyle->blockSignals( false );
165  cboCapStyle->blockSignals( false );
166 
167  //use a custom dash pattern?
168  bool useCustomDashPattern = mLayer->useCustomDashPattern();
169  mChangePatternButton->setEnabled( useCustomDashPattern );
170  label_3->setEnabled( !useCustomDashPattern );
171  cboPenStyle->setEnabled( !useCustomDashPattern );
172  mCustomCheckBox->blockSignals( true );
173  mCustomCheckBox->setCheckState( useCustomDashPattern ? Qt::Checked : Qt::Unchecked );
174  mCustomCheckBox->blockSignals( false );
175 
176  //draw inside polygon?
177  bool drawInsidePolygon = mLayer->drawInsidePolygon();
178  mDrawInsideCheckBox->blockSignals( true );
179  mDrawInsideCheckBox->setCheckState( drawInsidePolygon ? Qt::Checked : Qt::Unchecked );
180  mDrawInsideCheckBox->blockSignals( false );
181 
183 
191 }
192 
194 {
195  return mLayer;
196 }
197 
199 {
200  mLayer->setWidth( spinWidth->value() );
202  emit changed();
203 }
204 
206 {
207  mLayer->setColor( color );
209  emit changed();
210 }
211 
213 {
214  mLayer->setPenStyle( cboPenStyle->penStyle() );
215  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
216  mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
217  emit changed();
218 }
219 
221 {
222  mLayer->setOffset( spinOffset->value() );
224  emit changed();
225 }
226 
228 {
229  bool checked = ( state == Qt::Checked );
230  mChangePatternButton->setEnabled( checked );
231  label_3->setEnabled( !checked );
232  cboPenStyle->setEnabled( !checked );
233 
234  mLayer->setUseCustomDashPattern( checked );
235  emit changed();
236 }
237 
239 {
241  if ( d.exec() == QDialog::Accepted )
242  {
243  mLayer->setCustomDashVector( d.dashDotVector() );
245  emit changed();
246  }
247 }
248 
250 {
251  if ( mLayer )
252  {
253  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mPenWidthUnitWidget->getUnit() );
254  mLayer->setWidthUnit( unit );
255  mLayer->setWidthMapUnitScale( mPenWidthUnitWidget->getMapUnitScale() );
256  emit changed();
257  }
258 }
259 
261 {
262  if ( mLayer )
263  {
264  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
265  mLayer->setOffsetUnit( unit );
266  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
267  emit changed();
268  }
269 }
270 
272 {
273  if ( mLayer )
274  {
275  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mDashPatternUnitWidget->getUnit() );
277  mLayer->setCustomDashPatternMapUnitScale( mDashPatternUnitWidget->getMapUnitScale() );
278  emit changed();
279  }
280 }
281 
283 {
284  bool checked = ( state == Qt::Checked );
285  mLayer->setDrawInsidePolygon( checked );
286  emit changed();
287 }
288 
289 
291 {
292  if ( !mLayer )
293  {
294  return;
295  }
296  QgsSimpleLineSymbolLayerV2* layerCopy = dynamic_cast<QgsSimpleLineSymbolLayerV2*>( mLayer->clone() );
297  if ( !layerCopy )
298  {
299  return;
300  }
301  layerCopy->setUseCustomDashPattern( true );
302  QIcon buttonIcon = QgsSymbolLayerV2Utils::symbolLayerPreviewIcon( layerCopy, QgsSymbolV2::MM, mChangePatternButton->iconSize() );
303  mChangePatternButton->setIcon( buttonIcon );
304  delete layerCopy;
305 }
306 
307 
309 
310 
312  : QgsSymbolLayerV2Widget( parent, vl )
313 {
314  mLayer = NULL;
315 
316  setupUi( this );
317  mSizeUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
318  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
319  mOutlineWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
320 
321  btnChangeColorFill->setAllowAlpha( true );
322  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
323  btnChangeColorFill->setContext( "symbology" );
324  btnChangeColorFill->setShowNoColor( true );
325  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
326  btnChangeColorBorder->setAllowAlpha( true );
327  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
328  btnChangeColorBorder->setContext( "symbology" );
329  btnChangeColorBorder->setShowNoColor( true );
330  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
331 
332  spinOffsetX->setClearValue( 0.0 );
333  spinOffsetY->setClearValue( 0.0 );
334 
335  QSize size = lstNames->iconSize();
336  QStringList names;
337  names << "circle" << "rectangle" << "diamond" << "pentagon" << "cross" << "cross2" << "triangle"
338  << "equilateral_triangle" << "star" << "regular_star" << "arrow" << "line" << "arrowhead" << "filled_arrowhead";
339  double markerSize = DEFAULT_POINT_SIZE * 2;
340  for ( int i = 0; i < names.count(); ++i )
341  {
342  QgsSimpleMarkerSymbolLayerV2* lyr = new QgsSimpleMarkerSymbolLayerV2( names[i], QColor( 200, 200, 200 ), QColor( 0, 0, 0 ), markerSize );
344  QListWidgetItem* item = new QListWidgetItem( icon, QString(), lstNames );
345  item->setData( Qt::UserRole, names[i] );
346  delete lyr;
347  }
348 
349  connect( lstNames, SIGNAL( currentRowChanged( int ) ), this, SLOT( setName() ) );
350  connect( btnChangeColorBorder, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorBorder( const QColor& ) ) );
351  connect( btnChangeColorFill, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColorFill( const QColor& ) ) );
352  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
353  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
354  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
355  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
356 }
357 
359 {
360  if ( layer->layerType() != "SimpleMarker" )
361  return;
362 
363  // layer type is correct, we can do the cast
364  mLayer = static_cast<QgsSimpleMarkerSymbolLayerV2*>( layer );
365 
366  // set values
367  QString name = mLayer->name();
368  for ( int i = 0; i < lstNames->count(); ++i )
369  {
370  if ( lstNames->item( i )->data( Qt::UserRole ).toString() == name )
371  {
372  lstNames->setCurrentRow( i );
373  break;
374  }
375  }
376  btnChangeColorBorder->blockSignals( true );
377  btnChangeColorBorder->setColor( mLayer->borderColor() );
378  btnChangeColorBorder->blockSignals( false );
379  btnChangeColorFill->blockSignals( true );
380  btnChangeColorFill->setColor( mLayer->color() );
381  btnChangeColorFill->blockSignals( false );
382  spinSize->blockSignals( true );
383  spinSize->setValue( mLayer->size() );
384  spinSize->blockSignals( false );
385  spinAngle->blockSignals( true );
386  spinAngle->setValue( mLayer->angle() );
387  spinAngle->blockSignals( false );
388  mOutlineStyleComboBox->blockSignals( true );
389  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
390  mOutlineStyleComboBox->blockSignals( false );
391  mOutlineWidthSpinBox->blockSignals( true );
392  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
393  mOutlineWidthSpinBox->blockSignals( false );
394 
395  // without blocking signals the value gets changed because of slot setOffset()
396  spinOffsetX->blockSignals( true );
397  spinOffsetX->setValue( mLayer->offset().x() );
398  spinOffsetX->blockSignals( false );
399  spinOffsetY->blockSignals( true );
400  spinOffsetY->setValue( mLayer->offset().y() );
401  spinOffsetY->blockSignals( false );
402 
403  mSizeUnitWidget->blockSignals( true );
404  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
405  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
406  mSizeUnitWidget->blockSignals( false );
407  mOffsetUnitWidget->blockSignals( true );
408  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
409  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
410  mOffsetUnitWidget->blockSignals( false );
411  mOutlineWidthUnitWidget->blockSignals( true );
412  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
413  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
414  mOutlineWidthUnitWidget->blockSignals( false );
415 
416  //anchor points
417  mHorizontalAnchorComboBox->blockSignals( true );
418  mVerticalAnchorComboBox->blockSignals( true );
419  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
420  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
421  mHorizontalAnchorComboBox->blockSignals( false );
422  mVerticalAnchorComboBox->blockSignals( false );
423 
424  registerDataDefinedButton( mNameDDBtn, "name", QgsDataDefinedButton::String, tr( "string " ) + QString( "[<b>square</b>|<b>rectangle</b>|<b>diamond</b>|"
425  "<b>pentagon</b>|<b>triangle</b>|<b>equilateral_triangle</b>|"
426  "<b>star</b>|<b>regular_star</b>|<b>arrow</b>|<b>filled_arrowhead</b>|"
427  "<b>circle</b>|<b>cross</b>|<b>x</b>|"
428  "<b>cross2</b>|<b>line</b>|<b>arrowhead</b>]" ) );
436  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
437  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
438 }
439 
441 {
442  return mLayer;
443 }
444 
446 {
447  mLayer->setName( lstNames->currentItem()->data( Qt::UserRole ).toString() );
448  emit changed();
449 }
450 
452 {
453  mLayer->setBorderColor( color );
454  emit changed();
455 }
456 
458 {
459  mLayer->setColor( color );
460  emit changed();
461 }
462 
464 {
465  mLayer->setSize( spinSize->value() );
466  emit changed();
467 }
468 
470 {
471  mLayer->setAngle( spinAngle->value() );
472  emit changed();
473 }
474 
476 {
477  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
478  emit changed();
479 }
480 
482 {
483  Q_UNUSED( index );
484 
485  if ( mLayer )
486  {
487  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
488  emit changed();
489  }
490 }
491 
493 {
494  if ( mLayer )
495  {
496  mLayer->setOutlineWidth( d );
497  emit changed();
498  }
499 }
500 
502 {
503  if ( mLayer )
504  {
505  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSizeUnitWidget->getUnit() );
506  mLayer->setSizeUnit( unit );
507  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
508  emit changed();
509  }
510 }
511 
513 {
514  if ( mLayer )
515  {
516  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
517  mLayer->setOffsetUnit( unit );
518  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
519  emit changed();
520  }
521 }
522 
524 {
525  if ( mLayer )
526  {
527  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOutlineWidthUnitWidget->getUnit() );
528  mLayer->setOutlineWidthUnit( unit );
529  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
530  emit changed();
531  }
532 }
533 
535 {
536  if ( mLayer )
537  {
539  emit changed();
540  }
541 }
542 
544 {
545  if ( mLayer )
546  {
548  emit changed();
549  }
550 }
551 
552 
554 
556  : QgsSymbolLayerV2Widget( parent, vl )
557 {
558  mLayer = NULL;
559 
560  setupUi( this );
561  mBorderWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
562  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
563 
564  btnChangeColor->setAllowAlpha( true );
565  btnChangeColor->setColorDialogTitle( tr( "Select fill color" ) );
566  btnChangeColor->setContext( "symbology" );
567  btnChangeColor->setShowNoColor( true );
568  btnChangeColor->setNoColorString( tr( "Transparent fill" ) );
569  btnChangeBorderColor->setAllowAlpha( true );
570  btnChangeBorderColor->setColorDialogTitle( tr( "Select border color" ) );
571  btnChangeBorderColor->setContext( "symbology" );
572  btnChangeBorderColor->setShowNoColor( true );
573  btnChangeBorderColor->setNoColorString( tr( "Transparent border" ) );
574 
575  spinOffsetX->setClearValue( 0.0 );
576  spinOffsetY->setClearValue( 0.0 );
577 
578  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
579  connect( cboFillStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setBrushStyle() ) );
580  connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
581  connect( spinBorderWidth, SIGNAL( valueChanged( double ) ), this, SLOT( borderWidthChanged() ) );
582  connect( cboBorderStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
583  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
584  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
585  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
586 }
587 
589 {
590  if ( layer->layerType() != "SimpleFill" )
591  return;
592 
593  // layer type is correct, we can do the cast
594  mLayer = static_cast<QgsSimpleFillSymbolLayerV2*>( layer );
595 
596  // set values
597  btnChangeColor->blockSignals( true );
598  btnChangeColor->setColor( mLayer->color() );
599  btnChangeColor->blockSignals( false );
600  cboFillStyle->blockSignals( true );
601  cboFillStyle->setBrushStyle( mLayer->brushStyle() );
602  cboFillStyle->blockSignals( false );
603  btnChangeBorderColor->blockSignals( true );
604  btnChangeBorderColor->setColor( mLayer->borderColor() );
605  btnChangeBorderColor->blockSignals( false );
606  cboBorderStyle->blockSignals( true );
607  cboBorderStyle->setPenStyle( mLayer->borderStyle() );
608  cboBorderStyle->blockSignals( false );
609  spinBorderWidth->blockSignals( true );
610  spinBorderWidth->setValue( mLayer->borderWidth() );
611  spinBorderWidth->blockSignals( false );
612  cboJoinStyle->blockSignals( true );
613  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
614  cboJoinStyle->blockSignals( false );
615  spinOffsetX->blockSignals( true );
616  spinOffsetX->setValue( mLayer->offset().x() );
617  spinOffsetX->blockSignals( false );
618  spinOffsetY->blockSignals( true );
619  spinOffsetY->setValue( mLayer->offset().y() );
620  spinOffsetY->blockSignals( false );
621 
622  mBorderWidthUnitWidget->blockSignals( true );
623  mBorderWidthUnitWidget->setUnit( mLayer->borderWidthUnit() );
624  mBorderWidthUnitWidget->setMapUnitScale( mLayer->borderWidthMapUnitScale() );
625  mBorderWidthUnitWidget->blockSignals( false );
626  mOffsetUnitWidget->blockSignals( true );
627  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
628  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
629  mOffsetUnitWidget->blockSignals( false );
630 
637 
638 }
639 
641 {
642  return mLayer;
643 }
644 
646 {
647  mLayer->setColor( color );
648  emit changed();
649 }
650 
652 {
653  mLayer->setBorderColor( color );
654  emit changed();
655 }
656 
658 {
659  mLayer->setBrushStyle( cboFillStyle->brushStyle() );
660  emit changed();
661 }
662 
664 {
665  mLayer->setBorderWidth( spinBorderWidth->value() );
666  emit changed();
667 }
668 
670 {
671  mLayer->setBorderStyle( cboBorderStyle->penStyle() );
672  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
673  emit changed();
674 }
675 
677 {
678  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
679  emit changed();
680 }
681 
683 {
684  if ( mLayer )
685  {
686  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mBorderWidthUnitWidget->getUnit() );
687  mLayer->setBorderWidthUnit( unit );
688  mLayer->setBorderWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
689  emit changed();
690  }
691 }
692 
694 {
695  if ( mLayer )
696  {
697  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
698  mLayer->setOffsetUnit( unit );
699  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
700  emit changed();
701  }
702 }
703 
705 
707  : QgsSymbolLayerV2Widget( parent, vl )
708 {
709  mLayer = NULL;
710 
711  setupUi( this );
712  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
713 
714  cboGradientColorRamp->setShowGradientOnly( true );
715  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
716 
717  btnChangeColor->setAllowAlpha( true );
718  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
719  btnChangeColor->setContext( "symbology" );
720  btnChangeColor->setShowNoColor( true );
721  btnChangeColor->setNoColorString( tr( "Transparent" ) );
722  btnChangeColor2->setAllowAlpha( true );
723  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
724  btnChangeColor2->setContext( "symbology" );
725  btnChangeColor2->setShowNoColor( true );
726  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
727 
728  spinOffsetX->setClearValue( 0.0 );
729  spinOffsetY->setClearValue( 0.0 );
730 
731  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
732  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
733  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
734  connect( cboGradientType, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientType( int ) ) );
735  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
736  connect( cboGradientSpread, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setGradientSpread( int ) ) );
737  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
738  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
739  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
740  connect( spinRefPoint1X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
741  connect( spinRefPoint1Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
742  connect( checkRefPoint1Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
743  connect( spinRefPoint2X, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
744  connect( spinRefPoint2Y, SIGNAL( valueChanged( double ) ), this, SLOT( referencePointChanged() ) );
745  connect( checkRefPoint2Centroid, SIGNAL( toggled( bool ) ), this, SLOT( referencePointChanged() ) );
746 }
747 
749 {
750  if ( layer->layerType() != "GradientFill" )
751  return;
752 
753  // layer type is correct, we can do the cast
754  mLayer = static_cast<QgsGradientFillSymbolLayerV2*>( layer );
755 
756  // set values
757  btnChangeColor->blockSignals( true );
758  btnChangeColor->setColor( mLayer->color() );
759  btnChangeColor->blockSignals( false );
760  btnChangeColor2->blockSignals( true );
761  btnChangeColor2->setColor( mLayer->color2() );
762  btnChangeColor2->blockSignals( false );
763 
765  {
766  radioTwoColor->setChecked( true );
767  cboGradientColorRamp->setEnabled( false );
768  }
769  else
770  {
771  radioColorRamp->setChecked( true );
772  btnChangeColor->setEnabled( false );
773  btnChangeColor2->setEnabled( false );
774  }
775 
776  // set source color ramp
777  if ( mLayer->colorRamp() )
778  {
779  cboGradientColorRamp->blockSignals( true );
780  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
781  cboGradientColorRamp->blockSignals( false );
782  }
783 
784  cboGradientType->blockSignals( true );
785  switch ( mLayer->gradientType() )
786  {
788  cboGradientType->setCurrentIndex( 0 );
789  break;
791  cboGradientType->setCurrentIndex( 1 );
792  break;
794  cboGradientType->setCurrentIndex( 2 );
795  break;
796  }
797  cboGradientType->blockSignals( false );
798 
799  cboCoordinateMode->blockSignals( true );
800  switch ( mLayer->coordinateMode() )
801  {
803  cboCoordinateMode->setCurrentIndex( 1 );
804  checkRefPoint1Centroid->setEnabled( false );
805  checkRefPoint2Centroid->setEnabled( false );
806  break;
808  default:
809  cboCoordinateMode->setCurrentIndex( 0 );
810  break;
811  }
812  cboCoordinateMode->blockSignals( false );
813 
814  cboGradientSpread->blockSignals( true );
815  switch ( mLayer->gradientSpread() )
816  {
818  cboGradientSpread->setCurrentIndex( 0 );
819  break;
821  cboGradientSpread->setCurrentIndex( 1 );
822  break;
824  cboGradientSpread->setCurrentIndex( 2 );
825  break;
826  }
827  cboGradientSpread->blockSignals( false );
828 
829  spinRefPoint1X->blockSignals( true );
830  spinRefPoint1X->setValue( mLayer->referencePoint1().x() );
831  spinRefPoint1X->blockSignals( false );
832  spinRefPoint1Y->blockSignals( true );
833  spinRefPoint1Y->setValue( mLayer->referencePoint1().y() );
834  spinRefPoint1Y->blockSignals( false );
835  checkRefPoint1Centroid->blockSignals( true );
836  checkRefPoint1Centroid->setChecked( mLayer->referencePoint1IsCentroid() );
838  {
839  spinRefPoint1X->setEnabled( false );
840  spinRefPoint1Y->setEnabled( false );
841  }
842  checkRefPoint1Centroid->blockSignals( false );
843  spinRefPoint2X->blockSignals( true );
844  spinRefPoint2X->setValue( mLayer->referencePoint2().x() );
845  spinRefPoint2X->blockSignals( false );
846  spinRefPoint2Y->blockSignals( true );
847  spinRefPoint2Y->setValue( mLayer->referencePoint2().y() );
848  spinRefPoint2Y->blockSignals( false );
849  checkRefPoint2Centroid->blockSignals( true );
850  checkRefPoint2Centroid->setChecked( mLayer->referencePoint2IsCentroid() );
852  {
853  spinRefPoint2X->setEnabled( false );
854  spinRefPoint2Y->setEnabled( false );
855  }
856  checkRefPoint2Centroid->blockSignals( false );
857 
858  spinOffsetX->blockSignals( true );
859  spinOffsetX->setValue( mLayer->offset().x() );
860  spinOffsetX->blockSignals( false );
861  spinOffsetY->blockSignals( true );
862  spinOffsetY->setValue( mLayer->offset().y() );
863  spinOffsetY->blockSignals( false );
864  mSpinAngle->blockSignals( true );
865  mSpinAngle->setValue( mLayer->angle() );
866  mSpinAngle->blockSignals( false );
867 
868  mOffsetUnitWidget->blockSignals( true );
869  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
870  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
871  mOffsetUnitWidget->blockSignals( false );
872 
881  registerDataDefinedButton( mRefPoint1CentroidDDBtn, "reference1_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
884  registerDataDefinedButton( mRefPoint2CentroidDDBtn, "reference2_iscentroid", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
885 }
886 
888 {
889  return mLayer;
890 }
891 
893 {
894  mLayer->setColor( color );
895  emit changed();
896 }
897 
899 {
900  mLayer->setColor2( color );
901  emit changed();
902 }
903 
905 {
906  if ( radioTwoColor->isChecked() )
907  {
909  }
910  else
911  {
913  }
914  emit changed();
915 }
916 
918 {
919  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
920  if ( ramp == NULL )
921  return;
922 
923  mLayer->setColorRamp( ramp );
924  emit changed();
925 }
926 
928 {
929  if ( mLayer->colorRamp()->type() == "gradient" )
930  {
932  QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
933  QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
934 
935  if ( dlg.exec() && gradRamp )
936  {
937  mLayer->setColorRamp( gradRamp );
938  cboGradientColorRamp->blockSignals( true );
939  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
940  cboGradientColorRamp->blockSignals( false );
941  emit changed();
942  }
943  else
944  {
945  delete ramp;
946  }
947  }
948 }
949 
951 {
952  switch ( index )
953  {
954  case 0:
956  //set sensible default reference points
957  spinRefPoint1X->setValue( 0.5 );
958  spinRefPoint1Y->setValue( 0 );
959  spinRefPoint2X->setValue( 0.5 );
960  spinRefPoint2Y->setValue( 1 );
961  break;
962  case 1:
964  //set sensible default reference points
965  spinRefPoint1X->setValue( 0 );
966  spinRefPoint1Y->setValue( 0 );
967  spinRefPoint2X->setValue( 1 );
968  spinRefPoint2Y->setValue( 1 );
969  break;
970  case 2:
972  spinRefPoint1X->setValue( 0.5 );
973  spinRefPoint1Y->setValue( 0.5 );
974  spinRefPoint2X->setValue( 1 );
975  spinRefPoint2Y->setValue( 1 );
976  break;
977  }
978  emit changed();
979 }
980 
982 {
983 
984  switch ( index )
985  {
986  case 0:
987  //feature coordinate mode
989  //allow choice of centroid reference positions
990  checkRefPoint1Centroid->setEnabled( true );
991  checkRefPoint2Centroid->setEnabled( true );
992  break;
993  case 1:
994  //viewport coordinate mode
996  //disable choice of centroid reference positions
997  checkRefPoint1Centroid->setChecked( Qt::Unchecked );
998  checkRefPoint1Centroid->setEnabled( false );
999  checkRefPoint2Centroid->setChecked( Qt::Unchecked );
1000  checkRefPoint2Centroid->setEnabled( false );
1001  break;
1002  }
1003 
1004  emit changed();
1005 }
1006 
1008 {
1009  switch ( index )
1010  {
1011  case 0:
1013  break;
1014  case 1:
1016  break;
1017  case 2:
1019  break;
1020  }
1021 
1022  emit changed();
1023 }
1024 
1026 {
1027  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1028  emit changed();
1029 }
1030 
1032 {
1033  mLayer->setReferencePoint1( QPointF( spinRefPoint1X->value(), spinRefPoint1Y->value() ) );
1034  mLayer->setReferencePoint1IsCentroid( checkRefPoint1Centroid->isChecked() );
1035  mLayer->setReferencePoint2( QPointF( spinRefPoint2X->value(), spinRefPoint2Y->value() ) );
1036  mLayer->setReferencePoint2IsCentroid( checkRefPoint2Centroid->isChecked() );
1037  emit changed();
1038 }
1039 
1041 {
1042  mLayer->setAngle( value );
1043  emit changed();
1044 }
1045 
1047 {
1048  if ( mLayer )
1049  {
1050  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
1051  mLayer->setOffsetUnit( unit );
1052  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1053  emit changed();
1054  }
1055 }
1056 
1058 
1060  : QgsSymbolLayerV2Widget( parent, vl )
1061 {
1062  mLayer = NULL;
1063 
1064  setupUi( this );
1065  mDistanceUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1066  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1067 
1068  btnChangeColor->setAllowAlpha( true );
1069  btnChangeColor->setColorDialogTitle( tr( "Select gradient color" ) );
1070  btnChangeColor->setContext( "symbology" );
1071  btnChangeColor->setShowNoColor( true );
1072  btnChangeColor->setNoColorString( tr( "Transparent" ) );
1073  btnChangeColor2->setAllowAlpha( true );
1074  btnChangeColor2->setColorDialogTitle( tr( "Select gradient color" ) );
1075  btnChangeColor2->setContext( "symbology" );
1076  btnChangeColor2->setShowNoColor( true );
1077  btnChangeColor2->setNoColorString( tr( "Transparent" ) );
1078 
1079  spinOffsetX->setClearValue( 0.0 );
1080  spinOffsetY->setClearValue( 0.0 );
1081 
1082  cboGradientColorRamp->setShowGradientOnly( true );
1083  cboGradientColorRamp->populate( QgsStyleV2::defaultStyle() );
1084 
1085  connect( cboGradientColorRamp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( applyColorRamp() ) );
1086  connect( btnChangeColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
1087  connect( btnChangeColor2, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor2( const QColor& ) ) );
1088  connect( radioTwoColor, SIGNAL( toggled( bool ) ), this, SLOT( colorModeChanged() ) );
1089  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1090  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
1091 
1092  connect( mBlurSlider, SIGNAL( valueChanged( int ) ), mSpinBlurRadius, SLOT( setValue( int ) ) );
1093  connect( mSpinBlurRadius, SIGNAL( valueChanged( int ) ), mBlurSlider, SLOT( setValue( int ) ) );
1094 }
1095 
1097 {
1098  if ( layer->layerType() != "ShapeburstFill" )
1099  return;
1100 
1101  // layer type is correct, we can do the cast
1102  mLayer = static_cast<QgsShapeburstFillSymbolLayerV2*>( layer );
1103 
1104  // set values
1105  btnChangeColor->blockSignals( true );
1106  btnChangeColor->setColor( mLayer->color() );
1107  btnChangeColor->blockSignals( false );
1108  btnChangeColor2->blockSignals( true );
1109  btnChangeColor2->setColor( mLayer->color2() );
1110  btnChangeColor2->blockSignals( false );
1111 
1113  {
1114  radioTwoColor->setChecked( true );
1115  cboGradientColorRamp->setEnabled( false );
1116  }
1117  else
1118  {
1119  radioColorRamp->setChecked( true );
1120  btnChangeColor->setEnabled( false );
1121  btnChangeColor2->setEnabled( false );
1122  }
1123 
1124  mSpinBlurRadius->blockSignals( true );
1125  mBlurSlider->blockSignals( true );
1126  mSpinBlurRadius->setValue( mLayer->blurRadius() );
1127  mBlurSlider->setValue( mLayer->blurRadius() );
1128  mSpinBlurRadius->blockSignals( false );
1129  mBlurSlider->blockSignals( false );
1130 
1131  mSpinMaxDistance->blockSignals( true );
1132  mSpinMaxDistance->setValue( mLayer->maxDistance() );
1133  mSpinMaxDistance->blockSignals( false );
1134 
1135  mRadioUseWholeShape->blockSignals( true );
1136  mRadioUseMaxDistance->blockSignals( true );
1137  if ( mLayer->useWholeShape() )
1138  {
1139  mRadioUseWholeShape->setChecked( true );
1140  mSpinMaxDistance->setEnabled( false );
1141  mDistanceUnitWidget->setEnabled( false );
1142  }
1143  else
1144  {
1145  mRadioUseMaxDistance->setChecked( true );
1146  mSpinMaxDistance->setEnabled( true );
1147  mDistanceUnitWidget->setEnabled( true );
1148  }
1149  mRadioUseWholeShape->blockSignals( false );
1150  mRadioUseMaxDistance->blockSignals( false );
1151 
1152  mDistanceUnitWidget->blockSignals( true );
1153  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
1154  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
1155  mDistanceUnitWidget->blockSignals( false );
1156 
1157  mIgnoreRingsCheckBox->blockSignals( true );
1158  mIgnoreRingsCheckBox->setCheckState( mLayer->ignoreRings() ? Qt::Checked : Qt::Unchecked );
1159  mIgnoreRingsCheckBox->blockSignals( false );
1160 
1161  // set source color ramp
1162  if ( mLayer->colorRamp() )
1163  {
1164  cboGradientColorRamp->blockSignals( true );
1165  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1166  cboGradientColorRamp->blockSignals( false );
1167  }
1168 
1169  spinOffsetX->blockSignals( true );
1170  spinOffsetX->setValue( mLayer->offset().x() );
1171  spinOffsetX->blockSignals( false );
1172  spinOffsetY->blockSignals( true );
1173  spinOffsetY->setValue( mLayer->offset().y() );
1174  spinOffsetY->blockSignals( false );
1175  mOffsetUnitWidget->blockSignals( true );
1176  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1177  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1178  mOffsetUnitWidget->blockSignals( false );
1179 
1182  registerDataDefinedButton( mBlurRadiusDDBtn, "blur_radius", QgsDataDefinedButton::Int, tr( "Integer between 0 and 18" ) );
1183  registerDataDefinedButton( mShadeWholeShapeDDBtn, "use_whole_shape", QgsDataDefinedButton::Int, QgsDataDefinedButton::boolDesc() );
1186 }
1187 
1189 {
1190  return mLayer;
1191 }
1192 
1194 {
1195  if ( mLayer )
1196  {
1197  mLayer->setColor( color );
1198  emit changed();
1199  }
1200 }
1201 
1203 {
1204  if ( mLayer )
1205  {
1206  mLayer->setColor2( color );
1207  emit changed();
1208  }
1209 }
1210 
1212 {
1213  if ( !mLayer )
1214  {
1215  return;
1216  }
1217 
1218  if ( radioTwoColor->isChecked() )
1219  {
1221  }
1222  else
1223  {
1225  }
1226  emit changed();
1227 }
1228 
1230 {
1231  if ( mLayer )
1232  {
1233  mLayer->setBlurRadius( value );
1234  emit changed();
1235  }
1236 }
1237 
1239 {
1240  if ( mLayer )
1241  {
1242  mLayer->setMaxDistance( value );
1243  emit changed();
1244  }
1245 }
1246 
1248 {
1249  if ( mLayer )
1250  {
1251  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mDistanceUnitWidget->getUnit() );
1252  mLayer->setDistanceUnit( unit );
1253  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
1254  emit changed();
1255  }
1256 }
1257 
1259 {
1260  if ( mLayer )
1261  {
1262  mLayer->setUseWholeShape( value );
1263  mDistanceUnitWidget->setEnabled( !value );
1264  emit changed();
1265  }
1266 }
1267 
1269 {
1270  QgsVectorColorRampV2* ramp = cboGradientColorRamp->currentColorRamp();
1271  if ( ramp == NULL )
1272  return;
1273 
1274  mLayer->setColorRamp( ramp );
1275  emit changed();
1276 }
1277 
1279 {
1280  if ( mLayer->colorRamp()->type() == "gradient" )
1281  {
1283  QgsVectorGradientColorRampV2* gradRamp = static_cast<QgsVectorGradientColorRampV2*>( ramp );
1284  QgsVectorGradientColorRampV2Dialog dlg( gradRamp, this );
1285 
1286  if ( dlg.exec() && gradRamp )
1287  {
1288  mLayer->setColorRamp( gradRamp );
1289  cboGradientColorRamp->blockSignals( true );
1290  cboGradientColorRamp->setSourceColorRamp( mLayer->colorRamp() );
1291  cboGradientColorRamp->blockSignals( false );
1292  emit changed();
1293  }
1294  else
1295  {
1296  delete ramp;
1297  }
1298  }
1299 }
1300 
1302 {
1303  if ( mLayer )
1304  {
1305  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1306  emit changed();
1307  }
1308 }
1309 
1311 {
1312  if ( mLayer )
1313  {
1314  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
1315  mLayer->setOffsetUnit( unit );
1316  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1317  emit changed();
1318  }
1319 }
1320 
1321 
1323 {
1324  bool checked = ( state == Qt::Checked );
1325  mLayer->setIgnoreRings( checked );
1326  emit changed();
1327 }
1328 
1330 
1332  : QgsSymbolLayerV2Widget( parent, vl )
1333 {
1334  mLayer = NULL;
1335 
1336  setupUi( this );
1337  mIntervalUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1338  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1339  mOffsetAlongLineUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1340 
1341  spinOffset->setClearValue( 0.0 );
1342 
1343  connect( spinInterval, SIGNAL( valueChanged( double ) ), this, SLOT( setInterval( double ) ) );
1344  connect( mSpinOffsetAlongLine, SIGNAL( valueChanged( double ) ), this, SLOT( setOffsetAlongLine( double ) ) );
1345  connect( chkRotateMarker, SIGNAL( clicked() ), this, SLOT( setRotate() ) );
1346  connect( spinOffset, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1347  connect( radInterval, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1348  connect( radVertex, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1349  connect( radVertexLast, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1350  connect( radVertexFirst, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1351  connect( radCentralPoint, SIGNAL( clicked() ), this, SLOT( setPlacement() ) );
1352 }
1353 
1355 {
1356  if ( layer->layerType() != "MarkerLine" )
1357  return;
1358 
1359  // layer type is correct, we can do the cast
1360  mLayer = static_cast<QgsMarkerLineSymbolLayerV2*>( layer );
1361 
1362  // set values
1363  spinInterval->blockSignals( true );
1364  spinInterval->setValue( mLayer->interval() );
1365  spinInterval->blockSignals( false );
1366  mSpinOffsetAlongLine->blockSignals( true );
1367  mSpinOffsetAlongLine->setValue( mLayer->offsetAlongLine() );
1368  mSpinOffsetAlongLine->blockSignals( false );
1369  chkRotateMarker->blockSignals( true );
1370  chkRotateMarker->setChecked( mLayer->rotateMarker() );
1371  chkRotateMarker->blockSignals( false );
1372  spinOffset->blockSignals( true );
1373  spinOffset->setValue( mLayer->offset() );
1374  spinOffset->blockSignals( false );
1376  radInterval->setChecked( true );
1378  radVertex->setChecked( true );
1380  radVertexLast->setChecked( true );
1382  radCentralPoint->setChecked( true );
1383  else
1384  radVertexFirst->setChecked( true );
1385 
1386  // set units
1387  mIntervalUnitWidget->blockSignals( true );
1388  mIntervalUnitWidget->setUnit( mLayer->intervalUnit() );
1389  mIntervalUnitWidget->setMapUnitScale( mLayer->intervalMapUnitScale() );
1390  mIntervalUnitWidget->blockSignals( false );
1391  mOffsetUnitWidget->blockSignals( true );
1392  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1393  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1394  mOffsetUnitWidget->blockSignals( false );
1395  mOffsetAlongLineUnitWidget->blockSignals( true );
1396  mOffsetAlongLineUnitWidget->setUnit( mLayer->offsetAlongLineUnit() );
1397  mOffsetAlongLineUnitWidget->setMapUnitScale( mLayer->offsetAlongLineMapUnitScale() );
1398  mOffsetAlongLineUnitWidget->blockSignals( false );
1399 
1400  setPlacement(); // update gui
1401 
1404  registerDataDefinedButton( mPlacementDDBtn, "placement", QgsDataDefinedButton::String, tr( "string " ) + QString( "[<b>vertex</b>|<b>lastvertex</b>|<b>firstvertex</b>|<b>centerpoint</b>]" ) );
1405  registerDataDefinedButton( mOffsetAlongLineDDBtn, "offset_along_line", QgsDataDefinedButton::Double, QgsDataDefinedButton::doublePosDesc() );
1406 }
1407 
1409 {
1410  return mLayer;
1411 }
1412 
1414 {
1415  mLayer->setInterval( val );
1416  emit changed();
1417 }
1418 
1420 {
1421  mLayer->setOffsetAlongLine( val );
1422  emit changed();
1423 }
1424 
1426 {
1427  mLayer->setRotateMarker( chkRotateMarker->isChecked() );
1428  emit changed();
1429 }
1430 
1432 {
1433  mLayer->setOffset( spinOffset->value() );
1434  emit changed();
1435 }
1436 
1438 {
1439  bool interval = radInterval->isChecked();
1440  spinInterval->setEnabled( interval );
1441  mSpinOffsetAlongLine->setEnabled( radInterval->isChecked() || radVertexLast->isChecked() || radVertexFirst->isChecked() );
1442  //mLayer->setPlacement( interval ? QgsMarkerLineSymbolLayerV2::Interval : QgsMarkerLineSymbolLayerV2::Vertex );
1443  if ( radInterval->isChecked() )
1445  else if ( radVertex->isChecked() )
1447  else if ( radVertexLast->isChecked() )
1449  else if ( radVertexFirst->isChecked() )
1451  else
1453 
1454  emit changed();
1455 }
1456 
1458 {
1459  if ( mLayer )
1460  {
1461  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mIntervalUnitWidget->getUnit() );
1462  mLayer->setIntervalUnit( unit );
1463  mLayer->setIntervalMapUnitScale( mIntervalUnitWidget->getMapUnitScale() );
1464  emit changed();
1465  }
1466 }
1467 
1469 {
1470  if ( mLayer )
1471  {
1472  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
1473  mLayer->setOffsetUnit( unit );
1474  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1475  emit changed();
1476  }
1477 }
1478 
1480 {
1481  if ( mLayer )
1482  {
1483  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetAlongLineUnitWidget->getUnit() );
1484  mLayer->setOffsetAlongLineUnit( unit );
1485  mLayer->setOffsetAlongLineMapUnitScale( mOffsetAlongLineUnitWidget->getMapUnitScale() );
1486  }
1487  emit changed();
1488 }
1489 
1491 
1492 
1494  : QgsSymbolLayerV2Widget( parent, vl )
1495 {
1496  mLayer = NULL;
1497 
1498  setupUi( this );
1499  mSizeUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1500  mBorderWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1501  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1502  viewGroups->setHeaderHidden( true );
1503 
1504  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
1505  mChangeColorButton->setContext( "symbology" );
1506  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
1507  mChangeColorButton->setContext( "symbology" );
1508 
1509  spinOffsetX->setClearValue( 0.0 );
1510  spinOffsetY->setClearValue( 0.0 );
1511 
1512  populateList();
1513 
1514  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1515  connect( viewGroups->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
1516  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize() ) );
1517  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle() ) );
1518  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1519  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
1520 }
1521 
1522 #include <QTime>
1523 #include <QAbstractListModel>
1524 #include <QPixmapCache>
1525 #include <QStyle>
1526 
1527 class QgsSvgListModel : public QAbstractListModel
1528 {
1529  public:
1530  QgsSvgListModel( QObject* parent ) : QAbstractListModel( parent )
1531  {
1533  }
1534 
1535  // Constructor to create model for icons in a specific path
1536  QgsSvgListModel( QObject* parent, QString path ) : QAbstractListModel( parent )
1537  {
1539  }
1540 
1541  int rowCount( const QModelIndex & parent = QModelIndex() ) const override
1542  {
1543  Q_UNUSED( parent );
1544  return mSvgFiles.count();
1545  }
1546 
1547  QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const override
1548  {
1549  QString entry = mSvgFiles.at( index.row() );
1550 
1551  if ( role == Qt::DecorationRole ) // icon
1552  {
1553  QPixmap pixmap;
1554  if ( !QPixmapCache::find( entry, pixmap ) )
1555  {
1556  // render SVG file
1557  QColor fill, outline;
1558  double outlineWidth;
1559  bool fillParam, outlineParam, outlineWidthParam;
1560  QgsSvgCache::instance()->containsParams( entry, fillParam, fill, outlineParam, outline, outlineWidthParam, outlineWidth );
1561 
1562  bool fitsInCache; // should always fit in cache at these sizes (i.e. under 559 px ^ 2, or half cache size)
1563  const QImage& img = QgsSvgCache::instance()->svgAsImage( entry, 30.0, fill, outline, outlineWidth, 3.5 /*appr. 88 dpi*/, 1.0, fitsInCache );
1564  pixmap = QPixmap::fromImage( img );
1565  QPixmapCache::insert( entry, pixmap );
1566  }
1567 
1568  return pixmap;
1569  }
1570  else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
1571  {
1572  return entry;
1573  }
1574 
1575  return QVariant();
1576  }
1577 
1578  protected:
1579  QStringList mSvgFiles;
1580 };
1581 
1582 class QgsSvgGroupsModel : public QStandardItemModel
1583 {
1584  public:
1585  QgsSvgGroupsModel( QObject* parent ) : QStandardItemModel( parent )
1586  {
1587  QStringList svgPaths = QgsApplication::svgPaths();
1588  QStandardItem *parentItem = invisibleRootItem();
1589 
1590  for ( int i = 0; i < svgPaths.size(); i++ )
1591  {
1592  QDir dir( svgPaths[i] );
1593  QStandardItem *baseGroup;
1594 
1595  if ( dir.path().contains( QgsApplication::pkgDataPath() ) )
1596  {
1597  baseGroup = new QStandardItem( QString( "App Symbols" ) );
1598  }
1599  else if ( dir.path().contains( QgsApplication::qgisSettingsDirPath() ) )
1600  {
1601  baseGroup = new QStandardItem( QString( "User Symbols" ) );
1602  }
1603  else
1604  {
1605  baseGroup = new QStandardItem( dir.dirName() );
1606  }
1607  baseGroup->setData( QVariant( svgPaths[i] ) );
1608  baseGroup->setEditable( false );
1609  baseGroup->setCheckable( false );
1610  baseGroup->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
1611  baseGroup->setToolTip( dir.path() );
1612  parentItem->appendRow( baseGroup );
1613  createTree( baseGroup );
1614  QgsDebugMsg( QString( "SVG base path %1: %2" ).arg( i ).arg( baseGroup->data().toString() ) );
1615  }
1616  }
1617  private:
1618  void createTree( QStandardItem* &parentGroup )
1619  {
1620  QDir parentDir( parentGroup->data().toString() );
1621  foreach ( QString item, parentDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
1622  {
1623  QStandardItem* group = new QStandardItem( item );
1624  group->setData( QVariant( parentDir.path() + "/" + item ) );
1625  group->setEditable( false );
1626  group->setCheckable( false );
1627  group->setToolTip( parentDir.path() + "/" + item );
1628  group->setIcon( QgsApplication::style()->standardIcon( QStyle::SP_DirIcon ) );
1629  parentGroup->appendRow( group );
1630  createTree( group );
1631  }
1632  }
1633 };
1634 
1636 {
1637  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( viewGroups );
1638  viewGroups->setModel( g );
1639  // Set the tree expanded at the first level
1640  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
1641  for ( int i = 0; i < rows; i++ )
1642  {
1643  viewGroups->setExpanded( g->indexFromItem( g->item( i ) ), true );
1644  }
1645 
1646  // Initally load the icons in the List view without any grouping
1647  QgsSvgListModel* m = new QgsSvgListModel( viewImages );
1648  viewImages->setModel( m );
1649 }
1650 
1652 {
1653  QString path = idx.data( Qt::UserRole + 1 ).toString();
1654 
1655  QgsSvgListModel* m = new QgsSvgListModel( viewImages, path );
1656  viewImages->setModel( m );
1657 
1658  connect( viewImages->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setName( const QModelIndex& ) ) );
1659  emit changed();
1660 }
1661 
1663 {
1664  if ( !layer )
1665  {
1666  return;
1667  }
1668 
1669  //activate gui for svg parameters only if supported by the svg file
1670  bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
1671  QColor defaultFill, defaultOutline;
1672  double defaultOutlineWidth;
1673  QgsSvgCache::instance()->containsParams( layer->path(), hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
1674  mChangeColorButton->setEnabled( hasFillParam );
1675  mChangeBorderColorButton->setEnabled( hasOutlineParam );
1676  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
1677 
1678  if ( hasFillParam )
1679  {
1680  if ( layer->fillColor().isValid() )
1681  {
1682  mChangeColorButton->setColor( layer->fillColor() );
1683  }
1684  else
1685  {
1686  mChangeColorButton->setColor( defaultFill );
1687  }
1688  }
1689  if ( hasOutlineParam )
1690  {
1691  if ( layer->outlineColor().isValid() )
1692  {
1693  mChangeBorderColorButton->setColor( layer->outlineColor() );
1694  }
1695  else
1696  {
1697  mChangeBorderColorButton->setColor( defaultOutline );
1698  }
1699  }
1700 
1701  mFileLineEdit->blockSignals( true );
1702  mFileLineEdit->setText( layer->path() );
1703  mFileLineEdit->blockSignals( false );
1704 
1705  mBorderWidthSpinBox->blockSignals( true );
1706  mBorderWidthSpinBox->setValue( layer->outlineWidth() );
1707  mBorderWidthSpinBox->blockSignals( false );
1708 }
1709 
1710 
1712 {
1713  if ( !layer )
1714  {
1715  return;
1716  }
1717 
1718  if ( layer->layerType() != "SvgMarker" )
1719  return;
1720 
1721  // layer type is correct, we can do the cast
1722  mLayer = static_cast<QgsSvgMarkerSymbolLayerV2*>( layer );
1723 
1724  // set values
1725 
1726  QAbstractItemModel* m = viewImages->model();
1727  QItemSelectionModel* selModel = viewImages->selectionModel();
1728  for ( int i = 0; i < m->rowCount(); i++ )
1729  {
1730  QModelIndex idx( m->index( i, 0 ) );
1731  if ( m->data( idx ).toString() == mLayer->path() )
1732  {
1733  selModel->select( idx, QItemSelectionModel::SelectCurrent );
1734  selModel->setCurrentIndex( idx, QItemSelectionModel::SelectCurrent );
1735  setName( idx );
1736  break;
1737  }
1738  }
1739 
1740  spinSize->blockSignals( true );
1741  spinSize->setValue( mLayer->size() );
1742  spinSize->blockSignals( false );
1743  spinAngle->blockSignals( true );
1744  spinAngle->setValue( mLayer->angle() );
1745  spinAngle->blockSignals( false );
1746 
1747  // without blocking signals the value gets changed because of slot setOffset()
1748  spinOffsetX->blockSignals( true );
1749  spinOffsetX->setValue( mLayer->offset().x() );
1750  spinOffsetX->blockSignals( false );
1751  spinOffsetY->blockSignals( true );
1752  spinOffsetY->setValue( mLayer->offset().y() );
1753  spinOffsetY->blockSignals( false );
1754 
1755  mSizeUnitWidget->blockSignals( true );
1756  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
1757  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
1758  mSizeUnitWidget->blockSignals( false );
1759  mBorderWidthUnitWidget->blockSignals( true );
1760  mBorderWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
1761  mBorderWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
1762  mBorderWidthUnitWidget->blockSignals( false );
1763  mOffsetUnitWidget->blockSignals( true );
1764  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
1765  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
1766  mOffsetUnitWidget->blockSignals( false );
1767 
1768  //anchor points
1769  mHorizontalAnchorComboBox->blockSignals( true );
1770  mVerticalAnchorComboBox->blockSignals( true );
1771  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1772  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
1773  mHorizontalAnchorComboBox->blockSignals( false );
1774  mVerticalAnchorComboBox->blockSignals( false );
1775 
1776  setGuiForSvg( mLayer );
1777 
1785  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
1786  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
1787 }
1788 
1790 {
1791  return mLayer;
1792 }
1793 
1794 void QgsSvgMarkerSymbolLayerV2Widget::setName( const QModelIndex& idx )
1795 {
1796  QString name = idx.data( Qt::UserRole ).toString();
1797  mLayer->setPath( name );
1798  mFileLineEdit->setText( name );
1799 
1800  setGuiForSvg( mLayer );
1801  emit changed();
1802 }
1803 
1805 {
1806  mLayer->setSize( spinSize->value() );
1807  emit changed();
1808 }
1809 
1811 {
1812  mLayer->setAngle( spinAngle->value() );
1813  emit changed();
1814 }
1815 
1817 {
1818  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
1819  emit changed();
1820 }
1821 
1823 {
1824  QSettings s;
1825  QString file = QFileDialog::getOpenFileName( 0,
1826  tr( "Select SVG file" ),
1827  s.value( "/UI/lastSVGMarkerDir" ).toString(),
1828  tr( "SVG files" ) + " (*.svg)" );
1829  QFileInfo fi( file );
1830  if ( file.isEmpty() || !fi.exists() )
1831  {
1832  return;
1833  }
1834  mFileLineEdit->setText( file );
1835  mLayer->setPath( file );
1836  s.setValue( "/UI/lastSVGMarkerDir", fi.absolutePath() );
1837  emit changed();
1838 }
1839 
1841 {
1842  if ( !QFileInfo( text ).exists() )
1843  {
1844  return;
1845  }
1846  mLayer->setPath( text );
1847  setGuiForSvg( mLayer );
1848  emit changed();
1849 }
1850 
1852 {
1853  if ( !QFileInfo( mFileLineEdit->text() ).exists() )
1854  {
1855  QUrl url( mFileLineEdit->text() );
1856  if ( !url.isValid() )
1857  {
1858  return;
1859  }
1860  }
1861 
1862  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1863  mLayer->setPath( mFileLineEdit->text() );
1864  QApplication::restoreOverrideCursor();
1865 
1866  setGuiForSvg( mLayer );
1867  emit changed();
1868 }
1869 
1871 {
1872  if ( !mLayer )
1873  {
1874  return;
1875  }
1876 
1877  mLayer->setFillColor( color );
1878  emit changed();
1879 }
1880 
1882 {
1883  if ( !mLayer )
1884  {
1885  return;
1886  }
1887 
1888  mLayer->setOutlineColor( color );
1889  emit changed();
1890 }
1891 
1893 {
1894  if ( mLayer )
1895  {
1896  mLayer->setOutlineWidth( d );
1897  emit changed();
1898  }
1899 }
1900 
1902 {
1903  if ( mLayer )
1904  {
1905  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSizeUnitWidget->getUnit() );
1906  mLayer->setSizeUnit( unit );
1907  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
1908  emit changed();
1909  }
1910 }
1911 
1913 {
1914  if ( mLayer )
1915  {
1916  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mBorderWidthUnitWidget->getUnit() );
1917  mLayer->setOutlineWidthUnit( unit );
1918  mLayer->setOutlineWidthMapUnitScale( mBorderWidthUnitWidget->getMapUnitScale() );
1919  emit changed();
1920  }
1921 }
1922 
1924 {
1925  if ( mLayer )
1926  {
1927  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
1928  mLayer->setOffsetUnit( unit );
1929  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
1930  emit changed();
1931  }
1932 }
1933 
1935 {
1936  if ( mLayer )
1937  {
1939  emit changed();
1940  }
1941 }
1942 
1944 {
1945  if ( mLayer )
1946  {
1948  emit changed();
1949  }
1950 }
1951 
1953 
1954 #include <QFileDialog>
1955 
1957 {
1958  mLayer = 0;
1959  setupUi( this );
1960  mTextureWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1961  mSvgOutlineWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
1962  mSvgTreeView->setHeaderHidden( true );
1963  insertIcons();
1964 
1965  mChangeColorButton->setColorDialogTitle( tr( "Select fill color" ) );
1966  mChangeColorButton->setContext( "symbology" );
1967  mChangeBorderColorButton->setColorDialogTitle( tr( "Select border color" ) );
1968  mChangeBorderColorButton->setContext( "symbology" );
1969 
1970  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
1971  connect( mSvgTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( populateIcons( const QModelIndex& ) ) );
1972 }
1973 
1975 {
1976  if ( !layer )
1977  {
1978  return;
1979  }
1980 
1981  if ( layer->layerType() != "SVGFill" )
1982  {
1983  return;
1984  }
1985 
1986  mLayer = dynamic_cast<QgsSVGFillSymbolLayer*>( layer );
1987  if ( mLayer )
1988  {
1989  double width = mLayer->patternWidth();
1990  mTextureWidthSpinBox->blockSignals( true );
1991  mTextureWidthSpinBox->setValue( width );
1992  mTextureWidthSpinBox->blockSignals( false );
1993  mSVGLineEdit->setText( mLayer->svgFilePath() );
1994  mRotationSpinBox->blockSignals( true );
1995  mRotationSpinBox->setValue( mLayer->angle() );
1996  mRotationSpinBox->blockSignals( false );
1997  mTextureWidthUnitWidget->blockSignals( true );
1998  mTextureWidthUnitWidget->setUnit( mLayer->patternWidthUnit() );
1999  mTextureWidthUnitWidget->setMapUnitScale( mLayer->patternWidthMapUnitScale() );
2000  mTextureWidthUnitWidget->blockSignals( false );
2001  mSvgOutlineWidthUnitWidget->blockSignals( true );
2002  mSvgOutlineWidthUnitWidget->setUnit( mLayer->svgOutlineWidthUnit() );
2003  mSvgOutlineWidthUnitWidget->setMapUnitScale( mLayer->svgOutlineWidthMapUnitScale() );
2004  mSvgOutlineWidthUnitWidget->blockSignals( false );
2005  mChangeColorButton->blockSignals( true );
2006  mChangeColorButton->setColor( mLayer->svgFillColor() );
2007  mChangeColorButton->blockSignals( false );
2008  mChangeBorderColorButton->blockSignals( true );
2009  mChangeBorderColorButton->setColor( mLayer->svgOutlineColor() );
2010  mChangeBorderColorButton->blockSignals( false );
2011  mBorderWidthSpinBox->blockSignals( true );
2012  mBorderWidthSpinBox->setValue( mLayer->svgOutlineWidth() );
2013  mBorderWidthSpinBox->blockSignals( false );
2014  }
2015  updateParamGui( false );
2016 
2023 }
2024 
2026 {
2027  return mLayer;
2028 }
2029 
2030 void QgsSVGFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2031 {
2032  QString filePath = QFileDialog::getOpenFileName( 0, tr( "Select SVG texture file" ), QString(), tr( "SVG file" ) + " (*.svg);;" + tr( "All files" ) + " (*.*)" );
2033  if ( !filePath.isNull() )
2034  {
2035  mSVGLineEdit->setText( filePath );
2036  emit changed();
2037  }
2038 }
2039 
2040 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthSpinBox_valueChanged( double d )
2041 {
2042  if ( mLayer )
2043  {
2044  mLayer->setPatternWidth( d );
2045  emit changed();
2046  }
2047 }
2048 
2049 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_textEdited( const QString & text )
2050 {
2051  if ( !mLayer )
2052  {
2053  return;
2054  }
2055 
2056  QFileInfo fi( text );
2057  if ( !fi.exists() )
2058  {
2059  return;
2060  }
2061  mLayer->setSvgFilePath( text );
2062  updateParamGui();
2063  emit changed();
2064 }
2065 
2066 void QgsSVGFillSymbolLayerWidget::on_mSVGLineEdit_editingFinished()
2067 {
2068  if ( !mLayer )
2069  {
2070  return;
2071  }
2072 
2073  QFileInfo fi( mSVGLineEdit->text() );
2074  if ( !fi.exists() )
2075  {
2076  QUrl url( mSVGLineEdit->text() );
2077  if ( !url.isValid() )
2078  {
2079  return;
2080  }
2081  }
2082 
2083  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2084  mLayer->setSvgFilePath( mSVGLineEdit->text() );
2085  QApplication::restoreOverrideCursor();
2086 
2087  updateParamGui();
2088  emit changed();
2089 }
2090 
2091 void QgsSVGFillSymbolLayerWidget::setFile( const QModelIndex& item )
2092 {
2093  QString file = item.data( Qt::UserRole ).toString();
2094  mLayer->setSvgFilePath( file );
2095  mSVGLineEdit->setText( file );
2096 
2097  updateParamGui();
2098  emit changed();
2099 }
2100 
2102 {
2103  QgsSvgGroupsModel* g = new QgsSvgGroupsModel( mSvgTreeView );
2104  mSvgTreeView->setModel( g );
2105  // Set the tree expanded at the first level
2106  int rows = g->rowCount( g->indexFromItem( g->invisibleRootItem() ) );
2107  for ( int i = 0; i < rows; i++ )
2108  {
2109  mSvgTreeView->setExpanded( g->indexFromItem( g->item( i ) ), true );
2110  }
2111 
2112  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView );
2113  mSvgListView->setModel( m );
2114 }
2115 
2116 void QgsSVGFillSymbolLayerWidget::populateIcons( const QModelIndex& idx )
2117 {
2118  QString path = idx.data( Qt::UserRole + 1 ).toString();
2119 
2120  QgsSvgListModel* m = new QgsSvgListModel( mSvgListView, path );
2121  mSvgListView->setModel( m );
2122 
2123  connect( mSvgListView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), this, SLOT( setFile( const QModelIndex& ) ) );
2124  emit changed();
2125 }
2126 
2127 
2128 void QgsSVGFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2129 {
2130  if ( mLayer )
2131  {
2132  mLayer->setAngle( d );
2133  emit changed();
2134  }
2135 }
2136 
2138 {
2139  //activate gui for svg parameters only if supported by the svg file
2140  bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
2141  QColor defaultFill, defaultOutline;
2142  double defaultOutlineWidth;
2143  QgsSvgCache::instance()->containsParams( mSVGLineEdit->text(), hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
2144  if ( hasFillParam && resetValues )
2145  {
2146  mChangeColorButton->setColor( defaultFill );
2147  }
2148  mChangeColorButton->setEnabled( hasFillParam );
2149  if ( hasOutlineParam && resetValues )
2150  {
2151  mChangeBorderColorButton->setColor( defaultOutline );
2152  }
2153  mChangeBorderColorButton->setEnabled( hasOutlineParam );
2154  if ( hasOutlineWidthParam && resetValues )
2155  {
2156  mBorderWidthSpinBox->setValue( defaultOutlineWidth );
2157  }
2158  mBorderWidthSpinBox->setEnabled( hasOutlineWidthParam );
2159 }
2160 
2161 void QgsSVGFillSymbolLayerWidget::on_mChangeColorButton_colorChanged( const QColor& color )
2162 {
2163  if ( !mLayer )
2164  {
2165  return;
2166  }
2167 
2168  mLayer->setSvgFillColor( color );
2169  emit changed();
2170 }
2171 
2172 void QgsSVGFillSymbolLayerWidget::on_mChangeBorderColorButton_colorChanged( const QColor& color )
2173 {
2174  if ( !mLayer )
2175  {
2176  return;
2177  }
2178 
2179  mLayer->setSvgOutlineColor( color );
2180  emit changed();
2181 }
2182 
2183 void QgsSVGFillSymbolLayerWidget::on_mBorderWidthSpinBox_valueChanged( double d )
2184 {
2185  if ( mLayer )
2186  {
2187  mLayer->setSvgOutlineWidth( d );
2188  emit changed();
2189  }
2190 }
2191 
2192 void QgsSVGFillSymbolLayerWidget::on_mTextureWidthUnitWidget_changed()
2193 {
2194  if ( mLayer )
2195  {
2196  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mTextureWidthUnitWidget->getUnit() );
2197  mLayer->setPatternWidthUnit( unit );
2198  mLayer->setPatternWidthMapUnitScale( mTextureWidthUnitWidget->getMapUnitScale() );
2199  emit changed();
2200  }
2201 }
2202 
2203 void QgsSVGFillSymbolLayerWidget::on_mSvgOutlineWidthUnitWidget_changed()
2204 {
2205  if ( mLayer )
2206  {
2207  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSvgOutlineWidthUnitWidget->getUnit() );
2208  mLayer->setSvgOutlineWidthUnit( unit );
2209  mLayer->setSvgOutlineWidthMapUnitScale( mSvgOutlineWidthUnitWidget->getMapUnitScale() );
2210  emit changed();
2211  }
2212 }
2213 
2215 
2217  QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
2218 {
2219  setupUi( this );
2220  mDistanceUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2221  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2222 }
2223 
2225 {
2226  if ( layer->layerType() != "LinePatternFill" )
2227  {
2228  return;
2229  }
2230 
2231  QgsLinePatternFillSymbolLayer* patternLayer = static_cast<QgsLinePatternFillSymbolLayer*>( layer );
2232  if ( patternLayer )
2233  {
2234  mLayer = patternLayer;
2235  mAngleSpinBox->blockSignals( true );
2236  mAngleSpinBox->setValue( mLayer->lineAngle() );
2237  mAngleSpinBox->blockSignals( false );
2238  mDistanceSpinBox->blockSignals( true );
2239  mDistanceSpinBox->setValue( mLayer->distance() );
2240  mDistanceSpinBox->blockSignals( false );
2241  mOffsetSpinBox->blockSignals( true );
2242  mOffsetSpinBox->setValue( mLayer->offset() );
2243  mOffsetSpinBox->blockSignals( false );
2244 
2245  //units
2246  mDistanceUnitWidget->blockSignals( true );
2247  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
2248  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
2249  mDistanceUnitWidget->blockSignals( false );
2250  mOffsetUnitWidget->blockSignals( true );
2251  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2252  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2253  mOffsetUnitWidget->blockSignals( false );
2254  }
2255 
2258 }
2259 
2261 {
2262  return mLayer;
2263 }
2264 
2265 void QgsLinePatternFillSymbolLayerWidget::on_mAngleSpinBox_valueChanged( double d )
2266 {
2267  if ( mLayer )
2268  {
2269  mLayer->setLineAngle( d );
2270  emit changed();
2271  }
2272 }
2273 
2274 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceSpinBox_valueChanged( double d )
2275 {
2276  if ( mLayer )
2277  {
2278  mLayer->setDistance( d );
2279  emit changed();
2280  }
2281 }
2282 
2283 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetSpinBox_valueChanged( double d )
2284 {
2285  if ( mLayer )
2286  {
2287  mLayer->setOffset( d );
2288  emit changed();
2289  }
2290 }
2291 
2292 void QgsLinePatternFillSymbolLayerWidget::on_mDistanceUnitWidget_changed()
2293 {
2294  if ( mLayer )
2295  {
2296  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mDistanceUnitWidget->getUnit() );
2297  mLayer->setDistanceUnit( unit );
2298  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
2299  emit changed();
2300  }
2301 }
2302 
2303 void QgsLinePatternFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2304 {
2305  if ( mLayer )
2306  {
2307  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
2308  mLayer->setOffsetUnit( unit );
2309  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2310  emit changed();
2311  }
2312 }
2313 
2315 
2317  QgsSymbolLayerV2Widget( parent, vl ), mLayer( 0 )
2318 {
2319  setupUi( this );
2320  mHorizontalDistanceUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2321  mVerticalDistanceUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2322  mHorizontalDisplacementUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2323  mVerticalDisplacementUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2324 }
2325 
2326 
2328 {
2329  if ( !layer || layer->layerType() != "PointPatternFill" )
2330  {
2331  return;
2332  }
2333 
2334  mLayer = static_cast<QgsPointPatternFillSymbolLayer*>( layer );
2335  mHorizontalDistanceSpinBox->blockSignals( true );
2336  mHorizontalDistanceSpinBox->setValue( mLayer->distanceX() );
2337  mHorizontalDistanceSpinBox->blockSignals( false );
2338  mVerticalDistanceSpinBox->blockSignals( true );
2339  mVerticalDistanceSpinBox->setValue( mLayer->distanceY() );
2340  mVerticalDistanceSpinBox->blockSignals( false );
2341  mHorizontalDisplacementSpinBox->blockSignals( true );
2342  mHorizontalDisplacementSpinBox->setValue( mLayer->displacementX() );
2343  mHorizontalDisplacementSpinBox->blockSignals( false );
2344  mVerticalDisplacementSpinBox->blockSignals( true );
2345  mVerticalDisplacementSpinBox->setValue( mLayer->displacementY() );
2346  mVerticalDisplacementSpinBox->blockSignals( false );
2347 
2348  mHorizontalDistanceUnitWidget->blockSignals( true );
2349  mHorizontalDistanceUnitWidget->setUnit( mLayer->distanceXUnit() );
2350  mHorizontalDistanceUnitWidget->setMapUnitScale( mLayer->distanceXMapUnitScale() );
2351  mHorizontalDistanceUnitWidget->blockSignals( false );
2352  mVerticalDistanceUnitWidget->blockSignals( true );
2353  mVerticalDistanceUnitWidget->setUnit( mLayer->distanceYUnit() );
2354  mVerticalDistanceUnitWidget->setMapUnitScale( mLayer->distanceYMapUnitScale() );
2355  mVerticalDistanceUnitWidget->blockSignals( false );
2356  mHorizontalDisplacementUnitWidget->blockSignals( true );
2357  mHorizontalDisplacementUnitWidget->setUnit( mLayer->displacementXUnit() );
2358  mHorizontalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementXMapUnitScale() );
2359  mHorizontalDisplacementUnitWidget->blockSignals( false );
2360  mVerticalDisplacementUnitWidget->blockSignals( true );
2361  mVerticalDisplacementUnitWidget->setUnit( mLayer->displacementYUnit() );
2362  mVerticalDisplacementUnitWidget->setMapUnitScale( mLayer->displacementYMapUnitScale() );
2363  mVerticalDisplacementUnitWidget->blockSignals( false );
2364 
2365  registerDataDefinedButton( mHorizontalDistanceDDBtn, "distance_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2367  registerDataDefinedButton( mHorizontalDisplacementDDBtn, "displacement_x", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2368  registerDataDefinedButton( mVerticalDisplacementDDBtn, "displacement_y", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
2369 }
2370 
2372 {
2373  return mLayer;
2374 }
2375 
2376 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceSpinBox_valueChanged( double d )
2377 {
2378  if ( mLayer )
2379  {
2380  mLayer->setDistanceX( d );
2381  emit changed();
2382  }
2383 }
2384 
2385 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceSpinBox_valueChanged( double d )
2386 {
2387  if ( mLayer )
2388  {
2389  mLayer->setDistanceY( d );
2390  emit changed();
2391  }
2392 }
2393 
2394 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementSpinBox_valueChanged( double d )
2395 {
2396  if ( mLayer )
2397  {
2398  mLayer->setDisplacementX( d );
2399  emit changed();
2400  }
2401 }
2402 
2403 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementSpinBox_valueChanged( double d )
2404 {
2405  if ( mLayer )
2406  {
2407  mLayer->setDisplacementY( d );
2408  emit changed();
2409  }
2410 }
2411 
2412 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDistanceUnitWidget_changed()
2413 {
2414  if ( mLayer )
2415  {
2416  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mHorizontalDistanceUnitWidget->getUnit() );
2417  mLayer->setDistanceXUnit( unit );
2418  mLayer->setDistanceXMapUnitScale( mHorizontalDistanceUnitWidget->getMapUnitScale() );
2419  emit changed();
2420  }
2421 }
2422 
2423 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDistanceUnitWidget_changed()
2424 {
2425  if ( mLayer )
2426  {
2427  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mVerticalDistanceUnitWidget->getUnit() );
2428  mLayer->setDistanceYUnit( unit );
2429  mLayer->setDistanceYMapUnitScale( mVerticalDistanceUnitWidget->getMapUnitScale() );
2430  emit changed();
2431  }
2432 }
2433 
2434 void QgsPointPatternFillSymbolLayerWidget::on_mHorizontalDisplacementUnitWidget_changed()
2435 {
2436  if ( mLayer )
2437  {
2438  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mHorizontalDisplacementUnitWidget->getUnit() );
2439  mLayer->setDisplacementXUnit( unit );
2440  mLayer->setDisplacementXMapUnitScale( mHorizontalDisplacementUnitWidget->getMapUnitScale() );
2441  emit changed();
2442  }
2443 }
2444 
2445 void QgsPointPatternFillSymbolLayerWidget::on_mVerticalDisplacementUnitWidget_changed()
2446 {
2447  if ( mLayer )
2448  {
2449  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mVerticalDisplacementUnitWidget->getUnit() );
2450  mLayer->setDisplacementYUnit( unit );
2451  mLayer->setDisplacementYMapUnitScale( mVerticalDisplacementUnitWidget->getMapUnitScale() );
2452  emit changed();
2453  }
2454 }
2455 
2457 
2459  : QgsSymbolLayerV2Widget( parent, vl )
2460 {
2461  mLayer = NULL;
2462 
2463  setupUi( this );
2464  mSizeUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2465  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2467  scrollArea->setWidget( widgetChar );
2468 
2469  btnColor->setAllowAlpha( true );
2470  btnColor->setColorDialogTitle( tr( "Select symbol color" ) );
2471  btnColor->setContext( "symbology" );
2472 
2473  spinOffsetX->setClearValue( 0.0 );
2474  spinOffsetY->setClearValue( 0.0 );
2475 
2476  connect( cboFont, SIGNAL( currentFontChanged( const QFont & ) ), this, SLOT( setFontFamily( const QFont& ) ) );
2477  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
2478  connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setColor( const QColor& ) ) );
2479  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle( double ) ) );
2480  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2481  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
2482  connect( widgetChar, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
2483 }
2484 
2485 
2487 {
2488  if ( layer->layerType() != "FontMarker" )
2489  return;
2490 
2491  // layer type is correct, we can do the cast
2492  mLayer = static_cast<QgsFontMarkerSymbolLayerV2*>( layer );
2493 
2494  // set values
2495  cboFont->blockSignals( true );
2496  cboFont->setCurrentFont( QFont( mLayer->fontFamily() ) );
2497  cboFont->blockSignals( false );
2498  spinSize->blockSignals( true );
2499  spinSize->setValue( mLayer->size() );
2500  spinSize->blockSignals( false );
2501  btnColor->blockSignals( true );
2502  btnColor->setColor( mLayer->color() );
2503  btnColor->blockSignals( false );
2504  spinAngle->blockSignals( true );
2505  spinAngle->setValue( mLayer->angle() );
2506  spinAngle->blockSignals( false );
2507 
2508  //block
2509  spinOffsetX->blockSignals( true );
2510  spinOffsetX->setValue( mLayer->offset().x() );
2511  spinOffsetX->blockSignals( false );
2512  spinOffsetY->blockSignals( true );
2513  spinOffsetY->setValue( mLayer->offset().y() );
2514  spinOffsetY->blockSignals( false );
2515 
2516  mSizeUnitWidget->blockSignals( true );
2517  mSizeUnitWidget->setUnit( mLayer->sizeUnit() );
2518  mSizeUnitWidget->setMapUnitScale( mLayer->sizeMapUnitScale() );
2519  mSizeUnitWidget->blockSignals( false );
2520 
2521  mOffsetUnitWidget->blockSignals( true );
2522  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2523  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2524  mOffsetUnitWidget->blockSignals( false );
2525 
2526  //anchor points
2527  mHorizontalAnchorComboBox->blockSignals( true );
2528  mVerticalAnchorComboBox->blockSignals( true );
2529  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
2530  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
2531  mHorizontalAnchorComboBox->blockSignals( false );
2532  mVerticalAnchorComboBox->blockSignals( false );
2533 }
2534 
2536 {
2537  return mLayer;
2538 }
2539 
2541 {
2542  mLayer->setFontFamily( font.family() );
2543  widgetChar->updateFont( font );
2544  emit changed();
2545 }
2546 
2548 {
2549  mLayer->setColor( color );
2550  emit changed();
2551 }
2552 
2554 {
2555  mLayer->setSize( size );
2556  //widgetChar->updateSize(size);
2557  emit changed();
2558 }
2559 
2561 {
2562  mLayer->setAngle( angle );
2563  emit changed();
2564 }
2565 
2567 {
2568  mLayer->setCharacter( chr );
2569  emit changed();
2570 }
2571 
2573 {
2574  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
2575  emit changed();
2576 }
2577 
2579 {
2580  if ( mLayer )
2581  {
2582  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSizeUnitWidget->getUnit() );
2583  mLayer->setSizeUnit( unit );
2584  mLayer->setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
2585  emit changed();
2586  }
2587 }
2588 
2590 {
2591  if ( mLayer )
2592  {
2593  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
2594  mLayer->setOffsetUnit( unit );
2595  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2596  emit changed();
2597  }
2598 }
2599 
2601 {
2602  if ( mLayer )
2603  {
2605  emit changed();
2606  }
2607 }
2608 
2610 {
2611  if ( mLayer )
2612  {
2614  emit changed();
2615  }
2616 }
2617 
2618 
2620 
2621 
2623  : QgsSymbolLayerV2Widget( parent, vl )
2624 {
2625  mLayer = NULL;
2626 
2627  setupUi( this );
2628 }
2629 
2631 {
2632  if ( layer->layerType() != "CentroidFill" )
2633  return;
2634 
2635  // layer type is correct, we can do the cast
2636  mLayer = static_cast<QgsCentroidFillSymbolLayerV2*>( layer );
2637 
2638  // set values
2639  mDrawInsideCheckBox->blockSignals( true );
2640  mDrawInsideCheckBox->setChecked( mLayer->pointOnSurface() );
2641  mDrawInsideCheckBox->blockSignals( false );
2642 }
2643 
2645 {
2646  return mLayer;
2647 }
2648 
2650 {
2651  mLayer->setPointOnSurface( state == Qt::Checked );
2652  emit changed();
2653 }
2654 
2656 
2658  : QgsSymbolLayerV2Widget( parent, vl )
2659 {
2660  mLayer = 0;
2661  setupUi( this );
2662 
2663  mWidthUnitWidget->setUnits( QStringList() << tr( "Pixels" ) << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2664  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
2665 
2666  mSpinOffsetX->setClearValue( 0.0 );
2667  mSpinOffsetY->setClearValue( 0.0 );
2668 
2669  connect( cboCoordinateMode, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setCoordinateMode( int ) ) );
2670  connect( mSpinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2671  connect( mSpinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
2672 }
2673 
2675 {
2676  if ( !layer )
2677  {
2678  return;
2679  }
2680 
2681  if ( layer->layerType() != "RasterFill" )
2682  {
2683  return;
2684  }
2685 
2686  mLayer = dynamic_cast<QgsRasterFillSymbolLayer*>( layer );
2687  if ( !mLayer )
2688  {
2689  return;
2690  }
2691 
2692  mImageLineEdit->blockSignals( true );
2693  mImageLineEdit->setText( mLayer->imageFilePath() );
2694  mImageLineEdit->blockSignals( false );
2695 
2696  cboCoordinateMode->blockSignals( true );
2697  switch ( mLayer->coordinateMode() )
2698  {
2700  cboCoordinateMode->setCurrentIndex( 1 );
2701  break;
2703  default:
2704  cboCoordinateMode->setCurrentIndex( 0 );
2705  break;
2706  }
2707  cboCoordinateMode->blockSignals( false );
2708  mSpinTransparency->blockSignals( true );
2709  mSpinTransparency->setValue( mLayer->alpha() * 100.0 );
2710  mSpinTransparency->blockSignals( false );
2711  mSliderTransparency->blockSignals( true );
2712  mSliderTransparency->setValue( mLayer->alpha() * 100.0 );
2713  mSliderTransparency->blockSignals( false );
2714  mRotationSpinBox->blockSignals( true );
2715  mRotationSpinBox->setValue( mLayer->angle() );
2716  mRotationSpinBox->blockSignals( false );
2717 
2718  mSpinOffsetX->blockSignals( true );
2719  mSpinOffsetX->setValue( mLayer->offset().x() );
2720  mSpinOffsetX->blockSignals( false );
2721  mSpinOffsetY->blockSignals( true );
2722  mSpinOffsetY->setValue( mLayer->offset().y() );
2723  mSpinOffsetY->blockSignals( false );
2724  mOffsetUnitWidget->blockSignals( true );
2725  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
2726  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
2727  mOffsetUnitWidget->blockSignals( false );
2728 
2729  mWidthSpinBox->blockSignals( true );
2730  mWidthSpinBox->setValue( mLayer->width() );
2731  mWidthSpinBox->blockSignals( false );
2732  mWidthUnitWidget->blockSignals( true );
2733  switch ( mLayer->widthUnit() )
2734  {
2735  case QgsSymbolV2::MM:
2736  mWidthUnitWidget->setUnit( 1 );
2737  break;
2738  case QgsSymbolV2::MapUnit:
2739  mWidthUnitWidget->setUnit( 2 );
2740  break;
2741  case QgsSymbolV2::Pixel:
2742  default:
2743  mWidthUnitWidget->setUnit( 0 );
2744  break;
2745  }
2746  mWidthUnitWidget->setMapUnitScale( mLayer->widthMapUnitScale() );
2747  mWidthUnitWidget->blockSignals( false );
2748  updatePreviewImage();
2749 
2754 }
2755 
2757 {
2758  return mLayer;
2759 }
2760 
2761 void QgsRasterFillSymbolLayerWidget::on_mBrowseToolButton_clicked()
2762 {
2763  QSettings s;
2764  QString openDir;
2765  QString lineEditText = mImageLineEdit->text();
2766  if ( !lineEditText.isEmpty() )
2767  {
2768  QFileInfo openDirFileInfo( lineEditText );
2769  openDir = openDirFileInfo.path();
2770  }
2771 
2772  if ( openDir.isEmpty() )
2773  {
2774  openDir = s.value( "/UI/lastRasterFillImageDir", "" ).toString();
2775  }
2776 
2777  //show file dialog
2778  QString filePath = QFileDialog::getOpenFileName( 0, tr( "Select image file" ), openDir );
2779  if ( !filePath.isNull() )
2780  {
2781  //check if file exists
2782  QFileInfo fileInfo( filePath );
2783  if ( !fileInfo.exists() || !fileInfo.isReadable() )
2784  {
2785  QMessageBox::critical( 0, "Invalid file", "Error, file does not exist or is not readable" );
2786  return;
2787  }
2788 
2789  s.setValue( "/UI/lastRasterFillImageDir", fileInfo.absolutePath() );
2790  mImageLineEdit->setText( filePath );
2791  on_mImageLineEdit_editingFinished();
2792  }
2793 }
2794 
2795 void QgsRasterFillSymbolLayerWidget::on_mImageLineEdit_editingFinished()
2796 {
2797  if ( !mLayer )
2798  {
2799  return;
2800  }
2801 
2802  QFileInfo fi( mImageLineEdit->text() );
2803  if ( !fi.exists() )
2804  {
2805  QUrl url( mImageLineEdit->text() );
2806  if ( !url.isValid() )
2807  {
2808  return;
2809  }
2810  }
2811 
2812  QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2813  mLayer->setImageFilePath( mImageLineEdit->text() );
2814  updatePreviewImage();
2815  QApplication::restoreOverrideCursor();
2816 
2817  emit changed();
2818 }
2819 
2820 void QgsRasterFillSymbolLayerWidget::setCoordinateMode( int index )
2821 {
2822  switch ( index )
2823  {
2824  case 0:
2825  //feature coordinate mode
2827  break;
2828  case 1:
2829  //viewport coordinate mode
2831  break;
2832  }
2833 
2834  emit changed();
2835 }
2836 
2837 void QgsRasterFillSymbolLayerWidget::on_mSpinTransparency_valueChanged( int value )
2838 {
2839  if ( !mLayer )
2840  {
2841  return;
2842  }
2843 
2844  mLayer->setAlpha( value / 100.0 );
2845  emit changed();
2846  updatePreviewImage();
2847 }
2848 
2849 void QgsRasterFillSymbolLayerWidget::offsetChanged()
2850 {
2851  mLayer->setOffset( QPointF( mSpinOffsetX->value(), mSpinOffsetY->value() ) );
2852  emit changed();
2853 }
2854 
2855 void QgsRasterFillSymbolLayerWidget::on_mOffsetUnitWidget_changed()
2856 {
2857  if ( !mLayer )
2858  {
2859  return;
2860  }
2861  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
2862  mLayer->setOffsetUnit( unit );
2863  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2864  emit changed();
2865 }
2866 
2867 void QgsRasterFillSymbolLayerWidget::on_mRotationSpinBox_valueChanged( double d )
2868 {
2869  if ( mLayer )
2870  {
2871  mLayer->setAngle( d );
2872  emit changed();
2873  }
2874 }
2875 
2876 void QgsRasterFillSymbolLayerWidget::on_mWidthUnitWidget_changed()
2877 {
2878  if ( !mLayer )
2879  {
2880  return;
2881  }
2883  switch ( mWidthUnitWidget->getUnit() )
2884  {
2885  case 0:
2886  unit = QgsSymbolV2::Pixel;
2887  break;
2888  case 2:
2889  unit = QgsSymbolV2::MapUnit;
2890  break;
2891  case 1:
2892  default:
2893  unit = QgsSymbolV2::MM;
2894  break;
2895  }
2896 
2897  mLayer->setWidthUnit( unit );
2898  mLayer->setWidthMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
2899  emit changed();
2900 }
2901 
2902 void QgsRasterFillSymbolLayerWidget::on_mWidthSpinBox_valueChanged( double d )
2903 {
2904  if ( !mLayer )
2905  {
2906  return;
2907  }
2908  mLayer->setWidth( d );
2909  emit changed();
2910 }
2911 
2912 
2913 void QgsRasterFillSymbolLayerWidget::updatePreviewImage()
2914 {
2915  if ( !mLayer )
2916  {
2917  return;
2918  }
2919 
2920  QImage image( mLayer->imageFilePath() );
2921  if ( image.isNull() )
2922  {
2923  mLabelImagePreview->setPixmap( QPixmap() );
2924  return;
2925  }
2926 
2927  if ( image.height() > 150 || image.width() > 150 )
2928  {
2929  image = image.scaled( 150, 150, Qt::KeepAspectRatio, Qt::SmoothTransformation );
2930  }
2931 
2932  QImage previewImage( 150, 150, QImage::Format_ARGB32 );
2933  previewImage.fill( Qt::transparent );
2934  QRect imageRect(( 150 - image.width() ) / 2.0, ( 150 - image.height() ) / 2.0, image.width(), image.height() );
2935  QPainter p;
2936  p.begin( &previewImage );
2937  //draw a checkerboard background
2938  uchar pixDataRGB[] = { 150, 150, 150, 150,
2939  100, 100, 100, 150,
2940  100, 100, 100, 150,
2941  150, 150, 150, 150
2942  };
2943  QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
2944  QPixmap pix = QPixmap::fromImage( img.scaled( 8, 8 ) );
2945  QBrush checkerBrush;
2946  checkerBrush.setTexture( pix );
2947  p.fillRect( imageRect, checkerBrush );
2948 
2949  if ( mLayer->alpha() < 1.0 )
2950  {
2951  p.setOpacity( mLayer->alpha() );
2952  }
2953 
2954  p.drawImage( imageRect.left(), imageRect.top(), image );
2955  p.end();
2956  mLabelImagePreview->setPixmap( QPixmap::fromImage( previewImage ) );
2957 }