30 #include <QMessageBox> 31 #include <QInputDialog> 39 contextMenu =
new QMenu( tr(
"Renderer Options" ),
this );
43 mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
45 mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
50 connect(
mCopySymbolAction, &QAction::triggered,
this, &QgsRendererWidget::copySymbol );
70 connect(
contextMenu, &QMenu::aboutToShow,
this, [ = ]
85 if ( symbolList.isEmpty() )
102 QColor currentColor = firstSymbol->
color();
115 symbol->setColor( color );
125 if ( color.isValid() )
130 symbol->setColor( color );
140 if ( symbolList.isEmpty() )
146 const auto constSymbolList = symbolList;
147 for (
QgsSymbol *symbol : constSymbolList )
151 firstSymbol = symbol;
159 double oldOpacity = firstSymbol->
opacity() * 100;
160 double opacity = QInputDialog::getDouble(
this, tr(
"Opacity" ), tr(
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
163 const auto constSymbolList = symbolList;
164 for (
QgsSymbol *symbol : constSymbolList )
167 symbol->setOpacity( opacity / 100.0 );
176 if ( symbolList.isEmpty() )
182 const auto constSymbolList = symbolList;
183 for (
QgsSymbol *symbol : constSymbolList )
187 firstSymbol = symbol;
196 QString item = QInputDialog::getItem(
this, tr(
"Symbol unit" ), tr(
"Select symbol unit" ), QStringList() << tr(
"Millimeter" ) << tr(
"Map unit" ), currentUnit,
false, &ok );
201 const auto constSymbolList = symbolList;
202 for (
QgsSymbol *symbol : constSymbolList )
205 symbol->setOutputUnit( unit );
214 if ( symbolList.isEmpty() )
223 if ( QDialog::Accepted == dlg.exec() )
225 if ( !dlg.mDDBtn->isActive() )
227 const auto constSymbolList = symbolList;
228 for (
QgsSymbol *symbol : constSymbolList )
234 static_cast<QgsLineSymbol *>( symbol )->setWidth( dlg.mSpinBox->
value() );
244 if ( symbolList.isEmpty() )
252 if ( QDialog::Accepted == dlg.exec() )
254 if ( !dlg.mDDBtn->isActive() )
256 const auto constSymbolList = symbolList;
257 for (
QgsSymbol *symbol : constSymbolList )
263 static_cast<QgsMarkerSymbol *>( symbol )->setSize( dlg.mSpinBox->
value() );
273 if ( symbolList.isEmpty() )
281 if ( QDialog::Accepted == dlg.exec() )
283 if ( !dlg.mDDBtn->isActive() )
285 const auto constSymbolList = symbolList;
286 for (
QgsSymbol *symbol : constSymbolList )
292 static_cast<QgsMarkerSymbol *>( symbol )->setAngle( dlg.mSpinBox->
value() );
304 void QgsRendererWidget::copySymbol()
307 if ( symbolList.isEmpty() )
354 if ( !ddSize || !ddSize.
isActive() )
356 QMessageBox::warning(
this, tr(
"Data-defined Size Legend" ), tr(
"Data-defined size is not enabled!" ) );
360 QgsDataDefinedSizeLegendWidget *panel =
new QgsDataDefinedSizeLegendWidget( ddsLegend, ddSize, symbol->
clone(),
mContext.
mapCanvas() );
371 : mSymbolList( symbolList )
375 setWindowFlags( Qt::WindowStaysOnTopHint );
376 mLabel->setText( label );
424 mDDBtn->registerExpressionContextGenerator(
this );
427 const auto constMSymbolList = mSymbolList;
428 for (
QgsSymbol *symbol : constMSymbolList )
432 initialSymbol = symbol;
435 mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
436 mSpinBox->setEnabled( !mDDBtn->isActive() );
439 QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
const 441 if ( mSymbolList.isEmpty() || !mSymbolList.back() )
445 QgsProperty dd = symbolDataDefined( mSymbolList.back() );
446 const auto constMSymbolList = mSymbolList;
450 if ( !it || !dd || !symbolDD || symbolDD != dd )
459 mSpinBox->setEnabled( !dd.isActive() );
464 ( symbolDD && symbolDD.
isActive() && !dd.isActive() )
468 const auto constMSymbolList = mSymbolList;
470 setDataDefined( it, dd );
507 static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
510 void QgsRendererWidget::apply()
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
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
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
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...
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
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.
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...