QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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"
24 #include <QIcon>
25 
26 const double ICON_PADDING_FACTOR = 0.16;
27 
28 QgsStyleModel::QgsStyleModel( QgsStyle *style, QObject *parent )
29  : QAbstractItemModel( parent )
30  , mStyle( style )
31 {
32  Q_ASSERT( mStyle );
33  mSymbolNames = mStyle->symbolNames();
34  mRampNames = mStyle->colorRampNames();
35  mTextFormatNames = mStyle->textFormatNames();
36  mLabelSettingsNames = mStyle->labelSettingsNames();
37 
38  connect( mStyle, &QgsStyle::symbolSaved, this, &QgsStyleModel::onSymbolAdded );
39  connect( mStyle, &QgsStyle::symbolRemoved, this, &QgsStyleModel::onSymbolRemoved );
40  connect( mStyle, &QgsStyle::symbolRenamed, this, &QgsStyleModel::onSymbolRename );
41  connect( mStyle, &QgsStyle::symbolChanged, this, &QgsStyleModel::onSymbolChanged );
42 
43  connect( mStyle, &QgsStyle::rampAdded, this, &QgsStyleModel::onRampAdded );
44  connect( mStyle, &QgsStyle::rampChanged, this, &QgsStyleModel::onRampChanged );
45  connect( mStyle, &QgsStyle::rampRemoved, this, &QgsStyleModel::onRampRemoved );
46  connect( mStyle, &QgsStyle::rampRenamed, this, &QgsStyleModel::onRampRename );
47 
48  connect( mStyle, &QgsStyle::textFormatAdded, this, &QgsStyleModel::onTextFormatAdded );
49  connect( mStyle, &QgsStyle::textFormatChanged, this, &QgsStyleModel::onTextFormatChanged );
50  connect( mStyle, &QgsStyle::textFormatRemoved, this, &QgsStyleModel::onTextFormatRemoved );
51  connect( mStyle, &QgsStyle::textFormatRenamed, this, &QgsStyleModel::onTextFormatRename );
52 
53  connect( mStyle, &QgsStyle::labelSettingsAdded, this, &QgsStyleModel::onLabelSettingsAdded );
54  connect( mStyle, &QgsStyle::labelSettingsChanged, this, &QgsStyleModel::onLabelSettingsChanged );
55  connect( mStyle, &QgsStyle::labelSettingsRemoved, this, &QgsStyleModel::onLabelSettingsRemoved );
56  connect( mStyle, &QgsStyle::labelSettingsRenamed, this, &QgsStyleModel::onLabelSettingsRename );
57 
58  connect( mStyle, &QgsStyle::entityTagsChanged, this, &QgsStyleModel::onTagsChanged );
59 
60  // when a remote svg or image has been fetched, update the model's decorations.
61  // this is required if a symbol utilizes remote svgs, and the current icons
62  // have been generated using the temporary "downloading" svg. In this case
63  // we require the preview to be regenerated to use the correct fetched
64  // svg
65  connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsStyleModel::rebuildSymbolIcons );
66  connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsStyleModel::rebuildSymbolIcons );
67 
68  // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
69  // need updating to reflect the new colors
70  connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsStyleModel::rebuildSymbolIcons );
71 }
72 
73 QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
74 {
75  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
76  return QVariant();
77 
78 
79  QgsStyle::StyleEntity entityType = entityTypeFromRow( index.row() );
80 
81  QString name;
82  switch ( entityType )
83  {
85  name = mSymbolNames.value( index.row() );
86  break;
87 
89  name = mRampNames.value( index.row() - mSymbolNames.size() );
90  break;
91 
93  name = mTextFormatNames.value( index.row() - mSymbolNames.size() - mRampNames.size() );
94  break;
95 
97  name = mLabelSettingsNames.value( index.row() - mSymbolNames.size() - mRampNames.size() - mTextFormatNames.size() );
98  break;
99 
100  case QgsStyle::TagEntity:
102  break;
103  }
104 
105  switch ( role )
106  {
107  case Qt::DisplayRole:
108  case Qt::ToolTipRole:
109  case Qt::EditRole:
110  {
111  switch ( index.column() )
112  {
113  case Name:
114  {
115  const QStringList tags = mStyle->tagsOfSymbol( entityType, name );
116 
117  if ( role == Qt::ToolTipRole )
118  {
119  QString tooltip = QStringLiteral( "<h3>%1</h3><p><i>%2</i>" ).arg( name,
120  tags.count() > 0 ? tags.join( QStringLiteral( ", " ) ) : tr( "Not tagged" ) );
121 
122  switch ( entityType )
123  {
125  {
126  // create very large preview image
127  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
128  if ( symbol )
129  {
130 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
131  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
132 #else
133  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
134 #endif
135  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
136  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( width, height ), height / 20, nullptr, false, mExpressionContext.get() );
137  QByteArray data;
138  QBuffer buffer( &data );
139  pm.save( &buffer, "PNG", 100 );
140  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
141  }
142  break;
143  }
144 
146  {
147 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
148  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
149 #else
150  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
151 #endif
152  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
153  const QgsTextFormat format = mStyle->textFormat( name );
154  QPixmap pm = QgsTextFormat::textFormatPreviewPixmap( format, QSize( width, height ), QString(), height / 20 );
155  QByteArray data;
156  QBuffer buffer( &data );
157  pm.save( &buffer, "PNG", 100 );
158  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
159  break;
160  }
161 
163  {
164 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
165  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
166 #else
167  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
168 #endif
169  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
170  const QgsPalLayerSettings settings = mStyle->labelSettings( name );
171  QPixmap pm = QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, QSize( width, height ), QString(), height / 20 );
172  QByteArray data;
173  QBuffer buffer( &data );
174  pm.save( &buffer, "PNG", 100 );
175  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
176  break;
177  }
178 
180  case QgsStyle::TagEntity:
182  break;
183  }
184  return tooltip;
185  }
186  else
187  {
188  return name;
189  }
190  }
191  case Tags:
192  return mStyle->tagsOfSymbol( entityType, name ).join( QStringLiteral( ", " ) );
193  }
194  return QVariant();
195  }
196 
197  case Qt::DecorationRole:
198  {
199  // Generate icons at all additional sizes specified for the model.
200  // This allows the model to have size responsive icons.
201 
202  if ( !mExpressionContext )
203  {
204  // build the expression context once, and keep it around. Usually this is a no-no, but in this
205  // case we want to avoid creating potentially thousands of contexts one-by-one (usually one context
206  // is created for a batch of multiple evalutions like this), and we only use a very minimal context
207  // anyway...
208  mExpressionContext = qgis::make_unique< QgsExpressionContext >();
209  mExpressionContext->appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) );
210  }
211 
212  switch ( index.column() )
213  {
214  case Name:
215  switch ( entityType )
216  {
218  {
219  // use cached icon if possible
220  QIcon icon = mSymbolIconCache.value( name );
221  if ( !icon.isNull() )
222  return icon;
223 
224  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
225  if ( symbol )
226  {
227  if ( mAdditionalSizes.isEmpty() )
228  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( 24, 24 ), 1, nullptr, false, mExpressionContext.get() ) );
229 
230  for ( const QSize &s : mAdditionalSizes )
231  {
232  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ), nullptr, false, mExpressionContext.get() ) );
233  }
234 
235  }
236  mSymbolIconCache.insert( name, icon );
237  return icon;
238  }
240  {
241  // use cached icon if possible
242  QIcon icon = mColorRampIconCache.value( name );
243  if ( !icon.isNull() )
244  return icon;
245 
246  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
247  if ( ramp )
248  {
249  if ( mAdditionalSizes.isEmpty() )
250  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), QSize( 24, 24 ), 1 ) );
251  for ( const QSize &s : mAdditionalSizes )
252  {
253  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
254  }
255 
256  }
257  mColorRampIconCache.insert( name, icon );
258  return icon;
259  }
260 
262  {
263  // use cached icon if possible
264  QIcon icon = mTextFormatIconCache.value( name );
265  if ( !icon.isNull() )
266  return icon;
267 
268  const QgsTextFormat format( mStyle->textFormat( name ) );
269  if ( mAdditionalSizes.isEmpty() )
270  icon.addPixmap( QgsTextFormat::textFormatPreviewPixmap( format, QSize( 24, 24 ), QString(), 1 ) );
271  for ( const QSize &s : mAdditionalSizes )
272  {
273  icon.addPixmap( QgsTextFormat::textFormatPreviewPixmap( format, s, QString(), static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
274  }
275  mTextFormatIconCache.insert( name, icon );
276  return icon;
277  }
278 
280  {
281  // use cached icon if possible
282  QIcon icon = mLabelSettingsIconCache.value( name );
283  if ( !icon.isNull() )
284  return icon;
285 
286  const QgsPalLayerSettings settings( mStyle->labelSettings( name ) );
287  if ( mAdditionalSizes.isEmpty() )
288  icon.addPixmap( QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, QSize( 24, 24 ), QString(), 1 ) );
289  for ( const QSize &s : mAdditionalSizes )
290  {
291  icon.addPixmap( QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, s, QString(), static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
292  }
293  mLabelSettingsIconCache.insert( name, icon );
294  return icon;
295  }
296 
297  case QgsStyle::TagEntity:
299  return QVariant();
300  }
301  break;
302 
303  case Tags:
304  return QVariant();
305  }
306  return QVariant();
307  }
308 
309  case TypeRole:
310  return entityType;
311 
312  case TagRole:
313  return mStyle->tagsOfSymbol( entityType, name );
314 
315  case IsFavoriteRole:
316  return mStyle->isFavorite( entityType, name );
317 
318  case SymbolTypeRole:
319  {
320  if ( entityType != QgsStyle::SymbolEntity )
321  return QVariant();
322 
323  const QgsSymbol *symbol = mStyle->symbolRef( name );
324  return symbol ? symbol->type() : QVariant();
325  }
326 
327  case LayerTypeRole:
328  {
329  if ( entityType != QgsStyle::LabelSettingsEntity )
330  return QVariant();
331 
332  return mStyle->labelSettingsLayerType( name );
333  }
334 
335  default:
336  return QVariant();
337  }
338 #ifndef _MSC_VER // avoid warning
339  return QVariant(); // avoid warning
340 #endif
341 }
342 
343 bool QgsStyleModel::setData( const QModelIndex &index, const QVariant &value, int role )
344 {
345  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) || role != Qt::EditRole )
346  return false;
347 
348  switch ( index.column() )
349  {
350  case Name:
351  {
352  QgsStyle::StyleEntity entityType = entityTypeFromRow( index.row() );
353  QString name;
354  switch ( entityType )
355  {
357  name = mSymbolNames.value( index.row() );
358  break;
359 
361  name = mRampNames.value( index.row() - mSymbolNames.size() );
362  break;
363 
365  name = mTextFormatNames.value( index.row() - mSymbolNames.size() - mRampNames.size() );
366  break;
367 
369  name = mLabelSettingsNames.value( index.row() - mSymbolNames.size() - mRampNames.size() - mTextFormatNames.size() );
370  break;
371 
372  case QgsStyle::TagEntity:
374  break;
375  }
376 
377  const QString newName = value.toString();
378 
379  switch ( entityType )
380  {
382  return mStyle->renameSymbol( name, newName );
383 
385  return mStyle->renameColorRamp( name, newName );
386 
388  return mStyle->renameTextFormat( name, newName );
389 
391  return mStyle->renameLabelSettings( name, newName );
392 
393  case QgsStyle::TagEntity:
395  return false;
396  }
397  break;
398  }
399 
400  case Tags:
401  return false;
402  }
403 
404  return false;
405 }
406 
407 Qt::ItemFlags QgsStyleModel::flags( const QModelIndex &index ) const
408 {
409  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
410  if ( index.isValid() && index.column() == Name )
411  {
412  return flags | Qt::ItemIsEditable;
413  }
414  else
415  {
416  return flags;
417  }
418 }
419 
420 QVariant QgsStyleModel::headerData( int section, Qt::Orientation orientation, int role ) const
421 {
422  if ( role == Qt::DisplayRole )
423  {
424  if ( orientation == Qt::Vertical ) //row
425  {
426  return QVariant( section );
427  }
428  else
429  {
430  switch ( section )
431  {
432  case Name:
433  return QVariant( tr( "Name" ) );
434 
435  case Tags:
436  return QVariant( tr( "Tags" ) );
437 
438  default:
439  return QVariant();
440  }
441  }
442  }
443  else
444  {
445  return QVariant();
446  }
447 }
448 
449 QModelIndex QgsStyleModel::index( int row, int column, const QModelIndex &parent ) const
450 {
451  if ( !hasIndex( row, column, parent ) )
452  return QModelIndex();
453 
454  if ( !parent.isValid() )
455  {
456  return createIndex( row, column );
457  }
458 
459  return QModelIndex();
460 }
461 
462 QModelIndex QgsStyleModel::parent( const QModelIndex & ) const
463 {
464  //all items are top level for now
465  return QModelIndex();
466 }
467 
468 int QgsStyleModel::rowCount( const QModelIndex &parent ) const
469 {
470  if ( !parent.isValid() )
471  {
472  return mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() + mLabelSettingsNames.count();
473  }
474  return 0;
475 }
476 
477 int QgsStyleModel::columnCount( const QModelIndex & ) const
478 {
479  return 2;
480 }
481 
483 {
484  if ( mAdditionalSizes.contains( size ) )
485  return;
486 
487  mAdditionalSizes << size;
488  mSymbolIconCache.clear();
489  mColorRampIconCache.clear();
490  mTextFormatIconCache.clear();
491  mLabelSettingsIconCache.clear();
492 }
493 
494 void QgsStyleModel::onSymbolAdded( const QString &name, QgsSymbol * )
495 {
496  mSymbolIconCache.remove( name );
497  const QStringList oldSymbolNames = mSymbolNames;
498  const QStringList newSymbolNames = mStyle->symbolNames();
499 
500  // find index of newly added symbol
501  const int newNameIndex = newSymbolNames.indexOf( name );
502  if ( newNameIndex < 0 )
503  return; // shouldn't happen
504 
505  beginInsertRows( QModelIndex(), newNameIndex, newNameIndex );
506  mSymbolNames = newSymbolNames;
507  endInsertRows();
508 }
509 
510 void QgsStyleModel::onSymbolRemoved( const QString &name )
511 {
512  mSymbolIconCache.remove( name );
513  const QStringList oldSymbolNames = mSymbolNames;
514  const QStringList newSymbolNames = mStyle->symbolNames();
515 
516  // find index of removed symbol
517  const int oldNameIndex = oldSymbolNames.indexOf( name );
518  if ( oldNameIndex < 0 )
519  return; // shouldn't happen
520 
521  beginRemoveRows( QModelIndex(), oldNameIndex, oldNameIndex );
522  mSymbolNames = newSymbolNames;
523  endRemoveRows();
524 }
525 
526 void QgsStyleModel::onSymbolChanged( const QString &name )
527 {
528  mSymbolIconCache.remove( name );
529 
530  QModelIndex i = index( mSymbolNames.indexOf( name ), Tags );
531  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
532 }
533 
534 void QgsStyleModel::onSymbolRename( const QString &oldName, const QString &newName )
535 {
536  mSymbolIconCache.remove( oldName );
537  const QStringList oldSymbolNames = mSymbolNames;
538  const QStringList newSymbolNames = mStyle->symbolNames();
539 
540  // find index of removed symbol
541  const int oldNameIndex = oldSymbolNames.indexOf( oldName );
542  if ( oldNameIndex < 0 )
543  return; // shouldn't happen
544 
545  // find index of added symbol
546  const int newNameIndex = newSymbolNames.indexOf( newName );
547  if ( newNameIndex < 0 )
548  return; // shouldn't happen
549 
550  if ( newNameIndex == oldNameIndex )
551  {
552  mSymbolNames = newSymbolNames;
553  return;
554  }
555 
556  beginMoveRows( QModelIndex(), oldNameIndex, oldNameIndex, QModelIndex(), newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex );
557  mSymbolNames = newSymbolNames;
558  endMoveRows();
559 }
560 
561 void QgsStyleModel::onRampAdded( const QString &name )
562 {
563  mColorRampIconCache.remove( name );
564  const QStringList oldRampNames = mRampNames;
565  const QStringList newRampNames = mStyle->colorRampNames();
566 
567  // find index of newly added symbol
568  const int newNameIndex = newRampNames.indexOf( name );
569  if ( newNameIndex < 0 )
570  return; // shouldn't happen
571 
572  beginInsertRows( QModelIndex(), newNameIndex + mSymbolNames.count(), newNameIndex + mSymbolNames.count() );
573  mRampNames = newRampNames;
574  endInsertRows();
575 }
576 
577 void QgsStyleModel::onRampRemoved( const QString &name )
578 {
579  mColorRampIconCache.remove( name );
580  const QStringList oldRampNames = mRampNames;
581  const QStringList newRampNames = mStyle->colorRampNames();
582 
583  // find index of removed symbol
584  const int oldNameIndex = oldRampNames.indexOf( name );
585  if ( oldNameIndex < 0 )
586  return; // shouldn't happen
587 
588  beginRemoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count(), oldNameIndex + mSymbolNames.count() );
589  mRampNames = newRampNames;
590  endRemoveRows();
591 }
592 
593 void QgsStyleModel::onRampChanged( const QString &name )
594 {
595  mColorRampIconCache.remove( name );
596 
597  QModelIndex i = index( mSymbolNames.count() + mRampNames.indexOf( name ), Tags );
598  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
599 }
600 
601 void QgsStyleModel::onRampRename( const QString &oldName, const QString &newName )
602 {
603  mColorRampIconCache.remove( oldName );
604  const QStringList oldRampNames = mRampNames;
605  const QStringList newRampNames = mStyle->colorRampNames();
606 
607  // find index of removed ramp
608  const int oldNameIndex = oldRampNames.indexOf( oldName );
609  if ( oldNameIndex < 0 )
610  return; // shouldn't happen
611 
612  // find index of newly added ramp
613  const int newNameIndex = newRampNames.indexOf( newName );
614  if ( newNameIndex < 0 )
615  return; // shouldn't happen
616 
617  if ( newNameIndex == oldNameIndex )
618  {
619  mRampNames = newRampNames;
620  return;
621  }
622 
623  beginMoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count(), oldNameIndex + mSymbolNames.count(),
624  QModelIndex(), ( newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex ) + mSymbolNames.count() );
625  mRampNames = newRampNames;
626  endMoveRows();
627 }
628 
629 void QgsStyleModel::onTextFormatAdded( const QString &name )
630 {
631  mTextFormatIconCache.remove( name );
632  const QStringList oldTextFormatNames = mTextFormatNames;
633  const QStringList newTextFormatNames = mStyle->textFormatNames();
634 
635  // find index of newly added symbol
636  const int newNameIndex = newTextFormatNames.indexOf( name );
637  if ( newNameIndex < 0 )
638  return; // shouldn't happen
639 
640  beginInsertRows( QModelIndex(), newNameIndex + mSymbolNames.count() + mRampNames.count(), newNameIndex + mSymbolNames.count() + mRampNames.count() );
641  mTextFormatNames = newTextFormatNames;
642  endInsertRows();
643 }
644 
645 void QgsStyleModel::onTextFormatRemoved( const QString &name )
646 {
647  mTextFormatIconCache.remove( name );
648  const QStringList oldTextFormatNames = mTextFormatNames;
649  const QStringList newTextFormatNames = mStyle->textFormatNames();
650 
651  // find index of removed symbol
652  const int oldNameIndex = oldTextFormatNames.indexOf( name );
653  if ( oldNameIndex < 0 )
654  return; // shouldn't happen
655 
656  beginRemoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count() + mRampNames.count(), oldNameIndex + mSymbolNames.count() + mRampNames.count() );
657  mTextFormatNames = newTextFormatNames;
658  endRemoveRows();
659 }
660 
661 void QgsStyleModel::onTextFormatChanged( const QString &name )
662 {
663  mTextFormatIconCache.remove( name );
664 
665  QModelIndex i = index( mSymbolNames.count() + mRampNames.count() + mTextFormatNames.indexOf( name ), Tags );
666  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
667 }
668 
669 void QgsStyleModel::onTextFormatRename( const QString &oldName, const QString &newName )
670 {
671  mTextFormatIconCache.remove( oldName );
672  const QStringList oldTextFormatNames = mTextFormatNames;
673  const QStringList newTextFormatNames = mStyle->textFormatNames();
674 
675  // find index of removed format
676  const int oldNameIndex = oldTextFormatNames.indexOf( oldName );
677  if ( oldNameIndex < 0 )
678  return; // shouldn't happen
679 
680  // find index of newly added format
681  const int newNameIndex = newTextFormatNames.indexOf( newName );
682  if ( newNameIndex < 0 )
683  return; // shouldn't happen
684 
685  if ( newNameIndex == oldNameIndex )
686  {
687  mTextFormatNames = newTextFormatNames;
688  return;
689  }
690 
691  beginMoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count() + mRampNames.count(), oldNameIndex + mSymbolNames.count() + mRampNames.count(),
692  QModelIndex(), ( newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex ) + mSymbolNames.count() + mRampNames.count() );
693  mTextFormatNames = newTextFormatNames;
694  endMoveRows();
695 }
696 
697 void QgsStyleModel::onLabelSettingsAdded( const QString &name )
698 {
699  mLabelSettingsIconCache.remove( name );
700  const QStringList oldLabelSettingsNames = mLabelSettingsNames;
701  const QStringList newLabelSettingsNames = mStyle->labelSettingsNames();
702 
703  // find index of newly added symbol
704  const int newNameIndex = newLabelSettingsNames.indexOf( name );
705  if ( newNameIndex < 0 )
706  return; // shouldn't happen
707 
708  beginInsertRows( QModelIndex(), newNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count(), newNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() );
709  mLabelSettingsNames = newLabelSettingsNames;
710  endInsertRows();
711 }
712 
713 void QgsStyleModel::onLabelSettingsRemoved( const QString &name )
714 {
715  mLabelSettingsIconCache.remove( name );
716  const QStringList oldLabelSettingsNames = mLabelSettingsNames;
717  const QStringList newLabelSettingsNames = mStyle->labelSettingsNames();
718 
719  // find index of removed symbol
720  const int oldNameIndex = oldLabelSettingsNames.indexOf( name );
721  if ( oldNameIndex < 0 )
722  return; // shouldn't happen
723 
724  beginRemoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count(), oldNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() );
725  mLabelSettingsNames = newLabelSettingsNames;
726  endRemoveRows();
727 }
728 
729 void QgsStyleModel::onLabelSettingsChanged( const QString &name )
730 {
731  mLabelSettingsIconCache.remove( name );
732 
733  QModelIndex i = index( mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() + mLabelSettingsNames.indexOf( name ), Tags );
734  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
735 }
736 
737 void QgsStyleModel::onLabelSettingsRename( const QString &oldName, const QString &newName )
738 {
739  mLabelSettingsIconCache.remove( oldName );
740  const QStringList oldLabelSettingsNames = mLabelSettingsNames;
741  const QStringList newLabelSettingsNames = mStyle->labelSettingsNames();
742 
743  // find index of removed format
744  const int oldNameIndex = oldLabelSettingsNames.indexOf( oldName );
745  if ( oldNameIndex < 0 )
746  return; // shouldn't happen
747 
748  // find index of newly added format
749  const int newNameIndex = newLabelSettingsNames.indexOf( newName );
750  if ( newNameIndex < 0 )
751  return; // shouldn't happen
752 
753  if ( newNameIndex == oldNameIndex )
754  {
755  mLabelSettingsNames = newLabelSettingsNames;
756  return;
757  }
758 
759  beginMoveRows( QModelIndex(), oldNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count(), oldNameIndex + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count(),
760  QModelIndex(), ( newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex ) + mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() );
761  mLabelSettingsNames = newLabelSettingsNames;
762  endMoveRows();
763 }
764 
765 void QgsStyleModel::onTagsChanged( int entity, const QString &name, const QStringList & )
766 {
767  QModelIndex i;
768  switch ( static_cast< QgsStyle::StyleEntity >( entity ) )
769  {
771  i = index( mSymbolNames.indexOf( name ), Tags );
772  break;
773 
775  i = index( mSymbolNames.count() + mRampNames.indexOf( name ), Tags );
776  break;
777 
779  i = index( mSymbolNames.count() + mRampNames.count() + mTextFormatNames.indexOf( name ), Tags );
780  break;
781 
783  i = index( mSymbolNames.count() + mRampNames.count() + mTextFormatNames.count() + mLabelSettingsNames.indexOf( name ), Tags );
784  break;
785 
786  case QgsStyle::TagEntity:
788  return;
789  }
790  emit dataChanged( i, i );
791 }
792 
793 void QgsStyleModel::rebuildSymbolIcons()
794 {
795  mSymbolIconCache.clear();
796  mExpressionContext.reset();
797  emit dataChanged( index( 0, 0 ), index( mSymbolNames.count() - 1, 0 ), QVector<int>() << Qt::DecorationRole );
798 }
799 
800 QgsStyle::StyleEntity QgsStyleModel::entityTypeFromRow( int row ) const
801 {
802  if ( row >= mStyle->symbolCount() + mStyle->colorRampCount() + + mTextFormatNames.count() )
804  else if ( row >= mStyle->symbolCount() + mStyle->colorRampCount() )
806  else if ( row >= mStyle->symbolCount() )
808  return QgsStyle::SymbolEntity;
809 }
810 
811 //
812 // QgsStyleProxyModel
813 //
814 
816  : QSortFilterProxyModel( parent )
817  , mStyle( style )
818 {
819  mModel = new QgsStyleModel( mStyle, this );
820  initialize();
821 }
822 
823 void QgsStyleProxyModel::initialize()
824 {
825  setSortCaseSensitivity( Qt::CaseInsensitive );
826 // setSortLocaleAware( true );
827  setSourceModel( mModel );
828  setDynamicSortFilter( true );
829  sort( 0 );
830 
831  connect( mStyle, &QgsStyle::entityTagsChanged, this, [ = ]
832  {
833  // update tagged symbols if filtering by tag
834  if ( mTagId >= 0 )
835  setTagId( mTagId );
836  if ( mSmartGroupId >= 0 )
837  setSmartGroupId( mSmartGroupId );
838  } );
839 
840  connect( mStyle, &QgsStyle::favoritedChanged, this, [ = ]
841  {
842  // update favorited symbols if filtering by favorite
843  if ( mFavoritesOnly )
844  setFavoritesOnly( mFavoritesOnly );
845  } );
846 
847  connect( mStyle, &QgsStyle::rampRenamed, this, [ = ]
848  {
849  if ( mSmartGroupId >= 0 )
850  setSmartGroupId( mSmartGroupId );
851  } );
852  connect( mStyle, &QgsStyle::textFormatRenamed, this, [ = ]
853  {
854  if ( mSmartGroupId >= 0 )
855  setSmartGroupId( mSmartGroupId );
856  } );
857  connect( mStyle, &QgsStyle::labelSettingsRenamed, this, [ = ]
858  {
859  if ( mSmartGroupId >= 0 )
860  setSmartGroupId( mSmartGroupId );
861  } );
862  connect( mStyle, &QgsStyle::symbolRenamed, this, [ = ]
863  {
864  if ( mSmartGroupId >= 0 )
865  setSmartGroupId( mSmartGroupId );
866  } );
867 }
868 
870  : QSortFilterProxyModel( parent )
871  , mModel( model )
872  , mStyle( model->style() )
873 {
874  initialize();
875 }
876 
877 bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
878 {
879  if ( mFilterString.isEmpty() && !mEntityFilterEnabled && !mSymbolTypeFilterEnabled && mTagId < 0 && mSmartGroupId < 0 && !mFavoritesOnly )
880  return true;
881 
882  QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
883  const QString name = sourceModel()->data( index ).toString();
884  const QStringList tags = sourceModel()->data( index, QgsStyleModel::TagRole ).toStringList();
885 
886  QgsStyle::StyleEntity styleEntityType = static_cast< QgsStyle::StyleEntity >( sourceModel()->data( index, QgsStyleModel::TypeRole ).toInt() );
887  if ( mEntityFilterEnabled && ( mEntityFilters.empty() || !mEntityFilters.contains( styleEntityType ) ) )
888  return false;
889 
890  QgsSymbol::SymbolType symbolType = static_cast< QgsSymbol::SymbolType >( sourceModel()->data( index, QgsStyleModel::SymbolTypeRole ).toInt() );
891  if ( mSymbolTypeFilterEnabled && symbolType != mSymbolType )
892  return false;
893 
894  if ( styleEntityType == QgsStyle::LabelSettingsEntity && mLayerType != QgsWkbTypes::UnknownGeometry &&
895  mLayerType != static_cast< QgsWkbTypes::GeometryType >( sourceModel()->data( index, QgsStyleModel::LayerTypeRole ).toInt() ) )
896  return false;
897 
898  if ( mTagId >= 0 && !mTaggedSymbolNames.contains( name ) )
899  return false;
900 
901  if ( mSmartGroupId >= 0 && !mSmartGroupSymbolNames.contains( name ) )
902  return false;
903 
904  if ( mFavoritesOnly && !sourceModel()->data( index, QgsStyleModel::IsFavoriteRole ).toBool() )
905  return false;
906 
907  if ( !mFilterString.isEmpty() )
908  {
909  // filter by word, in both filter string and style entity name/tags
910  // this allows matching of a filter string "hash line" to the symbol "hashed red lines"
911  const QStringList partsToMatch = mFilterString.trimmed().split( ' ' );
912 
913  QStringList partsToSearch = name.split( ' ' );
914  for ( const QString &tag : tags )
915  {
916  partsToSearch.append( tag.split( ' ' ) );
917  }
918 
919  for ( const QString &part : partsToMatch )
920  {
921  bool found = false;
922  for ( const QString &partToSearch : qgis::as_const( partsToSearch ) )
923  {
924  if ( partToSearch.contains( part, Qt::CaseInsensitive ) )
925  {
926  found = true;
927  break;
928  }
929  }
930  if ( !found )
931  return false; // couldn't find a match for this word, so hide entity
932  }
933  }
934 
935  return true;
936 }
937 
938 void QgsStyleProxyModel::setFilterString( const QString &filter )
939 {
940  mFilterString = filter;
941  invalidateFilter();
942 }
943 
944 
946 {
947  return mFavoritesOnly;
948 }
949 
951 {
952  mFavoritesOnly = favoritesOnly;
953  invalidateFilter();
954 }
955 
957 {
958  mModel->addDesiredIconSize( size );
959 }
960 
962 {
963  return mSymbolTypeFilterEnabled;
964 }
965 
967 {
968  mSymbolTypeFilterEnabled = symbolTypeFilterEnabled;
969  invalidateFilter();
970 }
971 
973 {
974  return mLayerType;
975 }
976 
978 {
979  mLayerType = type;
980  invalidateFilter();
981 }
982 
984 {
985  mTagId = id;
986 
987  if ( mTagId >= 0 )
988  {
989  mTaggedSymbolNames = mStyle->symbolsWithTag( QgsStyle::SymbolEntity, mTagId );
990  mTaggedSymbolNames.append( mStyle->symbolsWithTag( QgsStyle::ColorrampEntity, mTagId ) );
991  mTaggedSymbolNames.append( mStyle->symbolsWithTag( QgsStyle::TextFormatEntity, mTagId ) );
992  mTaggedSymbolNames.append( mStyle->symbolsWithTag( QgsStyle::LabelSettingsEntity, mTagId ) );
993  }
994  else
995  {
996  mTaggedSymbolNames.clear();
997  }
998 
999  invalidateFilter();
1000 }
1001 
1003 {
1004  return mTagId;
1005 }
1006 
1008 {
1009  mSmartGroupId = id;
1010 
1011  if ( mSmartGroupId >= 0 )
1012  {
1013  mSmartGroupSymbolNames = mStyle->symbolsOfSmartgroup( QgsStyle::SymbolEntity, mSmartGroupId );
1014  mSmartGroupSymbolNames.append( mStyle->symbolsOfSmartgroup( QgsStyle::ColorrampEntity, mSmartGroupId ) );
1015  mSmartGroupSymbolNames.append( mStyle->symbolsOfSmartgroup( QgsStyle::TextFormatEntity, mSmartGroupId ) );
1016  mSmartGroupSymbolNames.append( mStyle->symbolsOfSmartgroup( QgsStyle::LabelSettingsEntity, mSmartGroupId ) );
1017  }
1018  else
1019  {
1020  mSmartGroupSymbolNames.clear();
1021  }
1022 
1023  invalidateFilter();
1024 }
1025 
1027 {
1028  return mSmartGroupId;
1029 }
1030 
1032 {
1033  return mSymbolType;
1034 }
1035 
1037 {
1038  mSymbolType = symbolType;
1039  invalidateFilter();
1040 }
1041 
1043 {
1044  return mEntityFilterEnabled;
1045 }
1046 
1048 {
1049  mEntityFilterEnabled = entityFilterEnabled;
1050  invalidateFilter();
1051 }
1052 
1054 {
1055  return mEntityFilters.empty() ? QgsStyle::SymbolEntity : mEntityFilters.at( 0 );
1056 }
1057 
1059 {
1060  mEntityFilters = QList< QgsStyle::StyleEntity >() << entityFilter;
1061  invalidateFilter();
1062 }
1063 
1064 void QgsStyleProxyModel::setEntityFilters( const QList<QgsStyle::StyleEntity> &filters )
1065 {
1066  mEntityFilters = filters;
1067  invalidateFilter();
1068 }
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:45
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
QgsStyle * style()
Returns the style managed by the model.
Definition: qgsstylemodel.h:80
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 textFormatAdded(const QString &name)
Emitted whenever a text format has been added to the style and the database has been updated as a res...
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:62
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:182
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:933
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:1674
Layer type (for label settings entities)
Definition: qgsstylemodel.h:65
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.
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for label settings.
void textFormatRemoved(const QString &name)
Emitted whenever a text format has been removed from the style and the database has been updated as a...
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:356
QgsWkbTypes::GeometryType layerType() const
Returns the layer type filter, or QgsWkbTypes::UnknownGeometry if no layer type filter is present...
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:62
QModelIndex parent(const QModelIndex &index) const override
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:177
bool isFavorite(StyleEntity type, const QString &name)
Returns true if the symbol with matching type and name is marked as a favorite.
Definition: qgsstyle.cpp:1806
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
SymbolType
Type of the symbol.
Definition: qgssymbol.h:84
int symbolCount()
Returns count of symbols in style.
Definition: qgsstyle.cpp:225
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:643
QStringList textFormatNames() const
Returns a list of names of text formats in the style.
Definition: qgsstyle.cpp:2038
const double ICON_PADDING_FACTOR
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
Definition: qgsstyle.cpp:2048
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
void labelSettingsRemoved(const QString &name)
Emitted whenever label settings have been removed from the style and the database has been updated as...
const QgsSymbol * symbolRef(const QString &name) const
Returns a const pointer to a symbol (doesn&#39;t create new instance)
Definition: qgsstyle.cpp:220
QStringList labelSettingsNames() const
Returns a list of names of label settings in the style.
Definition: qgsstyle.cpp:2066
static QPixmap textFormatPreviewPixmap(const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for a text format.
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.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer&#39;s project and layer.
void symbolRenamed(const QString &oldName, const QString &newName)
Emitted whenever a symbol has been renamed from oldName to newName.
void labelSettingsChanged(const QString &name)
Emitted whenever a label setting&#39;s definition is changed.
QgsTextFormat textFormat(const QString &name) const
Returns the text format with the specified name.
Definition: qgsstyle.cpp:2028
Tags column.
Definition: qgsstylemodel.h:55
void textFormatRenamed(const QString &oldName, const QString &newName)
Emitted whenever a text format has been renamed from oldName to newName.
void setLayerType(QgsWkbTypes::GeometryType type)
Sets the layer type filter.
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.
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:2212
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.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
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.
void textFormatChanged(const QString &name)
Emitted whenever a text format&#39;s definition is changed.
Name column.
Definition: qgsstylemodel.h:54
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:121
QgsSymbol::SymbolType symbolType() const
Returns the symbol type filter.
bool entityFilterEnabled() const
Returns true if filtering by entity type is enabled.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr)
Returns a pixmap preview for a color ramp.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:450
QStringList colorRampNames() const
Returns a list of names of color ramps.
Definition: qgsstyle.cpp:372
bool renameLabelSettings(const QString &oldName, const QString &newName)
Changes a label setting&#39;s name.
Definition: qgsstyle.cpp:855
bool renameColorRamp(const QString &oldName, const QString &newName)
Changes ramp&#39;s name.
Definition: qgsstyle.cpp:680
QgsWkbTypes::GeometryType labelSettingsLayerType(const QString &name) const
Returns the layer geometry type corresponding to the label settings with the specified name...
Definition: qgsstyle.cpp:2053
int colorRampCount()
Returns count of color ramps.
Definition: qgsstyle.cpp:367
void labelSettingsRenamed(const QString &oldName, const QString &newName)
Emitted whenever label settings have been renamed from oldName to newName.
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
void labelSettingsAdded(const QString &name)
Emitted whenever label settings have been added to the style and the database has been updated as a r...
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:214
QVariant data(const QModelIndex &index, int role) const override
Whether entity is flagged as a favorite.
Definition: qgsstylemodel.h:64
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
Container for all settings relating to text rendering.
Style entity type, see QgsStyle::StyleEntity.
Definition: qgsstylemodel.h:61
QgsStyle::StyleEntity entityFilter() const
Returns the style entity type filter.
bool symbolTypeFilterEnabled() const
Returns true if filtering by symbol type is enabled.
bool renameTextFormat(const QString &oldName, const QString &newName)
Changes a text format&#39;s name.
Definition: qgsstyle.cpp:768
void setEntityFilters(const QList< QgsStyle::StyleEntity > &filters)
Sets the style entity type filters.
Qt::ItemFlags flags(const QModelIndex &index) const override
Symbol type (for symbol entities)
Definition: qgsstylemodel.h:63
QStringList symbolNames() const
Returns a list of names of symbols.
Definition: qgsstyle.cpp:230