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 );
82 SymbolLayerFillVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
83 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
97 bool visitSymbol( QTreeWidgetItem *rootItem,
const QString &identifier,
const QgsSymbol *symbol, QVector<int> rootPath )
105 QVector<int> indexPath = rootPath;
106 indexPath.append( idx );
108 std::unique_ptr< QTreeWidgetItem > slItem = qgis::make_unique< QTreeWidgetItem >( rootItem );
110 slItem->setIcon( 0, slIcon );
113 slItem->setText( 0, QObject::tr(
"Mask symbol layer" ) );
114 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
115 slItem->setCheckState( 0, Qt::Unchecked );
118 if ( ( sl->
layerType() ==
"MaskMarker" ) ||
119 ( subSymbol && visitSymbol( slItem.get(), identifier, subSymbol, indexPath ) ) )
122 mItems[ref] = slItem.get();
123 rootItem->addChild( slItem.release() );
136 const QgsSymbol *symbol = symbolEntity->symbol();
140 std::unique_ptr< QTreeWidgetItem > symbolItem = qgis::make_unique< QTreeWidgetItem >( mLayerItem, QStringList() << ( mCurrentDescription + leaf.
description ) );
142 symbolItem->setIcon( 0, icon );
144 if ( visitSymbol( symbolItem.get(), leaf.
identifier, symbol, {} ) )
145 mLayerItem->addChild( symbolItem.release() );
151 QString mCurrentDescription;
152 QString mCurrentIdentifier;
153 QTreeWidgetItem *mLayerItem;
155 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
161 LabelMasksVisitor( QTreeWidgetItem *layerItem,
const QgsVectorLayer *layer, QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &items ):
162 mLayerItem( layerItem ), mLayer( layer ), mItems( items )
179 if ( labelSettingsEntity->settings().format().mask().enabled() )
181 QString maskTitle = currentRule.isEmpty()
182 ? QObject::tr(
"Label mask" )
183 : QObject::tr(
"Label mask for '%1' rule" ).arg( currentDescription );
184 QTreeWidgetItem *slItem =
new QTreeWidgetItem( mLayerItem, QStringList() << maskTitle );
185 slItem->setFlags( slItem->flags() | Qt::ItemIsUserCheckable );
186 slItem->setCheckState( 0, Qt::Unchecked );
187 mLayerItem->addChild( slItem );
194 QHash<QString, QHash<QString, QSet<QgsSymbolLayerId>>> masks;
197 QString currentDescription;
198 QTreeWidgetItem *mLayerItem;
200 QHash<QgsSymbolLayerReference, QTreeWidgetItem *> &mItems;
207 const QgsMapLayer *layer = layerTreeLayer->layer();
208 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer );
214 std::unique_ptr< QTreeWidgetItem > layerItem = qgis::make_unique< QTreeWidgetItem >( mTree, QStringList() << layer->
name() );
215 layerItem->setData( 0, Qt::UserRole, vl );
219 LabelMasksVisitor lblVisitor( layerItem.get(), vl, mItems );
223 SymbolLayerFillVisitor slVisitor( layerItem.get(), vl, mItems );
226 if ( layerItem->childCount() > 0 )
227 mTree->addTopLevelItem( layerItem.release() );
230 expandAll( mTree->invisibleRootItem() );
236 QList<QgsMaskSourceSelectionWidget::MaskSource> sel;
237 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
239 if ( it.value()->checkState( 0 ) == Qt::Checked )
246 sel.append( source );
256 for (
auto it = mItems.begin(); it != mItems.end(); it++ )
258 it.value()->setCheckState( 0, Qt::Unchecked );
263 QString layerId = ( src.isLabeling ?
"__labels__" :
"" ) + src.layerId;
265 if ( it != mItems.end() )
267 it.value()->setCheckState( 0, Qt::Checked );