QGIS API Documentation  2.15.0-Master (af20121)
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( nullptr )
25 {
26  setupUi( this );
27 
28  mSymbolWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
29  mSymbolHeightUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
30  mOutlineWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
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" << "diamond" << "cross" << "triangle" << "right_half_triangle" << "left_half_triangle" << "semi_circle";
50  QSize iconSize = mShapeListWidget->iconSize();
51 
52  Q_FOREACH ( const QString& name, names )
53  {
55  lyr->setSymbolName( name );
56  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
57  lyr->setFillColor( QColor( 200, 200, 200 ) );
58  lyr->setSymbolWidth( 4 );
59  lyr->setSymbolHeight( 2 );
61  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
62  item->setToolTip( name );
63  item->setData( Qt::UserRole, name );
64  delete lyr;
65  }
66 
67  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
68  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
69  connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( penJoinStyleChanged() ) );
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.isEmpty() )
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  cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
110  blockComboSignals( false );
111 
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  mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
219  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
220  emit changed();
221  }
222 }
223 
224 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthUnitWidget_changed()
225 {
226  if ( mLayer )
227  {
228  mLayer->setOutlineWidthUnit( mOutlineWidthUnitWidget->unit() );
229  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
230  emit changed();
231  }
232 }
233 
234 void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitWidget_changed()
235 {
236  if ( mLayer )
237  {
238  mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
239  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
240  emit changed();
241  }
242 }
243 
244 void QgsEllipseSymbolLayerV2Widget::on_mOffsetUnitWidget_changed()
245 {
246  if ( mLayer )
247  {
248  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
249  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
250  emit changed();
251  }
252 }
253 
254 void QgsEllipseSymbolLayerV2Widget::penJoinStyleChanged()
255 {
256  mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
257  emit changed();
258 }
259 
260 void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
261 {
262  mSymbolWidthUnitWidget->blockSignals( block );
263  mOutlineWidthUnitWidget->blockSignals( block );
264  mSymbolHeightUnitWidget->blockSignals( block );
265  mHorizontalAnchorComboBox->blockSignals( block );
266  mVerticalAnchorComboBox->blockSignals( block );
267  mSymbolWidthUnitWidget->blockSignals( block );
268  mOutlineWidthUnitWidget->blockSignals( block );
269  mSymbolHeightUnitWidget->blockSignals( block );
270  mOffsetUnitWidget->blockSignals( block );
271  cboJoinStyle->blockSignals( block );
272 }
273 
274 void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
275 {
276  if ( mLayer )
277  {
279  emit changed();
280  }
281 }
282 
283 void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
284 {
285  if ( mLayer )
286  {
288  emit changed();
289  }
290 }
291 
292 void QgsEllipseSymbolLayerV2Widget::setOffset()
293 {
294  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
295  emit changed();
296 }
297 
298 
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
static unsigned index
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
QColor fillColor() const override
Get fill color.
void setupUi(QWidget *widget)
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
static QString doublePosDesc()
HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
virtual QgsSymbolLayerV2 * symbolLayer() override
The output shall be in pixels.
Definition: qgssymbolv2.h:67
const T & at(int i) const
void setOffset(QPointF offset)
Sets the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered marker...
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
static QString lineStyleDesc()
const QPixmap * icon() const
QColor outlineColor() const override
Get outline color.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol&#39;s offset.
static QString horizontalAnchorDesc()
A symbol layer for rendering objects with major and minor axis (e.g.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the symbol&#39;s offset.
const char * name() const
QgsSymbolV2::OutputUnit offsetUnit() const
Returns the units for the symbol&#39;s offset.
const QgsMapUnitScale & symbolWidthMapUnitScale() const
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
The output shall be in millimeters.
Definition: qgssymbolv2.h:64
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
qreal x() const
qreal y() const
static QString penJoinStyleDesc()
static QString double180RotDesc()
void setToolTip(const QString &toolTip)
void registerDataDefinedButton(QgsDataDefinedButton *button, const QString &propertyName, QgsDataDefinedButton::DataType type, const QString &description)
QgsEllipseSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
bool isEmpty() const
The output shall be in map unitx.
Definition: qgssymbolv2.h:65
virtual QVariant data(int role) const
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
QgsSymbolV2::OutputUnit symbolHeightUnit() const
virtual void setData(int role, const QVariant &value)
static QString markerStyleDesc()
virtual QString layerType() const =0
Returns a string that represents this layer type.
Qt::PenJoinStyle penJoinStyle() const
Get outline join style.
const QgsMapUnitScale & outlineWidthMapUnitScale() const
VerticalAnchorPoint
Symbol vertical anchor points.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the symbol&#39;s offset.
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)
The fill color.
QgsSymbolV2::OutputUnit symbolWidthUnit() const
HorizontalAnchorPoint
Symbol horizontal anchor points.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set outline join style.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setAngle(double angle)
Sets the rotation angle for the marker.
Represents a vector layer which manages a vector based data sets.
QPointF offset() const
Returns the marker&#39;s offset, which is the horizontal and vertical displacement which the rendered mar...
QString toString() const
void setFillColor(const QColor &c) override
Set fill color.
void setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
static QString colorAlphaDesc()
QgsSymbolV2::OutputUnit outlineWidthUnit() const