QGIS API Documentation 3.41.0-Master (d5b93354e9c)
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
115
116 if ( mSymbol )
117 {
118 updateSymbolInfo();
119 }
120
121 connect( mSymbolUnitWidget, &QgsUnitSelectionWidget::changed, this, &QgsSymbolsListWidget::mSymbolUnitWidget_changed );
122 connect( mSymbolColorButton, &QgsColorButton::colorChanged, this, &QgsSymbolsListWidget::setSymbolColor );
123
124 registerSymbolDataDefinedButton( opacityDDBtn, QgsSymbol::Property::Opacity );
125
126 connect( this, &QgsSymbolsListWidget::changed, this, &QgsSymbolsListWidget::updateAssistantSymbol );
127 updateAssistantSymbol();
128
129 mSymbolColorButton->setAllowOpacity( true );
130 mSymbolColorButton->setColorDialogTitle( tr( "Select Color" ) );
131 mSymbolColorButton->setContext( QStringLiteral( "symbology" ) );
132
133 connect( mSymbolOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsSymbolsListWidget::opacityChanged );
134
135 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::selectionChangedWithStylePath, this, &QgsSymbolsListWidget::setSymbolFromStyle );
136 connect( mStyleItemsListWidget, &QgsStyleItemsListWidget::saveEntity, this, &QgsSymbolsListWidget::saveSymbol );
137}
138
140{
141 // This action was added to the menu by this widget, clean it up
142 // The menu can be passed in the constructor, so may live longer than this widget
143 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
144 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
145 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
146 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
147}
148
149void QgsSymbolsListWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key )
150{
151 button->setProperty( "propertyKey", static_cast<int>( key ) );
153
154 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createAuxiliaryField );
155}
156
157void QgsSymbolsListWidget::createAuxiliaryField()
158{
159 // try to create an auxiliary layer if not yet created
160 if ( !mLayer->auxiliaryLayer() )
161 {
162 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
163 dlg.exec();
164 }
165
166 // return if still not exists
167 if ( !mLayer->auxiliaryLayer() )
168 return;
169
170 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
171 const QgsSymbolLayer::Property key = static_cast<QgsSymbolLayer::Property>( button->propertyKey() );
172 const QgsPropertyDefinition def = QgsSymbolLayer::propertyDefinitions()[static_cast<int>( key )];
173
174 // create property in auxiliary storage if necessary
175 if ( !mLayer->auxiliaryLayer()->exists( def ) )
176 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
177
178 // update property with join field name from auxiliary storage
179 QgsProperty property = button->toProperty();
180 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
181 property.setActive( true );
182 button->updateFieldLists();
183 button->setToProperty( property );
184
185 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
186 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
187 switch ( key )
188 {
190 if ( markerSymbol )
191 markerSymbol->setDataDefinedAngle( button->toProperty() );
192 break;
193
195 if ( markerSymbol )
196 {
197 markerSymbol->setDataDefinedSize( button->toProperty() );
199 }
200 break;
201
203 if ( lineSymbol )
204 lineSymbol->setDataDefinedWidth( button->toProperty() );
205 break;
206
207 default:
208 break;
209 }
210
211 emit changed();
212}
213
214void QgsSymbolsListWidget::createSymbolAuxiliaryField()
215{
216 // try to create an auxiliary layer if not yet created
217 if ( !mLayer->auxiliaryLayer() )
218 {
219 QgsNewAuxiliaryLayerDialog dlg( mLayer, this );
220 dlg.exec();
221 }
222
223 // return if still not exists
224 if ( !mLayer->auxiliaryLayer() )
225 return;
226
227 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
228 const QgsSymbol::Property key = static_cast<QgsSymbol::Property>( button->propertyKey() );
229 const QgsPropertyDefinition def = QgsSymbol::propertyDefinitions()[static_cast<int>( key )];
230
231 // create property in auxiliary storage if necessary
232 if ( !mLayer->auxiliaryLayer()->exists( def ) )
233 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
234
235 // update property with join field name from auxiliary storage
236 QgsProperty property = button->toProperty();
237 property.setField( QgsAuxiliaryLayer::nameFromProperty( def, true ) );
238 property.setActive( true );
239 button->updateFieldLists();
240 button->setToProperty( property );
241
242 mSymbol->setDataDefinedProperty( key, button->toProperty() );
243
244 emit changed();
245}
246
248{
249 mContext = context;
250 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
251 for ( QgsUnitSelectionWidget *unitWidget : unitSelectionWidgets )
252 {
253 unitWidget->setMapCanvas( mContext.mapCanvas() );
254 }
255}
256
258{
259 return mContext;
260}
261
262void QgsSymbolsListWidget::forceRHRToggled( bool checked )
263{
264 if ( !mSymbol )
265 return;
266
267 mSymbol->setForceRHR( checked );
268 emit changed();
269}
270
271void QgsSymbolsListWidget::showAnimationSettings()
272{
274 if ( panel && panel->dockMode() )
275 {
277 widget->setPanelTitle( tr( "Animation Settings" ) );
278 widget->setAnimationSettings( mSymbol->animationSettings() );
279 connect( widget, &QgsPanelWidget::widgetChanged, this, [this, widget]() {
280 mSymbol->setAnimationSettings( widget->animationSettings() );
281 emit changed();
282 } );
283 panel->openPanel( widget );
284 return;
285 }
286
288 d.setAnimationSettings( mSymbol->animationSettings() );
289 if ( d.exec() == QDialog::Accepted )
290 {
291 mSymbol->setAnimationSettings( d.animationSettings() );
292 emit changed();
293 }
294}
295
296void QgsSymbolsListWidget::showBufferSettings()
297{
299 if ( panel && panel->dockMode() )
300 {
302 widget->setPanelTitle( tr( "Buffer Settings" ) );
303 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
304 widget->setBufferSettings( *settings );
305
306 connect( widget, &QgsPanelWidget::widgetChanged, this, [this, widget]() {
307 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( widget->bufferSettings() ) );
308 emit changed();
309 } );
310 panel->openPanel( widget );
311 return;
312 }
313
315 if ( const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
316 d.setBufferSettings( *settings );
317 if ( d.exec() == QDialog::Accepted )
318 {
319 mSymbol->setBufferSettings( new QgsSymbolBufferSettings( d.bufferSettings() ) );
320 emit changed();
321 }
322}
323
324void QgsSymbolsListWidget::saveSymbol()
325{
326 QgsStyleSaveDialog saveDlg( this );
327 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
328 if ( !saveDlg.exec() )
329 return;
330
331 if ( saveDlg.name().isEmpty() )
332 return;
333
334 QgsStyle *style = saveDlg.destinationStyle();
335 if ( !style )
336 return;
337
338 // check if there is no symbol with same name
339 if ( style->symbolNames().contains( saveDlg.name() ) )
340 {
341 const int res = QMessageBox::warning( this, tr( "Save Symbol" ), tr( "Symbol with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
342 if ( res != QMessageBox::Yes )
343 {
344 return;
345 }
346 style->removeSymbol( saveDlg.name() );
347 }
348
349 const QStringList symbolTags = saveDlg.tags().split( ',' );
350
351 // add new symbol to style and re-populate the list
352 QgsSymbol *newSymbol = mSymbol->clone();
353 style->addSymbol( saveDlg.name(), newSymbol );
354
355 // make sure the symbol is stored
356 style->saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
357}
358
359void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
360{
361 if ( !mSymbol )
362 return;
363
364 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
365 const QgsSymbol::Property key = static_cast<QgsSymbol::Property>( button->propertyKey() );
366 mSymbol->setDataDefinedProperty( key, button->toProperty() );
367 emit changed();
368}
369
370void QgsSymbolsListWidget::registerSymbolDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbol::Property key )
371{
372 button->init( static_cast<int>( key ), mSymbol ? mSymbol->dataDefinedProperties() : QgsPropertyCollection(), QgsSymbol::propertyDefinitions(), mLayer, true );
373 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolsListWidget::updateSymbolDataDefinedProperty );
374 connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolsListWidget::createSymbolAuxiliaryField );
375
377}
378
380{
381 if ( !mSymbol )
382 return;
383
384 mSymbol->setClipFeaturesToExtent( checked );
385 emit changed();
386}
387
388void QgsSymbolsListWidget::setSymbolColor( const QColor &color )
389{
390 mSymbol->setColor( color );
391 emit changed();
392}
393
395{
396 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
397 if ( markerSymbol->angle() == angle )
398 return;
399 markerSymbol->setAngle( angle );
400 emit changed();
401}
402
404{
405 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
406 const QgsProperty dd( mRotationDDBtn->toProperty() );
407
408 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
409
410 const QgsProperty symbolDD( markerSymbol->dataDefinedAngle() );
411
412 if ( // shall we remove datadefined expressions for layers ?
413 ( !symbolDD && !dd )
414 // shall we set the "en masse" expression for properties ?
415 || dd
416 )
417 {
418 markerSymbol->setDataDefinedAngle( dd );
419 emit changed();
420 }
421}
422
424{
425 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
426 if ( markerSymbol->size() == size )
427 return;
428 markerSymbol->setSize( size );
429 emit changed();
430}
431
433{
434 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
435 const QgsProperty dd( mSizeDDBtn->toProperty() );
436
437 spinSize->setEnabled( !mSizeDDBtn->isActive() );
438
439 const QgsProperty symbolDD( markerSymbol->dataDefinedSize() );
440
441 if ( // shall we remove datadefined expressions for layers ?
442 ( !symbolDD && !dd )
443 // shall we set the "en masse" expression for properties ?
444 || dd
445 )
446 {
447 markerSymbol->setDataDefinedSize( dd );
449 emit changed();
450 }
451}
452
454{
455 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
456 if ( lineSymbol->width() == width )
457 return;
458 lineSymbol->setWidth( width );
459 emit changed();
460}
461
463{
464 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
465 const QgsProperty dd( mWidthDDBtn->toProperty() );
466
467 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
468
469 const QgsProperty symbolDD( lineSymbol->dataDefinedWidth() );
470
471 if ( // shall we remove datadefined expressions for layers ?
472 ( !symbolDD && !dd )
473 // shall we set the "en masse" expression for properties ?
474 || dd
475 )
476 {
477 lineSymbol->setDataDefinedWidth( dd );
478 emit changed();
479 }
480}
481
482void QgsSymbolsListWidget::updateAssistantSymbol()
483{
484 mAssistantSymbol.reset( mSymbol->clone() );
485 if ( mSymbol->type() == Qgis::SymbolType::Marker )
486 mSizeDDBtn->setSymbol( mAssistantSymbol );
487 else if ( mSymbol->type() == Qgis::SymbolType::Line && mLayer )
488 mWidthDDBtn->setSymbol( mAssistantSymbol );
489}
490
491void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
492{
493 if ( mSymbol )
494 {
495 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
496 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
497
498 emit changed();
499 }
500}
501
502void QgsSymbolsListWidget::opacityChanged( double opacity )
503{
504 if ( mSymbol )
505 {
506 mSymbol->setOpacity( opacity );
507 emit changed();
508 }
509}
510
511void QgsSymbolsListWidget::updateSymbolColor()
512{
513 mSymbolColorButton->blockSignals( true );
514 mSymbolColorButton->setColor( mSymbol->color() );
515 mSymbolColorButton->blockSignals( false );
516}
517
518QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
519{
520 if ( auto *lExpressionContext = mContext.expressionContext() )
521 return QgsExpressionContext( *lExpressionContext );
522
523 //otherwise create a default symbol context
525
526 // additional scopes
527 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
528 for ( const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
529 {
530 expContext.appendScope( new QgsExpressionContextScope( scope ) );
531 }
532
534
535 return expContext;
536}
537
538void QgsSymbolsListWidget::updateSymbolInfo()
539{
540 updateSymbolColor();
541
542 const auto overrideButtons { findChildren<QgsPropertyOverrideButton *>() };
543 for ( QgsPropertyOverrideButton *button : overrideButtons )
544 {
546 }
547
548 if ( mSymbol->type() == Qgis::SymbolType::Marker )
549 {
550 QgsMarkerSymbol *markerSymbol = static_cast<QgsMarkerSymbol *>( mSymbol );
551 spinSize->setValue( markerSymbol->size() );
552 spinAngle->setValue( markerSymbol->angle() );
553
554 if ( mLayer )
555 {
556 const QgsProperty ddSize( markerSymbol->dataDefinedSize() );
557 mSizeDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::Size ), ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
558 spinSize->setEnabled( !mSizeDDBtn->isActive() );
559 const QgsProperty ddAngle( markerSymbol->dataDefinedAngle() );
560 mRotationDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::Angle ), ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
561 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
562 }
563 else
564 {
565 mSizeDDBtn->setEnabled( false );
566 mRotationDDBtn->setEnabled( false );
567 }
568 }
569 else if ( mSymbol->type() == Qgis::SymbolType::Line )
570 {
571 QgsLineSymbol *lineSymbol = static_cast<QgsLineSymbol *>( mSymbol );
572 spinWidth->setValue( lineSymbol->width() );
573
574 if ( mLayer )
575 {
576 const QgsProperty dd( lineSymbol->dataDefinedWidth() );
577 mWidthDDBtn->init( static_cast<int>( QgsSymbolLayer::Property::StrokeWidth ), dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true );
578 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
579 }
580 else
581 {
582 mWidthDDBtn->setEnabled( false );
583 }
584 }
585
586 mSymbolUnitWidget->blockSignals( true );
587 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
588 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
589 mSymbolUnitWidget->blockSignals( false );
590
591 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
592
593 // Clean up previous advanced symbol actions
594 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
595 for ( QAction *action : actionList )
596 {
597 for ( QAction *actionsToRemove :
598 {
599 mClipFeaturesAction,
600 mStandardizeRingsAction,
601 mAnimationSettingsAction,
602 mBufferSettingsAction
603 } )
604 {
605 if ( actionsToRemove->text() == action->text() )
606 {
607 mStyleItemsListWidget->advancedMenu()->removeAction( action );
608 break;
609 }
610 }
611 }
612
613 if ( mSymbol->type() == Qgis::SymbolType::Line || mSymbol->type() == Qgis::SymbolType::Fill )
614 {
615 //add clip features option for line or fill symbols
616 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
617 }
618 if ( mSymbol->type() == Qgis::SymbolType::Fill )
619 {
620 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
621 }
622 if ( mSymbol->type() == Qgis::SymbolType::Marker )
623 {
624 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
625 }
626 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
627
628 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
629
630 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
631 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
632}
633
634void QgsSymbolsListWidget::setSymbolFromStyle( const QString &name, QgsStyle::StyleEntity, const QString &stylePath )
635{
636 if ( name.isEmpty() )
637 return;
638
639 QgsStyle *style = nullptr;
640 if ( mStyle != QgsStyle::defaultStyle() )
641 {
642 // get new instance of symbol from style
643 style = mStyle;
644 }
645 else
646 {
647 style = QgsProject::instance()->styleSettings()->styleAtPath( stylePath );
648 }
649
650 if ( !style )
651 return;
652
653 // get new instance of symbol from style
654 std::unique_ptr<QgsSymbol> s( style->symbol( name ) );
655 if ( !s )
656 return;
657
658 // remove all symbol layers from original symbolgroupsCombo
659 while ( mSymbol->symbolLayerCount() )
660 mSymbol->deleteSymbolLayer( 0 );
661 // move all symbol layers to our symbol
662 while ( s->symbolLayerCount() )
663 {
664 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
665 mSymbol->appendSymbolLayer( sl );
666 }
667 mSymbol->setOpacity( s->opacity() );
668 mSymbol->setFlags( s->flags() );
669
670 updateSymbolInfo();
671 emit changed();
672}
@ 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:5928