QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsellipsesymbollayerv2widget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsellipsesymbollayerv2widget.cpp
3  ---------------------
4  begin : June 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
18 #include "qgsmaplayerregistry.h"
19 #include "qgsvectorlayer.h"
20 #include <QColorDialog>
21 
23  : QgsSymbolLayerV2Widget( parent, vl )
24  , mLayer( NULL )
25 {
26  setupUi( this );
27 
28  mSymbolWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
29  mSymbolHeightUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
30  mOutlineWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
31  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
32 
33  btnChangeColorFill->setAllowAlpha( true );
34  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
35  btnChangeColorFill->setContext( "symbology" );
36  btnChangeColorFill->setShowNoColor( true );
37  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
38  btnChangeColorBorder->setAllowAlpha( true );
39  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
40  btnChangeColorBorder->setContext( "symbology" );
41  btnChangeColorBorder->setShowNoColor( true );
42  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
43 
44  spinOffsetX->setClearValue( 0.0 );
45  spinOffsetY->setClearValue( 0.0 );
46  mRotationSpinBox->setClearValue( 0.0 );
47 
48  QStringList names;
49  names << "circle" << "rectangle" << "cross" << "triangle";
50  QSize iconSize = mShapeListWidget->iconSize();
51 
52  QStringList::const_iterator nameIt = names.constBegin();
53  for ( ; nameIt != names.constEnd(); ++nameIt )
54  {
56  lyr->setSymbolName( *nameIt );
57  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
58  lyr->setFillColor( QColor( 200, 200, 200 ) );
59  lyr->setSymbolWidth( 4 );
60  lyr->setSymbolHeight( 2 );
62  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
63  item->setToolTip( *nameIt );
64  item->setData( Qt::UserRole, *nameIt );
65  delete lyr;
66  }
67 
68  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
69  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
70 }
71 
73 {
74  if ( !layer || layer->layerType() != "EllipseMarker" )
75  {
76  return;
77  }
78 
79  mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
80  mWidthSpinBox->setValue( mLayer->symbolWidth() );
81  mHeightSpinBox->setValue( mLayer->symbolHeight() );
82  mRotationSpinBox->setValue( mLayer->angle() );
83  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
84  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
85  btnChangeColorBorder->setColor( mLayer->outlineColor() );
86  btnChangeColorFill->setColor( mLayer->fillColor() );
87 
88  QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
89  if ( symbolItemList.size() > 0 )
90  {
91  mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
92  }
93 
94  //set combo entries to current values
95  blockComboSignals( true );
96  mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
97  mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
98  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
99  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
100  mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
101  mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
102  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
103  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
104  QPointF offsetPt = mLayer->offset();
105  spinOffsetX->setValue( offsetPt.x() );
106  spinOffsetY->setValue( offsetPt.y() );
107  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
108  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
109  blockComboSignals( false );
110 
120  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
121  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
122 
123 }
124 
126 {
127  return mLayer;
128 }
129 
130 void QgsEllipseSymbolLayerV2Widget::on_mShapeListWidget_itemSelectionChanged()
131 {
132  if ( mLayer )
133  {
134  QListWidgetItem* item = mShapeListWidget->currentItem();
135  if ( item )
136  {
137  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
138  emit changed();
139  }
140  }
141 }
142 
143 void QgsEllipseSymbolLayerV2Widget::on_mWidthSpinBox_valueChanged( double d )
144 {
145  if ( mLayer )
146  {
147  mLayer->setSymbolWidth( d );
148  emit changed();
149  }
150 }
151 
152 void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
153 {
154  if ( mLayer )
155  {
156  mLayer->setSymbolHeight( d );
157  emit changed();
158  }
159 }
160 
161 void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
162 {
163  if ( mLayer )
164  {
165  mLayer->setAngle( d );
166  emit changed();
167  }
168 }
169 
170 void QgsEllipseSymbolLayerV2Widget::on_mOutlineStyleComboBox_currentIndexChanged( int index )
171 {
172  Q_UNUSED( index );
173 
174  if ( mLayer )
175  {
176  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
177  emit changed();
178  }
179 }
180 
181 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
182 {
183  if ( mLayer )
184  {
185  mLayer->setOutlineWidth( d );
186  emit changed();
187  }
188 }
189 
190 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorBorder_colorChanged( const QColor& newColor )
191 {
192  if ( !mLayer )
193  {
194  return;
195  }
196 
197  mLayer->setOutlineColor( newColor );
198  emit changed();
199 }
200 
201 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_colorChanged( const QColor& newColor )
202 {
203  if ( !mLayer )
204  {
205  return;
206  }
207 
208  mLayer->setFillColor( newColor );
209  emit changed();
210 }
211 
212 void QgsEllipseSymbolLayerV2Widget::on_mSymbolWidthUnitWidget_changed()
213 {
214  if ( mLayer )
215  {
216  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolWidthUnitWidget->getUnit() );
217  mLayer->setSymbolWidthUnit( unit );
218  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
219  emit changed();
220  }
221 }
222 
223 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthUnitWidget_changed()
224 {
225  if ( mLayer )
226  {
227  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOutlineWidthUnitWidget->getUnit() );
228  mLayer->setOutlineWidthUnit( unit );
229  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
230  emit changed();
231  }
232 }
233 
234 void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitWidget_changed()
235 {
236  if ( mLayer )
237  {
238  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolHeightUnitWidget->getUnit() );
239  mLayer->setSymbolHeightUnit( unit );
240  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
241  emit changed();
242  }
243 }
244 
245 void QgsEllipseSymbolLayerV2Widget::on_mOffsetUnitWidget_changed()
246 {
247  if ( mLayer )
248  {
249  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
250  mLayer->setOffsetUnit( unit );
251  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
252  emit changed();
253  }
254 }
255 
256 void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
257 {
258  mSymbolWidthUnitWidget->blockSignals( block );
259  mOutlineWidthUnitWidget->blockSignals( block );
260  mSymbolHeightUnitWidget->blockSignals( block );
261  mHorizontalAnchorComboBox->blockSignals( block );
262  mVerticalAnchorComboBox->blockSignals( block );
263  mSymbolWidthUnitWidget->blockSignals( block );
264  mOutlineWidthUnitWidget->blockSignals( block );
265  mSymbolHeightUnitWidget->blockSignals( block );
266  mOffsetUnitWidget->blockSignals( block );
267 }
268 
269 void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
270 {
271  if ( mLayer )
272  {
274  emit changed();
275  }
276 }
277 
278 void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
279 {
280  if ( mLayer )
281  {
283  emit changed();
284  }
285 }
286 
287 void QgsEllipseSymbolLayerV2Widget::setOffset()
288 {
289  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
290  emit changed();
291 }
292 
293