QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsmarkersymbol.h"
26 #include "qgslinesymbol.h"
27 #include "qgsfillsymbol.h"
30 
31 #include <QMessageBox>
32 
33 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
34  : QWidget( parent )
35  , mSymbol( symbol )
36  , mStyle( style )
37  , mAdvancedMenu( menu )
38  , mLayer( layer )
39 {
40  setupUi( this );
41  spinAngle->setClearValue( 0 );
42 
43  mStyleItemsListWidget->setStyle( mStyle );
44  mStyleItemsListWidget->setEntityType( QgsStyle::SymbolEntity );
45  if ( mSymbol )
46  mStyleItemsListWidget->setSymbolType( mSymbol->type() );
47  mStyleItemsListWidget->setAdvancedMenu( menu );
48 
49  mClipFeaturesAction = new QAction( tr( "Clip Features to Canvas Extent" ), this );
50  mClipFeaturesAction->setCheckable( true );
51  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
52  mStandardizeRingsAction = new QAction( tr( "Force Right-Hand-Rule Orientation" ), this );
53  mStandardizeRingsAction->setCheckable( true );
54  connect( mStandardizeRingsAction, &QAction::toggled, this, &QgsSymbolsListWidget::forceRHRToggled );
55  mAnimationSettingsAction = new QAction( tr( "Animation Settingsā€¦" ), this );
56  connect( mAnimationSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showAnimationSettings );
57 
58  // select correct page in stacked widget
59  QgsPropertyOverrideButton *opacityDDBtn = nullptr;
60  switch ( symbol->type() )
61  {
63  {
64  stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
65  stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
66  mSymbolColorButton = btnMarkerColor;
67  opacityDDBtn = mMarkerOpacityDDBtn;
68  mSymbolOpacityWidget = mMarkerOpacityWidget;
69  mSymbolUnitWidget = mMarkerUnitWidget;
70  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
71  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
72  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
74  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
76  break;
77  }
78 
80  {
81  stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
82  stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
83  mSymbolColorButton = btnLineColor;
84  opacityDDBtn = mLineOpacityDDBtn;
85  mSymbolOpacityWidget = mLineOpacityWidget;
86  mSymbolUnitWidget = mLineUnitWidget;
87  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
88  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
90  break;
91  }
92 
94  {
95  stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
96  stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
97  mSymbolColorButton = btnFillColor;
98  opacityDDBtn = mFillOpacityDDBtn;
99  mSymbolOpacityWidget = mFillOpacityWidget;
100  mSymbolUnitWidget = mFillUnitWidget;
101  break;
102  }
103 
105  break;
106  }
107 
108  stackedWidget->setCurrentIndex( 0 );
109 
112 
113  if ( mSymbol )
114  {
115  updateSymbolInfo();
116  }
117 
118  connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
119  connect( mSymbolColorButton, &QgsColorButton::colorChanged, this, &QgsSymbolsListWidget::setSymbolColor );
120 
121  registerSymbolDataDefinedButton( opacityDDBtn, QgsSymbol::PropertyOpacity );
122 
123  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
124  updateAssistantSymbol();
125 
126  mSymbolColorButton->setAllowOpacity( true );
127  mSymbolColorButton->setColorDialogTitle( tr( "Select Color" ) );
128  mSymbolColorButton->setContext( QStringLiteral( "symbology" ) );
129 
130  connect( mSymbolOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
131 
132  connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::selectionChangedWithStylePath, this, &QgsSymbolsListWidget::setSymbolFromStyle );
133  connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbolsListWidget::saveSymbol );
134 }
135 
137 {
138  // This action was added to the menu by this widget, clean it up
139  // The menu can be passed in the constructor, so may live longer than this widget
140  mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
141  mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
142  mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
143 }
144 
145 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
146 {
147  button->setProperty( "propertyKey", key );
148  button->registerExpressionContextGenerator( this );
149 
150  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
151 }
152 
153 void QgsSymbolsListWidget::createAuxiliaryField()
154 {
155  // try to create an auxiliary layer if not yet created
156  if ( !mLayer->auxiliaryLayer() )
157  {
158  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
159  dlg.exec();
160  }
161 
162  // return if still not exists
163  if ( !mLayer->auxiliaryLayer() )
164  return;
165 
166  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
167  const QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
169 
170  // create property in auxiliary storage if necessary
171  if ( !mLayer->auxiliaryLayer()->exists( def ) )
172  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
173 
174  // update property with join field name from auxiliary storage
175  QgsProperty property = button->toProperty();
176  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
177  property.setActive( true );
178  button->updateFieldLists();
179  button->setToProperty( property );
180 
181  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
182  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
183  switch ( key )
184  {
186  if ( markerSymbol )
187  markerSymbol->setDataDefinedAngle( button->toProperty() );
188  break;
189 
191  if ( markerSymbol )
192  {
193  markerSymbol->setDataDefinedSize( button->toProperty() );
195  }
196  break;
197 
199  if ( lineSymbol )
200  lineSymbol->setDataDefinedWidth( button->toProperty() );
201  break;
202 
203  default:
204  break;
205  }
206 
207  emit changed();
208 }
209 
210 void QgsSymbolsListWidget::createSymbolAuxiliaryField()
211 {
212  // try to create an auxiliary layer if not yet created
213  if ( !mLayer->auxiliaryLayer() )
214  {
215  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
216  dlg.exec();
217  }
218 
219  // return if still not exists
220  if ( !mLayer->auxiliaryLayer() )
221  return;
222 
223  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
224  const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
226 
227  // create property in auxiliary storage if necessary
228  if ( !mLayer->auxiliaryLayer()->exists( def ) )
229  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
230 
231  // update property with join field name from auxiliary storage
232  QgsProperty property = button->toProperty();
233  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
234  property.setActive( true );
235  button->updateFieldLists();
236  button->setToProperty( property );
237 
238  mSymbol->setDataDefinedProperty( key, button->toProperty() );
239 
240  emit changed();
241 }
242 
244 {
245  mContext = context;
246  const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
247  for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
248  {
249  unitWidget->setMapCanvas( mContext.mapCanvas() );
250  }
251 }
252 
254 {
255  return mContext;
256 }
257 
258 void QgsSymbolsListWidget::forceRHRToggled( bool checked )
259 {
260  if ( !mSymbol )
261  return;
262 
263  mSymbol->setForceRHR( checked );
264  emit changed();
265 }
266 
267 void QgsSymbolsListWidget::showAnimationSettings()
268 {
270  if ( panel && panel->dockMode() )
271  {
273  widget->setPanelTitle( tr( "Animation Settings" ) );
274  widget->setAnimationSettings( mSymbol->animationSettings() );
275  connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
276  {
277  mSymbol->setAnimationSettings( widget->animationSettings() );
278  emit changed();
279  } );
280  panel->openPanel( widget );
281  return;
282  }
283 
285  d.setAnimationSettings( mSymbol->animationSettings() );
286  if ( d.exec() == QDialog::Accepted )
287  {
288  mSymbol->setAnimationSettings( d.animationSettings() );
289  emit changed();
290  }
291 }
292 
293 void QgsSymbolsListWidget::saveSymbol()
294 {
295  QgsStyleSaveDialog saveDlg( this );
296  saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
297  if ( !saveDlg.exec() )
298  return;
299 
300  if ( saveDlg.name().isEmpty() )
301  return;
302 
303  QgsStyle *style = saveDlg.destinationStyle();
304  if ( !style )
305  return;
306 
307  // check if there is no symbol with same name
308  if ( style->symbolNames().contains( saveDlg.name() ) )
309  {
310  const int res = QMessageBox::warning( this, tr( "Save Symbol" ),
311  tr( "Symbol with name '%1' already exists. Overwrite?" )
312  .arg( saveDlg.name() ),
313  QMessageBox::Yes | QMessageBox::No );
314  if ( res != QMessageBox::Yes )
315  {
316  return;
317  }
318  style->removeSymbol( saveDlg.name() );
319  }
320 
321  const QStringList symbolTags = saveDlg.tags().split( ',' );
322 
323  // add new symbol to style and re-populate the list
324  QgsSymbol *newSymbol = mSymbol->clone();
325  style->addSymbol( saveDlg.name(), newSymbol );
326 
327  // make sure the symbol is stored
328  style->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
329 }
330 
331 void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
332 {
333  if ( !mSymbol )
334  return;
335 
336  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
337  const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
338  mSymbol->setDataDefinedProperty( key, button->toProperty() );
339  emit changed();
340 }
341 
342 void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
343 {
344  button->init( key, mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
345  connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
346  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
347 
348  button->registerExpressionContextGenerator( this );
349 }
350 
352 {
353  if ( !mSymbol )
354  return;
355 
356  mSymbol->setClipFeaturesToExtent( checked );
357  emit changed();
358 }
359 
360 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
361 {
362  mSymbol->setColor( color );
363  emit changed();
364 }
365 
367 {
368  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
369  if ( markerSymbol->angle() == angle )
370  return;
371  markerSymbol->setAngle( angle );
372  emit changed();
373 }
374 
376 {
377  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
378  const QgsProperty dd( mRotationDDBtn->toProperty() );
379 
380  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
381 
382  const QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
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->setDataDefinedAngle( dd );
390  emit changed();
391  }
392 }
393 
395 {
396  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
397  if ( markerSymbol->size() == size )
398  return;
399  markerSymbol->setSize( size );
400  emit changed();
401 }
402 
404 {
405  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
406  const QgsProperty dd( mSizeDDBtn->toProperty() );
407 
408  spinSize->setEnabled( !mSizeDDBtn->isActive() );
409 
410  const QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
411 
412  if ( // shall we remove datadefined expressions for layers ?
413  ( !symbolDD && !dd )
414  // shall we set the "en masse" expression for properties ?
415  || dd )
416  {
417  markerSymbol->setDataDefinedSize( dd );
419  emit changed();
420  }
421 }
422 
424 {
425  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
426  if ( lineSymbol->width() == width )
427  return;
428  lineSymbol->setWidth( width );
429  emit changed();
430 }
431 
433 {
434  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
435  const QgsProperty dd( mWidthDDBtn->toProperty() );
436 
437  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
438 
439  const QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
440 
441  if ( // shall we remove datadefined expressions for layers ?
442  ( !symbolDD && !dd )
443  // shall we set the "en masse" expression for properties ?
444  || dd )
445  {
446  lineSymbol->setDataDefinedWidth( dd );
447  emit changed();
448  }
449 }
450 
451 void QgsSymbolsListWidget::updateAssistantSymbol()
452 {
453  mAssistantSymbol.reset( mSymbol->clone() );
454  if ( mSymbol->type() == Qgis::SymbolType::Marker )
455  mSizeDDBtn->setSymbol( mAssistantSymbol );
456  else if ( mSymbol->type() == Qgis::SymbolType::Line && mLayer )
457  mWidthDDBtn->setSymbol( mAssistantSymbol );
458 }
459 
460 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
461 {
462  if ( mSymbol )
463  {
464 
465  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
466  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
467 
468  emit changed();
469  }
470 }
471 
472 void QgsSymbolsListWidget::opacityChanged( double opacity )
473 {
474  if ( mSymbol )
475  {
476  mSymbol->setOpacity( opacity );
477  emit changed();
478  }
479 }
480 
481 void QgsSymbolsListWidget::updateSymbolColor()
482 {
483  mSymbolColorButton->blockSignals( true );
484  mSymbolColorButton->setColor( mSymbol->color() );
485  mSymbolColorButton->blockSignals( false );
486 }
487 
488 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
489 {
490  if ( auto *lExpressionContext = mContext.expressionContext() )
491  return QgsExpressionContext( *lExpressionContext );
492 
493  //otherwise create a default symbol context
494  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
495 
496  // additional scopes
497  const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
498  for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
499  {
500  expContext.appendScope( new QgsExpressionContextScope( scope ) );
501  }
502 
503  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
508  << QStringLiteral( "symbol_layer_count" ) << QStringLiteral( "symbol_layer_index" )
509  << QStringLiteral( "symbol_frame" ) );
510 
511  return expContext;
512 }
513 
514 void QgsSymbolsListWidget::updateSymbolInfo()
515 {
516  updateSymbolColor();
517 
518  const auto overrideButtons {findChildren< QgsPropertyOverrideButton * >()};
519  for ( QgsPropertyOverrideButton *button : overrideButtons )
520  {
521  button->registerExpressionContextGenerator( this );
522  }
523 
524  if ( mSymbol->type() == Qgis::SymbolType::Marker )
525  {
526  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
527  spinSize->setValue( markerSymbol->size() );
528  spinAngle->setValue( markerSymbol->angle() );
529 
530  if ( mLayer )
531  {
532  const QgsProperty ddSize( markerSymbol->dataDefinedSize() );
533  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
534  spinSize->setEnabled( !mSizeDDBtn->isActive() );
535  const QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
536  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
537  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
538  }
539  else
540  {
541  mSizeDDBtn->setEnabled( false );
542  mRotationDDBtn->setEnabled( false );
543  }
544  }
545  else if ( mSymbol->type() == Qgis::SymbolType::Line )
546  {
547  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
548  spinWidth->setValue( lineSymbol->width() );
549 
550  if ( mLayer )
551  {
552  const QgsProperty dd( lineSymbol->dataDefinedWidth() );
553  mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
554  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
555  }
556  else
557  {
558  mWidthDDBtn->setEnabled( false );
559  }
560  }
561 
562  mSymbolUnitWidget->blockSignals( true );
563  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
564  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
565  mSymbolUnitWidget->blockSignals( false );
566 
567  mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
568 
569  // Clean up previous advanced symbol actions
570  const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
571  for ( const auto &action : actionList )
572  {
573  if ( mClipFeaturesAction->text() == action->text() )
574  {
575  mStyleItemsListWidget->advancedMenu()->removeAction( action );
576  }
577  else if ( mStandardizeRingsAction->text() == action->text() )
578  {
579  mStyleItemsListWidget->advancedMenu()->removeAction( action );
580  }
581  else if ( mAnimationSettingsAction->text() == action->text() )
582  {
583  mStyleItemsListWidget->advancedMenu()->removeAction( action );
584  }
585  }
586 
587  if ( mSymbol->type() == Qgis::SymbolType::Line || mSymbol->type() == Qgis::SymbolType::Fill )
588  {
589  //add clip features option for line or fill symbols
590  mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
591  }
592  if ( mSymbol->type() == Qgis::SymbolType::Fill )
593  {
594  mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
595  }
596  mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
597 
598  mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
599 
600  whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
601  whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
602 }
603 
604 void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity, const QString &stylePath )
605 {
606  if ( name.isEmpty() )
607  return;
608 
609  QgsStyle *style = nullptr;
610 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
611  if ( mStyle != QgsStyle::defaultStyle() )
612  {
613  // get new instance of symbol from style
614  style = mStyle;
615  }
616  else
617  {
618  style = QgsProject::instance()->styleSettings()->styleAtPath( stylePath );
619  }
620 #else
621  ( void )stylePath;
622  style = mStyle;
623 #endif
624 
625  if ( !style )
626  return;
627 
628  // get new instance of symbol from style
629  std::unique_ptr< QgsSymbol > s( style->symbol( name ) );
630  if ( !s )
631  return;
632 
633  // remove all symbol layers from original symbolgroupsCombo
634  while ( mSymbol->symbolLayerCount() )
635  mSymbol->deleteSymbolLayer( 0 );
636  // move all symbol layers to our symbol
637  while ( s->symbolLayerCount() )
638  {
639  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
640  mSymbol->appendSymbolLayer( sl );
641  }
642  mSymbol->setOpacity( s->opacity() );
643  mSymbol->setFlags( s->flags() );
644 
645  updateSymbolInfo();
646  emit changed();
647 }
QgsSymbolWidgetContext::globalProjectAtlasMapLayerScopes
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
Definition: qgssymbolwidgetcontext.cpp:92
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsOpacityWidget::opacityChanged
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
QgsSymbolWidgetContext::mapCanvas
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Definition: qgssymbolwidgetcontext.cpp:54
QgsSymbol::color
QColor color() const
Returns the symbol's color.
Definition: qgssymbol.cpp:877
QgsSymbolsListWidget::setLineWidth
void setLineWidth(double width)
Definition: qgssymbolslistwidget.cpp:423
QgsUnitTypes::RenderInches
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
QgsStyleItemsListWidget::saveEntity
void saveEntity()
Emitted when the user has opted to save a new entity to the style database, by clicking the "Save" bu...
qgsstyleitemslistwidget.h
QgsMarkerSymbol::setDataDefinedAngle
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgsmarkersymbol.cpp:77
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
qgsprojectstylesettings.h
QgsOpacityWidget::setOpacity
void setOpacity(double opacity)
Sets the current opacity to show in the widget, where opacity ranges from 0.0 (transparent) to 1....
Definition: qgsopacitywidget.cpp:61
Qgis::SymbolType::Fill
@ Fill
Fill symbol.
QgsSymbolsListWidget::QgsSymbolsListWidget
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer=nullptr)
Constructor for QgsSymbolsListWidget.
Definition: qgssymbolslistwidget.cpp:33
Qgis::SymbolType::Line
@ Line
Line symbol.
QgsExpressionContext::EXPR_ORIGINAL_VALUE
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
Definition: qgsexpressioncontext.h:805
QgsMarkerSymbol::size
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
Definition: qgsmarkersymbol.cpp:197
QgsPropertyOverrideButton::changed
void changed()
Emitted when property definition changes.
QgsPanelWidget::findParentPanel
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
Definition: qgspanelwidget.cpp:54
qgsstylemanagerdialog.h
QgsExpressionContext::EXPR_CLUSTER_COLOR
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Definition: qgsexpressioncontext.h:827
QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
Definition: qgsexpressioncontext.h:821
QgsMarkerSymbol::dataDefinedSize
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgsmarkersymbol.cpp:343
QgsColorButton::setColor
void setColor(const QColor &color)
Sets the current color for the button.
Definition: qgscolorbutton.cpp:658
QgsLineSymbol::width
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
Definition: qgslinesymbol.cpp:96
QgsAuxiliaryLayer::exists
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
Definition: qgsauxiliarystorage.cpp:135
QgsUnitTypes::RenderPoints
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
Definition: qgsexpressioncontext.h:823
QgsSymbolWidgetContext
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Definition: qgssymbolwidgetcontext.h:35
QgsPanelWidget::openPanel
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
Definition: qgspanelwidget.cpp:84
QgsSymbolSelectorDialog::context
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
Definition: qgssymbolselectordialog.cpp:818
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsVectorLayer::auxiliaryLayer
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
Definition: qgsvectorlayer.cpp:5520
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
QgsPropertyOverrideButton::createAuxiliaryField
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
QgsPropertyOverrideButton::propertyKey
int propertyKey() const
Returns the property key linked to the button.
Definition: qgspropertyoverridebutton.h:123
QgsSymbolsListWidget::setMarkerSize
void setMarkerSize(double size)
Definition: qgssymbolslistwidget.cpp:394
QgsSymbol::mapUnitScale
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
Definition: qgssymbol.cpp:616
QgsExpressionContext::EXPR_GEOMETRY_PART_NUM
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
Definition: qgsexpressioncontext.h:813
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
qgssymbolanimationsettingswidget.h
QgsStyleItemsListWidget::selectionChangedWithStylePath
void selectionChangedWithStylePath(const QString &name, QgsStyle::StyleEntity type, const QString &stylePath)
Emitted when the selected item is changed in the widget.
QgsProject::styleSettings
const QgsProjectStyleSettings * styleSettings() const
Returns the project's style settings, which contains settings and properties relating to how a QgsPro...
Definition: qgsproject.cpp:3501
QgsMarkerSymbol::angle
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgsmarkersymbol.cpp:53
QgsSymbol::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition: qgssymbol.h:622
QgsSymbol::outputUnit
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:578
QgsExpressionContext::EXPR_SYMBOL_COLOR
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
Definition: qgsexpressioncontext.h:807
Qgis::ScaleMethod::ScaleDiameter
@ ScaleDiameter
Calculate scale by the diameter.
QgsPanelWidget::dockMode
bool dockMode()
Returns the dock mode state.
Definition: qgspanelwidget.h:93
qgsstylesavedialog.h
QgsSymbol::setOutputUnit
void setOutputUnit(QgsUnitTypes::RenderUnit unit) const
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:640
QgsStyle::symbol
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:291
QgsStyle::SymbolEntity
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
QgsSymbol::PropertyOpacity
@ PropertyOpacity
Opacity.
Definition: qgssymbol.h:131
QgsPropertyOverrideButton::setToProperty
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
Definition: qgspropertyoverridebutton.cpp:270
QgsMarkerSymbol::setDataDefinedSize
void setDataDefinedSize(const QgsProperty &property) const
Set data defined size for whole symbol (including all symbol layers).
Definition: qgsmarkersymbol.cpp:306
QgsPropertyOverrideButton
A button for controlling property overrides which may apply to a widget.
Definition: qgspropertyoverridebutton.h:50
QgsSymbolWidgetContext::setMapCanvas
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
Definition: qgssymbolwidgetcontext.cpp:49
QgsColorButton::colorChanged
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:145
qgsauxiliarystorage.h
QgsSymbolsListWidget::changed
void changed()
qgsnewauxiliarylayerdialog.h
QgsSymbolLayer::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Definition: qgssymbollayer.cpp:292
QgsSymbol::setOpacity
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition: qgssymbol.h:502
QgsSymbol::setClipFeaturesToExtent
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition: qgssymbol.h:541
QgsColorButton::setAllowOpacity
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
Definition: qgscolorbutton.cpp:805
QgsSymbol::opacity
qreal opacity() const
Returns the opacity for the symbol.
Definition: qgssymbol.h:495
QgsSymbol::setMapUnitScale
void setMapUnitScale(const QgsMapUnitScale &scale) const
Sets the map unit scale for the symbol.
Definition: qgssymbol.cpp:649
QgsSymbol::propertyDefinitions
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
Definition: qgssymbol.cpp:566
QgsSymbolLayer
Definition: qgssymbollayer.h:54
QgsStyle::addSymbol
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
Definition: qgsstyle.cpp:197
QgsSymbol::setAnimationSettings
void setAnimationSettings(const QgsSymbolAnimationSettings &settings)
Sets a the symbol animation settings.
Definition: qgssymbol.cpp:668
QgsSymbol::setDataDefinedProperty
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the symbol.
Definition: qgssymbol.cpp:1168
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsSymbol::appendSymbolLayer
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
Definition: qgssymbol.cpp:748
QgsProperty::setField
void setField(const QString &field)
Sets the field name the property references.
Definition: qgsproperty.cpp:349
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:2191
QgsSymbol::type
Qgis::SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:152
QgsPropertyOverrideButton::updateFieldLists
void updateFieldLists()
Updates list of fields.
Definition: qgspropertyoverridebutton.cpp:152
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsSymbolLayer::PropertySize
@ PropertySize
Symbol size.
Definition: qgssymbollayer.h:144
QgsSymbolsListWidget::setMarkerAngle
void setMarkerAngle(double angle)
Definition: qgssymbolslistwidget.cpp:366
QgsSymbolsListWidget::setSymbolColor
void setSymbolColor(const QColor &color)
Definition: qgssymbolslistwidget.cpp:360
QgsPanelWidget::widgetChanged
void widgetChanged()
Emitted when the widget state changes.
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
QgsPropertyOverrideButton::toProperty
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
Definition: qgspropertyoverridebutton.cpp:192
QgsMarkerSymbol::setAngle
void setAngle(double symbolAngle) const
Sets the angle for the whole symbol.
Definition: qgsmarkersymbol.cpp:40
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
qgssymbolslistwidget.h
QgsSymbolAnimationSettingsWidget::setAnimationSettings
void setAnimationSettings(const QgsSymbolAnimationSettings &settings)
Sets the animation settings to show in the widget.
Definition: qgssymbolanimationsettingswidget.cpp:41
QgsLineSymbol::dataDefinedWidth
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
Definition: qgslinesymbol.cpp:178
QgsSymbolsListWidget::~QgsSymbolsListWidget
~QgsSymbolsListWidget() override
Definition: qgssymbolslistwidget.cpp:136
QgsUnitSelectionWidget::changed
void changed()
QgsSymbolWidgetContext::expressionContext
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
Definition: qgssymbolwidgetcontext.cpp:77
QgsSymbolLayer::PropertyStrokeWidth
@ PropertyStrokeWidth
Stroke width.
Definition: qgssymbollayer.h:149
QgsMarkerSymbol::setScaleMethod
void setScaleMethod(Qgis::ScaleMethod scaleMethod) const
Sets the method to use for scaling the marker's size.
Definition: qgsmarkersymbol.cpp:399
QgsPanelWidget::setPanelTitle
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
Definition: qgspanelwidget.h:44
QgsPropertyOverrideButton::init
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).
Definition: qgspropertyoverridebutton.cpp:96
QgsExpressionContext::EXPR_GEOMETRY_RING_NUM
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
Definition: qgsexpressioncontext.h:819
QgsSymbol::setForceRHR
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition: qgssymbol.h:563
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsSymbolAnimationSettingsDialog
A dialog for customising animation settings for a symbol.
Definition: qgssymbolanimationsettingswidget.h:68
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
QgsStyle::symbolNames
QStringList symbolNames() const
Returns a list of names of symbols.
Definition: qgsstyle.cpp:307
qgsvectorlayer.h
QgsExpressionContext::EXPR_CLUSTER_SIZE
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
Definition: qgsexpressioncontext.h:825
QgsSymbolsListWidget::updateDataDefinedMarkerSize
void updateDataDefinedMarkerSize()
Definition: qgssymbolslistwidget.cpp:403
QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
Definition: qgsexpressioncontext.h:811
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
Qgis::SymbolType::Hybrid
@ Hybrid
Hybrid symbol.
QgsSymbol::clone
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QgsStyle::removeSymbol
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition: qgsstyle.cpp:257
QgsSymbolsListWidget::clipFeaturesToggled
void clipFeaturesToggled(bool checked)
Definition: qgssymbolslistwidget.cpp:351
QgsSymbolsListWidget::setContext
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Definition: qgssymbolslistwidget.cpp:243
QgsSymbolSelectorDialog::symbol
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
Definition: qgssymbolselectordialog.cpp:823
QgsSymbolsListWidget::layer
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Definition: qgssymbolslistwidget.h:73
QgsSymbol::clipFeaturesToExtent
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
Definition: qgssymbol.h:552
QgsSymbolAnimationSettingsWidget
A widget for customising animation settings for a symbol.
Definition: qgssymbolanimationsettingswidget.h:35
QgsStyle
Definition: qgsstyle.h:159
QgsSymbol::Property
Property
Data definable properties.
Definition: qgssymbol.h:129
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsPropertyOverrideButton::registerExpressionContextGenerator
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
Definition: qgspropertyoverridebutton.cpp:945
QgsMarkerSymbol::dataDefinedAngle
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
Definition: qgsmarkersymbol.cpp:106
qgsmarkersymbol.h
QgsLineSymbol::setWidth
void setWidth(double width) const
Sets the width for the whole line symbol.
Definition: qgslinesymbol.cpp:40
QgsSymbol::deleteSymbolLayer
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
Definition: qgssymbol.cpp:758
QgsMarkerSymbol::setSize
void setSize(double size) const
Sets the size for the whole symbol.
Definition: qgsmarkersymbol.cpp:153
QgsSymbol::setFlags
void setFlags(Qgis::SymbolFlags flags)
Sets flags for the symbol.
Definition: qgssymbol.h:522
QgsSymbolLayer::PropertyAngle
@ PropertyAngle
Symbol angle.
Definition: qgssymbollayer.h:145
QgsUnitTypes::RenderMetersInMapUnits
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
QgsAuxiliaryLayer::nameFromProperty
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
Definition: qgsauxiliarystorage.cpp:440
QgsSymbol::animationSettings
QgsSymbolAnimationSettings & animationSettings()
Returns a reference to the symbol animation settings.
Definition: qgssymbol.cpp:658
QgsSymbolLayer::Property
Property
Data definable properties.
Definition: qgssymbollayer.h:142
QgsStyle::saveSymbol
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
Definition: qgsstyle.cpp:221
QgsProjectStyleSettings::styleAtPath
QgsStyle * styleAtPath(const QString &path)
Returns a reference to the style database associated with the project with matching file path.
Definition: qgsprojectstylesettings.cpp:337
QgsColorButton::setContext
void setContext(const QString &context)
Sets the context string for the color button.
Definition: qgscolorbutton.h:245
QgsSymbolAnimationSettingsWidget::animationSettings
QgsSymbolAnimationSettings animationSettings() const
Returns the animation settings as defined in the widget.
Definition: qgssymbolanimationsettingswidget.cpp:49
QgsUnitTypes::RenderUnitList
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:240
QgsLineSymbol::setDataDefinedWidth
void setDataDefinedWidth(const QgsProperty &property) const
Set data defined width for whole symbol (including all symbol layers).
Definition: qgslinesymbol.cpp:142
QgsAuxiliaryLayer::addAuxiliaryField
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
Definition: qgsauxiliarystorage.cpp:140
MathUtils::angle
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
qgsfillsymbol.h
QgsSymbol::setColor
void setColor(const QColor &color) const
Sets the color for the symbol.
Definition: qgssymbol.cpp:867
QgsSymbolsListWidget::context
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
Definition: qgssymbolslistwidget.cpp:253
QgsSymbol::forceRHR
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Definition: qgssymbol.h:574
QgsUnitTypes::RenderMapUnits
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
QgsNewAuxiliaryLayerDialog
A dialog to create a new auxiliary layer.
Definition: qgsnewauxiliarylayerdialog.h:34
Qgis::SymbolType::Marker
@ Marker
Marker symbol.
QgsSymbolWidgetContext::additionalExpressionContextScopes
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
Definition: qgssymbolwidgetcontext.cpp:87
QgsSymbolsListWidget::updateDataDefinedLineWidth
void updateDataDefinedLineWidth()
Definition: qgssymbolslistwidget.cpp:432
QgsSymbol::symbolLayerCount
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:215
qgslinesymbol.h
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:178
QgsSymbolsListWidget::updateDataDefinedMarkerAngle
void updateDataDefinedMarkerAngle()
Definition: qgssymbolslistwidget.cpp:375
QgsColorButton::setColorDialogTitle
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
Definition: qgscolorbutton.cpp:810