23#include <QStandardItem>
24#include <QStandardItemModel>
26#include "moc_qgsstylegroupselectiondialog.cpp"
36 QStandardItemModel *model =
new QStandardItemModel( groupTree );
37 groupTree->setModel( model );
39 QStandardItem *favSymbols =
new QStandardItem( tr(
"Favorites" ) );
40 favSymbols->setData(
"favorites", Qt::UserRole + 2 );
41 favSymbols->setEditable(
false );
43 model->appendRow( favSymbols );
45 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
46 allSymbols->setData(
"all", Qt::UserRole + 2 );
47 allSymbols->setEditable(
false );
49 model->appendRow( allSymbols );
51 QStandardItem *tags =
new QStandardItem( QString() );
52 tags->setData(
"tagsheader", Qt::UserRole + 2 );
53 tags->setEditable(
false );
54 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
56 tags->setText( tr(
"Tags" ) );
58 model->appendRow( tags );
60 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
61 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
62 tag->setEditable(
false );
63 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
66 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
67 while ( i != sgMap.constEnd() )
69 QStandardItem *item =
new QStandardItem( i.value() );
70 item->setEditable(
false );
71 item->setData( i.key() );
72 item->setData(
"smartgroup", Qt::UserRole + 2 );
73 tag->appendRow( item );
76 model->appendRow( tag );
79 const int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
80 for (
int i = 0; i < rows; i++ )
82 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
84 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
89 QFont font = item->font();
91 item->setFont( font );
94void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
96 const QModelIndexList selectedItems = selected.indexes();
97 const QModelIndexList deselectedItems = deselected.indexes();
99 for (
const QModelIndex &index : deselectedItems )
101 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
105 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
109 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
113 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
117 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
121 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
127 const auto constSelectedItems = selectedItems;
128 for (
const QModelIndex &index : constSelectedItems )
130 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
134 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
138 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
142 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
146 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
150 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
158void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
160 QStringList tags = mStyle->tags();
162 const auto constTags = tags;
163 for (
const QString &tag : constTags )
165 QStandardItem *item =
new QStandardItem( tag );
166 item->setData( mStyle->tagId( tag ) );
167 item->setData(
"tag", Qt::UserRole + 2 );
168 item->setEditable(
false );
169 parent->appendRow( item );
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
void favoritesDeselected()
Favorites has been deselected.
void allDeselected()
all deselected
void tagSelected(const QString &tagName)
tag with tagName has been selected
QgsStyleGroupSelectionDialog(QgsStyle *style, QWidget *parent=nullptr)
void setBold(QStandardItem *item)
Sets bold font for item.
void tagDeselected(const QString &tagName)
tag with tagName has been deselected
void smartgroupDeselected(const QString &groupName)
smart group with groupName has been deselected
void favoritesSelected()
Favorites has need selected.
void smartgroupSelected(const QString &groupName)
smartgroup with groupName has been selected
void allSelected()
all selected
A database of saved style entities, including symbols, color ramps, text formats and others.
QMap< int, QString > QgsSymbolGroupMap