QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  : QgsSymbolLayerV2Widget( parent, vl )
22  , mLayer( nullptr )
23 {
24  setupUi( this );
25 
26  mArrowWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
27  mArrowStartWidthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
28  mHeadLengthUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
29  mHeadThicknessUnitWidget->setUnits( QgsSymbolV2::OutputUnitList() << QgsSymbolV2::MM << QgsSymbolV2::MapUnit << QgsSymbolV2::Pixel );
31 
32  mOffsetSpin->setClearValue( 0.0 );
33 }
34 
36 {
37  if ( !layer || layer->layerType() != "ArrowLine" )
38  {
39  return;
40  }
41 
42  mLayer = static_cast<QgsArrowSymbolLayer*>( layer );
43 
44  mArrowWidthSpin->setValue( mLayer->arrowWidth() );
45  mArrowWidthUnitWidget->setUnit( mLayer->arrowWidthUnit() );
46  mArrowWidthUnitWidget->setMapUnitScale( mLayer->arrowWidthUnitScale() );
47 
48  mArrowStartWidthSpin->setValue( mLayer->arrowStartWidth() );
49  mArrowStartWidthUnitWidget->setUnit( mLayer->arrowStartWidthUnit() );
50  mArrowStartWidthUnitWidget->setMapUnitScale( mLayer->arrowStartWidthUnitScale() );
51 
52  mHeadLengthSpin->setValue( mLayer->headLength() );
53  mHeadLengthUnitWidget->setUnit( mLayer->headLengthUnit() );
54  mHeadLengthUnitWidget->setMapUnitScale( mLayer->headLengthUnitScale() );
55  mHeadThicknessSpin->setValue( mLayer->headThickness() );
56  mHeadThicknessUnitWidget->setUnit( mLayer->headThicknessUnit() );
57  mHeadThicknessUnitWidget->setMapUnitScale( mLayer->headThicknessUnitScale() );
58 
59  mHeadTypeCombo->setCurrentIndex( mLayer->headType() );
60  mArrowTypeCombo->setCurrentIndex( mLayer->arrowType() );
61 
62  mOffsetSpin->setValue( mLayer->offset() );
63  mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
64  mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
65 
66  mCurvedArrowChck->setChecked( mLayer->isCurved() );
67  mRepeatArrowChck->setChecked( mLayer->isRepeated() );
68 
70  registerDataDefinedButton( mArrowStartWidthDDBtn, "arrow_start_width", QgsDataDefinedButton::Double, QgsDataDefinedButton::doubleDesc() );
76 }
77 
78 
80 {
81  return mLayer;
82 }
83 
84 void QgsArrowSymbolLayerWidget::on_mArrowWidthSpin_valueChanged( double d )
85 {
86  if ( !mLayer )
87  return;
88 
89  mLayer->setArrowWidth( d );
90  emit changed();
91 }
92 
93 void QgsArrowSymbolLayerWidget::on_mArrowStartWidthSpin_valueChanged( double d )
94 {
95  if ( !mLayer )
96  return;
97 
98  mLayer->setArrowStartWidth( d );
99  emit changed();
100 }
101 
102 void QgsArrowSymbolLayerWidget::on_mHeadLengthSpin_valueChanged( double d )
103 {
104  if ( !mLayer )
105  return;
106 
107  mLayer->setHeadLength( d );
108  emit changed();
109 }
110 
111 void QgsArrowSymbolLayerWidget::on_mHeadThicknessSpin_valueChanged( double d )
112 {
113  if ( !mLayer )
114  return;
115 
116  mLayer->setHeadThickness( d );
117  emit changed();
118 }
119 
120 void QgsArrowSymbolLayerWidget::on_mArrowWidthUnitWidget_changed()
121 {
122  if ( !mLayer )
123  return;
124 
125  mLayer->setArrowWidthUnit( mArrowWidthUnitWidget->unit() );
126  mLayer->setArrowWidthUnitScale( mArrowWidthUnitWidget->getMapUnitScale() );
127  emit changed();
128 }
129 
130 void QgsArrowSymbolLayerWidget::on_mArrowStartWidthUnitWidget_changed()
131 {
132  if ( !mLayer )
133  return;
134 
135  mLayer->setArrowStartWidthUnit( mArrowStartWidthUnitWidget->unit() );
136  mLayer->setArrowStartWidthUnitScale( mArrowStartWidthUnitWidget->getMapUnitScale() );
137  emit changed();
138 }
139 
140 void QgsArrowSymbolLayerWidget::on_mHeadLengthUnitWidget_changed()
141 {
142  if ( !mLayer )
143  return;
144 
145  mLayer->setHeadLengthUnit( mHeadLengthUnitWidget->unit() );
146  mLayer->setHeadLengthUnitScale( mHeadLengthUnitWidget->getMapUnitScale() );
147  emit changed();
148 }
149 
150 void QgsArrowSymbolLayerWidget::on_mHeadThicknessUnitWidget_changed()
151 {
152  if ( !mLayer )
153  return;
154 
155  mLayer->setHeadThicknessUnit( mHeadThicknessUnitWidget->unit() );
156  mLayer->setHeadThicknessUnitScale( mHeadThicknessUnitWidget->getMapUnitScale() );
157  emit changed();
158 }
159 
160 void QgsArrowSymbolLayerWidget::on_mHeadTypeCombo_currentIndexChanged( int idx )
161 {
162  if ( !mLayer )
163  return;
164 
166  mLayer->setHeadType( t );
168  mArrowStartWidthDDBtn->setEnabled( isSingle );
169  mArrowStartWidthSpin->setEnabled( isSingle );
170  mArrowStartWidthUnitWidget->setEnabled( isSingle );
171  emit changed();
172 }
173 
174 void QgsArrowSymbolLayerWidget::on_mArrowTypeCombo_currentIndexChanged( int idx )
175 {
176  if ( !mLayer )
177  return;
178 
180  mLayer->setArrowType( t );
181  emit changed();
182 }
183 
184 void QgsArrowSymbolLayerWidget::on_mOffsetSpin_valueChanged( double d )
185 {
186  if ( !mLayer )
187  return;
188 
189  mLayer->setOffset( d );
190  emit changed();
191 }
192 
193 void QgsArrowSymbolLayerWidget::on_mOffsetUnitWidget_changed()
194 {
195  if ( !mLayer )
196  return;
197 
198  mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
199  mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
200  emit changed();
201 }
202 
203 void QgsArrowSymbolLayerWidget::on_mCurvedArrowChck_stateChanged( int state )
204 {
205  if ( ! mLayer )
206  return;
207 
208  mLayer->setIsCurved( state == Qt::Checked );
209  emit changed();
210 }
211 
212 void QgsArrowSymbolLayerWidget::on_mRepeatArrowChck_stateChanged( int state )
213 {
214  if ( ! mLayer )
215  return;
216 
217  mLayer->setIsRepeated( state == Qt::Checked );
218  emit changed();
219 }
void setHeadThicknessUnitScale(const QgsMapUnitScale &scale)
Set the scale for the head height.
void setupUi(QWidget *widget)
double arrowStartWidth() const
Get current arrow start width.
double arrowWidth() const
Get current arrow width.
QgsSymbolV2::OutputUnit headThicknessUnit() const
Get the unit for the head height.
virtual QgsSymbolLayerV2 * symbolLayer() override
Get the current symbol layer.
The output shall be in pixels.
Definition: qgssymbolv2.h:70
QgsMapUnitScale arrowStartWidthUnitScale() const
Get the scale for the arrow start width.
QgsMapUnitScale headLengthUnitScale() const
Get the scale for the head length.
void setArrowWidthUnit(QgsSymbolV2::OutputUnit unit)
Set the unit for the arrow width.
const QgsMapUnitScale & offsetMapUnitScale() const
ArrowType arrowType() const
Get the current arrow type.
bool isRepeated() const
Return whether the arrow is repeated along the line or not.
The output shall be in millimeters.
Definition: qgssymbolv2.h:67
void setOffset(double offset)
void setHeadLength(double length)
Set the arrow head length.
void setHeadThickness(double thickness)
Set the arrow head height.
void registerDataDefinedButton(QgsDataDefinedButton *button, const QString &propertyName, QgsDataDefinedButton::DataType type, const QString &description)
QgsArrowSymbolLayerWidget(const QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
The output shall be in map unitx.
Definition: qgssymbolv2.h:68
void setHeadThicknessUnit(QgsSymbolV2::OutputUnit unit)
Set the unit for the head height.
void setArrowWidth(double width)
Set the arrow width.
ArrowType
Possible arrow types.
bool isCurved() const
Return whether it is a curved arrow or a straight one.
double headLength() const
Get the current arrow head length.
void setIsRepeated(bool isRepeated)
Set whether the arrow is repeated along the line.
virtual void setSymbolLayer(QgsSymbolLayerV2 *layer) override
Set the symbol layer.
QgsMapUnitScale arrowWidthUnitScale() const
Get the scale for the arrow width.
void setOffsetUnit(QgsSymbolV2::OutputUnit unit)
virtual QString layerType() const =0
Returns a string that represents this layer type.
void setIsCurved(bool isCurved)
Set whether it is a curved arrow or a straight one.
void setHeadLengthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the head length.
void setMapUnitScale(const QgsMapUnitScale &scale) override
void setArrowType(ArrowType type)
Set the arrow type.
QgsSymbolV2::OutputUnit offsetUnit() const
QgsSymbolV2::OutputUnit headLengthUnit() const
Get the unit for the head length.
void setArrowWidthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the arrow width.
void setArrowStartWidthUnit(QgsSymbolV2::OutputUnit unit)
Set the unit for the arrow start width.
void setHeadType(HeadType type)
Set the head type.
QgsSymbolV2::OutputUnit arrowStartWidthUnit() const
Get the unit for the arrow start width.
void setHeadLengthUnit(QgsSymbolV2::OutputUnit unit)
Set the unit for the head length.
QgsMapUnitScale headThicknessUnitScale() const
Get the scale for the head height.
Line symbol layer used for representing lines as arrows.
HeadType
Possible head types.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
QgsSymbolV2::OutputUnit arrowWidthUnit() const
Get the unit for the arrow width.
Represents a vector layer which manages a vector based data sets.
HeadType headType() const
Get the current head type.
void setArrowStartWidth(double width)
Set the arrow start width.
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
void setArrowStartWidthUnitScale(const QgsMapUnitScale &scale)
Set the scale for the arrow start width.
double headThickness() const
Get the current arrow head height.