QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
18#include "qgsvectorlayer.h"
19
20#include "moc_qgsvectorfieldsymbollayerwidget.cpp"
21
23 : QgsSymbolLayerWidget( parent, vl )
24{
25 setupUi( this );
26 connect( mScaleSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged );
27 connect( mXAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged );
28 connect( mYAttributeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged );
29 connect( mCartesianRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled );
30 connect( mPolarRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled );
31 connect( mHeightRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled );
32 connect( mDegreesRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled );
33 connect( mRadiansRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled );
34 connect( mClockwiseFromNorthRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled );
35 connect( mCounterclockwiseFromEastRadioButton, &QRadioButton::toggled, this, &QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled );
36 connect( mDistanceUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed );
37
39
40 if ( auto *lVectorLayer = vectorLayer() )
41 {
42 mXAttributeComboBox->addItem( QString() );
43 mYAttributeComboBox->addItem( QString() );
44 int i = 0;
45 const QgsFields fields = lVectorLayer->fields();
46 for ( const QgsField &f : fields )
47 {
48 const QString fieldName = f.name();
49 mXAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
50 mYAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
51 i++;
52 }
53 }
54}
55
57{
58 if ( layer->layerType() != QLatin1String( "VectorField" ) )
59 {
60 return;
61 }
62 mLayer = static_cast<QgsVectorFieldSymbolLayer *>( layer );
63 if ( !mLayer )
64 {
65 return;
66 }
67
68 mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
69 mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
70 mScaleSpinBox->setValue( mLayer->scale() );
71
72 const QgsVectorFieldSymbolLayer::VectorFieldType type = mLayer->vectorFieldType();
74 {
75 mCartesianRadioButton->setChecked( true );
76 }
77 else if ( type == QgsVectorFieldSymbolLayer::Polar )
78 {
79 mPolarRadioButton->setChecked( true );
80 }
81 else if ( type == QgsVectorFieldSymbolLayer::Height )
82 {
83 mHeightRadioButton->setChecked( true );
84 }
85
86 const QgsVectorFieldSymbolLayer::AngleOrientation orientation = mLayer->angleOrientation();
88 {
89 mClockwiseFromNorthRadioButton->setChecked( true );
90 }
92 {
93 mCounterclockwiseFromEastRadioButton->setChecked( true );
94 }
95
96 const QgsVectorFieldSymbolLayer::AngleUnits angleUnits = mLayer->angleUnits();
97 if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
98 {
99 mDegreesRadioButton->setChecked( true );
100 }
101 else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
102 {
103 mRadiansRadioButton->setChecked( true );
104 }
105
106 mDistanceUnitWidget->blockSignals( true );
107 mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
108 mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
109 mDistanceUnitWidget->blockSignals( false );
110
111 emit changed();
112}
113
118
119void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
120{
121 if ( mLayer )
122 {
123 mLayer->setScale( d );
124 emit changed();
125 }
126}
127
128void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
129{
130 if ( mLayer )
131 {
132 mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
133 emit changed();
134 }
135}
136
137void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
138{
139 if ( mLayer )
140 {
141 mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
142 emit changed();
143 }
144}
145
146void QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled( bool checked )
147{
148 if ( mLayer && checked )
149 {
150 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Cartesian );
151 mXAttributeComboBox->setEnabled( true );
152 mYAttributeComboBox->setEnabled( true );
153 mXAttributeLabel->setText( tr( "X attribute" ) );
154 mYAttributeLabel->setText( tr( "Y attribute" ) );
155 emit changed();
156 }
157}
158
159void QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled( bool checked )
160{
161 if ( mLayer && checked )
162 {
163 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Polar );
164 mXAttributeComboBox->setEnabled( true );
165 mYAttributeComboBox->setEnabled( true );
166 mXAttributeLabel->setText( tr( "Length attribute" ) );
167 mYAttributeLabel->setText( tr( "Angle attribute" ) );
168 emit changed();
169 }
170}
171
172void QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled( bool checked )
173{
174 if ( mLayer && checked )
175 {
176 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Height );
177 mXAttributeLabel->clear();
178 mXAttributeComboBox->setEnabled( false );
179 mYAttributeLabel->setText( tr( "Height attribute" ) );
180 emit changed();
181 }
182}
183
184void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
185{
186 if ( mLayer && checked )
187 {
189 emit changed();
190 }
191}
192
193void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
194{
195 if ( mLayer && checked )
196 {
198 emit changed();
199 }
200}
201
202void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
203{
204 if ( mLayer && checked )
205 {
207 emit changed();
208 }
209}
210
211void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
212{
213 if ( mLayer && checked )
214 {
216 emit changed();
217 }
218}
219
220void QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed()
221{
222 if ( !mLayer )
223 {
224 return;
225 }
226
227 mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
228 mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
229 emit changed();
230}
@ Millimeters
Millimeters.
Definition qgis.h:5184
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5188
@ MapUnits
Map units.
Definition qgis.h:5185
@ Pixels
Pixels.
Definition qgis.h:5186
@ Inches
Inches.
Definition qgis.h:5189
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:54
Container of fields for a vector layer.
Definition qgsfields.h:46
QgsSymbolLayerWidget(QWidget *parent, QgsVectorLayer *vl=nullptr)
Constructor for QgsSymbolLayerWidget.
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.
Abstract base class for symbol layers.
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.
Represents a vector layer which manages a vector based dataset.