Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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@15681 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 8, 2011
1 parent 464a689 commit 7b4e699
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 36 deletions.
105 changes: 69 additions & 36 deletions src/app/qgswmssourceselect.cpp
Expand Up @@ -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++ )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
}
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/app/qgswmssourceselect.h
Expand Up @@ -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;

Expand Down

0 comments on commit 7b4e699

Please sign in to comment.