QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgsstylesavedialog.h"
19#include "qgsvectorlayer.h"
21#include "qgsauxiliarystorage.h"
22#include "qgsmarkersymbol.h"
23#include "qgslinesymbol.h"
27
28#include <QMessageBox>
29#include <QAction>
30#include <QMenu>
31
32QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
33 : QWidget( parent )
34 , mSymbol( symbol )
35 , mStyle( style )
36 , mAdvancedMenu( menu )
37 , mLayer( layer )
38{
39 setupUi( this );
40 spinAngle->setClearValue( 0 );
41
42 mStyleItemsListWidget->setStyle( mStyle );
43 mStyleItemsListWidget->setEntityType( QgsStyle::SymbolEntity );
44 if ( mSymbol )
45 mStyleItemsListWidget->setSymbolType( mSymbol->type() );
46 mStyleItemsListWidget->setAdvancedMenu( menu );
47
48 mClipFeaturesAction = new QAction( tr( "Clip Features to Canvas Extent" ), this );
49 mClipFeaturesAction->setCheckable( true );
50 connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
51 mStandardizeRingsAction = new QAction( tr( "Force Right-Hand-Rule Orientation" ), this );
52 mStandardizeRingsAction->setCheckable( true );
53 connect( mStandardizeRingsAction, &QAction::toggled, this, &QgsSymbolsListWidget::forceRHRToggled );
54
55 mBufferSettingsAction = new QAction( tr( "Buffer Settingsā€¦" ), this );
56 connect( mBufferSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showBufferSettings );
57
58 mAnimationSettingsAction = new QAction( tr( "Animation Settingsā€¦" ), this );
59 connect( mAnimationSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showAnimationSettings );
60
61 // select correct page in stacked widget
62 QgsPropertyOverrideButton *opacityDDBtn = nullptr;
63 switch ( symbol->type() )
64 {
66 {
67 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
68 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
69 mSymbolColorButton = btnMarkerColor;
70 opacityDDBtn = mMarkerOpacityDDBtn;
71 mSymbolOpacityWidget = mMarkerOpacityWidget;
72 mSymbolUnitWidget = mMarkerUnitWidget;
73 connect( spinAngle, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
74 connect( spinSize, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
75 registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::Property::Size );
77 registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::Property::Angle );
79 break;
80 }
81
83 {
84 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
85 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
86 mSymbolColorButton = btnLineColor;
87 opacityDDBtn = mLineOpacityDDBtn;
88 mSymbolOpacityWidget = mLineOpacityWidget;
89 mSymbolUnitWidget = mLineUnitWidget;
90 connect( spinWidth, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
91 registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::Property::StrokeWidth );
93 break;
94 }
95
97 {
98 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
99 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
100 mSymbolColorButton = btnFillColor;
101 opacityDDBtn = mFillOpacityDDBtn;
102 mSymbolOpacityWidget = mFillOpacityWidget;
103 mSymbolUnitWidget = mFillUnitWidget;
104 break;
105 }
106
108 break;
109 }
110
111 stackedWidget->setCurrentIndex( 0 );
112
113 mSymbolUnitWidget->setUnits( { Qgis::RenderUnit::Millimeters,
119
120 if ( mSymbol )
121 {
122 updateSymbolInfo();
123 }
124
125 connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
126 connect( mSymbolColorButton, &QgsColorButton::colorChanged, this, &QgsSymbolsListWidget::setSymbolColor );
127
128 registerSymbolDataDefinedButton( opacityDDBtn, QgsSymbol::Property::Opacity );
129
130 connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
131 updateAssistantSymbol();
132
133 mSymbolColorButton->setAllowOpacity( true );
134 mSymbolColorButton->setColorDialogTitle( tr( "Select Color" ) );
135 mSymbolColorButton->setContext( QStringLiteral( "symbology" ) );
136
137 connect( mSymbolOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
138
139 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::selectionChangedWithStylePath, this, &QgsSymbolsListWidget::setSymbolFromStyle );
140 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbolsListWidget::saveSymbol );
141}
142
144{
145 // This action was added to the menu by this widget, clean it up
146 // The menu can be passed in the constructor, so may live longer than this widget
147 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
148 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
149 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
150 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
151}
152
153void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
154{
155 button->setProperty( "propertyKey", static_cast< int >( key ) );
157
158 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
159}
160
161void QgsSymbolsListWidget::createAuxiliaryField()
162{
163 // try to create an auxiliary layer if not yet created
164 if ( !mLayer->auxiliaryLayer() )
165 {
166 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
167 dlg.exec();
168 }
169
170 // return if still not exists
171 if ( !mLayer->auxiliaryLayer() )
172 return;
173
174 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
175 const QgsSymbolLayer::Property key = static_cast< QgsSymbolLayer::Property >( button->propertyKey() );
176 const QgsPropertyDefinition def = QgsSymbolLayer::propertyDefinitions()[static_cast< int >( key )];
177
178 // create property in auxiliary storage if necessary
179 if ( !mLayer->auxiliaryLayer()->exists( def ) )
180 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
181
182 // update property with join field name from auxiliary storage
183 QgsProperty property = button->toProperty();
184 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
185 property.setActive( true );
186 button->updateFieldLists();
187 button->setToProperty( property );
188
189 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
190 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
191 switch ( key )
192 {
194 if ( markerSymbol )
195 markerSymbol->setDataDefinedAngle( button->toProperty() );
196 break;
197
199 if ( markerSymbol )
200 {
201 markerSymbol->setDataDefinedSize( button->toProperty() );
203 }
204 break;
205
207 if ( lineSymbol )
208 lineSymbol->setDataDefinedWidth( button->toProperty() );
209 break;
210
211 default:
212 break;
213 }
214
215 emit changed();
216}
217
218void QgsSymbolsListWidget::createSymbolAuxiliaryField()
219{
220 // try to create an auxiliary layer if not yet created
221 if ( !mLayer->auxiliaryLayer() )
222 {
223 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
224 dlg.exec();
225 }
226
227 // return if still not exists
228 if ( !mLayer->auxiliaryLayer() )
229 return;
230
231 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
232 const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
233 const QgsPropertyDefinition def = QgsSymbol::propertyDefinitions()[static_cast< int >( key )];
234
235 // create property in auxiliary storage if necessary
236 if ( !mLayer->auxiliaryLayer()->exists( def ) )
237 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
238
239 // update property with join field name from auxiliary storage
240 QgsProperty property = button->toProperty();
241 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
242 property.setActive( true );
243 button->updateFieldLists();
244 button->setToProperty( property );
245
246 mSymbol->setDataDefinedProperty( key, button->toProperty() );
247
248 emit changed();
249}
250
252{
253 mContext = context;
254 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
255 for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
256 {
257 unitWidget->setMapCanvas( mContext.mapCanvas() );
258 }
259}
260
262{
263 return mContext;
264}
265
266void QgsSymbolsListWidget::forceRHRToggled( bool checked )
267{
268 if ( !mSymbol )
269 return;
270
271 mSymbol->setForceRHR( checked );
272 emit changed();
273}
274
275void QgsSymbolsListWidget::showAnimationSettings()
276{
278 if ( panel && panel->dockMode() )
279 {
281 widget->setPanelTitle( tr( "Animation Settings" ) );
282 widget->setAnimationSettings( mSymbol->animationSettings() );
283 connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
284 {
285 mSymbol->setAnimationSettings( widget->animationSettings() );
286 emit changed();
287 } );
288 panel->openPanel( widget );
289 return;
290 }
291
293 d.setAnimationSettings( mSymbol->animationSettings() );
294 if ( d.exec() == QDialog::Accepted )
295 {
296 mSymbol->setAnimationSettings( d.animationSettings() );
297 emit changed();
298 }
299}
300
301void QgsSymbolsListWidget::showBufferSettings()
302{
304 if ( panel && panel->dockMode() )
305 {
307 widget->setPanelTitle( tr( "Buffer Settings" ) );
308 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
309 widget->setBufferSettings( *settings );
310
311 connect( widget, &QgsPanelWidget::widgetChanged, this, [ this, widget ]()
312 {
313 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( widget->bufferSettings() ) );
314 emit changed();
315 } );
316 panel->openPanel( widget );
317 return;
318 }
319
321 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
322 d.setBufferSettings( *settings );
323 if ( d.exec() == QDialog::Accepted )
324 {
325 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( d.bufferSettings() ) );
326 emit changed();
327 }
328}
329
330void QgsSymbolsListWidget::saveSymbol()
331{
332 QgsStyleSaveDialog saveDlg( this );
333 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
334 if ( !saveDlg.exec() )
335 return;
336
337 if ( saveDlg.name().isEmpty() )
338 return;
339
340 QgsStyle *style = saveDlg.destinationStyle();
341 if ( !style )
342 return;
343
344 // check if there is no symbol with same name
345 if ( style->symbolNames().contains( saveDlg.name() ) )
346 {
347 const int res = QMessageBox::warning( this, tr( "Save Symbol" ),
348 tr( "Symbol with name '%1' already exists. Overwrite?" )
349 .arg( saveDlg.name() ),
350 QMessageBox::Yes | QMessageBox::No );
351 if ( res != QMessageBox::Yes )
352 {
353 return;
354 }
355 style->removeSymbol( saveDlg.name() );
356 }
357
358 const QStringList symbolTags = saveDlg.tags().split( ',' );
359
360 // add new symbol to style and re-populate the list
361 QgsSymbol *newSymbol = mSymbol->clone();
362 style->addSymbol( saveDlg.name(), newSymbol );
363
364 // make sure the symbol is stored
365 style->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
366}
367
368void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
369{
370 if ( !mSymbol )
371 return;
372
373 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
374 const QgsSymbol::Property key = static_cast< QgsSymbol::Property >( button->propertyKey() );
375 mSymbol->setDataDefinedProperty( key, button->toProperty() );
376 emit changed();
377}
378
379void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
380{
381 button->init( static_cast< int >( key ), mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
382 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
383 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
384
386}
387
389{
390 if ( !mSymbol )
391 return;
392
393 mSymbol->setClipFeaturesToExtent( checked );
394 emit changed();
395}
396
397void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
398{
399 mSymbol->setColor( color );
400 emit changed();
401}
402
404{
405 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
406 if ( markerSymbol->angle() == angle )
407 return;
408 markerSymbol->setAngle( angle );
409 emit changed();
410}
411
413{
414 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
415 const QgsProperty dd( mRotationDDBtn->toProperty() );
416
417 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
418
419 const QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
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 markerSymbol->setDataDefinedAngle( dd );
427 emit changed();
428 }
429}
430
432{
433 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
434 if ( markerSymbol->size() == size )
435 return;
436 markerSymbol->setSize( size );
437 emit changed();
438}
439
441{
442 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
443 const QgsProperty dd( mSizeDDBtn->toProperty() );
444
445 spinSize->setEnabled( !mSizeDDBtn->isActive() );
446
447 const QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
448
449 if ( // shall we remove datadefined expressions for layers ?
450 ( !symbolDD && !dd )
451 // shall we set the "en masse" expression for properties ?
452 || dd )
453 {
454 markerSymbol->setDataDefinedSize( dd );
456 emit changed();
457 }
458}
459
461{
462 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
463 if ( lineSymbol->width() == width )
464 return;
465 lineSymbol->setWidth( width );
466 emit changed();
467}
468
470{
471 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
472 const QgsProperty dd( mWidthDDBtn->toProperty() );
473
474 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
475
476 const QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
477
478 if ( // shall we remove datadefined expressions for layers ?
479 ( !symbolDD && !dd )
480 // shall we set the "en masse" expression for properties ?
481 || dd )
482 {
483 lineSymbol->setDataDefinedWidth( dd );
484 emit changed();
485 }
486}
487
488void QgsSymbolsListWidget::updateAssistantSymbol()
489{
490 mAssistantSymbol.reset( mSymbol->clone() );
491 if ( mSymbol->type() == Qgis::SymbolType::Marker )
492 mSizeDDBtn->setSymbol( mAssistantSymbol );
493 else if ( mSymbol->type() == Qgis::SymbolType::Line && mLayer )
494 mWidthDDBtn->setSymbol( mAssistantSymbol );
495}
496
497void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
498{
499 if ( mSymbol )
500 {
501
502 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
503 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
504
505 emit changed();
506 }
507}
508
509void QgsSymbolsListWidget::opacityChanged( double opacity )
510{
511 if ( mSymbol )
512 {
513 mSymbol->setOpacity( opacity );
514 emit changed();
515 }
516}
517
518void QgsSymbolsListWidget::updateSymbolColor()
519{
520 mSymbolColorButton->blockSignals( true );
521 mSymbolColorButton->setColor( mSymbol->color() );
522 mSymbolColorButton->blockSignals( false );
523}
524
525QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
526{
527 if ( auto *lExpressionContext = mContext.expressionContext() )
528 return QgsExpressionContext( *lExpressionContext );
529
530 //otherwise create a default symbol context
532
533 // additional scopes
534 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
535 for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
536 {
537 expContext.appendScope( new QgsExpressionContextScope( scope ) );
538 }
539
540 expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
545 << QStringLiteral( "symbol_layer_count" ) << QStringLiteral( "symbol_layer_index" )
546 << QStringLiteral( "symbol_frame" ) );
547
548 return expContext;
549}
550
551void QgsSymbolsListWidget::updateSymbolInfo()
552{
553 updateSymbolColor();
554
555 const auto overrideButtons {findChildren< QgsPropertyOverrideButton * >()};
556 for ( QgsPropertyOverrideButton *button : overrideButtons )
557 {
559 }
560
561 if ( mSymbol->type() == Qgis::SymbolType::Marker )
562 {
563 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
564 spinSize->setValue( markerSymbol->size() );
565 spinAngle->setValue( markerSymbol->angle() );
566
567 if ( mLayer )
568 {
569 const QgsProperty ddSize( markerSymbol->dataDefinedSize() );
570 mSizeDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::Size ), ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
571 spinSize->setEnabled( !mSizeDDBtn->isActive() );
572 const QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
573 mRotationDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::Angle ), ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
574 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
575 }
576 else
577 {
578 mSizeDDBtn->setEnabled( false );
579 mRotationDDBtn->setEnabled( false );
580 }
581 }
582 else if ( mSymbol->type() == Qgis::SymbolType::Line )
583 {
584 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
585 spinWidth->setValue( lineSymbol->width() );
586
587 if ( mLayer )
588 {
589 const QgsProperty dd( lineSymbol->dataDefinedWidth() );
590 mWidthDDBtn->init( static_cast< int >( QgsSymbolLayer::Property::StrokeWidth ), dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
591 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
592 }
593 else
594 {
595 mWidthDDBtn->setEnabled( false );
596 }
597 }
598
599 mSymbolUnitWidget->blockSignals( true );
600 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
601 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
602 mSymbolUnitWidget->blockSignals( false );
603
604 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
605
606 // Clean up previous advanced symbol actions
607 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
608 for ( QAction *action : actionList )
609 {
610 for ( QAction *actionsToRemove :
611 {
612 mClipFeaturesAction,
613 mStandardizeRingsAction,
614 mAnimationSettingsAction,
615 mBufferSettingsAction
616 } )
617 {
618 if ( actionsToRemove->text() == action->text() )
619 {
620 mStyleItemsListWidget->advancedMenu()->removeAction( action );
621 break;
622 }
623 }
624 }
625
626 if ( mSymbol->type() == Qgis::SymbolType::Line || mSymbol->type() == Qgis::SymbolType::Fill )
627 {
628 //add clip features option for line or fill symbols
629 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
630 }
631 if ( mSymbol->type() == Qgis::SymbolType::Fill )
632 {
633 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
634 }
635 if ( mSymbol->type() == Qgis::SymbolType::Marker )
636 {
637 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
638 }
639 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
640
641 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
642
643 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
644 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
645}
646
647void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity, const QString &stylePath )
648{
649 if ( name.isEmpty() )
650 return;
651
652 QgsStyle *style = nullptr;
653 if ( mStyle != QgsStyle::defaultStyle() )
654 {
655 // get new instance of symbol from style
656 style = mStyle;
657 }
658 else
659 {
660 style = QgsProject::instance()->styleSettings()->styleAtPath( stylePath );
661 }
662
663 if ( !style )
664 return;
665
666 // get new instance of symbol from style
667 std::unique_ptr< QgsSymbol > s( style->symbol( name ) );
668 if ( !s )
669 return;
670
671 // remove all symbol layers from original symbolgroupsCombo
672 while ( mSymbol->symbolLayerCount() )
673 mSymbol->deleteSymbolLayer( 0 );
674 // move all symbol layers to our symbol
675 while ( s->symbolLayerCount() )
676 {
677 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
678 mSymbol->appendSymbolLayer( sl );
679 }
680 mSymbol->setOpacity( s->opacity() );
681 mSymbol->setFlags( s->flags() );
682
683 updateSymbolInfo();
684 emit changed();
685}
@ 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:283
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition qgsstyle.cpp:317
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:247
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:145
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
Definition qgsstyle.cpp:223
QStringList symbolNames() const
Returns a list of names of symbols.
Definition qgsstyle.cpp:339
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