QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 ***************************************************************************/
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 ( auto *lVectorLayer = vectorLayer() )
38 {
39 mXAttributeComboBox->addItem( QString() );
40 mYAttributeComboBox->addItem( QString() );
41 int i = 0;
42 const QgsFields fields = lVectorLayer->fields();
43 for ( const QgsField &f : fields )
44 {
45 const QString fieldName = f.name();
46 mXAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
47 mYAttributeComboBox->addItem( lVectorLayer->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
115
116void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
117{
118 if ( mLayer )
119 {
120 mLayer->setScale( d );
121 emit changed();
122 }
123}
124
125void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
126{
127 if ( mLayer )
128 {
129 mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
130 emit changed();
131 }
132}
133
134void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
135{
136 if ( mLayer )
137 {
138 mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
139 emit changed();
140 }
141}
142
143void 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
156void 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
169void 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
181void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
182{
183 if ( mLayer && checked )
184 {
186 emit changed();
187 }
188}
189
190void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
191{
192 if ( mLayer && checked )
193 {
195 emit changed();
196 }
197}
198
199void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
200{
201 if ( mLayer && checked )
202 {
204 emit changed();
205 }
206}
207
208void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
209{
210 if ( mLayer && checked )
211 {
213 emit changed();
214 }
215}
216
217void 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
@ 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:45
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.
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.