QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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( QString() );
40  mYAttributeComboBox->addItem( QString() );
41  int i = 0;
42  const QgsFields fields = vectorLayer()->fields();
43  for ( const QgsField &f : fields )
44  {
45  QString fieldName = f.name();
46  mXAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
47  mYAttributeComboBox->addItem( vectorLayer()->fields().iconForField( i ), fieldName );
48  i++;
49  }
50  }
51 }
52 
54 {
55  if ( layer->layerType() != QLatin1String( "VectorField" ) )
56  {
57  return;
58  }
59  mLayer = static_cast<QgsVectorFieldSymbolLayer *>( layer );
60  if ( !mLayer )
61  {
62  return;
63  }
64 
65  mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
66  mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
67  mScaleSpinBox->setValue( mLayer->scale() );
68 
71  {
72  mCartesianRadioButton->setChecked( true );
73  }
74  else if ( type == QgsVectorFieldSymbolLayer::Polar )
75  {
76  mPolarRadioButton->setChecked( true );
77  }
78  else if ( type == QgsVectorFieldSymbolLayer::Height )
79  {
80  mHeightRadioButton->setChecked( true );
81  }
82 
85  {
86  mClockwiseFromNorthRadioButton->setChecked( true );
87  }
89  {
90  mCounterclockwiseFromEastRadioButton->setChecked( true );
91  }
92 
94  if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
95  {
96  mDegreesRadioButton->setChecked( true );
97  }
98  else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
99  {
100  mRadiansRadioButton->setChecked( true );
101  }
102 
103  mDistanceUnitWidget->blockSignals( true );
104  mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
105  mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
106  mDistanceUnitWidget->blockSignals( false );
107 
108  emit changed();
109 }
110 
112 {
113  return mLayer;
114 }
115 
116 void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
117 {
118  if ( mLayer )
119  {
120  mLayer->setScale( d );
121  emit changed();
122  }
123 }
124 
125 void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
126 {
127  if ( mLayer )
128  {
129  mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
130  emit changed();
131  }
132 }
133 
134 void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
135 {
136  if ( mLayer )
137  {
138  mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
139  emit changed();
140  }
141 }
142 
143 void QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled( bool checked )
144 {
145  if ( mLayer && checked )
146  {
148  mXAttributeComboBox->setEnabled( true );
149  mYAttributeComboBox->setEnabled( true );
150  mXAttributeLabel->setText( tr( "X attribute" ) );
151  mYAttributeLabel->setText( tr( "Y attribute" ) );
152  emit changed();
153  }
154 }
155 
156 void QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled( bool checked )
157 {
158  if ( mLayer && checked )
159  {
161  mXAttributeComboBox->setEnabled( true );
162  mYAttributeComboBox->setEnabled( true );
163  mXAttributeLabel->setText( tr( "Length attribute" ) );
164  mYAttributeLabel->setText( tr( "Angle attribute" ) );
165  emit changed();
166  }
167 }
168 
169 void QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled( bool checked )
170 {
171  if ( mLayer && checked )
172  {
174  mXAttributeLabel->clear();
175  mXAttributeComboBox->setEnabled( false );
176  mYAttributeLabel->setText( tr( "Height attribute" ) );
177  emit changed();
178  }
179 }
180 
181 void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
182 {
183  if ( mLayer && checked )
184  {
186  emit changed();
187  }
188 }
189 
190 void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
191 {
192  if ( mLayer && checked )
193  {
195  emit changed();
196  }
197 }
198 
199 void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
200 {
201  if ( mLayer && checked )
202  {
204  emit changed();
205  }
206 }
207 
208 void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
209 {
210  if ( mLayer && checked )
211  {
213  emit changed();
214  }
215 }
216 
217 void QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed()
218 {
219  if ( !mLayer )
220  {
221  return;
222  }
223 
224  mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
225  mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
226  emit changed();
227 }
228 
229 
230 
QgsVectorFieldSymbolLayer::AngleOrientation
AngleOrientation
Definition: qgsvectorfieldsymbollayer.h:51
QgsUnitTypes::RenderInches
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
QgsVectorFieldSymbolLayer::setVectorFieldType
void setVectorFieldType(VectorFieldType type)
Definition: qgsvectorfieldsymbollayer.h:97
QgsVectorFieldSymbolLayer::setDistanceUnit
void setDistanceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the distance.
Definition: qgsvectorfieldsymbollayer.h:115
QgsSymbolLayerWidget::vectorLayer
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
Definition: qgssymbollayerwidget.h:72
QgsSymbolLayerWidget::changed
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
QgsVectorFieldSymbolLayer
Definition: qgsvectorfieldsymbollayer.h:28
QgsVectorFieldSymbolLayer::vectorFieldType
VectorFieldType vectorFieldType() const
Definition: qgsvectorfieldsymbollayer.h:98
QgsVectorFieldSymbolLayer::ClockwiseFromNorth
@ ClockwiseFromNorth
Definition: qgsvectorfieldsymbollayer.h:53
QgsVectorFieldSymbolLayer::yAttribute
QString yAttribute() const
Definition: qgsvectorfieldsymbollayer.h:94
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
QgsVectorFieldSymbolLayer::distanceMapUnitScale
const QgsMapUnitScale & distanceMapUnitScale() const
Definition: qgsvectorfieldsymbollayer.h:124
QgsFields
Definition: qgsfields.h:44
QgsSymbolLayerWidget
Definition: qgssymbollayerwidget.h:34
QgsVectorFieldSymbolLayerWidget::symbolLayer
QgsSymbolLayer * symbolLayer() override
Definition: qgsvectorfieldsymbollayerwidget.cpp:111
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsVectorFieldSymbolLayer::Height
@ Height
Definition: qgsvectorfieldsymbollayer.h:61
QgsVectorFieldSymbolLayer::setXAttribute
void setXAttribute(const QString &attribute)
Definition: qgsvectorfieldsymbollayer.h:91
qgsvectorfieldsymbollayerwidget.h
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3280
QgsVectorFieldSymbolLayerWidget::mLayer
QgsVectorFieldSymbolLayer * mLayer
Definition: qgsvectorfieldsymbollayerwidget.h:52
QgsSymbolLayer
Definition: qgssymbollayer.h:52
QgsVectorFieldSymbolLayer::Polar
@ Polar
Definition: qgsvectorfieldsymbollayer.h:60
QgsVectorFieldSymbolLayer::CounterclockwiseFromEast
@ CounterclockwiseFromEast
Definition: qgsvectorfieldsymbollayer.h:54
QgsVectorFieldSymbolLayerWidget::setSymbolLayer
void setSymbolLayer(QgsSymbolLayer *layer) override
Definition: qgsvectorfieldsymbollayerwidget.cpp:53
QgsUnitSelectionWidget::changed
void changed()
QgsVectorFieldSymbolLayer::setDistanceMapUnitScale
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgsvectorfieldsymbollayer.h:123
qgsvectorfieldsymbollayer.h
QgsVectorFieldSymbolLayer::Radians
@ Radians
Definition: qgsvectorfieldsymbollayer.h:60
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
qgsvectorlayer.h
QgsVectorFieldSymbolLayer::angleOrientation
AngleOrientation angleOrientation() const
Definition: qgsvectorfieldsymbollayer.h:100
QgsVectorFieldSymbolLayer::setScale
void setScale(double s)
Definition: qgsvectorfieldsymbollayer.h:95
QgsVectorFieldSymbolLayer::distanceUnit
QgsUnitTypes::RenderUnit distanceUnit() const
Returns the units for the distance.
Definition: qgsvectorfieldsymbollayer.h:121
QgsVectorFieldSymbolLayer::Degrees
@ Degrees
Definition: qgsvectorfieldsymbollayer.h:59
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsVectorFieldSymbolLayer::angleUnits
AngleUnits angleUnits() const
Definition: qgsvectorfieldsymbollayer.h:102
QgsVectorFieldSymbolLayer::VectorFieldType
VectorFieldType
Definition: qgsvectorfieldsymbollayer.h:44
QgsVectorFieldSymbolLayer::setAngleOrientation
void setAngleOrientation(AngleOrientation orientation)
Definition: qgsvectorfieldsymbollayer.h:99
QgsVectorFieldSymbolLayer::AngleUnits
AngleUnits
Definition: qgsvectorfieldsymbollayer.h:57
QgsVectorFieldSymbolLayer::Cartesian
@ Cartesian
Definition: qgsvectorfieldsymbollayer.h:59
QgsVectorFieldSymbolLayerWidget::QgsVectorFieldSymbolLayerWidget
QgsVectorFieldSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsVectorFieldSymbolLayerWidget.
Definition: qgsvectorfieldsymbollayerwidget.cpp:19
QgsSymbolLayer::layerType
virtual QString layerType() const =0
Returns a string that represents this layer type.
QgsVectorFieldSymbolLayer::scale
double scale() const
Definition: qgsvectorfieldsymbollayer.h:96
QgsUnitTypes::RenderUnitList
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:239
QgsVectorFieldSymbolLayer::xAttribute
QString xAttribute() const
Definition: qgsvectorfieldsymbollayer.h:92
QgsVectorFieldSymbolLayer::setYAttribute
void setYAttribute(const QString &attribute)
Definition: qgsvectorfieldsymbollayer.h:93
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
QgsVectorFieldSymbolLayer::setAngleUnits
void setAngleUnits(AngleUnits units)
Definition: qgsvectorfieldsymbollayer.h:101
QgsField
Definition: qgsfield.h:49