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