QGIS API Documentation 3.99.0-Master (d270888f95f)
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 <QString>
30#include <qdialogbuttonbox.h>
31
32#include "moc_qgsextentbufferdialog.cpp"
33
34using namespace Qt::StringLiterals;
35
37 : QgsPanelWidget( parent ), mSymbol( symbol ), mLayer( layer )
38{
39 setupUi( this );
40
41 mExtentBufferSpinBox->setValue( mSymbol->extentBuffer() );
42
43 mExtentBufferUnitSelectionWidget->setShowMapScaleButton( false );
45 mExtentBufferUnitSelectionWidget->setUnit( mSymbol->extentBufferSizeUnit() );
46
47 connect( mExtentBufferSpinBox, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, [this]() {
48 emit widgetChanged();
49 } );
50
51 connect( mExtentBufferUnitSelectionWidget, &QgsUnitSelectionWidget::changed, this, [this]() {
52 emit widgetChanged();
53 } );
54
55 registerDataDefinedButton( mExtentBufferDDButton, QgsSymbol::Property::ExtentBuffer );
56}
57
59{
60 return mContext;
61}
62
67
68void QgsExtentBufferWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
69{
70 // pass in nullptr to avoid id, feature and geometry variables being added
71 // since the buffer is not evaluated per-feature
72 button->init( static_cast<int>( key ), mSymbol->dataDefinedProperties(), QgsSymbol::propertyDefinitions(), nullptr );
73 connect( button, &QgsPropertyOverrideButton::changed, this, [this]() {
74 emit widgetChanged();
75 } );
76
78}
79
81{
82 if ( QgsExpressionContext *lExpressionContext = mContext.expressionContext() )
83 return *lExpressionContext;
84
85 QgsExpressionContext expContext;
86
87 if ( mContext.mapCanvas() )
88 {
89 expContext = mContext.mapCanvas()->createExpressionContext();
90 }
91 else
92 {
97 }
98
99 if ( mLayer )
100 expContext << QgsExpressionContextUtils::layerScope( mLayer );
101
102 expContext.setOriginalValueVariable( mExtentBufferSpinBox->value() );
104
105 return expContext;
106}
107
109{
110 return mExtentBufferSpinBox->value();
111}
112
114{
115 return mExtentBufferDDButton->toProperty();
116}
117
118
120
122 : QDialog( parent )
123{
124 QVBoxLayout *vLayout = new QVBoxLayout();
125 mWidget = new QgsExtentBufferWidget( symbol, layer );
126 vLayout->addWidget( mWidget );
127
128 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
129 connect( bbox, &QDialogButtonBox::accepted, this, &QgsExtentBufferDialog::accept );
130 connect( bbox, &QDialogButtonBox::rejected, this, &QgsExtentBufferDialog::reject );
131 connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsExtentBufferDialog::showHelp );
132
133 vLayout->addWidget( bbox );
134 setLayout( vLayout );
135
136 setWindowTitle( tr( "Extent Buffer" ) );
137}
138
140{
141 if ( !mWidget )
142 return 0;
143
144 return mWidget->extentBuffer();
145}
146
148{
149 return mExtentBufferUnitSelectionWidget->unit();
150}
151
153{
154 if ( !mWidget )
156
157 return mWidget->sizeUnit();
158}
159
161{
162 if ( !mWidget )
163 return QgsProperty();
164
165 return mWidget->dataDefinedProperty();
166}
167
169{
170 return mWidget;
171}
172
174{
175 mWidget->setContext( context );
176}
177
178
179void QgsExtentBufferDialog::showHelp()
180{
181 QgsHelp::openHelp( u"working_with_vector/vector_properties.html#extent-buffer"_s );
182}
RenderUnit
Rendering size units.
Definition qgis.h:5255
@ Millimeters
Millimeters.
Definition qgis.h:5256
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5260
@ MapUnits
Map units.
Definition qgis.h:5257
@ Pixels
Pixels.
Definition qgis.h:5258
@ Inches
Inches.
Definition qgis.h:5261
@ MetersInMapUnits
Meters value as Map units.
Definition qgis.h:5263
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:41
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.