QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
qgssymbolbuffersettingswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbolbuffersettingswidget.h
3 ---------------------
4 begin : July 2024
5 copyright : (C) 2024 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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 ***************************************************************************/
15
17#include "qgssymbol.h"
18#include "qgsfillsymbol.h"
19#include "qgsfillsymbollayer.h"
20
21#include <QDialogButtonBox>
22
24 : QgsPanelWidget( parent )
25{
26 setupUi( this );
27
28 setPanelTitle( tr( "Buffer Settings" ) );
29
30 mSpinWidth->setClearValue( 1 );
31 mSpinWidth->setShowClearButton( true );
32 mSpinWidth->setValue( 1 );
33
34 mEnabledGroup->setChecked( false );
35
36 mSizeUnitWidget->setUnits( { Qgis::RenderUnit::Millimeters,
42 } );
43 mSizeUnitWidget->setUnit( Qgis::RenderUnit::Millimeters );
44
45 mFillSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
46 mFillSymbolButton->setDialogTitle( tr( "Fill Symbol" ) );
47 mFillSymbolButton->setDefaultSymbol( new QgsFillSymbol( QgsSymbolLayerList() << new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::SolidPattern, QColor( 200, 200, 200 ), Qt::NoPen ) ) );
48 mFillSymbolButton->setToDefaultSymbol();
49
50 mComboJoinStyle->setPenJoinStyle( Qt::RoundJoin );
51
52 connect( mEnabledGroup, &QGroupBox::toggled, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
53 connect( mSpinWidth, qOverload< double >( &QgsDoubleSpinBox::valueChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
54 connect( mComboJoinStyle, qOverload< int >( &QComboBox::currentIndexChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
55 connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
56 connect( mFillSymbolButton, &QgsSymbolButton::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
57}
58
60{
61 mBlockUpdates = true;
62 mEnabledGroup->setChecked( settings.enabled() );
63 mSpinWidth->setValue( settings.size() );
64 mSizeUnitWidget->setUnit( settings.sizeUnit() );
65 mSizeUnitWidget->setMapUnitScale( settings.sizeMapUnitScale() );
66 mComboJoinStyle->setPenJoinStyle( settings.joinStyle() );
67
68 if ( const QgsFillSymbol *fill = settings.fillSymbol() )
69 mFillSymbolButton->setSymbol( fill->clone() );
70 mBlockUpdates = false;
71}
72
74{
76 settings.setEnabled( mEnabledGroup->isChecked() );
77 settings.setSize( mSpinWidth->value() );
78 settings.setSizeUnit( mSizeUnitWidget->unit() );
79 settings.setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
80 settings.setJoinStyle( mComboJoinStyle->penJoinStyle() );
81 settings.setFillSymbol( mFillSymbolButton->clonedSymbol< QgsFillSymbol >() );
82 return settings;
83}
84
85void QgsSymbolBufferSettingsWidget::onWidgetChanged()
86{
87 if ( !mBlockUpdates )
88 emit widgetChanged();
89}
90
91
92//
93// QgsSymbolBufferSettingsDialog
94//
95
97 : QDialog( parent, f )
98{
99 QVBoxLayout *vLayout = new QVBoxLayout();
100 mWidget = new QgsSymbolBufferSettingsWidget( );
101 vLayout->addWidget( mWidget );
102 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
103 connect( bbox, &QDialogButtonBox::accepted, this, &QgsSymbolBufferSettingsDialog::accept );
104 connect( bbox, &QDialogButtonBox::rejected, this, &QgsSymbolBufferSettingsDialog::reject );
105 vLayout->addWidget( bbox );
106 setLayout( vLayout );
107 setWindowTitle( tr( "Buffer Settings" ) );
108}
109
111{
112 mWidget->setBufferSettings( settings );
113}
114
119
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
@ Fill
Fill symbol.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Base class for any widget that can be shown as a inline panel.
void widgetChanged()
Emitted when the widget state changes.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Renders polygons using a single fill and stroke color.
QgsSymbolBufferSettingsDialog(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor for QgsSymbolBufferSettingsDialog.
QgsSymbolBufferSettings bufferSettings() const
Returns the buffer settings as defined in the dialog.
void setBufferSettings(const QgsSymbolBufferSettings &settings)
Sets the buffer settings to show in the dialog.
A widget for customising buffer settings for a symbol.
QgsSymbolBufferSettings bufferSettings() const
Returns the buffer settings as defined in the widget.
void setBufferSettings(const QgsSymbolBufferSettings &settings)
Sets the buffer settings to show in the widget.
QgsSymbolBufferSettingsWidget(QWidget *parent=nullptr)
Constructor for QgsSymbolBufferSettingsWidget.
Contains settings relating to symbol buffers, which draw a "halo" effect around the symbol.
Definition qgssymbol.h:97
QgsFillSymbol * fillSymbol() const
Returns the fill symbol used to render the buffer.
Definition qgssymbol.cpp:97
void setEnabled(bool enabled)
Sets whether the symbol buffer will be drawn.
Definition qgssymbol.h:116
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
Definition qgssymbol.h:168
bool enabled() const
Returns whether the buffer is enabled.
Definition qgssymbol.h:110
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
Definition qgssymbol.h:158
void setSize(double size)
Sets the size of the buffer.
Definition qgssymbol.h:133
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
Definition qgssymbol.h:180
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the buffer.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the unit used for the buffer size.
Definition qgssymbol.h:149
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
Definition qgssymbol.h:174
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Definition qgssymbol.h:141
double size() const
Returns the size of the buffer.
Definition qgssymbol.h:123
void changed()
Emitted when the symbol's settings are changed.
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30