QGIS API Documentation  2.99.0-Master (a18066b)
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 
25 
26  if ( vectorLayer() )
27  {
28  mXAttributeComboBox->addItem( QLatin1String( "" ) );
29  mYAttributeComboBox->addItem( QLatin1String( "" ) );
30  int i = 0;
31  Q_FOREACH ( const QgsField& f, vectorLayer()->fields() )
32  {
33  QString fieldName = f.name();
34  mXAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
35  mYAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
36  i++;
37  }
38  }
39 }
40 
42 {
43  if ( layer->layerType() != QLatin1String( "VectorField" ) )
44  {
45  return;
46  }
47  mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
48  if ( !mLayer )
49  {
50  return;
51  }
52 
53  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
54  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
55  mScaleSpinBox->setValue( mLayer->scale() );
56 
59  {
60  mCartesianRadioButton->setChecked( true );
61  }
62  else if ( type == QgsVectorFieldSymbolLayer::Polar )
63  {
64  mPolarRadioButton->setChecked( true );
65  }
66  else if ( type == QgsVectorFieldSymbolLayer::Height )
67  {
68  mHeightRadioButton->setChecked( true );
69  }
70 
73  {
74  mClockwiseFromNorthRadioButton->setChecked( true );
75  }
77  {
78  mCounterclockwiseFromEastRadioButton->setChecked( true );
79  }
80 
82  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
83  {
84  mDegreesRadioButton->setChecked( true );
85  }
86  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
87  {
88  mRadiansRadioButton->setChecked( true );
89  }
90 
91  mDistanceUnitWidget->blockSignals( true );
92  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
93  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
94  mDistanceUnitWidget->blockSignals( false );
95 
96  emit changed();
97 }
98 
100 {
101  return mLayer;
102 }
103 
104 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
105 {
106  if ( mLayer )
107  {
108  mLayer->setScale( d );
109  emit changed();
110  }
111 }
112 
113 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
114 {
115  if ( mLayer )
116  {
117  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
118  emit changed();
119  }
120 }
121 
122 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
123 {
124  if ( mLayer )
125  {
126  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
127  emit changed();
128  }
129 }
130 
131 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
132 {
133  if ( mLayer && checked )
134  {
136  mXAttributeComboBox->setEnabled( true );
137  mYAttributeComboBox->setEnabled( true );
138  mXAttributeLabel->setText( tr( "X attribute" ) );
139  mYAttributeLabel->setText( tr( "Y attribute" ) );
140  emit changed();
141  }
142 }
143 
144 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
145 {
146  if ( mLayer && checked )
147  {
149  mXAttributeComboBox->setEnabled( true );
150  mYAttributeComboBox->setEnabled( true );
151  mXAttributeLabel->setText( tr( "Length attribute" ) );
152  mYAttributeLabel->setText( tr( "Angle attribute" ) );
153  emit changed();
154  }
155 }
156 
157 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
158 {
159  if ( mLayer && checked )
160  {
162  mXAttributeLabel->setText( QLatin1String( "" ) );
163  mXAttributeComboBox->setEnabled( false );
164  mYAttributeLabel->setText( tr( "Height attribute" ) );
165  emit changed();
166  }
167 }
168 
169 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
170 {
171  if ( mLayer && checked )
172  {
174  emit changed();
175  }
176 }
177 
178 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
179 {
180  if ( mLayer && checked )
181  {
183  emit changed();
184  }
185 }
186 
187 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
188 {
189  if ( mLayer && checked )
190  {
192  emit changed();
193  }
194 }
195 
196 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
197 {
198  if ( mLayer && checked )
199  {
201  emit changed();
202  }
203 }
204 
205 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitWidget_changed()
206 {
207  if ( !mLayer )
208  {
209  return;
210  }
211 
212  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
213  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
214  emit changed();
215 }
216 
217 
218 
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:53
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:104
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
points (e.g., for font sizes)
Definition: qgsunittypes.h:99
virtual void setSymbolLayer(QgsSymbolLayer *layer) override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:45
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.