@@ -613,46 +613,27 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked()
613
613
614
614
void QgsWMSSourceSelect::applySelectionConstraints ( QTreeWidgetItem *item )
615
615
{
616
- QString layerName = item->data ( 0 , Qt::UserRole + 0 ).toString ();
617
- QString styleName = item->data ( 0 , Qt::UserRole + 1 ).toString ();
618
- if ( layerName.isEmpty () )
616
+ if ( item->childCount () == 0 )
619
617
{
620
- // layer group =>
621
- // process child layers and style selection first
622
- // then
623
- // if all child layers of a group are selected, deselect them and select the group and collapse it
624
- // if some child layers are selected, deselect the group and all parents
625
- // otherwise keep the selection state of the group
626
- int n = 0 ;
627
- for ( int i = 0 ; i < item->childCount (); i++ )
628
- {
629
- QTreeWidgetItem *child = item->child ( i );
630
- applySelectionConstraints ( child );
631
- if ( child->isSelected () )
632
- n++;
633
- }
618
+ return ;
619
+ }
634
620
635
- if ( n > 0 )
636
- {
637
- item->setSelected ( n == item->childCount () );
638
- if ( item->isSelected () )
639
- {
640
- for ( int i = 0 ; i < n; i++ )
641
- item->child ( i )->setSelected ( false );
642
- item->setExpanded ( false );
643
- }
644
- else
645
- {
646
- for ( QTreeWidgetItem *parent = item->parent (); parent; parent = parent->parent () )
647
- parent->setSelected ( false );
648
- }
649
- }
621
+ int styles = 0 ;
622
+ for ( int i = 0 ; i < item->childCount (); i++ )
623
+ {
624
+ QTreeWidgetItem *child = item->child ( i );
625
+ QString style = child->data ( 0 , Qt::UserRole + 1 ).toString ();
626
+ if ( !style.isEmpty () )
627
+ styles++;
650
628
}
651
- else if ( styleName.isEmpty () )
629
+
630
+ if ( styles > 0 )
652
631
{
653
- // named layer =>
654
- // if styles are selected, deselect the layer and all styles but the first newly selected or the first if there no new,
655
- // else if no styles are selected, keep the layer selection
632
+ if ( styles < item->childCount () )
633
+ {
634
+ return ;
635
+ }
636
+
656
637
QTreeWidgetItem *style = 0 ;
657
638
QTreeWidgetItem *firstNewStyle = 0 ;
658
639
for ( int i = 0 ; i < item->childCount (); i++ )
@@ -686,6 +667,42 @@ void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
686
667
style->setSelected ( true );
687
668
}
688
669
}
670
+ else
671
+ {
672
+ // no styles => layer or layer group =>
673
+ // process child layers and style selection first
674
+ // then
675
+ // if some child layers are selected, deselect the group and all parents
676
+ // otherwise keep the selection state of the group
677
+ int n = 0 ;
678
+ for ( int i = 0 ; i < item->childCount (); i++ )
679
+ {
680
+ QTreeWidgetItem *child = item->child ( i );
681
+ applySelectionConstraints ( child );
682
+ if ( child->isSelected () )
683
+ n++;
684
+ }
685
+
686
+ if ( n > 0 )
687
+ {
688
+ if ( item->isSelected () )
689
+ {
690
+ for ( int i = 0 ; i < n; i++ )
691
+ {
692
+ QTreeWidgetItem *child = item->child ( i );
693
+ child->setSelected ( false );
694
+ }
695
+ item->setExpanded ( false );
696
+ }
697
+ else
698
+ {
699
+ for ( QTreeWidgetItem *parent = item->parent (); parent; parent = parent->parent () )
700
+ {
701
+ parent->setSelected ( false );
702
+ }
703
+ }
704
+ }
705
+ }
689
706
}
690
707
691
708
void QgsWMSSourceSelect::collectNamedLayers ( QTreeWidgetItem *item, QStringList &layers, QStringList &styles )
@@ -896,6 +913,22 @@ void QgsWMSSourceSelect::updateButtons()
896
913
mAddButton ->setEnabled ( true );
897
914
}
898
915
}
916
+
917
+ if ( leLayerName->text ().isEmpty () || leLayerName->text () == mLastLayerName )
918
+ {
919
+ if ( mAddButton ->isEnabled () )
920
+ {
921
+ QStringList layers, styles;
922
+ collectSelectedLayers ( layers, styles );
923
+ mLastLayerName = layers.join ( " /" );
924
+ leLayerName->setText ( mLastLayerName );
925
+ }
926
+ else
927
+ {
928
+ mLastLayerName = " " ;
929
+ leLayerName->setText ( mLastLayerName );
930
+ }
931
+ }
899
932
}
900
933
901
934
0 commit comments