QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  int i = 0;
30  Q_FOREACH ( const QgsField& f, mVectorLayer->fields() )
31  {
32  QString fieldName = f.name();
33  mXAttributeComboBox->addItem( mVectorLayer->fields().iconForField( i ), fieldName );
34  mYAttributeComboBox->addItem( mVectorLayer->fields().iconForField( i ), fieldName );
35  i++;
36  }
37  }
38 }
39 
41 {
42 }
43 
45 {
46  if ( layer->layerType() != "VectorField" )
47  {
48  return;
49  }
50  mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
51  if ( !mLayer )
52  {
53  return;
54  }
55 
56  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
57  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
58  mScaleSpinBox->setValue( mLayer->scale() );
59 
62  {
63  mCartesianRadioButton->setChecked( true );
64  }
65  else if ( type == QgsVectorFieldSymbolLayer::Polar )
66  {
67  mPolarRadioButton->setChecked( true );
68  }
69  else if ( type == QgsVectorFieldSymbolLayer::Height )
70  {
71  mHeightRadioButton->setChecked( true );
72  }
73 
76  {
77  mClockwiseFromNorthRadioButton->setChecked( true );
78  }
80  {
81  mCounterclockwiseFromEastRadioButton->setChecked( true );
82  }
83 
85  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
86  {
87  mDegreesRadioButton->setChecked( true );
88  }
89  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
90  {
91  mRadiansRadioButton->setChecked( true );
92  }
93 
94  mDistanceUnitWidget->blockSignals( true );
95  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
96  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
97  mDistanceUnitWidget->blockSignals( false );
98 
99  emit changed();
100 }
101 
103 {
104  return mLayer;
105 }
106 
107 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
108 {
109  if ( mLayer )
110  {
111  mLayer->setScale( d );
112  emit changed();
113  }
114 }
115 
116 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
117 {
118  if ( mLayer )
119  {
120  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
121  emit changed();
122  }
123 }
124 
125 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
126 {
127  if ( mLayer )
128  {
129  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
130  emit changed();
131  }
132 }
133 
134 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
135 {
136  if ( mLayer && checked )
137  {
139  mXAttributeComboBox->setEnabled( true );
140  mYAttributeComboBox->setEnabled( true );
141  mXAttributeLabel->setText( tr( "X attribute" ) );
142  mYAttributeLabel->setText( tr( "Y attribute" ) );
143  emit changed();
144  }
145 }
146 
147 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
148 {
149  if ( mLayer && checked )
150  {
152  mXAttributeComboBox->setEnabled( true );
153  mYAttributeComboBox->setEnabled( true );
154  mXAttributeLabel->setText( tr( "Length attribute" ) );
155  mYAttributeLabel->setText( tr( "Angle attribute" ) );
156  emit changed();
157  }
158 }
159 
160 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
161 {
162  if ( mLayer && checked )
163  {
165  mXAttributeLabel->setText( "" );
166  mXAttributeComboBox->setEnabled( false );
167  mYAttributeLabel->setText( tr( "Height attribute" ) );
168  emit changed();
169  }
170 }
171 
172 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
173 {
174  if ( mLayer && checked )
175  {
177  emit changed();
178  }
179 }
180 
181 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
182 {
183  if ( mLayer && checked )
184  {
186  emit changed();
187  }
188 }
189 
190 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
191 {
192  if ( mLayer && checked )
193  {
195  emit changed();
196  }
197 }
198 
199 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
200 {
201  if ( mLayer && checked )
202  {
204  emit changed();
205  }
206 }
207 
208 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitWidget_changed()
209 {
210  if ( !mLayer )
211  {
212  return;
213  }
214 
215  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
216  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
217  emit changed();
218 }
219 
220 
221 
static unsigned index
void setXAttribute(const QString &attribute)
void setupUi(QWidget *widget)
void setYAttribute(const QString &attribute)
QString name
Definition: qgsfield.h:52
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
void setAngleUnits(AngleUnits units)
QIcon iconForField(int fieldIdx) const
Returns an icon corresponding to a field index, based on the field&#39;s type and source.
Definition: qgsfield.cpp:529
AngleOrientation angleOrientation() const
The output shall be in pixels.
Definition: qgssymbolv2.h:70
QgsSymbolV2::OutputUnit distanceUnit() const
QString tr(const char *sourceText, const char *disambiguation, int n)
const QgsVectorLayer * mVectorLayer
QgsFields fields() const
Returns the list of fields of this layer.
A symbol layer class for displaying displacement arrows based on point layer attributes.
The output shall be in millimeters.
Definition: qgssymbolv2.h:67
const QgsMapUnitScale & distanceMapUnitScale() const
The output shall be in map unitx.
Definition: qgssymbolv2.h:68
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.
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.
VectorFieldType vectorFieldType() const
void setVectorFieldType(VectorFieldType type)
virtual QgsSymbolLayerV2 * symbolLayer() override
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.