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 ) ) );
89 mSymbolTreeView->setMinimumHeight( mSymbolTreeView->fontMetrics().height() * 6 );
91 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
92 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
94 connect( openStyleManagerButton, &QToolButton::clicked,
this, &QgsStyleItemsListWidget::openStyleManager );
96 lblSymbolName->clear();
98 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
102 mSymbolViewStackedWidget->setCurrentIndex( 0 );
107 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
112 mSymbolViewStackedWidget->setCurrentIndex( 1 );
118 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
119 if ( currentView == 0 )
120 mButtonIconView->setChecked(
true );
122 mButtonListView->setChecked(
true );
124 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
125 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
128 QgsSettings().setValue( QStringLiteral(
"UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
134 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
135 groupsCombo->setLineEdit( groupEdit );
145 :
new QgsReadOnlyStyleModel( mStyle,
this );
149 viewSymbols->setModel( mModel );
150 mSymbolTreeView->setModel( mModel );
154 mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
155 connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsStyleItemsListWidget::onSelectionChanged );
158 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
159 connect( groupsCombo, &QComboBox::currentTextChanged,
this, &QgsStyleItemsListWidget::updateModelFilters );
162 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
169 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
173 btnSaveSymbol->setText( tr(
"Save Symbol…" ) );
174 btnSaveSymbol->setToolTip( tr(
"Save symbol to styles" ) );
176 groupsCombo->setItemText( allGroup, tr(
"All Symbols" ) );
180 btnSaveSymbol->setText( tr(
"Save Color Ramp…" ) );
181 btnSaveSymbol->setToolTip( tr(
"Save color ramp to styles" ) );
183 groupsCombo->setItemText( allGroup, tr(
"All Color Ramps" ) );
187 btnSaveSymbol->setText( tr(
"Save Format…" ) );
188 btnSaveSymbol->setToolTip( tr(
"Save text format to styles" ) );
190 groupsCombo->setItemText( allGroup, tr(
"All Text Formats" ) );
194 btnSaveSymbol->setText( tr(
"Save Label Settings…" ) );
195 btnSaveSymbol->setToolTip( tr(
"Save label settings to styles" ) );
197 groupsCombo->setItemText( allGroup, tr(
"All Label Settings" ) );
201 btnSaveSymbol->setText( tr(
"Save Legend Patch Shape…" ) );
202 btnSaveSymbol->setToolTip( tr(
"Save legend patch shape to styles" ) );
204 groupsCombo->setItemText( allGroup, tr(
"All Legend Patch Shapes" ) );
208 btnSaveSymbol->setText( tr(
"Save 3D Symbol…" ) );
209 btnSaveSymbol->setToolTip( tr(
"Save 3D symbol to styles" ) );
211 groupsCombo->setItemText( allGroup, tr(
"All 3D Symbols" ) );
226 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
229 btnSaveSymbol->setText( tr(
"Save Settings…" ) );
230 btnSaveSymbol->setToolTip( tr(
"Save label settings or text format to styles" ) );
232 groupsCombo->setItemText( allGroup, tr(
"All Settings" ) );
249 return groupsCombo->currentData().toString() == QLatin1String(
"tag" ) ? groupsCombo->currentText() : QString();
254 return btnAdvanced->menu();
262 btnAdvanced->setMenu( menu );
268 btnAdvanced->setVisible( enabled );
273 QItemSelection selection = viewSymbols->selectionModel()->selection();
274 if ( selection.isEmpty() )
277 const QModelIndex index = selection.at( 0 ).topLeft();
284 QItemSelection selection = viewSymbols->selectionModel()->selection();
285 if ( selection.isEmpty() )
288 const QModelIndex index = selection.at( 0 ).topLeft();
299 QWidget::showEvent( event );
301 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
304 void QgsStyleItemsListWidget::populateGroups()
309 mUpdatingGroups =
true;
310 groupsCombo->blockSignals(
true );
311 groupsCombo->clear();
313 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
315 QString allText = tr(
"All Symbols" );
321 allText = tr(
"All Symbols" );
325 allText = tr(
"All Color Ramps" );
329 allText = tr(
"All Text Formats" );
333 allText = tr(
"All Label Settings" );
337 allText = tr(
"All Legend Patch Shapes" );
341 allText = tr(
"All 3D Symbols" );
350 groupsCombo->addItem( allText, QVariant(
"all" ) );
353 QStringList tags = mStyle->
tags();
354 if ( tags.count() > 0 )
357 groupsCombo->insertSeparator( index );
358 const auto constTags = tags;
359 for (
const QString &tag : constTags )
361 groupsCombo->addItem( tag, QVariant(
"tag" ) );
367 if ( groups.count() > 0 )
370 groupsCombo->insertSeparator( index + 1 );
371 const auto constGroups = groups;
372 for (
const QString &group : constGroups )
374 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
377 groupsCombo->blockSignals(
false );
380 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
381 groupsCombo->setCurrentIndex( index );
383 mUpdatingGroups =
false;
385 updateModelFilters();
388 void QgsStyleItemsListWidget::updateModelFilters()
390 if ( mUpdatingGroups || !mModel )
393 const QString text = groupsCombo->currentText();
394 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
403 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
410 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
417 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
433 void QgsStyleItemsListWidget::openStyleManager()
449 updateModelFilters();
453 void QgsStyleItemsListWidget::onSelectionChanged(
const QModelIndex &index )
458 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
459 lblSymbolName->setText( symbolName );
464 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged(
int index )
467 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.
void setSymbolType(QgsSymbol::SymbolType type)
Sets the symbol type filter.
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.
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.
SymbolType
Type of the symbol.
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.