29 #include <QMessageBox> 30 #include <QInputDialog> 37 contextMenu =
new QMenu( tr(
"Renderer Options" ),
this );
40 mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
42 mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
68 if ( symbolList.isEmpty() )
74 const auto constSymbolList = symbolList;
75 for (
QgsSymbol *symbol : constSymbolList )
87 if ( color.isValid() )
89 const auto constSymbolList = symbolList;
90 for (
QgsSymbol *symbol : constSymbolList )
93 symbol->setColor( color );
102 if ( symbolList.isEmpty() )
108 const auto constSymbolList = symbolList;
109 for (
QgsSymbol *symbol : constSymbolList )
113 firstSymbol = symbol;
121 double oldOpacity = firstSymbol->
opacity() * 100;
122 double opacity = QInputDialog::getDouble(
this, tr(
"Opacity" ), tr(
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
125 const auto constSymbolList = symbolList;
126 for (
QgsSymbol *symbol : constSymbolList )
129 symbol->setOpacity( opacity / 100.0 );
138 if ( symbolList.isEmpty() )
144 const auto constSymbolList = symbolList;
145 for (
QgsSymbol *symbol : constSymbolList )
149 firstSymbol = symbol;
158 QString item = QInputDialog::getItem(
this, tr(
"Symbol unit" ), tr(
"Select symbol unit" ), QStringList() << tr(
"Millimeter" ) << tr(
"Map unit" ), currentUnit,
false, &ok );
163 const auto constSymbolList = symbolList;
164 for (
QgsSymbol *symbol : constSymbolList )
167 symbol->setOutputUnit( unit );
176 if ( symbolList.isEmpty() )
185 if ( QDialog::Accepted == dlg.exec() )
187 if ( !dlg.mDDBtn->isActive() )
189 const auto constSymbolList = symbolList;
190 for (
QgsSymbol *symbol : constSymbolList )
196 static_cast<QgsLineSymbol *>( symbol )->setWidth( dlg.mSpinBox->
value() );
206 if ( symbolList.isEmpty() )
214 if ( QDialog::Accepted == dlg.exec() )
216 if ( !dlg.mDDBtn->isActive() )
218 const auto constSymbolList = symbolList;
219 for (
QgsSymbol *symbol : constSymbolList )
225 static_cast<QgsMarkerSymbol *>( symbol )->setSize( dlg.mSpinBox->
value() );
235 if ( symbolList.isEmpty() )
243 if ( QDialog::Accepted == dlg.exec() )
245 if ( !dlg.mDDBtn->isActive() )
247 const auto constSymbolList = symbolList;
248 for (
QgsSymbol *symbol : constSymbolList )
254 static_cast<QgsMarkerSymbol *>( symbol )->setAngle( dlg.mSpinBox->
value() );
299 if ( !ddSize || !ddSize.
isActive() )
301 QMessageBox::warning(
this, tr(
"Data-defined Size Legend" ), tr(
"Data-defined size is not enabled!" ) );
316 : mSymbolList( symbolList )
320 setWindowFlags( Qt::WindowStaysOnTopHint );
321 mLabel->setText( label );
369 mDDBtn->registerExpressionContextGenerator(
this );
372 const auto constMSymbolList = mSymbolList;
373 for (
QgsSymbol *symbol : constMSymbolList )
377 initialSymbol = symbol;
380 mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
381 mSpinBox->setEnabled( !mDDBtn->isActive() );
384 QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
const 386 if ( mSymbolList.isEmpty() || !mSymbolList.back() )
390 QgsProperty dd = symbolDataDefined( mSymbolList.back() );
391 const auto constMSymbolList = mSymbolList;
395 if ( !it || !dd || !symbolDD || symbolDD != dd )
404 mSpinBox->setEnabled( !dd.isActive() );
409 ( symbolDD && symbolDD.
isActive() && !dd.isActive() )
413 const auto constMSymbolList = mSymbolList;
415 setDataDefined( it, dd );
452 static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
455 void QgsRendererWidget::apply()
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), bool allowOpacity=false)
Returns a color selection from a color dialog.
Calculate scale by the diameter.
double value(const QgsSymbol *symbol) const override
Abstract base class for all rendered symbols.
double value(const QgsSymbol *symbol) const override
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
A marker symbol type, for rendering Point and MultiPoint geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
The QgsMapSettings class contains configuration for rendering of the map.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QColor color() const
Returns the symbol's color.
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
A dialog which allows the user to modify the rendering order of symbol layers.
double value(const QgsSymbol *symbol) const override
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
void dataDefinedChanged()
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
static QgsExpressionContextScope * atlasScope(QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
bool usingSymbolLevels() const
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
void init(int propertyKey)
Should be called in the constructor of child classes.
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
QgsDataDefinedValueDialog(const QList< QgsSymbol *> &symbolList, QgsVectorLayer *layer, const QString &label)
Constructor.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
qreal opacity() const
Returns the opacity for the symbol.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Represents a vector layer which manages a vector based data sets.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend...
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
bool isActive() const
Returns whether the property is currently active.
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
RenderUnit
Rendering size units.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...