Skip to content
Permalink
Browse files
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
  • Loading branch information
jef committed Apr 8, 2011
1 parent 8f0ee3b commit b18b18ce4de7e0b2951eebe1cdac5019fe258785
Showing with 72 additions and 36 deletions.
  1. +69 −36 src/app/qgswmssourceselect.cpp
  2. +3 −0 src/app/qgswmssourceselect.h
@@ -613,46 +613,27 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked()

void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
{
QString layerName = item->data( 0, Qt::UserRole + 0 ).toString();
QString styleName = item->data( 0, Qt::UserRole + 1 ).toString();
if ( layerName.isEmpty() )
if ( item->childCount() == 0 )
{
// layer group =>
// process child layers and style selection first
// then
// if all child layers of a group are selected, deselect them and select the group and collapse it
// if some child layers are selected, deselect the group and all parents
// otherwise keep the selection state of the group
int n = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
QTreeWidgetItem *child = item->child( i );
applySelectionConstraints( child );
if ( child->isSelected() )
n++;
}
return;
}

if ( n > 0 )
{
item->setSelected( n == item->childCount() );
if ( item->isSelected() )
{
for ( int i = 0; i < n; i++ )
item->child( i )->setSelected( false );
item->setExpanded( false );
}
else
{
for ( QTreeWidgetItem *parent = item->parent(); parent; parent = parent->parent() )
parent->setSelected( false );
}
}
int styles = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
QTreeWidgetItem *child = item->child( i );
QString style = child->data( 0, Qt::UserRole + 1 ).toString();
if ( !style.isEmpty() )
styles++;
}
else if ( styleName.isEmpty() )

if ( styles > 0 )
{
// named layer =>
// if styles are selected, deselect the layer and all styles but the first newly selected or the first if there no new,
// else if no styles are selected, keep the layer selection
if ( styles < item->childCount() )
{
return;
}

QTreeWidgetItem *style = 0;
QTreeWidgetItem *firstNewStyle = 0;
for ( int i = 0; i < item->childCount(); i++ )
@@ -686,6 +667,42 @@ void QgsWMSSourceSelect::applySelectionConstraints( QTreeWidgetItem *item )
style->setSelected( true );
}
}
else
{
// no styles => layer or layer group =>
// process child layers and style selection first
// then
// if some child layers are selected, deselect the group and all parents
// otherwise keep the selection state of the group
int n = 0;
for ( int i = 0; i < item->childCount(); i++ )
{
QTreeWidgetItem *child = item->child( i );
applySelectionConstraints( child );
if ( child->isSelected() )
n++;
}

if ( n > 0 )
{
if ( item->isSelected() )
{
for ( int i = 0; i < n; i++ )
{
QTreeWidgetItem *child = item->child( i );
child->setSelected( false );
}
item->setExpanded( false );
}
else
{
for ( QTreeWidgetItem *parent = item->parent(); parent; parent = parent->parent() )
{
parent->setSelected( false );
}
}
}
}
}

void QgsWMSSourceSelect::collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles )
@@ -896,6 +913,22 @@ void QgsWMSSourceSelect::updateButtons()
mAddButton->setEnabled( true );
}
}

if ( leLayerName->text().isEmpty() || leLayerName->text() == mLastLayerName )
{
if ( mAddButton->isEnabled() )
{
QStringList layers, styles;
collectSelectedLayers( layers, styles );
mLastLayerName = layers.join( "/" );
leLayerName->setText( mLastLayerName );
}
else
{
mLastLayerName = "";
leLayerName->setText( mLastLayerName );
}
}
}


@@ -165,6 +165,9 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
//! URI for selected connection
QString mConnectionInfo;

//! layer name derived from latest layer selection (updated as long it's not edited manually)
QString mLastLayerName;

//! The widget that controls the image format radio buttons
QButtonGroup *mImageFormatGroup;

0 comments on commit b18b18c

Please sign in to comment.