QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 }
double arrowWidth() const
Gets current arrow width.
void setHeadThicknessUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head height.
void setHeadLengthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head length.
ArrowType arrowType() const
Gets the current arrow type.
void setMapUnitScale(const QgsMapUnitScale &scale) override
double arrowStartWidth() const
Gets current arrow start width. Only meaningful for single headed arrows.
void setArrowWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow width.
QgsMapUnitScale arrowWidthUnitScale() const
Gets the scale for the arrow width.
QgsUnitTypes::RenderUnit headLengthUnit() const
Gets the unit for the head length.
void setHeadThicknessUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the head height.
QgsUnitTypes::RenderUnit arrowStartWidthUnit() const
Gets the unit for the arrow start width.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:183
double headLength() const
Gets the current arrow head length.
QgsSymbolLayer * symbolLayer() override
const QgsMapUnitScale & offsetMapUnitScale() const
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
void setHeadLength(double length)
Sets the arrow head length.
void setHeadThickness(double thickness)
Sets the arrow head height.
points (e.g., for font sizes)
Definition: qgsunittypes.h:117
void setArrowWidth(double width)
Sets the arrow width.
ArrowType
Possible arrow types.
void setIsRepeated(bool isRepeated)
Sets whether the arrow is repeated along the line.
HeadType headType() const
Gets the current head type.
QgsMapUnitScale headThicknessUnitScale() const
Gets the scale for the head height.
QgsUnitTypes::RenderUnit arrowWidthUnit() const
Gets the unit for the arrow width.
bool isCurved() const
Returns whether it is a curved arrow or a straight one.
void registerDataDefinedButton(QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key)
Registers a data defined override button.
void setIsCurved(bool isCurved)
Sets whether it is a curved arrow or a straight one.
QgsUnitTypes::RenderUnit headThicknessUnit() const
Gets the unit for the head height.
void setHeadLengthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the head length.
void setArrowType(ArrowType type)
Sets the arrow type.
void setSymbolLayer(QgsSymbolLayer *layer) override
void setArrowWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow width.
void setHeadType(HeadType type)
Sets the head type.
void setOffsetUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the line&#39;s offset.
QgsArrowSymbolLayerWidget(QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
bool isRepeated() const
Returns whether the arrow is repeated along the line or not.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units for the line&#39;s offset.
Line symbol layer used for representing lines as arrows.
double offset() const
HeadType
Possible head types.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
void setArrowStartWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the arrow start width.
QgsMapUnitScale headLengthUnitScale() const
Gets the scale for the head length.
Represents a vector layer which manages a vector based data sets.
QgsMapUnitScale arrowStartWidthUnitScale() const
Gets the scale for the arrow start width.
void setArrowStartWidth(double width)
Sets the arrow start width.
void setArrowStartWidthUnitScale(const QgsMapUnitScale &scale)
Sets the scale for the arrow start width.
void setOffset(double offset)
virtual QString layerType() const =0
Returns a string that represents this layer type.
double headThickness() const
Gets the current arrow head height.