QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsellipsesymbollayerwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsellipsesymbollayerwidget.cpp
3 ---------------------
4 begin : June 2011
5 copyright : (C) 2011 by Marco Hugentobler
6 email : marco dot hugentobler at sourcepole dot ch
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_qgsellipsesymbollayerwidget.cpp"
18#include "qgsvectorlayer.h"
19#include "qgssymbollayerutils.h"
20#include <QColorDialog>
21
23 : QgsSymbolLayerWidget( parent, vl )
24
25{
26 setupUi( this );
27 connect( mShapeListWidget, &QListWidget::itemSelectionChanged, this, &QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged );
28 connect( mWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged );
29 connect( mHeightSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged );
30 connect( mRotationSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged );
31 connect( mStrokeStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged );
32 connect( mStrokeWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
33 connect( btnChangeColorStroke, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged );
34 connect( btnChangeColorFill, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged );
35 connect( mSymbolWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed );
36 connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
37 connect( mSymbolHeightUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed );
38 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed );
39 connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
40 connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
41
50
51 btnChangeColorFill->setAllowOpacity( true );
52 btnChangeColorFill->setColorDialogTitle( tr( "Select Fill Color" ) );
53 btnChangeColorFill->setContext( QStringLiteral( "symbology" ) );
54 btnChangeColorFill->setShowNoColor( true );
55 btnChangeColorFill->setNoColorString( tr( "Transparent Fill" ) );
56 btnChangeColorStroke->setAllowOpacity( true );
57 btnChangeColorStroke->setColorDialogTitle( tr( "Select Stroke Color" ) );
58 btnChangeColorStroke->setContext( QStringLiteral( "symbology" ) );
59 btnChangeColorStroke->setShowNoColor( true );
60 btnChangeColorStroke->setNoColorString( tr( "Transparent Stroke" ) );
61
62 mFillColorDDBtn->registerLinkedWidget( btnChangeColorFill );
63 mStrokeColorDDBtn->registerLinkedWidget( btnChangeColorStroke );
64
65 spinOffsetX->setClearValue( 0.0 );
66 spinOffsetY->setClearValue( 0.0 );
67 mRotationSpinBox->setClearValue( 0.0 );
68
69 int size = mShapeListWidget->iconSize().width();
70 size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
71 mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
72 mShapeListWidget->setIconSize( QSize( size, size ) );
73
74 const double markerSize = size * 0.8;
75 const auto shapes = QgsEllipseSymbolLayer::availableShapes();
76 for ( const QgsEllipseSymbolLayer::Shape shape : shapes )
77 {
81 lyr->setShape( shape );
82 lyr->setStrokeColor( QColor( 0, 0, 0 ) );
83 lyr->setFillColor( QColor( 200, 200, 200 ) );
84 lyr->setSymbolWidth( markerSize );
85 lyr->setSymbolHeight( markerSize * 0.75 );
87 QListWidgetItem *item = new QListWidgetItem( icon, QString(), mShapeListWidget );
88 item->setData( Qt::UserRole, static_cast< int >( shape ) );
89 item->setToolTip( QgsEllipseSymbolLayer::encodeShape( shape ) );
90 delete lyr;
91 }
92 // show at least 2 rows (only 1 row is required, but looks too cramped)
93 mShapeListWidget->setMinimumHeight( mShapeListWidget->gridSize().height() * 2.1 );
94
95 connect( spinOffsetX, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
96 connect( spinOffsetY, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
97 connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penJoinStyleChanged );
98 connect( cboCapStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penCapStyleChanged );
99}
100
102{
103 if ( !layer || layer->layerType() != QLatin1String( "EllipseMarker" ) )
104 {
105 return;
106 }
107
108 mLayer = static_cast<QgsEllipseSymbolLayer *>( layer );
109 mWidthSpinBox->setValue( mLayer->symbolWidth() );
110 mHeightSpinBox->setValue( mLayer->symbolHeight() );
111 mRotationSpinBox->setValue( mLayer->angle() );
112 mStrokeStyleComboBox->setPenStyle( mLayer->strokeStyle() );
113 mStrokeWidthSpinBox->setValue( mLayer->strokeWidth() );
114 btnChangeColorStroke->setColor( mLayer->strokeColor() );
115 btnChangeColorFill->setColor( mLayer->fillColor() );
116
118 for ( int i = 0; i < mShapeListWidget->count(); ++i )
119 {
120 if ( static_cast< QgsEllipseSymbolLayer::Shape >( mShapeListWidget->item( i )->data( Qt::UserRole ).toInt() ) == shape )
121 {
122 mShapeListWidget->setCurrentRow( i );
123 break;
124 }
125 }
126 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
127
128 //set combo entries to current values
129 blockComboSignals( true );
130 mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
131 mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
132 mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
133 mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
134 mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
135 mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
136 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
137 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
138 const QPointF offsetPt = mLayer->offset();
139 spinOffsetX->setValue( offsetPt.x() );
140 spinOffsetY->setValue( offsetPt.y() );
141 mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
142 mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
143 cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
144 cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
145 blockComboSignals( false );
146
160
161}
162
167
168void QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged()
169{
170 if ( mLayer )
171 {
172 mLayer->setShape( static_cast< QgsEllipseSymbolLayer::Shape>( mShapeListWidget->currentItem()->data( Qt::UserRole ).toInt() ) );
173 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
174 emit changed();
175 }
176}
177
178void QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged( double d )
179{
180 if ( mLayer )
181 {
183 emit changed();
184 }
185}
186
187void QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged( double d )
188{
189 if ( mLayer )
190 {
192 emit changed();
193 }
194}
195
196void QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
197{
198 if ( mLayer )
199 {
200 mLayer->setAngle( d );
201 emit changed();
202 }
203}
204
205void QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged( int index )
206{
207 Q_UNUSED( index )
208
209 if ( mLayer )
210 {
211 mLayer->setStrokeStyle( mStrokeStyleComboBox->penStyle() );
212 emit changed();
213 }
214}
215
216void QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
217{
218 if ( mLayer )
219 {
221 emit changed();
222 }
223}
224
225void QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged( const QColor &newColor )
226{
227 if ( !mLayer )
228 {
229 return;
230 }
231
232 mLayer->setStrokeColor( newColor );
233 emit changed();
234}
235
236void QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged( const QColor &newColor )
237{
238 if ( !mLayer )
239 {
240 return;
241 }
242
243 mLayer->setFillColor( newColor );
244 emit changed();
245}
246
247void QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed()
248{
249 if ( mLayer )
250 {
251 mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
252 mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
253 emit changed();
254 }
255}
256
257void QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
258{
259 if ( mLayer )
260 {
261 mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
262 mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
263 emit changed();
264 }
265}
266
267void QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed()
268{
269 if ( mLayer )
270 {
271 mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
272 mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
273 emit changed();
274 }
275}
276
277void QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed()
278{
279 if ( mLayer )
280 {
281 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
282 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
283 emit changed();
284 }
285}
286
287void QgsEllipseSymbolLayerWidget::penJoinStyleChanged()
288{
289 mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
290 emit changed();
291}
292
293void QgsEllipseSymbolLayerWidget::penCapStyleChanged()
294{
295 mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
296 emit changed();
297}
298
299void QgsEllipseSymbolLayerWidget::blockComboSignals( bool block )
300{
301 mSymbolWidthUnitWidget->blockSignals( block );
302 mStrokeWidthUnitWidget->blockSignals( block );
303 mSymbolHeightUnitWidget->blockSignals( block );
304 mHorizontalAnchorComboBox->blockSignals( block );
305 mVerticalAnchorComboBox->blockSignals( block );
306 mSymbolWidthUnitWidget->blockSignals( block );
307 mStrokeWidthUnitWidget->blockSignals( block );
308 mSymbolHeightUnitWidget->blockSignals( block );
309 mOffsetUnitWidget->blockSignals( block );
310 cboJoinStyle->blockSignals( block );
311 cboCapStyle->blockSignals( block );
312}
313
314void QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int index )
315{
316 if ( mLayer )
317 {
319 emit changed();
320 }
321}
322
323void QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int index )
324{
325 if ( mLayer )
326 {
328 emit changed();
329 }
330}
331
332void QgsEllipseSymbolLayerWidget::setOffset()
333{
334 mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
335 emit changed();
336}
337
338
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
@ Hybrid
Hybrid symbol.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:5667
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
QgsEllipseSymbolLayerWidget(QgsVectorLayer *vl, QWidget *parent=nullptr)
Constructor for QgsEllipseSymbolLayerWidget.
void setSymbolLayer(QgsSymbolLayer *layer) override
QgsSymbolLayer * symbolLayer() override
A symbol layer for rendering objects with major and minor axis (e.g.
void setPenCapStyle(Qt::PenCapStyle style)
Sets the marker's stroke cap style (e.g., flat, round, etc).
void setSymbolHeightMapUnitScale(const QgsMapUnitScale &scale)
void setSymbolWidthMapUnitScale(const QgsMapUnitScale &scale)
Qgis::RenderUnit symbolWidthUnit() const
Returns the units for the symbol's width.
const QgsMapUnitScale & strokeWidthMapUnitScale() const
Qgis::RenderUnit strokeWidthUnit() const
Returns the units for the symbol's stroke width.
void setStrokeColor(const QColor &c) override
Sets the stroke color for the symbol layer.
void setStrokeStyle(Qt::PenStyle strokeStyle)
void setStrokeWidthUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's stroke width.
Shape
Marker symbol shapes.
QColor fillColor() const override
Returns the fill color for the symbol layer.
QgsEllipseSymbolLayer::Shape shape() const
Returns the shape for the rendered ellipse marker symbol.
void setFillColor(const QColor &c) override
Sets the fill color for the symbol layer.
void setShape(QgsEllipseSymbolLayer::Shape shape)
Sets the rendered ellipse marker shape.
static QList< QgsEllipseSymbolLayer::Shape > availableShapes()
Returns a list of all available shape types.
const QgsMapUnitScale & symbolHeightMapUnitScale() const
Qt::PenStyle strokeStyle() const
const QgsMapUnitScale & symbolWidthMapUnitScale() const
static QString encodeShape(QgsEllipseSymbolLayer::Shape shape)
Encodes a shape to its string representation.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
void setSymbolHeightUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's height.
QColor strokeColor() const override
Returns the stroke color for the symbol layer.
void setPenJoinStyle(Qt::PenJoinStyle style)
Set stroke join style.
static bool shapeIsFilled(const QgsEllipseSymbolLayer::Shape &shape)
Returns true if a shape has a fill.
void setSymbolWidthUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's width.
Qgis::RenderUnit symbolHeightUnit() const
Returns the units for the symbol's height.
Qt::PenJoinStyle penJoinStyle() const
Gets stroke join style.
Qt::PenCapStyle penCapStyle() const
Returns the marker's stroke cap style (e.g., flat, round, etc).
Struct for storing maximum and minimum scales for measurements in map units.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
HorizontalAnchorPoint
Symbol horizontal anchor points.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's offset.
void setAngle(double angle)
Sets the rotation angle for the marker.
void setVerticalAnchorPoint(VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
void setHorizontalAnchorPoint(HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the symbol's offset.
Qgis::RenderUnit offsetUnit() const
Returns the units for the symbol's offset.
VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
VerticalAnchorPoint
Symbol vertical anchor points.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol's offset.
double angle() const
Returns the rotation angle for the marker, in degrees clockwise from north.
Stores properties relating to a screen.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, Qgis::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::SymbolType parentSymbolType=Qgis::SymbolType::Hybrid, QgsMapLayer *mapLayer=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Draws a symbol layer preview to an icon.
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.
@ VerticalAnchor
Vertical anchor point.
@ HorizontalAnchor
Horizontal anchor point.
@ StrokeStyle
Stroke style (eg solid, dashed)
@ Name
Name, eg shape name for simple markers.
@ StrokeColor
Stroke color.
@ CapStyle
Line cap style.
@ JoinStyle
Line join style.
@ StrokeWidth
Stroke width.
@ Offset
Symbol offset.
@ Height
Symbol height.
virtual QString layerType() const =0
Returns a string that represents this layer type.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
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.