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