QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsextentbufferdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsextentbufferdialog.cpp
3 ---------------------
4 begin : December 2024
5 copyright : (C) 2024 by Juho Ervasti
6 email : juho dot ervasti at gispo dot fi
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_qgsextentbufferdialog.cpp"
18#include "qdialogbuttonbox.h"
21#include "qgshelp.h"
22#include "qgsmapcanvas.h"
23#include "qgspanelwidget.h"
24#include "qgsproject.h"
25#include "qgssymbol.h"
27#include "qgsunittypes.h"
28#include "qgsvectorlayer.h"
29
31 : QgsPanelWidget( parent ), mSymbol( symbol ), mLayer( layer )
32{
33 setupUi( this );
34
35 mExtentBufferSpinBox->setValue( mSymbol->extentBuffer() );
36
37 mExtentBufferUnitSelectionWidget->setShowMapScaleButton( false );
39 mExtentBufferUnitSelectionWidget->setUnit( mSymbol->extentBufferSizeUnit() );
40
41 connect( mExtentBufferSpinBox, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, [=]() {
42 emit widgetChanged();
43 } );
44
45 connect( mExtentBufferUnitSelectionWidget, &QgsUnitSelectionWidget::changed, this, [=]() {
46 emit widgetChanged();
47 } );
48
49 registerDataDefinedButton( mExtentBufferDDButton, QgsSymbol::Property::ExtentBuffer );
50}
51
53{
54 return mContext;
55}
56
58{
59 mContext = context;
60}
61
62void QgsExtentBufferWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
63{
64 // pass in nullptr to avoid id, feature and geometry variables being added
65 // since the buffer is not evaluated per-feature
66 button->init( static_cast<int>( key ), mSymbol->dataDefinedProperties(), QgsSymbol::propertyDefinitions(), nullptr );
67 connect( button, &QgsPropertyOverrideButton::changed, this, [=]() {
68 emit widgetChanged();
69 } );
70
72}
73
74QgsExpressionContext QgsExtentBufferWidget::createExpressionContext() const
75{
76 if ( QgsExpressionContext *lExpressionContext = mContext.expressionContext() )
77 return *lExpressionContext;
78
79 QgsExpressionContext expContext;
80
81 if ( mContext.mapCanvas() )
82 {
83 expContext = mContext.mapCanvas()->createExpressionContext();
84 }
85 else
86 {
91 }
92
93 if ( mLayer )
94 expContext << QgsExpressionContextUtils::layerScope( mLayer );
95
96 expContext.setOriginalValueVariable( mExtentBufferSpinBox->value() );
98
99 return expContext;
100}
101
103{
104 return mExtentBufferSpinBox->value();
105}
106
108{
109 return mExtentBufferDDButton->toProperty();
110}
111
112
114
116 : QDialog( parent )
117{
118 QVBoxLayout *vLayout = new QVBoxLayout();
119 mWidget = new QgsExtentBufferWidget( symbol, layer );
120 vLayout->addWidget( mWidget );
121
122 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
123 connect( bbox, &QDialogButtonBox::accepted, this, &QgsExtentBufferDialog::accept );
124 connect( bbox, &QDialogButtonBox::rejected, this, &QgsExtentBufferDialog::reject );
125 connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsExtentBufferDialog::showHelp );
126
127 vLayout->addWidget( bbox );
128 setLayout( vLayout );
129
130 setWindowTitle( tr( "Extent Buffer" ) );
131}
132
134{
135 if ( !mWidget )
136 return 0;
137
138 return mWidget->extentBuffer();
139}
140
142{
143 return mExtentBufferUnitSelectionWidget->unit();
144}
145
147{
148 if ( !mWidget )
150
151 return mWidget->sizeUnit();
152}
153
155{
156 if ( !mWidget )
157 return QgsProperty();
158
159 return mWidget->dataDefinedProperty();
160}
161
163{
164 return mWidget;
165}
166
168{
169 mWidget->setContext( context );
170}
171
172
173void QgsExtentBufferDialog::showHelp()
174{
175 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#extent-buffer" ) );
176}
RenderUnit
Rendering size units.
Definition qgis.h:4910
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which widget is shown, e.g., the associated map canvas and expression contexts.
QgsExtentBufferDialog(QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor for QgsExtentBufferDialog.
QgsProperty dataDefinedProperty() const
Returns the extent buffer value currently set in the widget.
QgsExtentBufferWidget * widget() const
Returns the data defined property currently set in the widget.
double extentBuffer() const
Returns the extent buffer value currently set in the widget.
Qgis::RenderUnit sizeUnit() const
Returns the extent buffer unit currently set in the widget.
A widget which allows the user to modify the rendering order of extent buffers.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which widget is shown, e.g., the associated map canvas and expression contexts.
QgsSymbolWidgetContext context() const
Returns the context in which the widget is shown, e.g., the associated map canvas and expression cont...
double extentBuffer() const
Returns the extent buffer value currently set in the widget.
QgsProperty dataDefinedProperty() const
Returns the data defined property currently set in the widget.
QgsExtentBufferWidget(QgsSymbol *symbol, QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor for QgsExtentBufferWidget.
Qgis::RenderUnit sizeUnit() const
Returns the extent buffer unit currently set in the widget.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
The QgsMapSettings class contains configuration for rendering of the map.
Base class for any widget that can be shown as a inline panel.
void widgetChanged()
Emitted when the widget state changes.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A button for controlling property overrides which may apply to a widget.
void changed()
Emitted when property definition changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
A store for object properties.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Property
Data definable properties.
Definition qgssymbol.h:270
@ ExtentBuffer
Extent buffer.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:788
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
Qgis::RenderUnit extentBufferSizeUnit() const
Returns the units for the buffer size.
Definition qgssymbol.h:897
double extentBuffer() const
Returns the symbol's extent buffer.
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
Represents a vector layer which manages a vector based data sets.