23#include <QStandardItem>
24#include <QStandardItemModel>
27#include "moc_qgsstylegroupselectiondialog.cpp"
29using namespace Qt::StringLiterals;
39 QStandardItemModel *model =
new QStandardItemModel( groupTree );
40 groupTree->setModel( model );
42 QStandardItem *favSymbols =
new QStandardItem( tr(
"Favorites" ) );
43 favSymbols->setData(
"favorites", Qt::UserRole + 2 );
44 favSymbols->setEditable(
false );
46 model->appendRow( favSymbols );
48 QStandardItem *allSymbols =
new QStandardItem( tr(
"All" ) );
49 allSymbols->setData(
"all", Qt::UserRole + 2 );
50 allSymbols->setEditable(
false );
52 model->appendRow( allSymbols );
54 QStandardItem *tags =
new QStandardItem( QString() );
55 tags->setData(
"tagsheader", Qt::UserRole + 2 );
56 tags->setEditable(
false );
57 tags->setFlags( tags->flags() & ~Qt::ItemIsSelectable );
59 tags->setText( tr(
"Tags" ) );
61 model->appendRow( tags );
63 QStandardItem *tag =
new QStandardItem( tr(
"Smart Groups" ) );
64 tag->setData(
"smartgroupsheader", Qt::UserRole + 2 );
65 tag->setEditable(
false );
66 tag->setFlags( tag->flags() & ~Qt::ItemIsSelectable );
69 QgsSymbolGroupMap::const_iterator i = sgMap.constBegin();
70 while ( i != sgMap.constEnd() )
72 QStandardItem *item =
new QStandardItem( i.value() );
73 item->setEditable(
false );
74 item->setData( i.key() );
75 item->setData(
"smartgroup", Qt::UserRole + 2 );
76 tag->appendRow( item );
79 model->appendRow( tag );
82 const int rows = model->rowCount( model->indexFromItem( model->invisibleRootItem() ) );
83 for (
int i = 0; i < rows; i++ )
85 groupTree->setExpanded( model->indexFromItem( model->item( i ) ),
true );
87 connect( groupTree->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsStyleGroupSelectionDialog::groupTreeSelectionChanged );
92 QFont font = item->font();
94 item->setFont( font );
97void QgsStyleGroupSelectionDialog::groupTreeSelectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
99 const QModelIndexList selectedItems = selected.indexes();
100 const QModelIndexList deselectedItems = deselected.indexes();
102 for (
const QModelIndex &index : deselectedItems )
104 if ( index.data( Qt::UserRole + 2 ).toString() ==
"tagssheader"_L1 )
108 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"favorites"_L1 )
112 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"all"_L1 )
116 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"smartgroupsheader"_L1 )
120 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"smartgroup"_L1 )
124 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"tag"_L1 )
130 const auto constSelectedItems = selectedItems;
131 for (
const QModelIndex &index : constSelectedItems )
133 if ( index.data( Qt::UserRole + 2 ).toString() ==
"tagssheader"_L1 )
137 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"favorites"_L1 )
141 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"all"_L1 )
145 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"smartgroupsheader"_L1 )
149 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"smartgroup"_L1 )
153 else if ( index.data( Qt::UserRole + 2 ).toString() ==
"tag"_L1 )
161void QgsStyleGroupSelectionDialog::buildTagTree( QStandardItem *&parent )
163 QStringList tags = mStyle->tags();
165 const auto constTags = tags;
166 for (
const QString &tag : constTags )
168 QStandardItem *item =
new QStandardItem( tag );
169 item->setData( mStyle->tagId( tag ) );
170 item->setData(
"tag", Qt::UserRole + 2 );
171 item->setEditable(
false );
172 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
A database of saved style entities, including symbols, color ramps, text formats and others.
QMap< int, QString > QgsSymbolGroupMap