QGIS API Documentation 3.41.0-Master (cea29feecf2)
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"
19#include "qgsstylesavedialog.h"
21#include "qgsvectorlayer.h"
23#include "qgsauxiliarystorage.h"
24#include "qgsmarkersymbol.h"
25#include "qgslinesymbol.h"
29
30#include <QMessageBox>
31#include <QAction>
32#include <QMenu>
33
34QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbol *symbol, QgsStyle *style, QMenu *menu, QWidget *parent, QgsVectorLayer *layer )
35 : QWidget( parent )
36 , mSymbol( symbol )
37 , mStyle( style )
38 , mAdvancedMenu( menu )
39 , mLayer( layer )
40{
41 setupUi( this );
42 spinAngle->setClearValue( 0 );
43
44 mStyleItemsListWidget->setStyle( mStyle );
45 mStyleItemsListWidget->setEntityType( QgsStyle::SymbolEntity );
46 if ( mSymbol )
47 mStyleItemsListWidget->setSymbolType( mSymbol->type() );
48 mStyleItemsListWidget->setAdvancedMenu( menu );
49
50 mClipFeaturesAction = new QAction( tr( "Clip Features to Canvas Extent" ), this );
51 mClipFeaturesAction->setCheckable( true );
52 connect( mClipFeaturesAction, &QAction::toggled, this, &QgsSymbolsListWidget::clipFeaturesToggled );
53 mStandardizeRingsAction = new QAction( tr( "Force Right-Hand-Rule Orientation" ), this );
54 mStandardizeRingsAction->setCheckable( true );
55 connect( mStandardizeRingsAction, &QAction::toggled, this, &QgsSymbolsListWidget::forceRHRToggled );
56
57 mBufferSettingsAction = new QAction( tr( "Buffer Settings…" ), this );
58 connect( mBufferSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showBufferSettings );
59
60 mAnimationSettingsAction = new QAction( tr( "Animation Settings…" ), this );
61 connect( mAnimationSettingsAction, &QAction::triggered, this, &QgsSymbolsListWidget::showAnimationSettings );
62
63 mExtentBufferAction = new QAction( tr( "Extent Buffer…" ), this );
64 connect( mExtentBufferAction, &QAction::triggered, this, &QgsSymbolsListWidget::showExtentBufferSettings );
65
66 // select correct page in stacked widget
67 QgsPropertyOverrideButton *opacityDDBtn = nullptr;
68 switch ( symbol->type() )
69 {
71 {
72 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
73 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
74 mSymbolColorButton = btnMarkerColor;
75 opacityDDBtn = mMarkerOpacityDDBtn;
76 mSymbolOpacityWidget = mMarkerOpacityWidget;
77 mSymbolUnitWidget = mMarkerUnitWidget;
78 connect( spinAngle, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerAngle );
79 connect( spinSize, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setMarkerSize );
80 registerDataDefinedButton( mSizeDDBtn, QgsSymbolLayer::Property::Size );
82 registerDataDefinedButton( mRotationDDBtn, QgsSymbolLayer::Property::Angle );
84 break;
85 }
86
88 {
89 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
90 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
91 mSymbolColorButton = btnLineColor;
92 opacityDDBtn = mLineOpacityDDBtn;
93 mSymbolOpacityWidget = mLineOpacityWidget;
94 mSymbolUnitWidget = mLineUnitWidget;
95 connect( spinWidth, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsSymbolsListWidget::setLineWidth );
96 registerDataDefinedButton( mWidthDDBtn, QgsSymbolLayer::Property::StrokeWidth );
98 break;
99 }
100
102 {
103 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
104 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
105 mSymbolColorButton = btnFillColor;
106 opacityDDBtn = mFillOpacityDDBtn;
107 mSymbolOpacityWidget = mFillOpacityWidget;
108 mSymbolUnitWidget = mFillUnitWidget;
109 break;
110 }
111
113 break;
114 }
115
116 stackedWidget->setCurrentIndex( 0 );
117
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( mExtentBufferAction );
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 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::showExtentBufferSettings()
302{
304 if ( panel && panel->dockMode() )
305 {
306 QgsExtentBufferWidget *widget = new QgsExtentBufferWidget( mSymbol, mLayer, panel );
307 widget->setPanelTitle( tr( "Extent Buffer" ) );
308 widget->setContext( mContext );
309
310 connect( widget, &QgsPanelWidget::widgetChanged, this, [=]() {
311 mSymbol->setExtentBuffer( widget->extentBuffer() );
313 mSymbol->setExtentBufferSizeUnit( widget->sizeUnit() );
314
315 emit changed();
316 } );
317
318 panel->openPanel( widget );
319 }
320 else
321 {
322 QgsExtentBufferDialog dlg( mSymbol, mLayer, panel );
323
324 if ( dlg.widget() )
325 {
326 dlg.setContext( mContext );
327 }
328
329 if ( dlg.exec() == QDialog::Accepted )
330 {
331 mSymbol->setExtentBuffer( dlg.extentBuffer() );
332 mSymbol->setDataDefinedProperty( QgsSymbol::Property::ExtentBuffer, dlg.dataDefinedProperty() );
333 mSymbol->setExtentBufferSizeUnit( dlg.sizeUnit() );
334
335 emit changed();
336 }
337 }
338}
339
340void QgsSymbolsListWidget::showBufferSettings()
341{
343 if ( panel && panel->dockMode() )
344 {
346 widget->setPanelTitle( tr( "Buffer Settings" ) );
347 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
348 widget->setBufferSettings( *settings );
349
350 connect( widget, &QgsPanelWidget::widgetChanged, this, [this, widget]() {
351 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( widget->bufferSettings() ) );
352 emit changed();
353 } );
354 panel->openPanel( widget );
355 return;
356 }
357
359 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
360 d.setBufferSettings( *settings );
361 if ( d.exec() == QDialog::Accepted )
362 {
363 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( d.bufferSettings() ) );
364 emit changed();
365 }
366}
367
368void QgsSymbolsListWidget::saveSymbol()
369{
370 QgsStyleSaveDialog saveDlg( this );
371 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
372 if ( !saveDlg.exec() )
373 return;
374
375 if ( saveDlg.name().isEmpty() )
376 return;
377
378 QgsStyle *style = saveDlg.destinationStyle();
379 if ( !style )
380 return;
381
382 // check if there is no symbol with same name
383 if ( style->symbolNames().contains( saveDlg.name() ) )
384 {
385 const int res = QMessageBox::warning( this, tr( "Save Symbol" ), tr( "Symbol with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
386 if ( res != QMessageBox::Yes )
387 {
388 return;
389 }
390 style->removeSymbol( saveDlg.name() );
391 }
392
393 const QStringList symbolTags = saveDlg.tags().split( ',' );
394
395 // add new symbol to style and re-populate the list
396 QgsSymbol *newSymbol = mSymbol->clone();
397 style->addSymbol( saveDlg.name(), newSymbol );
398
399 // make sure the symbol is stored
400 style->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
401}
402
403void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
404{
405 if ( !mSymbol )
406 return;
407
408 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
409 const QgsSymbol::Property key = static_cast<QgsSymbol::Property>( button->propertyKey() );
410 mSymbol->setDataDefinedProperty( key, button->toProperty() );
411 emit changed();
412}
413
414void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
415{
416 button->init( static_cast<int>( key ), mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
417 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
418 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
419
421}
422
424{
425 if ( !mSymbol )
426 return;
427
428 mSymbol->setClipFeaturesToExtent( checked );
429 emit changed();
430}
431
432void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
433{
434 mSymbol->setColor( color );
435 emit changed();
436}
437
439{
440 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
441 if ( markerSymbol->angle() == angle )
442 return;
443 markerSymbol->setAngle( angle );
444 emit changed();
445}
446
448{
449 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
450 const QgsProperty dd( mRotationDDBtn->toProperty() );
451
452 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
453
454 const QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
455
456 if ( // shall we remove datadefined expressions for layers ?
457 ( !symbolDD && !dd )
458 // shall we set the "en masse" expression for properties ?
459 || dd
460 )
461 {
462 markerSymbol->setDataDefinedAngle( dd );
463 emit changed();
464 }
465}
466
468{
469 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
470 if ( markerSymbol->size() == size )
471 return;
472 markerSymbol->setSize( size );
473 emit changed();
474}
475
477{
478 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
479 const QgsProperty dd( mSizeDDBtn->toProperty() );
480
481 spinSize->setEnabled( !mSizeDDBtn->isActive() );
482
483 const QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
484
485 if ( // shall we remove datadefined expressions for layers ?
486 ( !symbolDD && !dd )
487 // shall we set the "en masse" expression for properties ?
488 || dd
489 )
490 {
491 markerSymbol->setDataDefinedSize( dd );
493 emit changed();
494 }
495}
496
498{
499 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
500 if ( lineSymbol->width() == width )
501 return;
502 lineSymbol->setWidth( width );
503 emit changed();
504}
505
507{
508 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
509 const QgsProperty dd( mWidthDDBtn->toProperty() );
510
511 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
512
513 const QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
514
515 if ( // shall we remove datadefined expressions for layers ?
516 ( !symbolDD && !dd )
517 // shall we set the "en masse" expression for properties ?
518 || dd
519 )
520 {
521 lineSymbol->setDataDefinedWidth( dd );
522 emit changed();
523 }
524}
525
526void QgsSymbolsListWidget::updateAssistantSymbol()
527{
528 mAssistantSymbol.reset( mSymbol->clone() );
529 if ( mSymbol->type() == Qgis::SymbolType::Marker )
530 mSizeDDBtn->setSymbol( mAssistantSymbol );
531 else if ( mSymbol->type() == Qgis::SymbolType::Line && mLayer )
532 mWidthDDBtn->setSymbol( mAssistantSymbol );
533}
534
535void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
536{
537 if ( mSymbol )
538 {
539 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
540 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
541
542 emit changed();
543 }
544}
545
546void QgsSymbolsListWidget::opacityChanged( double opacity )
547{
548 if ( mSymbol )
549 {
550 mSymbol->setOpacity( opacity );
551 emit changed();
552 }
553}
554
555void QgsSymbolsListWidget::updateSymbolColor()
556{
557 mSymbolColorButton->blockSignals( true );
558 mSymbolColorButton->setColor( mSymbol->color() );
559 mSymbolColorButton->blockSignals( false );
560}
561
562QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
563{
564 if ( auto *lExpressionContext = mContext.expressionContext() )
565 return QgsExpressionContext( *lExpressionContext );
566
567 //otherwise create a default symbol context
569
570 // additional scopes
571 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
572 for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
573 {
574 expContext.appendScope( new QgsExpressionContextScope( scope ) );
575 }
576
578
579 return expContext;
580}
581
582void QgsSymbolsListWidget::updateSymbolInfo()
583{
584 updateSymbolColor();
585
586 const auto overrideButtons { findChildren<QgsPropertyOverrideButton *>() };
587 for ( QgsPropertyOverrideButton *button : overrideButtons )
588 {
590 }
591
592 if ( mSymbol->type() == Qgis::SymbolType::Marker )
593 {
594 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
595 spinSize->setValue( markerSymbol->size() );
596 spinAngle->setValue( markerSymbol->angle() );
597
598 if ( mLayer )
599 {
600 const QgsProperty ddSize( markerSymbol->dataDefinedSize() );
601 mSizeDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::Size ), ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
602 spinSize->setEnabled( !mSizeDDBtn->isActive() );
603 const QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
604 mRotationDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::Angle ), ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
605 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
606 }
607 else
608 {
609 mSizeDDBtn->setEnabled( false );
610 mRotationDDBtn->setEnabled( false );
611 }
612 }
613 else if ( mSymbol->type() == Qgis::SymbolType::Line )
614 {
615 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
616 spinWidth->setValue( lineSymbol->width() );
617
618 if ( mLayer )
619 {
620 const QgsProperty dd( lineSymbol->dataDefinedWidth() );
621 mWidthDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::StrokeWidth ), dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
622 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
623 }
624 else
625 {
626 mWidthDDBtn->setEnabled( false );
627 }
628 }
629
630 mSymbolUnitWidget->blockSignals( true );
631 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
632 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
633 mSymbolUnitWidget->blockSignals( false );
634
635 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
636
637 // Clean up previous advanced symbol actions
638 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
639 for ( QAction *action : actionList )
640 {
641 for ( QAction *actionsToRemove :
642 {
643 mClipFeaturesAction,
644 mStandardizeRingsAction,
645 mAnimationSettingsAction,
646 mExtentBufferAction,
647 mBufferSettingsAction
648 } )
649 {
650 if ( actionsToRemove->text() == action->text() )
651 {
652 mStyleItemsListWidget->advancedMenu()->removeAction( action );
653 break;
654 }
655 }
656 }
657
658 if ( mSymbol->type() == Qgis::SymbolType::Line || mSymbol->type() == Qgis::SymbolType::Fill )
659 {
660 //add clip features option for line or fill symbols
661 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
662 }
663 if ( mSymbol->type() == Qgis::SymbolType::Fill )
664 {
665 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
666 }
667 if ( mSymbol->type() == Qgis::SymbolType::Marker )
668 {
669 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
670 }
671 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
672 mStyleItemsListWidget->advancedMenu()->addAction( mExtentBufferAction );
673
674 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
675
676 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
677 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
678}
679
680void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity, const QString &stylePath )
681{
682 if ( name.isEmpty() )
683 return;
684
685 QgsStyle *style = nullptr;
686 if ( mStyle != QgsStyle::defaultStyle() )
687 {
688 // get new instance of symbol from style
689 style = mStyle;
690 }
691 else
692 {
693 style = QgsProject::instance()->styleSettings()->styleAtPath( stylePath );
694 }
695
696 if ( !style )
697 return;
698
699 // get new instance of symbol from style
700 std::unique_ptr<QgsSymbol> s( style->symbol( name ) );
701 if ( !s )
702 return;
703
704 // remove all symbol layers from original symbolgroupsCombo
705 while ( mSymbol->symbolLayerCount() )
706 mSymbol->deleteSymbolLayer( 0 );
707 // move all symbol layers to our symbol
708 while ( s->symbolLayerCount() )
709 {
710 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
711 mSymbol->appendSymbolLayer( sl );
712 }
713 mSymbol->setOpacity( s->opacity() );
714 mSymbol->setFlags( s->flags() );
715
716 updateSymbolInfo();
717 emit changed();
718}
@ 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 dialog which allows the user to modify the extent buffer of a symbol.
A widget which allows the user to modify the rendering order of extent buffers.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which widget is shown, e.g., the associated map canvas and expression contexts.
double extentBuffer() const
Returns the extent buffer value currently set in the widget.
QgsProperty dataDefinedProperty() const
Returns the data defined property currently set in the widget.
Qgis::RenderUnit sizeUnit() const
Returns the extent buffer unit currently set in the widget.
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
@ ExtentBuffer
Extent buffer.
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:788
void setExtentBuffer(double extentBuffer)
Sets the symbol's extent buffer.
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:633
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:688
void setFlags(Qgis::SymbolFlags flags)
Sets flags for the symbol.
Definition qgssymbol.h:660
void setExtentBufferSizeUnit(Qgis::RenderUnit unit)
Sets the unit used for the extent buffer.
Definition qgssymbol.h:906
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:640
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:353
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:294
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:710
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent.
Definition qgssymbol.h:678
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Definition qgssymbol.h:699
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:5928