38 #include <QStringList> 41 #include <QStandardItemModel> 42 #include <QColorDialog> 43 #include <QInputDialog> 44 #include <QMessageBox> 46 #include <QPushButton> 54 QgsReadOnlyStyleModel::QgsReadOnlyStyleModel(
QgsStyle *style, QObject *parent )
60 Qt::ItemFlags QgsReadOnlyStyleModel::flags(
const QModelIndex &index )
const 62 return QgsStyleProxyModel::flags( index ) & ~Qt::ItemIsEditable;
65 QVariant QgsReadOnlyStyleModel::data(
const QModelIndex &index,
int role )
const 67 if ( role == Qt::FontRole )
70 QFont f = QgsStyleProxyModel::data( index, role ).value< QFont >();
74 return QgsStyleProxyModel::data( index, role );
92 spinAngle->setClearValue( 0 );
97 mModel =
new QgsReadOnlyStyleModel( mStyle,
this );
109 mAdvancedMenu = menu;
111 btnAdvanced->setMenu( mAdvancedMenu );
115 btnAdvanced->setMenu(
new QMenu(
this ) );
117 mClipFeaturesAction =
new QAction( tr(
"Clip Features to Canvas Extent" ),
this );
118 mClipFeaturesAction->setCheckable(
true );
120 mStandardizeRingsAction =
new QAction( tr(
"Force Right-Hand-Rule Orientation" ),
this );
121 mStandardizeRingsAction->setCheckable(
true );
122 connect( mStandardizeRingsAction, &QAction::toggled,
this, &QgsSymbolsListWidget::forceRHRToggled );
125 viewSymbols->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) );
127 mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );
131 viewSymbols->setModel( mModel );
132 mSymbolTreeView->setModel( mModel );
134 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
135 mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
136 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
144 lblSymbolName->clear();
146 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
150 mSymbolViewStackedWidget->setCurrentIndex( 0 );
155 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
160 mSymbolViewStackedWidget->setCurrentIndex( 1 );
166 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
167 if ( currentView == 0 )
168 mButtonIconView->setChecked(
true );
170 mButtonListView->setChecked(
true );
172 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
173 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
180 groupEdit->setShowSearchIcon(
true );
181 groupEdit->setShowClearButton(
true );
182 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
183 groupsCombo->setLineEdit( groupEdit );
185 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
186 connect( groupsCombo, &QComboBox::currentTextChanged,
this, &QgsSymbolsListWidget::updateModelFilters );
195 stackedWidget->setCurrentIndex( symbol->
type() );
209 updateAssistantSymbol();
211 btnColor->setAllowOpacity(
true );
212 btnColor->setColorDialogTitle( tr(
"Select Color" ) );
213 btnColor->setContext( QStringLiteral(
"symbology" ) );
223 btnAdvanced->menu()->removeAction( mClipFeaturesAction );
224 btnAdvanced->menu()->removeAction( mStandardizeRingsAction );
229 button->setProperty(
"propertyKey", key );
235 void QgsSymbolsListWidget::createAuxiliaryField()
259 property.setActive(
true );
295 const auto unitSelectionWidgets { findChildren<QgsUnitSelectionWidget *>() };
303 if ( ddButton->assistant() )
304 ddButton->assistant()->setMapCanvas( mContext.
mapCanvas() );
316 mUpdatingGroups =
true;
317 groupsCombo->blockSignals(
true );
318 groupsCombo->clear();
320 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
321 groupsCombo->addItem( tr(
"All Symbols" ), QVariant(
"all" ) );
324 QStringList tags = mStyle->
tags();
325 if ( tags.count() > 0 )
328 groupsCombo->insertSeparator( index );
329 const auto constTags = tags;
330 for (
const QString &tag : constTags )
332 groupsCombo->addItem( tag, QVariant(
"tag" ) );
338 if ( groups.count() > 0 )
341 groupsCombo->insertSeparator( index + 1 );
342 const auto constGroups = groups;
343 for (
const QString &group : constGroups )
345 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
348 groupsCombo->blockSignals(
false );
351 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
352 groupsCombo->setCurrentIndex( index );
354 mUpdatingGroups =
false;
356 updateModelFilters();
359 void QgsSymbolsListWidget::updateModelFilters()
361 if ( mUpdatingGroups )
364 const QString text = groupsCombo->currentText();
365 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
374 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
381 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
388 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
404 void QgsSymbolsListWidget::forceRHRToggled(
bool checked )
429 updateModelFilters();
462 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
479 if ( markerSymbol->
size() == size )
490 spinSize->setEnabled( !mSizeDDBtn->isActive() );
508 if ( lineSymbol->
width() == width )
519 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
533 void QgsSymbolsListWidget::updateAssistantSymbol()
535 mAssistantSymbol.reset( mSymbol->
clone() );
537 mSizeDDBtn->setSymbol( mAssistantSymbol );
539 mWidthDDBtn->setSymbol( mAssistantSymbol );
545 QString name = QInputDialog::getText(
this, tr(
"Save Symbol" ),
546 tr(
"Please enter name for the symbol:" ), QLineEdit::Normal, tr(
"New symbol" ), &ok );
547 if ( !ok || name.isEmpty() )
553 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
554 tr(
"Symbol with name '%1' already exists. Overwrite?" )
556 QMessageBox::Yes | QMessageBox::No );
557 if ( res != QMessageBox::Yes )
573 if ( !saveDlg.exec() )
576 if ( saveDlg.
name().isEmpty() )
582 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
583 tr(
"Symbol with name '%1' already exists. Overwrite?" )
584 .arg( saveDlg.
name() ),
585 QMessageBox::Yes | QMessageBox::No );
586 if ( res != QMessageBox::Yes )
593 QStringList symbolTags = saveDlg.
tags().split(
',' );
602 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
614 void QgsSymbolsListWidget::opacityChanged(
double opacity )
623 void QgsSymbolsListWidget::updateSymbolColor()
625 btnColor->blockSignals(
true );
626 btnColor->setColor( mSymbol->
color() );
627 btnColor->blockSignals(
false );
653 void QgsSymbolsListWidget::updateSymbolInfo()
657 const auto overrideButtons {findChildren< QgsPropertyOverrideButton * >()};
666 spinSize->setValue( markerSymbol->
size() );
667 spinAngle->setValue( markerSymbol->
angle() );
673 spinSize->setEnabled( !mSizeDDBtn->isActive() );
676 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
680 mSizeDDBtn->setEnabled(
false );
681 mRotationDDBtn->setEnabled(
false );
687 spinWidth->setValue( lineSymbol->
width() );
693 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
697 mWidthDDBtn->setEnabled(
false );
701 mSymbolUnitWidget->blockSignals(
true );
702 mSymbolUnitWidget->setUnit( mSymbol->
outputUnit() );
703 mSymbolUnitWidget->setMapUnitScale( mSymbol->
mapUnitScale() );
704 mSymbolUnitWidget->blockSignals(
false );
706 mOpacityWidget->setOpacity( mSymbol->
opacity() );
709 const QList<QAction *> actionList( btnAdvanced->menu()->actions() );
710 for (
const auto &action : actionList )
712 if ( mClipFeaturesAction->text() == action->text() )
714 btnAdvanced->menu()->removeAction( action );
716 else if ( mStandardizeRingsAction->text() == action->text() )
718 btnAdvanced->menu()->removeAction( action );
725 btnAdvanced->menu()->addAction( mClipFeaturesAction );
729 btnAdvanced->menu()->addAction( mStandardizeRingsAction );
732 btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
740 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
741 lblSymbolName->setText( symbolName );
743 std::unique_ptr< QgsSymbol > s( mStyle->
symbol( symbolName ) );
751 while ( s->symbolLayerCount() )
762 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged(
int index )
765 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), index );
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.
Meters value as Map units.
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
QString tags() const
returns the text value of the tags element
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
A dialog allowing users to customize and populate a QgsStyle.
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
void setMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the symbol.
Calculate scale by the diameter.
Abstract base class for all rendered symbols.
a dialog for setting properties of a newly saved style.
static const double UI_SCALE_FACTOR
UI scaling factor.
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
This class is a composition of two QSettings instances:
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setTagId(int id)
Sets a tag id to filter style entities by.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
QString name() const
returns the text value of the name element
void setSize(double size)
Sets the size for the whole symbol.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
bool deleteSymbolLayer(int index)
Removes and deletes the symbol layer at the specified index.
void setDataDefinedAngle(const QgsProperty &property)
Set data defined angle for whole symbol (including all symbol layers).
void setAngle(double symbolAngle)
Sets the angle for the whole symbol.
void setFavoritesOnly(bool favoritesOnly)
Sets whether the model should show only favorited entities.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
A marker symbol type, for rendering Point and MultiPoint geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
void setOutputUnit(QgsUnitTypes::RenderUnit unit)
Sets the units to use for sizes and widths within the symbol.
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
A dialog to create a new auxiliary layer.
void setField(const QString &field)
Sets the field name the property references.
void setEntityFilterEnabled(bool enabled)
Sets whether filtering by entity type is enabled.
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
QStringList symbolNames()
Returns a list of names of symbols.
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
void setOpacity(qreal opacity)
Sets the opacity for the symbol.
void setWidth(double width)
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...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void groupsModified()
Emitted every time a tag or smartgroup has been added, removed, or renamed.
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QColor color() const
Returns the symbol's color.
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
Definition for a property.
int smartgroupId(const QString &smartgroup)
Returns the DB id for the given smartgroup name.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
QStringList smartgroupNames()
Returns the smart groups list.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QStringList tags() const
Returns a list of all tags in the style database.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Points (e.g., for font sizes)
SymbolType type() const
Returns the symbol's type.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
static const QString EXPR_CLUSTER_SIZE
Inbuilt variable name for cluster size variable.
bool isFavorite() const
returns whether the favorite element is checked
static const QString EXPR_GEOMETRY_POINT_NUM
Inbuilt variable name for point number variable.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
QgsSymbol * symbol()
Returns the symbol that is currently active in the widget.
void setDataDefinedSize(const QgsProperty &property)
Set data defined size for whole symbol (including all symbol layers).
bool saveSymbol(const QString &name, QgsSymbol *symbol, bool favorite, const QStringList &tags)
Adds the symbol to the DB with the tags.
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent...
qreal opacity() const
Returns the opacity for the symbol.
bool removeSymbol(const QString &name)
Removes symbol from style (and delete it)
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
void setForceRHR(bool force)
Sets whether polygon features drawn by the symbol should be reoriented to follow the standard right-h...
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
Represents a vector layer which manages a vector based data sets.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
double angle() const
Returns the marker angle for the whole symbol.
Property
Data definable properties.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...
void setColor(const QColor &color)
Sets the color for the symbol.