32QgsReadOnlyStyleModel::QgsReadOnlyStyleModel(
QgsStyleModel *sourceModel, QObject *parent )
38QgsReadOnlyStyleModel::QgsReadOnlyStyleModel(
QgsStyle *style, QObject *parent )
50Qt::ItemFlags QgsReadOnlyStyleModel::flags(
const QModelIndex &index )
const
52 return QgsStyleProxyModel::flags( index ) & ~Qt::ItemIsEditable;
55QVariant QgsReadOnlyStyleModel::data(
const QModelIndex &index,
int role )
const
57 if ( role == Qt::FontRole )
60 QFont f = QgsStyleProxyModel::data( index, role ).value< QFont >();
65 return QgsStyleProxyModel::data( index, role );
73QgsStyleModelDelegate::QgsStyleModelDelegate( QObject *parent )
74 : QStyledItemDelegate( parent )
79QSize QgsStyleModelDelegate::sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
81 if (
const QListView *view = qobject_cast< const QListView * >( option.widget ) )
86 QFont f = option.font;
87 f.setPointSizeF( f.pointSizeF() * 1.4 );
88 const QFontMetrics fm( f );
89 return QSize( option.widget->width() - view->verticalScrollBar()->width() * 2, fm.height() );
95 const QSize
iconSize = option.decorationSize;
96 return QSize(
static_cast< int >(
iconSize.width() * 1.4 ),
static_cast< int >(
iconSize.height() * 1.7 ) );
99 else if ( qobject_cast< const QTreeView * >( option.widget ) )
103 QSize defaultSize = QStyledItemDelegate::sizeHint( option, index );
105 return QSize( defaultSize.width(),
static_cast< int >( defaultSize.height() * 1.2 ) );
109 return QStyledItemDelegate::sizeHint( option, index );
112void QgsStyleModelDelegate::paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
116 QStyleOptionViewItem titleOption( option );
117 initStyleOption( &titleOption, index );
118 if ( qobject_cast< const QListView * >( option.widget ) )
120 titleOption.font.setBold(
true );
121 titleOption.font.setPointSizeF( titleOption.font.pointSizeF() * 1.4 );
124 painter->setBrush( titleOption.palette.windowText() );
125 painter->setFont( titleOption.font );
126 const QRect rect = QRect( titleOption.rect.left(), titleOption.rect.top(),
127 titleOption.rect.width(), titleOption.rect.height() );
129 painter->drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, index.data( Qt::DisplayRole ).toString() );
130 painter->setBrush( Qt::NoBrush );
131 QColor lineColor = titleOption.palette.windowText().color();
132 lineColor.setAlpha( 100 );
133 painter->setPen( QPen( lineColor, 1 ) );
134 painter->drawLine( titleOption.rect.left(), titleOption.rect.bottom(), titleOption.rect.right(), titleOption.rect.bottom() );
138 else if ( qobject_cast< const QTreeView * >( option.widget ) )
141 QColor lineColor = option.palette.windowText().color();
142 lineColor.setAlpha( 100 );
143 painter->setPen( QPen( lineColor, 1 ) );
145 QFont f = option.font;
148 titleOption.font = f;
149 titleOption.fontMetrics = QFontMetrics( titleOption.font );
151 painter->drawLine( index.column() == 0 ? 0 : option.rect.left(),
152 option.rect.bottom(),
153 index.column() == 0 ? option.rect.right() : option.widget->width(),
154 option.rect.bottom() );
157 titleOption.state |= QStyle::State_Enabled;
158 QStyledItemDelegate::paint( painter, titleOption, index );
163 QStyledItemDelegate::paint( painter, option, index );
180 mDelegate =
new QgsStyleModelDelegate(
this );
183 btnAdvanced->setMenu(
new QMenu(
this ) );
186 viewSymbols->setIconSize( QSize(
static_cast< int >( iconSize ),
static_cast< int >( iconSize * 0.9 ) ) );
189 mSymbolTreeView->setIconSize( QSize(
static_cast< int >( treeIconSize ),
static_cast< int >( treeIconSize ) ) );
190 mSymbolTreeView->setMinimumHeight( mSymbolTreeView->fontMetrics().height() * 6 );
192 viewSymbols->setItemDelegate( mDelegate );
193 mSymbolTreeView->setItemDelegate( mDelegate );
195 viewSymbols->setSelectionBehavior( QAbstractItemView::SelectRows );
196 mSymbolTreeView->setSelectionMode( viewSymbols->selectionMode() );
198 connect( openStyleManagerButton, &QToolButton::clicked,
this, &QgsStyleItemsListWidget::openStyleManager );
200 lblSymbolName->clear();
202 connect( mButtonIconView, &QToolButton::toggled,
this, [ = ](
bool active )
206 mSymbolViewStackedWidget->setCurrentIndex( 0 );
211 connect( mButtonListView, &QToolButton::toggled,
this, [ = ](
bool active )
216 mSymbolViewStackedWidget->setCurrentIndex( 1 );
222 const int currentView = settings.
value( QStringLiteral(
"UI/symbolsList/lastIconView" ), 0,
QgsSettings::Gui ).toInt();
223 if ( currentView == 0 )
224 mButtonIconView->setChecked(
true );
226 mButtonListView->setChecked(
true );
228 mSymbolTreeView->header()->restoreState( settings.value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
229 connect( mSymbolTreeView->header(), &QHeaderView::sectionResized,
this, [
this]
232 QgsSettings().setValue( QStringLiteral(
"UI/symbolsList/treeState" ), mSymbolTreeView->header()->saveState(), QgsSettings::Gui );
238 groupEdit->setPlaceholderText( tr(
"Filter symbols…" ) );
239 groupsCombo->setLineEdit( groupEdit );
249 :
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 );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
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.
Stores properties relating to a screen.
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 ...
@ IsTitle
True if the index corresponds to a title item.
@ StyleFileName
File name of associated QgsStyle (QgsStyle::fileName())
@ Type
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 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 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 addTargetScreenProperties(const QgsScreenProperties &properties)
Adds additional target screen properties to use when generating icons 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...
void setLayerType(Qgis::GeometryType type)
Sets the layer type filter.
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
@ ColorrampEntity
Color ramps.
@ LegendPatchShapeEntity
Legend patch shape.
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(bool initialize=true)
Returns the default application-wide style.
QStringList smartgroupNames() const
Returns the smart groups list.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.