QGIS API Documentation  3.1.0-Master (f35745f)
qgssymbolslistwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolslist.cpp
3  ---------------------
4  begin : June 2012
5  copyright : (C) 2012 by Arunmozhi
6  email : aruntheguy at gmail.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 
17 #include "qgssymbolslistwidget.h"
18 
19 #include "qgsstylemanagerdialog.h"
20 #include "qgsstylesavedialog.h"
21 
22 #include "qgssymbol.h"
23 #include "qgsstyle.h"
24 #include "qgssymbollayerutils.h"
25 #include "qgsmarkersymbollayer.h"
26 #include "qgsmapcanvas.h"
27 #include "qgsapplication.h"
28 #include "qgsvectorlayer.h"
29 #include "qgssettings.h"
31 #include "qgsauxiliarystorage.h"
32 
33 #include <QAction>
34 #include <QString>
35 #include <QStringList>
36 #include <QPainter>
37 #include <QIcon>
38 #include <QStandardItemModel>
39 #include <QColorDialog>
40 #include <QInputDialog>
41 #include <QMessageBox>
42 #include <QMenu>
43 #include <QPushButton>
44 
45 
46 QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
47  : QWidget( parent )
48  , mSymbol( symbol )
49  , mStyle( style )
50  , mLayer( layer )
51 {
52  setupUi( this );
53  connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
54  connect( groupsCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
55  spinAngle->setClearValue( 0 );
56 
59 
60  btnAdvanced->hide(); // advanced button is hidden by default
61  if ( menu ) // show it if there is a menu pointer
62  {
63  mAdvancedMenu = menu;
64  btnAdvanced->show();
65  btnAdvanced->setMenu( mAdvancedMenu );
66  }
67  else
68  {
69  btnAdvanced->setMenu( new QMenu( this ) );
70  }
71  mClipFeaturesAction = new QAction( tr( "Clip features to canvas extent" ), this );
72  mClipFeaturesAction->setCheckable( true );
73  connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
74 
75  QStandardItemModel *model = new QStandardItemModel( viewSymbols );
76  viewSymbols->setModel( model );
77  connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsSymbolsListWidget::setSymbolFromStyle );
78 
81 
82  connect( openStyleManagerButton, &QPushButton::pressed, this, &QgsSymbolsListWidget::openStyleManager );
83 
84  lblSymbolName->clear();
85 
87 
88  if ( mSymbol )
89  {
90  updateSymbolInfo();
91  }
92 
93  // select correct page in stacked widget
94  // there's a correspondence between symbol type number and page numbering => exploit it!
95  stackedWidget->setCurrentIndex( symbol->type() );
97  connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
98  connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
99  connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
100 
101  registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::PropertyAngle );
103  registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::PropertySize );
105  registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::PropertyStrokeWidth );
107 
108  connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
109  updateAssistantSymbol();
110 
111  btnColor->setAllowOpacity( true );
112  btnColor->setColorDialogTitle( tr( "Select Color" ) );
113  btnColor->setContext( QStringLiteral( "symbology" ) );
114  connect( btnSaveSymbol, &QPushButton::clicked, this, &QgsSymbolsListWidget::saveSymbol );
115 
116  connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
117 }
118 
120 {
121  // This action was added to the menu by this widget, clean it up
122  // The menu can be passed in the constructor, so may live longer than this widget
123  btnAdvanced->menu()->removeAction( mClipFeaturesAction );
124 }
125 
126 void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
127 {
128  button->setProperty( "propertyKey", key );
129  button->registerExpressionContextGenerator( this );
130 
131  connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
132 }
133 
134 void QgsSymbolsListWidget::createAuxiliaryField()
135 {
136  // try to create an auxiliary layer if not yet created
137  if ( !mLayer->auxiliaryLayer() )
138  {
139  QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
140  dlg.exec();
141  }
142 
143  // return if still not exists
144  if ( !mLayer->auxiliaryLayer() )
145  return;
146 
147  QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
148  QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
150 
151  // create property in auxiliary storage if necessary
152  if ( !mLayer->auxiliaryLayer()->exists( def ) )
153  mLayer->auxiliaryLayer()->addAuxiliaryField( def );
154 
155  // update property with join field name from auxiliary storage
156  QgsProperty property = button->toProperty();
157  property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
158  property.setActive( true );
159  button->updateFieldLists();
160  button->setToProperty( property );
161 
162  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
163  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
164  switch ( key )
165  {
167  if ( markerSymbol )
168  markerSymbol->setDataDefinedAngle( button->toProperty() );
169  break;
171  if ( markerSymbol )
172  {
173  markerSymbol->setDataDefinedSize( button->toProperty() );
174  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
175  }
176  break;
178  if ( lineSymbol )
179  lineSymbol->setDataDefinedWidth( button->toProperty() );
180  default:
181  break;
182  }
183 
184  emit changed();
185 }
186 
188 {
189  mContext = context;
190  Q_FOREACH ( QgsUnitSelectionWidget *unitWidget, findChildren<QgsUnitSelectionWidget *>() )
191  {
192  unitWidget->setMapCanvas( mContext.mapCanvas() );
193  }
194 #if 0
195  Q_FOREACH ( QgsPropertyOverrideButton *ddButton, findChildren<QgsPropertyOverrideButton *>() )
196  {
197  if ( ddButton->assistant() )
198  ddButton->assistant()->setMapCanvas( mContext.mapCanvas() );
199  }
200 #endif
201 }
202 
204 {
205  return mContext;
206 }
207 
209 {
210  groupsCombo->blockSignals( true );
211  groupsCombo->clear();
212 
213  groupsCombo->addItem( tr( "Favorites" ), QVariant( "favorite" ) );
214  groupsCombo->addItem( tr( "All Symbols" ), QVariant( "all" ) );
215 
216  int index = 2;
217  QStringList tags = mStyle->tags();
218  if ( tags.count() > 0 )
219  {
220  tags.sort();
221  groupsCombo->insertSeparator( index );
222  Q_FOREACH ( const QString &tag, tags )
223  {
224  groupsCombo->addItem( tag, QVariant( "tag" ) );
225  index++;
226  }
227  }
228 
229  QStringList groups = mStyle->smartgroupNames();
230  if ( groups.count() > 0 )
231  {
232  groups.sort();
233  groupsCombo->insertSeparator( index + 1 );
234  Q_FOREACH ( const QString &group, groups )
235  {
236  groupsCombo->addItem( group, QVariant( "smartgroup" ) );
237  }
238  }
239  groupsCombo->blockSignals( false );
240 
241  QgsSettings settings;
242  index = settings.value( QStringLiteral( "qgis/symbolsListGroupsIndex" ), 0 ).toInt();
243  groupsCombo->setCurrentIndex( index );
244 
245  populateSymbolView();
246 }
247 
248 void QgsSymbolsListWidget::populateSymbolView()
249 {
250  QStringList symbols;
251  QString text = groupsCombo->currentText();
252  int id;
253 
254  if ( groupsCombo->currentData().toString() == QLatin1String( "favorite" ) )
255  {
256  symbols = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
257  }
258  else if ( groupsCombo->currentData().toString() == QLatin1String( "all" ) )
259  {
260  symbols = mStyle->symbolNames();
261  }
262  else if ( groupsCombo->currentData().toString() == QLatin1String( "smartgroup" ) )
263  {
264  id = mStyle->smartgroupId( text );
265  symbols = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, id );
266  }
267  else
268  {
269  id = mStyle->tagId( text );
270  symbols = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, id );
271  }
272 
273  symbols.sort();
274  populateSymbols( symbols );
275 }
276 
277 void QgsSymbolsListWidget::populateSymbols( const QStringList &names )
278 {
279  QSize previewSize = viewSymbols->iconSize();
280 
281  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( viewSymbols->model() );
282  if ( !model )
283  {
284  return;
285  }
286  model->clear();
287 
288  for ( int i = 0; i < names.count(); i++ )
289  {
290  QgsSymbol *s = mStyle->symbol( names[i] );
291  if ( s->type() != mSymbol->type() )
292  {
293  delete s;
294  continue;
295  }
296  QStringList tags = mStyle->tagsOfSymbol( QgsStyle::SymbolEntity, names[i] );
297  QStandardItem *item = new QStandardItem( names[i] );
298  item->setData( names[i], Qt::UserRole ); //so we can load symbol with that name
299  item->setText( names[i] );
300  item->setToolTip( QStringLiteral( "<b>%1</b><br><i>%2</i>" ).arg( names[i], tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) ) );
301  item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
302  // Set font to 10points to show reasonable text
303  QFont itemFont = item->font();
304  itemFont.setPointSize( 10 );
305  item->setFont( itemFont );
306  // create preview icon
307  QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( s, previewSize, 15 );
308  item->setIcon( icon );
309  // add to model
310  model->appendRow( item );
311  delete s;
312  }
313 }
314 
316 {
317  QgsStyleManagerDialog dlg( mStyle, this );
318  dlg.exec();
319 
320  populateSymbolView();
321 }
322 
324 {
325  if ( !mSymbol )
326  return;
327 
328  mSymbol->setClipFeaturesToExtent( checked );
329  emit changed();
330 }
331 
332 void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
333 {
334  mSymbol->setColor( color );
335  emit changed();
336 }
337 
339 {
340  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
341  if ( markerSymbol->angle() == angle )
342  return;
343  markerSymbol->setAngle( angle );
344  emit changed();
345 }
346 
348 {
349  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
350  QgsProperty dd( mRotationDDBtn->toProperty() );
351 
352  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
353 
354  QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
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  markerSymbol->setDataDefinedAngle( dd );
362  emit changed();
363  }
364 }
365 
367 {
368  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
369  if ( markerSymbol->size() == size )
370  return;
371  markerSymbol->setSize( size );
372  emit changed();
373 }
374 
376 {
377  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
378  QgsProperty dd( mSizeDDBtn->toProperty() );
379 
380  spinSize->setEnabled( !mSizeDDBtn->isActive() );
381 
382  QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
383 
384  if ( // shall we remove datadefined expressions for layers ?
385  ( !symbolDD && !dd )
386  // shall we set the "en masse" expression for properties ?
387  || dd )
388  {
389  markerSymbol->setDataDefinedSize( dd );
390  markerSymbol->setScaleMethod( QgsSymbol::ScaleDiameter );
391  emit changed();
392  }
393 }
394 
396 {
397  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
398  if ( lineSymbol->width() == width )
399  return;
400  lineSymbol->setWidth( width );
401  emit changed();
402 }
403 
405 {
406  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
407  QgsProperty dd( mWidthDDBtn->toProperty() );
408 
409  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
410 
411  QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
412 
413  if ( // shall we remove datadefined expressions for layers ?
414  ( !symbolDD && !dd )
415  // shall we set the "en masse" expression for properties ?
416  || dd )
417  {
418  lineSymbol->setDataDefinedWidth( dd );
419  emit changed();
420  }
421 }
422 
423 void QgsSymbolsListWidget::updateAssistantSymbol()
424 {
425  mAssistantSymbol.reset( mSymbol->clone() );
426  if ( mSymbol->type() == QgsSymbol::Marker )
427  mSizeDDBtn->setSymbol( mAssistantSymbol );
428  else if ( mSymbol->type() == QgsSymbol::Line && mLayer )
429  mWidthDDBtn->setSymbol( mAssistantSymbol );
430 }
431 
432 void QgsSymbolsListWidget::symbolAddedToStyle( const QString &name, QgsSymbol *symbol )
433 {
434  Q_UNUSED( name );
435  Q_UNUSED( symbol );
436  populateSymbolView();
437 }
438 
440 {
441  bool ok;
442  QString name = QInputDialog::getText( this, tr( "Symbol name" ),
443  tr( "Please enter name for the symbol:" ), QLineEdit::Normal, tr( "New symbol" ), &ok );
444  if ( !ok || name.isEmpty() )
445  return;
446 
447  // check if there is no symbol with same name
448  if ( mStyle->symbolNames().contains( name ) )
449  {
450  int res = QMessageBox::warning( this, tr( "Save symbol" ),
451  tr( "Symbol with name '%1' already exists. Overwrite?" )
452  .arg( name ),
453  QMessageBox::Yes | QMessageBox::No );
454  if ( res != QMessageBox::Yes )
455  {
456  return;
457  }
458  }
459 
460  // add new symbol to style and re-populate the list
461  mStyle->addSymbol( name, mSymbol->clone() );
462 
463  // make sure the symbol is stored
464  mStyle->saveSymbol( name, mSymbol->clone(), false, QStringList() );
465  populateSymbolView();
466 }
467 
469 {
470  QgsStyleSaveDialog saveDlg( this );
471  if ( !saveDlg.exec() )
472  return;
473 
474  if ( saveDlg.name().isEmpty() )
475  return;
476 
477  // check if there is no symbol with same name
478  if ( mStyle->symbolNames().contains( saveDlg.name() ) )
479  {
480  int res = QMessageBox::warning( this, tr( "Save symbol" ),
481  tr( "Symbol with name '%1' already exists. Overwrite?" )
482  .arg( saveDlg.name() ),
483  QMessageBox::Yes | QMessageBox::No );
484  if ( res != QMessageBox::Yes )
485  {
486  return;
487  }
488  mStyle->removeSymbol( saveDlg.name() );
489  }
490 
491  QStringList symbolTags = saveDlg.tags().split( ',' );
492 
493  // add new symbol to style and re-populate the list
494  mStyle->addSymbol( saveDlg.name(), mSymbol->clone() );
495 
496  // make sure the symbol is stored
497  mStyle->saveSymbol( saveDlg.name(), mSymbol->clone(), saveDlg.isFavorite(), symbolTags );
498 }
499 
500 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
501 {
502  if ( mSymbol )
503  {
504 
505  mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
506  mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
507 
508  emit changed();
509  }
510 }
511 
512 void QgsSymbolsListWidget::opacityChanged( double opacity )
513 {
514  if ( mSymbol )
515  {
516  mSymbol->setOpacity( opacity );
517  emit changed();
518  }
519 }
520 
521 void QgsSymbolsListWidget::updateSymbolColor()
522 {
523  btnColor->blockSignals( true );
524  btnColor->setColor( mSymbol->color() );
525  btnColor->blockSignals( false );
526 }
527 
528 QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
529 {
530  if ( mContext.expressionContext() )
531  return QgsExpressionContext( *mContext.expressionContext() );
532 
533  //otherwise create a default symbol context
534  QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes( layer() ) );
535 
536  // additional scopes
537  Q_FOREACH ( const QgsExpressionContextScope &scope, mContext.additionalExpressionContextScopes() )
538  {
539  expContext.appendScope( new QgsExpressionContextScope( scope ) );
540  }
541 
542  expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
546 
547  return expContext;
548 }
549 
550 void QgsSymbolsListWidget::updateSymbolInfo()
551 {
552  updateSymbolColor();
553 
554  Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
555  {
556  button->registerExpressionContextGenerator( this );
557  }
558 
559  if ( mSymbol->type() == QgsSymbol::Marker )
560  {
561  QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
562  spinSize->setValue( markerSymbol->size() );
563  spinAngle->setValue( markerSymbol->angle() );
564 
565  if ( mLayer )
566  {
567  QgsProperty ddSize( markerSymbol->dataDefinedSize() );
568  mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
569  spinSize->setEnabled( !mSizeDDBtn->isActive() );
570  QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
571  mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
572  spinAngle->setEnabled( !mRotationDDBtn->isActive() );
573  }
574  else
575  {
576  mSizeDDBtn->setEnabled( false );
577  mRotationDDBtn->setEnabled( false );
578  }
579  }
580  else if ( mSymbol->type() == QgsSymbol::Line )
581  {
582  QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
583  spinWidth->setValue( lineSymbol->width() );
584 
585  if ( mLayer )
586  {
587  QgsProperty dd( lineSymbol->dataDefinedWidth() );
588  mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
589  spinWidth->setEnabled( !mWidthDDBtn->isActive() );
590  }
591  else
592  {
593  mWidthDDBtn->setEnabled( false );
594  }
595  }
596 
597  mSymbolUnitWidget->blockSignals( true );
598  mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
599  mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
600  mSymbolUnitWidget->blockSignals( false );
601 
602  mOpacityWidget->setOpacity( mSymbol->opacity() );
603 
604  // Remove all previous clip actions
605  const QList<QAction *> actionList( btnAdvanced->menu()->actions() );
606  for ( const auto &action : actionList )
607  {
608  if ( mClipFeaturesAction->text() == action->text() )
609  {
610  btnAdvanced->menu()->removeAction( action );
611  }
612  }
613 
614  if ( mSymbol->type() == QgsSymbol::Line || mSymbol->type() == QgsSymbol::Fill )
615  {
616  //add clip features option for line or fill symbols
617  btnAdvanced->menu()->addAction( mClipFeaturesAction );
618  }
619 
620  btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
621 
622  mClipFeaturesAction->blockSignals( true );
623  mClipFeaturesAction->setChecked( mSymbol->clipFeaturesToExtent() );
624  mClipFeaturesAction->blockSignals( false );
625 }
626 
627 void QgsSymbolsListWidget::setSymbolFromStyle( const QModelIndex &index )
628 {
629  QString symbolName = index.data( Qt::UserRole ).toString();
630  lblSymbolName->setText( symbolName );
631  // get new instance of symbol from style
632  QgsSymbol *s = mStyle->symbol( symbolName );
633  // remove all symbol layers from original symbolgroupsCombo
634  while ( mSymbol->symbolLayerCount() )
635  mSymbol->deleteSymbolLayer( 0 );
636  // move all symbol layers to our symbol
637  while ( s->symbolLayerCount() )
638  {
639  QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
640  mSymbol->appendSymbolLayer( sl );
641  }
642  mSymbol->setOpacity( s->opacity() );
643 
644  // delete the temporary symbol
645  delete s;
646 
647  updateSymbolInfo();
648  emit changed();
649 }
650 
651 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged( int index )
652 {
653  QgsSettings settings;
654  settings.setValue( QStringLiteral( "qgis/symbolsListGroupsIndex" ), index );
655 
656  populateSymbolView();
657 }
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static const QString EXPR_CLUSTER_COLOR
Inbuilt variable name for cluster color variable.
Meters value as Map units.
Definition: qgsunittypes.h:109
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void setLineWidth(double width)
QString tags() const
returns the text value of the tags element
void symbolSaved(const QString &name, QgsSymbol *symbol)
Is emitted every time a new symbol has been added to the database.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
void setSymbolFromStyle(const QModelIndex &index)
void setMapUnitScale(const QgsMapUnitScale &scale)
Definition: qgssymbol.cpp:244
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:341
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbol.cpp:212
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:1229
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:351
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
Definition: qgssymbol.cpp:1155
Line symbol.
Definition: qgssymbol.h:86
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
Definition: qgssymbol.cpp:1120
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:191
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:236
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:1183
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:1542
double width() const
Definition: qgssymbol.cpp:1568
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:440
void setMarkerAngle(double angle)
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Definition: qgssymbol.cpp:1420
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:1587
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:1365
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:1252
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:362
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:1329
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:1622
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:1132
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:431