QGIS API Documentation 3.27.0-Master (0a97e3138f)
qgsstylemodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsstylemodel.h
3 ---------------
4 begin : September 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson 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 QGSSTYLEMODEL_H
17#define QGSSTYLEMODEL_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsstyle.h"
22#include <QAbstractItemModel>
23#include <QSortFilterProxyModel>
24#include <QIcon>
25#include <QHash>
26
27class QgsSymbol;
29
30#ifndef SIP_RUN
31
44class CORE_EXPORT QgsAbstractStyleEntityIconGenerator : public QObject
45{
46 Q_OBJECT
47
48 public:
49
54 QgsAbstractStyleEntityIconGenerator( QObject *parent );
55
60 virtual void generateIcon( QgsStyle *style, QgsStyle::StyleEntity type, const QString &name ) = 0;
61
67 void setIconSizes( const QList< QSize > &sizes );
68
74 QList< QSize > iconSizes() const;
75
76 signals:
77
82 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
83
84 private:
85
86 QList< QSize > mIconSizes;
87
88};
89
90#endif
91
107class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
108{
109 Q_OBJECT
110
111 public:
112
115 {
116 Name = 0,
118 };
119
121 enum Role
122 {
123 TypeRole = Qt::UserRole + 1,
133 };
134
140 explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
141
147 QgsStyle *style() { return mStyle; }
148
149 QVariant data( const QModelIndex &index, int role ) const override;
150 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
151 Qt::ItemFlags flags( const QModelIndex &index ) const override;
152 QVariant headerData( int section, Qt::Orientation orientation,
153 int role = Qt::DisplayRole ) const override;
154 QModelIndex index( int row, int column,
155 const QModelIndex &parent = QModelIndex() ) const override;
156 QModelIndex parent( const QModelIndex &index ) const override;
157 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
158 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
159
166 void addDesiredIconSize( QSize size );
167
176 static void setIconGenerator( QgsAbstractStyleEntityIconGenerator *generator ) SIP_SKIP;
177
178 private slots:
179
180 void onEntityAdded( QgsStyle::StyleEntity type, const QString &name );
181 void onEntityRemoved( QgsStyle::StyleEntity type, const QString &name );
182 void onEntityChanged( QgsStyle::StyleEntity type, const QString &name );
183 void onFavoriteChanged( QgsStyle::StyleEntity type, const QString &name, bool isFavorite );
184 void onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName );
185 void onTagsChanged( int entity, const QString &name, const QStringList &tags );
186 void rebuildSymbolIcons();
187 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
188
189 private:
190
191 QgsStyle *mStyle = nullptr;
192
193 QHash< QgsStyle::StyleEntity, QStringList > mEntityNames;
194
195 QList< QSize > mAdditionalSizes;
196 mutable std::unique_ptr< QgsExpressionContext > mExpressionContext;
197
198 mutable QHash< QgsStyle::StyleEntity, QHash< QString, QIcon > > mIconCache;
199
200 static QgsAbstractStyleEntityIconGenerator *sIconGenerator;
201 mutable QSet< QString > mPending3dSymbolIcons;
202
203 QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
204
205 int offsetForEntity( QgsStyle::StyleEntity entity ) const;
206 static QVariant headerDataStatic( int section, Qt::Orientation orientation,
207 int role = Qt::DisplayRole );
208
210};
211
222class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
223{
224 Q_OBJECT
225
226 public:
227
233 explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
234
240 explicit QgsStyleProxyModel( QgsStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
241
251 explicit QgsStyleProxyModel( QgsCombinedStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
252
258 QString filterString() const { return mFilterString; }
259
266 QgsStyle::StyleEntity entityFilter() const;
267
275 void setEntityFilter( QgsStyle::StyleEntity filter );
276
286 void setEntityFilters( const QList<QgsStyle::StyleEntity> &filters ) SIP_SKIP;
287
294 bool entityFilterEnabled() const;
295
305 void setEntityFilterEnabled( bool enabled );
306
315 Qgis::SymbolType symbolType() const;
316
324 void setSymbolType( Qgis::SymbolType type );
325
332 bool symbolTypeFilterEnabled() const;
333
344 void setSymbolTypeFilterEnabled( bool enabled );
345
354 QgsWkbTypes::GeometryType layerType() const;
355
362 void setLayerType( QgsWkbTypes::GeometryType type );
363
374 void setTagId( int id );
375
385 int tagId() const;
386
396 void setTagString( const QString &tag );
397
406 QString tagString() const;
407
418 void setSmartGroupId( int id );
419
429 int smartGroupId() const;
430
431 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
432 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
433
439 bool favoritesOnly() const;
440
446 void setFavoritesOnly( bool favoritesOnly );
447
454 void addDesiredIconSize( QSize size );
455
456 public slots:
457
464 void setFilterString( const QString &filter );
465
466 private:
467
468 void initialize();
469
470 QgsStyleModel *mModel = nullptr;
471 QgsCombinedStyleModel *mCombinedModel = nullptr;
472 QgsStyle *mStyle = nullptr;
473
474 QString mFilterString;
475
476 int mTagId = -1;
477 QStringList mTaggedSymbolNames;
478
479 QString mTagFilter;
480
481 int mSmartGroupId = -1;
482 QStringList mSmartGroupSymbolNames;
483
484 bool mFavoritesOnly = false;
485
486 bool mEntityFilterEnabled = false;
487 QList< QgsStyle::StyleEntity > mEntityFilters = QList< QgsStyle::StyleEntity >() << QgsStyle::SymbolEntity;
488
489 bool mSymbolTypeFilterEnabled = false;
491
493
494};
495
496#endif //QGSSTYLEMODEL_H
SymbolType
Symbol types.
Definition: qgis.h:206
@ Marker
Marker symbol.
An abstract base class for icon generators for a QgsStyleModel.
Definition: qgsstylemodel.h:45
virtual void generateIcon(QgsStyle *style, QgsStyle::StyleEntity type, const QString &name)=0
Triggers generation of an icon for an entity from the specified style database, with matching entity ...
void iconGenerated(QgsStyle::StyleEntity type, const QString &name, const QIcon &icon)
Emitted when the icon for the style entity with matching type and name has been generated.
A model which contains entities from multiple QgsStyle databases.
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Role
Custom model roles.
@ StyleName
Name of associated QgsStyle (QgsStyle::name()) (since QGIS 3.26)
@ LayerTypeRole
Layer type (for label settings entities)
@ StyleFileName
File name of associated QgsStyle (QgsStyle::fileName()) (since QGIS 3.26)
@ EntityName
Entity name (since QGIS 3.26)
@ CompatibleGeometryTypesRole
Compatible layer geometry types (for 3D symbols)
@ IsFavoriteRole
Whether entity is flagged as a favorite.
@ SymbolTypeRole
Symbol type (for symbol or legend patch shape entities)
@ IsTitleRole
True if the index corresponds to a title item (since QGIS 3.26)
@ TagRole
String list of tags.
QgsStyle * style()
Returns the style managed by the model.
Column
Model columns.
@ Tags
Tags column.
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
QString filterString() const
Returns the current filter string, if set.
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:179
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126