QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
57 mSymbolWidthUnitWidget->setUnits(
59 );
60 mSymbolHeightUnitWidget->setUnits(
62 );
63 mStrokeWidthUnitWidget->setUnits(
65 );
66 mOffsetUnitWidget->setUnits(
68 );
69
70 btnChangeColorFill->setAllowOpacity( true );
71 btnChangeColorFill->setColorDialogTitle( tr( "Select Fill Color" ) );
72 btnChangeColorFill->setContext( u"symbology"_s );
73 btnChangeColorFill->setShowNoColor( true );
74 btnChangeColorFill->setNoColorString( tr( "Transparent Fill" ) );
75 btnChangeColorStroke->setAllowOpacity( true );
76 btnChangeColorStroke->setColorDialogTitle( tr( "Select Stroke Color" ) );
77 btnChangeColorStroke->setContext( u"symbology"_s );
78 btnChangeColorStroke->setShowNoColor( true );
79 btnChangeColorStroke->setNoColorString( tr( "Transparent Stroke" ) );
80
81 mFillColorDDBtn->registerLinkedWidget( btnChangeColorFill );
82 mStrokeColorDDBtn->registerLinkedWidget( btnChangeColorStroke );
83
84 spinOffsetX->setClearValue( 0.0 );
85 spinOffsetY->setClearValue( 0.0 );
86 mRotationSpinBox->setClearValue( 0.0 );
87
88 int size = mShapeListWidget->iconSize().width();
89 size = std::max( 30, static_cast<int>( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );
90 mShapeListWidget->setGridSize( QSize( size * 1.2, size * 1.2 ) );
91 mShapeListWidget->setIconSize( QSize( size, size ) );
92
93 const double markerSize = size * 0.8;
94 const auto shapes = QgsEllipseSymbolLayer::availableShapes();
95 for ( const QgsEllipseSymbolLayer::Shape shape : shapes )
96 {
100 lyr->setShape( shape );
101 lyr->setStrokeColor( QColor( 0, 0, 0 ) );
102 lyr->setFillColor( QColor( 200, 200, 200 ) );
103 lyr->setSymbolWidth( markerSize );
104 lyr->setSymbolHeight( markerSize * 0.75 );
105 const QIcon icon
107 QListWidgetItem *item = new QListWidgetItem( icon, QString(), mShapeListWidget );
108 item->setData( Qt::UserRole, static_cast<int>( shape ) );
109 item->setToolTip( QgsEllipseSymbolLayer::encodeShape( shape ) );
110 delete lyr;
111 }
112 // show at least 2 rows (only 1 row is required, but looks too cramped)
113 mShapeListWidget->setMinimumHeight( mShapeListWidget->gridSize().height() * 2.1 );
114
115 connect( spinOffsetX, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
116 connect( spinOffsetY, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, &QgsEllipseSymbolLayerWidget::setOffset );
117 connect( cboJoinStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penJoinStyleChanged );
118 connect( cboCapStyle, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEllipseSymbolLayerWidget::penCapStyleChanged );
119}
120
122{
123 if ( !layer || layer->layerType() != "EllipseMarker"_L1 )
124 {
125 return;
126 }
127
128 mLayer = static_cast<QgsEllipseSymbolLayer *>( layer );
129 mWidthSpinBox->setValue( mLayer->symbolWidth() );
130 mHeightSpinBox->setValue( mLayer->symbolHeight() );
131 mRotationSpinBox->setValue( mLayer->angle() );
132 mStrokeStyleComboBox->setPenStyle( mLayer->strokeStyle() );
133 mStrokeWidthSpinBox->setValue( mLayer->strokeWidth() );
134 btnChangeColorStroke->setColor( mLayer->strokeColor() );
135 btnChangeColorFill->setColor( mLayer->fillColor() );
136
137 const QgsEllipseSymbolLayer::Shape shape = mLayer->shape();
138 for ( int i = 0; i < mShapeListWidget->count(); ++i )
139 {
140 if ( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->item( i )->data( Qt::UserRole ).toInt() ) == shape )
141 {
142 mShapeListWidget->setCurrentRow( i );
143 break;
144 }
145 }
146 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
147
148 //set combo entries to current values
149 blockComboSignals( true );
150 mSymbolWidthUnitWidget->setUnit( mLayer->symbolWidthUnit() );
151 mSymbolWidthUnitWidget->setMapUnitScale( mLayer->symbolWidthMapUnitScale() );
152 mStrokeWidthUnitWidget->setUnit( mLayer->strokeWidthUnit() );
153 mStrokeWidthUnitWidget->setMapUnitScale( mLayer->strokeWidthMapUnitScale() );
154 mSymbolHeightUnitWidget->setUnit( mLayer->symbolHeightUnit() );
155 mSymbolHeightUnitWidget->setMapUnitScale( mLayer->symbolHeightMapUnitScale() );
156 mOffsetUnitWidget->setUnit( mLayer->offsetUnit() );
157 mOffsetUnitWidget->setMapUnitScale( mLayer->offsetMapUnitScale() );
158 const QPointF offsetPt = mLayer->offset();
159 spinOffsetX->setValue( offsetPt.x() );
160 spinOffsetY->setValue( offsetPt.y() );
161 mHorizontalAnchorComboBox->setCurrentIndex( mHorizontalAnchorComboBox->findData( QVariant::fromValue( mLayer->horizontalAnchorPoint() ) ) );
162 mVerticalAnchorComboBox->setCurrentIndex( mVerticalAnchorComboBox->findData( QVariant::fromValue( mLayer->verticalAnchorPoint() ) ) );
163 cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
164 cboCapStyle->setPenCapStyle( mLayer->penCapStyle() );
165 blockComboSignals( false );
166
180}
181
186
187void QgsEllipseSymbolLayerWidget::mShapeListWidget_itemSelectionChanged()
188{
189 if ( mLayer )
190 {
191 mLayer->setShape( static_cast<QgsEllipseSymbolLayer::Shape>( mShapeListWidget->currentItem()->data( Qt::UserRole ).toInt() ) );
192 btnChangeColorFill->setEnabled( QgsEllipseSymbolLayer::shapeIsFilled( mLayer->shape() ) );
193 emit changed();
194 }
195}
196
197void QgsEllipseSymbolLayerWidget::mWidthSpinBox_valueChanged( double d )
198{
199 if ( mLayer )
200 {
201 mLayer->setSymbolWidth( d );
202 emit changed();
203 }
204}
205
206void QgsEllipseSymbolLayerWidget::mHeightSpinBox_valueChanged( double d )
207{
208 if ( mLayer )
209 {
210 mLayer->setSymbolHeight( d );
211 emit changed();
212 }
213}
214
215void QgsEllipseSymbolLayerWidget::mRotationSpinBox_valueChanged( double d )
216{
217 if ( mLayer )
218 {
219 mLayer->setAngle( d );
220 emit changed();
221 }
222}
223
224void QgsEllipseSymbolLayerWidget::mStrokeStyleComboBox_currentIndexChanged( int index )
225{
226 Q_UNUSED( index )
227
228 if ( mLayer )
229 {
230 mLayer->setStrokeStyle( mStrokeStyleComboBox->penStyle() );
231 emit changed();
232 }
233}
234
235void QgsEllipseSymbolLayerWidget::mStrokeWidthSpinBox_valueChanged( double d )
236{
237 if ( mLayer )
238 {
239 mLayer->setStrokeWidth( d );
240 emit changed();
241 }
242}
243
244void QgsEllipseSymbolLayerWidget::btnChangeColorStroke_colorChanged( const QColor &newColor )
245{
246 if ( !mLayer )
247 {
248 return;
249 }
250
251 mLayer->setStrokeColor( newColor );
252 emit changed();
253}
254
255void QgsEllipseSymbolLayerWidget::btnChangeColorFill_colorChanged( const QColor &newColor )
256{
257 if ( !mLayer )
258 {
259 return;
260 }
261
262 mLayer->setFillColor( newColor );
263 emit changed();
264}
265
266void QgsEllipseSymbolLayerWidget::mSymbolWidthUnitWidget_changed()
267{
268 if ( mLayer )
269 {
270 mLayer->setSymbolWidthUnit( mSymbolWidthUnitWidget->unit() );
271 mLayer->setSymbolWidthMapUnitScale( mSymbolWidthUnitWidget->getMapUnitScale() );
272 emit changed();
273 }
274}
275
276void QgsEllipseSymbolLayerWidget::mStrokeWidthUnitWidget_changed()
277{
278 if ( mLayer )
279 {
280 mLayer->setStrokeWidthUnit( mStrokeWidthUnitWidget->unit() );
281 mLayer->setStrokeWidthMapUnitScale( mStrokeWidthUnitWidget->getMapUnitScale() );
282 emit changed();
283 }
284}
285
286void QgsEllipseSymbolLayerWidget::mSymbolHeightUnitWidget_changed()
287{
288 if ( mLayer )
289 {
290 mLayer->setSymbolHeightUnit( mSymbolHeightUnitWidget->unit() );
291 mLayer->setSymbolHeightMapUnitScale( mSymbolHeightUnitWidget->getMapUnitScale() );
292 emit changed();
293 }
294}
295
296void QgsEllipseSymbolLayerWidget::mOffsetUnitWidget_changed()
297{
298 if ( mLayer )
299 {
300 mLayer->setOffsetUnit( mOffsetUnitWidget->unit() );
301 mLayer->setOffsetMapUnitScale( mOffsetUnitWidget->getMapUnitScale() );
302 emit changed();
303 }
304}
305
306void QgsEllipseSymbolLayerWidget::penJoinStyleChanged()
307{
308 mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
309 emit changed();
310}
311
312void QgsEllipseSymbolLayerWidget::penCapStyleChanged()
313{
314 mLayer->setPenCapStyle( cboCapStyle->penCapStyle() );
315 emit changed();
316}
317
318void QgsEllipseSymbolLayerWidget::blockComboSignals( bool block )
319{
320 mSymbolWidthUnitWidget->blockSignals( block );
321 mStrokeWidthUnitWidget->blockSignals( block );
322 mSymbolHeightUnitWidget->blockSignals( block );
323 mHorizontalAnchorComboBox->blockSignals( block );
324 mVerticalAnchorComboBox->blockSignals( block );
325 mSymbolWidthUnitWidget->blockSignals( block );
326 mStrokeWidthUnitWidget->blockSignals( block );
327 mSymbolHeightUnitWidget->blockSignals( block );
328 mOffsetUnitWidget->blockSignals( block );
329 cboJoinStyle->blockSignals( block );
330 cboCapStyle->blockSignals( block );
331}
332
333void QgsEllipseSymbolLayerWidget::mHorizontalAnchorComboBox_currentIndexChanged( int )
334{
335 if ( mLayer )
336 {
337 mLayer->setHorizontalAnchorPoint( mHorizontalAnchorComboBox->currentData().value< Qgis::HorizontalAnchorPoint >() );
338 emit changed();
339 }
340}
341
342void QgsEllipseSymbolLayerWidget::mVerticalAnchorComboBox_currentIndexChanged( int )
343{
344 if ( mLayer )
345 {
346 mLayer->setVerticalAnchorPoint( mVerticalAnchorComboBox->currentData().value< Qgis::VerticalAnchorPoint >() );
347 emit changed();
348 }
349}
350
351void QgsEllipseSymbolLayerWidget::setOffset()
352{
353 mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
354 emit changed();
355}
VerticalAnchorPoint
Marker symbol vertical anchor points.
Definition qgis.h:840
@ Bottom
Align to bottom of symbol.
Definition qgis.h:843
@ Center
Align to vertical center of symbol.
Definition qgis.h:842
@ Top
Align to top of symbol.
Definition qgis.h:841
@ Millimeters
Millimeters.
Definition qgis.h:5341
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5345
@ MapUnits
Map units.
Definition qgis.h:5342
@ Pixels
Pixels.
Definition qgis.h:5343
@ Inches
Inches.
Definition qgis.h:5346
@ MetersInMapUnits
Meters value as Map units.
Definition qgis.h:5348
@ Hybrid
Hybrid symbol.
Definition qgis.h:640
HorizontalAnchorPoint
Marker symbol horizontal anchor points.
Definition qgis.h:826
@ Center
Align to horizontal center of symbol.
Definition qgis.h:828
@ Right
Align to right side of symbol.
Definition qgis.h:829
@ Left
Align to left side of symbol.
Definition qgis.h:827
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition qgis.h:6591
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.