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  QStringList names;
26  names << "circle" << "rectangle" << "cross" << "triangle";
27  QSize iconSize = mShapeListWidget->iconSize();
28 
29  QStringList::const_iterator nameIt = names.constBegin();
30  for ( ; nameIt != names.constEnd(); ++nameIt )
31  {
33  lyr->setSymbolName( *nameIt );
34  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
35  lyr->setFillColor( QColor( 200, 200, 200 ) );
36  lyr->setSymbolWidth( 4 );
37  lyr->setSymbolHeight( 2 );
39  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
40  item->setToolTip( *nameIt );
41  item->setData( Qt::UserRole, *nameIt );
42  delete lyr;
43  }
44 
45  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
46  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
47 }
48 
50 {
51  if ( layer->layerType() != "EllipseMarker" )
52  {
53  return;
54  }
55 
56  mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
57  mWidthSpinBox->setValue( mLayer->symbolWidth() );
58  mHeightSpinBox->setValue( mLayer->symbolHeight() );
59  mRotationSpinBox->setValue( mLayer->angle() );
60  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
61  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
62 
63  btnChangeColorBorder->setColor( mLayer->outlineColor() );
64  btnChangeColorBorder->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
65  btnChangeColorFill->setColor( mLayer->fillColor() );
66  btnChangeColorFill->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
67 
68  QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
69  if ( symbolItemList.size() > 0 )
70  {
71  mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
72  }
73 
74  //set combo entries to current values
75  blockComboSignals( true );
76  if ( mLayer )
77  {
78  mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
79  mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
80  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
81  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
82  mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
83  mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
84  }
85 
86  QPointF offsetPt = mLayer->offset();
87  spinOffsetX->setValue( offsetPt.x() );
88  spinOffsetY->setValue( offsetPt.y() );
89  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
90  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
91  blockComboSignals( false );
92 }
93 
95 {
96  return mLayer;
97 }
98 
100 {
101  if ( mLayer )
102  {
103  QListWidgetItem* item = mShapeListWidget->currentItem();
104  if ( item )
105  {
106  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
107  emit changed();
108  }
109  }
110 }
111 
113 {
114  if ( mLayer )
115  {
116  mLayer->setSymbolWidth( d );
117  emit changed();
118  }
119 }
120 
122 {
123  if ( mLayer )
124  {
125  mLayer->setSymbolHeight( d );
126  emit changed();
127  }
128 }
129 
131 {
132  if ( mLayer )
133  {
134  mLayer->setAngle( d );
135  emit changed();
136  }
137 }
138 
140 {
141  Q_UNUSED( index );
142 
143  if ( mLayer )
144  {
145  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
146  emit changed();
147  }
148 }
149 
151 {
152  if ( mLayer )
153  {
154  mLayer->setOutlineWidth( d );
155  emit changed();
156  }
157 }
158 
160 {
161  if ( !mLayer )
162  {
163  return;
164  }
165 
166  mLayer->setOutlineColor( newColor );
167  emit changed();
168 }
169 
171 {
172  if ( !mLayer )
173  {
174  return;
175  }
176 
177  mLayer->setFillColor( newColor );
178  emit changed();
179 }
180 
182 {
183  if ( mLayer )
184  {
186  emit changed();
187  }
188 }
189 
191 {
192  if ( mLayer )
193  {
195  emit changed();
196  }
197 }
198 
200 {
201  if ( mLayer )
202  {
204  emit changed();
205  }
206 }
207 
209 {
210  if ( mLayer )
211  {
213  emit changed();
214  }
215 }
216 
218 {
219  mSymbolWidthUnitWidget->blockSignals( block );
220  mOutlineWidthUnitWidget->blockSignals( block );
221  mSymbolHeightUnitWidget->blockSignals( block );
222  mHorizontalAnchorComboBox->blockSignals( block );
223  mVerticalAnchorComboBox->blockSignals( block );
224 }
225 
227 {
228  if ( mLayer )
229  {
231  emit changed();
232  }
233 }
234 
236 {
237  if ( mLayer )
238  {
240  emit changed();
241  }
242 }
243 
245 {
246  if ( !mLayer )
247  {
248  return;
249  }
250 
251  QList< QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry > dataDefinedProperties;
252  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width", tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ),
254  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "height", tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ),
256  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "rotation", tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ),
258  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_width", tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ),
260  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "fill_color", tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ),
262  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_color", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ),
264  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "symbol_name", tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ),
265  "'circle'|'rectangle'|'cross'|'triangle'" );
266  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
268  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
270  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
272  QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
273  if ( d.exec() == QDialog::Accepted )
274  {
275  //empty all existing properties first
277 
278  QMap<QString, QString> properties = d.dataDefinedProperties();
279  QMap<QString, QString>::const_iterator it = properties.constBegin();
280  for ( ; it != properties.constEnd(); ++it )
281  {
282  if ( !it.value().isEmpty() )
283  {
284  mLayer->setDataDefinedProperty( it.key(), it.value() );
285  }
286  }
287  emit changed();
288  }
289 }
290 
292 {
293  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
294  emit changed();
295 }
296 
297 
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)
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)
const QgsMapUnitScale & symbolWidthMapUnitScale() const
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 QgsSymbolLayerV2 * symbolLayer()
virtual QString layerType() const =0
const QgsMapUnitScale & outlineWidthMapUnitScale() const
QColor outlineColor() const
Get outline color.
const QgsMapUnitScale & symbolHeightMapUnitScale() const
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.
QgsSymbolV2::OutputUnit outlineWidthUnit() const
void on_btnChangeColorFill_colorChanged(const QColor &newColor)
virtual void setDataDefinedProperty(const QString &property, const QString &expressionString)
#define tr(sourceText)