QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
29 
30 QgsAbstractStyleEntityIconGenerator *QgsStyleModel::sIconGenerator = nullptr;
31 
32 //
33 // QgsAbstractStyleEntityIconGenerator
34 //
35 
37  : QObject( parent )
38 {
39 
40 }
41 
42 void QgsAbstractStyleEntityIconGenerator::setIconSizes( const QList<QSize> &sizes )
43 {
44  mIconSizes = sizes;
45 }
46 
48 {
49  return mIconSizes;
50 }
51 
52 
53 //
54 // QgsStyleModel
55 //
56 
57 QgsStyleModel::QgsStyleModel( QgsStyle *style, QObject *parent )
58  : QAbstractItemModel( parent )
59  , mStyle( style )
60 {
61  Q_ASSERT( mStyle );
62 
63  for ( QgsStyle::StyleEntity entity : ENTITIES )
64  {
65  mEntityNames.insert( entity, mStyle->allNames( entity ) );
66  }
67 
68  connect( mStyle, &QgsStyle::entityAdded, this, &QgsStyleModel::onEntityAdded );
69  connect( mStyle, &QgsStyle::entityRemoved, this, &QgsStyleModel::onEntityRemoved );
70  connect( mStyle, &QgsStyle::entityRenamed, this, &QgsStyleModel::onEntityRename );
71  connect( mStyle, &QgsStyle::entityChanged, this, &QgsStyleModel::onEntityChanged );
72  connect( mStyle, &QgsStyle::entityTagsChanged, this, &QgsStyleModel::onTagsChanged );
73 
74  // when a remote svg or image has been fetched, update the model's decorations.
75  // this is required if a symbol utilizes remote svgs, and the current icons
76  // have been generated using the temporary "downloading" svg. In this case
77  // we require the preview to be regenerated to use the correct fetched
78  // svg
79  connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsStyleModel::rebuildSymbolIcons );
80  connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsStyleModel::rebuildSymbolIcons );
81 
82  // if project color scheme changes, we need to redraw symbols - they may use project colors and accordingly
83  // need updating to reflect the new colors
84  connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsStyleModel::rebuildSymbolIcons );
85 
86  if ( sIconGenerator )
87  connect( sIconGenerator, &QgsAbstractStyleEntityIconGenerator::iconGenerated, this, &QgsStyleModel::iconGenerated, Qt::QueuedConnection );
88 }
89 
90 QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const
91 {
92  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) )
93  return QVariant();
94 
95 
96  QgsStyle::StyleEntity entityType = entityTypeFromRow( index.row() );
97 
98  QString name;
99  switch ( entityType )
100  {
101  case QgsStyle::TagEntity:
103  break;
104 
105  default:
106  name = mEntityNames[ entityType ].value( index.row() - offsetForEntity( entityType ) );
107  break;
108  }
109 
110  switch ( role )
111  {
112  case Qt::DisplayRole:
113  case Qt::ToolTipRole:
114  case Qt::EditRole:
115  {
116  switch ( index.column() )
117  {
118  case Name:
119  {
120  const QStringList tags = mStyle->tagsOfSymbol( entityType, name );
121 
122  if ( role == Qt::ToolTipRole )
123  {
124  QString tooltip = QStringLiteral( "<h3>%1</h3><p><i>%2</i>" ).arg( name,
125  tags.count() > 0 ? tags.join( QLatin1String( ", " ) ) : tr( "Not tagged" ) );
126 
127  switch ( entityType )
128  {
130  {
131  // create very large preview image
132  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
133  if ( symbol )
134  {
135 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
136  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
137 #else
138  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
139 #endif
140  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
141  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( width, height ), height / 20, nullptr, false, mExpressionContext.get() );
142  QByteArray data;
143  QBuffer buffer( &data );
144  pm.save( &buffer, "PNG", 100 );
145  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
146  }
147  break;
148  }
149 
151  {
152 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
153  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
154 #else
155  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
156 #endif
157  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
158  const QgsTextFormat format = mStyle->textFormat( name );
159  QPixmap pm = QgsTextFormat::textFormatPreviewPixmap( format, QSize( width, height ), QString(), height / 20 );
160  QByteArray data;
161  QBuffer buffer( &data );
162  pm.save( &buffer, "PNG", 100 );
163  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
164  break;
165  }
166 
168  {
169 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
170  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
171 #else
172  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
173 #endif
174  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
175  const QgsPalLayerSettings settings = mStyle->labelSettings( name );
176  QPixmap pm = QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, QSize( width, height ), QString(), height / 20 );
177  QByteArray data;
178  QBuffer buffer( &data );
179  pm.save( &buffer, "PNG", 100 );
180  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
181  break;
182  }
183 
185  {
186 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
187  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).width( 'X' ) * 23 );
188 #else
189  int width = static_cast< int >( Qgis::UI_SCALE_FACTOR * QFontMetrics( data( index, Qt::FontRole ).value< QFont >() ).horizontalAdvance( 'X' ) * 23 );
190 #endif
191  int height = static_cast< int >( width / 1.61803398875 ); // golden ratio
192 
193  const QgsLegendPatchShape shape = mStyle->legendPatchShape( name );
194  if ( const QgsSymbol *symbol = mStyle->previewSymbolForPatchShape( shape ) )
195  {
196  QPixmap pm = QgsSymbolLayerUtils::symbolPreviewPixmap( symbol, QSize( width, height ), height / 20, nullptr, false, nullptr, &shape );
197  QByteArray data;
198  QBuffer buffer( &data );
199  pm.save( &buffer, "PNG", 100 );
200  tooltip += QStringLiteral( "<p><img src='data:image/png;base64, %3'>" ).arg( QString( data.toBase64() ) );
201  }
202  break;
203  }
204 
206  case QgsStyle::TagEntity:
209  break;
210  }
211  return tooltip;
212  }
213  else
214  {
215  return name;
216  }
217  }
218  case Tags:
219  return mStyle->tagsOfSymbol( entityType, name ).join( QLatin1String( ", " ) );
220  }
221  return QVariant();
222  }
223 
224  case Qt::DecorationRole:
225  {
226  // Generate icons at all additional sizes specified for the model.
227  // This allows the model to have size responsive icons.
228 
229  if ( !mExpressionContext )
230  {
231  // build the expression context once, and keep it around. Usually this is a no-no, but in this
232  // case we want to avoid creating potentially thousands of contexts one-by-one (usually one context
233  // is created for a batch of multiple evalutions like this), and we only use a very minimal context
234  // anyway...
235  mExpressionContext = qgis::make_unique< QgsExpressionContext >();
236  mExpressionContext->appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) );
237  }
238 
239  switch ( index.column() )
240  {
241  case Name:
242  switch ( entityType )
243  {
245  {
246  // use cached icon if possible
247  QIcon icon = mIconCache[ entityType ].value( name );
248  if ( !icon.isNull() )
249  return icon;
250 
251  std::unique_ptr< QgsSymbol > symbol( mStyle->symbol( name ) );
252  if ( symbol )
253  {
254  if ( mAdditionalSizes.isEmpty() )
255  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), QSize( 24, 24 ), 1, nullptr, false, mExpressionContext.get() ) );
256 
257  for ( const QSize &s : mAdditionalSizes )
258  {
259  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ), nullptr, false, mExpressionContext.get() ) );
260  }
261 
262  }
263  mIconCache[ entityType ].insert( name, icon );
264  return icon;
265  }
267  {
268  // use cached icon if possible
269  QIcon icon = mIconCache[ entityType ].value( name );
270  if ( !icon.isNull() )
271  return icon;
272 
273  std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
274  if ( ramp )
275  {
276  if ( mAdditionalSizes.isEmpty() )
277  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), QSize( 24, 24 ), 1 ) );
278  for ( const QSize &s : mAdditionalSizes )
279  {
280  icon.addPixmap( QgsSymbolLayerUtils::colorRampPreviewPixmap( ramp.get(), s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
281  }
282 
283  }
284  mIconCache[ entityType ].insert( name, icon );
285  return icon;
286  }
287 
289  {
290  // use cached icon if possible
291  QIcon icon = mIconCache[ entityType ].value( name );
292  if ( !icon.isNull() )
293  return icon;
294 
295  const QgsTextFormat format( mStyle->textFormat( name ) );
296  if ( mAdditionalSizes.isEmpty() )
297  icon.addPixmap( QgsTextFormat::textFormatPreviewPixmap( format, QSize( 24, 24 ), QString(), 1 ) );
298  for ( const QSize &s : mAdditionalSizes )
299  {
300  icon.addPixmap( QgsTextFormat::textFormatPreviewPixmap( format, s, QString(), static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
301  }
302  mIconCache[ entityType ].insert( name, icon );
303  return icon;
304  }
305 
307  {
308  // use cached icon if possible
309  QIcon icon = mIconCache[ entityType ].value( name );
310  if ( !icon.isNull() )
311  return icon;
312 
313  const QgsPalLayerSettings settings( mStyle->labelSettings( name ) );
314  if ( mAdditionalSizes.isEmpty() )
315  icon.addPixmap( QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, QSize( 24, 24 ), QString(), 1 ) );
316  for ( const QSize &s : mAdditionalSizes )
317  {
318  icon.addPixmap( QgsPalLayerSettings::labelSettingsPreviewPixmap( settings, s, QString(), static_cast< int >( s.width() * ICON_PADDING_FACTOR ) ) );
319  }
320  mIconCache[ entityType ].insert( name, icon );
321  return icon;
322  }
323 
325  {
326  // use cached icon if possible
327  QIcon icon = mIconCache[ entityType ].value( name );
328  if ( !icon.isNull() )
329  return icon;
330 
331  const QgsLegendPatchShape shape = mStyle->legendPatchShape( name );
332  if ( !shape.isNull() )
333  {
334  if ( const QgsSymbol *symbol = mStyle->previewSymbolForPatchShape( shape ) )
335  {
336  if ( mAdditionalSizes.isEmpty() )
337  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol, QSize( 24, 24 ), 1, nullptr, false, mExpressionContext.get(), &shape ) );
338 
339  for ( const QSize &s : mAdditionalSizes )
340  {
341  icon.addPixmap( QgsSymbolLayerUtils::symbolPreviewPixmap( symbol, s, static_cast< int >( s.width() * ICON_PADDING_FACTOR ), nullptr, false, mExpressionContext.get(), &shape ) );
342  }
343  }
344  }
345  mIconCache[ entityType ].insert( name, icon );
346  return icon;
347  }
348 
350  {
351  // hack for now -- we just use a generic "3d icon" svg file.
352  // TODO - render proper thumbnails
353 
354  // use cached icon if possible
355  QIcon icon = mIconCache[ entityType ].value( name );
356  if ( !icon.isNull() )
357  return icon;
358 
359  if ( sIconGenerator && !mPending3dSymbolIcons.contains( name ) )
360  {
361  mPending3dSymbolIcons.insert( name );
362  sIconGenerator->generateIcon( mStyle, QgsStyle::Symbol3DEntity, name );
363  }
364 
365  // TODO - use hourglass icon
366  if ( mAdditionalSizes.isEmpty() )
367  icon.addFile( QgsApplication::defaultThemePath() + QDir::separator() + QStringLiteral( "3d.svg" ), QSize( 24, 24 ) );
368  for ( const QSize &s : mAdditionalSizes )
369  {
370  icon.addFile( QgsApplication::defaultThemePath() + QDir::separator() + QStringLiteral( "3d.svg" ), s );
371  }
372  mIconCache[ entityType ].insert( name, icon );
373  return icon;
374  }
375 
376  case QgsStyle::TagEntity:
378  return QVariant();
379  }
380  break;
381 
382  case Tags:
383  return QVariant();
384  }
385  return QVariant();
386  }
387 
388  case TypeRole:
389  return entityType;
390 
391  case TagRole:
392  return mStyle->tagsOfSymbol( entityType, name );
393 
394  case IsFavoriteRole:
395  return mStyle->isFavorite( entityType, name );
396 
397  case SymbolTypeRole:
398  {
399  switch ( entityType )
400  {
402  {
403  const QgsSymbol *symbol = mStyle->symbolRef( name );
404  return symbol ? symbol->type() : QVariant();
405  }
406 
408  return mStyle->legendPatchShapeSymbolType( name );
409 
410  case QgsStyle::TagEntity:
416  return QVariant();
417  }
418  return QVariant();
419  }
420 
421  case LayerTypeRole:
422  {
423  switch ( entityType )
424  {
426  return mStyle->labelSettingsLayerType( name );
427 
431  case QgsStyle::TagEntity:
435  return QVariant();
436  }
437  return QVariant();
438  }
439 
441  {
442  switch ( entityType )
443  {
445  {
446  QVariantList res;
447  const QList< QgsWkbTypes::GeometryType > types = mStyle->symbol3DCompatibleGeometryTypes( name );
448  res.reserve( types.size() );
449  for ( QgsWkbTypes::GeometryType type : types )
450  {
451  res << static_cast< int >( type );
452  }
453  return res;
454  }
455 
459  case QgsStyle::TagEntity:
463  return QVariant();
464  }
465  return QVariant();
466  }
467 
468  default:
469  return QVariant();
470  }
471 #ifndef _MSC_VER // avoid warning
472  return QVariant(); // avoid warning
473 #endif
474 }
475 
476 bool QgsStyleModel::setData( const QModelIndex &index, const QVariant &value, int role )
477 {
478  if ( index.row() < 0 || index.row() >= rowCount( QModelIndex() ) || role != Qt::EditRole )
479  return false;
480 
481  switch ( index.column() )
482  {
483  case Name:
484  {
485  QgsStyle::StyleEntity entityType = entityTypeFromRow( index.row() );
486  QString name;
487  switch ( entityType )
488  {
489  case QgsStyle::TagEntity:
491  return false;
492 
493  default:
494  name = mEntityNames[ entityType ].value( index.row() - offsetForEntity( entityType ) );
495  break;
496  }
497 
498  const QString newName = value.toString();
499  return mStyle->renameEntity( entityType, name, newName );
500  }
501 
502  case Tags:
503  return false;
504  }
505 
506  return false;
507 }
508 
509 Qt::ItemFlags QgsStyleModel::flags( const QModelIndex &index ) const
510 {
511  Qt::ItemFlags flags = QAbstractItemModel::flags( index );
512  if ( index.isValid() && index.column() == Name )
513  {
514  return flags | Qt::ItemIsEditable;
515  }
516  else
517  {
518  return flags;
519  }
520 }
521 
522 QVariant QgsStyleModel::headerData( int section, Qt::Orientation orientation, int role ) const
523 {
524  if ( role == Qt::DisplayRole )
525  {
526  if ( orientation == Qt::Vertical ) //row
527  {
528  return QVariant( section );
529  }
530  else
531  {
532  switch ( section )
533  {
534  case Name:
535  return QVariant( tr( "Name" ) );
536 
537  case Tags:
538  return QVariant( tr( "Tags" ) );
539 
540  default:
541  return QVariant();
542  }
543  }
544  }
545  else
546  {
547  return QVariant();
548  }
549 }
550 
551 QModelIndex QgsStyleModel::index( int row, int column, const QModelIndex &parent ) const
552 {
553  if ( !hasIndex( row, column, parent ) )
554  return QModelIndex();
555 
556  if ( !parent.isValid() )
557  {
558  return createIndex( row, column );
559  }
560 
561  return QModelIndex();
562 }
563 
564 QModelIndex QgsStyleModel::parent( const QModelIndex & ) const
565 {
566  //all items are top level for now
567  return QModelIndex();
568 }
569 
570 int QgsStyleModel::rowCount( const QModelIndex &parent ) const
571 {
572  if ( !parent.isValid() )
573  {
574  int count = 0;
575  for ( QgsStyle::StyleEntity type : ENTITIES )
576  count += mEntityNames[ type ].size();
577  return count;
578  }
579  return 0;
580 }
581 
582 int QgsStyleModel::columnCount( const QModelIndex & ) const
583 {
584  return 2;
585 }
586 
588 {
589  if ( mAdditionalSizes.contains( size ) )
590  return;
591 
592  mAdditionalSizes << size;
593 
594  if ( sIconGenerator )
595  sIconGenerator->setIconSizes( mAdditionalSizes );
596 
597  mIconCache.clear();
598 }
599 
601 {
602  sIconGenerator = generator;
603  connect( sIconGenerator, &QgsAbstractStyleEntityIconGenerator::iconGenerated, QgsApplication::defaultStyleModel(), &QgsStyleModel::iconGenerated, Qt::QueuedConnection );
604 }
605 
606 void QgsStyleModel::onEntityAdded( QgsStyle::StyleEntity type, const QString &name )
607 {
608  mIconCache[ type ].remove( name );
609  const QStringList oldSymbolNames = mEntityNames[ type ];
610  const QStringList newSymbolNames = mStyle->allNames( type );
611 
612  // find index of newly added symbol
613  const int newNameIndex = newSymbolNames.indexOf( name );
614  if ( newNameIndex < 0 )
615  return; // shouldn't happen
616 
617  const int offset = offsetForEntity( type );
618  beginInsertRows( QModelIndex(), newNameIndex + offset, newNameIndex + offset );
619  mEntityNames[ type ] = newSymbolNames;
620  endInsertRows();
621 }
622 
623 void QgsStyleModel::onEntityRemoved( QgsStyle::StyleEntity type, const QString &name )
624 {
625  mIconCache[ type ].remove( name );
626  const QStringList oldSymbolNames = mEntityNames[ type ];
627  const QStringList newSymbolNames = mStyle->allNames( type );
628 
629  // find index of removed symbol
630  const int oldNameIndex = oldSymbolNames.indexOf( name );
631  if ( oldNameIndex < 0 )
632  return; // shouldn't happen
633 
634  const int offset = offsetForEntity( type );
635  beginRemoveRows( QModelIndex(), oldNameIndex + offset, oldNameIndex + offset );
636  mEntityNames[ type ] = newSymbolNames;
637  endRemoveRows();
638 }
639 
640 void QgsStyleModel::onEntityChanged( QgsStyle::StyleEntity type, const QString &name )
641 {
642  mIconCache[ type ].remove( name );
643 
644  const int offset = offsetForEntity( type );
645  QModelIndex i = index( offset + mEntityNames[ type ].indexOf( name ), Tags );
646  emit dataChanged( i, i, QVector< int >() << Qt::DecorationRole );
647 }
648 
649 void QgsStyleModel::onEntityRename( QgsStyle::StyleEntity type, const QString &oldName, const QString &newName )
650 {
651  mIconCache[ type ].remove( oldName );
652  const QStringList oldSymbolNames = mEntityNames[ type ];
653  const QStringList newSymbolNames = mStyle->allNames( type );
654 
655  // find index of removed symbol
656  const int oldNameIndex = oldSymbolNames.indexOf( oldName );
657  if ( oldNameIndex < 0 )
658  return; // shouldn't happen
659 
660  // find index of added symbol
661  const int newNameIndex = newSymbolNames.indexOf( newName );
662  if ( newNameIndex < 0 )
663  return; // shouldn't happen
664 
665  if ( newNameIndex == oldNameIndex )
666  {
667  mEntityNames[ type ] = newSymbolNames;
668  return;
669  }
670 
671  const int offset = offsetForEntity( type );
672  beginMoveRows( QModelIndex(), oldNameIndex + offset, oldNameIndex + offset, QModelIndex(), ( newNameIndex > oldNameIndex ? newNameIndex + 1 : newNameIndex ) + offset );
673  mEntityNames[ type ] = newSymbolNames;
674  endMoveRows();
675 }
676 
677 void QgsStyleModel::onTagsChanged( int entity, const QString &name, const QStringList & )
678 {
679  QgsStyle::StyleEntity type = static_cast< QgsStyle::StyleEntity >( entity );
680  QModelIndex i;
681  int row = mEntityNames[type].indexOf( name ) + offsetForEntity( type );
682  switch ( static_cast< QgsStyle::StyleEntity >( entity ) )
683  {
684  case QgsStyle::TagEntity:
686  return;
687 
688  default:
689  i = index( row, Tags );
690  }
691  emit dataChanged( i, i );
692 }
693 
694 void QgsStyleModel::rebuildSymbolIcons()
695 {
696  mIconCache[ QgsStyle::SymbolEntity ].clear();
697  mExpressionContext.reset();
698  emit dataChanged( index( 0, 0 ), index( mEntityNames[ QgsStyle::SymbolEntity ].count() - 1, 0 ), QVector<int>() << Qt::DecorationRole );
699 }
700 
701 void QgsStyleModel::iconGenerated( QgsStyle::StyleEntity type, const QString &name, const QIcon &icon )
702 {
703  int row = mEntityNames[type].indexOf( name ) + offsetForEntity( type );
704 
705  switch ( type )
706  {
708  mPending3dSymbolIcons.remove( name );
709  mIconCache[ QgsStyle::Symbol3DEntity ].insert( name, icon );
710  emit dataChanged( index( row, 0 ), index( row, 0 ) );
711  break;
712 
714  case QgsStyle::TagEntity:
720  break;
721  }
722 }
723 
724 QgsStyle::StyleEntity QgsStyleModel::entityTypeFromRow( int row ) const
725 {
726  int maxRowForEntity = 0;
727  for ( QgsStyle::StyleEntity type : ENTITIES )
728  {
729  maxRowForEntity += mEntityNames[ type ].size();
730  if ( row < maxRowForEntity )
731  return type;
732  }
733 
734  // should never happen
735  Q_ASSERT( false );
736  return QgsStyle::SymbolEntity;
737 }
738 
739 int QgsStyleModel::offsetForEntity( QgsStyle::StyleEntity entity ) const
740 {
741  int offset = 0;
742  for ( QgsStyle::StyleEntity type : ENTITIES )
743  {
744  if ( type == entity )
745  return offset;
746 
747  offset += mEntityNames[ type ].size();
748  }
749  return 0;
750 }
751 
752 //
753 // QgsStyleProxyModel
754 //
755 
757  : QSortFilterProxyModel( parent )
758  , mStyle( style )
759 {
760  mModel = new QgsStyleModel( mStyle, this );
761  initialize();
762 }
763 
764 void QgsStyleProxyModel::initialize()
765 {
766  setSortCaseSensitivity( Qt::CaseInsensitive );
767 // setSortLocaleAware( true );
768  setSourceModel( mModel );
769  setDynamicSortFilter( true );
770  sort( 0 );
771 
772  connect( mStyle, &QgsStyle::entityTagsChanged, this, [ = ]
773  {
774  // update tagged symbols if filtering by tag
775  if ( mTagId >= 0 )
776  setTagId( mTagId );
777  if ( mSmartGroupId >= 0 )
778  setSmartGroupId( mSmartGroupId );
779  } );
780 
781  connect( mStyle, &QgsStyle::favoritedChanged, this, [ = ]
782  {
783  // update favorited symbols if filtering by favorite
784  if ( mFavoritesOnly )
785  setFavoritesOnly( mFavoritesOnly );
786  } );
787 
788  connect( mStyle, &QgsStyle::entityRenamed, this, [ = ]( QgsStyle::StyleEntity entity, const QString &, const QString & )
789  {
790  switch ( entity )
791  {
793  case QgsStyle::TagEntity:
794  return;
795 
796  default:
797  break;
798  }
799 
800  if ( mSmartGroupId >= 0 )
801  setSmartGroupId( mSmartGroupId );
802  } );
803 }
804 
806  : QSortFilterProxyModel( parent )
807  , mModel( model )
808  , mStyle( model->style() )
809 {
810  initialize();
811 }
812 
813 bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
814 {
815  if ( mFilterString.isEmpty() && !mEntityFilterEnabled && !mSymbolTypeFilterEnabled && mTagId < 0 && mSmartGroupId < 0 && !mFavoritesOnly )
816  return true;
817 
818  QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
819  const QString name = sourceModel()->data( index ).toString();
820  const QStringList tags = sourceModel()->data( index, QgsStyleModel::TagRole ).toStringList();
821 
822  QgsStyle::StyleEntity styleEntityType = static_cast< QgsStyle::StyleEntity >( sourceModel()->data( index, QgsStyleModel::TypeRole ).toInt() );
823  if ( mEntityFilterEnabled && ( mEntityFilters.empty() || !mEntityFilters.contains( styleEntityType ) ) )
824  return false;
825 
826  QgsSymbol::SymbolType symbolType = static_cast< QgsSymbol::SymbolType >( sourceModel()->data( index, QgsStyleModel::SymbolTypeRole ).toInt() );
827  if ( mSymbolTypeFilterEnabled && symbolType != mSymbolType )
828  return false;
829 
830  if ( mLayerType != QgsWkbTypes::UnknownGeometry )
831  {
832  switch ( styleEntityType )
833  {
836  case QgsStyle::TagEntity:
840  break;
841 
843  {
844  if ( mLayerType != static_cast< QgsWkbTypes::GeometryType >( sourceModel()->data( index, QgsStyleModel::LayerTypeRole ).toInt() ) )
845  return false;
846  break;
847  }
848 
850  {
851  const QVariantList types = sourceModel()->data( index, QgsStyleModel::CompatibleGeometryTypesRole ).toList();
852  if ( !types.empty() && !types.contains( mLayerType ) )
853  return false;
854  break;
855  }
856  }
857  }
858 
859  if ( mTagId >= 0 && !mTaggedSymbolNames.contains( name ) )
860  return false;
861 
862  if ( mSmartGroupId >= 0 && !mSmartGroupSymbolNames.contains( name ) )
863  return false;
864 
865  if ( mFavoritesOnly && !sourceModel()->data( index, QgsStyleModel::IsFavoriteRole ).toBool() )
866  return false;
867 
868  if ( !mFilterString.isEmpty() )
869  {
870  // filter by word, in both filter string and style entity name/tags
871  // this allows matching of a filter string "hash line" to the symbol "hashed red lines"
872  const QStringList partsToMatch = mFilterString.trimmed().split( ' ' );
873 
874  QStringList partsToSearch = name.split( ' ' );
875  for ( const QString &tag : tags )
876  {
877  partsToSearch.append( tag.split( ' ' ) );
878  }
879 
880  for ( const QString &part : partsToMatch )
881  {
882  bool found = false;
883  for ( const QString &partToSearch : qgis::as_const( partsToSearch ) )
884  {
885  if ( partToSearch.contains( part, Qt::CaseInsensitive ) )
886  {
887  found = true;
888  break;
889  }
890  }
891  if ( !found )
892  return false; // couldn't find a match for this word, so hide entity
893  }
894  }
895 
896  return true;
897 }
898 
899 void QgsStyleProxyModel::setFilterString( const QString &filter )
900 {
901  mFilterString = filter;
902  invalidateFilter();
903 }
904 
905 
907 {
908  return mFavoritesOnly;
909 }
910 
911 void QgsStyleProxyModel::setFavoritesOnly( bool favoritesOnly )
912 {
913  mFavoritesOnly = favoritesOnly;
914  invalidateFilter();
915 }
916 
918 {
919  mModel->addDesiredIconSize( size );
920 }
921 
923 {
924  return mSymbolTypeFilterEnabled;
925 }
926 
927 void QgsStyleProxyModel::setSymbolTypeFilterEnabled( bool symbolTypeFilterEnabled )
928 {
929  mSymbolTypeFilterEnabled = symbolTypeFilterEnabled;
930  invalidateFilter();
931 }
932 
934 {
935  return mLayerType;
936 }
937 
939 {
940  mLayerType = type;
941  invalidateFilter();
942 }
943 
945 {
946  mTagId = id;
947 
948  mTaggedSymbolNames.clear();
949  if ( mTagId >= 0 )
950  {
951  for ( QgsStyle::StyleEntity entity : ENTITIES )
952  mTaggedSymbolNames.append( mStyle->symbolsWithTag( entity, mTagId ) );
953  }
954 
955  invalidateFilter();
956 }
957 
959 {
960  return mTagId;
961 }
962 
964 {
965  mSmartGroupId = id;
966 
967  mSmartGroupSymbolNames.clear();
968  if ( mSmartGroupId >= 0 )
969  {
970  for ( QgsStyle::StyleEntity entity : ENTITIES )
971  mSmartGroupSymbolNames.append( mStyle->symbolsOfSmartgroup( entity, mSmartGroupId ) );
972  }
973  invalidateFilter();
974 }
975 
977 {
978  return mSmartGroupId;
979 }
980 
982 {
983  return mSymbolType;
984 }
985 
987 {
988  mSymbolType = symbolType;
989  invalidateFilter();
990 }
991 
993 {
994  return mEntityFilterEnabled;
995 }
996 
997 void QgsStyleProxyModel::setEntityFilterEnabled( bool entityFilterEnabled )
998 {
999  mEntityFilterEnabled = entityFilterEnabled;
1000  invalidateFilter();
1001 }
1002 
1004 {
1005  return mEntityFilters.empty() ? QgsStyle::SymbolEntity : mEntityFilters.at( 0 );
1006 }
1007 
1009 {
1010  mEntityFilters = QList< QgsStyle::StyleEntity >() << entityFilter;
1011  invalidateFilter();
1012 }
1013 
1014 void QgsStyleProxyModel::setEntityFilters( const QList<QgsStyle::StyleEntity> &filters )
1015 {
1016  mEntityFilters = filters;
1017  invalidateFilter();
1018 }
1019 
qgsexpressioncontextutils.h
QgsStyle::favoritedChanged
void favoritedChanged(QgsStyle::StyleEntity entity, const QString &name, bool isFavorite)
Emitted whenever an entity is either favorited or un-favorited.
qgssvgcache.h
QgsStyleProxyModel::setEntityFilters
void setEntityFilters(const QList< QgsStyle::StyleEntity > &filters)
Sets the style entity type filters.
Definition: qgsstylemodel.cpp:1014
QgsStyle::ColorrampEntity
@ ColorrampEntity
Color ramps.
Definition: qgsstyle.h:182
QgsStyle::entityAdded
void entityAdded(QgsStyle::StyleEntity entity, const QString &name)
Emitted every time a new entity has been added to the database.
QgsStyleModel
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
Definition: qgsstylemodel.h:108
QgsStyle::labelSettingsLayerType
QgsWkbTypes::GeometryType labelSettingsLayerType(const QString &name) const
Returns the layer geometry type corresponding to the label settings with the specified name,...
Definition: qgsstyle.cpp:2162
QgsStyle::textFormat
QgsTextFormat textFormat(const QString &name) const
Returns the text format with the specified name.
Definition: qgsstyle.cpp:2101
QgsPalLayerSettings
Definition: qgspallabeling.h:207
QgsAbstractStyleEntityIconGenerator::iconSizes
QList< QSize > iconSizes() const
Returns the list of icon sizes to generate.
Definition: qgsstylemodel.cpp:47
QgsStyleModel::IsFavoriteRole
@ IsFavoriteRole
Whether entity is flagged as a favorite.
Definition: qgsstylemodel.h:126
qgssymbollayerutils.h
QgsStyleProxyModel::setEntityFilterEnabled
void setEntityFilterEnabled(bool enabled)
Sets whether filtering by entity type is enabled.
Definition: qgsstylemodel.cpp:997
QgsStyleModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: qgsstylemodel.cpp:551
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:468
QgsStyleProxyModel::setFilterString
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
Definition: qgsstylemodel.cpp:899
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:307
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsStyle::LegendPatchShapeEntity
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
Definition: qgsstyle.h:186
QgsStyle::renameEntity
bool renameEntity(StyleEntity type, const QString &oldName, const QString &newName)
Renames an entity of the specified type from oldName to newName.
Definition: qgsstyle.cpp:240
QgsStyle::entityRemoved
void entityRemoved(QgsStyle::StyleEntity entity, const QString &name)
Emitted whenever an entity of the specified type is removed from the style and the database has been ...
QgsStyleModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
Definition: qgsstylemodel.cpp:476
QgsStyle::symbol
QgsSymbol * symbol(const QString &name)
Returns a NEW copy of symbol.
Definition: qgsstyle.cpp:269
QgsStyleProxyModel::setSmartGroupId
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
Definition: qgsstylemodel.cpp:963
QgsLegendPatchShape
Represents a patch shape for use in map legends.
Definition: qgslegendpatchshape.h:31
QgsStyle::SymbolEntity
@ SymbolEntity
Symbols.
Definition: qgsstyle.h:180
QgsSymbolLayerUtils::colorRampPreviewPixmap
static QPixmap colorRampPreviewPixmap(QgsColorRamp *ramp, QSize size, int padding=0)
Returns a pixmap preview for a color ramp.
Definition: qgssymbollayerutils.cpp:877
QgsStyle::TagEntity
@ TagEntity
Tags.
Definition: qgsstyle.h:181
QgsStyle::LabelSettingsEntity
@ LabelSettingsEntity
Label settings.
Definition: qgsstyle.h:185
qgsapplication.h
QgsStyle::symbol3DCompatibleGeometryTypes
QList< QgsWkbTypes::GeometryType > symbol3DCompatibleGeometryTypes(const QString &name) const
Returns the list of the vector layer geometry types which are compatible with the 3D symbol with the ...
Definition: qgsstyle.cpp:2154
QgsStyleModel::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: qgsstylemodel.cpp:509
QgsStyleModel::TypeRole
@ TypeRole
Style entity type, see QgsStyle::StyleEntity.
Definition: qgsstylemodel.h:123
QgsStyleModel::headerData
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Definition: qgsstylemodel.cpp:522
QgsPalLayerSettings::labelSettingsPreviewPixmap
static QPixmap labelSettingsPreviewPixmap(const QgsPalLayerSettings &settings, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for label settings.
Definition: qgspallabeling.cpp:1256
QgsAbstractStyleEntityIconGenerator::setIconSizes
void setIconSizes(const QList< QSize > &sizes)
Sets the list of icon sizes to generate.
Definition: qgsstylemodel.cpp:42
QgsStyle::symbolsOfSmartgroup
QStringList symbolsOfSmartgroup(StyleEntity type, int id)
Returns the symbols for the smartgroup.
Definition: qgsstyle.cpp:2351
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsStyleProxyModel::symbolType
QgsSymbol::SymbolType symbolType() const
Returns the symbol type filter.
Definition: qgsstylemodel.cpp:981
QgsStyleModel::Tags
@ Tags
Tags column.
Definition: qgsstylemodel.h:117
QgsSymbolLayerUtils::symbolPreviewPixmap
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr)
Returns a pixmap preview for a color ramp.
Definition: qgssymbollayerutils.cpp:767
QgsStyleModel::setIconGenerator
static void setIconGenerator(QgsAbstractStyleEntityIconGenerator *generator)
Sets the icon generator to use for deferred style entity icon generation.
Definition: qgsstylemodel.cpp:600
QgsStyle::Symbol3DEntity
@ Symbol3DEntity
3D symbol entity (since QGIS 3.14)
Definition: qgsstyle.h:187
QgsStyleModel::TagRole
@ TagRole
String list of tags.
Definition: qgsstylemodel.h:124
QgsStyleProxyModel::layerType
QgsWkbTypes::GeometryType layerType() const
Returns the layer type filter, or QgsWkbTypes::UnknownGeometry if no layer type filter is present.
Definition: qgsstylemodel.cpp:933
QgsStyle::entityTagsChanged
void entityTagsChanged(QgsStyle::StyleEntity entity, const QString &name, const QStringList &newTags)
Emitted whenever an entity's tags are changed.
QgsApplication::defaultStyleModel
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
Definition: qgsapplication.cpp:2243
QgsProject::projectColorsChanged
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QgsStyleProxyModel::favoritesOnly
bool favoritesOnly() const
Returns true if the model is showing only favorited entities.
Definition: qgsstylemodel.cpp:906
QgsStyle::previewSymbolForPatchShape
const QgsSymbol * previewSymbolForPatchShape(const QgsLegendPatchShape &shape) const
Returns a symbol to use for rendering preview icons for a patch shape.
Definition: qgsstyle.cpp:2190
QgsApplication::imageCache
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
Definition: qgsapplication.cpp:2183
QgsAbstractStyleEntityIconGenerator::QgsAbstractStyleEntityIconGenerator
QgsAbstractStyleEntityIconGenerator(QObject *parent)
Constructor for QgsAbstractStyleEntityIconGenerator, with the specified parent object.
Definition: qgsstylemodel.cpp:36
QgsStyle::SmartgroupEntity
@ SmartgroupEntity
Smart groups.
Definition: qgsstyle.h:183
Qgis::UI_SCALE_FACTOR
static const double UI_SCALE_FACTOR
UI scaling factor.
Definition: qgis.h:182
QgsStyleModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsstylemodel.cpp:582
qgsstylemodel.h
QgsStyleModel::CompatibleGeometryTypesRole
@ CompatibleGeometryTypesRole
Compatible layer geometry types (for 3D symbols)
Definition: qgsstylemodel.h:128
QgsTextFormat::textFormatPreviewPixmap
static QPixmap textFormatPreviewPixmap(const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for a text format.
Definition: qgstextformat.cpp:911
QgsStyle::entityChanged
void entityChanged(QgsStyle::StyleEntity entity, const QString &name)
Emitted whenever an entity's definition is changed.
QgsApplication::svgCache
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
Definition: qgsapplication.cpp:2178
QgsStyleProxyModel::setLayerType
void setLayerType(QgsWkbTypes::GeometryType type)
Sets the layer type filter.
Definition: qgsstylemodel.cpp:938
qgsstyle.h
QgsStyleProxyModel::setEntityFilter
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
Definition: qgsstylemodel.cpp:1008
QgsStyleModel::SymbolTypeRole
@ SymbolTypeRole
Symbol type (for symbol or legend patch shape entities)
Definition: qgsstylemodel.h:125
QgsStyle::allNames
QStringList allNames(StyleEntity type) const
Returns a list of the names of all existing entities of the specified type.
Definition: qgsstyle.cpp:2219
QgsAbstractStyleEntityIconGenerator::generateIcon
virtual void generateIcon(QgsStyle *style, QgsStyle::StyleEntity type, const QString &name)=0
Triggers generation of an icon for an entity from the specified style database, with matching entity ...
QgsStyleProxyModel::setSymbolType
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
Definition: qgsstylemodel.cpp:986
QgsStyle::legendPatchShape
QgsLegendPatchShape legendPatchShape(const QString &name) const
Returns the legend patch shape with the specified name.
Definition: qgsstyle.cpp:2126
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsStyleProxyModel::symbolTypeFilterEnabled
bool symbolTypeFilterEnabled() const
Returns true if filtering by symbol type is enabled.
Definition: qgsstylemodel.cpp:922
QgsStyleModel::LayerTypeRole
@ LayerTypeRole
Layer type (for label settings entities)
Definition: qgsstylemodel.h:127
QgsStyleProxyModel::filterAcceptsRow
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Definition: qgsstylemodel.cpp:813
QgsAbstractStyleEntityIconGenerator::iconGenerated
void iconGenerated(QgsStyle::StyleEntity type, const QString &name, const QIcon &icon)
Emitted when the icon for the style entity with matching type and name has been generated.
QgsStyle
Definition: qgsstyle.h:160
QgsStyle::TextFormatEntity
@ TextFormatEntity
Text formats.
Definition: qgsstyle.h:184
qgsimagecache.h
QgsStyleProxyModel::entityFilterEnabled
bool entityFilterEnabled() const
Returns true if filtering by entity type is enabled.
Definition: qgsstylemodel.cpp:992
QgsStyleProxyModel::addDesiredIconSize
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
Definition: qgsstylemodel.cpp:917
QgsStyleProxyModel::setSymbolTypeFilterEnabled
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
Definition: qgsstylemodel.cpp:927
QgsStyleProxyModel::setFavoritesOnly
void setFavoritesOnly(bool favoritesOnly)
Sets whether the model should show only favorited entities.
Definition: qgsstylemodel.cpp:911
QgsStyleProxyModel::smartGroupId
int smartGroupId() const
Returns the smart group id used to filter style entities by.
Definition: qgsstylemodel.cpp:976
QgsStyleProxyModel::tagId
int tagId() const
Returns the tag id used to filter style entities by.
Definition: qgsstylemodel.cpp:958
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsStyleProxyModel::QgsStyleProxyModel
QgsStyleProxyModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleProxyModel, for the specified style and parent object.
Definition: qgsstylemodel.cpp:756
QgsStyleModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgsstylemodel.cpp:90
QgsSymbol::type
SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:122
QgsStyleModel::addDesiredIconSize
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
Definition: qgsstylemodel.cpp:587
QgsAbstractStyleEntityIconGenerator
An abstract base class for icon generators for a QgsStyleModel.
Definition: qgsstylemodel.h:45
QgsStyleProxyModel::setTagId
void setTagId(int id)
Sets a tag id to filter style entities by.
Definition: qgsstylemodel.cpp:944
QgsStyle::entityRenamed
void entityRenamed(QgsStyle::StyleEntity entity, const QString &oldName, const QString &newName)
Emitted whenever a entity of the specified type has been renamed from oldName to newName.
ICON_PADDING_FACTOR
const double ICON_PADDING_FACTOR
Definition: qgsstylemodel.cpp:26
QgsStyle::legendPatchShapeSymbolType
QgsSymbol::SymbolType legendPatchShapeSymbolType(const QString &name) const
Returns the symbol type corresponding to the legend patch shape with the specified name,...
Definition: qgsstyle.cpp:2136
QgsSymbol::SymbolType
SymbolType
Type of the symbol.
Definition: qgssymbol.h:86
QgsImageCache::remoteImageFetched
void remoteImageFetched(const QString &url)
Emitted when the cache has finished retrieving an image file from a remote url.
QgsStyle::tagsOfSymbol
QStringList tagsOfSymbol(StyleEntity type, const QString &symbol)
Returns the tags associated with the symbol.
Definition: qgsstyle.cpp:1892
QgsStyleModel::parent
QModelIndex parent(const QModelIndex &index) const override
Definition: qgsstylemodel.cpp:564
QgsStyle::isFavorite
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:1943
QgsStyle::symbolsWithTag
QStringList symbolsWithTag(StyleEntity type, int tagid) const
Returns the symbol names with which have the given tag.
Definition: qgsstyle.cpp:1316
QgsStyle::labelSettings
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
Definition: qgsstyle.cpp:2121
QgsStyle::symbolRef
const QgsSymbol * symbolRef(const QString &name) const
Returns a const pointer to a symbol (doesn't create new instance)
Definition: qgsstyle.cpp:275
QgsApplication::defaultThemePath
static QString defaultThemePath()
Returns the path to the default theme directory.
Definition: qgsapplication.cpp:586
QgsStyleProxyModel::entityFilter
QgsStyle::StyleEntity entityFilter() const
Returns the style entity type filter.
Definition: qgsstylemodel.cpp:1003
ENTITIES
const auto ENTITIES
Definition: qgsstylemodel.cpp:28
qgsproject.h
QgsStyle::colorRamp
QgsColorRamp * colorRamp(const QString &name) const
Returns a new copy of the specified color ramp.
Definition: qgsstyle.cpp:438
QgsStyleModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Definition: qgsstylemodel.cpp:570
QgsStyleModel::Name
@ Name
Name column.
Definition: qgsstylemodel.h:116
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:179
QgsStyleModel::QgsStyleModel
QgsStyleModel(QgsStyle *style, QObject *parent=nullptr)
Constructor for QgsStyleModel, for the specified style and parent object.
Definition: qgsstylemodel.cpp:57
QgsSvgCache::remoteSvgFetched
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
QgsLegendPatchShape::isNull
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
Definition: qgslegendpatchshape.cpp:32