QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
20#include "qgshelp.h"
21#include "qgsmapcanvas.h"
22#include "qgspanelwidget.h"
23#include "qgsproject.h"
24#include "qgssymbol.h"
26#include "qgsunittypes.h"
27#include "qgsvectorlayer.h"
28
29#include <qdialogbuttonbox.h>
30
31#include "moc_qgsextentbufferdialog.cpp"
32
34 : QgsPanelWidget( parent ), mSymbol( symbol ), mLayer( layer )
35{
36 setupUi( this );
37
38 mExtentBufferSpinBox->setValue( mSymbol->extentBuffer() );
39
40 mExtentBufferUnitSelectionWidget->setShowMapScaleButton( false );
42 mExtentBufferUnitSelectionWidget->setUnit( mSymbol->extentBufferSizeUnit() );
43
44 connect( mExtentBufferSpinBox, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, [this]() {
45 emit widgetChanged();
46 } );
47
48 connect( mExtentBufferUnitSelectionWidget, &QgsUnitSelectionWidget::changed, this, [this]() {
49 emit widgetChanged();
50 } );
51
52 registerDataDefinedButton( mExtentBufferDDButton, QgsSymbol::Property::ExtentBuffer );
53}
54
56{
57 return mContext;
58}
59
64
65void QgsExtentBufferWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
66{
67 // pass in nullptr to avoid id, feature and geometry variables being added
68 // since the buffer is not evaluated per-feature
69 button->init( static_cast<int>( key ), mSymbol->dataDefinedProperties(), QgsSymbol::propertyDefinitions(), nullptr );
70 connect( button, &QgsPropertyOverrideButton::changed, this, [this]() {
71 emit widgetChanged();
72 } );
73
75}
76
78{
79 if ( QgsExpressionContext *lExpressionContext = mContext.expressionContext() )
80 return *lExpressionContext;
81
82 QgsExpressionContext expContext;
83
84 if ( mContext.mapCanvas() )
85 {
86 expContext = mContext.mapCanvas()->createExpressionContext();
87 }
88 else
89 {
94 }
95
96 if ( mLayer )
97 expContext << QgsExpressionContextUtils::layerScope( mLayer );
98
99 expContext.setOriginalValueVariable( mExtentBufferSpinBox->value() );
101
102 return expContext;
103}
104
106{
107 return mExtentBufferSpinBox->value();
108}
109
111{
112 return mExtentBufferDDButton->toProperty();
113}
114
115
117
119 : QDialog( parent )
120{
121 QVBoxLayout *vLayout = new QVBoxLayout();
122 mWidget = new QgsExtentBufferWidget( symbol, layer );
123 vLayout->addWidget( mWidget );
124
125 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
126 connect( bbox, &QDialogButtonBox::accepted, this, &QgsExtentBufferDialog::accept );
127 connect( bbox, &QDialogButtonBox::rejected, this, &QgsExtentBufferDialog::reject );
128 connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsExtentBufferDialog::showHelp );
129
130 vLayout->addWidget( bbox );
131 setLayout( vLayout );
132
133 setWindowTitle( tr( "Extent Buffer" ) );
134}
135
137{
138 if ( !mWidget )
139 return 0;
140
141 return mWidget->extentBuffer();
142}
143
145{
146 return mExtentBufferUnitSelectionWidget->unit();
147}
148
150{
151 if ( !mWidget )
153
154 return mWidget->sizeUnit();
155}
156
158{
159 if ( !mWidget )
160 return QgsProperty();
161
162 return mWidget->dataDefinedProperty();
163}
164
166{
167 return mWidget;
168}
169
171{
172 mWidget->setContext( context );
173}
174
175
176void QgsExtentBufferDialog::showHelp()
177{
178 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#extent-buffer" ) );
179}
RenderUnit
Rendering size units.
Definition qgis.h:5183
@ 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
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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:38
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.
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,...
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Property
Data definable properties.
Definition qgssymbol.h:270
@ ExtentBuffer
Extent buffer.
Definition qgssymbol.h:272
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:814
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
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 dataset.