| 
    QGIS API Documentation
    3.26.3-Buenos Aires (65e4edfdad)
    
   | 
 
 
 
 
Go to the documentation of this file.
   33 #include <QMessageBox> 
   34 #include <QInputDialog> 
   42   contextMenu = 
new QMenu( tr( 
"Renderer Options" ), 
this );
 
   46   mCopyAction->setShortcut( QKeySequence( QKeySequence::Copy ) );
 
   48   mPasteAction->setShortcut( QKeySequence( QKeySequence::Paste ) );
 
   53   connect( 
mCopySymbolAction, &QAction::triggered, 
this, &QgsRendererWidget::copySymbol );
 
   73   connect( 
contextMenu, &QMenu::aboutToShow, 
this, [ = ]
 
   88   if ( symbolList.isEmpty() )
 
  105   const QColor currentColor = firstSymbol->
color();
 
  118           symbol->setColor( color );
 
  128     if ( color.isValid() )
 
  133           symbol->setColor( color );
 
  143   if ( symbolList.isEmpty() )
 
  149   const auto constSymbolList = symbolList;
 
  150   for ( 
QgsSymbol *symbol : constSymbolList )
 
  154       firstSymbol = symbol;
 
  162   const double oldOpacity = firstSymbol->
opacity() * 100; 
 
  163   const double opacity = QInputDialog::getDouble( 
this, tr( 
"Opacity" ), tr( 
"Change symbol opacity [%]" ), oldOpacity, 0.0, 100.0, 1, &ok );
 
  166     const auto constSymbolList = symbolList;
 
  167     for ( 
QgsSymbol *symbol : constSymbolList )
 
  170         symbol->setOpacity( opacity / 100.0 );
 
  179   if ( symbolList.isEmpty() )
 
  185   const auto constSymbolList = symbolList;
 
  186   for ( 
QgsSymbol *symbol : constSymbolList )
 
  190       firstSymbol = symbol;
 
  199   const QString item = QInputDialog::getItem( 
this, tr( 
"Symbol unit" ), tr( 
"Select symbol unit" ), QStringList() << tr( 
"Millimeter" ) << tr( 
"Map unit" ), currentUnit, 
false, &ok );
 
  204     const auto constSymbolList = symbolList;
 
  205     for ( 
QgsSymbol *symbol : constSymbolList )
 
  208         symbol->setOutputUnit( unit );
 
  217   if ( symbolList.isEmpty() )
 
  226   if ( QDialog::Accepted == dlg.exec() )
 
  228     if ( !dlg.mDDBtn->isActive() )
 
  230       const auto constSymbolList = symbolList;
 
  231       for ( 
QgsSymbol *symbol : constSymbolList )
 
  247   if ( symbolList.isEmpty() )
 
  255   if ( QDialog::Accepted == dlg.exec() )
 
  257     if ( !dlg.mDDBtn->isActive() )
 
  259       const auto constSymbolList = symbolList;
 
  260       for ( 
QgsSymbol *symbol : constSymbolList )
 
  276   if ( symbolList.isEmpty() )
 
  284   if ( QDialog::Accepted == dlg.exec() )
 
  286     if ( !dlg.mDDBtn->isActive() )
 
  288       const auto constSymbolList = symbolList;
 
  289       for ( 
QgsSymbol *symbol : constSymbolList )
 
  307 void QgsRendererWidget::copySymbol()
 
  310   if ( symbolList.isEmpty() )
 
  376   if ( !ddSize || !ddSize.
isActive() )
 
  378     QMessageBox::warning( 
this, tr( 
"Data-defined Size Legend" ), tr( 
"Data-defined size is not enabled!" ) );
 
  382   QgsDataDefinedSizeLegendWidget *panel = 
new QgsDataDefinedSizeLegendWidget( ddsLegend, ddSize, symbol->
clone(), 
mContext.
mapCanvas() );
 
  397   : mSymbolList( symbolList )
 
  401   setWindowFlags( Qt::WindowStaysOnTopHint );
 
  402   mLabel->setText( label );
 
  422   if ( 
auto *lMapCanvas = mContext.
mapCanvas() )
 
  429       expContext << generator->createExpressionContextScope();
 
  455   mDDBtn->registerExpressionContextGenerator( 
this );
 
  458   const auto constMSymbolList = mSymbolList;
 
  459   for ( 
QgsSymbol *symbol : constMSymbolList )
 
  463       initialSymbol = symbol;
 
  466   mSpinBox->setValue( initialSymbol ? value( initialSymbol ) : 0 );
 
  467   mSpinBox->setEnabled( !mDDBtn->isActive() );
 
  470 QgsProperty QgsDataDefinedValueDialog::symbolDataDefined()
 const 
  472   if ( mSymbolList.isEmpty() || !mSymbolList.back() )
 
  476   const QgsProperty dd = symbolDataDefined( mSymbolList.back() );
 
  477   const auto constMSymbolList = mSymbolList;
 
  480     const QgsProperty symbolDD( symbolDataDefined( it ) );
 
  481     if ( !it || !dd || !symbolDD || symbolDD != dd )
 
  490   mSpinBox->setEnabled( !dd.
isActive() );
 
  499     const auto constMSymbolList = mSymbolList;
 
  501       setDataDefined( it, dd );
 
  509   if ( !symbolList.isEmpty() && symbolList.at( 0 ) && 
vectorLayer() )
 
  512     mDDBtn->setSymbol( mAssistantSymbol );
 
  571   return static_cast<const QgsLineSymbol *
>( symbol )->width();
 
  576   static_cast<QgsLineSymbol *
>( symbol )->setDataDefinedWidth( dd );
 
  579 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.
 
QgsLegendSymbolList symbolLevels() const
Returns the current legend symbols with rendering passes set, as defined in the widget.
 
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
 
QgsDataDefinedWidthDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
 
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
 
QgsDataDefinedSizeDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
 
QgsDataDefinedRotationDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer)
 
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
 
static QgsProject * instance()
Returns the QgsProject singleton instance.
 
@ RenderMillimeters
Millimeters.
 
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
 
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.
 
@ ScaleDiameter
Calculate scale by the diameter.
 
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 ...
 
Utility classes for "en masse" size definition.
 
void setDataDefined(QgsSymbol *symbol, const QgsProperty &dd) override
 
A marker symbol type, for rendering Point and MultiPoint geometries.
 
bool usingLevels() const
Returns whether the level ordering is enabled.
 
QgsDataDefinedValueDialog(const QList< QgsSymbol * > &symbolList, QgsVectorLayer *layer, const QString &label)
Constructor.
 
@ PropertySize
Symbol size.
 
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.
 
@ PropertyStrokeWidth
Stroke width.
 
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...
 
@ PropertyAngle
Symbol angle.
 
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. The rendering itself is don...
 
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
 
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
 
@ 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