QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
23#include <QAbstractItemModel>
24#include <QHash>
25#include <QIcon>
26#include <QSortFilterProxyModel>
27
28class QgsSymbol;
30
31#ifndef SIP_RUN
32
45class CORE_EXPORT QgsAbstractStyleEntityIconGenerator : public QObject
46{
47 Q_OBJECT
48
49 public:
50
55 QgsAbstractStyleEntityIconGenerator( QObject *parent );
56
61 virtual void generateIcon( QgsStyle *style, QgsStyle::StyleEntity type, const QString &name ) = 0;
62
68 void setIconSizes( const QList< QSize > &sizes );
69
75 QList< QSize > iconSizes() const;
76
86 void setTargetScreenProperties( const QSet< QgsScreenProperties > &properties );
87
97 QSet< QgsScreenProperties > targetScreenProperties() const;
98
99 signals:
100
105 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
106
107 private:
108
109 QList< QSize > mIconSizes;
110 QSet< QgsScreenProperties > mTargetScreenProperties;
111
112};
113
114#endif
115
131class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
132{
133 Q_OBJECT
134
135 public:
136
139 {
140 Name = 0,
142 };
143
144 // *INDENT-OFF*
145
153 {
154 Type SIP_MONKEYPATCH_COMPAT_NAME(TypeRole) = Qt::UserRole + 1,
156 EntityName,
157 SymbolType SIP_MONKEYPATCH_COMPAT_NAME(SymbolTypeRole),
158 IsFavorite SIP_MONKEYPATCH_COMPAT_NAME(IsFavoriteRole),
159 LayerType SIP_MONKEYPATCH_COMPAT_NAME(LayerTypeRole),
160 CompatibleGeometryTypes SIP_MONKEYPATCH_COMPAT_NAME(CompatibleGeometryTypesRole),
161 StyleName,
162 StyleFileName,
163 IsTitle SIP_MONKEYPATCH_COMPAT_NAME(IsTitleRole),
164 };
165 Q_ENUM( CustomRole )
166 // *INDENT-ON*
167
168
173 explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
174
180 QgsStyle *style() { return mStyle; }
181
182 QVariant data( const QModelIndex &index, int role ) const override;
183 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
184 Qt::ItemFlags flags( const QModelIndex &index ) const override;
185 QVariant headerData( int section, Qt::Orientation orientation,
186 int role = Qt::DisplayRole ) const override;
187 QModelIndex index( int row, int column,
188 const QModelIndex &parent = QModelIndex() ) const override;
189 QModelIndex parent( const QModelIndex &index ) const override;
190 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
191 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
192
199 void addDesiredIconSize( QSize size );
200
209 void addTargetScreenProperties( const QgsScreenProperties &properties );
210
219 static void setIconGenerator( QgsAbstractStyleEntityIconGenerator *generator ) SIP_SKIP;
220
221 private slots:
222
223 void onEntityAdded( QgsStyle::StyleEntity type, const QString &name );
224 void onEntityRemoved( QgsStyle::StyleEntity type, const QString &name );
225 void onEntityChanged( QgsStyle::StyleEntity type, const QString &name );
226 void onFavoriteChanged( QgsStyle::StyleEntity type, const QString &name, bool isFavorite );
227 void onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName );
228 void onTagsChanged( int entity, const QString &name, const QStringList &tags );
229 void rebuildSymbolIcons();
230 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
231
232 private:
233
234 void initStyleModel();
235
236 QgsStyle *mStyle = nullptr;
237
238 QHash< QgsStyle::StyleEntity, QStringList > mEntityNames;
239
240 QSet< QgsScreenProperties > mTargetScreenProperties;
241
242 QList< QSize > mAdditionalSizes;
243 mutable std::unique_ptr< QgsExpressionContext > mExpressionContext;
244
245 mutable QHash< QgsStyle::StyleEntity, QHash< QString, QIcon > > mIconCache;
246
247 static QgsAbstractStyleEntityIconGenerator *sIconGenerator;
248 mutable QSet< QString > mPending3dSymbolIcons;
249
250 QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
251
252 int offsetForEntity( QgsStyle::StyleEntity entity ) const;
253 static QVariant headerDataStatic( int section, Qt::Orientation orientation,
254 int role = Qt::DisplayRole );
255
257};
258
269class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
270{
271 Q_OBJECT
272
273 public:
274
280 explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
281
287 explicit QgsStyleProxyModel( QgsStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
288
298 explicit QgsStyleProxyModel( QgsCombinedStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
299
305 QString filterString() const { return mFilterString; }
306
313 QgsStyle::StyleEntity entityFilter() const;
314
322 void setEntityFilter( QgsStyle::StyleEntity filter );
323
333 void setEntityFilters( const QList<QgsStyle::StyleEntity> &filters ) SIP_SKIP;
334
341 bool entityFilterEnabled() const;
342
352 void setEntityFilterEnabled( bool enabled );
353
362 Qgis::SymbolType symbolType() const;
363
371 void setSymbolType( Qgis::SymbolType type );
372
379 bool symbolTypeFilterEnabled() const;
380
391 void setSymbolTypeFilterEnabled( bool enabled );
392
401 Qgis::GeometryType layerType() const;
402
409 void setLayerType( Qgis::GeometryType type );
410
421 void setTagId( int id );
422
432 int tagId() const;
433
443 void setTagString( const QString &tag );
444
453 QString tagString() const;
454
465 void setSmartGroupId( int id );
466
476 int smartGroupId() const;
477
478 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
479 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
480
486 bool favoritesOnly() const;
487
493 void setFavoritesOnly( bool favoritesOnly );
494
501 void addDesiredIconSize( QSize size );
502
511 void addTargetScreenProperties( const QgsScreenProperties &properties );
512
513 public slots:
514
521 void setFilterString( const QString &filter );
522
523 private:
524
525 void initialize();
526
527 QgsStyleModel *mModel = nullptr;
528 QgsCombinedStyleModel *mCombinedModel = nullptr;
529 QgsStyle *mStyle = nullptr;
530
531 QString mFilterString;
532
533 int mTagId = -1;
534 QStringList mTaggedSymbolNames;
535
536 QString mTagFilter;
537
538 int mSmartGroupId = -1;
539 QStringList mSmartGroupSymbolNames;
540
541 bool mFavoritesOnly = false;
542
543 bool mEntityFilterEnabled = false;
544 QList< QgsStyle::StyleEntity > mEntityFilters = QList< QgsStyle::StyleEntity >() << QgsStyle::SymbolEntity;
545
546 bool mSymbolTypeFilterEnabled = false;
548
550
551};
552
553#endif //QGSSTYLEMODEL_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Unknown
Unknown types.
Definition qgis.h:362
SymbolType
Symbol types.
Definition qgis.h:610
@ Marker
Marker symbol.
Definition qgis.h:611
An abstract base class for icon generators for a QgsStyleModel.
void setTargetScreenProperties(const QSet< QgsScreenProperties > &properties)
Sets the target screen properties to use when generating icons.
void setIconSizes(const QList< QSize > &sizes)
Sets the list of icon sizes to generate.
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 ...
QgsAbstractStyleEntityIconGenerator(QObject *parent)
Constructor for QgsAbstractStyleEntityIconGenerator, with the specified parent object.
QSet< QgsScreenProperties > targetScreenProperties() const
Returns the target screen properties to use when generating icons.
QList< QSize > iconSizes() const
Returns the list of icon sizes to generate.
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.
friend class QgsCombinedStyleModel
QgsStyleModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleModel, for the specified style and parent object.
QgsStyle * style()
Returns the style managed by the model.
Column
Model columns.
@ Name
Name column.
@ Tags
Tags column.
QString filterString() const
Returns the current filter string, if set.
QgsStyleProxyModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleProxyModel, for the specified style and parent object.
A database of saved style entities, including symbols, color ramps, text formats and others.
Definition qgsstyle.h:88
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:204
@ SymbolEntity
Symbols.
Definition qgsstyle.h:205
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:134
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270