QGIS API Documentation  2.99.0-Master (b058df7)
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"
21 
22 #include "qgssymbol.h"
23 #include "qgsstyle.h"
24 #include "qgssymbollayerutils.h"
25 #include "qgsmarkersymbollayer.h"
26 #include "qgsmapcanvas.h"
27 #include "qgsapplication.h"
28 #include "qgsvectorlayer.h"
29 #include "qgssettings.h"
31 #include "qgsauxiliarystorage.h"
32 
33 #include <QAction>
34 #include <QString>
35 #include <QStringList>
36 #include <QPainter>
37 #include <QIcon>
38 #include <QStandardItemModel>
39 #include <QColorDialog>
40 #include <QInputDialog>
41 #include <QMessageBox>
42 #include <QMenu>
43 #include <QPushButton>
44 
45 
46 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
47  : QWidget( parent )
48  , mSymbol( symbol )
49  , mStyle( style )
50  , mLayer( layer )
51 {
52  setupUi( this );
53  connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
54  connect( groupsCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
55  spinAngle->setClearValue( 0 );
56 
59 
60  btnAdvanced->hide(); // advanced button is hidden by default
61  if ( menu ) // show it if there is a menu pointer
62  {
63  mAdvancedMenu = menu;
64  btnAdvanced->show();
65  btnAdvanced->setMenu( mAdvancedMenu );
66  }
67  else
68  {
69  btnAdvanced->setMenu( new QMenu( this ) );
70  }
71  mClipFeaturesAction = new QAction( tr( "Clip features to canvas extent" ), this );
72  mClipFeaturesAction->setCheckable( true );
73  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
74 
75  QStandardItemModel *model = new QStandardItemModel( viewSymbols );
76  viewSymbols->setModel( model );
77  connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );
78 
81 
82  connect( openStyleManagerButton, &QPushButton::pressed, this, &QgsSymbolsListWidget::openStyleManager );
83 
84  lblSymbolName->clear();
85 
87 
88  if ( mSymbol )
89  {
90  updateSymbolInfo();
91  }
92 
93  // select correct page in stacked widget
94  // there's a correspondence between symbol type number and page numbering => exploit it!
95  stackedWidget->setCurrentIndex( symbol->type() );
97  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
98  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
99  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
100 
101  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
103  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
105  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
107 
108  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
109  updateAssistantSymbol();
110 
111  // Live color updates are not undoable to child symbol layers
112  btnColor->setAcceptLiveUpdates( false );
113  btnColor->setAllowOpacity( true );
114  btnColor->setColorDialogTitle( tr( "Select Color" ) );
115  btnColor->setContext( QStringLiteral( "symbology" ) );
116  connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol );
117 
118  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
119 }
120 
122 {
123  // This action was added to the menu by this widget, clean it up
124  // The menu can be passed in the constructor, so may live longer than this widget
125  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
126 }
127 
128 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
129 {
130  button->setProperty( "propertyKey", key );
131  button->registerExpressionContextGenerator( this );
132 
133  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
134 }
135 
136 void QgsSymbolsListWidget::createAuxiliaryField()
137 {
138  // try to create an auxiliary layer if not yet created
139  if ( !mLayer->auxiliaryLayer() )
140  {
141  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
142  dlg.exec();
143  }
144 
145  // return if still not exists
146  if ( !mLayer->auxiliaryLayer() )
147  return;
148 
149  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
150  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
152 
153  // create property in auxiliary storage if necessary
154  if ( !mLayer->auxiliaryLayer()->exists( def ) )
155  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
156 
157  // update property with join field name from auxiliary storage
158  QgsProperty property = button->toProperty();
159  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
160  property.setActive( true );
161  button->updateFieldLists();
162  button->setToProperty( property );
163 
164  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
165  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
166  switch ( key )
167  {
169  if ( markerSymbol )
170  markerSymbol->setDataDefinedAngle( button->toProperty() );
171  break;
173  if ( markerSymbol )
174  {
175  markerSymbol->setDataDefinedSize( button->toProperty() );
176  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
177  }
178  break;
180  if ( lineSymbol )
181  lineSymbol->setDataDefinedWidth( button->toProperty() );
182  default:
183  break;
184  }
185 
186  emit changed();
187 }
188 
190 {
191  mContext = context;
192  Q_FOREACH ( QgsUnitSelectionWidget *unitWidget, findChildren<QgsUnitSelectionWidget *>() )
193  {
194  unitWidget->setMapCanvas( mContext.mapCanvas() );
195  }
196 #if 0
197  Q_FOREACH ( QgsPropertyOverrideButton *ddButton, findChildren<QgsPropertyOverrideButton *>() )
198  {
199  if ( ddButton->assistant() )
200  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
201  }
202 #endif
203 }
204 
206 {
207  return mContext;
208 }
209 
211 {
212  groupsCombo->blockSignals( true );
213  groupsCombo->clear();
214 
215  groupsCombo->addItem( tr( "Favorites" ), QVariant( "favorite" ) );
216  groupsCombo->addItem( tr( "All Symbols" ), QVariant( "all" ) );
217 
218  int index = 2;
219  QStringList tags = mStyle->tags();
220  if ( tags.count() > 0 )
221  {
222  tags.sort();
223  groupsCombo->insertSeparator( index );
224  Q_FOREACH ( const QString &tag, tags )
225  {
226  groupsCombo->addItem( tag, QVariant( "tag" ) );
227  index++;
228  }
229  }
230 
231  QStringList groups = mStyle->smartgroupNames();
232  if ( groups.count() > 0 )
233  {
234  groups.sort();
235  groupsCombo->insertSeparator( index + 1 );
236  Q_FOREACH ( const QString &group, groups )
237  {
238  groupsCombo->addItem( group, QVariant( "smartgroup" ) );
239  }
240  }
241  groupsCombo->blockSignals( false );
242 
243  QgsSettings settings;
244  index = settings.value( QStringLiteral( "qgis/symbolsListGroupsIndex" ), 0 ).toInt();
245  groupsCombo->setCurrentIndex( index );
246 
247  populateSymbolView();
248 }
249 
250 void QgsSymbolsListWidget::populateSymbolView()
251 {
252  QStringList symbols;
253  QString text = groupsCombo->currentText();
254  int id;
255 
256  if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
257  {
258  symbols = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
259  }
260  else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
261  {
262  symbols = mStyle->symbolNames();
263  }
264  else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
265  {
266  id = mStyle->smartgroupId( text );
267  symbols = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, id );
268  }
269  else
270  {
271  id = mStyle->tagId( text );
272  symbols = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, id );
273  }
274 
275  symbols.sort();
276  populateSymbols( symbols );
277 }
278 
279 void QgsSymbolsListWidget::populateSymbols( const QStringList &names )
280 {
281  QSize previewSize = viewSymbols->iconSize();
282 
283  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( viewSymbols->model() );
284  if ( !model )
285  {
286  return;
287  }
288  model->clear();
289 
290  for ( int i = 0; i < names.count(); i++ )
291  {
292  QgsSymbol *s = mStyle->symbol( names[i] );
293  if ( s->type() != mSymbol->type() )
294  {
295  delete s;
296  continue;
297  }
298  QStringList tags = mStyle->tagsOfSymbol( QgsStyle::SymbolEntity, names[i] );
299  QStandardItem *item = new QStandardItem( names[i] );
300  item->setData( names[i], Qt::UserRole ); //so we can load symbol with that name
301  item->setText( names[i] );
302  item->setToolTip( QStringLiteral( "<b>%1</b><br><i>%2</i>" ).arg( names[i], tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) ) );
303  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
304  // Set font to 10points to show reasonable text
305  QFont itemFont = item->font();
306  itemFont.setPointSize( 10 );
307  item->setFont( itemFont );
308  // create preview icon
309  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
310  item->setIcon( icon );
311  // add to model
312  model->appendRow( item );
313  delete s;
314  }
315 }
316 
318 {
319  QgsStyleManagerDialog dlg( mStyle, this );
320  dlg.exec();
321 
322  populateSymbolView();
323 }
324 
326 {
327  if ( !mSymbol )
328  return;
329 
330  mSymbol->setClipFeaturesToExtent( checked );
331  emit changed();
332 }
333 
334 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
335 {
336  mSymbol->setColor( color );
337  emit changed();
338 }
339 
341 {
342  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
343  if ( markerSymbol->angle() == angle )
344  return;
345  markerSymbol->setAngle( angle );
346  emit changed();
347 }
348 
350 {
351  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
352  QgsProperty dd( mRotationDDBtn->toProperty() );
353 
354  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
355 
356  QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
357 
358  if ( // shall we remove datadefined expressions for layers ?
359  ( !symbolDD && !dd )
360  // shall we set the "en masse" expression for properties ?
361  || dd )
362  {
363  markerSymbol->setDataDefinedAngle( dd );
364  emit changed();
365  }
366 }
367 
369 {
370  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
371  if ( markerSymbol->size() == size )
372  return;
373  markerSymbol->setSize( size );
374  emit changed();
375 }
376 
378 {
379  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
380  QgsProperty dd( mSizeDDBtn->toProperty() );
381 
382  spinSize->setEnabled( !mSizeDDBtn->isActive() );
383 
384  QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
385 
386  if ( // shall we remove datadefined expressions for layers ?
387  ( !symbolDD && !dd )
388  // shall we set the "en masse" expression for properties ?
389  || dd )
390  {
391  markerSymbol->setDataDefinedSize( dd );
392  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
393  emit changed();
394  }
395 }
396 
398 {
399  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
400  if ( lineSymbol->width() == width )
401  return;
402  lineSymbol->setWidth( width );
403  emit changed();
404 }
405 
407 {
408  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
409  QgsProperty dd( mWidthDDBtn->toProperty() );
410 
411  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
412 
413  QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
414 
415  if ( // shall we remove datadefined expressions for layers ?
416  ( !symbolDD && !dd )
417  // shall we set the "en masse" expression for properties ?
418  || dd )
419  {
420  lineSymbol->setDataDefinedWidth( dd );
421  emit changed();
422  }
423 }
424 
425 void QgsSymbolsListWidget::updateAssistantSymbol()
426 {
427  mAssistantSymbol.reset( mSymbol->clone() );
428  if ( mSymbol->type() == QgsSymbol::Marker )
429  mSizeDDBtn->setSymbol( mAssistantSymbol );
430  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
431  mWidthDDBtn->setSymbol( mAssistantSymbol );
432 }
433 
434 void QgsSymbolsListWidget::symbolAddedToStyle( const QString &name, QgsSymbol *symbol )
435 {
436  Q_UNUSED( name );
437  Q_UNUSED( symbol );
438  populateSymbolView();
439 }
440 
442 {
443  bool ok;
444  QString name = QInputDialog::getText( this, tr( "Symbol name" ),
445  tr( "Please enter name for the symbol:" ), QLineEdit::Normal, tr( "New symbol" ), &ok );
446  if ( !ok || name.isEmpty() )
447  return;
448 
449  // check if there is no symbol with same name
450  if ( mStyle->symbolNames().contains( name ) )
451  {
452  int res = QMessageBox::warning( this, tr( "Save symbol" ),
453  tr( "Symbol with name '%1' already exists. Overwrite?" )
454  .arg( name ),
455  QMessageBox::Yes | QMessageBox::No );
456  if ( res != QMessageBox::Yes )
457  {
458  return;
459  }
460  }
461 
462  // add new symbol to style and re-populate the list
463  mStyle->addSymbol( name, mSymbol->clone() );
464 
465  // make sure the symbol is stored
466  mStyle->saveSymbol( name, mSymbol->clone(), false, QStringList() );
467  populateSymbolView();
468 }
469 
471 {
472  QgsStyleSaveDialog saveDlg( this );
473  if ( !saveDlg.exec() )
474  return;
475 
476  if ( saveDlg.name().isEmpty() )
477  return;
478 
479  // check if there is no symbol with same name
480  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
481  {
482  int res = QMessageBox::warning( this, tr( "Save symbol" ),
483  tr( "Symbol with name '%1' already exists. Overwrite?" )
484  .arg( saveDlg.name() ),
485  QMessageBox::Yes | QMessageBox::No );
486  if ( res != QMessageBox::Yes )
487  {
488  return;
489  }
490  mStyle->removeSymbol( saveDlg.name() );
491  }
492 
493  QStringList symbolTags = saveDlg.tags().split( ',' );
494 
495  // add new symbol to style and re-populate the list
496  mStyle->addSymbol( saveDlg.name(), mSymbol->clone() );
497 
498  // make sure the symbol is stored
499  mStyle->saveSymbol( saveDlg.name(), mSymbol->clone(), saveDlg.isFavorite(), symbolTags );
500 }
501 
502 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
503 {
504  if ( mSymbol )
505  {
506 
507  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
508  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
509 
510  emit changed();
511  }
512 }
513 
514 void QgsSymbolsListWidget::opacityChanged( double opacity )
515 {
516  if ( mSymbol )
517  {
518  mSymbol->setOpacity( opacity );
519  emit changed();
520  }
521 }
522 
523 void QgsSymbolsListWidget::updateSymbolColor()
524 {
525  btnColor->blockSignals( true );
526  btnColor->setColor( mSymbol->color() );
527  btnColor->blockSignals( false );
528 }
529 
530 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
531 {
532  if ( mContext.expressionContext() )
533  return QgsExpressionContext( *mContext.expressionContext() );
534 
535  //otherwise create a default symbol context
536  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
537 
538  // additional scopes
539  Q_FOREACH ( const QgsExpressionContextScope &scope, mContext.additionalExpressionContextScopes() )
540  {
541  expContext.appendScope( new QgsExpressionContextScope( scope ) );
542  }
543 
544  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
548 
549  return expContext;
550 }
551 
552 void QgsSymbolsListWidget::updateSymbolInfo()
553 {
554  updateSymbolColor();
555 
556  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
557  {
558  button->registerExpressionContextGenerator( this );
559  }
560 
561  if ( mSymbol->type() == QgsSymbol::Marker )
562  {
563  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
564  spinSize->setValue( markerSymbol->size() );
565  spinAngle->setValue( markerSymbol->angle() );
566 
567  if ( mLayer )
568  {
569  QgsProperty ddSize( markerSymbol->dataDefinedSize() );
570  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
571  spinSize->setEnabled( !mSizeDDBtn->isActive() );
572  QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
573  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
574  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
575  }
576  else
577  {
578  mSizeDDBtn->setEnabled( false );
579  mRotationDDBtn->setEnabled( false );
580  }
581  }
582  else if ( mSymbol->type() == QgsSymbol::Line )
583  {
584  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
585  spinWidth->setValue( lineSymbol->width() );
586 
587  if ( mLayer )
588  {
589  QgsProperty dd( lineSymbol->dataDefinedWidth() );
590  mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
591  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
592  }
593  else
594  {
595  mWidthDDBtn->setEnabled( false );
596  }
597  }
598 
599  mSymbolUnitWidget->blockSignals( true );
600  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
601  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
602  mSymbolUnitWidget->blockSignals( false );
603 
604  mOpacityWidget->setOpacity( mSymbol->opacity() );
605 
606  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
607  {
608  //add clip features option for line or fill symbols
609  btnAdvanced->menu()->addAction( mClipFeaturesAction );
610  }
611  else
612  {
613  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
614  }
615  btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
616 
617  mClipFeaturesAction->blockSignals( true );
618  mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
619  mClipFeaturesAction->blockSignals( false );
620 }
621 
622 void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex &index )
623 {
624  QString symbolName = index.data( Qt::UserRole ).toString();
625  lblSymbolName->setText( symbolName );
626  // get new instance of symbol from style
627  QgsSymbol *s = mStyle->symbol( symbolName );
628  // remove all symbol layers from original symbolgroupsCombo
629  while ( mSymbol->symbolLayerCount() )
630  mSymbol->deleteSymbolLayer( 0 );
631  // move all symbol layers to our symbol
632  while ( s->symbolLayerCount() )
633  {
634  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
635  mSymbol->appendSymbolLayer( sl );
636  }
637  mSymbol->setOpacity( s->opacity() );
638 
639  // delete the temporary symbol
640  delete s;
641 
642  updateSymbolInfo();
643  emit changed();
644 }
645 
646 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged( int index )
647 {
648  QgsSettings settings;
649  settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );
650 
651  populateSymbolView();
652 }
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.
Meters value as Map units.
Definition: qgsunittypes.h:109
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void setLineWidth(double width)
QString tags() const
returns the text value of the tags element
void symbolSaved(const QString &name, QgsSymbol *symbol)
Is emitted every time a new symbol has been added to the database.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
void setSymbolFromStyle(const QModelIndex &index)
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbol.cpp:246
Calculate scale by the diameter.
Definition: qgssymbol.h:97
a dialog for setting properties of a newly saved style.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:55
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:556
bool appendSymbolLayer(QgsSymbolLayer *layer)
Append symbol layer at the end of the list Ownership will be transferred.
Definition: qgssymbol.cpp:337
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbol.cpp:214
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
Definition: qgsstyle.cpp:998
QString name() const
returns the text value of the name element
void setSize(double size)
Sets the size for the whole symbol.
Definition: qgssymbol.cpp:1213
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:298
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:143
void setMarkerSize(double size)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
Definition: qgssymbol.cpp:347
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1139
Line symbol.
Definition: qgssymbol.h:86
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1104
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:173
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
void populateGroups()
Pupulates the groups combo box with available tags and smartgroups.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:193
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:238
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1167
A dialog to create a new auxiliary layer.
void setField(const QString &field)
Sets the field name the property references.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
A button for controlling property overrides which may apply to a widget.
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
QStringList symbolNames()
Returns a list of names of symbols.
Definition: qgsstyle.cpp:180
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition: qgssymbol.h:264
void setWidth(double width)
Definition: qgssymbol.cpp:1526
double width() const
Definition: qgssymbol.cpp:1552
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void groupsModified()
Is emitted every time a tag or smartgroup has been added, removed, or renamed.
points (e.g., for font sizes)
Definition: qgsunittypes.h:107
void setSymbolColor(const QColor &color)
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QColor color() const
Definition: qgssymbol.cpp:436
void setMarkerAngle(double angle)
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1404
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
Definition: qgsproperty.h:229
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1571
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
Definition for a property.
Definition: qgsproperty.h:46
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
Definition: qgsstyle.cpp:1230
int smartgroupId(const QString &smartgroup)
Returns the DB id for the given smartgroup name.
Definition: qgsstyle.cpp:1132
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1349
QStringList smartgroupNames()
Returns the smart groups list.
Definition: qgsstyle.cpp:1206
int tagId(const QString &tag)
Returns the DB id for the given tag name.
Definition: qgsstyle.cpp:1127
void colorChanged(const QColor &color)
Is emitted whenever a new color is set for the button.
void changed()
Emitted when property definition changes.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
void clipFeaturesToggled(bool checked)
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
Marker symbol.
Definition: qgssymbol.h:85
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol&#39;s ownership.
Definition: qgsstyle.cpp:81
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QStringList tags() const
Returns a list of all tags in the style database.
Definition: qgsstyle.cpp:625
Fill symbol.
Definition: qgssymbol.h:87
void symbolAddedToStyle(const QString &name, QgsSymbol *symbol)
SymbolType type() const
Definition: qgssymbol.h:113
virtual QgsSymbol * clone() const =0
Get a deep copy of this symbol.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
double size() const
Returns the size for the whole symbol, which is the maximum size of all marker symbol layers in the s...
Definition: qgssymbol.cpp:1236
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
int propertyKey() const
Returns the property key linked to the button.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
bool isFavorite() const
returns whether the favorite element is checked
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
QgsSymbolLayer * takeSymbolLayer(int index)
Remove symbol layer from the list and return pointer to it.
Definition: qgssymbol.cpp:358
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:164
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1313
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
Definition: qgsstyle.cpp:105
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:287
qreal opacity() const
Returns the opacity for the symbol.
Definition: qgssymbol.h:257
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition: qgsstyle.cpp:136
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
A widget displaying a combobox allowing the user to choose between various display units...
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Add an an auxiliary field for the given property.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
Represents a vector layer which manages a vector based data sets.
void updateFieldLists()
Updates list of fields.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1606
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:520
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgssymbol.cpp:1116
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer=nullptr)
Constructor for QgsSymbolsListWidget.
Property
Data definable properties.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...
void setColor(const QColor &color)
Definition: qgssymbol.cpp:427