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  btnChangeColorFill->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
27  btnChangeColorFill->setColorDialogTitle( tr( "Select fill color" ) );
28  btnChangeColorFill->setContext( "symbology" );
29  btnChangeColorFill->setShowNoColor( true );
30  btnChangeColorFill->setNoColorString( tr( "Transparent fill" ) );
31  btnChangeColorBorder->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
32  btnChangeColorBorder->setColorDialogTitle( tr( "Select border color" ) );
33  btnChangeColorBorder->setContext( "symbology" );
34  btnChangeColorBorder->setShowNoColor( true );
35  btnChangeColorBorder->setNoColorString( tr( "Transparent border" ) );
36 
37  QStringList names;
38  names << "circle" << "rectangle" << "cross" << "triangle";
39  QSize iconSize = mShapeListWidget->iconSize();
40 
41  QStringList::const_iterator nameIt = names.constBegin();
42  for ( ; nameIt != names.constEnd(); ++nameIt )
43  {
45  lyr->setSymbolName( *nameIt );
46  lyr->setOutlineColor( QColor( 0, 0, 0 ) );
47  lyr->setFillColor( QColor( 200, 200, 200 ) );
48  lyr->setSymbolWidth( 4 );
49  lyr->setSymbolHeight( 2 );
51  QListWidgetItem* item = new QListWidgetItem( icon, "", mShapeListWidget );
52  item->setToolTip( *nameIt );
53  item->setData( Qt::UserRole, *nameIt );
54  delete lyr;
55  }
56 
57  connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
58  connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
59 }
60 
62 {
63  if ( layer->layerType() != "EllipseMarker" )
64  {
65  return;
66  }
67 
68  mLayer = static_cast<QgsEllipseSymbolLayerV2*>( layer );
69  mWidthSpinBox->setValue( mLayer->symbolWidth() );
70  mHeightSpinBox->setValue( mLayer->symbolHeight() );
71  mRotationSpinBox->setValue( mLayer->angle() );
72  mOutlineStyleComboBox->setPenStyle( mLayer->outlineStyle() );
73  mOutlineWidthSpinBox->setValue( mLayer->outlineWidth() );
74  btnChangeColorBorder->setColor( mLayer->outlineColor() );
75  btnChangeColorFill->setColor( mLayer->fillColor() );
76 
77  QList<QListWidgetItem *> symbolItemList = mShapeListWidget->findItems( mLayer->symbolName(), Qt::MatchExactly );
78  if ( symbolItemList.size() > 0 )
79  {
80  mShapeListWidget->setCurrentItem( symbolItemList.at( 0 ) );
81  }
82 
83  //set combo entries to current values
84  blockComboSignals( true );
85  if ( mLayer )
86  {
87  mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
88  mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
89  mOutlineWidthUnitWidget->setUnit( mLayer->outlineWidthUnit() );
90  mOutlineWidthUnitWidget->setMapUnitScale( mLayer->outlineWidthMapUnitScale() );
91  mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
92  mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
93  }
94 
95  QPointF offsetPt = mLayer->offset();
96  spinOffsetX->setValue( offsetPt.x() );
97  spinOffsetY->setValue( offsetPt.y() );
98  mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
99  mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
100  blockComboSignals( false );
101 }
102 
104 {
105  return mLayer;
106 }
107 
109 {
110  if ( mLayer )
111  {
112  QListWidgetItem* item = mShapeListWidget->currentItem();
113  if ( item )
114  {
115  mLayer->setSymbolName( item->data( Qt::UserRole ).toString() );
116  emit changed();
117  }
118  }
119 }
120 
122 {
123  if ( mLayer )
124  {
125  mLayer->setSymbolWidth( d );
126  emit changed();
127  }
128 }
129 
131 {
132  if ( mLayer )
133  {
134  mLayer->setSymbolHeight( d );
135  emit changed();
136  }
137 }
138 
140 {
141  if ( mLayer )
142  {
143  mLayer->setAngle( d );
144  emit changed();
145  }
146 }
147 
149 {
150  Q_UNUSED( index );
151 
152  if ( mLayer )
153  {
154  mLayer->setOutlineStyle( mOutlineStyleComboBox->penStyle() );
155  emit changed();
156  }
157 }
158 
160 {
161  if ( mLayer )
162  {
163  mLayer->setOutlineWidth( d );
164  emit changed();
165  }
166 }
167 
169 {
170  if ( !mLayer )
171  {
172  return;
173  }
174 
175  mLayer->setOutlineColor( newColor );
176  emit changed();
177 }
178 
180 {
181  if ( !mLayer )
182  {
183  return;
184  }
185 
186  mLayer->setFillColor( newColor );
187  emit changed();
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  if ( mLayer )
220  {
222  emit changed();
223  }
224 }
225 
227 {
228  mSymbolWidthUnitWidget->blockSignals( block );
229  mOutlineWidthUnitWidget->blockSignals( block );
230  mSymbolHeightUnitWidget->blockSignals( block );
231  mHorizontalAnchorComboBox->blockSignals( block );
232  mVerticalAnchorComboBox->blockSignals( block );
233 }
234 
236 {
237  if ( mLayer )
238  {
240  emit changed();
241  }
242 }
243 
245 {
246  if ( mLayer )
247  {
249  emit changed();
250  }
251 }
252 
254 {
255  if ( !mLayer )
256  {
257  return;
258  }
259 
260  QList< QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry > dataDefinedProperties;
261  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width", tr( "Symbol width" ), mLayer->dataDefinedPropertyString( "width" ),
263  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "height", tr( "Symbol height" ), mLayer->dataDefinedPropertyString( "height" ),
265  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "rotation", tr( "Rotation" ), mLayer->dataDefinedPropertyString( "rotation" ),
267  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_width", tr( "Outline width" ), mLayer->dataDefinedPropertyString( "outline_width" ),
269  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "fill_color", tr( "Fill color" ), mLayer->dataDefinedPropertyString( "fill_color" ),
271  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline_color", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline_color" ),
273  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "symbol_name", tr( "Symbol name" ), mLayer->dataDefinedPropertyString( "symbol_name" ),
274  "'circle'|'rectangle'|'cross'|'triangle'" );
275  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
277  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
279  dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
281  QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
282  if ( d.exec() == QDialog::Accepted )
283  {
284  //empty all existing properties first
286 
287  QMap<QString, QString> properties = d.dataDefinedProperties();
288  QMap<QString, QString>::const_iterator it = properties.constBegin();
289  for ( ; it != properties.constEnd(); ++it )
290  {
291  if ( !it.value().isEmpty() )
292  {
293  mLayer->setDataDefinedProperty( it.key(), it.value() );
294  }
295  }
296  emit changed();
297  }
298 }
299 
301 {
302  mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
303  emit changed();
304 }
305 
306 
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 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)