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 );
302 if ( ddButton->assistant() )
303 ddButton->assistant()->setMapCanvas( mContext.
mapCanvas() );
315 mUpdatingGroups =
true;
316 groupsCombo->blockSignals(
true );
317 groupsCombo->clear();
319 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
320 groupsCombo->addItem( tr(
"All Symbols" ), QVariant(
"all" ) );
323 QStringList tags = mStyle->
tags();
324 if ( tags.count() > 0 )
327 groupsCombo->insertSeparator( index );
328 Q_FOREACH (
const QString &tag, tags )
330 groupsCombo->addItem( tag, QVariant(
"tag" ) );
336 if ( groups.count() > 0 )
339 groupsCombo->insertSeparator( index + 1 );
340 Q_FOREACH (
const QString &group, groups )
342 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
345 groupsCombo->blockSignals(
false );
348 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
349 groupsCombo->setCurrentIndex( index );
351 mUpdatingGroups =
false;
353 updateModelFilters();
356 void QgsSymbolsListWidget::updateModelFilters()
358 if ( mUpdatingGroups )
361 const QString text = groupsCombo->currentText();
362 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
371 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
378 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
385 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
401 void QgsSymbolsListWidget::forceRHRToggled(
bool checked )
426 updateModelFilters();
459 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
476 if ( markerSymbol->
size() == size )
487 spinSize->setEnabled( !mSizeDDBtn->isActive() );
505 if ( lineSymbol->
width() == width )
516 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
530 void QgsSymbolsListWidget::updateAssistantSymbol()
532 mAssistantSymbol.reset( mSymbol->
clone() );
534 mSizeDDBtn->setSymbol( mAssistantSymbol );
536 mWidthDDBtn->setSymbol( mAssistantSymbol );
542 QString name = QInputDialog::getText(
this, tr(
"Save Symbol" ),
543 tr(
"Please enter name for the symbol:" ), QLineEdit::Normal, tr(
"New symbol" ), &ok );
544 if ( !ok || name.isEmpty() )
550 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
551 tr(
"Symbol with name '%1' already exists. Overwrite?" )
553 QMessageBox::Yes | QMessageBox::No );
554 if ( res != QMessageBox::Yes )
570 if ( !saveDlg.exec() )
573 if ( saveDlg.
name().isEmpty() )
579 int res = QMessageBox::warning(
this, tr(
"Save Symbol" ),
580 tr(
"Symbol with name '%1' already exists. Overwrite?" )
581 .arg( saveDlg.
name() ),
582 QMessageBox::Yes | QMessageBox::No );
583 if ( res != QMessageBox::Yes )
590 QStringList symbolTags = saveDlg.
tags().split(
',' );
599 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
611 void QgsSymbolsListWidget::opacityChanged(
double opacity )
620 void QgsSymbolsListWidget::updateSymbolColor()
622 btnColor->blockSignals(
true );
623 btnColor->setColor( mSymbol->
color() );
624 btnColor->blockSignals(
false );
649 void QgsSymbolsListWidget::updateSymbolInfo()
661 spinSize->setValue( markerSymbol->
size() );
662 spinAngle->setValue( markerSymbol->
angle() );
668 spinSize->setEnabled( !mSizeDDBtn->isActive() );
671 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
675 mSizeDDBtn->setEnabled(
false );
676 mRotationDDBtn->setEnabled(
false );
682 spinWidth->setValue( lineSymbol->
width() );
688 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
692 mWidthDDBtn->setEnabled(
false );
696 mSymbolUnitWidget->blockSignals(
true );
697 mSymbolUnitWidget->setUnit( mSymbol->
outputUnit() );
698 mSymbolUnitWidget->setMapUnitScale( mSymbol->
mapUnitScale() );
699 mSymbolUnitWidget->blockSignals(
false );
701 mOpacityWidget->setOpacity( mSymbol->
opacity() );
704 const QList<QAction *> actionList( btnAdvanced->menu()->actions() );
705 for (
const auto &action : actionList )
707 if ( mClipFeaturesAction->text() == action->text() )
709 btnAdvanced->menu()->removeAction( action );
711 else if ( mStandardizeRingsAction->text() == action->text() )
713 btnAdvanced->menu()->removeAction( action );
720 btnAdvanced->menu()->addAction( mClipFeaturesAction );
724 btnAdvanced->menu()->addAction( mStandardizeRingsAction );
727 btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
735 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
736 lblSymbolName->setText( symbolName );
738 std::unique_ptr< QgsSymbol > s( mStyle->
symbol( symbolName ) );
746 while ( s->symbolLayerCount() )
757 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged(
int index )
760 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.
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
double angle() const
Returns the marker angle for the whole symbol.
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
bool isFavorite() const
returns whether the favorite element is checked
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.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
a dialog for setting properties of a newly saved style.
static const double UI_SCALE_FACTOR
UI scaling factor.
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.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
void setTagId(int id)
Sets a tag id to filter style entities by.
double width() const
Returns the estimated width for the whole symbol, which is the maximum width of all marker symbol lay...
void setSize(double size)
Sets the size for the whole symbol.
bool forceRHR() const
Returns true if polygon features drawn by the symbol will be reoriented to follow the standard right-...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
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.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
qreal opacity() const
Returns the opacity for the symbol.
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.
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.
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.
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.
QgsMapUnitScale mapUnitScale() const
Returns the map unit scale for the symbol.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void groupsModified()
Is emitted every time a tag or smartgroup has been added, removed, or renamed.
points (e.g., for font sizes)
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
QgsExpressionContext * expressionContext() const
Returns the expression context used for the widget, if set.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setScaleMethod(QgsSymbol::ScaleMethod scaleMethod)
Single scope for storing variables and functions for use within a QgsExpressionContext.
A store for object properties.
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).
QgsProperty dataDefinedWidth() const
Returns 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.
QStringList smartgroupNames()
Returns the smart groups list.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
bool addSymbol(const QString &name, QgsSymbol *symbol, bool update=false)
Adds a symbol to style and takes symbol's ownership.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
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.
QString name() const
returns the text value of the name element
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
SymbolType type() const
Returns the symbol's type.
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.
QList< QgsExpressionContextScope > additionalExpressionContextScopes() const
Returns the list of additional expression context scopes to show as available within the layer...
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
QList< QgsExpressionContextScope * > globalProjectAtlasMapLayerScopes(const QgsMapLayer *layer) const
Returns list of scopes: global, project, atlas, map, layer.
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...
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...
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
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.
QColor color() const
Returns the symbol's color.
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.
QStringList tags() const
Returns a list of all tags in the style database.
QString tags() const
returns the text value of the tags element
Property
Data definable properties.
void setColor(const QColor &color)
Sets the color for the symbol.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.