QGIS API Documentation
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 << QgsSymbolV2::Pixel );
24 
25  if ( mVectorLayer )
26  {
27  mXAttributeComboBox->addItem( "" );
28  mYAttributeComboBox->addItem( "" );
29  Q_FOREACH ( const QgsField& f, mVectorLayer->fields() )
30  {
31  QString fieldName = f.name();
32  mXAttributeComboBox->addItem( fieldName );
33  mYAttributeComboBox->addItem( fieldName );
34  }
35  }
36 }
37 
39 {
40 }
41 
43 {
44  if ( layer->layerType() != "VectorField" )
45  {
46  return;
47  }
48  mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
49  if ( !mLayer )
50  {
51  return;
52  }
53 
54  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
55  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
56  mScaleSpinBox->setValue( mLayer->scale() );
57 
60  {
61  mCartesianRadioButton->setChecked( true );
62  }
63  else if ( type == QgsVectorFieldSymbolLayer::Polar )
64  {
65  mPolarRadioButton->setChecked( true );
66  }
67  else if ( type == QgsVectorFieldSymbolLayer::Height )
68  {
69  mHeightRadioButton->setChecked( true );
70  }
71 
74  {
75  mClockwiseFromNorthRadioButton->setChecked( true );
76  }
78  {
79  mCounterclockwiseFromEastRadioButton->setChecked( true );
80  }
81 
83  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
84  {
85  mDegreesRadioButton->setChecked( true );
86  }
87  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
88  {
89  mRadiansRadioButton->setChecked( true );
90  }
91 
92  mDistanceUnitWidget->blockSignals( true );
93  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
94  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
95  mDistanceUnitWidget->blockSignals( false );
96 
97  emit changed();
98 }
99 
101 {
102  return mLayer;
103 }
104 
105 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
106 {
107  if ( mLayer )
108  {
109  mLayer->setScale( d );
110  emit changed();
111  }
112 }
113 
114 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
115 {
116  if ( mLayer )
117  {
118  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
119  emit changed();
120  }
121 }
122 
123 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
124 {
125  if ( mLayer )
126  {
127  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
128  emit changed();
129  }
130 }
131 
132 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
133 {
134  if ( mLayer && checked )
135  {
137  mXAttributeComboBox->setEnabled( true );
138  mYAttributeComboBox->setEnabled( true );
139  mXAttributeLabel->setText( tr( "X attribute" ) );
140  mYAttributeLabel->setText( tr( "Y attribute" ) );
141  emit changed();
142  }
143 }
144 
145 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
146 {
147  if ( mLayer && checked )
148  {
150  mXAttributeComboBox->setEnabled( true );
151  mYAttributeComboBox->setEnabled( true );
152  mXAttributeLabel->setText( tr( "Length attribute" ) );
153  mYAttributeLabel->setText( tr( "Angle attribute" ) );
154  emit changed();
155  }
156 }
157 
158 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
159 {
160  if ( mLayer && checked )
161  {
163  mXAttributeLabel->setText( "" );
164  mXAttributeComboBox->setEnabled( false );
165  mYAttributeLabel->setText( tr( "Height attribute" ) );
166  emit changed();
167  }
168 }
169 
170 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
171 {
172  if ( mLayer && checked )
173  {
175  emit changed();
176  }
177 }
178 
179 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
180 {
181  if ( mLayer && checked )
182  {
184  emit changed();
185  }
186 }
187 
188 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
189 {
190  if ( mLayer && checked )
191  {
193  emit changed();
194  }
195 }
196 
197 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
198 {
199  if ( mLayer && checked )
200  {
202  emit changed();
203  }
204 }
205 
206 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitWidget_changed()
207 {
208  if ( !mLayer )
209  {
210  return;
211  }
212 
213  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
214  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
215  emit changed();
216 }
217 
218 
219 
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.
The output shall be in pixels.
Definition: qgssymbolv2.h:67
AngleOrientation angleOrientation() const
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.
The output shall be in millimeters.
Definition: qgssymbolv2.h:64
QString name() const
Gets the name of the field.
Definition: qgsfield.cpp:84
The output shall be in map unitx.
Definition: qgssymbolv2.h:65
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
virtual QString layerType() const =0
Returns a string that represents this layer type.
QgsSymbolV2::OutputUnit distanceUnit() const
QgsVectorFieldSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
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
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.