QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsvectorfieldsymbollayerwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorfieldsymbollayerwidget.cpp
3  ---------------------
4  begin : October 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  ***************************************************************************/
17 #include "qgsvectorlayer.h"
18 
20 {
21  setupUi( this );
22 
23  mDistanceUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit );
24 
25  if ( mVectorLayer )
26  {
27  const QgsFields& fm = mVectorLayer->fields();
28  mXAttributeComboBox->addItem( "" );
29  mYAttributeComboBox->addItem( "" );
30  for ( int idx = 0; idx < fm.count(); ++idx )
31  {
32  QString fieldName = fm[idx].name();
33  mXAttributeComboBox->addItem( fieldName );
34  mYAttributeComboBox->addItem( fieldName );
35  }
36  }
37 }
38 
40 {
41 }
42 
44 {
45  if ( layer->layerType() != "VectorField" )
46  {
47  return;
48  }
49  mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
50  if ( !mLayer )
51  {
52  return;
53  }
54 
55  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
56  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
57  mScaleSpinBox->setValue( mLayer->scale() );
58 
61  {
62  mCartesianRadioButton->setChecked( true );
63  }
64  else if ( type == QgsVectorFieldSymbolLayer::Polar )
65  {
66  mPolarRadioButton->setChecked( true );
67  }
68  else if ( type == QgsVectorFieldSymbolLayer::Height )
69  {
70  mHeightRadioButton->setChecked( true );
71  }
72 
75  {
76  mClockwiseFromNorthRadioButton->setChecked( true );
77  }
79  {
80  mCounterclockwiseFromEastRadioButton->setChecked( true );
81  }
82 
84  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
85  {
86  mDegreesRadioButton->setChecked( true );
87  }
88  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
89  {
90  mRadiansRadioButton->setChecked( true );
91  }
92 
93  mDistanceUnitWidget->blockSignals( true );
94  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
95  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
96  mDistanceUnitWidget->blockSignals( false );
97 
98  emit changed();
99 }
100 
102 {
103  return mLayer;
104 }
105 
106 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
107 {
108  if ( mLayer )
109  {
110  mLayer->setScale( d );
111  emit changed();
112  }
113 }
114 
115 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
116 {
117  if ( mLayer )
118  {
119  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
120  emit changed();
121  }
122 }
123 
124 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
125 {
126  if ( mLayer )
127  {
128  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
129  emit changed();
130  }
131 }
132 
133 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
134 {
135  if ( mLayer && checked )
136  {
138  mXAttributeComboBox->setEnabled( true );
139  mYAttributeComboBox->setEnabled( true );
140  mXAttributeLabel->setText( tr( "X attribute" ) );
141  mYAttributeLabel->setText( tr( "Y attribute" ) );
142  emit changed();
143  }
144 }
145 
146 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
147 {
148  if ( mLayer && checked )
149  {
151  mXAttributeComboBox->setEnabled( true );
152  mYAttributeComboBox->setEnabled( true );
153  mXAttributeLabel->setText( tr( "Length attribute" ) );
154  mYAttributeLabel->setText( tr( "Angle attribute" ) );
155  emit changed();
156  }
157 }
158 
159 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
160 {
161  if ( mLayer && checked )
162  {
164  mXAttributeLabel->setText( "" );
165  mXAttributeComboBox->setEnabled( false );
166  mYAttributeLabel->setText( tr( "Height attribute" ) );
167  emit changed();
168  }
169 }
170 
171 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
172 {
173  if ( mLayer && checked )
174  {
176  emit changed();
177  }
178 }
179 
180 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
181 {
182  if ( mLayer && checked )
183  {
185  emit changed();
186  }
187 }
188 
189 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
190 {
191  if ( mLayer && checked )
192  {
194  emit changed();
195  }
196 }
197 
198 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
199 {
200  if ( mLayer && checked )
201  {
203  emit changed();
204  }
205 }
206 
207 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitWidget_changed()
208 {
209  if ( !mLayer )
210  {
211  return;
212  }
213 
214  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
215  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
216  emit changed();
217 }
218 
219 
220 
static unsigned index
void setXAttribute(const QString &attribute)
void setupUi(QWidget *widget)
void setYAttribute(const QString &attribute)
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setAngleUnits(AngleUnits units)
QgsFields fields() const
Returns the list of fields of this layer.
AngleOrientation angleOrientation() const
Container of fields for a vector layer.
Definition: qgsfield.h:177
const QgsMapUnitScale & distanceMapUnitScale() const
VectorFieldType vectorFieldType() const
QString tr(const char *sourceText, const char *disambiguation, int n)
const QgsVectorLayer * mVectorLayer
A symbol layer class for displaying displacement arrows based on point layer attributes.
int count() const
Return number of items.
Definition: qgsfield.cpp:285
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
virtual QString layerType() const =0
QgsSymbolV2::OutputUnit distanceUnit() const
QgsVectorFieldSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=0)
void setDistanceUnit(QgsSymbolV2::OutputUnit unit)
void setAngleOrientation(AngleOrientation orientation)
Represents a vector layer which manages a vector based data sets.
void setVectorFieldType(VectorFieldType type)
virtual QgsSymbolLayerV2 * symbolLayer() override