QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
17#include "moc_qgssymbolslistwidget.cpp"
18#include "qgsstylesavedialog.h"
20#include "qgsvectorlayer.h"
22#include "qgsauxiliarystorage.h"
23#include "qgsmarkersymbol.h"
24#include "qgslinesymbol.h"
28
29#include <QMessageBox>
30#include <QAction>
31#include <QMenu>
32
33QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
34 : QWidget( parent )
35 , mSymbol( symbol )
36 , mStyle( style )
37 , mAdvancedMenu( menu )
38 , mLayer( layer )
39{
40 setupUi( this );
41 spinAngle->setClearValue( 0 );
42
43 mStyleItemsListWidget->setStyle( mStyle );
44 mStyleItemsListWidget->setEntityType( QgsStyle::SymbolEntity );
45 if ( mSymbol )
46 mStyleItemsListWidget->setSymbolType( mSymbol->type() );
47 mStyleItemsListWidget->setAdvancedMenu( menu );
48
49 mClipFeaturesAction = new QAction( tr( "Clip Features to Canvas Extent" ), this );
50 mClipFeaturesAction->setCheckable( true );
51 connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
52 mStandardizeRingsAction = new QAction( tr( "Force Right-Hand-Rule Orientation" ), this );
53 mStandardizeRingsAction->setCheckable( true );
54 connect( mStandardizeRingsAction, &QAction::toggled, this, &QgsSymbolsListWidget::forceRHRToggled );
55
56 mBufferSettingsAction = new QAction( tr( "Buffer Settingsā€¦" ), this );
57 connect( mBufferSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showBufferSettings );
58
59 mAnimationSettingsAction = new QAction( tr( "Animation Settingsā€¦" ), this );
60 connect( mAnimationSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showAnimationSettings );
61
62 // select correct page in stacked widget
63 QgsPropertyOverrideButton *opacityDDBtn = nullptr;
64 switch ( symbol->type() )
65 {
67 {
68 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
69 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
70 mSymbolColorButton = btnMarkerColor;
71 opacityDDBtn = mMarkerOpacityDDBtn;
72 mSymbolOpacityWidget = mMarkerOpacityWidget;
73 mSymbolUnitWidget = mMarkerUnitWidget;
74 connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
75 connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
76 registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::Property::Size );
78 registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::Property::Angle );
80 break;
81 }
82
84 {
85 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
86 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
87 mSymbolColorButton = btnLineColor;
88 opacityDDBtn = mLineOpacityDDBtn;
89 mSymbolOpacityWidget = mLineOpacityWidget;
90 mSymbolUnitWidget = mLineUnitWidget;
91 connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
92 registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::Property::StrokeWidth );
94 break;
95 }
96
98 {
99 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
100 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
101 mSymbolColorButton = btnFillColor;
102 opacityDDBtn = mFillOpacityDDBtn;
103 mSymbolOpacityWidget = mFillOpacityWidget;
104 mSymbolUnitWidget = mFillUnitWidget;
105 break;
106 }
107
109 break;
110 }
111
112 stackedWidget->setCurrentIndex( 0 );
113
114 mSymbolUnitWidget->setUnits( { Qgis::RenderUnit::Millimeters,
120
121 if ( mSymbol )
122 {
123 updateSymbolInfo();
124 }
125
126 connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
127 connect( mSymbolColorButton, &QgsColorButton::colorChanged, this, &QgsSymbolsListWidget::setSymbolColor );
128
129 registerSymbolDataDefinedButton( opacityDDBtn, QgsSymbol::Property::Opacity );
130
131 connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
132 updateAssistantSymbol();
133
134 mSymbolColorButton->setAllowOpacity( true );
135 mSymbolColorButton->setColorDialogTitle( tr( "Select Color" ) );
136 mSymbolColorButton->setContext( QStringLiteral( "symbology" ) );
137
138 connect( mSymbolOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
139
140 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::selectionChangedWithStylePath, this, &QgsSymbolsListWidget::setSymbolFromStyle );
141 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbolsListWidget::saveSymbol );
142}
143
145{
146 // This action was added to the menu by this widget, clean it up
147 // The menu can be passed in the constructor, so may live longer than this widget
148 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
149 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
150 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
151 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
152}
153
154void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
155{
156 button->setProperty( "propertyKey", static_cast< int >( key ) );
158
159 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
160}
161
162void QgsSymbolsListWidget::createAuxiliaryField()
163{
164 // try to create an auxiliary layer if not yet created
165 if ( !mLayer->auxiliaryLayer() )
166 {
167 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
168 dlg.exec();
169 }
170
171 // return if still not exists
172 if ( !mLayer->auxiliaryLayer() )
173 return;
174
175 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
176 const QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
177 const QgsPropertyDefinition def = QgsSymbolLayer::propertyDefinitions()[static_cast< int >( key )];
178
179 // create property in auxiliary storage if necessary
180 if ( !mLayer->auxiliaryLayer()->exists( def ) )
181 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
182
183 // update property with join field name from auxiliary storage
184 QgsProperty property = button->toProperty();
185 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
186 property.setActive( true );
187 button->updateFieldLists();
188 button->setToProperty( property );
189
190 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
191 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
192 switch ( key )
193 {
195 if ( markerSymbol )
196 markerSymbol->setDataDefinedAngle( button->toProperty() );
197 break;
198
200 if ( markerSymbol )
201 {
202 markerSymbol->setDataDefinedSize( button->toProperty() );
204 }
205 break;
206
208 if ( lineSymbol )
209 lineSymbol->setDataDefinedWidth( button->toProperty() );
210 break;
211
212 default:
213 break;
214 }
215
216 emit changed();
217}
218
219void QgsSymbolsListWidget::createSymbolAuxiliaryField()
220{
221 // try to create an auxiliary layer if not yet created
222 if ( !mLayer->auxiliaryLayer() )
223 {
224 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
225 dlg.exec();
226 }
227
228 // return if still not exists
229 if ( !mLayer->auxiliaryLayer() )
230 return;
231
232 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
233 const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
234 const QgsPropertyDefinition def = QgsSymbol::propertyDefinitions()[static_cast< int >( key )];
235
236 // create property in auxiliary storage if necessary
237 if ( !mLayer->auxiliaryLayer()->exists( def ) )
238 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
239
240 // update property with join field name from auxiliary storage
241 QgsProperty property = button->toProperty();
242 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
243 property.setActive( true );
244 button->updateFieldLists();
245 button->setToProperty( property );
246
247 mSymbol->setDataDefinedProperty( key, button->toProperty() );
248
249 emit changed();
250}
251
253{
254 mContext = context;
255 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
256 for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
257 {
258 unitWidget->setMapCanvas( mContext.mapCanvas() );
259 }
260}
261
263{
264 return mContext;
265}
266
267void QgsSymbolsListWidget::forceRHRToggled( bool checked )
268{
269 if ( !mSymbol )
270 return;
271
272 mSymbol->setForceRHR( checked );
273 emit changed();
274}
275
276void QgsSymbolsListWidget::showAnimationSettings()
277{
279 if ( panel && panel->dockMode() )
280 {
282 widget->setPanelTitle( tr( "Animation Settings" ) );
283 widget->setAnimationSettings( mSymbol->animationSettings() );
284 connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
285 {
286 mSymbol->setAnimationSettings( widget->animationSettings() );
287 emit changed();
288 } );
289 panel->openPanel( widget );
290 return;
291 }
292
294 d.setAnimationSettings( mSymbol->animationSettings() );
295 if ( d.exec() == QDialog::Accepted )
296 {
297 mSymbol->setAnimationSettings( d.animationSettings() );
298 emit changed();
299 }
300}
301
302void QgsSymbolsListWidget::showBufferSettings()
303{
305 if ( panel && panel->dockMode() )
306 {
308 widget->setPanelTitle( tr( "Buffer Settings" ) );
309 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
310 widget->setBufferSettings( *settings );
311
312 connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
313 {
314 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( widget->bufferSettings() ) );
315 emit changed();
316 } );
317 panel->openPanel( widget );
318 return;
319 }
320
322 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
323 d.setBufferSettings( *settings );
324 if ( d.exec() == QDialog::Accepted )
325 {
326 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( d.bufferSettings() ) );
327 emit changed();
328 }
329}
330
331void QgsSymbolsListWidget::saveSymbol()
332{
333 QgsStyleSaveDialog saveDlg( this );
334 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
335 if ( !saveDlg.exec() )
336 return;
337
338 if ( saveDlg.name().isEmpty() )
339 return;
340
341 QgsStyle *style = saveDlg.destinationStyle();
342 if ( !style )
343 return;
344
345 // check if there is no symbol with same name
346 if ( style->symbolNames().contains( saveDlg.name() ) )
347 {
348 const int res = QMessageBox::warning( this, tr( "Save Symbol" ),
349 tr( "Symbol with name '%1' already exists. Overwrite?" )
350 .arg( saveDlg.name() ),
351 QMessageBox::Yes | QMessageBox::No );
352 if ( res != QMessageBox::Yes )
353 {
354 return;
355 }
356 style->removeSymbol( saveDlg.name() );
357 }
358
359 const QStringList symbolTags = saveDlg.tags().split( ',' );
360
361 // add new symbol to style and re-populate the list
362 QgsSymbol *newSymbol = mSymbol->clone();
363 style->addSymbol( saveDlg.name(), newSymbol );
364
365 // make sure the symbol is stored
366 style->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
367}
368
369void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
370{
371 if ( !mSymbol )
372 return;
373
374 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
375 const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
376 mSymbol->setDataDefinedProperty( key, button->toProperty() );
377 emit changed();
378}
379
380void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
381{
382 button->init( static_cast< int >( key ), mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
383 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
384 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
385
387}
388
390{
391 if ( !mSymbol )
392 return;
393
394 mSymbol->setClipFeaturesToExtent( checked );
395 emit changed();
396}
397
398void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
399{
400 mSymbol->setColor( color );
401 emit changed();
402}
403
405{
406 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
407 if ( markerSymbol->angle() == angle )
408 return;
409 markerSymbol->setAngle( angle );
410 emit changed();
411}
412
414{
415 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
416 const QgsProperty dd( mRotationDDBtn->toProperty() );
417
418 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
419
420 const QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
421
422 if ( // shall we remove datadefined expressions for layers ?
423 ( !symbolDD && !dd )
424 // shall we set the "en masse" expression for properties ?
425 || dd )
426 {
427 markerSymbol->setDataDefinedAngle( dd );
428 emit changed();
429 }
430}
431
433{
434 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
435 if ( markerSymbol->size() == size )
436 return;
437 markerSymbol->setSize( size );
438 emit changed();
439}
440
442{
443 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
444 const QgsProperty dd( mSizeDDBtn->toProperty() );
445
446 spinSize->setEnabled( !mSizeDDBtn->isActive() );
447
448 const QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
449
450 if ( // shall we remove datadefined expressions for layers ?
451 ( !symbolDD && !dd )
452 // shall we set the "en masse" expression for properties ?
453 || dd )
454 {
455 markerSymbol->setDataDefinedSize( dd );
457 emit changed();
458 }
459}
460
462{
463 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
464 if ( lineSymbol->width() == width )
465 return;
466 lineSymbol->setWidth( width );
467 emit changed();
468}
469
471{
472 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
473 const QgsProperty dd( mWidthDDBtn->toProperty() );
474
475 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
476
477 const QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
478
479 if ( // shall we remove datadefined expressions for layers ?
480 ( !symbolDD && !dd )
481 // shall we set the "en masse" expression for properties ?
482 || dd )
483 {
484 lineSymbol->setDataDefinedWidth( dd );
485 emit changed();
486 }
487}
488
489void QgsSymbolsListWidget::updateAssistantSymbol()
490{
491 mAssistantSymbol.reset( mSymbol->clone() );
492 if ( mSymbol->type() == Qgis::SymbolType::Marker )
493 mSizeDDBtn->setSymbol( mAssistantSymbol );
494 else if ( mSymbol->type() == Qgis::SymbolType::Line && mLayer )
495 mWidthDDBtn->setSymbol( mAssistantSymbol );
496}
497
498void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
499{
500 if ( mSymbol )
501 {
502
503 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
504 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
505
506 emit changed();
507 }
508}
509
510void QgsSymbolsListWidget::opacityChanged( double opacity )
511{
512 if ( mSymbol )
513 {
514 mSymbol->setOpacity( opacity );
515 emit changed();
516 }
517}
518
519void QgsSymbolsListWidget::updateSymbolColor()
520{
521 mSymbolColorButton->blockSignals( true );
522 mSymbolColorButton->setColor( mSymbol->color() );
523 mSymbolColorButton->blockSignals( false );
524}
525
526QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
527{
528 if ( auto *lExpressionContext = mContext.expressionContext() )
529 return QgsExpressionContext( *lExpressionContext );
530
531 //otherwise create a default symbol context
533
534 // additional scopes
535 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
536 for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
537 {
538 expContext.appendScope( new QgsExpressionContextScope( scope ) );
539 }
540
541 expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
546 << QStringLiteral( "symbol_layer_count" ) << QStringLiteral( "symbol_layer_index" )
547 << QStringLiteral( "symbol_frame" ) );
548
549 return expContext;
550}
551
552void QgsSymbolsListWidget::updateSymbolInfo()
553{
554 updateSymbolColor();
555
556 const auto overrideButtons {findChildren< QgsPropertyOverrideButton * >()};
557 for ( QgsPropertyOverrideButton *button : overrideButtons )
558 {
560 }
561
562 if ( mSymbol->type() == Qgis::SymbolType::Marker )
563 {
564 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
565 spinSize->setValue( markerSymbol->size() );
566 spinAngle->setValue( markerSymbol->angle() );
567
568 if ( mLayer )
569 {
570 const QgsProperty ddSize( markerSymbol->dataDefinedSize() );
571 mSizeDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::Size ), ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
572 spinSize->setEnabled( !mSizeDDBtn->isActive() );
573 const QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
574 mRotationDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::Angle ), ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
575 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
576 }
577 else
578 {
579 mSizeDDBtn->setEnabled( false );
580 mRotationDDBtn->setEnabled( false );
581 }
582 }
583 else if ( mSymbol->type() == Qgis::SymbolType::Line )
584 {
585 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
586 spinWidth->setValue( lineSymbol->width() );
587
588 if ( mLayer )
589 {
590 const QgsProperty dd( lineSymbol->dataDefinedWidth() );
591 mWidthDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::StrokeWidth ), dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
592 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
593 }
594 else
595 {
596 mWidthDDBtn->setEnabled( false );
597 }
598 }
599
600 mSymbolUnitWidget->blockSignals( true );
601 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
602 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
603 mSymbolUnitWidget->blockSignals( false );
604
605 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
606
607 // Clean up previous advanced symbol actions
608 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
609 for ( QAction *action : actionList )
610 {
611 for ( QAction *actionsToRemove :
612 {
613 mClipFeaturesAction,
614 mStandardizeRingsAction,
615 mAnimationSettingsAction,
616 mBufferSettingsAction
617 } )
618 {
619 if ( actionsToRemove->text() == action->text() )
620 {
621 mStyleItemsListWidget->advancedMenu()->removeAction( action );
622 break;
623 }
624 }
625 }
626
627 if ( mSymbol->type() == Qgis::SymbolType::Line || mSymbol->type() == Qgis::SymbolType::Fill )
628 {
629 //add clip features option for line or fill symbols
630 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
631 }
632 if ( mSymbol->type() == Qgis::SymbolType::Fill )
633 {
634 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
635 }
636 if ( mSymbol->type() == Qgis::SymbolType::Marker )
637 {
638 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
639 }
640 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
641
642 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
643
644 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
645 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
646}
647
648void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity, const QString &stylePath )
649{
650 if ( name.isEmpty() )
651 return;
652
653 QgsStyle *style = nullptr;
654 if ( mStyle != QgsStyle::defaultStyle() )
655 {
656 // get new instance of symbol from style
657 style = mStyle;
658 }
659 else
660 {
661 style = QgsProject::instance()->styleSettings()->styleAtPath( stylePath );
662 }
663
664 if ( !style )
665 return;
666
667 // get new instance of symbol from style
668 std::unique_ptr< QgsSymbol > s( style->symbol( name ) );
669 if ( !s )
670 return;
671
672 // remove all symbol layers from original symbolgroupsCombo
673 while ( mSymbol->symbolLayerCount() )
674 mSymbol->deleteSymbolLayer( 0 );
675 // move all symbol layers to our symbol
676 while ( s->symbolLayerCount() )
677 {
678 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
679 mSymbol->appendSymbolLayer( sl );
680 }
681 mSymbol->setOpacity( s->opacity() );
682 mSymbol->setFlags( s->flags() );
683
684 updateSymbolInfo();
685 emit changed();
686}
@ ScaleDiameter
Calculate scale by the diameter.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
@ Marker
Marker symbol.
@ Line
Line symbol.
@ Fill
Fill symbol.
@ Hybrid
Hybrid symbol.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
void setColorDialogTitle(const QString &title)
Set the title for the color chooser dialog window.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
void setContext(const QString &context)
Sets the context string for the color button.
void setColor(const QColor &color)
Sets the current color for the button.
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
static const QString EXPR_GEOMETRY_RING_NUM
Inbuilt variable name for geometry ring number variable.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
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.
A line symbol type, for rendering LineString and MultiLineString geometries.
void setDataDefinedWidth(const QgsProperty &property) const
Set data defined width for whole symbol (including all symbol layers).
void setWidth(double width) const
Sets the width for the whole line symbol.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
A marker symbol type, for rendering Point and MultiPoint geometries.
void setScaleMethod(Qgis::ScaleMethod scaleMethod) const
Sets the method to use for scaling the marker's size.
void setAngle(double symbolAngle) const
Sets the angle for the whole symbol.
void setSize(double size) const
Sets the size for the whole symbol.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
double angle() const
Returns the marker angle for the whole symbol.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
void setDataDefinedSize(const QgsProperty &property) const
Set data defined size for whole symbol (including all symbol layers).
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
A dialog to create a new auxiliary layer.
void opacityChanged(double opacity)
Emitted when the opacity is changed in the widget, where opacity ranges from 0.0 (transparent) to 1....
void setOpacity(double opacity)
Sets the current opacity to show in the widget, where opacity ranges from 0.0 (transparent) to 1....
Base class for any widget that can be shown as a inline panel.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
QgsStyle * styleAtPath(const QString &path)
Returns a reference to the style database associated with the project with matching file path.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsProjectStyleSettings * styleSettings() const
Returns the project's style settings, which contains settings and properties relating to how a QgsPro...
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition for a property.
Definition qgsproperty.h:45
A button for controlling property overrides which may apply to a widget.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void updateFieldLists()
Updates list of fields.
void changed()
Emitted when property definition changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
int propertyKey() const
Returns the property key linked to the button.
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
void createAuxiliaryField()
Emitted when creating a new auxiliary field.
A store for object properties.
void setField(const QString &field)
Sets the field name the property references.
void saveEntity()
Emitted when the user has opted to save a new entity to the style database, by clicking the "Save" bu...
void selectionChangedWithStylePath(const QString &name, QgsStyle::StyleEntity type, const QString &stylePath)
Emitted when the selected item is changed in the widget.
a dialog for setting properties of a newly saved style.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
Definition qgsstyle.cpp:284
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition qgsstyle.cpp:318
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:203
@ SymbolEntity
Symbols.
Definition qgsstyle.h:204
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
Definition qgsstyle.cpp:248
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:146
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
Definition qgsstyle.cpp:224
QStringList symbolNames() const
Returns a list of names of symbols.
Definition qgsstyle.cpp:340
A dialog for customising animation settings for a symbol.
A widget for customising animation settings for a symbol.
void setAnimationSettings(const QgsSymbolAnimationSettings &settings)
Sets the animation settings to show in the widget.
QgsSymbolAnimationSettings animationSettings() const
Returns the animation settings as defined in the widget.
A dialog for customising buffer settings for a symbol.
A widget for customising buffer settings for a symbol.
QgsSymbolBufferSettings bufferSettings() const
Returns the buffer settings as defined in the widget.
void setBufferSettings(const QgsSymbolBufferSettings &settings)
Sets the buffer settings to show in the widget.
Contains settings relating to symbol buffers, which draw a "halo" effect around the symbol.
Definition qgssymbol.h:97
Property
Data definable properties.
@ StrokeWidth
Stroke width.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
void setOutputUnit(Qgis::RenderUnit unit) const
Sets the units to use for sizes and widths within the symbol.
Property
Data definable properties.
Definition qgssymbol.h:270
void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the symbol.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol's property collection, used for data defined overrides.
Definition qgssymbol.h:787
QgsSymbolAnimationSettings & animationSettings()
Returns a reference to the symbol animation settings.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
void setColor(const QColor &color) const
Sets the color for the symbol.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
qreal opacity() const
Returns the opacity for the symbol.
Definition qgssymbol.h:632
void setMapUnitScale(const QgsMapUnitScale &scale) const
Sets the map unit scale for the symbol.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent.
Definition qgssymbol.h:687
void setFlags(Qgis::SymbolFlags flags)
Sets flags for the symbol.
Definition qgssymbol.h:659
QgsSymbolBufferSettings * bufferSettings()
Returns the symbol buffer settings, which control an optional "halo" effect around the symbol.
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
Definition qgssymbol.h:639
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:352
QColor color() const
Returns the symbol's color.
Qgis::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:293
void setAnimationSettings(const QgsSymbolAnimationSettings &settings)
Sets a the symbol animation settings.
void setBufferSettings(QgsSymbolBufferSettings *settings)
Sets a the symbol buffer settings, which control an optional "halo" effect around the symbol.
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Definition qgssymbol.h:709
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition qgssymbol.h:677
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition qgssymbol.h:698
void setLineWidth(double width)
QgsSymbolWidgetContext context() const
Returns the context in which the symbol widget is shown, e.g., the associated map canvas and expressi...
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the symbol widget is shown, e.g., the associated map canvas and expression ...
void setSymbolColor(const QColor &color)
void setMarkerAngle(double angle)
QgsSymbolsListWidget(QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer=nullptr)
Constructor for QgsSymbolsListWidget.
const QgsVectorLayer * layer() const
Returns the vector layer associated with the widget.
void changed()
Emitted when the symbol is modified in the widget.
void clipFeaturesToggled(bool checked)
void setMarkerSize(double size)
A widget displaying a combobox allowing the user to choose between various display units,...
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
QgsMapUnitScale getMapUnitScale() const
Returns the map unit scale.
void setUnits(const QStringList &units, int mapUnitIdx)
Sets the units which the user can choose from in the combobox.
void setUnit(int unitIndex)
Sets the selected unit index.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale.
Qgis::RenderUnit unit() const
Returns the current predefined selected unit (if applicable).
Represents a vector layer which manages a vector based data sets.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5821