31 QgsReadOnlyStyleModel::QgsReadOnlyStyleModel( 
QgsStyleModel *sourceModel, QObject *parent )
 
   37 QgsReadOnlyStyleModel::QgsReadOnlyStyleModel( 
QgsStyle *style, QObject *parent )
 
   43 Qt::ItemFlags QgsReadOnlyStyleModel::flags( 
const QModelIndex &index )
 const 
   45   return QgsStyleProxyModel::flags( index ) & ~Qt::ItemIsEditable;
 
   48 QVariant QgsReadOnlyStyleModel::data( 
const QModelIndex &index, 
int role )
 const 
   50   if ( role == Qt::FontRole )
 
   53     QFont f = QgsStyleProxyModel::data( index, role ).value< QFont >();
 
   57   return QgsStyleProxyModel::data( index, role );
 
   73   btnAdvanced->setMenu( 
new QMenu( 
this ) );
 
   76   viewSymbols->setIconSize( QSize( 
static_cast< int >( 
iconSize ), 
static_cast< int >( 
iconSize * 0.9 ) ) );  
 
   79   mSymbolTreeView->setIconSize( QSize( 
static_cast< int >( treeIconSize ), 
static_cast< int >( treeIconSize ) ) );
 
   80   mSymbolTreeView->setMinimumHeight( mSymbolTreeView->fontMetrics().height() * 6 );
 
   82   viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
 
   83   mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
 
   85   connect( openStyleManagerButton, &QToolButton::clicked, 
this, &QgsStyleItemsListWidget::openStyleManager );
 
   87   lblSymbolName->clear();
 
   89   connect( mButtonIconView, &QToolButton::toggled, 
this, [ = ]( 
bool active )
 
   93       mSymbolViewStackedWidget->setCurrentIndex( 0 );
 
   98   connect( mButtonListView, &QToolButton::toggled, 
this, [ = ]( 
bool active )
 
  103       mSymbolViewStackedWidget->setCurrentIndex( 1 );
 
  109   const int currentView = settings.
value( QStringLiteral( 
"UI/symbolsList/lastIconView" ), 0, 
QgsSettings::Gui ).toInt();
 
  110   if ( currentView == 0 )
 
  111     mButtonIconView->setChecked( 
true );
 
  113     mButtonListView->setChecked( 
true );
 
  115   mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( 
"UI/symbolsList/treeState" ), QByteArray(), 
QgsSettings::Gui ).toByteArray() );
 
  116   connect( mSymbolTreeView->header(), &QHeaderView::sectionResized, 
this, [
this]
 
  119     QgsSettings().setValue( QStringLiteral( 
"UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
 
  125   groupEdit->setPlaceholderText( tr( 
"Filter symbols…" ) );
 
  126   groupsCombo->setLineEdit( groupEdit );
 
  136            : 
new QgsReadOnlyStyleModel( mStyle, 
this );
 
  142   viewSymbols->setGridSize( QSize( 
static_cast< int >( viewSymbols->iconSize().width() * 1.4 ), 
static_cast< int >( viewSymbols->iconSize().height() * 1.7 ) ) );
 
  143   viewSymbols->setTextElideMode( Qt::TextElideMode::ElideRight );
 
  145   viewSymbols->setModel( mModel );
 
  146   mSymbolTreeView->setModel( mModel );
 
  150   mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
 
  151   connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, 
this, &QgsStyleItemsListWidget::onSelectionChanged );
 
  154   connect( groupsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
 
  155   connect( groupsCombo, &QComboBox::currentTextChanged, 
this, &QgsStyleItemsListWidget::updateModelFilters );
 
  158   mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral( 
"UI/symbolsList/treeState" ), QByteArray(), 
QgsSettings::Gui ).toByteArray() );
 
  165   const int allGroup = groupsCombo->findData( QVariant( 
"all" ) );
 
  169       btnSaveSymbol->setText( tr( 
"Save Symbol…" ) );
 
  170       btnSaveSymbol->setToolTip( tr( 
"Save symbol to styles" ) );
 
  172         groupsCombo->setItemText( allGroup, tr( 
"All Symbols" ) );
 
  176       btnSaveSymbol->setText( tr( 
"Save Color Ramp…" ) );
 
  177       btnSaveSymbol->setToolTip( tr( 
"Save color ramp to styles" ) );
 
  179         groupsCombo->setItemText( allGroup, tr( 
"All Color Ramps" ) );
 
  183       btnSaveSymbol->setText( tr( 
"Save Format…" ) );
 
  184       btnSaveSymbol->setToolTip( tr( 
"Save text format to styles" ) );
 
  186         groupsCombo->setItemText( allGroup, tr( 
"All Text Formats" ) );
 
  190       btnSaveSymbol->setText( tr( 
"Save Label Settings…" ) );
 
  191       btnSaveSymbol->setToolTip( tr( 
"Save label settings to styles" ) );
 
  193         groupsCombo->setItemText( allGroup, tr( 
"All Label Settings" ) );
 
  197       btnSaveSymbol->setText( tr( 
"Save Legend Patch Shape…" ) );
 
  198       btnSaveSymbol->setToolTip( tr( 
"Save legend patch shape to styles" ) );
 
  200         groupsCombo->setItemText( allGroup, tr( 
"All Legend Patch Shapes" ) );
 
  204       btnSaveSymbol->setText( tr( 
"Save 3D Symbol…" ) );
 
  205       btnSaveSymbol->setToolTip( tr( 
"Save 3D symbol to styles" ) );
 
  207         groupsCombo->setItemText( allGroup, tr( 
"All 3D Symbols" ) );
 
  222   const int allGroup = groupsCombo->findData( QVariant( 
"all" ) );
 
  225     btnSaveSymbol->setText( tr( 
"Save Settings…" ) );
 
  226     btnSaveSymbol->setToolTip( tr( 
"Save label settings or text format to styles" ) );
 
  228       groupsCombo->setItemText( allGroup, tr( 
"All Settings" ) );
 
  245   return groupsCombo->currentData().toString() == QLatin1String( 
"tag" ) ? groupsCombo->currentText() : QString();
 
  250   return btnAdvanced->menu();
 
  258     btnAdvanced->setMenu( menu );
 
  264   btnAdvanced->setVisible( enabled );
 
  269   const QItemSelection selection = viewSymbols->selectionModel()->selection();
 
  270   if ( selection.isEmpty() )
 
  273   const QModelIndex index = selection.at( 0 ).topLeft();
 
  280   const QItemSelection selection = viewSymbols->selectionModel()->selection();
 
  281   if ( selection.isEmpty() )
 
  284   const QModelIndex index = selection.at( 0 ).topLeft();
 
  295   QWidget::showEvent( event );
 
  297   mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral( 
"UI/symbolsList/treeState" ), QByteArray(), 
QgsSettings::Gui ).toByteArray() );
 
  300 void QgsStyleItemsListWidget::populateGroups()
 
  305   mUpdatingGroups = 
true;
 
  306   groupsCombo->blockSignals( 
true );
 
  307   groupsCombo->clear();
 
  309   groupsCombo->addItem( tr( 
"Favorites" ), QVariant( 
"favorite" ) );
 
  311   QString allText = tr( 
"All Symbols" );
 
  317         allText = tr( 
"All Symbols" );
 
  321         allText = tr( 
"All Color Ramps" );
 
  325         allText = tr( 
"All Text Formats" );
 
  329         allText = tr( 
"All Label Settings" );
 
  333         allText = tr( 
"All Legend Patch Shapes" );
 
  337         allText = tr( 
"All 3D Symbols" );
 
  346   groupsCombo->addItem( allText, QVariant( 
"all" ) );
 
  349   QStringList tags = mStyle->
tags();
 
  350   if ( tags.count() > 0 )
 
  353     groupsCombo->insertSeparator( index );
 
  354     const auto constTags = tags;
 
  355     for ( 
const QString &tag : constTags )
 
  357       groupsCombo->addItem( tag, QVariant( 
"tag" ) );
 
  363   if ( groups.count() > 0 )
 
  366     groupsCombo->insertSeparator( index + 1 );
 
  367     const auto constGroups = groups;
 
  368     for ( 
const QString &group : constGroups )
 
  370       groupsCombo->addItem( group, QVariant( 
"smartgroup" ) );
 
  373   groupsCombo->blockSignals( 
false );
 
  376   index = settings.
value( QStringLiteral( 
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
 
  377   groupsCombo->setCurrentIndex( index );
 
  379   mUpdatingGroups = 
false;
 
  381   updateModelFilters();
 
  384 void QgsStyleItemsListWidget::updateModelFilters()
 
  386   if ( mUpdatingGroups || !mModel )
 
  389   const QString text = groupsCombo->currentText();
 
  390   const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
 
  399   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"favorite" ) )
 
  406   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"all" ) )
 
  413   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"smartgroup" ) )
 
  429 void QgsStyleItemsListWidget::openStyleManager()
 
  445     updateModelFilters(); 
 
  449 void QgsStyleItemsListWidget::onSelectionChanged( 
const QModelIndex &index )
 
  454   const QString symbolName = mModel->data( mModel->index( index.row(), 
QgsStyleModel::Name ) ).toString();
 
  455   lblSymbolName->setText( symbolName );
 
  460 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged( 
int index )
 
  463   settings.
setValue( QStringLiteral( 
"qgis/symbolsListGroupsIndex" ), index );
 
static const double UI_SCALE_FACTOR
UI scaling factor.
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setShowSearchIcon(bool visible)
Define if a search icon shall be shown on the left of the image when no text is entered.
void setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
A dialog allowing users to customize and populate a QgsStyle.
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
@ TypeRole
Style entity type, see QgsStyle::StyleEntity.
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
void setTagId(int id)
Sets a tag id to filter style entities by.
QgsStyle::StyleEntity entityFilter() const
Returns the style entity type filter.
void setEntityFilters(const QList< QgsStyle::StyleEntity > &filters)
Sets the style entity type filters.
void setFavoritesOnly(bool favoritesOnly)
Sets whether the model should show only favorited entities.
void setLayerType(QgsWkbTypes::GeometryType type)
Sets the layer type filter.
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type filter.
bool entityFilterEnabled() const
Returns true if filtering by entity type is enabled.
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
void setEntityFilterEnabled(bool enabled)
Sets whether filtering by entity type is enabled.
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
QStringList tags() const
Returns a list of all tags in the style database.
StyleEntity
Enum for Entities involved in a style.
@ LabelSettingsEntity
Label settings.
@ TextFormatEntity
Text formats.
@ SmartgroupEntity
Smart groups.
@ Symbol3DEntity
3D symbol entity (since QGIS 3.14)
@ ColorrampEntity
Color ramps.
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
void groupsModified()
Emitted every time a tag or smartgroup has been added, removed, or renamed.
int smartgroupId(const QString &smartgroup)
Returns the database id for the given smartgroup name.
static QgsStyle * defaultStyle()
Returns default application-wide style.
int tagId(const QString &tag)
Returns the database id for the given tag name.
QStringList smartgroupNames() const
Returns the smart groups list.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.