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 )
90 QModelIndexList selectedItems = selected.indexes();
91 QModelIndexList deselectedItems = deselected.indexes();
93 Q_FOREACH ( index, deselectedItems )
95 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
99 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
103 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
107 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
111 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
117 Q_FOREACH ( index, selectedItems )
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 Q_FOREACH (
const QString &tag, tags )
150 QStandardItem *item =
new QStandardItem( tag );
151 item->setData( mStyle->
tagId( tag ) );
152 item->setData(
"tag", Qt::UserRole + 2 );
153 item->setEditable(
false );
154 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