22 #include <QStandardItemModel> 23 #include <QStandardItem> 34 QStandardItemModel *model =
new QStandardItemModel( groupTree );
35 groupTree->setModel( model );
37 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
38 allSymbols->setData(
"all", Qt::UserRole + 2 );
39 allSymbols->setEditable(
false );
41 model->appendRow( allSymbols );
43 QStandardItem *tags =
new QStandardItem( QString() );
44 tags->setData(
"tagsheader", Qt::UserRole + 2 );
45 tags->setEditable(
false );
46 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
48 tags->setText( tr(
"Tags" ) );
50 model->appendRow( tags );
52 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
53 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
54 tag->setEditable(
false );
55 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
58 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
59 while ( i != sgMap.constEnd() )
61 QStandardItem *item =
new QStandardItem( i.value() );
62 item->setEditable(
false );
63 item->setData( i.key() );
64 item->setData(
"smartgroup", Qt::UserRole + 2 );
65 tag->appendRow( item );
68 model->appendRow( tag );
71 int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
72 for (
int i = 0; i < rows; i++ )
74 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
76 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
81 QFont font = item->font();
83 item->setFont( font );
87 void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
89 const QModelIndexList selectedItems = selected.indexes();
90 const QModelIndexList deselectedItems = deselected.indexes();
92 for (
const QModelIndex &index : deselectedItems )
94 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
98 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
102 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
106 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
110 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
116 const auto constSelectedItems = selectedItems;
117 for (
const QModelIndex &index : constSelectedItems )
119 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
123 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
127 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
131 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
135 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
144 void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
146 QStringList tags = mStyle->
tags();
148 const auto constTags = tags;
149 for (
const QString &tag : constTags )
151 QStandardItem *item =
new QStandardItem( tag );
152 item->setData( mStyle->
tagId( tag ) );
153 item->setData(
"tag", Qt::UserRole + 2 );
154 item->setEditable(
false );
155 parent->appendRow( item );
QMap< int, QString > QgsSymbolGroupMap
void tagSelected(const QString &tagName)
tag with tagName has been selected
void setBold(QStandardItem *item)
Sets bold font for item.
void smartgroupSelected(const QString &groupName)
smartgroup with groupName has been selected
void allDeselected()
all deselected
void allSelected()
all selected
int tagId(const QString &tag)
Returns the DB id for the given tag name.
QStringList tags() const
Returns a list of all tags in the style database.
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 smartgroupDeselected(const QString &groupName)
smart group with groupName has been deselected
QgsStyleGroupSelectionDialog(QgsStyle *style, QWidget *parent=nullptr)
QgsSymbolGroupMap smartgroupsListMap()
Returns the smart groups map with id as key and name as value.
void tagDeselected(const QString &tagName)
tag with tagName has been deselected