QGIS API Documentation  2.99.0-Master (8ec3eaf)
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 
19 QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget( const QgsVectorLayer* vl, QWidget* parent ): QgsSymbolLayerWidget( parent, vl ), mLayer( nullptr )
20 {
21  setupUi( this );
22 
24 
25  if ( vectorLayer() )
26  {
27  mXAttributeComboBox->addItem( QLatin1String( "" ) );
28  mYAttributeComboBox->addItem( QLatin1String( "" ) );
29  int i = 0;
30  Q_FOREACH ( const QgsField& f, vectorLayer()->fields() )
31  {
32  QString fieldName = f.name();
33  mXAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
34  mYAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
35  i++;
36  }
37  }
38 }
39 
41 {
42 }
43 
45 {
46  if ( layer->layerType() != QLatin1String( "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( QLatin1String( "" ) );
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 
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
static unsigned index
void setXAttribute(const QString &attribute)
void setYAttribute(const QString &attribute)
QString name
Definition: qgsfield.h:55
void setAngleUnits(AngleUnits units)
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
AngleOrientation angleOrientation() const
QList< RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:102
A symbol layer class for displaying displacement arrows based on point layer attributes.
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
const QgsMapUnitScale & distanceMapUnitScale() const
virtual void setSymbolLayer(QgsSymbolLayer *layer) override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:47
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
QgsVectorFieldSymbolLayerWidget(const QgsVectorLayer *vl, QWidget *parent=nullptr)
void setAngleOrientation(AngleOrientation orientation)
Represents a vector layer which manages a vector based data sets.
virtual QgsSymbolLayer * symbolLayer() override
VectorFieldType vectorFieldType() const
void setVectorFieldType(VectorFieldType type)
virtual QString layerType() const =0
Returns a string that represents this layer type.