QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
39 mSizeUnitWidget->setUnits(
41 );
42 mSizeUnitWidget->setUnit( Qgis::RenderUnit::Millimeters );
43
44 mFillSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
45 mFillSymbolButton->setDialogTitle( tr( "Fill Symbol" ) );
46 mFillSymbolButton->setDefaultSymbol( new QgsFillSymbol( QgsSymbolLayerList() << new QgsSimpleFillSymbolLayer( QColor( 255, 255, 255 ), Qt::SolidPattern, QColor( 200, 200, 200 ), Qt::NoPen ) ) );
47 mFillSymbolButton->setToDefaultSymbol();
48
49 mComboJoinStyle->setPenJoinStyle( Qt::RoundJoin );
50
51 connect( mEnabledGroup, &QGroupBox::toggled, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
52 connect( mSpinWidth, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
53 connect( mComboJoinStyle, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
54 connect( mSizeUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
55 connect( mFillSymbolButton, &QgsSymbolButton::changed, this, &QgsSymbolBufferSettingsWidget::onWidgetChanged );
56}
57
59{
60 mBlockUpdates = true;
61 mEnabledGroup->setChecked( settings.enabled() );
62 mSpinWidth->setValue( settings.size() );
63 mSizeUnitWidget->setUnit( settings.sizeUnit() );
64 mSizeUnitWidget->setMapUnitScale( settings.sizeMapUnitScale() );
65 mComboJoinStyle->setPenJoinStyle( settings.joinStyle() );
66
67 if ( const QgsFillSymbol *fill = settings.fillSymbol() )
68 mFillSymbolButton->setSymbol( fill->clone() );
69 mBlockUpdates = false;
70}
71
73{
75 settings.setEnabled( mEnabledGroup->isChecked() );
76 settings.setSize( mSpinWidth->value() );
77 settings.setSizeUnit( mSizeUnitWidget->unit() );
78 settings.setSizeMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
79 settings.setJoinStyle( mComboJoinStyle->penJoinStyle() );
80 settings.setFillSymbol( mFillSymbolButton->clonedSymbol<QgsFillSymbol>() );
81 return settings;
82}
83
84void QgsSymbolBufferSettingsWidget::onWidgetChanged()
85{
86 if ( !mBlockUpdates )
87 emit widgetChanged();
88}
89
90
91//
92// QgsSymbolBufferSettingsDialog
93//
94
96 : QDialog( parent, f )
97{
98 QVBoxLayout *vLayout = new QVBoxLayout();
99 mWidget = new QgsSymbolBufferSettingsWidget();
100 vLayout->addWidget( mWidget );
101 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
102 connect( bbox, &QDialogButtonBox::accepted, this, &QgsSymbolBufferSettingsDialog::accept );
103 connect( bbox, &QDialogButtonBox::rejected, this, &QgsSymbolBufferSettingsDialog::reject );
104 vLayout->addWidget( bbox );
105 setLayout( vLayout );
106 setWindowTitle( tr( "Buffer Settings" ) );
107}
108
110{
111 mWidget->setBufferSettings( settings );
112}
113
115{
116 return mWidget->bufferSettings();
117}
@ Millimeters
Millimeters.
Definition qgis.h:5341
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5345
@ MapUnits
Map units.
Definition qgis.h:5342
@ Pixels
Pixels.
Definition qgis.h:5343
@ Inches
Inches.
Definition qgis.h:5346
@ MetersInMapUnits
Meters value as Map units.
Definition qgis.h:5348
@ Fill
Fill symbol.
Definition qgis.h:639
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:94
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:112
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
Definition qgssymbol.h:164
bool enabled() const
Returns whether the buffer is enabled.
Definition qgssymbol.h:106
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
Definition qgssymbol.h:154
void setSize(double size)
Sets the size of the buffer.
Definition qgssymbol.h:129
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
Definition qgssymbol.h:176
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:145
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
Definition qgssymbol.h:170
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Definition qgssymbol.h:137
double size() const
Returns the size of the buffer.
Definition qgssymbol.h:119
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