QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
18#include "qgssymbollayerutils.h"
19#include "qgsvectorlayer.h"
20
21#include <QColorDialog>
22#include <QString>
23
24#include "moc_qgsellipsesymbollayerwidget.cpp"
25
26using namespace Qt::StringLiterals;
27
29 : QgsSymbolLayerWidget( parent, vl )
30
31{
32 setupUi( this );
33
34 mHorizontalAnchorComboBox->addItem( tr( "Left" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Left ) );
35 mHorizontalAnchorComboBox->addItem( tr( "Horizontal Center" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Center ) );
36 mHorizontalAnchorComboBox->addItem( tr( "Right" ), QVariant::fromValue( Qgis::HorizontalAnchorPoint::Right ) );
37
38 mVerticalAnchorComboBox->addItem( tr( "Top" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Top ) );
39 mVerticalAnchorComboBox->addItem( tr( "Vertical Center" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Center ) );
40 mVerticalAnchorComboBox->addItem( tr( "Bottom" ), QVariant::fromValue( Qgis::VerticalAnchorPoint::Bottom ) );
41
42 connect( mShapeListWidget, &QListWidget::itemSelectionChanged, this, &QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged );
43 connect( mWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged );
44 connect( mHeightSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged );
45 connect( mRotationSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged );
46 connect( mStrokeStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged );
47 connect( mStrokeWidthSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged );
48 connect( btnChangeColorStroke, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged );
49 connect( btnChangeColorFill, &QgsColorButton::colorChanged, this, &QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged );
50 connect( mSymbolWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed );
51 connect( mStrokeWidthUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed );
52 connect( mSymbolHeightUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed );
53 connect( mOffsetUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed );
54 connect( mHorizontalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged );
55 connect( mVerticalAnchorComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged );
56
61
62 btnChangeColorFill->setAllowOpacity( true );
63 btnChangeColorFill->setColorDialogTitle( tr( "Select Fill Color" ) );
64 btnChangeColorFill->setContext( u"symbology"_s );
65 btnChangeColorFill->setShowNoColor( true );
66 btnChangeColorFill->setNoColorString( tr( "Transparent Fill" ) );
67 btnChangeColorStroke->setAllowOpacity( true );
68 btnChangeColorStroke->setColorDialogTitle( tr( "Select Stroke Color" ) );
69 btnChangeColorStroke->setContext( u"symbology"_s );
70 btnChangeColorStroke->setShowNoColor( true );
71 btnChangeColorStroke->setNoColorString( tr( "Transparent Stroke" ) );
72
73 mFillColorDDBtn->registerLinkedWidget( btnChangeColorFill );
74 mStrokeColorDDBtn->registerLinkedWidget( btnChangeColorStroke );
75
76 spinOffsetX->setClearValue( 0.0 );
77 spinOffsetY->setClearValue( 0.0 );
78 mRotationSpinBox->setClearValue( 0.0 );
79
80 int size = mShapeListWidget->iconSize().width();
81 size = std::max( 30, static_cast<int>( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
82 mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
83 mShapeListWidget->setIconSize( QSize( size, size ) );
84
85 const double markerSize = size * 0.8;
86 const auto shapes = QgsEllipseSymbolLayer::availableShapes();
87 for ( const QgsEllipseSymbolLayer::Shape shape : shapes )
88 {
92 lyr->setShape( shape );
93 lyr->setStrokeColor( QColor( 0, 0, 0 ) );
94 lyr->setFillColor( QColor( 200, 200, 200 ) );
95 lyr->setSymbolWidth( markerSize );
96 lyr->setSymbolHeight( markerSize * 0.75 );
98 QListWidgetItem *item = new QListWidgetItem( icon, QString(), mShapeListWidget );
99 item->setData( Qt::UserRole, static_cast<int>( shape ) );
100 item->setToolTip( QgsEllipseSymbolLayer::encodeShape( shape ) );
101 delete lyr;
102 }
103 // show at least 2 rows (only 1 row is required, but looks too cramped)
104 mShapeListWidget->setMinimumHeight( mShapeListWidget->gridSize().height() * 2.1 );
105
106 connect( spinOffsetX, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
107 connect( spinOffsetY, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
108 connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penJoinStyleChanged );
109 connect( cboCapStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penCapStyleChanged );
110}
111
113{
114 if ( !layer || layer->layerType() != "EllipseMarker"_L1 )
115 {
116 return;
117 }
118
119 mLayer = static_cast<QgsEllipseSymbolLayer *>( layer );
120 mWidthSpinBox->setValue( mLayer->symbolWidth() );
121 mHeightSpinBox->setValue( mLayer->symbolHeight() );
122 mRotationSpinBox->setValue( mLayer->angle() );
123 mStrokeStyleComboBox->setPenStyle( mLayer->strokeStyle() );
124 mStrokeWidthSpinBox->setValue( mLayer->strokeWidth() );
125 btnChangeColorStroke->setColor( mLayer->strokeColor() );
126 btnChangeColorFill->setColor( mLayer->fillColor() );
127
128 const QgsEllipseSymbolLayer::Shape shape = mLayer->shape();
129 for ( int i = 0; i < mShapeListWidget->count(); ++i )
130 {
131 if ( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->item( i )->data( Qt::UserRole ).toInt() ) == shape )
132 {
133 mShapeListWidget->setCurrentRow( i );
134 break;
135 }
136 }
137 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
138
139 //set combo entries to current values
140 blockComboSignals( true );
141 mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
142 mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
143 mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
144 mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
145 mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
146 mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
147 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
148 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
149 const QPointF offsetPt = mLayer->offset();
150 spinOffsetX->setValue( offsetPt.x() );
151 spinOffsetY->setValue( offsetPt.y() );
152 mHorizontalAnchorComboBox->setCurrentIndex( mHorizontalAnchorComboBox->findData( QVariant::fromValue( mLayer->horizontalAnchorPoint() ) ) );
153 mVerticalAnchorComboBox->setCurrentIndex( mVerticalAnchorComboBox->findData( QVariant::fromValue( mLayer->verticalAnchorPoint() ) ) );
154 cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
155 cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
156 blockComboSignals( false );
157
171}
172
177
178void QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged()
179{
180 if ( mLayer )
181 {
182 mLayer->setShape( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->currentItem()->data( Qt::UserRole ).toInt() ) );
183 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
184 emit changed();
185 }
186}
187
188void QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged( double d )
189{
190 if ( mLayer )
191 {
192 mLayer->setSymbolWidth( d );
193 emit changed();
194 }
195}
196
197void QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged( double d )
198{
199 if ( mLayer )
200 {
201 mLayer->setSymbolHeight( d );
202 emit changed();
203 }
204}
205
206void QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
207{
208 if ( mLayer )
209 {
210 mLayer->setAngle( d );
211 emit changed();
212 }
213}
214
215void QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged( int index )
216{
217 Q_UNUSED( index )
218
219 if ( mLayer )
220 {
221 mLayer->setStrokeStyle( mStrokeStyleComboBox->penStyle() );
222 emit changed();
223 }
224}
225
226void QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
227{
228 if ( mLayer )
229 {
230 mLayer->setStrokeWidth( d );
231 emit changed();
232 }
233}
234
235void QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged( const QColor &newColor )
236{
237 if ( !mLayer )
238 {
239 return;
240 }
241
242 mLayer->setStrokeColor( newColor );
243 emit changed();
244}
245
246void QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged( const QColor &newColor )
247{
248 if ( !mLayer )
249 {
250 return;
251 }
252
253 mLayer->setFillColor( newColor );
254 emit changed();
255}
256
257void QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed()
258{
259 if ( mLayer )
260 {
261 mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
262 mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
263 emit changed();
264 }
265}
266
267void QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
268{
269 if ( mLayer )
270 {
271 mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
272 mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
273 emit changed();
274 }
275}
276
277void QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed()
278{
279 if ( mLayer )
280 {
281 mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
282 mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
283 emit changed();
284 }
285}
286
287void QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed()
288{
289 if ( mLayer )
290 {
291 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
292 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
293 emit changed();
294 }
295}
296
297void QgsEllipseSymbolLayerWidget::penJoinStyleChanged()
298{
299 mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
300 emit changed();
301}
302
303void QgsEllipseSymbolLayerWidget::penCapStyleChanged()
304{
305 mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
306 emit changed();
307}
308
309void QgsEllipseSymbolLayerWidget::blockComboSignals( bool block )
310{
311 mSymbolWidthUnitWidget->blockSignals( block );
312 mStrokeWidthUnitWidget->blockSignals( block );
313 mSymbolHeightUnitWidget->blockSignals( block );
314 mHorizontalAnchorComboBox->blockSignals( block );
315 mVerticalAnchorComboBox->blockSignals( block );
316 mSymbolWidthUnitWidget->blockSignals( block );
317 mStrokeWidthUnitWidget->blockSignals( block );
318 mSymbolHeightUnitWidget->blockSignals( block );
319 mOffsetUnitWidget->blockSignals( block );
320 cboJoinStyle->blockSignals( block );
321 cboCapStyle->blockSignals( block );
322}
323
324void QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int )
325{
326 if ( mLayer )
327 {
328 mLayer->setHorizontalAnchorPoint( mHorizontalAnchorComboBox->currentData().value< Qgis::HorizontalAnchorPoint >() );
329 emit changed();
330 }
331}
332
333void QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int )
334{
335 if ( mLayer )
336 {
337 mLayer->setVerticalAnchorPoint( mVerticalAnchorComboBox->currentData().value< Qgis::VerticalAnchorPoint >() );
338 emit changed();
339 }
340}
341
342void QgsEllipseSymbolLayerWidget::setOffset()
343{
344 mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
345 emit changed();
346}
VerticalAnchorPoint
Marker symbol vertical anchor points.
Definition qgis.h:833
@ Bottom
Align to bottom of symbol.
Definition qgis.h:836
@ Center
Align to vertical center of symbol.
Definition qgis.h:835
@ Top
Align to top of symbol.
Definition qgis.h:834
@ Millimeters
Millimeters.
Definition qgis.h:5280
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5284
@ MapUnits
Map units.
Definition qgis.h:5281
@ Pixels
Pixels.
Definition qgis.h:5282
@ Inches
Inches.
Definition qgis.h:5285
@ MetersInMapUnits
Meters value as Map units.
Definition qgis.h:5287
@ Hybrid
Hybrid symbol.
Definition qgis.h:633
HorizontalAnchorPoint
Marker symbol horizontal anchor points.
Definition qgis.h:819
@ Center
Align to horizontal center of symbol.
Definition qgis.h:821
@ Right
Align to right side of symbol.
Definition qgis.h:822
@ Left
Align to left side of symbol.
Definition qgis.h:820
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:6523
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 setStrokeColor(const QColor &c) override
Sets the stroke color for the symbol layer.
Shape
Marker symbol shapes.
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.
static QString encodeShape(QgsEllipseSymbolLayer::Shape shape)
Encodes a shape to its string representation.
void setSymbolHeightUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's height.
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.
Struct for storing maximum and minimum scales for measurements in map units.
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.
QgsSymbolLayerWidget(QWidget *parent, QgsVectorLayer *vl=nullptr)
Constructor for QgsSymbolLayerWidget.
void changed()
Should be emitted whenever configuration changes happened on this symbol layer configuration.
Abstract base class for symbol layers.
@ VerticalAnchor
Vertical anchor point.
@ HorizontalAnchor
Horizontal anchor point.
@ StrokeStyle
Stroke style (eg solid, dashed).
@ Name
Name, eg shape name for simple markers.
@ CapStyle
Line cap style.
@ JoinStyle
Line join style.
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 dataset.