QGIS API Documentation  3.23.0-Master (22c16f2067)
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 
185  const QgsArrowSymbolLayer::HeadType t = static_cast<QgsArrowSymbolLayer::HeadType>( idx );
186  mLayer->setHeadType( t );
187  const bool isSingle = t == QgsArrowSymbolLayer::HeadSingle || t == QgsArrowSymbolLayer::HeadReversed;
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 }
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.
QgsUnitTypes::RenderUnit headLengthUnit() const
Gets the unit for the head length.
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.
QgsUnitTypes::RenderUnit arrowWidthUnit() const
Gets the unit for the arrow width.
void setArrowWidth(double width)
Sets the arrow width.
QgsUnitTypes::RenderUnit arrowStartWidthUnit() const
Gets the unit for the arrow start 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.
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 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.
QgsUnitTypes::RenderUnit headThicknessUnit() const
Gets the unit for the head height.
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.
void setArrowWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow width.
double arrowWidth() const
Gets current arrow width.
QgsMapUnitScale arrowWidthUnitScale() const
Gets the scale for the arrow width.
void setArrowStartWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow start width.
void setHeadLengthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head length.
void setHeadThicknessUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head height.
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.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the line's offset.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the line's offset.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the line's offset.
void setOffset(double offset)
Sets 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.
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.
@ PropertyArrowStartWidth
Arrow tail start width.
@ PropertyArrowHeadLength
Arrow head length.
@ PropertyArrowHeadThickness
Arrow head thickness.
@ PropertyOffset
Symbol offset.
@ PropertyArrowHeadType
Arrow head type.
@ PropertyArrowType
Arrow type.
@ PropertyArrowWidth
Arrow tail width.
virtual QString layerType() const =0
Returns a string that represents this layer type.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:240
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
Represents a vector layer which manages a vector based data sets.