34#include "moc_qgssymbolslistwidget.cpp"
40 , mAdvancedMenu( menu )
44 spinAngle->setClearValue( 0 );
46 mStyleItemsListWidget->setStyle( mStyle );
49 mStyleItemsListWidget->setSymbolType( mSymbol->type() );
50 mStyleItemsListWidget->setAdvancedMenu( menu );
52 mClipFeaturesAction =
new QAction( tr(
"Clip Features to Canvas Extent" ),
this );
53 mClipFeaturesAction->setCheckable(
true );
55 mStandardizeRingsAction =
new QAction( tr(
"Force Right-Hand-Rule Orientation" ),
this );
56 mStandardizeRingsAction->setCheckable(
true );
57 connect( mStandardizeRingsAction, &QAction::toggled,
this, &QgsSymbolsListWidget::forceRHRToggled );
59 mBufferSettingsAction =
new QAction( tr(
"Buffer Settings…" ),
this );
60 connect( mBufferSettingsAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showBufferSettings );
62 mAnimationSettingsAction =
new QAction( tr(
"Animation Settings…" ),
this );
63 connect( mAnimationSettingsAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showAnimationSettings );
65 mExtentBufferAction =
new QAction( tr(
"Extent Buffer…" ),
this );
66 connect( mExtentBufferAction, &QAction::triggered,
this, &QgsSymbolsListWidget::showExtentBufferSettings );
70 switch ( symbol->
type() )
74 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
75 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
76 mSymbolColorButton = btnMarkerColor;
77 opacityDDBtn = mMarkerOpacityDDBtn;
78 mSymbolOpacityWidget = mMarkerOpacityWidget;
79 mSymbolUnitWidget = mMarkerUnitWidget;
91 stackedWidget->removeWidget( stackedWidget->widget( 2 ) );
92 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
93 mSymbolColorButton = btnLineColor;
94 opacityDDBtn = mLineOpacityDDBtn;
95 mSymbolOpacityWidget = mLineOpacityWidget;
96 mSymbolUnitWidget = mLineUnitWidget;
105 stackedWidget->removeWidget( stackedWidget->widget( 1 ) );
106 stackedWidget->removeWidget( stackedWidget->widget( 0 ) );
107 mSymbolColorButton = btnFillColor;
108 opacityDDBtn = mFillOpacityDDBtn;
109 mSymbolOpacityWidget = mFillOpacityWidget;
110 mSymbolUnitWidget = mFillUnitWidget;
118 stackedWidget->setCurrentIndex( 0 );
138 updateAssistantSymbol();
141 mSymbolColorButton->setAllowOpacity(
true );
142 mSymbolColorButton->setColorDialogTitle( tr(
"Select Color" ) );
143 mSymbolColorButton->setContext( QStringLiteral(
"symbology" ) );
155 mStyleItemsListWidget->advancedMenu()->removeAction( mClipFeaturesAction );
156 mStyleItemsListWidget->advancedMenu()->removeAction( mStandardizeRingsAction );
157 mStyleItemsListWidget->advancedMenu()->removeAction( mAnimationSettingsAction );
158 mStyleItemsListWidget->advancedMenu()->removeAction( mExtentBufferAction );
159 mStyleItemsListWidget->advancedMenu()->removeAction( mBufferSettingsAction );
164 button->setProperty(
"propertyKey",
static_cast<int>( key ) );
170void QgsSymbolsListWidget::createAuxiliaryField()
173 if ( !mLayer->auxiliaryLayer() )
175 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
180 if ( !mLayer->auxiliaryLayer() )
183 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
188 if ( !mLayer->auxiliaryLayer()->exists( def ) )
189 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
194 property.setActive(
true );
198 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
199 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
227void QgsSymbolsListWidget::createSymbolAuxiliaryField()
230 if ( !mLayer->auxiliaryLayer() )
232 QgsNewAuxiliaryLayerDialog dlg( mLayer,
this );
237 if ( !mLayer->auxiliaryLayer() )
240 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
245 if ( !mLayer->auxiliaryLayer()->exists( def ) )
246 mLayer->auxiliaryLayer()->addAuxiliaryField( def );
251 property.setActive(
true );
255 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
263 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
266 unitWidget->setMapCanvas( mContext.mapCanvas() );
275void QgsSymbolsListWidget::forceRHRToggled(
bool checked )
284void QgsSymbolsListWidget::showAnimationSettings()
289 QgsSymbolAnimationSettingsWidget *widget =
new QgsSymbolAnimationSettingsWidget( panel );
300 QgsSymbolAnimationSettingsDialog d(
this );
301 d.setAnimationSettings( mSymbol->animationSettings() );
302 if ( d.exec() == QDialog::Accepted )
304 mSymbol->setAnimationSettings( d.animationSettings() );
309void QgsSymbolsListWidget::showExtentBufferSettings()
314 QgsExtentBufferWidget *widget =
new QgsExtentBufferWidget( mSymbol, mLayer, panel );
321 mSymbol->setExtentBufferSizeUnit( widget->
sizeUnit() );
330 QgsExtentBufferDialog dlg( mSymbol, mLayer, panel );
334 dlg.setContext( mContext );
337 if ( dlg.exec() == QDialog::Accepted )
339 mSymbol->setExtentBuffer( dlg.extentBuffer() );
341 mSymbol->setExtentBufferSizeUnit( dlg.sizeUnit() );
348void QgsSymbolsListWidget::showBufferSettings()
353 QgsSymbolBufferSettingsWidget *widget =
new QgsSymbolBufferSettingsWidget( panel );
355 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
359 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( widget->
bufferSettings() ) );
366 QgsSymbolBufferSettingsDialog d(
this );
367 if (
const QgsSymbolBufferSettings *settings = mSymbol->bufferSettings() )
368 d.setBufferSettings( *settings );
369 if ( d.exec() == QDialog::Accepted )
371 mSymbol->setBufferSettings(
new QgsSymbolBufferSettings( d.bufferSettings() ) );
376void QgsSymbolsListWidget::saveSymbol()
378 QgsStyleSaveDialog saveDlg(
this );
379 saveDlg.setDefaultTags( mStyleItemsListWidget->currentTagFilter() );
380 if ( !saveDlg.exec() )
383 if ( saveDlg.name().isEmpty() )
386 QgsStyle *style = saveDlg.destinationStyle();
391 if ( style->
symbolNames().contains( saveDlg.name() ) )
393 const int res = QMessageBox::warning(
this, tr(
"Save Symbol" ), tr(
"Symbol with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
394 if ( res != QMessageBox::Yes )
401 const QStringList symbolTags = saveDlg.tags().split(
',' );
404 QgsSymbol *newSymbol = mSymbol->clone();
405 style->
addSymbol( saveDlg.name(), newSymbol );
408 style->
saveSymbol( saveDlg.name(), newSymbol, saveDlg.isFavorite(), symbolTags );
411void QgsSymbolsListWidget::updateSymbolDataDefinedProperty()
416 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
418 mSymbol->setDataDefinedProperty( key, button->
toProperty() );
436 mSymbol->setClipFeaturesToExtent( checked );
442 mSymbol->setColor( color );
449 if ( markerSymbol->
angle() == angle )
458 const QgsProperty dd( mRotationDDBtn->toProperty() );
460 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
478 if ( markerSymbol->
size() == size )
489 spinSize->setEnabled( !mSizeDDBtn->isActive() );
508 if ( lineSymbol->
width() == width )
519 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
534void QgsSymbolsListWidget::updateAssistantSymbol()
536 mAssistantSymbol.reset( mSymbol->
clone() );
538 mSizeDDBtn->setSymbol( mAssistantSymbol );
540 mWidthDDBtn->setSymbol( mAssistantSymbol );
543void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
547 mSymbol->setOutputUnit( mSymbolUnitWidget->unit() );
548 mSymbol->setMapUnitScale( mSymbolUnitWidget->getMapUnitScale() );
554void QgsSymbolsListWidget::opacityChanged(
double opacity )
558 mSymbol->setOpacity( opacity );
563void QgsSymbolsListWidget::updateSymbolColor()
565 mSymbolColorButton->blockSignals(
true );
566 mSymbolColorButton->setColor( mSymbol->color() );
567 mSymbolColorButton->blockSignals(
false );
572 if (
auto *lExpressionContext = mContext.expressionContext() )
573 return QgsExpressionContext( *lExpressionContext );
576 QgsExpressionContext expContext( mContext.globalProjectAtlasMapLayerScopes(
layer() ) );
579 const auto constAdditionalExpressionContextScopes = mContext.additionalExpressionContextScopes();
580 for (
const QgsExpressionContextScope &scope : constAdditionalExpressionContextScopes )
582 expContext.appendScope(
new QgsExpressionContextScope( scope ) );
590void QgsSymbolsListWidget::updateSymbolInfo()
594 const QList<QgsPropertyOverrideButton *> overrideButtons { findChildren<QgsPropertyOverrideButton *>() };
595 for ( QgsPropertyOverrideButton *button : overrideButtons )
602 QgsMarkerSymbol *markerSymbol =
static_cast<QgsMarkerSymbol *
>( mSymbol );
603 spinSize->setValue( markerSymbol->
size() );
604 spinAngle->setValue( markerSymbol->
angle() );
610 spinSize->setEnabled( !mSizeDDBtn->isActive() );
613 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
617 mSizeDDBtn->setEnabled(
false );
618 mRotationDDBtn->setEnabled(
false );
623 QgsLineSymbol *lineSymbol =
static_cast<QgsLineSymbol *
>( mSymbol );
624 spinWidth->setValue( lineSymbol->
width() );
630 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
634 mWidthDDBtn->setEnabled(
false );
638 mSymbolUnitWidget->blockSignals(
true );
639 mSymbolUnitWidget->setUnit( mSymbol->outputUnit() );
640 mSymbolUnitWidget->setMapUnitScale( mSymbol->mapUnitScale() );
641 mSymbolUnitWidget->blockSignals(
false );
643 mSymbolOpacityWidget->setOpacity( mSymbol->opacity() );
646 const QList<QAction *> actionList( mStyleItemsListWidget->advancedMenu()->actions() );
647 for ( QAction *action : actionList )
649 for ( QAction *actionsToRemove :
652 mStandardizeRingsAction,
653 mAnimationSettingsAction,
655 mBufferSettingsAction
658 if ( actionsToRemove->text() == action->text() )
660 mStyleItemsListWidget->advancedMenu()->removeAction( action );
669 mStyleItemsListWidget->advancedMenu()->addAction( mClipFeaturesAction );
673 mStyleItemsListWidget->advancedMenu()->addAction( mStandardizeRingsAction );
677 mStyleItemsListWidget->advancedMenu()->addAction( mBufferSettingsAction );
679 mStyleItemsListWidget->advancedMenu()->addAction( mAnimationSettingsAction );
680 mStyleItemsListWidget->advancedMenu()->addAction( mExtentBufferAction );
682 mStyleItemsListWidget->showAdvancedButton( mAdvancedMenu || !mStyleItemsListWidget->advancedMenu()->isEmpty() );
684 whileBlocking( mClipFeaturesAction )->setChecked( mSymbol->clipFeaturesToExtent() );
685 whileBlocking( mStandardizeRingsAction )->setChecked( mSymbol->forceRHR() );
688void QgsSymbolsListWidget::setSymbolFromStyle(
const QString &name,
QgsStyle::StyleEntity,
const QString &stylePath )
690 if ( name.isEmpty() )
693 QgsStyle *style =
nullptr;
708 std::unique_ptr<QgsSymbol> s( style->
symbol( name ) );
713 while ( mSymbol->symbolLayerCount() )
714 mSymbol->deleteSymbolLayer( 0 );
716 while ( s->symbolLayerCount() )
718 QgsSymbolLayer *sl = s->takeSymbolLayer( 0 );
719 mSymbol->appendSymbolLayer( sl );
721 mSymbol->setOpacity( s->opacity() );
722 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.