QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
157
163 explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
164
170 QgsStyle *style() { return mStyle; }
171
172 QVariant data( const QModelIndex &index, int role ) const override;
173 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
174 Qt::ItemFlags flags( const QModelIndex &index ) const override;
175 QVariant headerData( int section, Qt::Orientation orientation,
176 int role = Qt::DisplayRole ) const override;
177 QModelIndex index( int row, int column,
178 const QModelIndex &parent = QModelIndex() ) const override;
179 QModelIndex parent( const QModelIndex &index ) const override;
180 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
181 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
182
189 void addDesiredIconSize( QSize size );
190
199 void addTargetScreenProperties( const QgsScreenProperties &properties );
200
209 static void setIconGenerator( QgsAbstractStyleEntityIconGenerator *generator ) SIP_SKIP;
210
211 private slots:
212
213 void onEntityAdded( QgsStyle::StyleEntity type, const QString &name );
214 void onEntityRemoved( QgsStyle::StyleEntity type, const QString &name );
215 void onEntityChanged( QgsStyle::StyleEntity type, const QString &name );
216 void onFavoriteChanged( QgsStyle::StyleEntity type, const QString &name, bool isFavorite );
217 void onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName );
218 void onTagsChanged( int entity, const QString &name, const QStringList &tags );
219 void rebuildSymbolIcons();
220 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
221
222 private:
223
224 QgsStyle *mStyle = nullptr;
225
226 QHash< QgsStyle::StyleEntity, QStringList > mEntityNames;
227
228 QSet< QgsScreenProperties > mTargetScreenProperties;
229
230 QList< QSize > mAdditionalSizes;
231 mutable std::unique_ptr< QgsExpressionContext > mExpressionContext;
232
233 mutable QHash< QgsStyle::StyleEntity, QHash< QString, QIcon > > mIconCache;
234
235 static QgsAbstractStyleEntityIconGenerator *sIconGenerator;
236 mutable QSet< QString > mPending3dSymbolIcons;
237
238 QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
239
240 int offsetForEntity( QgsStyle::StyleEntity entity ) const;
241 static QVariant headerDataStatic( int section, Qt::Orientation orientation,
242 int role = Qt::DisplayRole );
243
245};
246
257class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
258{
259 Q_OBJECT
260
261 public:
262
268 explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
269
275 explicit QgsStyleProxyModel( QgsStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
276
286 explicit QgsStyleProxyModel( QgsCombinedStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
287
293 QString filterString() const { return mFilterString; }
294
301 QgsStyle::StyleEntity entityFilter() const;
302
310 void setEntityFilter( QgsStyle::StyleEntity filter );
311
321 void setEntityFilters( const QList<QgsStyle::StyleEntity> &filters ) SIP_SKIP;
322
329 bool entityFilterEnabled() const;
330
340 void setEntityFilterEnabled( bool enabled );
341
350 Qgis::SymbolType symbolType() const;
351
359 void setSymbolType( Qgis::SymbolType type );
360
367 bool symbolTypeFilterEnabled() const;
368
379 void setSymbolTypeFilterEnabled( bool enabled );
380
389 Qgis::GeometryType layerType() const;
390
397 void setLayerType( Qgis::GeometryType type );
398
409 void setTagId( int id );
410
420 int tagId() const;
421
431 void setTagString( const QString &tag );
432
441 QString tagString() const;
442
453 void setSmartGroupId( int id );
454
464 int smartGroupId() const;
465
466 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
467 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
468
474 bool favoritesOnly() const;
475
481 void setFavoritesOnly( bool favoritesOnly );
482
489 void addDesiredIconSize( QSize size );
490
499 void addTargetScreenProperties( const QgsScreenProperties &properties );
500
501 public slots:
502
509 void setFilterString( const QString &filter );
510
511 private:
512
513 void initialize();
514
515 QgsStyleModel *mModel = nullptr;
516 QgsCombinedStyleModel *mCombinedModel = nullptr;
517 QgsStyle *mStyle = nullptr;
518
519 QString mFilterString;
520
521 int mTagId = -1;
522 QStringList mTaggedSymbolNames;
523
524 QString mTagFilter;
525
526 int mSmartGroupId = -1;
527 QStringList mSmartGroupSymbolNames;
528
529 bool mFavoritesOnly = false;
530
531 bool mEntityFilterEnabled = false;
532 QList< QgsStyle::StyleEntity > mEntityFilters = QList< QgsStyle::StyleEntity >() << QgsStyle::SymbolEntity;
533
534 bool mSymbolTypeFilterEnabled = false;
536
538
539};
540
541#endif //QGSSTYLEMODEL_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Unknown
Unknown types.
SymbolType
Attribute editing capabilities which may be supported by vector data providers.
Definition qgis.h:368
@ 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 ...
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:94
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126