22 #include <QStandardItemModel>
23 #include <QStandardItem>
34 QStandardItemModel *model =
new QStandardItemModel( groupTree );
35 groupTree->setModel( model );
37 QStandardItem *favSymbols =
new QStandardItem( tr(
"Favorites" ) );
38 favSymbols->setData(
"favorites", Qt::UserRole + 2 );
39 favSymbols->setEditable(
false );
41 model->appendRow( favSymbols );
43 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
44 allSymbols->setData(
"all", Qt::UserRole + 2 );
45 allSymbols->setEditable(
false );
47 model->appendRow( allSymbols );
49 QStandardItem *tags =
new QStandardItem( QString() );
50 tags->setData(
"tagsheader", Qt::UserRole + 2 );
51 tags->setEditable(
false );
52 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
54 tags->setText( tr(
"Tags" ) );
56 model->appendRow( tags );
58 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
59 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
60 tag->setEditable(
false );
61 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
64 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
65 while ( i != sgMap.constEnd() )
67 QStandardItem *item =
new QStandardItem( i.value() );
68 item->setEditable(
false );
69 item->setData( i.key() );
70 item->setData(
"smartgroup", Qt::UserRole + 2 );
71 tag->appendRow( item );
74 model->appendRow( tag );
77 int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
78 for (
int i = 0; i < rows; i++ )
80 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
82 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
87 QFont font = item->font();
89 item->setFont( font );
92 void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
94 const QModelIndexList selectedItems = selected.indexes();
95 const QModelIndexList deselectedItems = deselected.indexes();
97 for (
const QModelIndex &index : deselectedItems )
99 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
103 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
107 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
111 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
115 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
119 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
125 const auto constSelectedItems = selectedItems;
126 for (
const QModelIndex &index : constSelectedItems )
128 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
132 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
136 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
140 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
144 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
148 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
156 void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
158 QStringList tags = mStyle->
tags();
160 const auto constTags = tags;
161 for (
const QString &tag : constTags )
163 QStandardItem *item =
new QStandardItem( tag );
164 item->setData( mStyle->
tagId( tag ) );
165 item->setData(
"tag", Qt::UserRole + 2 );
166 item->setEditable(
false );
167 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
QStringList tags() const
Returns a list of all tags in the style database.
int tagId(const QString &tag)
Returns the database id for the given tag name.
QgsSymbolGroupMap smartgroupsListMap()
Returns the smart groups map with id as key and name as value.
QMap< int, QString > QgsSymbolGroupMap