QGIS API Documentation  2.7.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 {
24  setupUi( this );
25 
26  mSymbolWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
27  mSymbolHeightUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
28  mOutlineWidthUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
29  mOffsetUnitWidget->setUnits( QStringList() << tr( "Millimeter" ) << tr( "Map unit" ), 1 );
30 
31  btnChangeColorFill->setAllowAlpha( true );
32  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
33  btnChangeColorFill->setContext( "symbology" );
34  btnChangeColorFill->setShowNoColor( true );
35  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
36  btnChangeColorBorder->setAllowAlpha( true );
37  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
38  btnChangeColorBorder->setContext( "symbology" );
39  btnChangeColorBorder->setShowNoColor( true );
40  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
41 
42  spinOffsetX->setClearValue( 0.0 );
43  spinOffsetY->setClearValue( 0.0 );
44  mRotationSpinBox->setClearValue( 0.0 );
45 
46  QStringList names;
47  names << "circle" << "rectangle" << "cross" << "triangle";
48  QSize iconSize = mShapeListWidget->iconSize();
49 
50  QStringList::const_iterator nameIt = names.constBegin();
51  for ( ; nameIt != names.constEnd(); ++nameIt )
52  {
54  lyr->setSymbolName( *nameIt );
55  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
56  lyr->setFillColor( QColor( 200, 200, 200 ) );
57  lyr->setSymbolWidth( 4 );
58  lyr->setSymbolHeight( 2 );
60  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
61  item->setToolTip( *nameIt );
62  item->setData( Qt::UserRole, *nameIt );
63  delete lyr;
64  }
65 
66  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
67  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
68 }
69 
71 {
72  if ( layer->layerType() != "EllipseMarker" )
73  {
74  return;
75  }
76 
77  mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
78  mWidthSpinBox->setValue( mLayer->symbolWidth() );
79  mHeightSpinBox->setValue( mLayer->symbolHeight() );
80  mRotationSpinBox->setValue( mLayer->angle() );
81  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
82  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
83  btnChangeColorBorder->setColor( mLayer->outlineColor() );
84  btnChangeColorFill->setColor( mLayer->fillColor() );
85 
86  QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
87  if ( symbolItemList.size() > 0 )
88  {
89  mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
90  }
91 
92  //set combo entries to current values
93  blockComboSignals( true );
94  if ( mLayer )
95  {
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  }
105 
106  QPointF offsetPt = mLayer->offset();
107  spinOffsetX->setValue( offsetPt.x() );
108  spinOffsetY->setValue( offsetPt.y() );
109  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
110  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
111  blockComboSignals( false );
112 
122  registerDataDefinedButton( mHorizontalAnchorDDBtn, "horizontal_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::horizontalAnchorDesc() );
123  registerDataDefinedButton( mVerticalAnchorDDBtn, "vertical_anchor_point", QgsDataDefinedButton::String, QgsDataDefinedButton::verticalAnchorDesc() );
124 
125 }
126 
128 {
129  return mLayer;
130 }
131 
132 void QgsEllipseSymbolLayerV2Widget::on_mShapeListWidget_itemSelectionChanged()
133 {
134  if ( mLayer )
135  {
136  QListWidgetItem* item = mShapeListWidget->currentItem();
137  if ( item )
138  {
139  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
140  emit changed();
141  }
142  }
143 }
144 
145 void QgsEllipseSymbolLayerV2Widget::on_mWidthSpinBox_valueChanged( double d )
146 {
147  if ( mLayer )
148  {
149  mLayer->setSymbolWidth( d );
150  emit changed();
151  }
152 }
153 
154 void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
155 {
156  if ( mLayer )
157  {
158  mLayer->setSymbolHeight( d );
159  emit changed();
160  }
161 }
162 
163 void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
164 {
165  if ( mLayer )
166  {
167  mLayer->setAngle( d );
168  emit changed();
169  }
170 }
171 
172 void QgsEllipseSymbolLayerV2Widget::on_mOutlineStyleComboBox_currentIndexChanged( int index )
173 {
174  Q_UNUSED( index );
175 
176  if ( mLayer )
177  {
178  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
179  emit changed();
180  }
181 }
182 
183 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
184 {
185  if ( mLayer )
186  {
187  mLayer->setOutlineWidth( d );
188  emit changed();
189  }
190 }
191 
192 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorBorder_colorChanged( const QColor& newColor )
193 {
194  if ( !mLayer )
195  {
196  return;
197  }
198 
199  mLayer->setOutlineColor( newColor );
200  emit changed();
201 }
202 
203 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_colorChanged( const QColor& newColor )
204 {
205  if ( !mLayer )
206  {
207  return;
208  }
209 
210  mLayer->setFillColor( newColor );
211  emit changed();
212 }
213 
214 void QgsEllipseSymbolLayerV2Widget::on_mSymbolWidthUnitWidget_changed()
215 {
216  if ( mLayer )
217  {
218  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolWidthUnitWidget->getUnit() );
219  mLayer->setSymbolWidthUnit( unit );
220  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
221  emit changed();
222  }
223 }
224 
225 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthUnitWidget_changed()
226 {
227  if ( mLayer )
228  {
229  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOutlineWidthUnitWidget->getUnit() );
230  mLayer->setOutlineWidthUnit( unit );
231  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
232  emit changed();
233  }
234 }
235 
236 void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitWidget_changed()
237 {
238  if ( mLayer )
239  {
240  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolHeightUnitWidget->getUnit() );
241  mLayer->setSymbolHeightUnit( unit );
242  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
243  emit changed();
244  }
245 }
246 
247 void QgsEllipseSymbolLayerV2Widget::on_mOffsetUnitWidget_changed()
248 {
249  if ( mLayer )
250  {
251  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
252  mLayer->setOffsetUnit( unit );
253  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
254  emit changed();
255  }
256 }
257 
258 void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
259 {
260  mSymbolWidthUnitWidget->blockSignals( block );
261  mOutlineWidthUnitWidget->blockSignals( block );
262  mSymbolHeightUnitWidget->blockSignals( block );
263  mHorizontalAnchorComboBox->blockSignals( block );
264  mVerticalAnchorComboBox->blockSignals( block );
265  mSymbolWidthUnitWidget->blockSignals( block );
266  mOutlineWidthUnitWidget->blockSignals( block );
267  mSymbolHeightUnitWidget->blockSignals( block );
268  mOffsetUnitWidget->blockSignals( block );
269 }
270 
271 void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
272 {
273  if ( mLayer )
274  {
276  emit changed();
277  }
278 }
279 
280 void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
281 {
282  if ( mLayer )
283  {
285  emit changed();
286  }
287 }
288 
289 void QgsEllipseSymbolLayerV2Widget::setOffset()
290 {
291  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
292  emit changed();
293 }
294 
295 
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
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)