QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
29  mSymbolHeightUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
30  mOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
31  mOffsetUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
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  mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
217  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
218  emit changed();
219  }
220 }
221 
222 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthUnitWidget_changed()
223 {
224  if ( mLayer )
225  {
226  mLayer->setOutlineWidthUnit( mOutlineWidthUnitWidget->unit() );
227  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
228  emit changed();
229  }
230 }
231 
232 void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitWidget_changed()
233 {
234  if ( mLayer )
235  {
236  mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
237  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
238  emit changed();
239  }
240 }
241 
242 void QgsEllipseSymbolLayerV2Widget::on_mOffsetUnitWidget_changed()
243 {
244  if ( mLayer )
245  {
246  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
247  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
248  emit changed();
249  }
250 }
251 
252 void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
253 {
254  mSymbolWidthUnitWidget->blockSignals( block );
255  mOutlineWidthUnitWidget->blockSignals( block );
256  mSymbolHeightUnitWidget->blockSignals( block );
257  mHorizontalAnchorComboBox->blockSignals( block );
258  mVerticalAnchorComboBox->blockSignals( block );
259  mSymbolWidthUnitWidget->blockSignals( block );
260  mOutlineWidthUnitWidget->blockSignals( block );
261  mSymbolHeightUnitWidget->blockSignals( block );
262  mOffsetUnitWidget->blockSignals( block );
263 }
264 
265 void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
266 {
267  if ( mLayer )
268  {
270  emit changed();
271  }
272 }
273 
274 void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
275 {
276  if ( mLayer )
277  {
279  emit changed();
280  }
281 }
282 
283 void QgsEllipseSymbolLayerV2Widget::setOffset()
284 {
285  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
286  emit changed();
287 }
288 
289 
VerticalAnchorPoint verticalAnchorPoint() const
static unsigned index
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
QColor fillColor() const override
Get fill color.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
static QString doublePosDesc()
HorizontalAnchorPoint horizontalAnchorPoint() const
virtual QgsSymbolLayerV2 * symbolLayer() override
QList< OutputUnit > OutputUnitList
Definition: qgssymbolv2.h:59
void setOffset(QPointF offset)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
void setVerticalAnchorPoint(VerticalAnchorPoint v)
static QString lineStyleDesc()
QColor outlineColor() const override
Get outline color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
static QString horizontalAnchorDesc()
A symbol layer for rendering objects with major and minor axis (e.g.
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit offsetUnit() const
const QgsMapUnitScale & symbolWidthMapUnitScale() const
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
static QString double180RotDesc()
void registerDataDefinedButton(QgsDataDefinedButton *button, const QString &propertyName, QgsDataDefinedButton::DataType type, const QString &description)
QgsEllipseSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=0)
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
QgsSymbolV2::OutputUnit symbolHeightUnit() const
static QString markerStyleDesc()
virtual QString layerType() const =0
const QgsMapUnitScale & outlineWidthMapUnitScale() const
const QgsMapUnitScale & offsetMapUnitScale() const
const QgsMapUnitScale & symbolHeightMapUnitScale() const
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
static QString verticalAnchorDesc()
void setOutlineColor(const QColor &c) override
Set outline color.
Qt::PenStyle outlineStyle() const
virtual void setColor(const QColor &color)
QgsSymbolV2::OutputUnit symbolWidthUnit() const
void setAngle(double angle)
Represents a vector layer which manages a vector based data sets.
void setFillColor(const QColor &c) override
Set fill color.
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
static QString colorAlphaDesc()
QgsSymbolV2::OutputUnit outlineWidthUnit() const
#define tr(sourceText)