QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgssymbolslistwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolslist.cpp
3  ---------------------
4  begin : June 2012
5  copyright : (C) 2012 by Arunmozhi
6  email : aruntheguy at gmail.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #include "qgssymbolslistwidget.h"
18 
19 #include "qgsstylemanagerdialog.h"
20 #include "qgsstylesavedialog.h"
22 #include "qgsvectorlayer.h"
24 #include "qgsauxiliarystorage.h"
25 #include <QMessageBox>
26 
27 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
28  : QWidget( parent )
29  , mSymbol( symbol )
30  , mStyle( style )
31  , mAdvancedMenu( menu )
32  , mLayer( layer )
33 {
34  setupUi( this );
35  spinAngle->setClearValue( 0 );
36 
37  mStyleItemsListWidget->setStyle( mStyle );
38  mStyleItemsListWidget->setEntityType( QgsStyle::SymbolEntity );
39  if ( mSymbol )
40  mStyleItemsListWidget->setSymbolType( mSymbol->type() );
41  mStyleItemsListWidget->setAdvancedMenu( menu );
42 
43  mClipFeaturesAction = new QAction( tr( "Clip Features to Canvas Extent" ), this );
44  mClipFeaturesAction->setCheckable( true );
45  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
46  mStandardizeRingsAction = new QAction( tr( "Force Right-Hand-Rule Orientation" ), this );
47  mStandardizeRingsAction->setCheckable( true );
48  connect( mStandardizeRingsAction, &QAction::toggled, this, &QgsSymbolsListWidget::forceRHRToggled );
49 
50 
51  // select correct page in stacked widget
52  QgsPropertyOverrideButton *opacityDDBtn = nullptr;
53  switch ( symbol->type() )
54  {
55  case QgsSymbol::Marker:
56  {
57  stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
58  stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
59  mSymbolColorButton = btnMarkerColor;
60  opacityDDBtn = mMarkerOpacityDDBtn;
61  mSymbolOpacityWidget = mMarkerOpacityWidget;
62  mSymbolUnitWidget = mMarkerUnitWidget;
63  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
64  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
65  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
67  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
69  break;
70  }
71 
72  case QgsSymbol::Line:
73  {
74  stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
75  stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
76  mSymbolColorButton = btnLineColor;
77  opacityDDBtn = mLineOpacityDDBtn;
78  mSymbolOpacityWidget = mLineOpacityWidget;
79  mSymbolUnitWidget = mLineUnitWidget;
80  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
81  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
83  break;
84  }
85 
86  case QgsSymbol::Fill:
87  {
88  stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
89  stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
90  mSymbolColorButton = btnFillColor;
91  opacityDDBtn = mFillOpacityDDBtn;
92  mSymbolOpacityWidget = mFillOpacityWidget;
93  mSymbolUnitWidget = mFillUnitWidget;
94  break;
95  }
96 
97  case QgsSymbol::Hybrid:
98  break;
99  }
100 
101  stackedWidget->setCurrentIndex( 0 );
102 
103  if ( mSymbol )
104  {
105  updateSymbolInfo();
106  }
107 
108  connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
111 
112  connect( mSymbolColorButton, &QgsColorButton::colorChanged, this, &QgsSymbolsListWidget::setSymbolColor );
113 
114  registerSymbolDataDefinedButton( opacityDDBtn, QgsSymbol::PropertyOpacity );
115 
116  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
117  updateAssistantSymbol();
118 
119  mSymbolColorButton->setAllowOpacity( true );
120  mSymbolColorButton->setColorDialogTitle( tr( "Select Color" ) );
121  mSymbolColorButton->setContext( QStringLiteral( "symbology" ) );
122 
123  connect( mSymbolOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
124 
125  connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::selectionChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );
126  connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbolsListWidget::saveSymbol );
127 }
128 
130 {
131  // This action was added to the menu by this widget, clean it up
132  // The menu can be passed in the constructor, so may live longer than this widget
133  mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
134  mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
135 }
136 
137 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
138 {
139  button->setProperty( "propertyKey", key );
140  button->registerExpressionContextGenerator( this );
141 
142  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
143 }
144 
145 void QgsSymbolsListWidget::createAuxiliaryField()
146 {
147  // try to create an auxiliary layer if not yet created
148  if ( !mLayer->auxiliaryLayer() )
149  {
150  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
151  dlg.exec();
152  }
153 
154  // return if still not exists
155  if ( !mLayer->auxiliaryLayer() )
156  return;
157 
158  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
159  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
161 
162  // create property in auxiliary storage if necessary
163  if ( !mLayer->auxiliaryLayer()->exists( def ) )
164  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
165 
166  // update property with join field name from auxiliary storage
167  QgsProperty property = button->toProperty();
168  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
169  property.setActive( true );
170  button->updateFieldLists();
171  button->setToProperty( property );
172 
173  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
174  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
175  switch ( key )
176  {
178  if ( markerSymbol )
179  markerSymbol->setDataDefinedAngle( button->toProperty() );
180  break;
181 
183  if ( markerSymbol )
184  {
185  markerSymbol->setDataDefinedSize( button->toProperty() );
186  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
187  }
188  break;
189 
191  if ( lineSymbol )
192  lineSymbol->setDataDefinedWidth( button->toProperty() );
193  break;
194 
195  default:
196  break;
197  }
198 
199  emit changed();
200 }
201 
202 void QgsSymbolsListWidget::createSymbolAuxiliaryField()
203 {
204  // try to create an auxiliary layer if not yet created
205  if ( !mLayer->auxiliaryLayer() )
206  {
207  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
208  dlg.exec();
209  }
210 
211  // return if still not exists
212  if ( !mLayer->auxiliaryLayer() )
213  return;
214 
215  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
216  QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
218 
219  // create property in auxiliary storage if necessary
220  if ( !mLayer->auxiliaryLayer()->exists( def ) )
221  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
222 
223  // update property with join field name from auxiliary storage
224  QgsProperty property = button->toProperty();
225  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
226  property.setActive( true );
227  button->updateFieldLists();
228  button->setToProperty( property );
229 
230  mSymbol->setDataDefinedProperty( key, button->toProperty() );
231 
232  emit changed();
233 }
234 
236 {
237  mContext = context;
238  const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
239  for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
240  {
241  unitWidget->setMapCanvas( mContext.mapCanvas() );
242  }
243 #if 0
244  Q_FOREACH ( QgsPropertyOverrideButton *ddButton, findChildren<QgsPropertyOverrideButton *>() )
245  {
246  if ( ddButton->assistant() )
247  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
248  }
249 #endif
250 }
251 
253 {
254  return mContext;
255 }
256 
257 void QgsSymbolsListWidget::forceRHRToggled( bool checked )
258 {
259  if ( !mSymbol )
260  return;
261 
262  mSymbol->setForceRHR( checked );
263  emit changed();
264 }
265 
266 void QgsSymbolsListWidget::saveSymbol()
267 {
268  if ( !mStyle )
269  return;
270 
271  QgsStyleSaveDialog saveDlg( this );
272  saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
273  if ( !saveDlg.exec() )
274  return;
275 
276  if ( saveDlg.name().isEmpty() )
277  return;
278 
279  // check if there is no symbol with same name
280  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
281  {
282  int res = QMessageBox::warning( this, tr( "Save Symbol" ),
283  tr( "Symbol with name '%1' already exists. Overwrite?" )
284  .arg( saveDlg.name() ),
285  QMessageBox::Yes | QMessageBox::No );
286  if ( res != QMessageBox::Yes )
287  {
288  return;
289  }
290  mStyle->removeSymbol( saveDlg.name() );
291  }
292 
293  QStringList symbolTags = saveDlg.tags().split( ',' );
294 
295  // add new symbol to style and re-populate the list
296  QgsSymbol *newSymbol = mSymbol->clone();
297  mStyle->addSymbol( saveDlg.name(), newSymbol );
298 
299  // make sure the symbol is stored
300  mStyle->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
301 }
302 
303 void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
304 {
305  if ( !mSymbol )
306  return;
307 
308  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
309  QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
310  mSymbol->setDataDefinedProperty( key, button->toProperty() );
311  emit changed();
312 }
313 
314 void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
315 {
316  button->init( key, mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
317  connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
318  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
319 
320  button->registerExpressionContextGenerator( this );
321 }
322 
324 {
325  if ( !mSymbol )
326  return;
327 
328  mSymbol->setClipFeaturesToExtent( checked );
329  emit changed();
330 }
331 
332 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
333 {
334  mSymbol->setColor( color );
335  emit changed();
336 }
337 
339 {
340  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
341  if ( markerSymbol->angle() == angle )
342  return;
343  markerSymbol->setAngle( angle );
344  emit changed();
345 }
346 
348 {
349  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
350  QgsProperty dd( mRotationDDBtn->toProperty() );
351 
352  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
353 
354  QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
355 
356  if ( // shall we remove datadefined expressions for layers ?
357  ( !symbolDD && !dd )
358  // shall we set the "en masse" expression for properties ?
359  || dd )
360  {
361  markerSymbol->setDataDefinedAngle( dd );
362  emit changed();
363  }
364 }
365 
367 {
368  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
369  if ( markerSymbol->size() == size )
370  return;
371  markerSymbol->setSize( size );
372  emit changed();
373 }
374 
376 {
377  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
378  QgsProperty dd( mSizeDDBtn->toProperty() );
379 
380  spinSize->setEnabled( !mSizeDDBtn->isActive() );
381 
382  QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
383 
384  if ( // shall we remove datadefined expressions for layers ?
385  ( !symbolDD && !dd )
386  // shall we set the "en masse" expression for properties ?
387  || dd )
388  {
389  markerSymbol->setDataDefinedSize( dd );
390  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
391  emit changed();
392  }
393 }
394 
396 {
397  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
398  if ( lineSymbol->width() == width )
399  return;
400  lineSymbol->setWidth( width );
401  emit changed();
402 }
403 
405 {
406  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
407  QgsProperty dd( mWidthDDBtn->toProperty() );
408 
409  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
410 
411  QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
412 
413  if ( // shall we remove datadefined expressions for layers ?
414  ( !symbolDD && !dd )
415  // shall we set the "en masse" expression for properties ?
416  || dd )
417  {
418  lineSymbol->setDataDefinedWidth( dd );
419  emit changed();
420  }
421 }
422 
423 void QgsSymbolsListWidget::updateAssistantSymbol()
424 {
425  mAssistantSymbol.reset( mSymbol->clone() );
426  if ( mSymbol->type() == QgsSymbol::Marker )
427  mSizeDDBtn->setSymbol( mAssistantSymbol );
428  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
429  mWidthDDBtn->setSymbol( mAssistantSymbol );
430 }
431 
432 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
433 {
434  if ( mSymbol )
435  {
436 
437  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
438  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
439 
440  emit changed();
441  }
442 }
443 
444 void QgsSymbolsListWidget::opacityChanged( double opacity )
445 {
446  if ( mSymbol )
447  {
448  mSymbol->setOpacity( opacity );
449  emit changed();
450  }
451 }
452 
453 void QgsSymbolsListWidget::updateSymbolColor()
454 {
455  mSymbolColorButton->blockSignals( true );
456  mSymbolColorButton->setColor( mSymbol->color() );
457  mSymbolColorButton->blockSignals( false );
458 }
459 
460 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
461 {
462  if ( auto *lExpressionContext = mContext.expressionContext() )
463  return QgsExpressionContext( *lExpressionContext );
464 
465  //otherwise create a default symbol context
466  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
467 
468  // additional scopes
469  const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
470  for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
471  {
472  expContext.appendScope( new QgsExpressionContextScope( scope ) );
473  }
474 
475  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
479  << QStringLiteral( "symbol_layer_count" ) << QStringLiteral( "symbol_layer_index" ) );
480 
481  return expContext;
482 }
483 
484 void QgsSymbolsListWidget::updateSymbolInfo()
485 {
486  updateSymbolColor();
487 
488  const auto overrideButtons {findChildren< QgsPropertyOverrideButton * >()};
489  for ( QgsPropertyOverrideButton *button : overrideButtons )
490  {
491  button->registerExpressionContextGenerator( this );
492  }
493 
494  if ( mSymbol->type() == QgsSymbol::Marker )
495  {
496  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
497  spinSize->setValue( markerSymbol->size() );
498  spinAngle->setValue( markerSymbol->angle() );
499 
500  if ( mLayer )
501  {
502  QgsProperty ddSize( markerSymbol->dataDefinedSize() );
503  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
504  spinSize->setEnabled( !mSizeDDBtn->isActive() );
505  QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
506  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
507  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
508  }
509  else
510  {
511  mSizeDDBtn->setEnabled( false );
512  mRotationDDBtn->setEnabled( false );
513  }
514  }
515  else if ( mSymbol->type() == QgsSymbol::Line )
516  {
517  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
518  spinWidth->setValue( lineSymbol->width() );
519 
520  if ( mLayer )
521  {
522  QgsProperty dd( lineSymbol->dataDefinedWidth() );
523  mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
524  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
525  }
526  else
527  {
528  mWidthDDBtn->setEnabled( false );
529  }
530  }
531 
532  mSymbolUnitWidget->blockSignals( true );
533  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
534  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
535  mSymbolUnitWidget->blockSignals( false );
536 
537  mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
538 
539  // Clean up previous advanced symbol actions
540  const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
541  for ( const auto &action : actionList )
542  {
543  if ( mClipFeaturesAction->text() == action->text() )
544  {
545  mStyleItemsListWidget->advancedMenu()->removeAction( action );
546  }
547  else if ( mStandardizeRingsAction->text() == action->text() )
548  {
549  mStyleItemsListWidget->advancedMenu()->removeAction( action );
550  }
551  }
552 
553  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
554  {
555  //add clip features option for line or fill symbols
556  mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
557  }
558  if ( mSymbol->type() == QgsSymbol::Fill )
559  {
560  mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
561  }
562 
563  mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
564 
565  whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
566  whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
567 }
568 
569 void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity )
570 {
571  // get new instance of symbol from style
572  std::unique_ptr< QgsSymbol > s( mStyle->symbol( name ) );
573  if ( !s )
574  return;
575 
576  // remove all symbol layers from original symbolgroupsCombo
577  while ( mSymbol->symbolLayerCount() )
578  mSymbol->deleteSymbolLayer( 0 );
579  // move all symbol layers to our symbol
580  while ( s->symbolLayerCount() )
581  {
582  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
583  mSymbol->appendSymbolLayer( sl );
584  }
585  mSymbol->setOpacity( s->opacity() );
586 
587  updateSymbolInfo();
588  emit changed();
589 }
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
void setContext(const QString &context)
Sets the context string for the color button.
void setColor(const QColor &color)
Sets the current color for the button.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1204
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
Definition: qgssymbol.cpp:2100
void setWidth(double width)
Sets the width for the whole line symbol.
Definition: qgssymbol.cpp:2060
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:2135
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:2171
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:1004
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1664
void setSize(double size)
Sets the size for the whole symbol.
Definition: qgssymbol.cpp:1711
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1925
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
Definition: qgssymbol.cpp:1735
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgssymbol.cpp:1611
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1832
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1869
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1598
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1635
A dialog to create a new auxiliary layer.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
void setOpacity(double opacity)
Sets the current opacity to show in the widget, where opacity ranges from 0.0 (transparent) to 1....
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition for a property.
Definition: qgsproperty.h:48
A button for controlling property overrides which may apply to a widget.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void updateFieldLists()
Updates list of fields.
void changed()
Emitted when property definition changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
int propertyKey() const
Returns the property key linked to the button.
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
A store for object properties.
Definition: qgsproperty.h:232
void setField(const QString &field)
Sets the field name the property references.
void selectionChanged(const QString &name, QgsStyle::StyleEntity type)
Emitted when the selected item is changed in the widget.
void saveEntity()
Emitted when the user has opted to save a new entity to the style database, by clicking the "Save" bu...
a dialog for setting properties of a newly saved style.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition: qgsstyle.cpp:236
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:270
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:179
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
Definition: qgsstyle.cpp:202
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
Definition: qgsstyle.cpp:178
QStringList symbolNames() const
Returns a list of names of symbols.
Definition: qgsstyle.cpp:286
Property
Data definable properties.
@ PropertyAngle
Symbol angle.
@ PropertySize
Symbol size.
@ PropertyStrokeWidth
Stroke width.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
Property
Data definable properties.
Definition: qgssymbol.h:116
@ PropertyOpacity
Opacity.
Definition: qgssymbol.h:117
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the symbol.
Definition: qgssymbol.cpp:806
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:328
@ ScaleDiameter
Calculate scale by the diameter.
Definition: qgssymbol.h:100
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
Definition: qgssymbol.cpp:254
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
Definition: qgssymbol.cpp:434
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:266
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
Definition: qgssymbol.cpp:304
SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:138
qreal opacity() const
Returns the opacity for the symbol.
Definition: qgssymbol.h:481
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
Definition: qgssymbol.h:522
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
Definition: qgssymbol.cpp:444
void setColor(const QColor &color)
Sets the color for the symbol.
Definition: qgssymbol.cpp:532
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition: qgssymbol.h:568
@ Line
Line symbol.
Definition: qgssymbol.h:89
@ Hybrid
Hybrid symbol.
Definition: qgssymbol.h:91
@ Fill
Fill symbol.
Definition: qgssymbol.h:90
@ Marker
Marker symbol.
Definition: qgssymbol.h:88
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition: qgssymbol.h:488
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol.
Definition: qgssymbol.cpp:337
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:199
QColor color() const
Returns the symbol's color.
Definition: qgssymbol.cpp:542
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Definition: qgssymbol.h:544
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition: qgssymbol.h:511
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition: qgssymbol.h:533
void setLineWidth(double width)
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setSymbolColor(const QColor &color)
void setMarkerAngle(double angle)
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer=nullptr)
Constructor for QgsSymbolsListWidget.
void clipFeaturesToggled(bool checked)
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
void setMarkerSize(double size)
A widget displaying a combobox allowing the user to choose between various display units,...
QgsMapUnitScale getMapUnitScale() const
Returns the map unit scale.
void setUnits(const QStringList &units, int mapUnitIdx)
Sets the units which the user can choose from in the combobox.
void setUnit(int unitIndex)
Sets the selected unit index.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale.
QgsUnitTypes::RenderUnit unit() const
Returns the current predefined selected unit (if applicable).
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:239
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:175
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
Represents a vector layer which manages a vector based data sets.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
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)
Definition: MathUtils.cpp:786
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:263