QGIS API Documentation 4.1.0-Master (60fea48833c)
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:
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 QList< QSize > mIconSizes;
108 QSet< QgsScreenProperties > mTargetScreenProperties;
109};
110
111#endif
112
128class CORE_EXPORT QgsStyleModel : public QAbstractItemModel
129{
130 Q_OBJECT
131
132 public:
135 {
136 Name = 0,
138 };
139
140 // *INDENT-OFF*
141
149 {
150 Type SIP_MONKEYPATCH_COMPAT_NAME( TypeRole ) = Qt::UserRole + 1,
152 EntityName,
153 SymbolType SIP_MONKEYPATCH_COMPAT_NAME( SymbolTypeRole ),
154 IsFavorite SIP_MONKEYPATCH_COMPAT_NAME( IsFavoriteRole ),
155 LayerType SIP_MONKEYPATCH_COMPAT_NAME( LayerTypeRole ),
156 CompatibleGeometryTypes SIP_MONKEYPATCH_COMPAT_NAME( CompatibleGeometryTypesRole ),
157 StyleName,
158 StyleFileName,
159 IsTitle SIP_MONKEYPATCH_COMPAT_NAME( IsTitleRole ),
160 };
161 Q_ENUM( CustomRole )
162 // *INDENT-ON*
163
164
169 explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
170
176 QgsStyle *style() { return mStyle; }
177
178 QVariant data( const QModelIndex &index, int role ) const override;
179 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
180 Qt::ItemFlags flags( const QModelIndex &index ) const override;
181 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
182 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
183 QModelIndex parent( const QModelIndex &index ) const override;
184 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
185 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
186
193 void addDesiredIconSize( QSize size );
194
203 void addTargetScreenProperties( const QgsScreenProperties &properties );
204
213 static void setIconGenerator( QgsAbstractStyleEntityIconGenerator *generator ) SIP_SKIP;
214
215 private slots:
216
217 void onEntityAdded( QgsStyle::StyleEntity type, const QString &name );
218 void onEntityRemoved( QgsStyle::StyleEntity type, const QString &name );
219 void onEntityChanged( QgsStyle::StyleEntity type, const QString &name );
220 void onFavoriteChanged( QgsStyle::StyleEntity type, const QString &name, bool isFavorite );
221 void onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName );
222 void onTagsChanged( int entity, const QString &name, const QStringList &tags );
223 void rebuildSymbolIcons();
224 void iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon );
225
226 private:
227 void initStyleModel();
228
229 QgsStyle *mStyle = nullptr;
230
231 QHash< QgsStyle::StyleEntity, QStringList > mEntityNames;
232
233 QSet< QgsScreenProperties > mTargetScreenProperties;
234
235 QList< QSize > mAdditionalSizes;
236 mutable std::unique_ptr< QgsExpressionContext > mExpressionContext;
237
238 mutable QHash< QgsStyle::StyleEntity, QHash< QString, QIcon > > mIconCache;
239
240 static QgsAbstractStyleEntityIconGenerator *sIconGenerator;
241 mutable QSet< QString > mPending3dSymbolIcons;
242
243 QgsStyle::StyleEntity entityTypeFromRow( int row ) const;
244
245 int offsetForEntity( QgsStyle::StyleEntity entity ) const;
246 static QVariant headerDataStatic( int section, Qt::Orientation orientation, int role = Qt::DisplayRole );
247
249};
250
261class CORE_EXPORT QgsStyleProxyModel : public QSortFilterProxyModel
262{
263 Q_OBJECT
264
265 public:
271 explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
272
278 explicit QgsStyleProxyModel( QgsStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
279
289 explicit QgsStyleProxyModel( QgsCombinedStyleModel *model, QObject *parent SIP_TRANSFERTHIS = nullptr );
290
296 QString filterString() const { return mFilterString; }
297
304 QgsStyle::StyleEntity entityFilter() const;
305
313 void setEntityFilter( QgsStyle::StyleEntity filter );
314
324 void setEntityFilters( const QList<QgsStyle::StyleEntity> &filters ) SIP_SKIP;
325
332 bool entityFilterEnabled() const;
333
343 void setEntityFilterEnabled( bool enabled );
344
353 Qgis::SymbolType symbolType() const;
354
362 void setSymbolType( Qgis::SymbolType type );
363
370 bool symbolTypeFilterEnabled() const;
371
382 void setSymbolTypeFilterEnabled( bool enabled );
383
392 Qgis::GeometryType layerType() const;
393
400 void setLayerType( Qgis::GeometryType type );
401
412 void setTagId( int id );
413
423 int tagId() const;
424
434 void setTagString( const QString &tag );
435
444 QString tagString() const;
445
456 void setSmartGroupId( int id );
457
467 int smartGroupId() const;
468
469 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
470 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
471
477 bool favoritesOnly() const;
478
484 void setFavoritesOnly( bool favoritesOnly );
485
492 void addDesiredIconSize( QSize size );
493
502 void addTargetScreenProperties( const QgsScreenProperties &properties );
503
504 public slots:
505
512 void setFilterString( const QString &filter );
513
514 private:
515 void initialize();
516
517 QgsStyleModel *mModel = nullptr;
518 QgsCombinedStyleModel *mCombinedModel = nullptr;
519 QgsStyle *mStyle = nullptr;
520
521 QString mFilterString;
522
523 int mTagId = -1;
524 QStringList mTaggedSymbolNames;
525
526 QString mTagFilter;
527
528 int mSmartGroupId = -1;
529 QStringList mSmartGroupSymbolNames;
530
531 bool mFavoritesOnly = false;
532
533 bool mEntityFilterEnabled = false;
534 QList< QgsStyle::StyleEntity > mEntityFilters = QList< QgsStyle::StyleEntity >() << QgsStyle::SymbolEntity;
535
536 bool mSymbolTypeFilterEnabled = false;
538
540};
541
542#endif //QGSSTYLEMODEL_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Unknown
Unknown types.
Definition qgis.h:383
SymbolType
Symbol types.
Definition qgis.h:636
@ Marker
Marker symbol.
Definition qgis.h:637
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:89
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:227
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269