[QGIS Commit] r15681 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Apr 8 16:19:17 EDT 2011


Author: jef
Date: 2011-04-08 13:19:17 -0700 (Fri, 08 Apr 2011)
New Revision: 15681

Modified:
   trunk/qgis/src/app/qgswmssourceselect.cpp
   trunk/qgis/src/app/qgswmssourceselect.h
Log:
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


Modified: trunk/qgis/src/app/qgswmssourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.cpp	2011-04-07 20:11:00 UTC (rev 15680)
+++ trunk/qgis/src/app/qgswmssourceselect.cpp	2011-04-08 20:19:17 UTC (rev 15681)
@@ -613,46 +613,27 @@
 
 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++ )
+    return;
+  }
+
+  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++;
+  }
+
+  if ( styles > 0 )
+  {
+    if ( styles < item->childCount() )
     {
-      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 );
-      }
-    }
-  }
-  else if ( styleName.isEmpty() )
-  {
-    // 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
     QTreeWidgetItem *style = 0;
     QTreeWidgetItem *firstNewStyle = 0;
     for ( int i = 0; i < item->childCount(); i++ )
@@ -686,6 +667,42 @@
         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 @@
       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 );
+    }
+  }
 }
 
 

Modified: trunk/qgis/src/app/qgswmssourceselect.h
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.h	2011-04-07 20:11:00 UTC (rev 15680)
+++ trunk/qgis/src/app/qgswmssourceselect.h	2011-04-08 20:19:17 UTC (rev 15681)
@@ -165,6 +165,9 @@
     //! 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;
 



More information about the QGIS-commit mailing list