34QgsReadOnlyStyleModel::QgsReadOnlyStyleModel(
QgsStyleModel *sourceModel, QObject *parent )
40QgsReadOnlyStyleModel::QgsReadOnlyStyleModel(
QgsStyle *style, QObject *parent )
52Qt::ItemFlags QgsReadOnlyStyleModel::flags(
const QModelIndex &index )
const
54 return QgsStyleProxyModel::flags( index ) & ~Qt::ItemIsEditable;
57QVariant QgsReadOnlyStyleModel::data(
const QModelIndex &index,
int role )
const
59 if ( role == Qt::FontRole )
62 QFont f = QgsStyleProxyModel::data( index, role ).value< QFont >();
67 return QgsStyleProxyModel::data( index, role );
75QgsStyleModelDelegate::QgsStyleModelDelegate( QObject *parent )
76 : QStyledItemDelegate( parent )
81QSize QgsStyleModelDelegate::sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
83 if (
const QListView *view = qobject_cast< const QListView * >( option.widget ) )
88 QFont f = option.font;
89 f.setPointSizeF( f.pointSizeF() * 1.4 );
90 const QFontMetrics fm( f );
91 return QSize( option.widget->width() - view->verticalScrollBar()->width() * 2, fm.height() );
97 const QSize
iconSize = option.decorationSize;
98 return QSize(
static_cast< int >(
iconSize.width() * 1.4 ),
static_cast< int >(
iconSize.height() * 1.7 ) );
101 else if ( qobject_cast< const QTreeView * >( option.widget ) )
105 QSize defaultSize = QStyledItemDelegate::sizeHint( option, index );
107 return QSize( defaultSize.width(),
static_cast< int >( defaultSize.height() * 1.2 ) );
111 return QStyledItemDelegate::sizeHint( option, index );
114void QgsStyleModelDelegate::paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
118 QStyleOptionViewItem titleOption( option );
119 initStyleOption( &titleOption, index );
120 if ( qobject_cast< const QListView * >( option.widget ) )
122 titleOption.font.setBold(
true );
123 titleOption.font.setPointSizeF( titleOption.font.pointSizeF() * 1.4 );
126 painter->setBrush( titleOption.palette.windowText() );
127 painter->setFont( titleOption.font );
128 const QRect rect = QRect( titleOption.rect.left(), titleOption.rect.top(),
129 titleOption.rect.width(), titleOption.rect.height() );
131 painter->drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, index.data( Qt::DisplayRole ).toString() );
132 painter->setBrush( Qt::NoBrush );
133 QColor lineColor = titleOption.palette.windowText().color();
134 lineColor.setAlpha( 100 );
135 painter->setPen( QPen( lineColor, 1 ) );
136 painter->drawLine( titleOption.rect.left(), titleOption.rect.bottom(), titleOption.rect.right(), titleOption.rect.bottom() );
140 else if ( qobject_cast< const QTreeView * >( option.widget ) )
143 QColor lineColor = option.palette.windowText().color();
144 lineColor.setAlpha( 100 );
145 painter->setPen( QPen( lineColor, 1 ) );
147 QFont f = option.font;
150 titleOption.font = f;
151 titleOption.fontMetrics = QFontMetrics( titleOption.font );
153 painter->drawLine( index.column() == 0 ? 0 : option.rect.left(),
154 option.rect.bottom(),
155 index.column() == 0 ? option.rect.right() : option.widget->width(),
156 option.rect.bottom() );
159 titleOption.state |= QStyle::State_Enabled;
160 QStyledItemDelegate::paint( painter, titleOption, index );
165 QStyledItemDelegate::paint( painter, option, index );
182 mDelegate =
new QgsStyleModelDelegate(
this );
185 btnAdvanced->setMenu(
new QMenu(
this ) );
188 viewSymbols->setIconSize( QSize(
static_cast< int >(
iconSize ),
static_cast< int >(
iconSize * 0.9 ) ) );
191 mSymbolTreeView->setIconSize( QSize(
static_cast< int >( treeIconSize ),
static_cast< int >( treeIconSize ) ) );
192 mSymbolTreeView->setMinimumHeight( mSymbolTreeView->fontMetrics().height() * 6 );
194 viewSymbols->setItemDelegate( mDelegate );
195 mSymbolTreeView->setItemDelegate( mDelegate );
197 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
198 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
200 connect( openStyleManagerButton, &QToolButton::clicked,
this, &QgsStyleItemsListWidget::openStyleManager );
202 lblSymbolName->clear();
204 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
208 mSymbolViewStackedWidget->setCurrentIndex( 0 );
213 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
218 mSymbolViewStackedWidget->setCurrentIndex( 1 );
224 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
225 if ( currentView == 0 )
226 mButtonIconView->setChecked(
true );
228 mButtonListView->setChecked(
true );
230 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
231 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
234 QgsSettings().setValue( QStringLiteral(
"UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
240 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
241 groupsCombo->setLineEdit( groupEdit );
251 :
new QgsReadOnlyStyleModel( mStyle,
this );
256 viewSymbols->setTextElideMode( Qt::TextElideMode::ElideRight );
258 viewSymbols->setModel( mModel );
259 mSymbolTreeView->setModel( mModel );
263 mSymbolTreeView->setSelectionModel( viewSymbols->selectionModel() );
264 connect( viewSymbols->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsStyleItemsListWidget::onSelectionChanged );
267 connect( groupsCombo,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsStyleItemsListWidget::groupsCombo_currentIndexChanged );
268 connect( groupsCombo, &QComboBox::currentTextChanged,
this, &QgsStyleItemsListWidget::updateModelFilters );
271 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
278 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
282 btnSaveSymbol->setText( tr(
"Save Symbol…" ) );
283 btnSaveSymbol->setToolTip( tr(
"Save symbol to styles" ) );
285 groupsCombo->setItemText( allGroup, tr(
"All Symbols" ) );
289 btnSaveSymbol->setText( tr(
"Save Color Ramp…" ) );
290 btnSaveSymbol->setToolTip( tr(
"Save color ramp to styles" ) );
292 groupsCombo->setItemText( allGroup, tr(
"All Color Ramps" ) );
296 btnSaveSymbol->setText( tr(
"Save Format…" ) );
297 btnSaveSymbol->setToolTip( tr(
"Save text format to styles" ) );
299 groupsCombo->setItemText( allGroup, tr(
"All Text Formats" ) );
303 btnSaveSymbol->setText( tr(
"Save Label Settings…" ) );
304 btnSaveSymbol->setToolTip( tr(
"Save label settings to styles" ) );
306 groupsCombo->setItemText( allGroup, tr(
"All Label Settings" ) );
310 btnSaveSymbol->setText( tr(
"Save Legend Patch Shape…" ) );
311 btnSaveSymbol->setToolTip( tr(
"Save legend patch shape to styles" ) );
313 groupsCombo->setItemText( allGroup, tr(
"All Legend Patch Shapes" ) );
317 btnSaveSymbol->setText( tr(
"Save 3D Symbol…" ) );
318 btnSaveSymbol->setToolTip( tr(
"Save 3D symbol to styles" ) );
320 groupsCombo->setItemText( allGroup, tr(
"All 3D Symbols" ) );
335 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
338 btnSaveSymbol->setText( tr(
"Save Settings…" ) );
339 btnSaveSymbol->setToolTip( tr(
"Save label settings or text format to styles" ) );
341 groupsCombo->setItemText( allGroup, tr(
"All Settings" ) );
358 return groupsCombo->currentData().toString() == QLatin1String(
"tag" ) ? groupsCombo->currentText() : QString();
363 return btnAdvanced->menu();
371 btnAdvanced->setMenu( menu );
377 btnAdvanced->setVisible( enabled );
382 const QItemSelection selection = viewSymbols->selectionModel()->selection();
383 if ( selection.isEmpty() )
386 const QModelIndex index = selection.at( 0 ).topLeft();
393 const QItemSelection selection = viewSymbols->selectionModel()->selection();
394 if ( selection.isEmpty() )
397 const QModelIndex index = selection.at( 0 ).topLeft();
408 QWidget::showEvent( event );
410 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
413void QgsStyleItemsListWidget::populateGroups()
418 mUpdatingGroups =
true;
419 groupsCombo->blockSignals(
true );
420 groupsCombo->clear();
422 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
424 QString allText = tr(
"All Symbols" );
430 allText = tr(
"All Symbols" );
434 allText = tr(
"All Color Ramps" );
438 allText = tr(
"All Text Formats" );
442 allText = tr(
"All Label Settings" );
446 allText = tr(
"All Legend Patch Shapes" );
450 allText = tr(
"All 3D Symbols" );
459 groupsCombo->addItem( allText, QVariant(
"all" ) );
462 QStringList tags = mStyle->
tags();
463 if ( tags.count() > 0 )
466 groupsCombo->insertSeparator( index );
467 const auto constTags = tags;
468 for (
const QString &tag : constTags )
470 groupsCombo->addItem( tag, QVariant(
"tag" ) );
476 if ( groups.count() > 0 )
479 groupsCombo->insertSeparator( index + 1 );
480 const auto constGroups = groups;
481 for (
const QString &group : constGroups )
483 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
486 groupsCombo->blockSignals(
false );
489 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
490 groupsCombo->setCurrentIndex( index );
492 mUpdatingGroups =
false;
494 updateModelFilters();
497void QgsStyleItemsListWidget::updateModelFilters()
499 if ( mUpdatingGroups || !mModel )
502 const QString text = groupsCombo->currentText();
503 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
512 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
519 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
526 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
542void QgsStyleItemsListWidget::openStyleManager()
558 updateModelFilters();
562void QgsStyleItemsListWidget::onSelectionChanged(
const QModelIndex &index )
567 const QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
568 lblSymbolName->setText( symbolName );
576void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged(
int index )
579 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), index );
static const double UI_SCALE_FACTOR
UI scaling factor.
A model which contains entities from multiple QgsStyle databases.
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
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 ...
@ StyleFileName
File name of associated QgsStyle (QgsStyle::fileName()) (since QGIS 3.26)
@ TypeRole
Style entity type, see QgsStyle::StyleEntity.
@ IsTitleRole
True if the index corresponds to a title item (since QGIS 3.26)
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 setTagString(const QString &tag)
Sets a tag 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.
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.