QGIS API Documentation  2.99.0-Master (69af2f5)
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"
30 
31 #include <QAction>
32 #include <QString>
33 #include <QStringList>
34 #include <QPainter>
35 #include <QIcon>
36 #include <QStandardItemModel>
37 #include <QColorDialog>
38 #include <QInputDialog>
39 #include <QMessageBox>
40 #include <QMenu>
41 #include <QPushButton>
42 
43 
44 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, const QgsVectorLayer *layer )
45  : QWidget( parent )
46  , mSymbol( symbol )
47  , mStyle( style )
48  , mAdvancedMenu( nullptr )
49  , mClipFeaturesAction( nullptr )
50  , mLayer( layer )
51  , mMapCanvas( nullptr )
52 {
53  setupUi( this );
54  spinAngle->setClearValue( 0 );
55 
58 
59  btnAdvanced->hide(); // advanced button is hidden by default
60  if ( menu ) // show it if there is a menu pointer
61  {
62  mAdvancedMenu = menu;
63  btnAdvanced->show();
64  btnAdvanced->setMenu( mAdvancedMenu );
65  }
66  else
67  {
68  btnAdvanced->setMenu( new QMenu( this ) );
69  }
70  mClipFeaturesAction = new QAction( tr( "Clip features to canvas extent" ), this );
71  mClipFeaturesAction->setCheckable( true );
72  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
73 
74  QStandardItemModel *model = new QStandardItemModel( viewSymbols );
75  viewSymbols->setModel( model );
76  connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );
77 
80 
81  connect( openStyleManagerButton, &QPushButton::pressed, this, &QgsSymbolsListWidget::openStyleManager );
82 
83  lblSymbolName->setText( QLatin1String( "" ) );
84 
86 
87  if ( mSymbol )
88  {
89  updateSymbolInfo();
90  }
91 
92  // select correct page in stacked widget
93  // there's a correspondence between symbol type number and page numbering => exploit it!
94  stackedWidget->setCurrentIndex( symbol->type() );
96  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
97  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
98  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
99 
100  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
102  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
104  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
106 
107  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
108  updateAssistantSymbol();
109 
110  // Live color updates are not undoable to child symbol layers
111  btnColor->setAcceptLiveUpdates( false );
112  btnColor->setAllowOpacity( true );
113  btnColor->setColorDialogTitle( tr( "Select color" ) );
114  btnColor->setContext( QStringLiteral( "symbology" ) );
115  connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol );
116 
117  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
118 }
119 
121 {
122  // This action was added to the menu by this widget, clean it up
123  // The menu can be passed in the constructor, so may live longer than this widget
124  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
125 }
126 
127 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
128 {
129  button->setProperty( "propertyKey", key );
130  button->registerExpressionContextGenerator( this );
131 }
132 
134 {
135  mContext = context;
136  Q_FOREACH ( QgsUnitSelectionWidget *unitWidget, findChildren<QgsUnitSelectionWidget *>() )
137  {
138  unitWidget->setMapCanvas( mContext.mapCanvas() );
139  }
140 #if 0
141  Q_FOREACH ( QgsPropertyOverrideButton *ddButton, findChildren<QgsPropertyOverrideButton *>() )
142  {
143  if ( ddButton->assistant() )
144  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
145  }
146 #endif
147 }
148 
150 {
151  return mContext;
152 }
153 
155 {
156  groupsCombo->blockSignals( true );
157  groupsCombo->clear();
158 
159  groupsCombo->addItem( tr( "Favorites" ), QVariant( "favorite" ) );
160  groupsCombo->addItem( tr( "All Symbols" ), QVariant( "all" ) );
161 
162  int index = 2;
163  QStringList tags = mStyle->tags();
164  if ( tags.count() > 0 )
165  {
166  tags.sort();
167  groupsCombo->insertSeparator( index );
168  Q_FOREACH ( const QString &tag, tags )
169  {
170  groupsCombo->addItem( tag, QVariant( "tag" ) );
171  index++;
172  }
173  }
174 
175  QStringList groups = mStyle->smartgroupNames();
176  if ( groups.count() > 0 )
177  {
178  groups.sort();
179  groupsCombo->insertSeparator( index + 1 );
180  Q_FOREACH ( const QString &group, groups )
181  {
182  groupsCombo->addItem( group, QVariant( "smartgroup" ) );
183  }
184  }
185  groupsCombo->blockSignals( false );
186 
187  QgsSettings settings;
188  index = settings.value( "qgis/symbolsListGroupsIndex", 0 ).toInt();
189  groupsCombo->setCurrentIndex( index );
190 
191  populateSymbolView();
192 }
193 
194 void QgsSymbolsListWidget::populateSymbolView()
195 {
196  QStringList symbols;
197  QString text = groupsCombo->currentText();
198  int id;
199 
200  if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
201  {
202  symbols = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
203  }
204  else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
205  {
206  symbols = mStyle->symbolNames();
207  }
208  else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
209  {
210  id = mStyle->smartgroupId( text );
211  symbols = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, id );
212  }
213  else
214  {
215  id = mStyle->tagId( text );
216  symbols = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, id );
217  }
218 
219  symbols.sort();
220  populateSymbols( symbols );
221 }
222 
223 void QgsSymbolsListWidget::populateSymbols( const QStringList &names )
224 {
225  QSize previewSize = viewSymbols->iconSize();
226 
227  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( viewSymbols->model() );
228  if ( !model )
229  {
230  return;
231  }
232  model->clear();
233 
234  for ( int i = 0; i < names.count(); i++ )
235  {
236  QgsSymbol *s = mStyle->symbol( names[i] );
237  if ( s->type() != mSymbol->type() )
238  {
239  delete s;
240  continue;
241  }
242  QStringList tags = mStyle->tagsOfSymbol( QgsStyle::SymbolEntity, names[i] );
243  QStandardItem *item = new QStandardItem( names[i] );
244  item->setData( names[i], Qt::UserRole ); //so we can load symbol with that name
245  item->setText( names[i] );
246  item->setToolTip( QString( "<b>%1</b><br><i>%2</i>" ).arg( names[i] ).arg( tags.count() > 0 ? tags.join( ", " ) : tr( "Not tagged" ) ) );
247  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
248  // Set font to 10points to show reasonable text
249  QFont itemFont = item->font();
250  itemFont.setPointSize( 10 );
251  item->setFont( itemFont );
252  // create preview icon
253  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
254  item->setIcon( icon );
255  // add to model
256  model->appendRow( item );
257  delete s;
258  }
259 }
260 
262 {
263  QgsStyleManagerDialog dlg( mStyle, this );
264  dlg.exec();
265 
266  populateSymbolView();
267 }
268 
270 {
271  if ( !mSymbol )
272  return;
273 
274  mSymbol->setClipFeaturesToExtent( checked );
275  emit changed();
276 }
277 
278 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
279 {
280  mSymbol->setColor( color );
281  emit changed();
282 }
283 
285 {
286  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
287  if ( markerSymbol->angle() == angle )
288  return;
289  markerSymbol->setAngle( angle );
290  emit changed();
291 }
292 
294 {
295  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
296  QgsProperty dd( mRotationDDBtn->toProperty() );
297 
298  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
299 
300  QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
301 
302  if ( // shall we remove datadefined expressions for layers ?
303  ( !symbolDD && !dd )
304  // shall we set the "en masse" expression for properties ?
305  || dd )
306  {
307  markerSymbol->setDataDefinedAngle( dd );
308  emit changed();
309  }
310 }
311 
313 {
314  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
315  if ( markerSymbol->size() == size )
316  return;
317  markerSymbol->setSize( size );
318  emit changed();
319 }
320 
322 {
323  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
324  QgsProperty dd( mSizeDDBtn->toProperty() );
325 
326  spinSize->setEnabled( !mSizeDDBtn->isActive() );
327 
328  QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
329 
330  if ( // shall we remove datadefined expressions for layers ?
331  ( !symbolDD && !dd )
332  // shall we set the "en masse" expression for properties ?
333  || dd )
334  {
335  markerSymbol->setDataDefinedSize( dd );
336  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
337  emit changed();
338  }
339 }
340 
342 {
343  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
344  if ( lineSymbol->width() == width )
345  return;
346  lineSymbol->setWidth( width );
347  emit changed();
348 }
349 
351 {
352  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
353  QgsProperty dd( mWidthDDBtn->toProperty() );
354 
355  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
356 
357  QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
358 
359  if ( // shall we remove datadefined expressions for layers ?
360  ( !symbolDD && !dd )
361  // shall we set the "en masse" expression for properties ?
362  || dd )
363  {
364  lineSymbol->setDataDefinedWidth( dd );
365  emit changed();
366  }
367 }
368 
369 void QgsSymbolsListWidget::updateAssistantSymbol()
370 {
371  mAssistantSymbol.reset( mSymbol->clone() );
372  if ( mSymbol->type() == QgsSymbol::Marker )
373  mSizeDDBtn->setSymbol( mAssistantSymbol );
374  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
375  mWidthDDBtn->setSymbol( mAssistantSymbol );
376 }
377 
378 void QgsSymbolsListWidget::symbolAddedToStyle( const QString &name, QgsSymbol *symbol )
379 {
380  Q_UNUSED( name );
381  Q_UNUSED( symbol );
382  populateSymbolView();
383 }
384 
386 {
387  bool ok;
388  QString name = QInputDialog::getText( this, tr( "Symbol name" ),
389  tr( "Please enter name for the symbol:" ), QLineEdit::Normal, tr( "New symbol" ), &ok );
390  if ( !ok || name.isEmpty() )
391  return;
392 
393  // check if there is no symbol with same name
394  if ( mStyle->symbolNames().contains( name ) )
395  {
396  int res = QMessageBox::warning( this, tr( "Save symbol" ),
397  tr( "Symbol with name '%1' already exists. Overwrite?" )
398  .arg( name ),
399  QMessageBox::Yes | QMessageBox::No );
400  if ( res != QMessageBox::Yes )
401  {
402  return;
403  }
404  }
405 
406  // add new symbol to style and re-populate the list
407  mStyle->addSymbol( name, mSymbol->clone() );
408 
409  // make sure the symbol is stored
410  mStyle->saveSymbol( name, mSymbol->clone(), false, QStringList() );
411  populateSymbolView();
412 }
413 
415 {
416  QgsStyleSaveDialog saveDlg( this );
417  if ( !saveDlg.exec() )
418  return;
419 
420  if ( saveDlg.name().isEmpty() )
421  return;
422 
423  // check if there is no symbol with same name
424  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
425  {
426  int res = QMessageBox::warning( this, tr( "Save symbol" ),
427  tr( "Symbol with name '%1' already exists. Overwrite?" )
428  .arg( saveDlg.name() ),
429  QMessageBox::Yes | QMessageBox::No );
430  if ( res != QMessageBox::Yes )
431  {
432  return;
433  }
434  mStyle->removeSymbol( saveDlg.name() );
435  }
436 
437  QStringList symbolTags = saveDlg.tags().split( ',' );
438 
439  // add new symbol to style and re-populate the list
440  mStyle->addSymbol( saveDlg.name(), mSymbol->clone() );
441 
442  // make sure the symbol is stored
443  mStyle->saveSymbol( saveDlg.name(), mSymbol->clone(), saveDlg.isFavorite(), symbolTags );
444 }
445 
447 {
448  if ( mSymbol )
449  {
450 
451  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
452  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
453 
454  emit changed();
455  }
456 }
457 
458 void QgsSymbolsListWidget::opacityChanged( double opacity )
459 {
460  if ( mSymbol )
461  {
462  mSymbol->setOpacity( opacity );
463  emit changed();
464  }
465 }
466 
467 void QgsSymbolsListWidget::updateSymbolColor()
468 {
469  btnColor->blockSignals( true );
470  btnColor->setColor( mSymbol->color() );
471  btnColor->blockSignals( false );
472 }
473 
474 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
475 {
476  if ( mContext.expressionContext() )
477  return QgsExpressionContext( *mContext.expressionContext() );
478 
479  //otherwise create a default symbol context
480  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
481 
482  // additional scopes
483  Q_FOREACH ( const QgsExpressionContextScope &scope, mContext.additionalExpressionContextScopes() )
484  {
485  expContext.appendScope( new QgsExpressionContextScope( scope ) );
486  }
487 
488  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
492 
493  return expContext;
494 }
495 
496 void QgsSymbolsListWidget::updateSymbolInfo()
497 {
498  updateSymbolColor();
499 
500  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
501  {
502  button->registerExpressionContextGenerator( this );
503  }
504 
505  if ( mSymbol->type() == QgsSymbol::Marker )
506  {
507  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
508  spinSize->setValue( markerSymbol->size() );
509  spinAngle->setValue( markerSymbol->angle() );
510 
511  if ( mLayer )
512  {
513  QgsProperty ddSize( markerSymbol->dataDefinedSize() );
514  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer );
515  spinSize->setEnabled( !mSizeDDBtn->isActive() );
516  QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
517  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer );
518  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
519  }
520  else
521  {
522  mSizeDDBtn->setEnabled( false );
523  mRotationDDBtn->setEnabled( false );
524  }
525  }
526  else if ( mSymbol->type() == QgsSymbol::Line )
527  {
528  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
529  spinWidth->setValue( lineSymbol->width() );
530 
531  if ( mLayer )
532  {
533  QgsProperty dd( lineSymbol->dataDefinedWidth() );
535  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
536  }
537  else
538  {
539  mWidthDDBtn->setEnabled( false );
540  }
541  }
542 
543  mSymbolUnitWidget->blockSignals( true );
544  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
545  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
546  mSymbolUnitWidget->blockSignals( false );
547 
548  mOpacityWidget->setOpacity( mSymbol->opacity() );
549 
550  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
551  {
552  //add clip features option for line or fill symbols
553  btnAdvanced->menu()->addAction( mClipFeaturesAction );
554  }
555  else
556  {
557  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
558  }
559  btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
560 
561  mClipFeaturesAction->blockSignals( true );
562  mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
563  mClipFeaturesAction->blockSignals( false );
564 }
565 
566 void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex &index )
567 {
568  QString symbolName = index.data( Qt::UserRole ).toString();
569  lblSymbolName->setText( symbolName );
570  // get new instance of symbol from style
571  QgsSymbol *s = mStyle->symbol( symbolName );
572  // remove all symbol layers from original symbolgroupsCombo
573  while ( mSymbol->symbolLayerCount() )
574  mSymbol->deleteSymbolLayer( 0 );
575  // move all symbol layers to our symbol
576  while ( s->symbolLayerCount() )
577  {
578  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
579  mSymbol->appendSymbolLayer( sl );
580  }
581  mSymbol->setOpacity( s->opacity() );
582 
583  // delete the temporary symbol
584  delete s;
585 
586  updateSymbolInfo();
587  emit changed();
588 }
589 
591 {
592  QgsSettings settings;
593  settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );
594 
595  populateSymbolView();
596 }
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.
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:96
a dialog for setting properties of a newly saved style.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:54
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:565
bool appendSymbolLayer(QgsSymbolLayer *layer)
Append symbol layer at the end of the list Ownership will be transferred.
Definition: qgssymbol.cpp:338
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbol.cpp:214
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
Definition: qgsstyle.cpp:1027
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:1204
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:283
void setMarkerSize(double size)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
Definition: qgssymbol.cpp:348
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1130
Line symbol.
Definition: qgssymbol.h:85
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1095
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:145
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.cc:857
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
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1158
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, const QgsVectorLayer *layer=nullptr)
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:187
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition: qgssymbol.h:253
void setWidth(double width)
Definition: qgssymbol.cpp:1517
double width() const
Definition: qgssymbol.cpp:1543
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:102
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:139
void setSymbolColor(const QColor &color)
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QColor color() const
Definition: qgssymbol.cpp:431
void setMarkerAngle(double angle)
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1395
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
Definition: qgsproperty.h:189
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1562
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
void on_groupsCombo_currentIndexChanged(int index)
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
Definition: qgsstyle.cpp:1268
int smartgroupId(const QString &smartgroup)
Returns the DB id for the given smartgroup name.
Definition: qgsstyle.cpp:1168
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1340
QStringList smartgroupNames()
Returns the smart groups list.
Definition: qgsstyle.cpp:1243
int tagId(const QString &tag)
Returns the DB id for the given tag name.
Definition: qgsstyle.cpp:1163
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:84
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol&#39;s ownership.
Definition: qgsstyle.cpp:88
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:634
Fill symbol.
Definition: qgssymbol.h:86
void symbolAddedToStyle(const QString &name, QgsSymbol *symbol)
SymbolType type() const
Definition: qgssymbol.h:112
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:1227
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
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:359
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:171
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:1304
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
Definition: qgsstyle.cpp:112
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:273
qreal opacity() const
Returns the opacity for the symbol.
Definition: qgssymbol.h:246
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition: qgsstyle.cpp:143
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
A widget displaying a combobox allowing the user to choose between various display units...
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.
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:1597
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:528
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgssymbol.cpp:1107
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:422