QGIS API Documentation  3.0.2-Girona (307d082)
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 #include "qgssvgcache.h"
33 
34 #include <QAction>
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 
46 
47 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
48  : QWidget( parent )
49  , mSymbol( symbol )
50  , mStyle( style )
51  , mLayer( layer )
52 {
53  setupUi( this );
54  connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
55  connect( groupsCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
56  spinAngle->setClearValue( 0 );
57 
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(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );
79 
82 
83  connect( openStyleManagerButton, &QPushButton::pressed, this, &QgsSymbolsListWidget::openStyleManager );
84 
85  lblSymbolName->clear();
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() );
98  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
99  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
100  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
101 
102  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
104  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
106  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
108 
109  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
110  updateAssistantSymbol();
111 
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  // when a remote svg has been fetched, update the widget's previews
120  // this is required if the symbol utilizes remote svgs, and the current previews
121  // have been generated using the temporary "downloading" svg. In this case
122  // we require the preview to be regenerated to use the correct fetched
123  // svg
124  connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsSymbolsListWidget::populateSymbolView );
125 }
126 
128 {
129  // This action was added to the menu by this widget, clean it up
130  // The menu can be passed in the constructor, so may live longer than this widget
131  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
132 }
133 
134 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
135 {
136  button->setProperty( "propertyKey", key );
137  button->registerExpressionContextGenerator( this );
138 
139  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
140 }
141 
142 void QgsSymbolsListWidget::createAuxiliaryField()
143 {
144  // try to create an auxiliary layer if not yet created
145  if ( !mLayer->auxiliaryLayer() )
146  {
147  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
148  dlg.exec();
149  }
150 
151  // return if still not exists
152  if ( !mLayer->auxiliaryLayer() )
153  return;
154 
155  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
156  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
158 
159  // create property in auxiliary storage if necessary
160  if ( !mLayer->auxiliaryLayer()->exists( def ) )
161  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
162 
163  // update property with join field name from auxiliary storage
164  QgsProperty property = button->toProperty();
165  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
166  property.setActive( true );
167  button->updateFieldLists();
168  button->setToProperty( property );
169 
170  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
171  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
172  switch ( key )
173  {
175  if ( markerSymbol )
176  markerSymbol->setDataDefinedAngle( button->toProperty() );
177  break;
179  if ( markerSymbol )
180  {
181  markerSymbol->setDataDefinedSize( button->toProperty() );
182  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
183  }
184  break;
186  if ( lineSymbol )
187  lineSymbol->setDataDefinedWidth( button->toProperty() );
188  default:
189  break;
190  }
191 
192  emit changed();
193 }
194 
196 {
197  mContext = context;
198  Q_FOREACH ( QgsUnitSelectionWidget *unitWidget, findChildren<QgsUnitSelectionWidget *>() )
199  {
200  unitWidget->setMapCanvas( mContext.mapCanvas() );
201  }
202 #if 0
203  Q_FOREACH ( QgsPropertyOverrideButton *ddButton, findChildren<QgsPropertyOverrideButton *>() )
204  {
205  if ( ddButton->assistant() )
206  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
207  }
208 #endif
209 }
210 
212 {
213  return mContext;
214 }
215 
217 {
218  groupsCombo->blockSignals( true );
219  groupsCombo->clear();
220 
221  groupsCombo->addItem( tr( "Favorites" ), QVariant( "favorite" ) );
222  groupsCombo->addItem( tr( "All Symbols" ), QVariant( "all" ) );
223 
224  int index = 2;
225  QStringList tags = mStyle->tags();
226  if ( tags.count() > 0 )
227  {
228  tags.sort();
229  groupsCombo->insertSeparator( index );
230  Q_FOREACH ( const QString &tag, tags )
231  {
232  groupsCombo->addItem( tag, QVariant( "tag" ) );
233  index++;
234  }
235  }
236 
237  QStringList groups = mStyle->smartgroupNames();
238  if ( groups.count() > 0 )
239  {
240  groups.sort();
241  groupsCombo->insertSeparator( index + 1 );
242  Q_FOREACH ( const QString &group, groups )
243  {
244  groupsCombo->addItem( group, QVariant( "smartgroup" ) );
245  }
246  }
247  groupsCombo->blockSignals( false );
248 
249  QgsSettings settings;
250  index = settings.value( QStringLiteral( "qgis/symbolsListGroupsIndex" ), 0 ).toInt();
251  groupsCombo->setCurrentIndex( index );
252 
253  populateSymbolView();
254 }
255 
256 void QgsSymbolsListWidget::populateSymbolView()
257 {
258  QStringList symbols;
259  QString text = groupsCombo->currentText();
260  int id;
261 
262  if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
263  {
264  symbols = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
265  }
266  else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
267  {
268  symbols = mStyle->symbolNames();
269  }
270  else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
271  {
272  id = mStyle->smartgroupId( text );
273  symbols = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, id );
274  }
275  else
276  {
277  id = mStyle->tagId( text );
278  symbols = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, id );
279  }
280 
281  symbols.sort();
282  populateSymbols( symbols );
283 }
284 
285 void QgsSymbolsListWidget::populateSymbols( const QStringList &names )
286 {
287  QSize previewSize = viewSymbols->iconSize();
288 
289  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( viewSymbols->model() );
290  if ( !model )
291  {
292  return;
293  }
294  model->clear();
295 
296  for ( int i = 0; i < names.count(); i++ )
297  {
298  QgsSymbol *s = mStyle->symbol( names[i] );
299  if ( s->type() != mSymbol->type() )
300  {
301  delete s;
302  continue;
303  }
304  QStringList tags = mStyle->tagsOfSymbol( QgsStyle::SymbolEntity, names[i] );
305  QStandardItem *item = new QStandardItem( names[i] );
306  item->setData( names[i], Qt::UserRole ); //so we can load symbol with that name
307  item->setText( names[i] );
308  item->setToolTip( QStringLiteral( "<b>%1</b><br><i>%2</i>" ).arg( names[i], tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) ) );
309  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
310  // Set font to 10points to show reasonable text
311  QFont itemFont = item->font();
312  itemFont.setPointSize( 10 );
313  item->setFont( itemFont );
314  // create preview icon
315  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
316  item->setIcon( icon );
317  // add to model
318  model->appendRow( item );
319  delete s;
320  }
321 }
322 
324 {
325  QgsStyleManagerDialog dlg( mStyle, this );
326  dlg.exec();
327 
328  populateSymbolView();
329 }
330 
332 {
333  if ( !mSymbol )
334  return;
335 
336  mSymbol->setClipFeaturesToExtent( checked );
337  emit changed();
338 }
339 
340 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
341 {
342  mSymbol->setColor( color );
343  emit changed();
344 }
345 
347 {
348  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
349  if ( markerSymbol->angle() == angle )
350  return;
351  markerSymbol->setAngle( angle );
352  emit changed();
353 }
354 
356 {
357  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
358  QgsProperty dd( mRotationDDBtn->toProperty() );
359 
360  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
361 
362  QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
363 
364  if ( // shall we remove datadefined expressions for layers ?
365  ( !symbolDD && !dd )
366  // shall we set the "en masse" expression for properties ?
367  || dd )
368  {
369  markerSymbol->setDataDefinedAngle( dd );
370  emit changed();
371  }
372 }
373 
375 {
376  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
377  if ( markerSymbol->size() == size )
378  return;
379  markerSymbol->setSize( size );
380  emit changed();
381 }
382 
384 {
385  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
386  QgsProperty dd( mSizeDDBtn->toProperty() );
387 
388  spinSize->setEnabled( !mSizeDDBtn->isActive() );
389 
390  QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
391 
392  if ( // shall we remove datadefined expressions for layers ?
393  ( !symbolDD && !dd )
394  // shall we set the "en masse" expression for properties ?
395  || dd )
396  {
397  markerSymbol->setDataDefinedSize( dd );
398  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
399  emit changed();
400  }
401 }
402 
404 {
405  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
406  if ( lineSymbol->width() == width )
407  return;
408  lineSymbol->setWidth( width );
409  emit changed();
410 }
411 
413 {
414  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
415  QgsProperty dd( mWidthDDBtn->toProperty() );
416 
417  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
418 
419  QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
420 
421  if ( // shall we remove datadefined expressions for layers ?
422  ( !symbolDD && !dd )
423  // shall we set the "en masse" expression for properties ?
424  || dd )
425  {
426  lineSymbol->setDataDefinedWidth( dd );
427  emit changed();
428  }
429 }
430 
431 void QgsSymbolsListWidget::updateAssistantSymbol()
432 {
433  mAssistantSymbol.reset( mSymbol->clone() );
434  if ( mSymbol->type() == QgsSymbol::Marker )
435  mSizeDDBtn->setSymbol( mAssistantSymbol );
436  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
437  mWidthDDBtn->setSymbol( mAssistantSymbol );
438 }
439 
440 void QgsSymbolsListWidget::symbolAddedToStyle( const QString &name, QgsSymbol *symbol )
441 {
442  Q_UNUSED( name );
443  Q_UNUSED( symbol );
444  populateSymbolView();
445 }
446 
448 {
449  bool ok;
450  QString name = QInputDialog::getText( this, tr( "Symbol name" ),
451  tr( "Please enter name for the symbol:" ), QLineEdit::Normal, tr( "New symbol" ), &ok );
452  if ( !ok || name.isEmpty() )
453  return;
454 
455  // check if there is no symbol with same name
456  if ( mStyle->symbolNames().contains( name ) )
457  {
458  int res = QMessageBox::warning( this, tr( "Save symbol" ),
459  tr( "Symbol with name '%1' already exists. Overwrite?" )
460  .arg( name ),
461  QMessageBox::Yes | QMessageBox::No );
462  if ( res != QMessageBox::Yes )
463  {
464  return;
465  }
466  }
467 
468  // add new symbol to style and re-populate the list
469  mStyle->addSymbol( name, mSymbol->clone() );
470 
471  // make sure the symbol is stored
472  mStyle->saveSymbol( name, mSymbol->clone(), false, QStringList() );
473  populateSymbolView();
474 }
475 
477 {
478  QgsStyleSaveDialog saveDlg( this );
479  if ( !saveDlg.exec() )
480  return;
481 
482  if ( saveDlg.name().isEmpty() )
483  return;
484 
485  // check if there is no symbol with same name
486  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
487  {
488  int res = QMessageBox::warning( this, tr( "Save symbol" ),
489  tr( "Symbol with name '%1' already exists. Overwrite?" )
490  .arg( saveDlg.name() ),
491  QMessageBox::Yes | QMessageBox::No );
492  if ( res != QMessageBox::Yes )
493  {
494  return;
495  }
496  mStyle->removeSymbol( saveDlg.name() );
497  }
498 
499  QStringList symbolTags = saveDlg.tags().split( ',' );
500 
501  // add new symbol to style and re-populate the list
502  mStyle->addSymbol( saveDlg.name(), mSymbol->clone() );
503 
504  // make sure the symbol is stored
505  mStyle->saveSymbol( saveDlg.name(), mSymbol->clone(), saveDlg.isFavorite(), symbolTags );
506 }
507 
508 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
509 {
510  if ( mSymbol )
511  {
512 
513  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
514  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
515 
516  emit changed();
517  }
518 }
519 
520 void QgsSymbolsListWidget::opacityChanged( double opacity )
521 {
522  if ( mSymbol )
523  {
524  mSymbol->setOpacity( opacity );
525  emit changed();
526  }
527 }
528 
529 void QgsSymbolsListWidget::updateSymbolColor()
530 {
531  btnColor->blockSignals( true );
532  btnColor->setColor( mSymbol->color() );
533  btnColor->blockSignals( false );
534 }
535 
536 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
537 {
538  if ( mContext.expressionContext() )
539  return QgsExpressionContext( *mContext.expressionContext() );
540 
541  //otherwise create a default symbol context
542  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
543 
544  // additional scopes
545  Q_FOREACH ( const QgsExpressionContextScope &scope, mContext.additionalExpressionContextScopes() )
546  {
547  expContext.appendScope( new QgsExpressionContextScope( scope ) );
548  }
549 
550  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
554 
555  return expContext;
556 }
557 
558 void QgsSymbolsListWidget::updateSymbolInfo()
559 {
560  updateSymbolColor();
561 
562  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
563  {
564  button->registerExpressionContextGenerator( this );
565  }
566 
567  if ( mSymbol->type() == QgsSymbol::Marker )
568  {
569  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
570  spinSize->setValue( markerSymbol->size() );
571  spinAngle->setValue( markerSymbol->angle() );
572 
573  if ( mLayer )
574  {
575  QgsProperty ddSize( markerSymbol->dataDefinedSize() );
576  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
577  spinSize->setEnabled( !mSizeDDBtn->isActive() );
578  QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
579  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
580  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
581  }
582  else
583  {
584  mSizeDDBtn->setEnabled( false );
585  mRotationDDBtn->setEnabled( false );
586  }
587  }
588  else if ( mSymbol->type() == QgsSymbol::Line )
589  {
590  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
591  spinWidth->setValue( lineSymbol->width() );
592 
593  if ( mLayer )
594  {
595  QgsProperty dd( lineSymbol->dataDefinedWidth() );
596  mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
597  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
598  }
599  else
600  {
601  mWidthDDBtn->setEnabled( false );
602  }
603  }
604 
605  mSymbolUnitWidget->blockSignals( true );
606  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
607  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
608  mSymbolUnitWidget->blockSignals( false );
609 
610  mOpacityWidget->setOpacity( mSymbol->opacity() );
611 
612  // Remove all previous clip actions
613  const QList<QAction *> actionList( btnAdvanced->menu()->actions() );
614  for ( const auto &action : actionList )
615  {
616  if ( mClipFeaturesAction->text() == action->text() )
617  {
618  btnAdvanced->menu()->removeAction( action );
619  }
620  }
621 
622  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
623  {
624  //add clip features option for line or fill symbols
625  btnAdvanced->menu()->addAction( mClipFeaturesAction );
626  }
627 
628  btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
629 
630  mClipFeaturesAction->blockSignals( true );
631  mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
632  mClipFeaturesAction->blockSignals( false );
633 }
634 
635 void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex &index )
636 {
637  QString symbolName = index.data( Qt::UserRole ).toString();
638  lblSymbolName->setText( symbolName );
639  // get new instance of symbol from style
640  QgsSymbol *s = mStyle->symbol( symbolName );
641  // remove all symbol layers from original symbolgroupsCombo
642  while ( mSymbol->symbolLayerCount() )
643  mSymbol->deleteSymbolLayer( 0 );
644  // move all symbol layers to our symbol
645  while ( s->symbolLayerCount() )
646  {
647  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
648  mSymbol->appendSymbolLayer( sl );
649  }
650  mSymbol->setOpacity( s->opacity() );
651 
652  // delete the temporary symbol
653  delete s;
654 
655  updateSymbolInfo();
656  emit changed();
657 }
658 
659 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged( int index )
660 {
661  QgsSettings settings;
662  settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );
663 
664  populateSymbolView();
665 }
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static QgsSvgCache * svgCache()
Returns the application&#39;s SVG cache, used for caching SVG images and handling parameter replacement w...
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:258
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:57
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:355
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbol.cpp:226
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:1243
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:365
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1169
Line symbol.
Definition: qgssymbol.h:86
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1134
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:205
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:250
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:1197
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:1556
double width() const
Definition: qgssymbol.cpp:1582
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:454
void setMarkerAngle(double angle)
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1434
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:1601
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:1379
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:1266
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:376
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
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:1343
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)
Adds 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:1636
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:1146
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:445