QGIS API Documentation  2.99.0-Master (c42dad3)
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 "qgssizescalewidget.h"
20 
21 #include "qgsstylemanagerdialog.h"
22 #include "qgsstylesavedialog.h"
23 #include "qgsdatadefined.h"
24 
25 #include "qgssymbol.h"
26 #include "qgsstyle.h"
27 #include "qgssymbollayerutils.h"
28 #include "qgsmarkersymbollayer.h"
29 #include "qgsmapcanvas.h"
30 #include "qgsapplication.h"
31 #include "qgsvectorlayer.h"
32 
33 #include <QAction>
34 #include <QSettings>
35 #include <QString>
36 #include <QStringList>
37 #include <QPainter>
38 #include <QIcon>
39 #include <QStandardItemModel>
40 #include <QColorDialog>
41 #include <QInputDialog>
42 #include <QMessageBox>
43 #include <QMenu>
44 #include <QPushButton>
45 #include <QScopedPointer>
46 
47 
48 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol* symbol, QgsStyle* style, QMenu* menu, QWidget* parent, const QgsVectorLayer * layer )
49  : QWidget( parent )
50  , mSymbol( symbol )
51  , mStyle( style )
52  , mAdvancedMenu( nullptr )
53  , mClipFeaturesAction( nullptr )
54  , mLayer( layer )
55  , mMapCanvas( nullptr )
56 {
57  setupUi( this );
58 
60 
61  btnAdvanced->hide(); // advanced button is hidden by default
62  if ( menu ) // show it if there is a menu pointer
63  {
64  mAdvancedMenu = menu;
65  btnAdvanced->show();
66  btnAdvanced->setMenu( mAdvancedMenu );
67  }
68  else
69  {
70  btnAdvanced->setMenu( new QMenu( this ) );
71  }
72  mClipFeaturesAction = new QAction( tr( "Clip features to canvas extent" ), this );
73  mClipFeaturesAction->setCheckable( true );
74  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
75 
76  QStandardItemModel* model = new QStandardItemModel( viewSymbols );
77  viewSymbols->setModel( model );
78  connect( viewSymbols->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), this, SLOT( setSymbolFromStyle( const QModelIndex & ) ) );
79 
82 
83  connect( openStyleManagerButton, &QPushButton::pressed, this, &QgsSymbolsListWidget::openStyleManager );
84 
85  lblSymbolName->setText( QLatin1String( "" ) );
86 
88 
89  if ( mSymbol )
90  {
91  updateSymbolInfo();
92  }
93 
94  // select correct page in stacked widget
95  // there's a correspondence between symbol type number and page numbering => exploit it!
96  stackedWidget->setCurrentIndex( symbol->type() );
97  connect( btnColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolColor( const QColor& ) ) );
98  connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setMarkerAngle( double ) ) );
99  connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setMarkerSize( double ) ) );
100  connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( setLineWidth( double ) ) );
101 
102  connect( mRotationDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedMarkerAngle() ) );
103  connect( mRotationDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedMarkerAngle() ) );
104  connect( mSizeDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedMarkerSize() ) );
105  connect( mSizeDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedMarkerSize() ) );
106  connect( mWidthDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedLineWidth() ) );
107  connect( mWidthDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedLineWidth() ) );
108 
109  if ( mSymbol->type() == QgsSymbol::Marker && mLayer )
110  mSizeDDBtn->setAssistant( tr( "Size Assistant..." ), new QgsSizeScaleWidget( mLayer, mSymbol ) );
111  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
112  mWidthDDBtn->setAssistant( tr( "Width Assistant..." ), new QgsSizeScaleWidget( mLayer, mSymbol ) );
113 
114  // Live color updates are not undoable to child symbol layers
115  btnColor->setAcceptLiveUpdates( false );
116  btnColor->setAllowAlpha( true );
117  btnColor->setColorDialogTitle( tr( "Select color" ) );
118  btnColor->setContext( QStringLiteral( "symbology" ) );
119 
120  connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol );
121 }
122 
124 {
125  // This action was added to the menu by this widget, clean it up
126  // The menu can be passed in the constructor, so may live longer than this widget
127  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
128 }
129 
131 {
132  mContext = context;
133  Q_FOREACH ( QgsUnitSelectionWidget* unitWidget, findChildren<QgsUnitSelectionWidget*>() )
134  {
135  unitWidget->setMapCanvas( mContext.mapCanvas() );
136  }
137  Q_FOREACH ( QgsDataDefinedButton* ddButton, findChildren<QgsDataDefinedButton*>() )
138  {
139  if ( ddButton->assistant() )
140  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
141  }
142 }
143 
145 {
146  return mContext;
147 }
148 
150 {
151  groupsCombo->blockSignals( true );
152  groupsCombo->clear();
153 
154  groupsCombo->addItem( tr( "Favorites" ), QVariant( "favorite" ) );
155  groupsCombo->addItem( tr( "All Symbols" ), QVariant( "all" ) );
156 
157  int index = 2;
158  QStringList tags = mStyle->tags();
159  if ( tags.count() > 0 )
160  {
161  tags.sort();
162  groupsCombo->insertSeparator( index );
163  Q_FOREACH ( const QString& tag, tags )
164  {
165  groupsCombo->addItem( tag, QVariant( "tag" ) );
166  index++;
167  }
168  }
169 
170  QStringList groups = mStyle->smartgroupNames();
171  if ( groups.count() > 0 )
172  {
173  groups.sort();
174  groupsCombo->insertSeparator( index + 1 );
175  Q_FOREACH ( const QString& group, groups )
176  {
177  groupsCombo->addItem( group, QVariant( "smartgroup" ) );
178  }
179  }
180  groupsCombo->blockSignals( false );
181 
182  QSettings settings;
183  index = settings.value( "qgis/symbolsListGroupsIndex", 0 ).toInt();
184  groupsCombo->setCurrentIndex( index );
185 
186  populateSymbolView();
187 }
188 
189 void QgsSymbolsListWidget::populateSymbolView()
190 {
191  QStringList symbols;
192  QString text = groupsCombo->currentText();
193  int id;
194 
195  if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
196  {
197  symbols = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
198  }
199  else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
200  {
201  symbols = mStyle->symbolNames();
202  }
203  else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
204  {
205  id = mStyle->smartgroupId( text );
206  symbols = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, id );
207  }
208  else
209  {
210  id = mStyle->tagId( text );
211  symbols = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, id );
212  }
213 
214  symbols.sort();
215  populateSymbols( symbols );
216 }
217 
218 void QgsSymbolsListWidget::populateSymbols( const QStringList& names )
219 {
220  QSize previewSize = viewSymbols->iconSize();
221 
222  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( viewSymbols->model() );
223  if ( !model )
224  {
225  return;
226  }
227  model->clear();
228 
229  for ( int i = 0; i < names.count(); i++ )
230  {
231  QgsSymbol* s = mStyle->symbol( names[i] );
232  if ( s->type() != mSymbol->type() )
233  {
234  delete s;
235  continue;
236  }
237  QStringList tags = mStyle->tagsOfSymbol( QgsStyle::SymbolEntity, names[i] );
238  QStandardItem* item = new QStandardItem( names[i] );
239  item->setData( names[i], Qt::UserRole ); //so we can load symbol with that name
240  item->setText( names[i] );
241  item->setToolTip( QString( "<b>%1</b><br><i>%2</i>" ).arg( names[i] ).arg( tags.count() > 0 ? tags.join( ", " ) : tr( "Not tagged" ) ) );
242  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
243  // Set font to 10points to show reasonable text
244  QFont itemFont = item->font();
245  itemFont.setPointSize( 10 );
246  item->setFont( itemFont );
247  // create preview icon
248  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
249  item->setIcon( icon );
250  // add to model
251  model->appendRow( item );
252  delete s;
253  }
254 }
255 
257 {
258  QgsStyleManagerDialog dlg( mStyle, this );
259  dlg.exec();
260 
261  populateSymbolView();
262 }
263 
265 {
266  if ( !mSymbol )
267  return;
268 
269  mSymbol->setClipFeaturesToExtent( checked );
270  emit changed();
271 }
272 
273 void QgsSymbolsListWidget::setSymbolColor( const QColor& color )
274 {
275  mSymbol->setColor( color );
276  emit changed();
277 }
278 
280 {
281  QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( mSymbol );
282  if ( markerSymbol->angle() == angle )
283  return;
284  markerSymbol->setAngle( angle );
285  emit changed();
286 }
287 
289 {
290  QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( mSymbol );
291  QgsDataDefined dd = mRotationDDBtn->currentDataDefined();
292 
293  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
294 
295  bool isDefault = dd.hasDefaultValues();
296 
297  if ( // shall we remove datadefined expressions for layers ?
298  ( markerSymbol->dataDefinedAngle().hasDefaultValues() && isDefault )
299  // shall we set the "en masse" expression for properties ?
300  || !isDefault )
301  {
302  markerSymbol->setDataDefinedAngle( dd );
303  emit changed();
304  }
305 }
306 
308 {
309  QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( mSymbol );
310  if ( markerSymbol->size() == size )
311  return;
312  markerSymbol->setSize( size );
313  emit changed();
314 }
315 
317 {
318  QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( mSymbol );
319  QgsDataDefined dd = mSizeDDBtn->currentDataDefined();
320 
321  spinSize->setEnabled( !mSizeDDBtn->isActive() );
322 
323  bool isDefault = dd.hasDefaultValues();
324 
325  if ( // shall we remove datadefined expressions for layers ?
326  ( !markerSymbol->dataDefinedSize().hasDefaultValues() && isDefault )
327  // shall we set the "en masse" expression for properties ?
328  || !isDefault )
329  {
330  markerSymbol->setDataDefinedSize( dd );
331  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
332  emit changed();
333  }
334 }
335 
337 {
338  QgsLineSymbol* lineSymbol = static_cast<QgsLineSymbol*>( mSymbol );
339  if ( lineSymbol->width() == width )
340  return;
341  lineSymbol->setWidth( width );
342  emit changed();
343 }
344 
346 {
347  QgsLineSymbol* lineSymbol = static_cast<QgsLineSymbol*>( mSymbol );
348  QgsDataDefined dd = mWidthDDBtn->currentDataDefined();
349 
350  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
351 
352  bool isDefault = dd.hasDefaultValues();
353 
354  if ( // shall we remove datadefined expressions for layers ?
355  ( !lineSymbol->dataDefinedWidth().hasDefaultValues() && isDefault )
356  // shall we set the "en masse" expression for properties ?
357  || !isDefault )
358  {
359  lineSymbol->setDataDefinedWidth( dd );
360  emit changed();
361  }
362 }
363 
364 void QgsSymbolsListWidget::symbolAddedToStyle( const QString& name, QgsSymbol* symbol )
365 {
366  Q_UNUSED( name );
367  Q_UNUSED( symbol );
368  populateSymbolView();
369 }
370 
372 {
373  bool ok;
374  QString name = QInputDialog::getText( this, tr( "Symbol name" ),
375  tr( "Please enter name for the symbol:" ), QLineEdit::Normal, tr( "New symbol" ), &ok );
376  if ( !ok || name.isEmpty() )
377  return;
378 
379  // check if there is no symbol with same name
380  if ( mStyle->symbolNames().contains( name ) )
381  {
382  int res = QMessageBox::warning( this, tr( "Save symbol" ),
383  tr( "Symbol with name '%1' already exists. Overwrite?" )
384  .arg( name ),
385  QMessageBox::Yes | QMessageBox::No );
386  if ( res != QMessageBox::Yes )
387  {
388  return;
389  }
390  }
391 
392  // add new symbol to style and re-populate the list
393  mStyle->addSymbol( name, mSymbol->clone() );
394 
395  // make sure the symbol is stored
396  mStyle->saveSymbol( name, mSymbol->clone(), 0, QStringList() );
397  populateSymbolView();
398 }
399 
401 {
402  QgsStyleSaveDialog saveDlg( this );
403  if ( !saveDlg.exec() )
404  return;
405 
406  if ( saveDlg.name().isEmpty() )
407  return;
408 
409  // check if there is no symbol with same name
410  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
411  {
412  int res = QMessageBox::warning( this, tr( "Save symbol" ),
413  tr( "Symbol with name '%1' already exists. Overwrite?" )
414  .arg( saveDlg.name() ),
415  QMessageBox::Yes | QMessageBox::No );
416  if ( res != QMessageBox::Yes )
417  {
418  return;
419  }
420  mStyle->removeSymbol( saveDlg.name() );
421  }
422 
423  QStringList symbolTags = saveDlg.tags().split( ',' );
424 
425  // add new symbol to style and re-populate the list
426  mStyle->addSymbol( saveDlg.name(), mSymbol->clone() );
427 
428  // make sure the symbol is stored
429  mStyle->saveSymbol( saveDlg.name(), mSymbol->clone(), saveDlg.isFavorite(), symbolTags );
430 }
431 
433 {
434  if ( mSymbol )
435  {
436 
437  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
438  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
439 
440  emit changed();
441  }
442 }
443 
445 {
446  if ( mSymbol )
447  {
448  double alpha = 1 - ( value / 255.0 );
449  mSymbol->setAlpha( alpha );
450  displayTransparency( alpha );
451  emit changed();
452  }
453 }
454 
455 void QgsSymbolsListWidget::displayTransparency( double alpha )
456 {
457  double transparencyPercent = ( 1 - alpha ) * 100;
458  mTransparencyLabel->setText( tr( "Transparency %1%" ).arg(( int ) transparencyPercent ) );
459 }
460 
461 void QgsSymbolsListWidget::updateSymbolColor()
462 {
463  btnColor->blockSignals( true );
464  btnColor->setColor( mSymbol->color() );
465  btnColor->blockSignals( false );
466 }
467 
468 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
469 {
470  if ( mContext.expressionContext() )
471  return QgsExpressionContext( *mContext.expressionContext() );
472 
473  //otherwise create a default symbol context
474  QgsExpressionContext expContext;
478 
479  if ( mContext.mapCanvas() )
480  {
483  }
484  else
485  {
487  }
488 
489  expContext << QgsExpressionContextUtils::layerScope( layer() );
490 
491  // additional scopes
492  Q_FOREACH ( const QgsExpressionContextScope& scope, mContext.additionalExpressionContextScopes() )
493  {
494  expContext.appendScope( new QgsExpressionContextScope( scope ) );
495  }
496 
501 
502  return expContext;
503 }
504 
505 void QgsSymbolsListWidget::updateSymbolInfo()
506 {
507  updateSymbolColor();
508 
509  Q_FOREACH ( QgsDataDefinedButton* button, findChildren< QgsDataDefinedButton* >() )
510  {
511  button->registerExpressionContextGenerator( this );
512  }
513 
514  if ( mSymbol->type() == QgsSymbol::Marker )
515  {
516  QgsMarkerSymbol* markerSymbol = static_cast<QgsMarkerSymbol*>( mSymbol );
517  spinSize->setValue( markerSymbol->size() );
518  spinAngle->setValue( markerSymbol->angle() );
519 
520  if ( mLayer )
521  {
522  QgsDataDefined ddSize = markerSymbol->dataDefinedSize();
523  mSizeDDBtn->init( mLayer, &ddSize, QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doublePosDesc() );
524  spinSize->setEnabled( !mSizeDDBtn->isActive() );
525  QgsDataDefined ddAngle( markerSymbol->dataDefinedAngle() );
526  mRotationDDBtn->init( mLayer, &ddAngle, QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
527  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
528  }
529  else
530  {
531  mSizeDDBtn->setEnabled( false );
532  mRotationDDBtn->setEnabled( false );
533  }
534  }
535  else if ( mSymbol->type() == QgsSymbol::Line )
536  {
537  QgsLineSymbol* lineSymbol = static_cast<QgsLineSymbol*>( mSymbol );
538  spinWidth->setValue( lineSymbol->width() );
539 
540  if ( mLayer )
541  {
542  QgsDataDefined dd( lineSymbol->dataDefinedWidth() );
543  mWidthDDBtn->init( mLayer, &dd, QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
544  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
545  }
546  else
547  {
548  mWidthDDBtn->setEnabled( false );
549  }
550  }
551 
552  mSymbolUnitWidget->blockSignals( true );
553  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
554  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
555  mSymbolUnitWidget->blockSignals( false );
556 
557  mTransparencySlider->blockSignals( true );
558  double transparency = 1 - mSymbol->alpha();
559  mTransparencySlider->setValue( transparency * 255 );
560  displayTransparency( mSymbol->alpha() );
561  mTransparencySlider->blockSignals( false );
562 
563  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
564  {
565  //add clip features option for line or fill symbols
566  btnAdvanced->menu()->addAction( mClipFeaturesAction );
567  }
568  else
569  {
570  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
571  }
572  btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
573 
574  mClipFeaturesAction->blockSignals( true );
575  mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
576  mClipFeaturesAction->blockSignals( false );
577 }
578 
580 {
581  QString symbolName = index.data( Qt::UserRole ).toString();
582  lblSymbolName->setText( symbolName );
583  // get new instance of symbol from style
584  QgsSymbol* s = mStyle->symbol( symbolName );
585  // remove all symbol layers from original symbolgroupsCombo
586  while ( mSymbol->symbolLayerCount() )
587  mSymbol->deleteSymbolLayer( 0 );
588  // move all symbol layers to our symbol
589  while ( s->symbolLayerCount() )
590  {
591  QgsSymbolLayer* sl = s->takeSymbolLayer( 0 );
592  mSymbol->appendSymbolLayer( sl );
593  }
594  mSymbol->setAlpha( s->alpha() );
595 
596  // delete the temporary symbol
597  delete s;
598 
599  updateSymbolInfo();
600  emit changed();
601 }
602 
604 {
605  QSettings settings;
606  settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );
607 
608  populateSymbolView();
609 }
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.
static unsigned index
void on_mTransparencySlider_valueChanged(int value)
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.
A container class for data source field mapping or expression.
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:258
Calculate scale by the diameter.
Definition: qgssymbol.h:80
static QString doublePosDesc()
a dialog for setting properties of a newly saved style.
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:566
bool appendSymbolLayer(QgsSymbolLayer *layer)
Append symbol layer at the end of the list Ownership will be transferred.
Definition: qgssymbol.cpp:341
QgsDataDefined dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1149
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbol.h:228
void setAngle(double angle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1086
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbol.cpp:226
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:1194
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:258
void setMarkerSize(double size)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
Definition: qgssymbol.cpp:351
Line symbol.
Definition: qgssymbol.h:69
QList< RenderUnit > RenderUnitList
List of render units.
Definition: qgsunittypes.h:102
void populateGroups()
Pupulates the groups combo box with available tags and smartgroups.
The QgsMapSettings class contains configuration for rendering of the map.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:205
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:250
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, const QgsVectorLayer *layer=nullptr)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
virtual void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void setDataDefinedWidth(const QgsDataDefined &dd)
Set data defined width for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1557
QStringList symbolNames()
Returns a list of names of symbols.
Definition: qgsstyle.cpp:188
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
void setWidth(double width)
Definition: qgssymbol.cpp:1512
double width() const
Definition: qgssymbol.cpp:1538
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.
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:123
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)
QgsDataDefined dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1330
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1385
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QgsDataDefinedAssistant * assistant()
Returns the assistant used to defined the data defined object properties, if set. ...
Single scope for storing variables and functions for use within a QgsExpressionContext.
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbol.h:226
A button for defining data source field mappings or expressions.
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
void on_groupsCombo_currentIndexChanged(int index)
virtual ~QgsSymbolsListWidget()
Destructor.
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
Definition: qgsstyle.cpp:1275
int smartgroupId(const QString &smartgroup)
Returns the DB id for the given smartgroup name.
Definition: qgsstyle.cpp:1175
QStringList smartgroupNames()
Returns the smart groups list.
Definition: qgsstyle.cpp:1250
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
Definition: qgsstyle.cpp:1170
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, eg the associated map canvas and expression con...
QgsDataDefined dataDefinedWidth() const
Returns data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1592
Marker symbol.
Definition: qgssymbol.h:68
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol&#39;s ownership.
Definition: qgsstyle.cpp:89
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:635
Fill symbol.
Definition: qgssymbol.h:70
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
Definition: qgsmapcanvas.h:417
void symbolAddedToStyle(const QString &name, QgsSymbol *symbol)
SymbolType type() const
Definition: qgssymbol.h:96
virtual QgsSymbol * clone() const =0
Get a deep copy of this symbol.
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:1217
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setDataDefinedSize(const QgsDataDefined &dd)
Set data defined size for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1294
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, eg the associated map canvas and expression ...
bool isFavorite() const
returns whether the favorite element is checked
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
QgsSymbolLayer * takeSymbolLayer(int index)
Remove symbol layer from the list and return pointer to it.
Definition: qgssymbol.cpp:362
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:172
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
Definition: qgsstyle.cpp:113
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context&#39;s extent...
Definition: qgssymbol.h:248
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition: qgsstyle.cpp:144
bool hasDefaultValues() const
Returns whether the data defined container is set to all the default values, ie, disabled, with empty expression and no assigned field.
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.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cc:857
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:529
double angle() const
Returns the marker angle for the whole symbol.
Definition: qgssymbol.cpp:1098
void setDataDefinedAngle(const QgsDataDefined &dd)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1121
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