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 );
141 updateAssistantSymbol();
144 mSymbolColorButton->setAllowOpacity(
true );
145 mSymbolColorButton->setColorDialogTitle( tr(
"Select Color" ) );
146 mSymbolColorButton->setContext( u
"symbology"_s );
158 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
159 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
160 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
161 mStyleItemsListWidget->advancedMenu()->removeAction( mExtentBufferAction );
162 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
167 button->setProperty(
"propertyKey",
static_cast<int>( key ) );
173void QgsSymbolsListWidget::createAuxiliaryField()
176 if ( !mLayer->auxiliaryLayer() )
178 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
183 if ( !mLayer->auxiliaryLayer() )
186 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
191 if ( !mLayer->auxiliaryLayer()->exists( def ) )
192 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
197 property.setActive(
true );
201 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
202 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
230void QgsSymbolsListWidget::createSymbolAuxiliaryField()
233 if ( !mLayer->auxiliaryLayer() )
235 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
240 if ( !mLayer->auxiliaryLayer() )
243 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
248 if ( !mLayer->auxiliaryLayer()->exists( def ) )
249 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
254 property.setActive(
true );
258 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
266 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
269 unitWidget->setMapCanvas( mContext.mapCanvas() );
278void QgsSymbolsListWidget::forceRHRToggled(
bool checked )
287void QgsSymbolsListWidget::showAnimationSettings()
292 QgsSymbolAnimationSettingsWidget *widget =
new QgsSymbolAnimationSettingsWidget( panel );
303 QgsSymbolAnimationSettingsDialog d(
this );
304 d.setAnimationSettings( mSymbol->animationSettings() );
305 if ( d.exec() == QDialog::Accepted )
307 mSymbol->setAnimationSettings( d.animationSettings() );
312void QgsSymbolsListWidget::showExtentBufferSettings()
317 QgsExtentBufferWidget *widget =
new QgsExtentBufferWidget( mSymbol, mLayer, panel );
324 mSymbol->setExtentBufferSizeUnit( widget->
sizeUnit() );
333 QgsExtentBufferDialog dlg( mSymbol, mLayer, panel );
337 dlg.setContext( mContext );
340 if ( dlg.exec() == QDialog::Accepted )
342 mSymbol->setExtentBuffer( dlg.extentBuffer() );
344 mSymbol->setExtentBufferSizeUnit( dlg.sizeUnit() );
351void QgsSymbolsListWidget::showBufferSettings()
356 QgsSymbolBufferSettingsWidget *widget =
new QgsSymbolBufferSettingsWidget( panel );
358 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
362 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( widget->
bufferSettings() ) );
369 QgsSymbolBufferSettingsDialog d(
this );
370 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
371 d.setBufferSettings( *settings );
372 if ( d.exec() == QDialog::Accepted )
374 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( d.bufferSettings() ) );
379void QgsSymbolsListWidget::saveSymbol()
381 QgsStyleSaveDialog saveDlg(
this );
382 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
383 if ( !saveDlg.exec() )
386 if ( saveDlg.name().isEmpty() )
389 QgsStyle *style = saveDlg.destinationStyle();
394 if ( style->
symbolNames().contains( saveDlg.name() ) )
396 const int res = QMessageBox::warning(
this, tr(
"Save Symbol" ), tr(
"Symbol with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
397 if ( res != QMessageBox::Yes )
404 const QStringList symbolTags = saveDlg.tags().split(
',' );
407 QgsSymbol *newSymbol = mSymbol->clone();
408 style->
addSymbol( saveDlg.name(), newSymbol );
411 style->
saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
414void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
419 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
421 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
439 mSymbol->setClipFeaturesToExtent( checked );
445 mSymbol->setColor( color );
452 if ( markerSymbol->
angle() == angle )
461 const QgsProperty dd( mRotationDDBtn->toProperty() );
463 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
481 if ( markerSymbol->
size() == size )
492 spinSize->setEnabled( !mSizeDDBtn->isActive() );
511 if ( lineSymbol->
width() == width )
522 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
537void QgsSymbolsListWidget::updateAssistantSymbol()
539 mAssistantSymbol.reset( mSymbol->
clone() );
541 mSizeDDBtn->setSymbol( mAssistantSymbol );
543 mWidthDDBtn->setSymbol( mAssistantSymbol );
546void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
550 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
551 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
557void QgsSymbolsListWidget::opacityChanged(
double opacity )
561 mSymbol->setOpacity( opacity );
566void QgsSymbolsListWidget::updateSymbolColor()
568 mSymbolColorButton->blockSignals(
true );
569 mSymbolColorButton->setColor( mSymbol->color() );
570 mSymbolColorButton->blockSignals(
false );
575 if (
auto *lExpressionContext = mContext.expressionContext() )
576 return QgsExpressionContext( *lExpressionContext );
579 QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes(
layer() ) );
582 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
583 for (
const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
585 expContext.appendScope(
new QgsExpressionContextScope( scope ) );
593void QgsSymbolsListWidget::updateSymbolInfo()
597 const QList<QgsPropertyOverrideButton *> overrideButtons { findChildren<QgsPropertyOverrideButton *>() };
598 for ( QgsPropertyOverrideButton *button : overrideButtons )
605 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
606 spinSize->setValue( markerSymbol->
size() );
607 spinAngle->setValue( markerSymbol->
angle() );
613 spinSize->setEnabled( !mSizeDDBtn->isActive() );
616 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
620 mSizeDDBtn->setEnabled(
false );
621 mRotationDDBtn->setEnabled(
false );
626 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
627 spinWidth->setValue( lineSymbol->
width() );
633 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
637 mWidthDDBtn->setEnabled(
false );
641 mSymbolUnitWidget->blockSignals(
true );
642 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
643 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
644 mSymbolUnitWidget->blockSignals(
false );
646 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
649 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
650 for ( QAction *action : actionList )
652 for ( QAction *actionsToRemove :
655 mStandardizeRingsAction,
656 mAnimationSettingsAction,
658 mBufferSettingsAction
661 if ( actionsToRemove->text() == action->text() )
663 mStyleItemsListWidget->advancedMenu()->removeAction( action );
672 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
676 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
680 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
682 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
683 mStyleItemsListWidget->advancedMenu()->addAction( mExtentBufferAction );
685 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
687 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
688 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
691void QgsSymbolsListWidget::setSymbolFromStyle(
const QString &name,
QgsStyle::StyleEntity,
const QString &stylePath )
693 if ( name.isEmpty() )
696 QgsStyle *style =
nullptr;
711 std::unique_ptr<QgsSymbol> s( style->
symbol( name ) );
716 while ( mSymbol->symbolLayerCount() )
717 mSymbol->deleteSymbolLayer( 0 );
719 while ( s->symbolLayerCount() )
721 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
722 mSymbol->appendSymbolLayer( sl );
724 mSymbol->setOpacity( s->opacity() );
725 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.