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" ) );
219 const int allGroup = groupsCombo->findData( QVariant(
"all" ) );
222 btnSaveSymbol->setText( tr(
"Save Settings…" ) );
223 btnSaveSymbol->setToolTip( tr(
"Save label settings or text format to styles" ) );
225 groupsCombo->setItemText( allGroup, tr(
"All Settings" ) );
242 return groupsCombo->currentData().toString() == QLatin1String(
"tag" ) ? groupsCombo->currentText() : QString();
247 return btnAdvanced->menu();
255 btnAdvanced->setMenu( menu );
261 btnAdvanced->setVisible( enabled );
266 QItemSelection selection = viewSymbols->selectionModel()->selection();
267 if ( selection.isEmpty() )
270 const QModelIndex index = selection.at( 0 ).topLeft();
277 QItemSelection selection = viewSymbols->selectionModel()->selection();
278 if ( selection.isEmpty() )
281 const QModelIndex index = selection.at( 0 ).topLeft();
292 QWidget::showEvent( event );
294 mSymbolTreeView->header()->restoreState( settings.
value( QStringLiteral(
"UI/symbolsList/treeState" ), QByteArray(),
QgsSettings::Gui ).toByteArray() );
297 void QgsStyleItemsListWidget::populateGroups()
302 mUpdatingGroups =
true;
303 groupsCombo->blockSignals(
true );
304 groupsCombo->clear();
306 groupsCombo->addItem( tr(
"Favorites" ), QVariant(
"favorite" ) );
308 QString allText = tr(
"All Symbols" );
314 allText = tr(
"All Symbols" );
318 allText = tr(
"All Color Ramps" );
322 allText = tr(
"All Text Formats" );
326 allText = tr(
"All Label Settings" );
330 allText = tr(
"All Legend Patch Shapes" );
339 groupsCombo->addItem( allText, QVariant(
"all" ) );
342 QStringList tags = mStyle->
tags();
343 if ( tags.count() > 0 )
346 groupsCombo->insertSeparator( index );
347 const auto constTags = tags;
348 for (
const QString &tag : constTags )
350 groupsCombo->addItem( tag, QVariant(
"tag" ) );
356 if ( groups.count() > 0 )
359 groupsCombo->insertSeparator( index + 1 );
360 const auto constGroups = groups;
361 for (
const QString &group : constGroups )
363 groupsCombo->addItem( group, QVariant(
"smartgroup" ) );
366 groupsCombo->blockSignals(
false );
369 index = settings.
value( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), 0 ).toInt();
370 groupsCombo->setCurrentIndex( index );
372 mUpdatingGroups =
false;
374 updateModelFilters();
377 void QgsStyleItemsListWidget::updateModelFilters()
379 if ( mUpdatingGroups || !mModel )
382 const QString text = groupsCombo->currentText();
383 const bool isFreeText = text != groupsCombo->itemText( groupsCombo->currentIndex() );
392 else if ( groupsCombo->currentData().toString() == QLatin1String(
"favorite" ) )
399 else if ( groupsCombo->currentData().toString() == QLatin1String(
"all" ) )
406 else if ( groupsCombo->currentData().toString() == QLatin1String(
"smartgroup" ) )
422 void QgsStyleItemsListWidget::openStyleManager()
438 updateModelFilters();
442 void QgsStyleItemsListWidget::onSelectionChanged(
const QModelIndex &index )
447 QString symbolName = mModel->data( mModel->index( index.row(),
QgsStyleModel::Name ) ).toString();
448 lblSymbolName->setText( symbolName );
453 void QgsStyleItemsListWidget::groupsCombo_currentIndexChanged(
int index )
456 settings.
setValue( QStringLiteral(
"qgis/symbolsListGroupsIndex" ), index );