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 }
113 
115 {
116  return mLayer;
117 }
118 
119 void QgsEllipseSymbolLayerV2Widget::on_mShapeListWidget_itemSelectionChanged()
120 {
121  if ( mLayer )
122  {
123  QListWidgetItem* item = mShapeListWidget->currentItem();
124  if ( item )
125  {
126  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
127  emit changed();
128  }
129  }
130 }
131 
132 void QgsEllipseSymbolLayerV2Widget::on_mWidthSpinBox_valueChanged( double d )
133 {
134  if ( mLayer )
135  {
136  mLayer->setSymbolWidth( d );
137  emit changed();
138  }
139 }
140 
141 void QgsEllipseSymbolLayerV2Widget::on_mHeightSpinBox_valueChanged( double d )
142 {
143  if ( mLayer )
144  {
145  mLayer->setSymbolHeight( d );
146  emit changed();
147  }
148 }
149 
150 void QgsEllipseSymbolLayerV2Widget::on_mRotationSpinBox_valueChanged( double d )
151 {
152  if ( mLayer )
153  {
154  mLayer->setAngle( d );
155  emit changed();
156  }
157 }
158 
159 void QgsEllipseSymbolLayerV2Widget::on_mOutlineStyleComboBox_currentIndexChanged( int index )
160 {
161  Q_UNUSED( index );
162 
163  if ( mLayer )
164  {
165  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
166  emit changed();
167  }
168 }
169 
170 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthSpinBox_valueChanged( double d )
171 {
172  if ( mLayer )
173  {
174  mLayer->setOutlineWidth( d );
175  emit changed();
176  }
177 }
178 
179 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorBorder_colorChanged( const QColor& newColor )
180 {
181  if ( !mLayer )
182  {
183  return;
184  }
185 
186  mLayer->setOutlineColor( newColor );
187  emit changed();
188 }
189 
190 void QgsEllipseSymbolLayerV2Widget::on_btnChangeColorFill_colorChanged( const QColor& newColor )
191 {
192  if ( !mLayer )
193  {
194  return;
195  }
196 
197  mLayer->setFillColor( newColor );
198  emit changed();
199 }
200 
201 void QgsEllipseSymbolLayerV2Widget::on_mSymbolWidthUnitWidget_changed()
202 {
203  if ( mLayer )
204  {
205  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolWidthUnitWidget->getUnit() );
206  mLayer->setSymbolWidthUnit( unit );
207  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
208  emit changed();
209  }
210 }
211 
212 void QgsEllipseSymbolLayerV2Widget::on_mOutlineWidthUnitWidget_changed()
213 {
214  if ( mLayer )
215  {
216  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOutlineWidthUnitWidget->getUnit() );
217  mLayer->setOutlineWidthUnit( unit );
218  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
219  emit changed();
220  }
221 }
222 
223 void QgsEllipseSymbolLayerV2Widget::on_mSymbolHeightUnitWidget_changed()
224 {
225  if ( mLayer )
226  {
227  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolHeightUnitWidget->getUnit() );
228  mLayer->setSymbolHeightUnit( unit );
229  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
230  emit changed();
231  }
232 }
233 
234 void QgsEllipseSymbolLayerV2Widget::on_mOffsetUnitWidget_changed()
235 {
236  if ( mLayer )
237  {
238  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
239  mLayer->setOffsetUnit( unit );
240  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
241  emit changed();
242  }
243 }
244 
245 void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
246 {
247  mSymbolWidthUnitWidget->blockSignals( block );
248  mOutlineWidthUnitWidget->blockSignals( block );
249  mSymbolHeightUnitWidget->blockSignals( block );
250  mHorizontalAnchorComboBox->blockSignals( block );
251  mVerticalAnchorComboBox->blockSignals( block );
252  mSymbolWidthUnitWidget->blockSignals( block );
253  mOutlineWidthUnitWidget->blockSignals( block );
254  mSymbolHeightUnitWidget->blockSignals( block );
255  mOffsetUnitWidget->blockSignals( block );
256 }
257 
258 void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
259 {
260  if ( mLayer )
261  {
263  emit changed();
264  }
265 }
266 
267 void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
268 {
269  if ( mLayer )
270  {
272  emit changed();
273  }
274 }
275 
276 void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
277 {
278  if ( !mLayer )
279  {
280  return;
281  }
282 
283  QList< QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry > dataDefinedProperties;
284  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width", tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ),
286  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "height", tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ),
288  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "rotation", tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ),
290  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_width", tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ),
292  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "fill_color", tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ),
294  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_color", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ),
296  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "symbol_name", tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ),
297  "'circle'|'rectangle'|'cross'|'triangle'" );
298  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
300  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
302  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
304  QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
305  if ( d.exec() == QDialog::Accepted )
306  {
307  //empty all existing properties first
309 
310  QMap<QString, QString> properties = d.dataDefinedProperties();
311  QMap<QString, QString>::const_iterator it = properties.constBegin();
312  for ( ; it != properties.constEnd(); ++it )
313  {
314  if ( !it.value().isEmpty() )
315  {
316  mLayer->setDataDefinedProperty( it.key(), it.value() );
317  }
318  }
319  emit changed();
320  }
321 }
322 
323 void QgsEllipseSymbolLayerV2Widget::setOffset()
324 {
325  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
326  emit changed();
327 }
328 
329 
VerticalAnchorPoint verticalAnchorPoint() const
static unsigned index
virtual void removeDataDefinedProperties()
void setSymbolWidthUnit(QgsSymbolV2::OutputUnit unit)
QColor fillColor() const
Get fill color.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
HorizontalAnchorPoint horizontalAnchorPoint() const
void setOffset(QPointF offset)
void setOutlineWidthUnit(QgsSymbolV2::OutputUnit unit)
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
void setVerticalAnchorPoint(VerticalAnchorPoint v)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer)
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
static QIcon icon(QString icon)
A symbol layer for rendering objects with major and minor axis (e.g.
const QgsVectorLayer * mVectorLayer
virtual QString dataDefinedPropertyString(const QString &property) const
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
QgsSymbolV2::OutputUnit offsetUnit() const
const QgsMapUnitScale & symbolWidthMapUnitScale() const
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
void setFillColor(const QColor &c)
Set fill color.
QgsEllipseSymbolLayerV2Widget(const QgsVectorLayer *vl, QWidget *parent=0)
void setOutlineStyle(Qt::PenStyle outlineStyle)
void setSymbolName(const QString &name)
QgsSymbolV2::OutputUnit symbolHeightUnit() const
virtual QString layerType() const =0
const QgsMapUnitScale & outlineWidthMapUnitScale() const
QColor outlineColor() const
Get outline color.
const QgsMapUnitScale & offsetMapUnitScale() const
const QgsMapUnitScale & symbolHeightMapUnitScale() const
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
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 setSymbolHeightUnit(QgsSymbolV2::OutputUnit unit)
void setOutlineColor(const QColor &c)
Set outline color.
void setOutlineWidthMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolV2::OutputUnit outlineWidthUnit() const
virtual void setDataDefinedProperty(const QString &property, const QString &expressionString)
#define tr(sourceText)