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