QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsarrowsymbollayerwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsarrowsymbollayerwidget.cpp
3 ---------------------
4 begin : February 2016
5 copyright : (C) 2016 by Hugo Mercier / Oslandia
6 email : hugo dot mercier at oslandia dot com
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_qgsarrowsymbollayerwidget.cpp"
17#include "qgsarrowsymbollayer.h"
18#include "qgsvectorlayer.h"
19#include <QColorDialog>
20
22 : QgsSymbolLayerWidget( parent, vl )
23
24{
25 setupUi( this );
26 connect( mArrowWidthSpin, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsArrowSymbolLayerWidget::mArrowWidthSpin_valueChanged );
27 connect( mArrowWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsArrowSymbolLayerWidget::mArrowWidthUnitWidget_changed );
28 connect( mArrowStartWidthSpin, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsArrowSymbolLayerWidget::mArrowStartWidthSpin_valueChanged );
29 connect( mArrowStartWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsArrowSymbolLayerWidget::mArrowStartWidthUnitWidget_changed );
30 connect( mHeadLengthSpin, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsArrowSymbolLayerWidget::mHeadLengthSpin_valueChanged );
31 connect( mHeadLengthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsArrowSymbolLayerWidget::mHeadLengthUnitWidget_changed );
32 connect( mHeadThicknessSpin, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsArrowSymbolLayerWidget::mHeadThicknessSpin_valueChanged );
33 connect( mHeadThicknessUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsArrowSymbolLayerWidget::mHeadThicknessUnitWidget_changed );
34 connect( mHeadTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsArrowSymbolLayerWidget::mHeadTypeCombo_currentIndexChanged );
35 connect( mArrowTypeCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsArrowSymbolLayerWidget::mArrowTypeCombo_currentIndexChanged );
36 connect( mOffsetSpin, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsArrowSymbolLayerWidget::mOffsetSpin_valueChanged );
37 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsArrowSymbolLayerWidget::mOffsetUnitWidget_changed );
38 connect( mCurvedArrowChck, &QCheckBox::stateChanged, this, &QgsArrowSymbolLayerWidget::mCurvedArrowChck_stateChanged );
39 connect( mRepeatArrowChck, &QCheckBox::stateChanged, this, &QgsArrowSymbolLayerWidget::mRepeatArrowChck_stateChanged );
40 this->layout()->setContentsMargins( 0, 0, 0, 0 );
41
52
53 mOffsetSpin->setClearValue( 0.0 );
54}
55
57{
58 if ( !layer || layer->layerType() != QLatin1String( "ArrowLine" ) )
59 {
60 return;
61 }
62
63 mLayer = static_cast<QgsArrowSymbolLayer *>( layer );
64
65 mArrowWidthSpin->setValue( mLayer->arrowWidth() );
66 mArrowWidthUnitWidget->setUnit( mLayer->arrowWidthUnit() );
67 mArrowWidthUnitWidget->setMapUnitScale( mLayer->arrowWidthUnitScale() );
68
69 mArrowStartWidthSpin->setValue( mLayer->arrowStartWidth() );
70 mArrowStartWidthUnitWidget->setUnit( mLayer->arrowStartWidthUnit() );
71 mArrowStartWidthUnitWidget->setMapUnitScale( mLayer->arrowStartWidthUnitScale() );
72
73 mHeadLengthSpin->setValue( mLayer->headLength() );
74 mHeadLengthUnitWidget->setUnit( mLayer->headLengthUnit() );
75 mHeadLengthUnitWidget->setMapUnitScale( mLayer->headLengthUnitScale() );
76 mHeadThicknessSpin->setValue( mLayer->headThickness() );
77 mHeadThicknessUnitWidget->setUnit( mLayer->headThicknessUnit() );
78 mHeadThicknessUnitWidget->setMapUnitScale( mLayer->headThicknessUnitScale() );
79
80 mHeadTypeCombo->setCurrentIndex( mLayer->headType() );
81 mArrowTypeCombo->setCurrentIndex( mLayer->arrowType() );
82
83 mOffsetSpin->setValue( mLayer->offset() );
84 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
85 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
86
87 mCurvedArrowChck->setChecked( mLayer->isCurved() );
88 mRepeatArrowChck->setChecked( mLayer->isRepeated() );
89
97}
98
99
104
105void QgsArrowSymbolLayerWidget::mArrowWidthSpin_valueChanged( double d )
106{
107 if ( !mLayer )
108 return;
109
110 mLayer->setArrowWidth( d );
111 emit changed();
112}
113
114void QgsArrowSymbolLayerWidget::mArrowStartWidthSpin_valueChanged( double d )
115{
116 if ( !mLayer )
117 return;
118
119 mLayer->setArrowStartWidth( d );
120 emit changed();
121}
122
123void QgsArrowSymbolLayerWidget::mHeadLengthSpin_valueChanged( double d )
124{
125 if ( !mLayer )
126 return;
127
128 mLayer->setHeadLength( d );
129 emit changed();
130}
131
132void QgsArrowSymbolLayerWidget::mHeadThicknessSpin_valueChanged( double d )
133{
134 if ( !mLayer )
135 return;
136
137 mLayer->setHeadThickness( d );
138 emit changed();
139}
140
141void QgsArrowSymbolLayerWidget::mArrowWidthUnitWidget_changed()
142{
143 if ( !mLayer )
144 return;
145
146 mLayer->setArrowWidthUnit( mArrowWidthUnitWidget->unit() );
147 mLayer->setArrowWidthUnitScale( mArrowWidthUnitWidget->getMapUnitScale() );
148 emit changed();
149}
150
151void QgsArrowSymbolLayerWidget::mArrowStartWidthUnitWidget_changed()
152{
153 if ( !mLayer )
154 return;
155
156 mLayer->setArrowStartWidthUnit( mArrowStartWidthUnitWidget->unit() );
157 mLayer->setArrowStartWidthUnitScale( mArrowStartWidthUnitWidget->getMapUnitScale() );
158 emit changed();
159}
160
161void QgsArrowSymbolLayerWidget::mHeadLengthUnitWidget_changed()
162{
163 if ( !mLayer )
164 return;
165
166 mLayer->setHeadLengthUnit( mHeadLengthUnitWidget->unit() );
167 mLayer->setHeadLengthUnitScale( mHeadLengthUnitWidget->getMapUnitScale() );
168 emit changed();
169}
170
171void QgsArrowSymbolLayerWidget::mHeadThicknessUnitWidget_changed()
172{
173 if ( !mLayer )
174 return;
175
176 mLayer->setHeadThicknessUnit( mHeadThicknessUnitWidget->unit() );
177 mLayer->setHeadThicknessUnitScale( mHeadThicknessUnitWidget->getMapUnitScale() );
178 emit changed();
179}
180
181void QgsArrowSymbolLayerWidget::mHeadTypeCombo_currentIndexChanged( int idx )
182{
183 if ( !mLayer )
184 return;
185
187 mLayer->setHeadType( t );
189 mArrowStartWidthDDBtn->setEnabled( isSingle );
190 mArrowStartWidthSpin->setEnabled( isSingle );
191 mArrowStartWidthUnitWidget->setEnabled( isSingle );
192 emit changed();
193}
194
195void QgsArrowSymbolLayerWidget::mArrowTypeCombo_currentIndexChanged( int idx )
196{
197 if ( !mLayer )
198 return;
199
201 mLayer->setArrowType( t );
202 emit changed();
203}
204
205void QgsArrowSymbolLayerWidget::mOffsetSpin_valueChanged( double d )
206{
207 if ( !mLayer )
208 return;
209
210 mLayer->setOffset( d );
211 emit changed();
212}
213
214void QgsArrowSymbolLayerWidget::mOffsetUnitWidget_changed()
215{
216 if ( !mLayer )
217 return;
218
219 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
220 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
221 emit changed();
222}
223
224void QgsArrowSymbolLayerWidget::mCurvedArrowChck_stateChanged( int state )
225{
226 if ( ! mLayer )
227 return;
228
229 mLayer->setIsCurved( state == Qt::Checked );
230 emit changed();
231}
232
233void QgsArrowSymbolLayerWidget::mRepeatArrowChck_stateChanged( int state )
234{
235 if ( ! mLayer )
236 return;
237
238 mLayer->setIsRepeated( state == Qt::Checked );
239 emit changed();
240}
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
QgsArrowSymbolLayerWidget(QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
QgsSymbolLayer * symbolLayer() override
void setSymbolLayer(QgsSymbolLayer *layer) override
Line symbol layer used for representing lines as arrows.
bool isCurved() const
Returns whether it is a curved arrow or a straight one.
ArrowType arrowType() const
Gets the current arrow type.
HeadType
Possible head types.
HeadType headType() const
Gets the current head type.
void setArrowStartWidth(double width)
Sets the arrow start width.
bool isRepeated() const
Returns whether the arrow is repeated along the line or not.
void setArrowWidth(double width)
Sets the arrow width.
void setArrowType(ArrowType type)
Sets the arrow type.
void setHeadLengthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head length.
QgsMapUnitScale headThicknessUnitScale() const
Gets the scale for the head height.
Qgis::RenderUnit arrowWidthUnit() const
Gets the unit for the arrow width.
Qgis::RenderUnit headLengthUnit() const
Gets the unit for the head length.
Qgis::RenderUnit headThicknessUnit() const
Gets the unit for the head height.
void setArrowWidthUnit(Qgis::RenderUnit unit)
Sets the unit for the arrow width.
void setIsCurved(bool isCurved)
Sets whether it is a curved arrow or a straight one.
void setHeadThickness(double thickness)
Sets the arrow head height.
void setHeadLengthUnit(Qgis::RenderUnit unit)
Sets the unit for the head length.
void setIsRepeated(bool isRepeated)
Sets whether the arrow is repeated along the line.
double arrowStartWidth() const
Gets current arrow start width. Only meaningful for single headed arrows.
void setArrowStartWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow start width.
void setHeadThicknessUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head height.
void setHeadType(HeadType type)
Sets the head type.
QgsMapUnitScale arrowStartWidthUnitScale() const
Gets the scale for the arrow start width.
double headThickness() const
Gets the current arrow head height.
void setArrowWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow width.
ArrowType
Possible arrow types.
double arrowWidth() const
Gets current arrow width.
QgsMapUnitScale arrowWidthUnitScale() const
Gets the scale for the arrow width.
void setArrowStartWidthUnit(Qgis::RenderUnit unit)
Sets the unit for the arrow start width.
Qgis::RenderUnit arrowStartWidthUnit() const
Gets the unit for the arrow start width.
QgsMapUnitScale headLengthUnitScale() const
Gets the scale for the head length.
void setHeadLength(double length)
Sets the arrow head length.
double headLength() const
Gets the current arrow head length.
void setHeadThicknessUnit(Qgis::RenderUnit unit)
Sets the unit for the head height.
void setOffset(double offset)
Sets the line's offset.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the line's offset.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the line's offset.
void setMapUnitScale(const QgsMapUnitScale &scale) override
double offset() const
Returns the line's offset.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the line's offset.
Qgis::RenderUnit offsetUnit() const
Returns the units for the line's offset.
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key)
Registers a data defined override button.
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
@ ArrowHeadLength
Arrow head length.
@ ArrowWidth
Arrow tail width.
@ ArrowHeadType
Arrow head type.
@ ArrowHeadThickness
Arrow head thickness.
@ ArrowStartWidth
Arrow tail start width.
@ Offset
Symbol offset.
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.
Represents a vector layer which manages a vector based data sets.