QGIS API Documentation  2.99.0-Master (9fdd060)
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  connect( mScaleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged );
23  connect( mXAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged );
24  connect( mYAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged );
25  connect( mCartesianRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled );
26  connect( mPolarRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled );
27  connect( mHeightRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled );
28  connect( mDegreesRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled );
29  connect( mRadiansRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled );
30  connect( mClockwiseFromNorthRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled );
31  connect( mCounterclockwiseFromEastRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled );
32  connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed );
33 
36 
37  if ( vectorLayer() )
38  {
39  mXAttributeComboBox->addItem( QLatin1String( "" ) );
40  mYAttributeComboBox->addItem( QLatin1String( "" ) );
41  int i = 0;
42  Q_FOREACH ( const QgsField &f, vectorLayer()->fields() )
43  {
44  QString fieldName = f.name();
45  mXAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
46  mYAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
47  i++;
48  }
49  }
50 }
51 
53 {
54  if ( layer->layerType() != QLatin1String( "VectorField" ) )
55  {
56  return;
57  }
58  mLayer = static_cast<QgsVectorFieldSymbolLayer *>( layer );
59  if ( !mLayer )
60  {
61  return;
62  }
63 
64  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
65  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
66  mScaleSpinBox->setValue( mLayer->scale() );
67 
70  {
71  mCartesianRadioButton->setChecked( true );
72  }
73  else if ( type == QgsVectorFieldSymbolLayer::Polar )
74  {
75  mPolarRadioButton->setChecked( true );
76  }
77  else if ( type == QgsVectorFieldSymbolLayer::Height )
78  {
79  mHeightRadioButton->setChecked( true );
80  }
81 
84  {
85  mClockwiseFromNorthRadioButton->setChecked( true );
86  }
88  {
89  mCounterclockwiseFromEastRadioButton->setChecked( true );
90  }
91 
93  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
94  {
95  mDegreesRadioButton->setChecked( true );
96  }
97  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
98  {
99  mRadiansRadioButton->setChecked( true );
100  }
101 
102  mDistanceUnitWidget->blockSignals( true );
103  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
104  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
105  mDistanceUnitWidget->blockSignals( false );
106 
107  emit changed();
108 }
109 
111 {
112  return mLayer;
113 }
114 
115 void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
116 {
117  if ( mLayer )
118  {
119  mLayer->setScale( d );
120  emit changed();
121  }
122 }
123 
124 void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
125 {
126  if ( mLayer )
127  {
128  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
129  emit changed();
130  }
131 }
132 
133 void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
134 {
135  if ( mLayer )
136  {
137  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
138  emit changed();
139  }
140 }
141 
142 void QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled( bool checked )
143 {
144  if ( mLayer && checked )
145  {
147  mXAttributeComboBox->setEnabled( true );
148  mYAttributeComboBox->setEnabled( true );
149  mXAttributeLabel->setText( tr( "X attribute" ) );
150  mYAttributeLabel->setText( tr( "Y attribute" ) );
151  emit changed();
152  }
153 }
154 
155 void QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled( bool checked )
156 {
157  if ( mLayer && checked )
158  {
160  mXAttributeComboBox->setEnabled( true );
161  mYAttributeComboBox->setEnabled( true );
162  mXAttributeLabel->setText( tr( "Length attribute" ) );
163  mYAttributeLabel->setText( tr( "Angle attribute" ) );
164  emit changed();
165  }
166 }
167 
168 void QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled( bool checked )
169 {
170  if ( mLayer && checked )
171  {
173  mXAttributeLabel->clear();
174  mXAttributeComboBox->setEnabled( false );
175  mYAttributeLabel->setText( tr( "Height attribute" ) );
176  emit changed();
177  }
178 }
179 
180 void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
181 {
182  if ( mLayer && checked )
183  {
185  emit changed();
186  }
187 }
188 
189 void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
190 {
191  if ( mLayer && checked )
192  {
194  emit changed();
195  }
196 }
197 
198 void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
199 {
200  if ( mLayer && checked )
201  {
203  emit changed();
204  }
205 }
206 
207 void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
208 {
209  if ( mLayer && checked )
210  {
212  emit changed();
213  }
214 }
215 
216 void QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed()
217 {
218  if ( !mLayer )
219  {
220  return;
221  }
222 
223  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
224  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
225  emit changed();
226 }
227 
228 
229 
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
void setXAttribute(const QString &attribute)
void setYAttribute(const QString &attribute)
QString name
Definition: qgsfield.h:56
void setAngleUnits(AngleUnits units)
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
AngleOrientation angleOrientation() const
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:173
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:107
virtual void setSymbolLayer(QgsSymbolLayer *layer) override
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
QgsVectorFieldSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=0)
Constructor for QgsVectorFieldSymbolLayerWidget.
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.