QGIS API Documentation 3.43.0-Master (9e873c7bc91)
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
28 mHorizontalAnchorComboBox->addItem( tr( "Left" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Left ) );
29 mHorizontalAnchorComboBox->addItem( tr( "Horizontal Center" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Center ) );
30 mHorizontalAnchorComboBox->addItem( tr( "Right" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Right ) );
31
32 mVerticalAnchorComboBox->addItem( tr( "Top" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Top ) );
33 mVerticalAnchorComboBox->addItem( tr( "Vertical Center" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Center ) );
34 mVerticalAnchorComboBox->addItem( tr( "Bottom" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Bottom ) );
35
36 connect( mShapeListWidget, &QListWidget::itemSelectionChanged, this, &QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged );
37 connect( mWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged );
38 connect( mHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged );
39 connect( mRotationSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged );
40 connect( mStrokeStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged );
41 connect( mStrokeWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
42 connect( btnChangeColorStroke, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged );
43 connect( btnChangeColorFill, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged );
44 connect( mSymbolWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed );
45 connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
46 connect( mSymbolHeightUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed );
47 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed );
48 connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
49 connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
50
55
56 btnChangeColorFill->setAllowOpacity( true );
57 btnChangeColorFill->setColorDialogTitle( tr( "Select Fill Color" ) );
58 btnChangeColorFill->setContext( QStringLiteral( "symbology" ) );
59 btnChangeColorFill->setShowNoColor( true );
60 btnChangeColorFill->setNoColorString( tr( "Transparent Fill" ) );
61 btnChangeColorStroke->setAllowOpacity( true );
62 btnChangeColorStroke->setColorDialogTitle( tr( "Select Stroke Color" ) );
63 btnChangeColorStroke->setContext( QStringLiteral( "symbology" ) );
64 btnChangeColorStroke->setShowNoColor( true );
65 btnChangeColorStroke->setNoColorString( tr( "Transparent Stroke" ) );
66
67 mFillColorDDBtn->registerLinkedWidget( btnChangeColorFill );
68 mStrokeColorDDBtn->registerLinkedWidget( btnChangeColorStroke );
69
70 spinOffsetX->setClearValue( 0.0 );
71 spinOffsetY->setClearValue( 0.0 );
72 mRotationSpinBox->setClearValue( 0.0 );
73
74 int size = mShapeListWidget->iconSize().width();
75 size = std::max( 30, static_cast<int>( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
76 mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
77 mShapeListWidget->setIconSize( QSize( size, size ) );
78
79 const double markerSize = size * 0.8;
80 const auto shapes = QgsEllipseSymbolLayer::availableShapes();
81 for ( const QgsEllipseSymbolLayer::Shape shape : shapes )
82 {
86 lyr->setShape( shape );
87 lyr->setStrokeColor( QColor( 0, 0, 0 ) );
88 lyr->setFillColor( QColor( 200, 200, 200 ) );
89 lyr->setSymbolWidth( markerSize );
90 lyr->setSymbolHeight( markerSize * 0.75 );
92 QListWidgetItem *item = new QListWidgetItem( icon, QString(), mShapeListWidget );
93 item->setData( Qt::UserRole, static_cast<int>( shape ) );
94 item->setToolTip( QgsEllipseSymbolLayer::encodeShape( shape ) );
95 delete lyr;
96 }
97 // show at least 2 rows (only 1 row is required, but looks too cramped)
98 mShapeListWidget->setMinimumHeight( mShapeListWidget->gridSize().height() * 2.1 );
99
100 connect( spinOffsetX, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
101 connect( spinOffsetY, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
102 connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penJoinStyleChanged );
103 connect( cboCapStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penCapStyleChanged );
104}
105
107{
108 if ( !layer || layer->layerType() != QLatin1String( "EllipseMarker" ) )
109 {
110 return;
111 }
112
113 mLayer = static_cast<QgsEllipseSymbolLayer *>( layer );
114 mWidthSpinBox->setValue( mLayer->symbolWidth() );
115 mHeightSpinBox->setValue( mLayer->symbolHeight() );
116 mRotationSpinBox->setValue( mLayer->angle() );
117 mStrokeStyleComboBox->setPenStyle( mLayer->strokeStyle() );
118 mStrokeWidthSpinBox->setValue( mLayer->strokeWidth() );
119 btnChangeColorStroke->setColor( mLayer->strokeColor() );
120 btnChangeColorFill->setColor( mLayer->fillColor() );
121
123 for ( int i = 0; i < mShapeListWidget->count(); ++i )
124 {
125 if ( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->item( i )->data( Qt::UserRole ).toInt() ) == shape )
126 {
127 mShapeListWidget->setCurrentRow( i );
128 break;
129 }
130 }
131 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
132
133 //set combo entries to current values
134 blockComboSignals( true );
135 mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
136 mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
137 mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
138 mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
139 mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
140 mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
141 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
142 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
143 const QPointF offsetPt = mLayer->offset();
144 spinOffsetX->setValue( offsetPt.x() );
145 spinOffsetY->setValue( offsetPt.y() );
146 mHorizontalAnchorComboBox->setCurrentIndex( mHorizontalAnchorComboBox->findData( QVariant::fromValue( mLayer->horizontalAnchorPoint() ) ) );
147 mVerticalAnchorComboBox->setCurrentIndex( mVerticalAnchorComboBox->findData( QVariant::fromValue( mLayer->verticalAnchorPoint() ) ) );
148 cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
149 cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
150 blockComboSignals( false );
151
165}
166
171
172void QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged()
173{
174 if ( mLayer )
175 {
176 mLayer->setShape( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->currentItem()->data( Qt::UserRole ).toInt() ) );
177 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
178 emit changed();
179 }
180}
181
182void QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged( double d )
183{
184 if ( mLayer )
185 {
187 emit changed();
188 }
189}
190
191void QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged( double d )
192{
193 if ( mLayer )
194 {
196 emit changed();
197 }
198}
199
200void QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
201{
202 if ( mLayer )
203 {
204 mLayer->setAngle( d );
205 emit changed();
206 }
207}
208
209void QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged( int index )
210{
211 Q_UNUSED( index )
212
213 if ( mLayer )
214 {
215 mLayer->setStrokeStyle( mStrokeStyleComboBox->penStyle() );
216 emit changed();
217 }
218}
219
220void QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
221{
222 if ( mLayer )
223 {
225 emit changed();
226 }
227}
228
229void QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged( const QColor &newColor )
230{
231 if ( !mLayer )
232 {
233 return;
234 }
235
236 mLayer->setStrokeColor( newColor );
237 emit changed();
238}
239
240void QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged( const QColor &newColor )
241{
242 if ( !mLayer )
243 {
244 return;
245 }
246
247 mLayer->setFillColor( newColor );
248 emit changed();
249}
250
251void QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed()
252{
253 if ( mLayer )
254 {
255 mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
256 mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
257 emit changed();
258 }
259}
260
261void QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
262{
263 if ( mLayer )
264 {
265 mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
266 mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
267 emit changed();
268 }
269}
270
271void QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed()
272{
273 if ( mLayer )
274 {
275 mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
276 mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
277 emit changed();
278 }
279}
280
281void QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed()
282{
283 if ( mLayer )
284 {
285 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
286 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
287 emit changed();
288 }
289}
290
291void QgsEllipseSymbolLayerWidget::penJoinStyleChanged()
292{
293 mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
294 emit changed();
295}
296
297void QgsEllipseSymbolLayerWidget::penCapStyleChanged()
298{
299 mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
300 emit changed();
301}
302
303void QgsEllipseSymbolLayerWidget::blockComboSignals( bool block )
304{
305 mSymbolWidthUnitWidget->blockSignals( block );
306 mStrokeWidthUnitWidget->blockSignals( block );
307 mSymbolHeightUnitWidget->blockSignals( block );
308 mHorizontalAnchorComboBox->blockSignals( block );
309 mVerticalAnchorComboBox->blockSignals( block );
310 mSymbolWidthUnitWidget->blockSignals( block );
311 mStrokeWidthUnitWidget->blockSignals( block );
312 mSymbolHeightUnitWidget->blockSignals( block );
313 mOffsetUnitWidget->blockSignals( block );
314 cboJoinStyle->blockSignals( block );
315 cboCapStyle->blockSignals( block );
316}
317
318void QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int )
319{
320 if ( mLayer )
321 {
322 mLayer->setHorizontalAnchorPoint( mHorizontalAnchorComboBox->currentData().value< Qgis::HorizontalAnchorPoint >() );
323 emit changed();
324 }
325}
326
327void QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int )
328{
329 if ( mLayer )
330 {
331 mLayer->setVerticalAnchorPoint( mVerticalAnchorComboBox->currentData().value< Qgis::VerticalAnchorPoint >() );
332 emit changed();
333 }
334}
335
336void QgsEllipseSymbolLayerWidget::setOffset()
337{
338 mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
339 emit changed();
340}
VerticalAnchorPoint
Marker symbol vertical anchor points.
Definition qgis.h:778
@ Bottom
Align to bottom of symbol.
@ Center
Align to vertical center of symbol.
@ Top
Align to top of symbol.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
@ Hybrid
Hybrid symbol.
HorizontalAnchorPoint
Marker symbol horizontal anchor points.
Definition qgis.h:764
@ Center
Align to horizontal center of symbol.
@ Right
Align to right side of symbol.
@ Left
Align to left side of symbol.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:5909
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.
void setVerticalAnchorPoint(Qgis::VerticalAnchorPoint v)
Sets the vertical anchor point for positioning the symbol.
QPointF offset() const
Returns the marker's offset, which is the horizontal and vertical displacement which the rendered mar...
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 setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
Qgis::VerticalAnchorPoint verticalAnchorPoint() const
Returns the vertical anchor point for positioning the symbol.
const QgsMapUnitScale & offsetMapUnitScale() const
Returns the map unit scale for the symbol's offset.
void setHorizontalAnchorPoint(Qgis::HorizontalAnchorPoint h)
Sets the horizontal anchor point for positioning the symbol.
Qgis::RenderUnit offsetUnit() const
Returns the units for the symbol's offset.
Qgis::HorizontalAnchorPoint horizontalAnchorPoint() const
Returns the horizontal anchor point for positioning the symbol.
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.