Skip to content

Commit b18b18c

Browse files
author
jef
committedApr 8, 2011
fix wms source select:
- allow selection of named layers - allow individual selection of all layers of a group to allow layer order management - show upcoming layer name unless one is manually given git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15681 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+72
-36
lines changed

2 files changed

+72
-36
lines changed
 

‎src/app/qgswmssourceselect.cpp

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -613,46 +613,27 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked()
613613

614614
void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
615615
{
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 )
619617
{
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+
}
634620

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++;
650628
}
651-
else if ( styleName.isEmpty() )
629+
630+
if ( styles > 0 )
652631
{
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+
656637
QTreeWidgetItem *style = 0;
657638
QTreeWidgetItem *firstNewStyle = 0;
658639
for ( int i = 0; i < item->childCount(); i++ )
@@ -686,6 +667,42 @@ void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
686667
style->setSelected( true );
687668
}
688669
}
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+
}
689706
}
690707

691708
void QgsWMSSourceSelect::collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles )
@@ -896,6 +913,22 @@ void QgsWMSSourceSelect::updateButtons()
896913
mAddButton->setEnabled( true );
897914
}
898915
}
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+
}
899932
}
900933

901934

‎src/app/qgswmssourceselect.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
165165
//! URI for selected connection
166166
QString mConnectionInfo;
167167

168+
//! layer name derived from latest layer selection (updated as long it's not edited manually)
169+
QString mLastLayerName;
170+
168171
//! The widget that controls the image format radio buttons
169172
QButtonGroup *mImageFormatGroup;
170173

0 commit comments

Comments
 (0)
Please sign in to comment.