35#include "moc_qgssymbolslistwidget.cpp"
37using namespace Qt::StringLiterals;
43 , mAdvancedMenu( menu )
47 spinAngle->setClearValue( 0 );
49 mStyleItemsListWidget->setStyle( mStyle );
52 mStyleItemsListWidget->setSymbolType( mSymbol->type() );
53 mStyleItemsListWidget->setAdvancedMenu( menu );
55 mClipFeaturesAction =
new QAction( tr(
"Clip Features to Canvas Extent" ),
this );
56 mClipFeaturesAction->setCheckable(
true );
58 mStandardizeRingsAction =
new QAction( tr(
"Force Right-Hand-Rule Orientation" ),
this );
59 mStandardizeRingsAction->setCheckable(
true );
60 connect( mStandardizeRingsAction, &QAction::toggled,
this, &QgsSymbolsListWidget::forceRHRToggled );
62 mBufferSettingsAction =
new QAction( tr(
"Buffer Settings…" ),
this );
63 connect( mBufferSettingsAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showBufferSettings );
65 mAnimationSettingsAction =
new QAction( tr(
"Animation Settings…" ),
this );
66 connect( mAnimationSettingsAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showAnimationSettings );
68 mExtentBufferAction =
new QAction( tr(
"Extent Buffer…" ),
this );
69 connect( mExtentBufferAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showExtentBufferSettings );
73 switch ( symbol->
type() )
77 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
78 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
79 mSymbolColorButton = btnMarkerColor;
80 opacityDDBtn = mMarkerOpacityDDBtn;
81 mSymbolOpacityWidget = mMarkerOpacityWidget;
82 mSymbolUnitWidget = mMarkerUnitWidget;
94 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
95 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
96 mSymbolColorButton = btnLineColor;
97 opacityDDBtn = mLineOpacityDDBtn;
98 mSymbolOpacityWidget = mLineOpacityWidget;
99 mSymbolUnitWidget = mLineUnitWidget;
108 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
109 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
110 mSymbolColorButton = btnFillColor;
111 opacityDDBtn = mFillOpacityDDBtn;
112 mSymbolOpacityWidget = mFillOpacityWidget;
113 mSymbolUnitWidget = mFillUnitWidget;
121 stackedWidget->setCurrentIndex( 0 );
123 mSymbolUnitWidget->setUnits(
143 updateAssistantSymbol();
146 mSymbolColorButton->setAllowOpacity(
true );
147 mSymbolColorButton->setColorDialogTitle( tr(
"Select Color" ) );
148 mSymbolColorButton->setContext( u
"symbology"_s );
160 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
161 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
162 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
163 mStyleItemsListWidget->advancedMenu()->removeAction( mExtentBufferAction );
164 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
169 button->setProperty(
"propertyKey",
static_cast<int>( key ) );
175void QgsSymbolsListWidget::createAuxiliaryField()
178 if ( !mLayer->auxiliaryLayer() )
180 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
185 if ( !mLayer->auxiliaryLayer() )
188 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
193 if ( !mLayer->auxiliaryLayer()->exists( def ) )
194 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
199 property.setActive(
true );
203 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
204 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
232void QgsSymbolsListWidget::createSymbolAuxiliaryField()
235 if ( !mLayer->auxiliaryLayer() )
237 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
242 if ( !mLayer->auxiliaryLayer() )
245 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
250 if ( !mLayer->auxiliaryLayer()->exists( def ) )
251 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
256 property.setActive(
true );
260 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
268 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
271 unitWidget->setMapCanvas( mContext.mapCanvas() );
280void QgsSymbolsListWidget::forceRHRToggled(
bool checked )
289void QgsSymbolsListWidget::showAnimationSettings()
294 QgsSymbolAnimationSettingsWidget *widget =
new QgsSymbolAnimationSettingsWidget( panel );
305 QgsSymbolAnimationSettingsDialog d(
this );
306 d.setAnimationSettings( mSymbol->animationSettings() );
307 if ( d.exec() == QDialog::Accepted )
309 mSymbol->setAnimationSettings( d.animationSettings() );
314void QgsSymbolsListWidget::showExtentBufferSettings()
319 QgsExtentBufferWidget *widget =
new QgsExtentBufferWidget( mSymbol, mLayer, panel );
326 mSymbol->setExtentBufferSizeUnit( widget->
sizeUnit() );
335 QgsExtentBufferDialog dlg( mSymbol, mLayer, panel );
339 dlg.setContext( mContext );
342 if ( dlg.exec() == QDialog::Accepted )
344 mSymbol->setExtentBuffer( dlg.extentBuffer() );
346 mSymbol->setExtentBufferSizeUnit( dlg.sizeUnit() );
353void QgsSymbolsListWidget::showBufferSettings()
358 QgsSymbolBufferSettingsWidget *widget =
new QgsSymbolBufferSettingsWidget( panel );
360 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
364 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( widget->
bufferSettings() ) );
371 QgsSymbolBufferSettingsDialog d(
this );
372 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
373 d.setBufferSettings( *settings );
374 if ( d.exec() == QDialog::Accepted )
376 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( d.bufferSettings() ) );
381void QgsSymbolsListWidget::saveSymbol()
383 QgsStyleSaveDialog saveDlg(
this );
384 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
385 if ( !saveDlg.exec() )
388 if ( saveDlg.name().isEmpty() )
391 QgsStyle *style = saveDlg.destinationStyle();
396 if ( style->
symbolNames().contains( saveDlg.name() ) )
398 const int res = QMessageBox::warning(
this, tr(
"Save Symbol" ), tr(
"Symbol with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
399 if ( res != QMessageBox::Yes )
406 const QStringList symbolTags = saveDlg.tags().split(
',' );
409 QgsSymbol *newSymbol = mSymbol->clone();
410 style->
addSymbol( saveDlg.name(), newSymbol );
413 style->
saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
416void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
421 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
423 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
441 mSymbol->setClipFeaturesToExtent( checked );
447 mSymbol->setColor( color );
454 if ( markerSymbol->
angle() == angle )
463 const QgsProperty dd( mRotationDDBtn->toProperty() );
465 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
483 if ( markerSymbol->
size() == size )
494 spinSize->setEnabled( !mSizeDDBtn->isActive() );
513 if ( lineSymbol->
width() == width )
524 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
539void QgsSymbolsListWidget::updateAssistantSymbol()
541 mAssistantSymbol.reset( mSymbol->
clone() );
543 mSizeDDBtn->setSymbol( mAssistantSymbol );
545 mWidthDDBtn->setSymbol( mAssistantSymbol );
548void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
552 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
553 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
559void QgsSymbolsListWidget::opacityChanged(
double opacity )
563 mSymbol->setOpacity( opacity );
568void QgsSymbolsListWidget::updateSymbolColor()
570 mSymbolColorButton->blockSignals(
true );
571 mSymbolColorButton->setColor( mSymbol->color() );
572 mSymbolColorButton->blockSignals(
false );
577 if (
auto *lExpressionContext = mContext.expressionContext() )
578 return QgsExpressionContext( *lExpressionContext );
581 QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes(
layer() ) );
584 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
585 for (
const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
587 expContext.appendScope(
new QgsExpressionContextScope( scope ) );
590 expContext.setHighlightedVariables(
601 << u
"symbol_layer_count"_s
602 << u
"symbol_layer_index"_s
609void QgsSymbolsListWidget::updateSymbolInfo()
613 const QList<QgsPropertyOverrideButton *> overrideButtons { findChildren<QgsPropertyOverrideButton *>() };
614 for ( QgsPropertyOverrideButton *button : overrideButtons )
621 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
622 spinSize->setValue( markerSymbol->
size() );
623 spinAngle->setValue( markerSymbol->
angle() );
629 spinSize->setEnabled( !mSizeDDBtn->isActive() );
632 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
636 mSizeDDBtn->setEnabled(
false );
637 mRotationDDBtn->setEnabled(
false );
642 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
643 spinWidth->setValue( lineSymbol->
width() );
649 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
653 mWidthDDBtn->setEnabled(
false );
657 mSymbolUnitWidget->blockSignals(
true );
658 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
659 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
660 mSymbolUnitWidget->blockSignals(
false );
662 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
665 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
666 for ( QAction *action : actionList )
668 for ( QAction *actionsToRemove : { mClipFeaturesAction, mStandardizeRingsAction, mAnimationSettingsAction, mExtentBufferAction, mBufferSettingsAction } )
670 if ( actionsToRemove->text() == action->text() )
672 mStyleItemsListWidget->advancedMenu()->removeAction( action );
681 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
685 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
689 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
691 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
692 mStyleItemsListWidget->advancedMenu()->addAction( mExtentBufferAction );
694 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
696 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
697 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
700void QgsSymbolsListWidget::setSymbolFromStyle(
const QString &name,
QgsStyle::StyleEntity,
const QString &stylePath )
702 if ( name.isEmpty() )
705 QgsStyle *style =
nullptr;
720 std::unique_ptr<QgsSymbol> s( style->
symbol( name ) );
725 while ( mSymbol->symbolLayerCount() )
726 mSymbol->deleteSymbolLayer( 0 );
728 while ( s->symbolLayerCount() )
730 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
731 mSymbol->appendSymbolLayer( sl );
733 mSymbol->setOpacity( s->opacity() );
734 mSymbol->setFlags( s->flags() );
@ ScaleDiameter
Calculate scale by the diameter.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes).
@ MetersInMapUnits
Meters value as Map units.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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).
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 store for object properties.
void setField(const QString &field)
Sets the field name the property references.
A database of saved style entities, including symbols, color ramps, text formats and others.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it).
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
StyleEntity
Enum for Entities involved in a style.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
bool saveSymbol(const QString &name, const QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the database with tags.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
QStringList symbolNames() const
Returns a list of names of symbols.
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,...
Abstract base class for all rendered symbols.
Property
Data definable properties.
@ ExtentBuffer
Extent buffer.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol property definitions.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
Represents a vector layer which manages a vector based dataset.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.