QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsstylemodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstylemodel.cpp
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 #include "qgsstylemodel.h"
17 #include "qgsstyle.h"
18 #include "qgssymbollayerutils.h"
19 #include "qgsapplication.h"
20 #include "qgssvgcache.h"
21 #include <QIcon>
22 
23 const double ICON_PADDING_FACTOR = 0.16;
24 
25 QgsStyleModel::QgsStyleModel( QgsStyle *style, QObject *parent )
26  : QAbstractItemModel( parent )
27  , mStyle( style )
28 {
29  Q_ASSERT( mStyle );
30  mSymbolNames = mStyle->symbolNames();
31  mRampNames = mStyle->colorRampNames();
32 
33  connect( mStyle, &QgsStyle::symbolSaved, this, &QgsStyleModel::onSymbolAdded );
34  connect( mStyle, &QgsStyle::symbolRemoved, this, &QgsStyleModel::onSymbolRemoved );
35  connect( mStyle, &QgsStyle::symbolRenamed, this, &QgsStyleModel::onSymbolRename );
36  connect( mStyle, &QgsStyle::symbolChanged, this, &QgsStyleModel::onSymbolChanged );
37  connect( mStyle, &QgsStyle::rampAdded, this, &QgsStyleModel::onRampAdded );
38  connect( mStyle, &QgsStyle::rampChanged, this, &QgsStyleModel::onRampChanged );
39  connect( mStyle, &QgsStyle::rampRemoved, this, &QgsStyleModel::onRampRemoved );
40  connect( mStyle, &QgsStyle::rampRenamed, this, &QgsStyleModel::onRampRename );
41 
42  connect( mStyle, &QgsStyle::entityTagsChanged, this, &QgsStyleModel::onTagsChanged );
43 
44  // when a remote svg has been fetched, update the model's decorations.
45  // this is required if a symbol utilizes remote svgs, and the current icons
46  // have been generated using the temporary "downloading" svg. In this case
47  // we require the preview to be regenerated to use the correct fetched
48  // svg
49  connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsStyleModel::rebuildSymbolIcons );
50 }
51 
52 QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
53 {
54  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
55  return QVariant();
56 
57 
58  const bool isColorRamp = index.row() >= mStyle->symbolCount();
59  const QString name = !isColorRamp
60  ? mSymbolNames.value( index.row() )
61  : mRampNames.value( index.row() - mSymbolNames.size() );
62 
63  switch ( role )
64  {
65  case Qt::DisplayRole:
66  case Qt::ToolTipRole:
67  case Qt::EditRole:
68  {
69  switch ( index.column() )
70  {
71  case Name:
72  {
73  const QStringList tags = mStyle->tagsOfSymbol( isColorRamp ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity, name );
74 
75  if ( role == Qt::ToolTipRole )
76  {
77  QString tooltip = QStringLiteral( "<h3>%1</h3><p><i>%2</i>" ).arg( name,
78  tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) );
79 
80  // create very large preview image
81  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
82  if ( symbol )
83  {
84  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
85  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
86  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( width, height ), height / 20 );
87  QByteArray data;
88  QBuffer buffer( &data );
89  pm.save( &buffer, "PNG", 100 );
90  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
91  }
92  return tooltip;
93  }
94  else
95  {
96  return name;
97  }
98  }
99  case Tags:
100  return mStyle->tagsOfSymbol( isColorRamp ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity, name ).join( QStringLiteral( ", " ) );
101  }
102  return QVariant();
103  }
104 
105  case Qt::DecorationRole:
106  {
107  // Generate icons at all additional sizes specified for the model.
108  // This allows the model to have size responsive icons.
109  switch ( index.column() )
110  {
111  case Name:
112  if ( !isColorRamp )
113  {
114  // use cached icon if possible
115  QIcon icon = mSymbolIconCache.value( name );
116  if ( !icon.isNull() )
117  return icon;
118 
119  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
120  if ( symbol )
121  {
122  if ( mAdditionalSizes.isEmpty() )
123  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( 24, 24 ), 1 ) );
124 
125  for ( const QVariant &size : mAdditionalSizes )
126  {
127  QSize s = size.toSize();
128  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
129  }
130 
131  }
132  mSymbolIconCache.insert( name, icon );
133  return icon;
134  }
135  else
136  {
137  // use cached icon if possible
138  QIcon icon = mColorRampIconCache.value( name );
139  if ( !icon.isNull() )
140  return icon;
141 
142  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
143  if ( ramp )
144  {
145  if ( mAdditionalSizes.isEmpty() )
146  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), QSize( 24, 24 ), 1 ) );
147  for ( const QVariant &size : mAdditionalSizes )
148  {
149  QSize s = size.toSize();
150  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
151  }
152 
153  }
154  mColorRampIconCache.insert( name, icon );
155  return icon;
156  }
157  case Tags:
158  return QVariant();
159  }
160  return QVariant();
161  }
162 
163  case TypeRole:
164  return isColorRamp ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity;
165 
166  case TagRole:
167  return mStyle->tagsOfSymbol( isColorRamp ? QgsStyle::ColorrampEntity : QgsStyle::SymbolEntity, name );
168 
169  case SymbolTypeRole:
170  {
171  if ( isColorRamp )
172  return QVariant();
173 
174  const QgsSymbol *symbol = mStyle->symbolRef( name );
175  return symbol ? symbol->type() : QVariant();
176  }
177 
178  default:
179  return QVariant();
180  }
181 
182  return QVariant();
183 }
184 
185 bool QgsStyleModel::setData( const QModelIndex &index, const QVariant &value, int role )
186 {
187  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) || role != Qt::EditRole )
188  return false;
189 
190  switch ( index.column() )
191  {
192  case Name:
193  {
194  const bool isColorRamp = index.row() >= mStyle->symbolCount();
195  const QString name = !isColorRamp
196  ? mSymbolNames.value( index.row() )
197  : mRampNames.value( index.row() - mSymbolNames.size() );
198  const QString newName = value.toString();
199 
200  return isColorRamp
201  ? mStyle->renameColorRamp( name, newName )
202  : mStyle->renameSymbol( name, newName );
203  }
204 
205  case Tags:
206  return false;
207  }
208 
209  return false;
210 }
211 
212 Qt::ItemFlags QgsStyleModel::flags( const QModelIndex &index ) const
213 {
214  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
215  if ( index.isValid() && index.column() == Name )
216  {
217  return flags | Qt::ItemIsEditable;
218  }
219  else
220  {
221  return flags;
222  }
223 }
224 
225 QVariant QgsStyleModel::headerData( int section, Qt::Orientation orientation, int role ) const
226 {
227  if ( role == Qt::DisplayRole )
228  {
229  if ( orientation == Qt::Vertical ) //row
230  {
231  return QVariant( section );
232  }
233  else
234  {
235  switch ( section )
236  {
237  case Name:
238  return QVariant( tr( "Name" ) );
239 
240  case Tags:
241  return QVariant( tr( "Tags" ) );
242 
243  default:
244  return QVariant();
245  }
246  }
247  }
248  else
249  {
250  return QVariant();
251  }
252 }
253 
254 QModelIndex QgsStyleModel::index( int row, int column, const QModelIndex &parent ) const
255 {
256  if ( !hasIndex( row, column, parent ) )
257  return QModelIndex();
258 
259  if ( !parent.isValid() )
260  {
261  return createIndex( row, column );
262  }
263 
264  return QModelIndex();
265 }
266 
267 QModelIndex QgsStyleModel::parent( const QModelIndex & ) const
268 {
269  //all items are top level for now
270  return QModelIndex();
271 }
272 
273 int QgsStyleModel::rowCount( const QModelIndex &parent ) const
274 {
275  if ( !parent.isValid() )
276  {
277  return mSymbolNames.count() + mRampNames.count();
278  }
279  return 0;
280 }
281 
282 int QgsStyleModel::columnCount( const QModelIndex & ) const
283 {
284  return 2;
285 }
286 
288 {
289  mAdditionalSizes << size;
290  mSymbolIconCache.clear();
291  mColorRampIconCache.clear();
292 }
293 
294 void QgsStyleModel::onSymbolAdded( const QString &name, QgsSymbol * )
295 {
296  mSymbolIconCache.remove( name );
297  const QStringList oldSymbolNames = mSymbolNames;
298  const QStringList newSymbolNames = mStyle->symbolNames();
299 
300  // find index of newly added symbol
301  const int newNameIndex = newSymbolNames.indexOf( name );
302  if ( newNameIndex < 0 )
303  return; // shouldn't happen
304 
305  beginInsertRows( QModelIndex(), newNameIndex, newNameIndex );
306  mSymbolNames = newSymbolNames;
307  endInsertRows();
308 }
309 
310 void QgsStyleModel::onSymbolRemoved( const QString &name )
311 {
312  mSymbolIconCache.remove( name );
313  const QStringList oldSymbolNames = mSymbolNames;
314  const QStringList newSymbolNames = mStyle->symbolNames();
315 
316  // find index of removed symbol
317  const int oldNameIndex = oldSymbolNames.indexOf( name );
318  if ( oldNameIndex < 0 )
319  return; // shouldn't happen
320 
321  beginRemoveRows( QModelIndex(), oldNameIndex, oldNameIndex );
322  mSymbolNames = newSymbolNames;
323  endRemoveRows();
324 }
325 
326 void QgsStyleModel::onSymbolChanged( const QString &name )
327 {
328  mSymbolIconCache.remove( name );
329 
330  QModelIndex i = index( mSymbolNames.indexOf( name ), Tags );
331  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
332 }
333 
334 void QgsStyleModel::onSymbolRename( const QString &oldName, const QString &newName )
335 {
336  mSymbolIconCache.remove( oldName );
337  const QStringList oldSymbolNames = mSymbolNames;
338  const QStringList newSymbolNames = mStyle->symbolNames();
339 
340  // find index of removed symbol
341  const int oldNameIndex = oldSymbolNames.indexOf( oldName );
342  if ( oldNameIndex < 0 )
343  return; // shouldn't happen
344 
345  // find index of added symbol
346  const int newNameIndex = newSymbolNames.indexOf( newName );
347  if ( newNameIndex < 0 )
348  return; // shouldn't happen
349 
350  if ( newNameIndex == oldNameIndex )
351  {
352  mSymbolNames = newSymbolNames;
353  return;
354  }
355 
356  beginMoveRows( QModelIndex(), oldNameIndex, oldNameIndex, QModelIndex(), newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex );
357  mSymbolNames = newSymbolNames;
358  endMoveRows();
359 }
360 
361 void QgsStyleModel::onRampAdded( const QString &name )
362 {
363  mColorRampIconCache.remove( name );
364  const QStringList oldRampNames = mRampNames;
365  const QStringList newRampNames = mStyle->colorRampNames();
366 
367  // find index of newly added symbol
368  const int newNameIndex = newRampNames.indexOf( name );
369  if ( newNameIndex < 0 )
370  return; // shouldn't happen
371 
372  beginInsertRows( QModelIndex(), newNameIndex + mSymbolNames.count(), newNameIndex + mSymbolNames.count() );
373  mRampNames = newRampNames;
374  endInsertRows();
375 }
376 
377 void QgsStyleModel::onRampRemoved( const QString &name )
378 {
379  mColorRampIconCache.remove( name );
380  const QStringList oldRampNames = mRampNames;
381  const QStringList newRampNames = mStyle->colorRampNames();
382 
383  // find index of removed symbol
384  const int oldNameIndex = oldRampNames.indexOf( name );
385  if ( oldNameIndex < 0 )
386  return; // shouldn't happen
387 
388  beginRemoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count(), oldNameIndex + mSymbolNames.count() );
389  mRampNames = newRampNames;
390  endRemoveRows();
391 }
392 
393 void QgsStyleModel::onRampChanged( const QString &name )
394 {
395  mColorRampIconCache.remove( name );
396 
397  QModelIndex i = index( mSymbolNames.count() + mRampNames.indexOf( name ), Tags );
398  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
399 }
400 
401 void QgsStyleModel::onRampRename( const QString &oldName, const QString &newName )
402 {
403  mColorRampIconCache.remove( oldName );
404  const QStringList oldRampNames = mRampNames;
405  const QStringList newRampNames = mStyle->colorRampNames();
406 
407  // find index of removed ramp
408  const int oldNameIndex = oldRampNames.indexOf( oldName );
409  if ( oldNameIndex < 0 )
410  return; // shouldn't happen
411 
412  // find index of newly added ramp
413  const int newNameIndex = newRampNames.indexOf( newName );
414  if ( newNameIndex < 0 )
415  return; // shouldn't happen
416 
417  if ( newNameIndex == oldNameIndex )
418  {
419  mRampNames = newRampNames;
420  return;
421  }
422 
423  beginMoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count(), oldNameIndex + mSymbolNames.count(),
424  QModelIndex(), ( newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex ) + mSymbolNames.count() );
425  mRampNames = newRampNames;
426  endMoveRows();
427 }
428 
429 void QgsStyleModel::onTagsChanged( int entity, const QString &name, const QStringList & )
430 {
431  QModelIndex i;
432  if ( entity == QgsStyle::SymbolEntity )
433  {
434  i = index( mSymbolNames.indexOf( name ), Tags );
435  }
436  else if ( entity == QgsStyle::ColorrampEntity )
437  {
438  i = index( mSymbolNames.count() + mRampNames.indexOf( name ), Tags );
439  }
440  emit dataChanged( i, i );
441 }
442 
443 void QgsStyleModel::rebuildSymbolIcons()
444 {
445  mSymbolIconCache.clear();
446  emit dataChanged( index( 0, 0 ), index( mSymbolNames.count() - 1, 0 ), QVector<int>() << Qt::DecorationRole );
447 }
448 
449 //
450 // QgsStyleProxyModel
451 //
452 
454  : QSortFilterProxyModel( parent )
455  , mStyle( style )
456 {
457  mModel = new QgsStyleModel( mStyle, this );
458  setSortCaseSensitivity( Qt::CaseInsensitive );
459 // setSortLocaleAware( true );
460  setSourceModel( mModel );
461  setDynamicSortFilter( true );
462  sort( 0 );
463 
464  connect( mStyle, &QgsStyle::entityTagsChanged, this, [ = ]
465  {
466  // update tagged symbols if filtering by tag
467  if ( mTagId >= 0 )
468  setTagId( mTagId );
469  if ( mSmartGroupId >= 0 )
470  setSmartGroupId( mSmartGroupId );
471  } );
472 
473  connect( mStyle, &QgsStyle::favoritedChanged, this, [ = ]
474  {
475  // update favorited symbols if filtering by favorite
476  if ( mFavoritesOnly )
477  setFavoritesOnly( mFavoritesOnly );
478  } );
479 
480  connect( mStyle, &QgsStyle::rampRenamed, this, [ = ]
481  {
482  if ( mSmartGroupId >= 0 )
483  setSmartGroupId( mSmartGroupId );
484  } );
485  connect( mStyle, &QgsStyle::symbolRenamed, this, [ = ]
486  {
487  if ( mSmartGroupId >= 0 )
488  setSmartGroupId( mSmartGroupId );
489  } );
490 }
491 
492 bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
493 {
494  if ( mFilterString.isEmpty() && !mEntityFilterEnabled && !mSymbolTypeFilterEnabled && mTagId < 0 && mSmartGroupId < 0 && !mFavoritesOnly )
495  return true;
496 
497  QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
498  const QString name = sourceModel()->data( index ).toString();
499  const QStringList tags = sourceModel()->data( index, QgsStyleModel::TagRole ).toStringList();
500 
501  QgsStyle::StyleEntity styleEntityType = static_cast< QgsStyle::StyleEntity >( sourceModel()->data( index, QgsStyleModel::TypeRole ).toInt() );
502  if ( mEntityFilterEnabled && styleEntityType != mEntityFilter )
503  return false;
504 
505  QgsSymbol::SymbolType symbolType = static_cast< QgsSymbol::SymbolType >( sourceModel()->data( index, QgsStyleModel::SymbolTypeRole ).toInt() );
506  if ( mSymbolTypeFilterEnabled && symbolType != mSymbolType )
507  return false;
508 
509  if ( mTagId >= 0 && !mTaggedSymbolNames.contains( name ) )
510  return false;
511 
512  if ( mSmartGroupId >= 0 && !mSmartGroupSymbolNames.contains( name ) )
513  return false;
514 
515  if ( mFavoritesOnly && !mFavoritedSymbolNames.contains( name ) )
516  return false;
517 
518  if ( !mFilterString.isEmpty() )
519  {
520  // filter by word, in both filter string and style entity name/tags
521  // this allows matching of a filter string "hash line" to the symbol "hashed red lines"
522  const QStringList partsToMatch = mFilterString.trimmed().split( ' ' );
523 
524  QStringList partsToSearch = name.split( ' ' );
525  for ( const QString &tag : tags )
526  {
527  partsToSearch.append( tag.split( ' ' ) );
528  }
529 
530  for ( const QString &part : partsToMatch )
531  {
532  bool found = false;
533  for ( const QString &partToSearch : qgis::as_const( partsToSearch ) )
534  {
535  if ( partToSearch.contains( part, Qt::CaseInsensitive ) )
536  {
537  found = true;
538  break;
539  }
540  }
541  if ( !found )
542  return false; // couldn't find a match for this word, so hide entity
543  }
544  }
545 
546  return true;
547 }
548 
549 void QgsStyleProxyModel::setFilterString( const QString &filter )
550 {
551  mFilterString = filter;
552  invalidateFilter();
553 }
554 
556 {
557  return mFavoritesOnly;
558 }
559 
561 {
562  mFavoritesOnly = favoritesOnly;
563 
564  if ( mFavoritesOnly )
565  {
566  mFavoritedSymbolNames = mStyle->symbolsOfFavorite( QgsStyle::SymbolEntity );
567  mFavoritedSymbolNames.append( mStyle->symbolsOfFavorite( QgsStyle::ColorrampEntity ) );
568  }
569  else
570  {
571  mFavoritedSymbolNames.clear();
572  }
573  invalidateFilter();
574 }
575 
577 {
578  mModel->addDesiredIconSize( size );
579 }
580 
582 {
583  return mSymbolTypeFilterEnabled;
584 }
585 
587 {
588  mSymbolTypeFilterEnabled = symbolTypeFilterEnabled;
589  invalidateFilter();
590 }
591 
593 {
594  mTagId = id;
595 
596  if ( mTagId >= 0 )
597  {
598  mTaggedSymbolNames = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, mTagId );
599  mTaggedSymbolNames.append( mStyle->symbolsWithTag( QgsStyle::ColorrampEntity, mTagId ) );
600  }
601  else
602  {
603  mTaggedSymbolNames.clear();
604  }
605 
606  invalidateFilter();
607 }
608 
610 {
611  return mTagId;
612 }
613 
615 {
616  mSmartGroupId = id;
617 
618  if ( mSmartGroupId >= 0 )
619  {
620  mSmartGroupSymbolNames = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, mSmartGroupId );
621  mSmartGroupSymbolNames.append( mStyle->symbolsOfSmartgroup( QgsStyle::ColorrampEntity, mSmartGroupId ) );
622  }
623  else
624  {
625  mSmartGroupSymbolNames.clear();
626  }
627 
628  invalidateFilter();
629 }
630 
632 {
633  return mSmartGroupId;
634 }
635 
637 {
638  return mSymbolType;
639 }
640 
642 {
643  mSymbolType = symbolType;
644  invalidateFilter();
645 }
646 
648 {
649  return mEntityFilterEnabled;
650 }
651 
653 {
654  mEntityFilterEnabled = entityFilterEnabled;
655  invalidateFilter();
656 }
657 
659 {
660  return mEntityFilter;
661 }
662 
664 {
665  mEntityFilter = entityFilter;
666  invalidateFilter();
667 }
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:41
static QgsSvgCache * svgCache()
Returns the application&#39;s SVG cache, used for caching SVG images and handling parameter replacement w...
static QPixmap symbolPreviewPixmap(QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr)
Returns a pixmap preview for a color ramp.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
void symbolSaved(const QString &name, QgsSymbol *symbol)
Emitted every time a new symbol has been added to the database.
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
QgsSymbol::SymbolType symbolType() const
Returns the symbol type filter.
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:152
void entityTagsChanged(QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags)
Emitted whenever an entity&#39;s tags are changed.
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition: qgsstyle.cpp:272
QgsStyleModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleModel, for the specified style and parent object.
void setTagId(int id)
Sets a tag id to filter style entities by.
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
Definition: qgsstyle.cpp:1041
int columnCount(const QModelIndex &parent=QModelIndex()) const override
const QgsSymbol * symbolRef(const QString &name) const
Returns a const pointer to a symbol (doesn&#39;t create new instance)
Definition: qgsstyle.cpp:181
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
void rampChanged(const QString &name)
Emitted whenever a color ramp&#39;s definition is changed.
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:578
void setFavoritesOnly(bool favoritesOnly)
Sets whether the model should show only favorited entities.
void rampAdded(const QString &name)
Emitted whenever a color ramp has been added to the style and the database has been updated as a resu...
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
String list of tags.
Definition: qgsstylemodel.h:58
QModelIndex parent(const QModelIndex &index) const override
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:95
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
SymbolType
Type of the symbol.
Definition: qgssymbol.h:83
int symbolCount()
Returns count of symbols in style.
Definition: qgsstyle.cpp:186
QgsStyle::StyleEntity entityFilter() const
Returns the style entity type filter.
void setEntityFilterEnabled(bool enabled)
Sets whether filtering by entity type is enabled.
bool renameSymbol(const QString &oldName, const QString &newName)
Renames a symbol from oldName to newName.
Definition: qgsstyle.cpp:475
const double ICON_PADDING_FACTOR
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
void rampRemoved(const QString &name)
Emitted whenever a color ramp has been removed from the style and the database has been updated as a ...
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QStringList symbolNames()
Returns a list of names of symbols.
Definition: qgsstyle.cpp:191
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool symbolTypeFilterEnabled() const
Returns true if filtering by symbol type is enabled.
QStringList symbolsOfFavorite(StyleEntity type) const
Returns the symbol names which are flagged as favorite.
Definition: qgsstyle.cpp:542
void symbolRenamed(const QString &oldName, const QString &newName)
Emitted whenever a symbol has been renamed from oldName to newName.
Tags column.
Definition: qgsstylemodel.h:51
void favoritedChanged(QgsStyle::StyleEntity entity, const QString &name, bool isFavorite)
Emitted whenever an entity is either favorited or un-favorited.
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
QStringList colorRampNames()
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:288
void symbolRemoved(const QString &name)
Emitted whenever a symbol has been removed from the style and the database has been updated as a resu...
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
Definition: qgsstyle.cpp:1327
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
void rampRenamed(const QString &oldName, const QString &newName)
Emitted whenever a color ramp has been renamed from oldName to newName.
QgsStyleProxyModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleProxyModel, for the specified style and parent object.
Name column.
Definition: qgsstylemodel.h:50
void symbolChanged(const QString &name)
Emitted whenever a symbol&#39;s definition is changed.
int tagId() const
Returns the tag id used to filter style entities by.
bool favoritesOnly() const
Returns true if the model is showing only favorited entities.
bool entityFilterEnabled() const
Returns true if filtering by entity type is enabled.
SymbolType type() const
Returns the symbol&#39;s type.
Definition: qgssymbol.h:120
bool renameColorRamp(const QString &oldName, const QString &newName)
Changes ramp&#39;s name.
Definition: qgsstyle.cpp:511
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:175
QVariant data(const QModelIndex &index, int role) const override
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
Style entity type, see QgsStyle::StyleEntity.
Definition: qgsstylemodel.h:57
int smartGroupId() const
Returns the smart group id used to filter style entities by.
Qt::ItemFlags flags(const QModelIndex &index) const override
Symbol type (for symbol entities)
Definition: qgsstylemodel.h:59