QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
47
48 mOffsetSpin->setClearValue( 0.0 );
49}
50
52{
53 if ( !layer || layer->layerType() != QLatin1String( "ArrowLine" ) )
54 {
55 return;
56 }
57
58 mLayer = static_cast<QgsArrowSymbolLayer *>( layer );
59
60 mArrowWidthSpin->setValue( mLayer->arrowWidth() );
61 mArrowWidthUnitWidget->setUnit( mLayer->arrowWidthUnit() );
62 mArrowWidthUnitWidget->setMapUnitScale( mLayer->arrowWidthUnitScale() );
63
64 mArrowStartWidthSpin->setValue( mLayer->arrowStartWidth() );
65 mArrowStartWidthUnitWidget->setUnit( mLayer->arrowStartWidthUnit() );
66 mArrowStartWidthUnitWidget->setMapUnitScale( mLayer->arrowStartWidthUnitScale() );
67
68 mHeadLengthSpin->setValue( mLayer->headLength() );
69 mHeadLengthUnitWidget->setUnit( mLayer->headLengthUnit() );
70 mHeadLengthUnitWidget->setMapUnitScale( mLayer->headLengthUnitScale() );
71 mHeadThicknessSpin->setValue( mLayer->headThickness() );
72 mHeadThicknessUnitWidget->setUnit( mLayer->headThicknessUnit() );
73 mHeadThicknessUnitWidget->setMapUnitScale( mLayer->headThicknessUnitScale() );
74
75 mHeadTypeCombo->setCurrentIndex( mLayer->headType() );
76 mArrowTypeCombo->setCurrentIndex( mLayer->arrowType() );
77
78 mOffsetSpin->setValue( mLayer->offset() );
79 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
80 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
81
82 mCurvedArrowChck->setChecked( mLayer->isCurved() );
83 mRepeatArrowChck->setChecked( mLayer->isRepeated() );
84
92}
93
94
99
100void QgsArrowSymbolLayerWidget::mArrowWidthSpin_valueChanged( double d )
101{
102 if ( !mLayer )
103 return;
104
105 mLayer->setArrowWidth( d );
106 emit changed();
107}
108
109void QgsArrowSymbolLayerWidget::mArrowStartWidthSpin_valueChanged( double d )
110{
111 if ( !mLayer )
112 return;
113
114 mLayer->setArrowStartWidth( d );
115 emit changed();
116}
117
118void QgsArrowSymbolLayerWidget::mHeadLengthSpin_valueChanged( double d )
119{
120 if ( !mLayer )
121 return;
122
123 mLayer->setHeadLength( d );
124 emit changed();
125}
126
127void QgsArrowSymbolLayerWidget::mHeadThicknessSpin_valueChanged( double d )
128{
129 if ( !mLayer )
130 return;
131
132 mLayer->setHeadThickness( d );
133 emit changed();
134}
135
136void QgsArrowSymbolLayerWidget::mArrowWidthUnitWidget_changed()
137{
138 if ( !mLayer )
139 return;
140
141 mLayer->setArrowWidthUnit( mArrowWidthUnitWidget->unit() );
142 mLayer->setArrowWidthUnitScale( mArrowWidthUnitWidget->getMapUnitScale() );
143 emit changed();
144}
145
146void QgsArrowSymbolLayerWidget::mArrowStartWidthUnitWidget_changed()
147{
148 if ( !mLayer )
149 return;
150
151 mLayer->setArrowStartWidthUnit( mArrowStartWidthUnitWidget->unit() );
152 mLayer->setArrowStartWidthUnitScale( mArrowStartWidthUnitWidget->getMapUnitScale() );
153 emit changed();
154}
155
156void QgsArrowSymbolLayerWidget::mHeadLengthUnitWidget_changed()
157{
158 if ( !mLayer )
159 return;
160
161 mLayer->setHeadLengthUnit( mHeadLengthUnitWidget->unit() );
162 mLayer->setHeadLengthUnitScale( mHeadLengthUnitWidget->getMapUnitScale() );
163 emit changed();
164}
165
166void QgsArrowSymbolLayerWidget::mHeadThicknessUnitWidget_changed()
167{
168 if ( !mLayer )
169 return;
170
171 mLayer->setHeadThicknessUnit( mHeadThicknessUnitWidget->unit() );
172 mLayer->setHeadThicknessUnitScale( mHeadThicknessUnitWidget->getMapUnitScale() );
173 emit changed();
174}
175
176void QgsArrowSymbolLayerWidget::mHeadTypeCombo_currentIndexChanged( int idx )
177{
178 if ( !mLayer )
179 return;
180
182 mLayer->setHeadType( t );
184 mArrowStartWidthDDBtn->setEnabled( isSingle );
185 mArrowStartWidthSpin->setEnabled( isSingle );
186 mArrowStartWidthUnitWidget->setEnabled( isSingle );
187 emit changed();
188}
189
190void QgsArrowSymbolLayerWidget::mArrowTypeCombo_currentIndexChanged( int idx )
191{
192 if ( !mLayer )
193 return;
194
196 mLayer->setArrowType( t );
197 emit changed();
198}
199
200void QgsArrowSymbolLayerWidget::mOffsetSpin_valueChanged( double d )
201{
202 if ( !mLayer )
203 return;
204
205 mLayer->setOffset( d );
206 emit changed();
207}
208
209void QgsArrowSymbolLayerWidget::mOffsetUnitWidget_changed()
210{
211 if ( !mLayer )
212 return;
213
214 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
215 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
216 emit changed();
217}
218
219void QgsArrowSymbolLayerWidget::mCurvedArrowChck_stateChanged( int state )
220{
221 if ( !mLayer )
222 return;
223
224 mLayer->setIsCurved( state == Qt::Checked );
225 emit changed();
226}
227
228void QgsArrowSymbolLayerWidget::mRepeatArrowChck_stateChanged( int state )
229{
230 if ( !mLayer )
231 return;
232
233 mLayer->setIsRepeated( state == Qt::Checked );
234 emit changed();
235}
@ 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.