16 #include <QTreeWidget>
17 #include <QVBoxLayout>
33 static void expandAll( QTreeWidgetItem *item )
35 for (
int i = 0; i < item->childCount(); i++ )
36 expandAll( item->child( i ) );
37 item->setExpanded(
true );
42 std::cout << lid.
symbolKey().toLocal8Bit().constData() <<
"/";
44 for (
int i = 0; i < path.size(); i++ )
46 std::cout << path[i] <<
"/";
52 std::cout << ref.
layerId().toLocal8Bit().constData() <<
"/";
59 mTree =
new QTreeWidget(
this );
60 mTree->setHeaderHidden(
true );
62 connect( mTree, &QTreeWidget::itemChanged,
this, [&]( QTreeWidgetItem *,
int ) { emit this->
changed(); } );
65 QVBoxLayout *vbox =
new QVBoxLayout();
66 vbox->setContentsMargins( 0, 0, 0, 0 );
67 vbox->addWidget( mTree );
80 SymbolLayerFillVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
81 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
95 bool visitSymbol( QTreeWidgetItem *rootItem,
const QString &identifier,
const QgsSymbol *symbol, QVector<int> rootPath )
103 QVector<int> indexPath = rootPath;
104 indexPath.append( idx );
106 std::unique_ptr< QTreeWidgetItem > slItem = std::make_unique< QTreeWidgetItem >( rootItem );
108 slItem->setIcon( 0, slIcon );
111 slItem->setText( 0, QObject::tr(
"Mask symbol layer" ) );
112 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
113 slItem->setCheckState( 0, Qt::Unchecked );
116 if ( ( sl->
layerType() ==
"MaskMarker" ) ||
117 ( subSymbol && visitSymbol( slItem.get(), identifier, subSymbol, indexPath ) ) )
120 mItems[ref] = slItem.get();
121 rootItem->addChild( slItem.release() );
134 const QgsSymbol *symbol = symbolEntity->symbol();
138 std::unique_ptr< QTreeWidgetItem > symbolItem = std::make_unique< QTreeWidgetItem >( mLayerItem, QStringList() << ( mCurrentDescription + leaf.
description ) );
140 symbolItem->setIcon( 0, icon );
142 if ( visitSymbol( symbolItem.get(), leaf.
identifier, symbol, {} ) )
143 mLayerItem->addChild( symbolItem.release() );
149 QString mCurrentDescription;
150 QString mCurrentIdentifier;
151 QTreeWidgetItem *mLayerItem;
153 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
159 LabelMasksVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
160 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
177 if ( labelSettingsEntity->settings().format().mask().enabled() )
179 const QString maskTitle = currentRule.isEmpty()
180 ? QObject::tr(
"Label mask" )
181 : QObject::tr(
"Label mask for '%1' rule" ).arg( currentDescription );
182 QTreeWidgetItem *slItem =
new QTreeWidgetItem( mLayerItem, QStringList() << maskTitle );
183 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
184 slItem->setCheckState( 0, Qt::Unchecked );
185 mLayerItem->addChild( slItem );
192 QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> masks;
195 QString currentDescription;
196 QTreeWidgetItem *mLayerItem;
198 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
205 const QgsMapLayer *layer = layerTreeLayer->layer();
206 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
212 std::unique_ptr< QTreeWidgetItem > layerItem = std::make_unique< QTreeWidgetItem >( mTree, QStringList() << layer->
name() );
213 layerItem->setData( 0, Qt::UserRole, vl );
217 LabelMasksVisitor lblVisitor( layerItem.get(), vl, mItems );
221 SymbolLayerFillVisitor slVisitor( layerItem.get(), vl, mItems );
224 if ( layerItem->childCount() > 0 )
225 mTree->addTopLevelItem( layerItem.release() );
228 expandAll( mTree->invisibleRootItem() );
234 QList<QgsMaskSourceSelectionWidget::MaskSource> sel;
235 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
237 if ( it.value()->checkState( 0 ) == Qt::Checked )
244 sel.append( source );
254 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
256 it.value()->setCheckState( 0, Qt::Unchecked );
261 const QString layerId = ( src.isLabeling ?
"__labels__" :
"" ) + src.layerId;
263 if ( it != mItems.end() )
265 it.value()->setCheckState( 0, Qt::Checked );