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 ) ) );
78 mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );
80 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
81 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
83 connect( openStyleManagerButton, &QToolButton::clicked,
this, &QgsStyleItemsListWidget::openStyleManager );
85 lblSymbolName->clear();
87 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
91 mSymbolViewStackedWidget->setCurrentIndex( 0 );
96 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
101 mSymbolViewStackedWidget->setCurrentIndex( 1 );
107 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
108 if ( currentView == 0 )
109 mButtonIconView->setChecked(
true );
111 mButtonListView->setChecked(
true );
113 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
114 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
121 groupEdit->setShowSearchIcon(
true );
122 groupEdit->setShowClearButton(
true );
123 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
124 groupsCombo->setLineEdit( groupEdit );
134 :
new QgsReadOnlyStyleModel( mStyle,
this );
138 viewSymbols->setModel( mModel );
139 mSymbolTreeView->setModel( mModel );
143 mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
144 connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsStyleItemsListWidget::onSelectionChanged );
147 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
148 connect( groupsCombo, &QComboBox::currentTextChanged,
this, &QgsStyleItemsListWidget::updateModelFilters );
151 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
158 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
162 btnSaveSymbol->setText( tr(
"Save Symbol…" ) );
163 btnSaveSymbol->setToolTip( tr(
"Save symbol to styles" ) );
165 groupsCombo->setItemText( allGroup, tr(
"All Symbols" ) );
169 btnSaveSymbol->setText( tr(
"Save Color Ramp…" ) );
170 btnSaveSymbol->setToolTip( tr(
"Save color ramp to styles" ) );
172 groupsCombo->setItemText( allGroup, tr(
"All Color Ramps" ) );
176 btnSaveSymbol->setText( tr(
"Save Format…" ) );
177 btnSaveSymbol->setToolTip( tr(
"Save text format to styles" ) );
179 groupsCombo->setItemText( allGroup, tr(
"All Text Formats" ) );
183 btnSaveSymbol->setText( tr(
"Save Label Settings…" ) );
184 btnSaveSymbol->setToolTip( tr(
"Save label settings to styles" ) );
186 groupsCombo->setItemText( allGroup, tr(
"All Label Settings" ) );
201 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
204 btnSaveSymbol->setText( tr(
"Save Settings…" ) );
205 btnSaveSymbol->setToolTip( tr(
"Save label settings or text format to styles" ) );
207 groupsCombo->setItemText( allGroup, tr(
"All Settings" ) );
224 return groupsCombo->currentData().toString() == QLatin1String(
"tag" ) ? groupsCombo->currentText() : QString();
229 return btnAdvanced->menu();
237 btnAdvanced->setMenu( menu );
243 btnAdvanced->setVisible( enabled );
248 QItemSelection selection = viewSymbols->selectionModel()->selection();
249 if ( selection.isEmpty() )
252 const QModelIndex index = selection.at( 0 ).topLeft();
259 QItemSelection selection = viewSymbols->selectionModel()->selection();
260 if ( selection.isEmpty() )
263 const QModelIndex index = selection.at( 0 ).topLeft();
274 QWidget::showEvent( event );
276 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
279 void QgsStyleItemsListWidget::populateGroups()
284 mUpdatingGroups =
true;
285 groupsCombo->blockSignals(
true );
286 groupsCombo->clear();
288 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
290 QString allText = tr(
"All Symbols" );
296 allText = tr(
"All Symbols" );
300 allText = tr(
"All Color Ramps" );
304 allText = tr(
"All Text Formats" );
308 allText = tr(
"All Label Settings" );
317 groupsCombo->addItem( allText, QVariant(
"all" ) );
320 QStringList tags = mStyle->
tags();
321 if ( tags.count() > 0 )
324 groupsCombo->insertSeparator( index );
325 const auto constTags = tags;
326 for (
const QString &tag : constTags )
328 groupsCombo->addItem( tag, QVariant(
"tag" ) );
334 if ( groups.count() > 0 )
337 groupsCombo->insertSeparator( index + 1 );
338 const auto constGroups = groups;
339 for (
const QString &group : constGroups )
341 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
344 groupsCombo->blockSignals(
false );
347 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
348 groupsCombo->setCurrentIndex( index );
350 mUpdatingGroups =
false;
352 updateModelFilters();
355 void QgsStyleItemsListWidget::updateModelFilters()
357 if ( mUpdatingGroups || !mModel )
360 const QString text = groupsCombo->currentText();
361 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
370 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
377 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
384 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
400 void QgsStyleItemsListWidget::openStyleManager()
416 updateModelFilters();
420 void QgsStyleItemsListWidget::onSelectionChanged(
const QModelIndex &index )
425 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
426 lblSymbolName->setText( symbolName );
431 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged(
int index )
434 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), index );
A QAbstractItemModel subclass for showing symbol and color ramp entities contained within a QgsStyle ...
void setFilterString(const QString &filter)
Sets a filter string, such that only symbol entities with names matching the specified string will be...
static QgsWindowManagerInterface * windowManager()
Returns the global window manager, if set.
A dialog allowing users to customize and populate a QgsStyle.
void setSmartGroupId(int id)
Sets a smart group id to filter style entities by.
static const double UI_SCALE_FACTOR
UI scaling factor.
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 setTagId(int id)
Sets a tag id to filter style entities by.
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
void setFavoritesOnly(bool favoritesOnly)
Sets whether the model should show only favorited entities.
static QgsStyle * defaultStyle()
Returns default application-wide style.
StyleEntity
Enum for Entities involved in a style.
void setSymbolTypeFilterEnabled(bool enabled)
Sets whether filtering by symbol type is enabled.
SymbolType
Type of the symbol.
void setEntityFilterEnabled(bool enabled)
Sets whether filtering by entity type is enabled.
void addDesiredIconSize(QSize size)
Adds an additional icon size to generate for Qt::DecorationRole data.
void groupsModified()
Emitted every time a tag or smartgroup has been added, removed, or renamed.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
A QSortFilterProxyModel subclass for showing filtered symbol and color ramps entries from a QgsStyle ...
void setLayerType(QgsWkbTypes::GeometryType type)
Sets the layer type filter.
int smartgroupId(const QString &smartgroup)
Returns the DB id for the given smartgroup name.
int tagId(const QString &tag)
Returns the DB id for the given tag name.
static QgsStyleModel * defaultStyleModel()
Returns a shared QgsStyleModel containing the default style library (see QgsStyle::defaultStyle()).
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QStringList tags() const
Returns a list of all tags in the style database.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
bool entityFilterEnabled() const
Returns true if filtering by entity type is enabled.
void setEntityFilter(QgsStyle::StyleEntity filter)
Sets the style entity type filter.
Style entity type, see QgsStyle::StyleEntity.
QgsStyle::StyleEntity entityFilter() const
Returns the style entity type filter.
void setEntityFilters(const QList< QgsStyle::StyleEntity > &filters)
Sets the style entity type filters.
QStringList smartgroupNames() const
Returns the smart groups list.