21 #include "qgssettings.h" 
   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 );
 
   95       QgsSettings().setValue( QStringLiteral( 
"UI/symbolsList/lastIconView" ), 0, QgsSettings::Gui );
 
   98   connect( mButtonListView, &QToolButton::toggled, 
this, [ = ]( 
bool active )
 
  102       QgsSettings().setValue( QStringLiteral( 
"UI/symbolsList/lastIconView" ), 1, QgsSettings::Gui );
 
  103       mSymbolViewStackedWidget->setCurrentIndex( 1 );
 
  108   QgsSettings settings;
 
  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 );
 
  140   viewSymbols->setModel( mModel );
 
  141   mSymbolTreeView->setModel( mModel );
 
  145   mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
 
  146   connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged, 
this, &QgsStyleItemsListWidget::onSelectionChanged );
 
  149   connect( groupsCombo, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
 
  150   connect( groupsCombo, &QComboBox::currentTextChanged, 
this, &QgsStyleItemsListWidget::updateModelFilters );
 
  152   QgsSettings settings;
 
  153   mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( 
"UI/symbolsList/treeState" ), QByteArray(), QgsSettings::Gui ).toByteArray() );
 
  160   const int allGroup = groupsCombo->findData( QVariant( 
"all" ) );
 
  164       btnSaveSymbol->setText( tr( 
"Save Symbol…" ) );
 
  165       btnSaveSymbol->setToolTip( tr( 
"Save symbol to styles" ) );
 
  167         groupsCombo->setItemText( allGroup, tr( 
"All Symbols" ) );
 
  171       btnSaveSymbol->setText( tr( 
"Save Color Ramp…" ) );
 
  172       btnSaveSymbol->setToolTip( tr( 
"Save color ramp to styles" ) );
 
  174         groupsCombo->setItemText( allGroup, tr( 
"All Color Ramps" ) );
 
  178       btnSaveSymbol->setText( tr( 
"Save Format…" ) );
 
  179       btnSaveSymbol->setToolTip( tr( 
"Save text format to styles" ) );
 
  181         groupsCombo->setItemText( allGroup, tr( 
"All Text Formats" ) );
 
  185       btnSaveSymbol->setText( tr( 
"Save Label Settings…" ) );
 
  186       btnSaveSymbol->setToolTip( tr( 
"Save label settings to styles" ) );
 
  188         groupsCombo->setItemText( allGroup, tr( 
"All Label Settings" ) );
 
  192       btnSaveSymbol->setText( tr( 
"Save Legend Patch Shape…" ) );
 
  193       btnSaveSymbol->setToolTip( tr( 
"Save legend patch shape to styles" ) );
 
  195         groupsCombo->setItemText( allGroup, tr( 
"All Legend Patch Shapes" ) );
 
  199       btnSaveSymbol->setText( tr( 
"Save 3D Symbol…" ) );
 
  200       btnSaveSymbol->setToolTip( tr( 
"Save 3D symbol to styles" ) );
 
  202         groupsCombo->setItemText( allGroup, tr( 
"All 3D Symbols" ) );
 
  217   const int allGroup = groupsCombo->findData( QVariant( 
"all" ) );
 
  220     btnSaveSymbol->setText( tr( 
"Save Settings…" ) );
 
  221     btnSaveSymbol->setToolTip( tr( 
"Save label settings or text format to styles" ) );
 
  223       groupsCombo->setItemText( allGroup, tr( 
"All Settings" ) );
 
  240   return groupsCombo->currentData().toString() == QLatin1String( 
"tag" ) ? groupsCombo->currentText() : QString();
 
  245   return btnAdvanced->menu();
 
  253     btnAdvanced->setMenu( menu );
 
  259   btnAdvanced->setVisible( enabled );
 
  264   QItemSelection selection = viewSymbols->selectionModel()->selection();
 
  265   if ( selection.isEmpty() )
 
  268   const QModelIndex index = selection.at( 0 ).topLeft();
 
  275   QItemSelection selection = viewSymbols->selectionModel()->selection();
 
  276   if ( selection.isEmpty() )
 
  279   const QModelIndex index = selection.at( 0 ).topLeft();
 
  290   QWidget::showEvent( event );
 
  291   QgsSettings settings;
 
  292   mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral( 
"UI/symbolsList/treeState" ), QByteArray(), QgsSettings::Gui ).toByteArray() );
 
  295 void QgsStyleItemsListWidget::populateGroups()
 
  300   mUpdatingGroups = 
true;
 
  301   groupsCombo->blockSignals( 
true );
 
  302   groupsCombo->clear();
 
  304   groupsCombo->addItem( tr( 
"Favorites" ), QVariant( 
"favorite" ) );
 
  306   QString allText = tr( 
"All Symbols" );
 
  312         allText = tr( 
"All Symbols" );
 
  316         allText = tr( 
"All Color Ramps" );
 
  320         allText = tr( 
"All Text Formats" );
 
  324         allText = tr( 
"All Label Settings" );
 
  328         allText = tr( 
"All Legend Patch Shapes" );
 
  332         allText = tr( 
"All 3D Symbols" );
 
  341   groupsCombo->addItem( allText, QVariant( 
"all" ) );
 
  344   QStringList tags = mStyle->
tags();
 
  345   if ( tags.count() > 0 )
 
  348     groupsCombo->insertSeparator( index );
 
  349     const auto constTags = tags;
 
  350     for ( 
const QString &tag : constTags )
 
  352       groupsCombo->addItem( tag, QVariant( 
"tag" ) );
 
  358   if ( groups.count() > 0 )
 
  361     groupsCombo->insertSeparator( index + 1 );
 
  362     const auto constGroups = groups;
 
  363     for ( 
const QString &group : constGroups )
 
  365       groupsCombo->addItem( group, QVariant( 
"smartgroup" ) );
 
  368   groupsCombo->blockSignals( 
false );
 
  370   QgsSettings settings;
 
  371   index = settings.value( QStringLiteral( 
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
 
  372   groupsCombo->setCurrentIndex( index );
 
  374   mUpdatingGroups = 
false;
 
  376   updateModelFilters();
 
  379 void QgsStyleItemsListWidget::updateModelFilters()
 
  381   if ( mUpdatingGroups || !mModel )
 
  384   const QString text = groupsCombo->currentText();
 
  385   const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
 
  394   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"favorite" ) )
 
  401   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"all" ) )
 
  408   else if ( groupsCombo->currentData().toString() == QLatin1String( 
"smartgroup" ) )
 
  424 void QgsStyleItemsListWidget::openStyleManager()
 
  440     updateModelFilters(); 
 
  444 void QgsStyleItemsListWidget::onSelectionChanged( 
const QModelIndex &index )
 
  449   QString symbolName = mModel->data( mModel->index( index.row(), 
QgsStyleModel::Name ) ).toString();
 
  450   lblSymbolName->setText( symbolName );
 
  455 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged( 
int index )
 
  457   QgsSettings settings;
 
  458   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.
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.