QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 ***************************************************************************/
16#include "moc_qgsvectorfieldsymbollayerwidget.cpp"
18#include "qgsvectorlayer.h"
19
21{
22 setupUi( this );
23 connect( mScaleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged );
24 connect( mXAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged );
25 connect( mYAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged );
26 connect( mCartesianRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled );
27 connect( mPolarRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled );
28 connect( mHeightRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled );
29 connect( mDegreesRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled );
30 connect( mRadiansRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled );
31 connect( mClockwiseFromNorthRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled );
32 connect( mCounterclockwiseFromEastRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled );
33 connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed );
34
37
38 if ( auto *lVectorLayer = vectorLayer() )
39 {
40 mXAttributeComboBox->addItem( QString() );
41 mYAttributeComboBox->addItem( QString() );
42 int i = 0;
43 const QgsFields fields = lVectorLayer->fields();
44 for ( const QgsField &f : fields )
45 {
46 const QString fieldName = f.name();
47 mXAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
48 mYAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
49 i++;
50 }
51 }
52}
53
55{
56 if ( layer->layerType() != QLatin1String( "VectorField" ) )
57 {
58 return;
59 }
60 mLayer = static_cast<QgsVectorFieldSymbolLayer *>( layer );
61 if ( !mLayer )
62 {
63 return;
64 }
65
66 mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
67 mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
68 mScaleSpinBox->setValue( mLayer->scale() );
69
72 {
73 mCartesianRadioButton->setChecked( true );
74 }
75 else if ( type == QgsVectorFieldSymbolLayer::Polar )
76 {
77 mPolarRadioButton->setChecked( true );
78 }
79 else if ( type == QgsVectorFieldSymbolLayer::Height )
80 {
81 mHeightRadioButton->setChecked( true );
82 }
83
86 {
87 mClockwiseFromNorthRadioButton->setChecked( true );
88 }
90 {
91 mCounterclockwiseFromEastRadioButton->setChecked( true );
92 }
93
95 if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
96 {
97 mDegreesRadioButton->setChecked( true );
98 }
99 else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
100 {
101 mRadiansRadioButton->setChecked( true );
102 }
103
104 mDistanceUnitWidget->blockSignals( true );
105 mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
106 mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
107 mDistanceUnitWidget->blockSignals( false );
108
109 emit changed();
110}
111
116
117void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
118{
119 if ( mLayer )
120 {
121 mLayer->setScale( d );
122 emit changed();
123 }
124}
125
126void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
127{
128 if ( mLayer )
129 {
130 mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
131 emit changed();
132 }
133}
134
135void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
136{
137 if ( mLayer )
138 {
139 mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
140 emit changed();
141 }
142}
143
144void QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled( bool checked )
145{
146 if ( mLayer && checked )
147 {
149 mXAttributeComboBox->setEnabled( true );
150 mYAttributeComboBox->setEnabled( true );
151 mXAttributeLabel->setText( tr( "X attribute" ) );
152 mYAttributeLabel->setText( tr( "Y attribute" ) );
153 emit changed();
154 }
155}
156
157void QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled( bool checked )
158{
159 if ( mLayer && checked )
160 {
162 mXAttributeComboBox->setEnabled( true );
163 mYAttributeComboBox->setEnabled( true );
164 mXAttributeLabel->setText( tr( "Length attribute" ) );
165 mYAttributeLabel->setText( tr( "Angle attribute" ) );
166 emit changed();
167 }
168}
169
170void QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled( bool checked )
171{
172 if ( mLayer && checked )
173 {
175 mXAttributeLabel->clear();
176 mXAttributeComboBox->setEnabled( false );
177 mYAttributeLabel->setText( tr( "Height attribute" ) );
178 emit changed();
179 }
180}
181
182void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
183{
184 if ( mLayer && checked )
185 {
187 emit changed();
188 }
189}
190
191void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
192{
193 if ( mLayer && checked )
194 {
196 emit changed();
197 }
198}
199
200void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
201{
202 if ( mLayer && checked )
203 {
205 emit changed();
206 }
207}
208
209void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
210{
211 if ( mLayer && checked )
212 {
214 emit changed();
215 }
216}
217
218void QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed()
219{
220 if ( !mLayer )
221 {
222 return;
223 }
224
225 mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
226 mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
227 emit changed();
228}
229
230
231
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
virtual QString layerType() const =0
Returns a string that represents this layer type.
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
QList< Qgis::RenderUnit > RenderUnitList
List of render units.
QgsVectorFieldSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsVectorFieldSymbolLayerWidget.
void setSymbolLayer(QgsSymbolLayer *layer) override
A symbol layer class for displaying displacement arrows based on point layer attributes.
const QgsMapUnitScale & distanceMapUnitScale() const
void setYAttribute(const QString &attribute)
void setAngleUnits(AngleUnits units)
void setVectorFieldType(VectorFieldType type)
void setDistanceUnit(Qgis::RenderUnit unit)
Sets the units for the distance.
void setAngleOrientation(AngleOrientation orientation)
AngleOrientation angleOrientation() const
void setXAttribute(const QString &attribute)
void setDistanceMapUnitScale(const QgsMapUnitScale &scale)
Qgis::RenderUnit distanceUnit() const
Returns the units for the distance.
VectorFieldType vectorFieldType() const
Represents a vector layer which manages a vector based data sets.