QGIS API Documentation  3.6.0-Noosa (5873452)
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 "qgssymbol.h"
23 #include <QAbstractItemModel>
24 #include <QSortFilterProxyModel>
25 #include <QIcon>
26 #include <QHash>
27 
28 class QgsSymbol;
29 
41 class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
42 {
43  Q_OBJECT
44 
45  public:
46 
48  enum Column
49  {
50  Name = 0,
51  Tags,
52  };
53 
55  enum Role
56  {
57  TypeRole = Qt::UserRole + 1,
60  };
61 
67  explicit QgsStyleModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
68 
69  QVariant data( const QModelIndex &index, int role ) const override;
70  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
71  Qt::ItemFlags flags( const QModelIndex &index ) const override;
72  QVariant headerData( int section, Qt::Orientation orientation,
73  int role = Qt::DisplayRole ) const override;
74  QModelIndex index( int row, int column,
75  const QModelIndex &parent = QModelIndex() ) const override;
76  QModelIndex parent( const QModelIndex &index ) const override;
77  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
78  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
79 
86  void addDesiredIconSize( QSize size );
87 
88  private slots:
89 
90  void onSymbolAdded( const QString &name, QgsSymbol *symbol );
91  void onSymbolRemoved( const QString &name );
92  void onSymbolChanged( const QString &name );
93  void onSymbolRename( const QString &oldName, const QString &newName );
94  void onRampAdded( const QString &name );
95  void onRampRemoved( const QString &name );
96  void onRampChanged( const QString &name );
97  void onRampRename( const QString &oldName, const QString &newName );
98  void onTagsChanged( int entity, const QString &name, const QStringList &tags );
99  void rebuildSymbolIcons();
100 
101  private:
102 
103  QgsStyle *mStyle = nullptr;
104  QStringList mSymbolNames;
105  QStringList mRampNames;
106  QList< QSize > mAdditionalSizes;
107 
108  mutable QHash< QString, QIcon > mSymbolIconCache;
109  mutable QHash< QString, QIcon > mColorRampIconCache;
110 
111 };
112 
123 class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
124 {
125  Q_OBJECT
126 
127  public:
128 
134  explicit QgsStyleProxyModel( QgsStyle *style, QObject *parent SIP_TRANSFERTHIS = nullptr );
135 
141  QString filterString() const { return mFilterString; }
142 
149  QgsStyle::StyleEntity entityFilter() const;
150 
158  void setEntityFilter( QgsStyle::StyleEntity filter );
159 
166  bool entityFilterEnabled() const;
167 
177  void setEntityFilterEnabled( bool enabled );
178 
187  QgsSymbol::SymbolType symbolType() const;
188 
196  void setSymbolType( QgsSymbol::SymbolType type );
197 
204  bool symbolTypeFilterEnabled() const;
205 
216  void setSymbolTypeFilterEnabled( bool enabled );
217 
226  void setTagId( int id );
227 
235  int tagId() const;
236 
245  void setSmartGroupId( int id );
246 
254  int smartGroupId() const;
255 
256  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
257 
263  bool favoritesOnly() const;
264 
270  void setFavoritesOnly( bool favoritesOnly );
271 
278  void addDesiredIconSize( QSize size );
279 
280  public slots:
281 
288  void setFilterString( const QString &filter );
289 
290  private:
291 
292  QgsStyleModel *mModel = nullptr;
293  QgsStyle *mStyle = nullptr;
294 
295  QString mFilterString;
296 
297  int mTagId = -1;
298  QStringList mTaggedSymbolNames;
299 
300  int mSmartGroupId = -1;
301  QStringList mSmartGroupSymbolNames;
302 
303  bool mFavoritesOnly = false;
304  QStringList mFavoritedSymbolNames;
305 
306  bool mEntityFilterEnabled = false;
308 
309  bool mSymbolTypeFilterEnabled = false;
311 
312 };
313 
314 #endif //QGSSTYLEMODEL_H
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:41
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
Role
Custom model roles.
Definition: qgsstylemodel.h:55
String list of tags.
Definition: qgsstylemodel.h:58
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:95
SymbolType
Type of the symbol.
Definition: qgssymbol.h:83
QString filterString() const
Returns the current filter string, if set.
Tags column.
Definition: qgsstylemodel.h:51
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
Marker symbol.
Definition: qgssymbol.h:85
Column
Model columns.
Definition: qgsstylemodel.h:48
Symbol type (for symbol entities)
Definition: qgsstylemodel.h:59