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