36 #include <QStringList> 39 #include <QStandardItemModel> 40 #include <QColorDialog> 41 #include <QInputDialog> 42 #include <QMessageBox> 44 #include <QPushButton> 55 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsSymbolsListWidget::groupsCombo_currentIndexChanged );
56 spinAngle->setClearValue( 0 );
66 btnAdvanced->setMenu( mAdvancedMenu );
70 btnAdvanced->setMenu(
new QMenu(
this ) );
72 mClipFeaturesAction =
new QAction( tr(
"Clip Features to Canvas Extent" ),
this );
73 mClipFeaturesAction->setCheckable(
true );
76 QStandardItemModel *model =
new QStandardItemModel( viewSymbols );
77 viewSymbols->setModel( model );
85 lblSymbolName->clear();
96 stackedWidget->setCurrentIndex( symbol->
type() );
110 updateAssistantSymbol();
112 btnColor->setAllowOpacity(
true );
113 btnColor->setColorDialogTitle( tr(
"Select Color" ) );
114 btnColor->setContext( QStringLiteral(
"symbology" ) );
131 btnAdvanced->menu()->removeAction( mClipFeaturesAction );
136 button->setProperty(
"propertyKey", key );
142 void QgsSymbolsListWidget::createAuxiliaryField()
166 property.setActive(
true );
205 if ( ddButton->assistant() )
206 ddButton->assistant()->setMapCanvas( mContext.
mapCanvas() );
218 groupsCombo->blockSignals(
true );
219 groupsCombo->clear();
221 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
222 groupsCombo->addItem( tr(
"All Symbols" ), QVariant(
"all" ) );
225 QStringList tags = mStyle->
tags();
226 if ( tags.count() > 0 )
229 groupsCombo->insertSeparator( index );
230 Q_FOREACH (
const QString &tag, tags )
232 groupsCombo->addItem( tag, QVariant(
"tag" ) );
238 if ( groups.count() > 0 )
241 groupsCombo->insertSeparator( index + 1 );
242 Q_FOREACH (
const QString &group, groups )
244 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
247 groupsCombo->blockSignals(
false );
250 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
251 groupsCombo->setCurrentIndex( index );
253 populateSymbolView();
256 void QgsSymbolsListWidget::populateSymbolView()
259 QString text = groupsCombo->currentText();
262 if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
266 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
270 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
277 id = mStyle->
tagId( text );
282 populateSymbols( symbols );
285 void QgsSymbolsListWidget::populateSymbols(
const QStringList &names )
287 QSize previewSize = viewSymbols->iconSize();
289 QStandardItemModel *model = qobject_cast<QStandardItemModel *>( viewSymbols->model() );
296 for (
int i = 0; i < names.count(); i++ )
305 QStandardItem *item =
new QStandardItem( names[i] );
306 item->setData( names[i], Qt::UserRole );
307 item->setText( names[i] );
308 item->setToolTip( QStringLiteral(
"<b>%1</b><br><i>%2</i>" ).arg( names[i], tags.count() > 0 ? tags.join( QStringLiteral(
", " ) ) : tr(
"Not tagged" ) ) );
309 item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
311 QFont itemFont = item->font();
312 itemFont.setPointSize( 10 );
313 item->setFont( itemFont );
316 item->setIcon( icon );
318 model->appendRow( item );
328 populateSymbolView();
360 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
377 if ( markerSymbol->
size() == size )
388 spinSize->setEnabled( !mSizeDDBtn->isActive() );
406 if ( lineSymbol->
width() == width )
417 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
431 void QgsSymbolsListWidget::updateAssistantSymbol()
433 mAssistantSymbol.reset( mSymbol->
clone() );
435 mSizeDDBtn->setSymbol( mAssistantSymbol );
437 mWidthDDBtn->setSymbol( mAssistantSymbol );
444 populateSymbolView();
450 QString name = QInputDialog::getText(
this, tr(
"Symbol name" ),
451 tr(
"Please enter name for the symbol:" ), QLineEdit::Normal, tr(
"New symbol" ), &ok );
452 if ( !ok || name.isEmpty() )
458 int res = QMessageBox::warning(
this, tr(
"Save symbol" ),
459 tr(
"Symbol with name '%1' already exists. Overwrite?" )
461 QMessageBox::Yes | QMessageBox::No );
462 if ( res != QMessageBox::Yes )
473 populateSymbolView();
479 if ( !saveDlg.exec() )
482 if ( saveDlg.
name().isEmpty() )
488 int res = QMessageBox::warning(
this, tr(
"Save symbol" ),
489 tr(
"Symbol with name '%1' already exists. Overwrite?" )
490 .arg( saveDlg.
name() ),
491 QMessageBox::Yes | QMessageBox::No );
492 if ( res != QMessageBox::Yes )
499 QStringList symbolTags = saveDlg.
tags().split(
',' );
508 void QgsSymbolsListWidget::mSymbolUnitWidget_changed()
520 void QgsSymbolsListWidget::opacityChanged(
double opacity )
529 void QgsSymbolsListWidget::updateSymbolColor()
531 btnColor->blockSignals(
true );
532 btnColor->setColor( mSymbol->
color() );
533 btnColor->blockSignals(
false );
558 void QgsSymbolsListWidget::updateSymbolInfo()
570 spinSize->setValue( markerSymbol->
size() );
571 spinAngle->setValue( markerSymbol->
angle() );
577 spinSize->setEnabled( !mSizeDDBtn->isActive() );
580 spinAngle->setEnabled( !mRotationDDBtn->isActive() );
584 mSizeDDBtn->setEnabled(
false );
585 mRotationDDBtn->setEnabled(
false );
591 spinWidth->setValue( lineSymbol->
width() );
597 spinWidth->setEnabled( !mWidthDDBtn->isActive() );
601 mWidthDDBtn->setEnabled(
false );
605 mSymbolUnitWidget->blockSignals(
true );
606 mSymbolUnitWidget->setUnit( mSymbol->
outputUnit() );
607 mSymbolUnitWidget->setMapUnitScale( mSymbol->
mapUnitScale() );
608 mSymbolUnitWidget->blockSignals(
false );
610 mOpacityWidget->setOpacity( mSymbol->
opacity() );
613 const QList<QAction *> actionList( btnAdvanced->menu()->actions() );
614 for (
const auto &action : actionList )
616 if ( mClipFeaturesAction->text() == action->text() )
618 btnAdvanced->menu()->removeAction( action );
625 btnAdvanced->menu()->addAction( mClipFeaturesAction );
628 btnAdvanced->setVisible( mAdvancedMenu || !btnAdvanced->menu()->isEmpty() );
630 mClipFeaturesAction->blockSignals(
true );
632 mClipFeaturesAction->blockSignals(
false );
637 QString symbolName = index.data( Qt::UserRole ).toString();
638 lblSymbolName->setText( symbolName );
659 void QgsSymbolsListWidget::groupsCombo_currentIndexChanged(
int index )
662 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), index );
664 populateSymbolView();
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
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.
QString tags() const
returns the text value of the tags element
void symbolSaved(const QString &name, QgsSymbol *symbol)
Is emitted every time a new symbol has been added to the database.
static const QString EXPR_GEOMETRY_POINT_COUNT
Inbuilt variable name for point count variable.
void setMapUnitScale(const QgsMapUnitScale &scale)
Calculate scale by the diameter.
a dialog for setting properties of a newly saved style.
This class is a composition of two QSettings instances:
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Append symbol layer at the end of the list Ownership will be transferred.
QgsMapUnitScale mapUnitScale() const
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with 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...
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
bool deleteSymbolLayer(int index)
delete symbol layer at 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.
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)
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.
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 setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
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)
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.
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.
void setDataDefinedWidth(const QgsProperty &property)
Set data defined width for whole symbol (including all symbol layers).
Definition for a property.
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
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.
virtual QgsSymbol * clone() const =0
Get a deep copy of this symbol.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
double size() const
Returns the size for the whole symbol, which is the maximum size of all marker symbol layers in the s...
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.
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.
QgsSymbolLayer * takeSymbolLayer(int index)
Remove symbol layer from the list and return pointer to it.
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
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)
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the symbol layer property definitions.
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).
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
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)