QGIS API Documentation 4.3.0-Master (621ced71bd7)
Loading...
Searching...
No Matches
qgssymbollayermodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbollayermodel.h
3 ---------------------
4 begin : June 2026
5 copyright : (C) 2026 by Valentin Buira
6 email : valentin 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#ifndef QGSSYMBOLLAYERMODEL_H
17#define QGSSYMBOLLAYERMODEL_H
18
19#include <deque>
20
21#include "qgis.h"
22#include "qgis_gui.h"
23#include "qgsvectorlayer.h"
24
25#include <QAbstractItemModel>
26
27#define SIP_NO_FILE
28
30class QgsSymbol;
31class QScreen;
32class QgsSymbolLayer;
33
34
42{
43 public:
52 QgsSymbolLayerModelNode( QgsSymbolLayer *layer, Qgis::SymbolType symbolType, QgsVectorLayer *vectorLayer, QScreen *screen );
57 QgsSymbolLayerModelNode( QgsSymbol *symbol, QgsVectorLayer *vectorLayer, QScreen *screen );
59
64 void setLayer( QgsSymbolLayer *layer, Qgis::SymbolType symbolType );
65
69 void setScreen( QScreen *screen );
70
72 bool isLayer() const { return mIsLayer; }
73
75 QIcon icon() const;
76
78 QVariant data( int role ) const;
79
81 QgsSymbol *symbol() { return mSymbol; }
82
84 QgsSymbolLayer *layer() { return mLayer; }
85
90 QgsSymbolLayerModelNode *addChildNode( std::unique_ptr<QgsSymbolLayerModelNode> node );
91
96 QgsSymbolLayerModelNode *insertChildNode( int index, std::unique_ptr<QgsSymbolLayerModelNode> node );
97
102 void moveChildNode( QgsSymbolLayerModelNode *node, int to );
103
107 void removeChildNode( QgsSymbolLayerModelNode *node );
108
112 void deleteChildren();
113
115 QgsSymbolLayerModelNode *parent() { return mParent; }
116
118 bool isRootNode() const { return mParent == nullptr; }
119
123 QgsSymbolLayerModelNode *childAt( int index ) const;
124
128 int indexOf( const QgsSymbolLayerModelNode *node );
129
133 int rowCount() const;
134
138 int rowIndex() const;
139
140 private:
145 void setSymbol( QgsSymbol *symbol );
146
147 QgsSymbolLayer *mLayer = nullptr;
148 QgsSymbol *mSymbol = nullptr;
149 QPointer<QgsVectorLayer> mVectorLayer;
150 bool mIsLayer = false;
151 QSize mSize;
153 QPointer<QScreen> mScreen;
154
155 QgsSymbolLayerModelNode *mParent = nullptr;
156 std::deque<std::unique_ptr<QgsSymbolLayerModelNode>> mChildren;
157
159};
160
167class GUI_EXPORT QgsSymbolLayerModel : public QAbstractItemModel
168{
169 Q_OBJECT
170
171 public:
175 QgsSymbolLayerModel( QgsVectorLayer *vl, QObject *parent SIP_TRANSFERTHIS = nullptr, QScreen *screen = nullptr );
176
177 QVariant data( const QModelIndex &index, int role ) const override;
178 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
179 int columnCount( const QModelIndex & = QModelIndex() ) const override;
180 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
181 QModelIndex parent( const QModelIndex &child ) const override;
182
187
191 void moveLayerByOffset( QgsSymbolLayerModelNode *node, int offset );
192
197
201 QgsSymbolLayerModelNode *addLayer( QModelIndex index );
202
207
211 void changeLayer( QgsSymbolLayerModelNode *node, QgsSymbolLayer *newLayer );
212
217
222 void setSymbol( QgsSymbol *symbol );
223
230 void setScreen( QScreen *screen );
231
236 QModelIndex node2index( QgsSymbolLayerModelNode *node ) const;
237
242 QgsSymbolLayerModelNode *index2node( const QModelIndex &index ) const;
243
245 QgsSymbolLayerModelNode *rootNode() const { return mRootNode.get(); }
246
247
248 private:
249 QModelIndex indexOfParentTreeNode( QgsSymbolLayerModelNode *parentNode ) const;
250 void loadSymbol( QgsSymbol *symbol, QgsSymbolLayerModelNode *parent );
251 void rebuild();
252
253 std::unique_ptr<QgsSymbolLayerModelNode> mRootNode;
254
255 QgsSymbol *mSymbol = nullptr;
256
257 QPointer<QgsVectorLayer> mVectorLayer;
258
259 QPointer<QScreen> mScreen;
260
262};
263
264#endif // QGSSYMBOLLAYERMODEL_H
SymbolType
Symbol types.
Definition qgis.h:651
@ Hybrid
Hybrid symbol.
Definition qgis.h:655
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.
bool isRootNode() const
Returns true if the node is a root node (i.e. has no parent).
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.
QgsSymbolLayerModelNode()
Constructor for QgsSymbolLayerModelNode for an empty 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.
void removeLayer(QgsSymbolLayerModelNode *node)
Removes the symbol layer node from it's parent node hierarchy.
void updatePreview(QgsSymbolLayerModelNode *node)
Updates the preview icon of the given node.
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.
QgsSymbolLayerModelNode * rootNode() const
Returns the root node of the model.
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.
void setSymbol(QgsSymbol *symbol)
Sets the symbol associated with the model.
void setScreen(QScreen *screen)
Set the QScreen of the model itself.
friend class TestQgsSymbolLayerModel
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
Abstract base class for symbol layers.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52