From 7b4e69982771804e621b40205e03e8b9f84530ec Mon Sep 17 00:00:00 2001 From: jef Date: Fri, 8 Apr 2011 20:19:17 +0000 Subject: [PATCH] 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 --- src/app/qgswmssourceselect.cpp | 105 ++++++++++++++++++++++----------- src/app/qgswmssourceselect.h | 3 + 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/src/app/qgswmssourceselect.cpp b/src/app/qgswmssourceselect.cpp index 0cc4ab38b27c..d403cd074b1b 100644 --- a/src/app/qgswmssourceselect.cpp +++ b/src/app/qgswmssourceselect.cpp @@ -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 ); + } + } } diff --git a/src/app/qgswmssourceselect.h b/src/app/qgswmssourceselect.h index 38150d9e9c88..0a3562ec9ca4 100644 --- a/src/app/qgswmssourceselect.h +++ b/src/app/qgswmssourceselect.h @@ -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;