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