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