QGIS API Documentation 4.3.0-Master (0cfde48c85b)
Loading...
Searching...
No Matches
qgssymbollayermodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayermodel.h
3 ---------------------
4 begin : June 2026
5 copyright : (C) 2026 by Celia Buira
6 email : celia dot buira at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgssymbollayermodel.h"
17
18#include "qgsapplication.h"
20#include "qgsguiutils.h"
21#include "qgslinesymbol.h"
22#include "qgsmarkersymbol.h"
23#include "qgsstyle.h"
24#include "qgssymbol.h"
25#include "qgssymbollayer.h"
27#include "qgssymbollayerutils.h"
28#include "qgsvectorlayer.h"
29
30#include <qscreen.h>
31
32#include "moc_qgssymbollayermodel.cpp"
33
34using namespace Qt::StringLiterals;
35
38
40 : mVectorLayer( vectorLayer )
41 , mScreen( screen )
42{
43 setLayer( layer, symbolType );
44}
45
47 : mVectorLayer( vectorLayer )
48 , mScreen( screen )
49{
50 setSymbol( symbol );
51}
52
57
59{
60 mLayer = layer;
61 mIsLayer = true;
62 mSymbol = nullptr;
63 mSymbolType = symbolType;
64}
65
67{
68 mScreen = screen;
69}
70
71void QgsSymbolLayerModelNode::setSymbol( QgsSymbol *symbol )
72{
73 mSymbol = symbol;
74 mIsLayer = false;
75 mLayer = nullptr;
76}
77
79{
80 const int size = QgsGuiUtils::scaleIconSize( 16 );
81 const QSize iconSize = QSize( size, size );
82
83 QIcon icon;
84 if ( mIsLayer )
86 symbolLayerPreviewIcon( mLayer, Qgis::RenderUnit::Millimeters, iconSize, QgsMapUnitScale(), mSymbol ? mSymbol->type() : mSymbolType, mVectorLayer, QgsScreenProperties( mScreen.data() ) );
87 else
88 {
89 QgsExpressionContext expContext;
90 // TODO -- this model should have a way to register an explicit expression context, so that the preview icons
91 // correctly reflect atlas features/map scales/etc
93 icon = QIcon( QgsSymbolLayerUtils::symbolPreviewPixmap( mSymbol, iconSize, 0, nullptr, false, &expContext, nullptr, QgsScreenProperties( mScreen.data() ) ) );
94 }
95 return icon;
96}
97
98QVariant QgsSymbolLayerModelNode::data( int role ) const
99{
100 if ( role == Qt::DisplayRole || role == Qt::EditRole )
101 {
102 if ( mIsLayer )
103 {
105 if ( m )
106 return m->visibleName();
107 else
108 return QString();
109 }
110 else
111 {
112 switch ( mSymbol->type() )
113 {
115 return QCoreApplication::translate( "QgsSymbolLayerModelNode", "Marker" );
117 return QCoreApplication::translate( "QgsSymbolLayerModelNode", "Fill" );
119 return QCoreApplication::translate( "QgsSymbolLayerModelNode", "Line" );
121 return "Symbol";
122 default:
123 QgsDebugError( "Unhandled Symbol Type" );
124 }
125 }
126 }
127 else if ( role == Qt::ForegroundRole && mIsLayer )
128 {
129 if ( !mLayer->enabled() )
130 {
131 QPalette pal = qApp->palette();
132 QBrush brush = QBrush();
133 brush.setColor( pal.color( QPalette::Disabled, QPalette::WindowText ) );
134 return brush;
135 }
136 else
137 {
138 return QVariant();
139 }
140 }
141 else if ( role == Qt::DecorationRole )
142 {
143 return icon();
144 }
145 else if ( role == Qt::FontRole && !mIsLayer )
146 {
147 QFont font;
148 font.setBold( true );
149 return font;
150 }
151 else if ( role == Qt::CheckStateRole )
152 {
153 if ( !mIsLayer )
154 {
155 return Qt::CheckState::PartiallyChecked;
156 }
157
158 if ( mLayer->enabled() )
159 {
160 return Qt::CheckState::Checked;
161 }
162 else
163 {
164 return Qt::CheckState::Unchecked;
165 }
166 }
167 return QVariant();
168}
169
171{
172 mChildren.clear();
173}
174
175QgsSymbolLayerModelNode *QgsSymbolLayerModelNode::addChildNode( std::unique_ptr<QgsSymbolLayerModelNode> node )
176{
177 if ( !node )
178 return nullptr;
179
180 Q_ASSERT( !node->mParent );
181 node->mParent = this;
182
183 return mChildren.emplace_back( std::move( node ) ).get();
184}
185
186QgsSymbolLayerModelNode *QgsSymbolLayerModelNode::insertChildNode( int index, std::unique_ptr<QgsSymbolLayerModelNode> node )
187{
188 if ( !node )
189 return nullptr;
190
191 Q_ASSERT( !node->mParent );
192 node->mParent = this;
193
194 return mChildren.insert( mChildren.begin() + index, std::move( node ) )->get();
195}
196
198{
199 if ( !node )
200 return;
201
202 // Only allow moving a node that is a child of this current node
203 Q_ASSERT( node->mParent == this );
204
205 int idx = indexOf( node );
206 if ( idx != -1 && idx != to )
207 {
208 std::unique_ptr<QgsSymbolLayerModelNode> n = std::move( mChildren.at( idx ) );
209 mChildren.erase( mChildren.begin() + idx );
210 mChildren.insert( mChildren.begin() + to, std::move( n ) );
211 }
212}
213
215{
216 if ( !node )
217 return;
218
219 int idx = indexOf( node );
220 if ( idx != -1 )
221 {
222 mChildren.erase( mChildren.begin() + idx );
223 }
224}
225
227{
228 return mChildren.at( index ).get();
229}
230
232{
233 Q_ASSERT( node->mParent == this );
234
235 auto it = std::find_if( mChildren.begin(), mChildren.end(), [&]( const std::unique_ptr<QgsSymbolLayerModelNode> &p ) { return p.get() == node; } );
236
237 if ( it != mChildren.end() )
238 return std::distance( mChildren.begin(), it );
239 return -1;
240}
241
243{
244 return mChildren.size();
245}
246
248{
249 if ( !mParent )
250 return -1;
251
252 return mParent->indexOf( this );
253}
254
256 : QAbstractItemModel( parent )
257 , mRootNode( std::make_unique<QgsSymbolLayerModelNode>() )
258 , mVectorLayer( vl )
259 , mScreen( screen )
260{}
261
262Qt::ItemFlags QgsSymbolLayerModel::flags( const QModelIndex &index ) const
263{
264 if ( !index.isValid() )
265 return Qt::ItemFlags();
266
267 Qt::ItemFlags f = Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsSelectable;
268
270 if ( node->isLayer() )
271 {
272 f |= Qt::ItemFlag::ItemIsUserCheckable;
273 }
274 else
275 {
276 f &= ~Qt::ItemFlag::ItemIsUserCheckable;
277 }
278
279 return f;
280}
281
282QVariant QgsSymbolLayerModel::data( const QModelIndex &index, int role ) const
283{
284 if ( !index.isValid() )
285 return QVariant();
286
288 if ( !node )
289 return QVariant();
290
291 return node->data( role );
292};
293
294bool QgsSymbolLayerModel::setData( const QModelIndex &index, const QVariant &value, int role )
295{
296 if ( !index.isValid() )
297 return false;
298
300 if ( !node )
301 return false;
302
303 if ( role == Qt::CheckStateRole )
304 {
305 if ( !node->isLayer() )
306 return false;
307
308
309 bool checked = value.value<Qt::CheckState>() == Qt::Checked;
310 QgsSymbolLayer *symbolLayer = node->layer();
311 symbolLayer->setEnabled( checked );
312
313 emit dataChanged( index, index, { Qt::CheckStateRole } );
314 updatePreviewIcons( node );
315 return true;
316 }
317 return QAbstractItemModel::setData( index, value, role );
318}
319
320int QgsSymbolLayerModel::rowCount( const QModelIndex &parent ) const
321{
323 if ( !n )
324 return 0;
325
326 return n->rowCount();
327};
328
329int QgsSymbolLayerModel::columnCount( const QModelIndex & ) const
330{
331 return 1;
332};
333
334QModelIndex QgsSymbolLayerModel::index( int row, int column, const QModelIndex &parent ) const
335{
336 if ( !hasIndex( row, column, parent ) )
337 return QModelIndex();
338
340 if ( !node )
341 return QModelIndex(); // have no children
342
343 return createIndex( row, column, node->childAt( row ) );
344};
345
346QModelIndex QgsSymbolLayerModel::parent( const QModelIndex &child ) const
347{
348 if ( !child.isValid() )
349 return QModelIndex();
350
351 if ( QgsSymbolLayerModelNode *node = index2node( child ) )
352 {
353 return indexOfParentTreeNode( node->parent() ); // must not be null
354 }
355 else
356 {
357 Q_ASSERT( false ); // no other node types!
358 return QModelIndex();
359 }
360};
361
362QModelIndex QgsSymbolLayerModel::indexOfParentTreeNode( QgsSymbolLayerModelNode *parentNode ) const
363{
364 Q_ASSERT( parentNode );
365
366 QgsSymbolLayerModelNode *grandParentNode = parentNode->parent();
367 if ( !grandParentNode )
368 return QModelIndex(); // root node -> invalid index
369
370 int row = grandParentNode->indexOf( parentNode );
371 Q_ASSERT( row >= 0 );
372
373 return createIndex( row, 0, parentNode );
374};
375
377{
378 if ( !index.isValid() )
379 return mRootNode.get();
380
381 return reinterpret_cast<QgsSymbolLayerModelNode *>( index.internalPointer() );
382};
383
385{
386 if ( !node || !node->parent() )
387 return QModelIndex(); // this is the only root item -> invalid index
388
389 QModelIndex parentIndex = node2index( node->parent() );
390
391 int row = node->parent()->indexOf( node );
392 Q_ASSERT( row >= 0 );
393 return index( row, 0, parentIndex );
394};
395
396void QgsSymbolLayerModel::rebuild()
397{
398 beginResetModel();
399 mRootNode->deleteChildren();
400 loadSymbol( mSymbol, mRootNode.get() );
401 endResetModel();
402}
403
405{
406 const QModelIndex parentIndex = node2index( parent );
407 beginRemoveRows( parentIndex, 0, rowCount( parentIndex ) - 1 );
408 parent->deleteChildren();
409 endRemoveRows();
410
411 beginInsertRows( parentIndex, 0, symbol->symbolLayerCount() - 1 );
412
413 loadSymbol( symbol, parent );
414
415 endInsertRows();
416}
417
419{
420 if ( !node->isLayer() )
421 return;
422
424 QModelIndex parentIndex = node2index( parent );
425 const int row = node->rowIndex();
426
427 QgsSymbol *parentSymbol = parent->symbol();
428
429 const int layerIdx = parent->rowCount() - row - 1;
430 // switch layers
431 QgsSymbolLayer *tmpLayer = parentSymbol->takeSymbolLayer( layerIdx );
432 parentSymbol->insertSymbolLayer( layerIdx - offset, tmpLayer );
433
434 beginMoveRows( parentIndex, row, row, parentIndex, row + offset + ( offset > 0 ? 1 : 0 ) );
435 parent->moveChildNode( node, row + offset );
436 endMoveRows();
437}
438
440{
441 if ( !node->isLayer() )
442 return nullptr;
443
444 QgsSymbolLayer *source = node->layer();
445 const int insertIdx = node->rowIndex();
447 QModelIndex parentIndex = node2index( parent );
448
449 QgsSymbol *parentSymbol = parent->symbol();
450
451 QgsSymbolLayer *newLayer = source->clone();
453 if ( insertIdx == -1 )
454 parentSymbol->appendSymbolLayer( newLayer );
455 else
456 parentSymbol->insertSymbolLayer( parent->rowCount() - insertIdx, newLayer );
457
458
459 beginInsertRows( parentIndex, insertIdx, insertIdx );
460
461 auto newNode = std::make_unique<QgsSymbolLayerModelNode>( newLayer, parentSymbol->type(), mVectorLayer, mScreen );
462 QgsSymbolLayerModelNode *newNodePtr;
463 if ( insertIdx == -1 )
464 newNodePtr = parent->addChildNode( std::move( newNode ) );
465 else
466 newNodePtr = parent->insertChildNode( insertIdx, std::move( newNode ) );
467
468 if ( newLayer->subSymbol() )
469 {
470 loadSymbol( newLayer->subSymbol(), newNodePtr );
471 }
472
473 endInsertRows();
474
475 return newNodePtr;
476}
477
479{
480 if ( !index.isValid() )
481 return nullptr;
482
483 int insertIdx = -1;
485 if ( node->isLayer() )
486 {
487 insertIdx = node->rowIndex();
488 node = node->parent();
489 }
490
491
492 QgsSymbol *parentSymbol = node->symbol();
493
494 // save data-defined values from symbol, to apply to the new symbol layer
495 const QgsProperty ddSize( parentSymbol->type() == Qgis::SymbolType::Marker ? static_cast<QgsMarkerSymbol *>( parentSymbol )->dataDefinedSize() : QgsProperty() );
496 const QgsProperty ddAngle( parentSymbol->type() == Qgis::SymbolType::Marker ? static_cast<QgsMarkerSymbol *>( parentSymbol )->dataDefinedAngle() : QgsProperty() );
497 const QgsProperty ddWidth( parentSymbol->type() == Qgis::SymbolType::Line ? static_cast<QgsLineSymbol *>( parentSymbol )->dataDefinedWidth() : QgsProperty() );
498
499 QgsSymbolLayer *newLayer = QgsSymbolLayerRegistry::defaultSymbolLayer( parentSymbol->type() ).release();
500 {
501 // Transfer the ownership to the parent symbol, which takes ownership of the layer
502 if ( insertIdx == -1 )
503 parentSymbol->appendSymbolLayer( newLayer );
504 else
505 parentSymbol->insertSymbolLayer( node->rowCount() - insertIdx, newLayer );
506 }
507
508 // restore data-defined values from the symbol
509 if ( ddSize )
510 static_cast<QgsMarkerSymbol *>( parentSymbol )->setDataDefinedSize( ddSize );
511 if ( ddAngle )
512 static_cast<QgsMarkerSymbol *>( parentSymbol )->setDataDefinedAngle( ddAngle );
513 if ( ddWidth )
514 static_cast<QgsLineSymbol *>( parentSymbol )->setDataDefinedWidth( ddWidth );
515
516
517 const int atRowIndex = ( insertIdx == -1 ) ? 0 : insertIdx;
518 beginInsertRows( node2index( node ), atRowIndex, atRowIndex );
519
520 auto newNode = std::make_unique<QgsSymbolLayerModelNode>( newLayer, parentSymbol->type(), mVectorLayer, mScreen );
521
522 QgsSymbolLayerModelNode *newNodePtr = node->insertChildNode( atRowIndex, std::move( newNode ) );
523
524 endInsertRows();
525
526 return newNodePtr;
527}
528
530{
531 if ( !node->isLayer() )
532 return;
533
534 const int row = node->rowIndex();
536 const int layerIdx = parent->rowCount() - row - 1; // The index in the model and the symbol are inverted
537 QgsSymbol *parentSymbol = parent->symbol();
538
539 beginRemoveRows( node2index( parent ), row, row );
540 parent->removeChildNode( node );
541
542 QgsSymbolLayer *tmpLayer = parentSymbol->takeSymbolLayer( layerIdx );
543 //finally delete the removed layer pointer
544 delete tmpLayer;
545 endRemoveRows();
546}
547
549{
550 QgsSymbolLayerModelNode *parentNode = node->parent();
551 QgsSymbol *parentSymbol = parentNode->symbol();
552
553 const int layerIdx = parentNode->rowCount() - node->rowIndex() - 1;
554 parentSymbol->changeSymbolLayer( layerIdx, newLayer );
555
556 if ( node->rowCount() > 0 )
557 {
558 beginRemoveRows( node2index( node ), 0, node->rowCount() - 1 );
559 node->deleteChildren();
560 endRemoveRows();
561 }
562
563 node->setLayer( newLayer, parentSymbol->type() );
564 if ( newLayer->subSymbol() )
565 {
566 updateNode( newLayer->subSymbol(), node );
567 }
568
569 updatePreviewIcons( node );
570}
571
573{
574 const QModelIndex index = node2index( node );
575 if ( !index.isValid() )
576 return;
577
578 emit dataChanged( index, index, QVector<int>() << Qt::DecorationRole );
579
580 // Recursively update the parent's preview up to the root node.
581 if ( QgsSymbolLayerModelNode *lParent = node->parent() )
582 updatePreviewIcons( lParent );
583}
584
585
587{
588 if ( symbol )
589 {
590 mSymbol = symbol;
591 }
592
593 rebuild();
594}
595
596void QgsSymbolLayerModel::setScreen( QScreen *screen )
597{
598 mScreen = screen;
599
600 // BFS traversal to set the screen for all nodes and update their preview icons
601 QList<QgsSymbolLayerModelNode * > stack;
602 stack.append( mRootNode.get() );
603
604 while ( !stack.isEmpty() )
605 {
606 QgsSymbolLayerModelNode *node = stack.takeLast();
607 node->setScreen( mScreen );
608 updatePreviewIcons( node );
609
610 for ( int i = 0; i < node->rowCount(); ++i )
611 {
612 stack.append( node->childAt( i ) );
613 }
614 }
615}
616
617void QgsSymbolLayerModel::loadSymbol( QgsSymbol *symbol, QgsSymbolLayerModelNode *parent )
618{
619 if ( !symbol )
620 return;
621
622 if ( !parent )
623 {
624 return;
625 }
626
627 auto symbolNode = std::make_unique<QgsSymbolLayerModelNode>( symbol, mVectorLayer, mScreen );
628 const int count = symbol->symbolLayerCount();
629 for ( int i = count - 1; i >= 0; i-- )
630 {
631 auto layerNode = std::make_unique<QgsSymbolLayerModelNode>( symbol->symbolLayer( i ), symbol->type(), mVectorLayer, mScreen );
632 if ( symbol->symbolLayer( i )->subSymbol() )
633 {
634 loadSymbol( symbol->symbolLayer( i )->subSymbol(), layerNode.get() );
635 }
636 symbolNode->addChildNode( std::move( layerNode ) );
637 }
638 parent->addChildNode( std::move( symbolNode ) );
639}
@ Millimeters
Millimeters.
Definition qgis.h:5759
SymbolType
Symbol types.
Definition qgis.h:671
@ Marker
Marker symbol.
Definition qgis.h:672
@ Line
Line symbol.
Definition qgis.h:673
@ Fill
Fill symbol.
Definition qgis.h:674
@ Hybrid
Hybrid symbol.
Definition qgis.h:675
static QgsSymbolLayerRegistry * symbolLayerRegistry()
Returns the application's symbol layer registry, used for managing symbol layers.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsProperty dataDefinedWidth() const
Returns data defined width for whole symbol (including all symbol layers).
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsProperty dataDefinedAngle() const
Returns data defined angle for whole symbol (including all symbol layers).
QgsProperty dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
A store for object properties.
Stores properties relating to a screen.
Stores metadata about one symbol layer class.
A node contained within a QgsSymbolLayerModel.
QgsSymbolLayerModelNode * parent()
Returns the pointer of the parent node. If parent is nullptr, the node is a root node.
void setLayer(QgsSymbolLayer *layer, Qgis::SymbolType symbolType)
Sets the layer associated with the node, and the symbolType of the QgsSymbol it belongs to.
QgsSymbol * symbol()
Returns the symbol pointer; helpful in determining a layer's parent symbol.
QgsSymbolLayer * layer()
Returns the symbol layer pointer.
int rowCount() const
Returns the number of rows(children) belonging to the node.
QgsSymbolLayerModelNode * childAt(int index) const
Returns the child node at the given index.
void moveChildNode(QgsSymbolLayerModelNode *node, int to)
Move a child node of the current node, the ownership of the moved node is transferred to the current ...
int rowIndex() const
Returns the row index of the node within its parent.
QgsSymbolLayerModelNode * insertChildNode(int index, std::unique_ptr< QgsSymbolLayerModelNode > node)
Inserts a child node to this node at index, transferring ownership of the node.
void removeChildNode(QgsSymbolLayerModelNode *node)
Remove a child node of the current node.
QIcon icon() const
Returns the item preview icon.
void setScreen(QScreen *screen)
Sets the screen associated with the node, which is used to render the preview icons.
bool isLayer() const
Returns true if the node is a symbol layer. And otherwise, it is a symbol.
void deleteChildren()
Deletes all child nodes from this node.
QgsSymbolLayerModelNode()
Constructor for QgsSymbolLayerModelNode for an empty node.
int indexOf(const QgsSymbolLayerModelNode *node)
Returns the index position of the given node within the current node's children.
QVariant data(int role) const
Returns the item's data for the given role.
QgsSymbolLayerModelNode * addChildNode(std::unique_ptr< QgsSymbolLayerModelNode > node)
Adds a child node to this node, transferring ownership of the node.
int columnCount(const QModelIndex &=QModelIndex()) const override
void updateNode(QgsSymbol *symbol, QgsSymbolLayerModelNode *parent)
Updates the descendants of the given parent node with the given symbol.
QModelIndex parent(const QModelIndex &child) const override
QVariant data(const QModelIndex &index, int role) const override
QgsSymbolLayerModelNode * addLayer(QModelIndex index)
Adds the symbol layer node inserted right before the idx.
bool setData(const QModelIndex &index, const QVariant &value, int role) override
void removeLayer(QgsSymbolLayerModelNode *node)
Removes the symbol layer node from it's parent node hierarchy.
void moveLayerByOffset(QgsSymbolLayerModelNode *node, int offset)
Moves the symbol layer node by the offset in the parent hierarchy.
QgsSymbolLayerModelNode * duplicateLayer(QgsSymbolLayerModelNode *node)
Duplicates the symbol layer node in the parent node hierarchy.
QModelIndex node2index(QgsSymbolLayerModelNode *node) const
Returns the model index corresponding to the given node.
QgsSymbolLayerModel(QgsVectorLayer *vl, QObject *parent=nullptr, QScreen *screen=nullptr)
Constructor for QgsSymbolLayerModel, with the specified parent object.
Qt::ItemFlags flags(const QModelIndex &index) const override
void setSymbol(QgsSymbol *symbol)
Sets the symbol associated with the model.
void setScreen(QScreen *screen)
Set the QScreen of the model itself.
void changeLayer(QgsSymbolLayerModelNode *node, QgsSymbolLayer *newLayer)
Change the symbol layer associated with node by a newLayer symbol layer.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QgsSymbolLayerModelNode * index2node(const QModelIndex &index) const
Returns the model node corresponding to the given index.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void updatePreviewIcons(QgsSymbolLayerModelNode *node)
Updates the preview icon of the given node.
static std::unique_ptr< QgsSymbolLayer > defaultSymbolLayer(Qgis::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings
QgsSymbolLayerAbstractMetadata * symbolLayerMetadata(const QString &name) const
Returns metadata for specified symbol layer. Returns nullptr if not found.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, Qgis::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::SymbolType parentSymbolType=Qgis::SymbolType::Hybrid, QgsMapLayer *mapLayer=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Draws a symbol layer preview to an icon.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for a color ramp.
static void resetSymbolLayerIds(QgsSymbol *symbol)
Regenerate recursively unique id from all symbol symbol layers.
Abstract base class for symbol layers.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
void setEnabled(bool enabled)
Sets whether symbol layer is enabled and should be drawn.
virtual QgsSymbol * subSymbol()
Returns the symbol's sub symbol, if present.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
bool appendSymbolLayer(QgsSymbolLayer *layer)
Appends a symbol layer at the end of the current symbol layer list.
bool insertSymbolLayer(int index, QgsSymbolLayer *layer)
Inserts a symbol layer to specified index.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
QgsSymbolLayer * takeSymbolLayer(int index)
Removes a symbol layer from the list and returns a pointer to it.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:357
Qgis::SymbolType type() const
Returns the symbol's type.
Definition qgssymbol.h:296
Represents a vector layer which manages a vector based dataset.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
#define QgsDebugError(str)
Definition qgslogger.h:71