21 #include <QStandardItemModel> 22 #include <QStandardItem> 31 QStandardItemModel *model =
new QStandardItemModel( groupTree );
32 groupTree->setModel( model );
34 QStandardItem *allSymbols =
new QStandardItem( tr(
"All Symbols" ) );
35 allSymbols->setData(
"all", Qt::UserRole + 2 );
36 allSymbols->setEditable(
false );
38 model->appendRow( allSymbols );
40 QStandardItem *tags =
new QStandardItem( QLatin1String(
"" ) );
41 tags->setData(
"tagsheader", Qt::UserRole + 2 );
42 tags->setEditable(
false );
43 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
45 tags->setText( tr(
"Tags" ) );
47 model->appendRow( tags );
49 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
50 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
51 tag->setEditable(
false );
52 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
55 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
56 while ( i != sgMap.constEnd() )
58 QStandardItem *item =
new QStandardItem( i.value() );
59 item->setEditable(
false );
60 item->setData( i.key() );
61 item->setData(
"smartgroup", Qt::UserRole + 2 );
62 tag->appendRow( item );
65 model->appendRow( tag );
68 int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
69 for (
int i = 0; i < rows; i++ )
71 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
73 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
78 QFont font = item->font();
80 item->setFont( font );
84 void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
87 QModelIndexList selectedItems = selected.indexes();
88 QModelIndexList deselectedItems = deselected.indexes();
90 Q_FOREACH ( index, deselectedItems )
92 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
96 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
100 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
104 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
108 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
114 Q_FOREACH ( index, selectedItems )
116 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
120 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
124 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
128 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
132 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
141 void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
143 QStringList tags = mStyle->
tags();
145 Q_FOREACH (
const QString &tag, tags )
147 QStandardItem *item =
new QStandardItem( tag );
148 item->setData( mStyle->
tagId( tag ) );
149 item->setData(
"tag", Qt::UserRole + 2 );
150 item->setEditable(
false );
151 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.
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