QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
31 #include <QMessageBox>
32 #include <QInputDialog>
40 contextMenu =
new QMenu( tr(
"Renderer Options" ),
this );
44 mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
46 mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
51 connect(
mCopySymbolAction, &QAction::triggered,
this, &QgsRendererWidget::copySymbol );
71 connect(
contextMenu, &QMenu::aboutToShow,
this, [ = ]
86 if ( symbolList.isEmpty() )
103 QColor currentColor = firstSymbol->
color();
116 symbol->setColor( color );
126 if ( color.isValid() )
131 symbol->setColor( color );
141 if ( symbolList.isEmpty() )
147 const auto constSymbolList = symbolList;
148 for (
QgsSymbol *symbol : constSymbolList )
152 firstSymbol = symbol;
160 double oldOpacity = firstSymbol->
opacity() * 100;
161 double opacity = QInputDialog::getDouble(
this, tr(
"Opacity" ), tr(
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
164 const auto constSymbolList = symbolList;
165 for (
QgsSymbol *symbol : constSymbolList )
168 symbol->setOpacity( opacity / 100.0 );
177 if ( symbolList.isEmpty() )
183 const auto constSymbolList = symbolList;
184 for (
QgsSymbol *symbol : constSymbolList )
188 firstSymbol = symbol;
197 QString item = QInputDialog::getItem(
this, tr(
"Symbol unit" ), tr(
"Select symbol unit" ), QStringList() << tr(
"Millimeter" ) << tr(
"Map unit" ), currentUnit,
false, &ok );
202 const auto constSymbolList = symbolList;
203 for (
QgsSymbol *symbol : constSymbolList )
206 symbol->setOutputUnit( unit );
215 if ( symbolList.isEmpty() )
224 if ( QDialog::Accepted == dlg.exec() )
226 if ( !dlg.mDDBtn->isActive() )
228 const auto constSymbolList = symbolList;
229 for (
QgsSymbol *symbol : constSymbolList )
245 if ( symbolList.isEmpty() )
253 if ( QDialog::Accepted == dlg.exec() )
255 if ( !dlg.mDDBtn->isActive() )
257 const auto constSymbolList = symbolList;
258 for (
QgsSymbol *symbol : constSymbolList )
274 if ( symbolList.isEmpty() )
282 if ( QDialog::Accepted == dlg.exec() )
284 if ( !dlg.mDDBtn->isActive() )
286 const auto constSymbolList = symbolList;
287 for (
QgsSymbol *symbol : constSymbolList )
305 void QgsRendererWidget::copySymbol()
308 if ( symbolList.isEmpty() )
368 if ( !ddSize || !ddSize.
isActive() )
370 QMessageBox::warning(
this, tr(
"Data-defined Size Legend" ), tr(
"Data-defined size is not enabled!" ) );
374 QgsDataDefinedSizeLegendWidget *panel =
new QgsDataDefinedSizeLegendWidget( ddsLegend, ddSize, symbol->
clone(),
mContext.
mapCanvas() );
385 : mSymbolList( symbolList )
389 setWindowFlags( Qt::WindowStaysOnTopHint );
390 mLabel->setText( label );
410 if (
auto *lMapCanvas = mContext.
mapCanvas() )
417 expContext << generator->createExpressionContextScope();
443 mDDBtn->registerExpressionContextGenerator(
this );
446 const auto constMSymbolList = mSymbolList;
447 for (
QgsSymbol *symbol : constMSymbolList )
451 initialSymbol = symbol;
454 mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
455 mSpinBox->setEnabled( !mDDBtn->isActive() );
458 QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
const
460 if ( mSymbolList.isEmpty() || !mSymbolList.back() )
464 QgsProperty dd = symbolDataDefined( mSymbolList.back() );
465 const auto constMSymbolList = mSymbolList;
469 if ( !it || !dd || !symbolDD || symbolDD != dd )
478 mSpinBox->setEnabled( !dd.
isActive() );
487 const auto constMSymbolList = mSymbolList;
489 setDataDefined( it, dd );
526 static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
529 void QgsRendererWidget::apply()
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isActive() const
Returns whether the property is currently active.
double value(const QgsSymbol *symbol) const override
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QColor color() const
Returns the symbol's color.
A store for object properties.
RenderUnit
Rendering size units.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
static QgsSymbol * symbolFromMimeData(const QMimeData *data)
Attempts to parse mime data as a symbol.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
void dataDefinedChanged()
const QgsVectorLayer * vectorLayer() const
Returns the vector layer associated with the widget.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
@ ScaleDiameter
Calculate scale by the diameter.
static QgsProject * instance()
Returns the QgsProject singleton instance.
@ RenderMillimeters
Millimeters.
Abstract interface for generating an expression context scope.
Abstract base class for all rendered symbols.
QgsProperty symbolDataDefined(const QgsSymbol *symbol) const override
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
double value(const QgsSymbol *symbol) const override
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
static QMimeData * symbolToMimeData(const QgsSymbol *symbol)
Creates new mime data from a symbol.
double value(const QgsSymbol *symbol) const override
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
qreal opacity() const
Returns the opacity for the symbol.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsDataDefinedValueDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer, const QString &label)
Constructor.
A line symbol type, for rendering LineString and MultiLineString geometries.
bool usingSymbolLevels() const
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
void init(int propertyKey)
Should be called in the constructor of child classes.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
A dialog which allows the user to modify the rendering order of symbol layers.
Represents a vector layer which manages a vector based data sets.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
The QgsMapSettings class contains configuration for rendering of the map.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
@ RenderMapUnits
Map units.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
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