QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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
85 void setTargetScreenProperties( const QSet< QgsScreenProperties > &properties );
86
96 QSet< QgsScreenProperties > targetScreenProperties() const;
97
98 signals:
99
104 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
105
106 private:
107
108 QList< QSize > mIconSizes;
109 QSet< QgsScreenProperties > mTargetScreenProperties;
110
111};
112
113#endif
114
130class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
131{
132 Q_OBJECT
133
134 public:
135
138 {
139 Name = 0,
141 };
142
143 // *INDENT-OFF*
144
152 {
153 Type SIP_MONKEYPATCH_COMPAT_NAME(TypeRole) = Qt::UserRole + 1,
154 Tag SIP_MONKEYPATCH_COMPAT_NAME(TagRole),
155 EntityName,
156 SymbolType SIP_MONKEYPATCH_COMPAT_NAME(SymbolTypeRole),
157 IsFavorite SIP_MONKEYPATCH_COMPAT_NAME(IsFavoriteRole),
158 LayerType SIP_MONKEYPATCH_COMPAT_NAME(LayerTypeRole),
159 CompatibleGeometryTypes SIP_MONKEYPATCH_COMPAT_NAME(CompatibleGeometryTypesRole),
160 StyleName,
161 StyleFileName,
162 IsTitle SIP_MONKEYPATCH_COMPAT_NAME(IsTitleRole),
163 };
164 Q_ENUM( CustomRole )
165 // *INDENT-ON*
166
167
172 explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
173
179 QgsStyle *style() { return mStyle; }
180
181 QVariant data( const QModelIndex &index, int role ) const override;
182 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
183 Qt::ItemFlags flags( const QModelIndex &index ) const override;
184 QVariant headerData( int section, Qt::Orientation orientation,
185 int role = Qt::DisplayRole ) const override;
186 QModelIndex index( int row, int column,
187 const QModelIndex &parent = QModelIndex() ) const override;
188 QModelIndex parent( const QModelIndex &index ) const override;
189 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
190 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
191
198 void addDesiredIconSize( QSize size );
199
208 void addTargetScreenProperties( const QgsScreenProperties &properties );
209
218 static void setIconGenerator( QgsAbstractStyleEntityIconGenerator *generator ) SIP_SKIP;
219
220 private slots:
221
222 void onEntityAdded( QgsStyle::StyleEntity type, const QString &name );
223 void onEntityRemoved( QgsStyle::StyleEntity type, const QString &name );
224 void onEntityChanged( QgsStyle::StyleEntity type, const QString &name );
225 void onFavoriteChanged( QgsStyle::StyleEntity type, const QString &name, bool isFavorite );
226 void onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName );
227 void onTagsChanged( int entity, const QString &name, const QStringList &tags );
228 void rebuildSymbolIcons();
229 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
230
231 private:
232
233 void initStyleModel();
234
235 QgsStyle *mStyle = nullptr;
236
237 QHash< QgsStyle::StyleEntity, QStringList > mEntityNames;
238
239 QSet< QgsScreenProperties > mTargetScreenProperties;
240
241 QList< QSize > mAdditionalSizes;
242 mutable std::unique_ptr< QgsExpressionContext > mExpressionContext;
243
244 mutable QHash< QgsStyle::StyleEntity, QHash< QString, QIcon > > mIconCache;
245
246 static QgsAbstractStyleEntityIconGenerator *sIconGenerator;
247 mutable QSet< QString > mPending3dSymbolIcons;
248
249 QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
250
251 int offsetForEntity( QgsStyle::StyleEntity entity ) const;
252 static QVariant headerDataStatic( int section, Qt::Orientation orientation,
253 int role = Qt::DisplayRole );
254
256};
257
268class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
269{
270 Q_OBJECT
271
272 public:
273
279 explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
280
286 explicit QgsStyleProxyModel( QgsStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
287
297 explicit QgsStyleProxyModel( QgsCombinedStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
298
304 QString filterString() const { return mFilterString; }
305
312 QgsStyle::StyleEntity entityFilter() const;
313
321 void setEntityFilter( QgsStyle::StyleEntity filter );
322
332 void setEntityFilters( const QList<QgsStyle::StyleEntity> &filters ) SIP_SKIP;
333
340 bool entityFilterEnabled() const;
341
351 void setEntityFilterEnabled( bool enabled );
352
361 Qgis::SymbolType symbolType() const;
362
370 void setSymbolType( Qgis::SymbolType type );
371
378 bool symbolTypeFilterEnabled() const;
379
390 void setSymbolTypeFilterEnabled( bool enabled );
391
400 Qgis::GeometryType layerType() const;
401
408 void setLayerType( Qgis::GeometryType type );
409
420 void setTagId( int id );
421
431 int tagId() const;
432
442 void setTagString( const QString &tag );
443
452 QString tagString() const;
453
464 void setSmartGroupId( int id );
465
475 int smartGroupId() const;
476
477 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
478 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
479
485 bool favoritesOnly() const;
486
492 void setFavoritesOnly( bool favoritesOnly );
493
500 void addDesiredIconSize( QSize size );
501
510 void addTargetScreenProperties( const QgsScreenProperties &properties );
511
512 public slots:
513
520 void setFilterString( const QString &filter );
521
522 private:
523
524 void initialize();
525
526 QgsStyleModel *mModel = nullptr;
527 QgsCombinedStyleModel *mCombinedModel = nullptr;
528 QgsStyle *mStyle = nullptr;
529
530 QString mFilterString;
531
532 int mTagId = -1;
533 QStringList mTaggedSymbolNames;
534
535 QString mTagFilter;
536
537 int mSmartGroupId = -1;
538 QStringList mSmartGroupSymbolNames;
539
540 bool mFavoritesOnly = false;
541
542 bool mEntityFilterEnabled = false;
543 QList< QgsStyle::StyleEntity > mEntityFilters = QList< QgsStyle::StyleEntity >() << QgsStyle::SymbolEntity;
544
545 bool mSymbolTypeFilterEnabled = false;
547
549
550};
551
552#endif //QGSSTYLEMODEL_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Unknown
Unknown types.
SymbolType
Symbol types.
Definition qgis.h:574
@ Marker
Marker symbol.
An abstract base class for icon generators for a QgsStyleModel.
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.
Stores properties relating to a screen.
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
CustomRole
Custom model roles.
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:203
@ SymbolEntity
Symbols.
Definition qgsstyle.h:204
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273