19#include "moc_qgsstylegroupselectiondialog.cpp"
23#include <QStandardItemModel>
24#include <QStandardItem>
35 QStandardItemModel *model =
new QStandardItemModel( groupTree );
36 groupTree->setModel( model );
38 QStandardItem *favSymbols =
new QStandardItem( tr(
"Favorites" ) );
39 favSymbols->setData(
"favorites", Qt::UserRole + 2 );
40 favSymbols->setEditable(
false );
42 model->appendRow( favSymbols );
44 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
45 allSymbols->setData(
"all", Qt::UserRole + 2 );
46 allSymbols->setEditable(
false );
48 model->appendRow( allSymbols );
50 QStandardItem *tags =
new QStandardItem( QString() );
51 tags->setData(
"tagsheader", Qt::UserRole + 2 );
52 tags->setEditable(
false );
53 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
55 tags->setText( tr(
"Tags" ) );
57 model->appendRow( tags );
59 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
60 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
61 tag->setEditable(
false );
62 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
65 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
66 while ( i != sgMap.constEnd() )
68 QStandardItem *item =
new QStandardItem( i.value() );
69 item->setEditable(
false );
70 item->setData( i.key() );
71 item->setData(
"smartgroup", Qt::UserRole + 2 );
72 tag->appendRow( item );
75 model->appendRow( tag );
78 const int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
79 for (
int i = 0; i < rows; i++ )
81 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
83 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
88 QFont font = item->font();
90 item->setFont( font );
93void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
95 const QModelIndexList selectedItems = selected.indexes();
96 const QModelIndexList deselectedItems = deselected.indexes();
98 for (
const QModelIndex &index : deselectedItems )
100 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
104 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
108 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
112 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
116 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
120 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
126 const auto constSelectedItems = selectedItems;
127 for (
const QModelIndex &index : constSelectedItems )
129 if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tagssheader" ) )
133 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"favorites" ) )
137 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"all" ) )
141 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroupsheader" ) )
145 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"smartgroup" ) )
149 else if ( index.data( Qt::UserRole + 2 ).toString() == QLatin1String(
"tag" ) )
157void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
159 QStringList tags = mStyle->
tags();
161 const auto constTags = tags;
162 for (
const QString &tag : constTags )
164 QStandardItem *item =
new QStandardItem( tag );
165 item->setData( mStyle->
tagId( tag ) );
166 item->setData(
"tag", Qt::UserRole + 2 );
167 item->setEditable(
false );
168 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