QGIS API Documentation  2.5.0-Master
 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 {
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->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
32  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
33  btnChangeColorFill->setContext( "symbology" );
34  btnChangeColorFill->setShowNoColor( true );
35  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
36  btnChangeColorBorder->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
37  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
38  btnChangeColorBorder->setContext( "symbology" );
39  btnChangeColorBorder->setShowNoColor( true );
40  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
41 
42  QStringList names;
43  names << "circle" << "rectangle" << "cross" << "triangle";
44  QSize iconSize = mShapeListWidget->iconSize();
45 
46  QStringList::const_iterator nameIt = names.constBegin();
47  for ( ; nameIt != names.constEnd(); ++nameIt )
48  {
50  lyr->setSymbolName( *nameIt );
51  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
52  lyr->setFillColor( QColor( 200, 200, 200 ) );
53  lyr->setSymbolWidth( 4 );
54  lyr->setSymbolHeight( 2 );
56  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
57  item->setToolTip( *nameIt );
58  item->setData( Qt::UserRole, *nameIt );
59  delete lyr;
60  }
61 
62  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
63  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
64 }
65 
67 {
68  if ( layer->layerType() != "EllipseMarker" )
69  {
70  return;
71  }
72 
73  mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
74  mWidthSpinBox->setValue( mLayer->symbolWidth() );
75  mHeightSpinBox->setValue( mLayer->symbolHeight() );
76  mRotationSpinBox->setValue( mLayer->angle() );
77  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
78  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
79  btnChangeColorBorder->setColor( mLayer->outlineColor() );
80  btnChangeColorFill->setColor( mLayer->fillColor() );
81 
82  QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
83  if ( symbolItemList.size() > 0 )
84  {
85  mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
86  }
87 
88  //set combo entries to current values
89  blockComboSignals( true );
90  if ( mLayer )
91  {
92  mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
93  mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
94  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
95  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
96  mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
97  mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
98  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
99  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
100  }
101 
102  QPointF offsetPt = mLayer->offset();
103  spinOffsetX->setValue( offsetPt.x() );
104  spinOffsetY->setValue( offsetPt.y() );
105  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
106  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
107  blockComboSignals( false );
108 }
109 
111 {
112  return mLayer;
113 }
114 
116 {
117  if ( mLayer )
118  {
119  QListWidgetItem* item = mShapeListWidget->currentItem();
120  if ( item )
121  {
122  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
123  emit changed();
124  }
125  }
126 }
127 
129 {
130  if ( mLayer )
131  {
132  mLayer->setSymbolWidth( d );
133  emit changed();
134  }
135 }
136 
138 {
139  if ( mLayer )
140  {
141  mLayer->setSymbolHeight( d );
142  emit changed();
143  }
144 }
145 
147 {
148  if ( mLayer )
149  {
150  mLayer->setAngle( d );
151  emit changed();
152  }
153 }
154 
156 {
157  Q_UNUSED( index );
158 
159  if ( mLayer )
160  {
161  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
162  emit changed();
163  }
164 }
165 
167 {
168  if ( mLayer )
169  {
170  mLayer->setOutlineWidth( d );
171  emit changed();
172  }
173 }
174 
176 {
177  if ( !mLayer )
178  {
179  return;
180  }
181 
182  mLayer->setOutlineColor( newColor );
183  emit changed();
184 }
185 
187 {
188  if ( !mLayer )
189  {
190  return;
191  }
192 
193  mLayer->setFillColor( newColor );
194  emit changed();
195 }
196 
198 {
199  if ( mLayer )
200  {
201  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolWidthUnitWidget->getUnit() );
202  mLayer->setSymbolWidthUnit( unit );
203  mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
204  emit changed();
205  }
206 }
207 
209 {
210  if ( mLayer )
211  {
212  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOutlineWidthUnitWidget->getUnit() );
213  mLayer->setOutlineWidthUnit( unit );
214  mLayer->setOutlineWidthMapUnitScale( mOutlineWidthUnitWidget->getMapUnitScale() );
215  emit changed();
216  }
217 }
218 
220 {
221  if ( mLayer )
222  {
223  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mSymbolHeightUnitWidget->getUnit() );
224  mLayer->setSymbolHeightUnit( unit );
225  mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
226  emit changed();
227  }
228 }
229 
231 {
232  if ( mLayer )
233  {
234  QgsSymbolV2::OutputUnit unit = static_cast<QgsSymbolV2::OutputUnit>( mOffsetUnitWidget->getUnit() );
235  mLayer->setOffsetUnit( unit );
236  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
237  emit changed();
238  }
239 }
240 
242 {
243  mSymbolWidthUnitWidget->blockSignals( block );
244  mOutlineWidthUnitWidget->blockSignals( block );
245  mSymbolHeightUnitWidget->blockSignals( block );
246  mHorizontalAnchorComboBox->blockSignals( block );
247  mVerticalAnchorComboBox->blockSignals( block );
248  mSymbolWidthUnitWidget->blockSignals( block );
249  mOutlineWidthUnitWidget->blockSignals( block );
250  mSymbolHeightUnitWidget->blockSignals( block );
251  mOffsetUnitWidget->blockSignals( block );
252 }
253 
255 {
256  if ( mLayer )
257  {
259  emit changed();
260  }
261 }
262 
264 {
265  if ( mLayer )
266  {
268  emit changed();
269  }
270 }
271 
273 {
274  if ( !mLayer )
275  {
276  return;
277  }
278 
279  QList< QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry > dataDefinedProperties;
280  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width", tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ),
282  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "height", tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ),
284  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "rotation", tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ),
286  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_width", tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ),
288  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "fill_color", tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ),
290  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_color", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ),
292  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "symbol_name", tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ),
293  "'circle'|'rectangle'|'cross'|'triangle'" );
294  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
296  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
298  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
300  QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
301  if ( d.exec() == QDialog::Accepted )
302  {
303  //empty all existing properties first
305 
306  QMap<QString, QString> properties = d.dataDefinedProperties();
307  QMap<QString, QString>::const_iterator it = properties.constBegin();
308  for ( ; it != properties.constEnd(); ++it )
309  {
310  if ( !it.value().isEmpty() )
311  {
312  mLayer->setDataDefinedProperty( it.key(), it.value() );
313  }
314  }
315  emit changed();
316  }
317 }
318 
320 {
321  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
322  emit changed();
323 }
324 
325 
VerticalAnchorPoint verticalAnchorPoint() const
static unsigned index
virtual void removeDataDefinedProperties()
void on_btnChangeColorBorder_colorChanged(const QColor &newColor)
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
void on_btnChangeColorFill_colorChanged(const QColor &newColor)
virtual void setDataDefinedProperty(const QString &property, const QString &expressionString)
#define tr(sourceText)