33#include <QInputDialog>
38#include "moc_qgsrendererwidget.cpp"
40using namespace Qt::StringLiterals;
46 contextMenu =
new QMenu( tr(
"Renderer Options" ),
this );
50 mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
52 mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
57 connect(
mCopySymbolAction, &QAction::triggered,
this, &QgsRendererWidget::copySymbol );
77 connect(
contextMenu, &QMenu::aboutToShow,
this, [
this] {
91 if ( symbolList.isEmpty() )
101 firstSymbol = symbol;
108 const QColor currentColor = firstSymbol->
color();
120 symbol->setColor( color );
130 if ( color.isValid() )
135 symbol->setColor( color );
145 if ( symbolList.isEmpty() )
151 const auto constSymbolList = symbolList;
152 for (
QgsSymbol *symbol : constSymbolList )
156 firstSymbol = symbol;
164 const double oldOpacity = firstSymbol->
opacity() * 100;
165 const double opacity = QInputDialog::getDouble(
this, tr(
"Opacity" ), tr(
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
168 const auto constSymbolList = symbolList;
169 for (
QgsSymbol *symbol : constSymbolList )
172 symbol->setOpacity( opacity / 100.0 );
181 if ( symbolList.isEmpty() )
187 const auto constSymbolList = symbolList;
188 for (
QgsSymbol *symbol : constSymbolList )
192 firstSymbol = symbol;
201 const QString item = QInputDialog::getItem(
this, tr(
"Symbol unit" ), tr(
"Select symbol unit" ), QStringList() << tr(
"Millimeter" ) << tr(
"Map unit" ), currentUnit,
false, &ok );
206 const auto constSymbolList = symbolList;
207 for (
QgsSymbol *symbol : constSymbolList )
210 symbol->setOutputUnit( unit );
219 if ( symbolList.isEmpty() )
228 if ( QDialog::Accepted == dlg.exec() )
230 if ( !dlg.mDDBtn->isActive() )
232 const auto constSymbolList = symbolList;
233 for (
QgsSymbol *symbol : constSymbolList )
249 if ( symbolList.isEmpty() )
257 if ( QDialog::Accepted == dlg.exec() )
259 if ( !dlg.mDDBtn->isActive() )
261 const auto constSymbolList = symbolList;
262 for (
QgsSymbol *symbol : constSymbolList )
278 if ( symbolList.isEmpty() )
286 if ( QDialog::Accepted == dlg.exec() )
288 if ( !dlg.mDDBtn->isActive() )
290 const auto constSymbolList = symbolList;
291 for (
QgsSymbol *symbol : constSymbolList )
308void QgsRendererWidget::copySymbol()
311 if ( symbolList.isEmpty() )
319void QgsRendererWidget::updateDataDefinedProperty()
321 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
384 if ( !ddSize || !ddSize.
isActive() )
386 QMessageBox::warning(
this, tr(
"Data-defined Size Legend" ), tr(
"Data-defined size is not enabled!" ) );
411 if (
auto *lExpressionContext =
mContext.expressionContext() )
412 return *lExpressionContext;
417 const auto constAdditionalExpressionContextScopes =
mContext.additionalExpressionContextScopes();
426 QStringList highlights;
431 highlights << u
"zoom_level"_s;
433 if ( expContext.
hasVariable( u
"vector_tile_zoom"_s ) )
435 highlights << u
"vector_tile_zoom"_s;
448 : mSymbolList( symbolList )
452 setWindowFlags( Qt::WindowStaysOnTopHint );
453 mLabel->setText( label );
470 if (
auto *lMapCanvas = mContext.
mapCanvas() )
472 expContext = lMapCanvas->createExpressionContext();
486 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
487 for (
const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
489 expContext.
appendScope(
new QgsExpressionContextScope( scope ) );
500 mDDBtn->registerExpressionContextGenerator(
this );
503 const auto constMSymbolList = mSymbolList;
504 for (
QgsSymbol *symbol : constMSymbolList )
508 initialSymbol = symbol;
511 mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
512 mSpinBox->setEnabled( !mDDBtn->isActive() );
515QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
const
517 if ( mSymbolList.isEmpty() || !mSymbolList.back() )
521 const QgsProperty dd = symbolDataDefined( mSymbolList.back() );
522 const auto constMSymbolList = mSymbolList;
525 const QgsProperty symbolDD( symbolDataDefined( it ) );
526 if ( !it || !dd || !symbolDD || symbolDD != dd )
535 mSpinBox->setEnabled( !dd.
isActive() );
545 const auto constMSymbolList = mSymbolList;
547 setDataDefined( it, dd );
555 if ( !symbolList.isEmpty() && symbolList.at( 0 ) &&
vectorLayer() )
558 mDDBtn->setSymbol( mAssistantSymbol );
617 return static_cast<const QgsLineSymbol *
>( symbol )->width();
622 static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
625void 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.
A dialog for configuring symbol-level data defined rotation.
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
A dialog for configuring symbol-level data defined size.
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.
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.
A dialog for configuring symbol-level data defined width.
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)
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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 setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
bool hasVariable(const QString &name) const
Check whether a variable is specified by any scope within 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.
Abstract base class for all 2D vector feature renderers.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Property
Data definable properties for renderers.
bool usingSymbolLevels() const
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the renderer.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
A marker symbol type, for rendering Point and MultiPoint geometries.
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.
A database of saved style entities, including symbols, color ramps, text formats and others.
static std::unique_ptr< 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,...
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 dataset.