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