33#include <QInputDialog>
41 contextMenu =
new QMenu( tr(
"Renderer Options" ),
this );
45 mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
47 mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
52 connect(
mCopySymbolAction, &QAction::triggered,
this, &QgsRendererWidget::copySymbol );
72 connect(
contextMenu, &QMenu::aboutToShow,
this, [ = ]
87 if ( symbolList.isEmpty() )
104 const QColor currentColor = firstSymbol->
color();
127 if ( color.isValid() )
132 symbol->setColor( color );
142 if ( symbolList.isEmpty() )
148 const auto constSymbolList = symbolList;
149 for (
QgsSymbol *symbol : constSymbolList )
153 firstSymbol = symbol;
161 const double oldOpacity = firstSymbol->
opacity() * 100;
162 const double opacity = QInputDialog::getDouble(
this, tr(
"Opacity" ), tr(
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
165 const auto constSymbolList = symbolList;
166 for (
QgsSymbol *symbol : constSymbolList )
169 symbol->setOpacity( opacity / 100.0 );
178 if ( symbolList.isEmpty() )
184 const auto constSymbolList = symbolList;
185 for (
QgsSymbol *symbol : constSymbolList )
189 firstSymbol = symbol;
198 const QString item = QInputDialog::getItem(
this, tr(
"Symbol unit" ), tr(
"Select symbol unit" ), QStringList() << tr(
"Millimeter" ) << tr(
"Map unit" ), currentUnit,
false, &ok );
203 const auto constSymbolList = symbolList;
204 for (
QgsSymbol *symbol : constSymbolList )
207 symbol->setOutputUnit( unit );
216 if ( symbolList.isEmpty() )
225 if ( QDialog::Accepted == dlg.exec() )
227 if ( !dlg.mDDBtn->isActive() )
229 const auto constSymbolList = symbolList;
230 for (
QgsSymbol *symbol : constSymbolList )
246 if ( symbolList.isEmpty() )
254 if ( QDialog::Accepted == dlg.exec() )
256 if ( !dlg.mDDBtn->isActive() )
258 const auto constSymbolList = symbolList;
259 for (
QgsSymbol *symbol : constSymbolList )
275 if ( symbolList.isEmpty() )
283 if ( QDialog::Accepted == dlg.exec() )
285 if ( !dlg.mDDBtn->isActive() )
287 const auto constSymbolList = symbolList;
288 for (
QgsSymbol *symbol : constSymbolList )
306void QgsRendererWidget::copySymbol()
309 if ( symbolList.isEmpty() )
375 if ( !ddSize || !ddSize.
isActive() )
377 QMessageBox::warning(
this, tr(
"Data-defined Size Legend" ), tr(
"Data-defined size is not enabled!" ) );
396 : mSymbolList( symbolList )
400 setWindowFlags( Qt::WindowStaysOnTopHint );
401 mLabel->setText( label );
421 if (
auto *lMapCanvas = mContext.
mapCanvas() )
428 expContext << generator->createExpressionContextScope();
454 mDDBtn->registerExpressionContextGenerator(
this );
457 const auto constMSymbolList = mSymbolList;
458 for (
QgsSymbol *symbol : constMSymbolList )
462 initialSymbol = symbol;
465 mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
466 mSpinBox->setEnabled( !mDDBtn->isActive() );
469QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
const
471 if ( mSymbolList.isEmpty() || !mSymbolList.back() )
475 const QgsProperty dd = symbolDataDefined( mSymbolList.back() );
476 const auto constMSymbolList = mSymbolList;
479 const QgsProperty symbolDD( symbolDataDefined( it ) );
480 if ( !it || !dd || !symbolDD || symbolDD != dd )
489 mSpinBox->setEnabled( !dd.
isActive() );
498 const auto constMSymbolList = mSymbolList;
500 setDataDefined( it, dd );
508 if ( !symbolList.isEmpty() && symbolList.at( 0 ) &&
vectorLayer() )
511 mDDBtn->setSymbol( mAssistantSymbol );
570 return static_cast<const QgsLineSymbol *
>( symbol )->width();
575 static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
578void QgsRendererWidget::apply()
@ ScaleDiameter
Calculate scale by the diameter.
RenderUnit
Rendering size units.
@ Millimeters
Millimeters.
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
QgsDataDefinedRotationDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
double value(const QgsSymbol *symbol) const override
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
double value(const QgsSymbol *symbol) const override
QgsDataDefinedSizeDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Utility classes for "en masse" size definition.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void dataDefinedChanged()
QgsDataDefinedValueDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer, const QString &label)
Constructor.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
void init(int propertyKey)
Should be called in the constructor of child classes.
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
double value(const QgsSymbol *symbol) const override
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
QgsDataDefinedWidthDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
Abstract interface for generating an expression context scope.
Single scope for storing variables and functions for use within a QgsExpressionContext.
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 appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
bool usingSymbolLevels() const
A line symbol type, for rendering LineString and MultiLineString geometries.
void setWidth(double width) const
Sets the width for the whole line symbol.
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
The QgsMapSettings class contains configuration for rendering of the map.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setAngle(double symbolAngle) const
Sets the angle for the whole symbol.
void setSize(double size) const
Sets the size for the whole symbol.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A store for object properties.
bool isActive() const
Returns whether the property is currently active.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
@ StrokeWidth
Stroke width.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
A dialog which allows the user to modify the rendering order of symbol layers.
QgsLegendSymbolList symbolLevels() const
Returns the current legend symbols with rendering passes set, as defined in the widget.
bool usingLevels() const
Returns whether the level ordering is enabled.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Abstract base class for all rendered symbols.
qreal opacity() const
Returns the opacity for the symbol.
QColor color() const
Returns the symbol's color.
Qgis::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.