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 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 81 viewSymbols->setIconSize( QSize( static_cast< int >( iconSize ), static_cast< int >( iconSize * 0.9 ) ) );
83 #if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) 88 mSymbolTreeView->setIconSize( QSize( static_cast< int >( treeIconSize ), static_cast< int >( treeIconSize ) ) );
90 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
91 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
93 connect( openStyleManagerButton, &QToolButton::clicked,
this, &QgsStyleItemsListWidget::openStyleManager );
95 lblSymbolName->clear();
97 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
101 mSymbolViewStackedWidget->setCurrentIndex( 0 );
106 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
111 mSymbolViewStackedWidget->setCurrentIndex( 1 );
117 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
118 if ( currentView == 0 )
119 mButtonIconView->setChecked(
true );
121 mButtonListView->setChecked(
true );
123 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
124 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
131 groupEdit->setShowSearchIcon(
true );
132 groupEdit->setShowClearButton(
true );
133 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
134 groupsCombo->setLineEdit( groupEdit );
144 :
new QgsReadOnlyStyleModel( mStyle,
this );
148 viewSymbols->setModel( mModel );
149 mSymbolTreeView->setModel( mModel );
153 mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
154 connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsStyleItemsListWidget::onSelectionChanged );
157 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
158 connect( groupsCombo, &QComboBox::currentTextChanged,
this, &QgsStyleItemsListWidget::updateModelFilters );
161 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
168 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
172 btnSaveSymbol->setText( tr(
"Save Symbol…" ) );
173 btnSaveSymbol->setToolTip( tr(
"Save symbol to styles" ) );
175 groupsCombo->setItemText( allGroup, tr(
"All Symbols" ) );
179 btnSaveSymbol->setText( tr(
"Save Color Ramp…" ) );
180 btnSaveSymbol->setToolTip( tr(
"Save color ramp to styles" ) );
182 groupsCombo->setItemText( allGroup, tr(
"All Color Ramps" ) );
186 btnSaveSymbol->setText( tr(
"Save Format…" ) );
187 btnSaveSymbol->setToolTip( tr(
"Save text format to styles" ) );
189 groupsCombo->setItemText( allGroup, tr(
"All Text Formats" ) );
193 btnSaveSymbol->setText( tr(
"Save Label Settings…" ) );
194 btnSaveSymbol->setToolTip( tr(
"Save label settings to styles" ) );
196 groupsCombo->setItemText( allGroup, tr(
"All Label Settings" ) );
211 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
214 btnSaveSymbol->setText( tr(
"Save Settings…" ) );
215 btnSaveSymbol->setToolTip( tr(
"Save label settings or text format to styles" ) );
217 groupsCombo->setItemText( allGroup, tr(
"All Settings" ) );
234 return groupsCombo->currentData().toString() == QLatin1String(
"tag" ) ? groupsCombo->currentText() : QString();
239 return btnAdvanced->menu();
247 btnAdvanced->setMenu( menu );
253 btnAdvanced->setVisible( enabled );
258 QItemSelection selection = viewSymbols->selectionModel()->selection();
259 if ( selection.isEmpty() )
262 const QModelIndex index = selection.at( 0 ).topLeft();
269 QItemSelection selection = viewSymbols->selectionModel()->selection();
270 if ( selection.isEmpty() )
273 const QModelIndex index = selection.at( 0 ).topLeft();
284 QWidget::showEvent( event );
286 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
289 void QgsStyleItemsListWidget::populateGroups()
294 mUpdatingGroups =
true;
295 groupsCombo->blockSignals(
true );
296 groupsCombo->clear();
298 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
300 QString allText = tr(
"All Symbols" );
306 allText = tr(
"All Symbols" );
310 allText = tr(
"All Color Ramps" );
314 allText = tr(
"All Text Formats" );
318 allText = tr(
"All Label Settings" );
327 groupsCombo->addItem( allText, QVariant(
"all" ) );
330 QStringList tags = mStyle->
tags();
331 if ( tags.count() > 0 )
334 groupsCombo->insertSeparator( index );
335 const auto constTags = tags;
336 for (
const QString &tag : constTags )
338 groupsCombo->addItem( tag, QVariant(
"tag" ) );
344 if ( groups.count() > 0 )
347 groupsCombo->insertSeparator( index + 1 );
348 const auto constGroups = groups;
349 for (
const QString &group : constGroups )
351 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
354 groupsCombo->blockSignals(
false );
357 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
358 groupsCombo->setCurrentIndex( index );
360 mUpdatingGroups =
false;
362 updateModelFilters();
365 void QgsStyleItemsListWidget::updateModelFilters()
367 if ( mUpdatingGroups || !mModel )
370 const QString text = groupsCombo->currentText();
371 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
380 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
387 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
394 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
410 void QgsStyleItemsListWidget::openStyleManager()
426 updateModelFilters();
430 void QgsStyleItemsListWidget::onSelectionChanged(
const QModelIndex &index )
435 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
436 lblSymbolName->setText( symbolName );
441 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged(
int index )
444 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.