QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
18#include "qgsfillsymbol.h"
19#include "qgsfillsymbollayer.h"
20#include "qgssymbol.h"
21
22#include <QDialogButtonBox>
23
24#include "moc_qgssymbolbuffersettingswidget.cpp"
25
27 : QgsPanelWidget( parent )
28{
29 setupUi( this );
30
31 setPanelTitle( tr( "Buffer Settings" ) );
32
33 mSpinWidth->setClearValue( 1 );
34 mSpinWidth->setShowClearButton( true );
35 mSpinWidth->setValue( 1 );
36
37 mEnabledGroup->setChecked( false );
38
40 mSizeUnitWidget->setUnit( Qgis::RenderUnit::Millimeters );
41
42 mFillSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
43 mFillSymbolButton->setDialogTitle( tr( "Fill Symbol" ) );
44 mFillSymbolButton->setDefaultSymbol( new QgsFillSymbol( QgsSymbolLayerList() << new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::SolidPattern, QColor( 200, 200, 200 ), Qt::NoPen ) ) );
45 mFillSymbolButton->setToDefaultSymbol();
46
47 mComboJoinStyle->setPenJoinStyle( Qt::RoundJoin );
48
49 connect( mEnabledGroup, &QGroupBox::toggled, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
50 connect( mSpinWidth, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
51 connect( mComboJoinStyle, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
52 connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
53 connect( mFillSymbolButton, &QgsSymbolButton::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
54}
55
57{
58 mBlockUpdates = true;
59 mEnabledGroup->setChecked( settings.enabled() );
60 mSpinWidth->setValue( settings.size() );
61 mSizeUnitWidget->setUnit( settings.sizeUnit() );
62 mSizeUnitWidget->setMapUnitScale( settings.sizeMapUnitScale() );
63 mComboJoinStyle->setPenJoinStyle( settings.joinStyle() );
64
65 if ( const QgsFillSymbol *fill = settings.fillSymbol() )
66 mFillSymbolButton->setSymbol( fill->clone() );
67 mBlockUpdates = false;
68}
69
71{
73 settings.setEnabled( mEnabledGroup->isChecked() );
74 settings.setSize( mSpinWidth->value() );
75 settings.setSizeUnit( mSizeUnitWidget->unit() );
76 settings.setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
77 settings.setJoinStyle( mComboJoinStyle->penJoinStyle() );
78 settings.setFillSymbol( mFillSymbolButton->clonedSymbol<QgsFillSymbol>() );
79 return settings;
80}
81
82void QgsSymbolBufferSettingsWidget::onWidgetChanged()
83{
84 if ( !mBlockUpdates )
85 emit widgetChanged();
86}
87
88
89//
90// QgsSymbolBufferSettingsDialog
91//
92
94 : QDialog( parent, f )
95{
96 QVBoxLayout *vLayout = new QVBoxLayout();
97 mWidget = new QgsSymbolBufferSettingsWidget();
98 vLayout->addWidget( mWidget );
99 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
100 connect( bbox, &QDialogButtonBox::accepted, this, &QgsSymbolBufferSettingsDialog::accept );
101 connect( bbox, &QDialogButtonBox::rejected, this, &QgsSymbolBufferSettingsDialog::reject );
102 vLayout->addWidget( bbox );
103 setLayout( vLayout );
104 setWindowTitle( tr( "Buffer Settings" ) );
105}
106
108{
109 mWidget->setBufferSettings( settings );
110}
111
113{
114 return mWidget->bufferSettings();
115}
@ 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
@ Fill
Fill symbol.
Definition qgis.h:613
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an 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.
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