QGIS API Documentation  2.99.0-Master (0a63d1f)
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  if ( layer->layerType() != QLatin1String( "VectorField" ) )
43  {
44  return;
45  }
46  mLayer = static_cast<QgsVectorFieldSymbolLayer*>( layer );
47  if ( !mLayer )
48  {
49  return;
50  }
51 
52  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
53  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
54  mScaleSpinBox->setValue( mLayer->scale() );
55 
58  {
59  mCartesianRadioButton->setChecked( true );
60  }
61  else if ( type == QgsVectorFieldSymbolLayer::Polar )
62  {
63  mPolarRadioButton->setChecked( true );
64  }
65  else if ( type == QgsVectorFieldSymbolLayer::Height )
66  {
67  mHeightRadioButton->setChecked( true );
68  }
69 
72  {
73  mClockwiseFromNorthRadioButton->setChecked( true );
74  }
76  {
77  mCounterclockwiseFromEastRadioButton->setChecked( true );
78  }
79 
81  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
82  {
83  mDegreesRadioButton->setChecked( true );
84  }
85  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
86  {
87  mRadiansRadioButton->setChecked( true );
88  }
89 
90  mDistanceUnitWidget->blockSignals( true );
91  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
92  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
93  mDistanceUnitWidget->blockSignals( false );
94 
95  emit changed();
96 }
97 
99 {
100  return mLayer;
101 }
102 
103 void QgsVectorFieldSymbolLayerWidget::on_mScaleSpinBox_valueChanged( double d )
104 {
105  if ( mLayer )
106  {
107  mLayer->setScale( d );
108  emit changed();
109  }
110 }
111 
112 void QgsVectorFieldSymbolLayerWidget::on_mXAttributeComboBox_currentIndexChanged( int index )
113 {
114  if ( mLayer )
115  {
116  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
117  emit changed();
118  }
119 }
120 
121 void QgsVectorFieldSymbolLayerWidget::on_mYAttributeComboBox_currentIndexChanged( int index )
122 {
123  if ( mLayer )
124  {
125  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
126  emit changed();
127  }
128 }
129 
130 void QgsVectorFieldSymbolLayerWidget::on_mCartesianRadioButton_toggled( bool checked )
131 {
132  if ( mLayer && checked )
133  {
135  mXAttributeComboBox->setEnabled( true );
136  mYAttributeComboBox->setEnabled( true );
137  mXAttributeLabel->setText( tr( "X attribute" ) );
138  mYAttributeLabel->setText( tr( "Y attribute" ) );
139  emit changed();
140  }
141 }
142 
143 void QgsVectorFieldSymbolLayerWidget::on_mPolarRadioButton_toggled( bool checked )
144 {
145  if ( mLayer && checked )
146  {
148  mXAttributeComboBox->setEnabled( true );
149  mYAttributeComboBox->setEnabled( true );
150  mXAttributeLabel->setText( tr( "Length attribute" ) );
151  mYAttributeLabel->setText( tr( "Angle attribute" ) );
152  emit changed();
153  }
154 }
155 
156 void QgsVectorFieldSymbolLayerWidget::on_mHeightRadioButton_toggled( bool checked )
157 {
158  if ( mLayer && checked )
159  {
161  mXAttributeLabel->setText( QLatin1String( "" ) );
162  mXAttributeComboBox->setEnabled( false );
163  mYAttributeLabel->setText( tr( "Height attribute" ) );
164  emit changed();
165  }
166 }
167 
168 void QgsVectorFieldSymbolLayerWidget::on_mDegreesRadioButton_toggled( bool checked )
169 {
170  if ( mLayer && checked )
171  {
173  emit changed();
174  }
175 }
176 
177 void QgsVectorFieldSymbolLayerWidget::on_mRadiansRadioButton_toggled( bool checked )
178 {
179  if ( mLayer && checked )
180  {
182  emit changed();
183  }
184 }
185 
186 void QgsVectorFieldSymbolLayerWidget::on_mClockwiseFromNorthRadioButton_toggled( bool checked )
187 {
188  if ( mLayer && checked )
189  {
191  emit changed();
192  }
193 }
194 
195 void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_toggled( bool checked )
196 {
197  if ( mLayer && checked )
198  {
200  emit changed();
201  }
202 }
203 
204 void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitWidget_changed()
205 {
206  if ( !mLayer )
207  {
208  return;
209  }
210 
211  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
212  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
213  emit changed();
214 }
215 
216 
217 
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:103
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: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.