QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 )
38 , mSymbol( symbol )
39 , mLayer( layer )
40{
41 setupUi( this );
42
43 mExtentBufferSpinBox->setValue( mSymbol->extentBuffer() );
44
45 mExtentBufferUnitSelectionWidget->setShowMapScaleButton( false );
46 mExtentBufferUnitSelectionWidget->setUnits(
48 );
49 mExtentBufferUnitSelectionWidget->setUnit( mSymbol->extentBufferSizeUnit() );
50
51 connect( mExtentBufferSpinBox, static_cast<void ( QgsDoubleSpinBox::* )( double )>( &QgsDoubleSpinBox::valueChanged ), this, [this]() { emit widgetChanged(); } );
52
53 connect( mExtentBufferUnitSelectionWidget, &QgsUnitSelectionWidget::changed, this, [this]() { emit widgetChanged(); } );
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]() { emit widgetChanged(); } );
74
76}
77
79{
80 if ( QgsExpressionContext *lExpressionContext = mContext.expressionContext() )
81 return *lExpressionContext;
82
83 QgsExpressionContext expContext;
84
85 if ( mContext.mapCanvas() )
86 {
87 expContext = mContext.mapCanvas()->createExpressionContext();
88 }
89 else
90 {
91 expContext
96 }
97
98 if ( mLayer )
99 expContext << QgsExpressionContextUtils::layerScope( mLayer );
100
101 expContext.setOriginalValueVariable( mExtentBufferSpinBox->value() );
103
104 return expContext;
105}
106
108{
109 return mExtentBufferSpinBox->value();
110}
111
113{
114 return mExtentBufferDDButton->toProperty();
115}
116
117
119
121 : QDialog( parent )
122{
123 QVBoxLayout *vLayout = new QVBoxLayout();
124 mWidget = new QgsExtentBufferWidget( symbol, layer );
125 vLayout->addWidget( mWidget );
126
127 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
128 connect( bbox, &QDialogButtonBox::accepted, this, &QgsExtentBufferDialog::accept );
129 connect( bbox, &QDialogButtonBox::rejected, this, &QgsExtentBufferDialog::reject );
130 connect( bbox, &QDialogButtonBox::helpRequested, this, &QgsExtentBufferDialog::showHelp );
131
132 vLayout->addWidget( bbox );
133 setLayout( vLayout );
134
135 setWindowTitle( tr( "Extent Buffer" ) );
136}
137
139{
140 if ( !mWidget )
141 return 0;
142
143 return mWidget->extentBuffer();
144}
145
147{
148 return mExtentBufferUnitSelectionWidget->unit();
149}
150
152{
153 if ( !mWidget )
155
156 return mWidget->sizeUnit();
157}
158
160{
161 if ( !mWidget )
162 return QgsProperty();
163
164 return mWidget->dataDefinedProperty();
165}
166
168{
169 return mWidget;
170}
171
173{
174 mWidget->setContext( context );
175}
176
177
178void QgsExtentBufferDialog::showHelp()
179{
180 QgsHelp::openHelp( u"working_with_vector/vector_properties.html#extent-buffer"_s );
181}
RenderUnit
Rendering size units.
Definition qgis.h:5340
@ 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
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:227
Property
Data definable properties.
Definition qgssymbol.h:272
@ ExtentBuffer
Extent buffer.
Definition qgssymbol.h:274
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:832
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.