QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
42 mDistanceUnitWidget->setUnits(
44 );
45
46 if ( auto *lVectorLayer = vectorLayer() )
47 {
48 mXAttributeComboBox->addItem( QString() );
49 mYAttributeComboBox->addItem( QString() );
50 int i = 0;
51 const QgsFields fields = lVectorLayer->fields();
52 for ( const QgsField &f : fields )
53 {
54 const QString fieldName = f.name();
55 mXAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
56 mYAttributeComboBox->addItem( lVectorLayer->fields().iconForField( i ), fieldName );
57 i++;
58 }
59 }
60}
61
63{
64 if ( layer->layerType() != "VectorField"_L1 )
65 {
66 return;
67 }
68 mLayer = static_cast<QgsVectorFieldSymbolLayer *>( layer );
69 if ( !mLayer )
70 {
71 return;
72 }
73
74 mXAttributeComboBox->setCurrentIndex( mXAttributeComboBox->findText( mLayer->xAttribute() ) );
75 mYAttributeComboBox->setCurrentIndex( mYAttributeComboBox->findText( mLayer->yAttribute() ) );
76 mScaleSpinBox->setValue( mLayer->scale() );
77
78 const QgsVectorFieldSymbolLayer::VectorFieldType type = mLayer->vectorFieldType();
80 {
81 mCartesianRadioButton->setChecked( true );
82 }
83 else if ( type == QgsVectorFieldSymbolLayer::Polar )
84 {
85 mPolarRadioButton->setChecked( true );
86 }
87 else if ( type == QgsVectorFieldSymbolLayer::Height )
88 {
89 mHeightRadioButton->setChecked( true );
90 }
91
92 const QgsVectorFieldSymbolLayer::AngleOrientation orientation = mLayer->angleOrientation();
94 {
95 mClockwiseFromNorthRadioButton->setChecked( true );
96 }
98 {
99 mCounterclockwiseFromEastRadioButton->setChecked( true );
100 }
101
102 const QgsVectorFieldSymbolLayer::AngleUnits angleUnits = mLayer->angleUnits();
103 if ( angleUnits == QgsVectorFieldSymbolLayer::Degrees )
104 {
105 mDegreesRadioButton->setChecked( true );
106 }
107 else if ( angleUnits == QgsVectorFieldSymbolLayer::Radians )
108 {
109 mRadiansRadioButton->setChecked( true );
110 }
111
112 mDistanceUnitWidget->blockSignals( true );
113 mDistanceUnitWidget->setUnit( mLayer->distanceUnit() );
114 mDistanceUnitWidget->setMapUnitScale( mLayer->distanceMapUnitScale() );
115 mDistanceUnitWidget->blockSignals( false );
116
117 emit changed();
118}
119
124
125void QgsVectorFieldSymbolLayerWidget::mScaleSpinBox_valueChanged( double d )
126{
127 if ( mLayer )
128 {
129 mLayer->setScale( d );
130 emit changed();
131 }
132}
133
134void QgsVectorFieldSymbolLayerWidget::mXAttributeComboBox_currentIndexChanged( int index )
135{
136 if ( mLayer )
137 {
138 mLayer->setXAttribute( mXAttributeComboBox->itemText( index ) );
139 emit changed();
140 }
141}
142
143void QgsVectorFieldSymbolLayerWidget::mYAttributeComboBox_currentIndexChanged( int index )
144{
145 if ( mLayer )
146 {
147 mLayer->setYAttribute( mYAttributeComboBox->itemText( index ) );
148 emit changed();
149 }
150}
151
152void QgsVectorFieldSymbolLayerWidget::mCartesianRadioButton_toggled( bool checked )
153{
154 if ( mLayer && checked )
155 {
156 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Cartesian );
157 mXAttributeComboBox->setEnabled( true );
158 mYAttributeComboBox->setEnabled( true );
159 mXAttributeLabel->setText( tr( "X attribute" ) );
160 mYAttributeLabel->setText( tr( "Y attribute" ) );
161 emit changed();
162 }
163}
164
165void QgsVectorFieldSymbolLayerWidget::mPolarRadioButton_toggled( bool checked )
166{
167 if ( mLayer && checked )
168 {
169 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Polar );
170 mXAttributeComboBox->setEnabled( true );
171 mYAttributeComboBox->setEnabled( true );
172 mXAttributeLabel->setText( tr( "Length attribute" ) );
173 mYAttributeLabel->setText( tr( "Angle attribute" ) );
174 emit changed();
175 }
176}
177
178void QgsVectorFieldSymbolLayerWidget::mHeightRadioButton_toggled( bool checked )
179{
180 if ( mLayer && checked )
181 {
182 mLayer->setVectorFieldType( QgsVectorFieldSymbolLayer::Height );
183 mXAttributeLabel->clear();
184 mXAttributeComboBox->setEnabled( false );
185 mYAttributeLabel->setText( tr( "Height attribute" ) );
186 emit changed();
187 }
188}
189
190void QgsVectorFieldSymbolLayerWidget::mDegreesRadioButton_toggled( bool checked )
191{
192 if ( mLayer && checked )
193 {
195 emit changed();
196 }
197}
198
199void QgsVectorFieldSymbolLayerWidget::mRadiansRadioButton_toggled( bool checked )
200{
201 if ( mLayer && checked )
202 {
204 emit changed();
205 }
206}
207
208void QgsVectorFieldSymbolLayerWidget::mClockwiseFromNorthRadioButton_toggled( bool checked )
209{
210 if ( mLayer && checked )
211 {
213 emit changed();
214 }
215}
216
217void QgsVectorFieldSymbolLayerWidget::mCounterclockwiseFromEastRadioButton_toggled( bool checked )
218{
219 if ( mLayer && checked )
220 {
222 emit changed();
223 }
224}
225
226void QgsVectorFieldSymbolLayerWidget::mDistanceUnitWidget_changed()
227{
228 if ( !mLayer )
229 {
230 return;
231 }
232
233 mLayer->setDistanceUnit( mDistanceUnitWidget->unit() );
234 mLayer->setDistanceMapUnitScale( mDistanceUnitWidget->getMapUnitScale() );
235 emit changed();
236}
@ Millimeters
Millimeters.
Definition qgis.h:5341
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5345
@ MapUnits
Map units.
Definition qgis.h:5342
@ Pixels
Pixels.
Definition qgis.h:5343
@ Inches
Inches.
Definition qgis.h:5346
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.