QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
37 mSizeUnitWidget->setUnits( { Qgis::RenderUnit::Millimeters,
43 } );
44 mSizeUnitWidget->setUnit( Qgis::RenderUnit::Millimeters );
45
46 mFillSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
47 mFillSymbolButton->setDialogTitle( tr( "Fill Symbol" ) );
48 mFillSymbolButton->setDefaultSymbol( new QgsFillSymbol( QgsSymbolLayerList() << new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::SolidPattern, QColor( 200, 200, 200 ), Qt::NoPen ) ) );
49 mFillSymbolButton->setToDefaultSymbol();
50
51 mComboJoinStyle->setPenJoinStyle( Qt::RoundJoin );
52
53 connect( mEnabledGroup, &QGroupBox::toggled, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
54 connect( mSpinWidth, qOverload< double >( &QgsDoubleSpinBox::valueChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
55 connect( mComboJoinStyle, qOverload< int >( &QComboBox::currentIndexChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
56 connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
57 connect( mFillSymbolButton, &QgsSymbolButton::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
58}
59
61{
62 mBlockUpdates = true;
63 mEnabledGroup->setChecked( settings.enabled() );
64 mSpinWidth->setValue( settings.size() );
65 mSizeUnitWidget->setUnit( settings.sizeUnit() );
66 mSizeUnitWidget->setMapUnitScale( settings.sizeMapUnitScale() );
67 mComboJoinStyle->setPenJoinStyle( settings.joinStyle() );
68
69 if ( const QgsFillSymbol *fill = settings.fillSymbol() )
70 mFillSymbolButton->setSymbol( fill->clone() );
71 mBlockUpdates = false;
72}
73
75{
77 settings.setEnabled( mEnabledGroup->isChecked() );
78 settings.setSize( mSpinWidth->value() );
79 settings.setSizeUnit( mSizeUnitWidget->unit() );
80 settings.setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
81 settings.setJoinStyle( mComboJoinStyle->penJoinStyle() );
82 settings.setFillSymbol( mFillSymbolButton->clonedSymbol< QgsFillSymbol >() );
83 return settings;
84}
85
86void QgsSymbolBufferSettingsWidget::onWidgetChanged()
87{
88 if ( !mBlockUpdates )
89 emit widgetChanged();
90}
91
92
93//
94// QgsSymbolBufferSettingsDialog
95//
96
98 : QDialog( parent, f )
99{
100 QVBoxLayout *vLayout = new QVBoxLayout();
101 mWidget = new QgsSymbolBufferSettingsWidget( );
102 vLayout->addWidget( mWidget );
103 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
104 connect( bbox, &QDialogButtonBox::accepted, this, &QgsSymbolBufferSettingsDialog::accept );
105 connect( bbox, &QDialogButtonBox::rejected, this, &QgsSymbolBufferSettingsDialog::reject );
106 vLayout->addWidget( bbox );
107 setLayout( vLayout );
108 setWindowTitle( tr( "Buffer Settings" ) );
109}
110
112{
113 mWidget->setBufferSettings( settings );
114}
115
120
@ 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