[QGIS Commit] r10850 - in trunk/qgis: images/themes/default src/app src/ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed May 27 03:28:07 EDT 2009


Author: mhugent
Date: 2009-05-27 03:28:05 -0400 (Wed, 27 May 2009)
New Revision: 10850

Added:
   trunk/qgis/images/themes/default/mActionArrowDown.png
   trunk/qgis/images/themes/default/mActionArrowUp.png
Modified:
   trunk/qgis/src/app/qgsserversourceselect.cpp
   trunk/qgis/src/app/qgsserversourceselect.h
   trunk/qgis/src/ui/qgsserversourceselectbase.ui
Log:
Added the possibility to change the order of layers in the WMS dialog

Added: trunk/qgis/images/themes/default/mActionArrowDown.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/images/themes/default/mActionArrowDown.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/qgis/images/themes/default/mActionArrowUp.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/images/themes/default/mActionArrowUp.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/qgis/src/app/qgsserversourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgsserversourceselect.cpp	2009-05-26 18:07:37 UTC (rev 10849)
+++ trunk/qgis/src/app/qgsserversourceselect.cpp	2009-05-27 07:28:05 UTC (rev 10850)
@@ -21,6 +21,7 @@
 
 #include "../providers/wms/qgswmsprovider.h"
 #include "qgis.h" // GEO_EPSG_CRS_ID 
+#include "qgisapp.h" //for getThemeIcon
 #include "qgscontexthelp.h"
 #include "qgscoordinatereferencesystem.h"
 #include "qgsgenericprojectionselector.h"
@@ -55,6 +56,8 @@
     mWmsProvider( 0 )
 {
   setupUi( this );
+  mLayerUpButton->setIcon(QgisApp::getThemeIcon("/mActionArrowUp.png"));
+  mLayerDownButton->setIcon(QgisApp::getThemeIcon("/mActionArrowDown.png"));
   connect( btnCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
 
   // Qt Designer 4.1 doesn't let us use a QButtonGroup, so it has to
@@ -426,11 +429,11 @@
 
 void QgsServerSourceSelect::on_btnAdd_clicked()
 {
-  if ( m_selectedLayers.empty() == TRUE )
+  if ( selectedLayers().empty() == TRUE )
   {
     QMessageBox::information( this, tr( "Select Layer" ), tr( "You must select at least one leaf layer first." ) );
   }
-  else if ( mWmsProvider->supportedCrsForLayers( m_selectedLayers ).size() == 0 )
+  else if ( mWmsProvider->supportedCrsForLayers( selectedLayers() ).size() == 0 )
   {
     QMessageBox::information( this, tr( "Coordinate Reference System" ), tr( "There are no available coordinate reference system for the set of layers you've selected." ) );
   }
@@ -448,7 +451,7 @@
     return;
   }
 
-  QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers( m_selectedLayers );
+  QSet<QString> crsFilter = mWmsProvider->supportedCrsForLayers( selectedLayers() );
 
   QgsGenericProjectionSelector * mySelector =
     new QgsGenericProjectionSelector( this );
@@ -519,6 +522,13 @@
     {
       // Remove old style selection
       lstLayers->findItems( m_selectedStyleIdForLayer[layerName], Qt::MatchRecursive ).first()->setSelected( false );
+      // Remove old layer/style pair also from newSelectedLayers / newSelectedStylesForSelectedLayers
+      int oldIndex = newSelectedLayers.indexOf(layerName);
+      if(oldIndex != -1)
+      {
+        newSelectedLayers.removeAt(oldIndex);
+        newSelectedStylesForSelectedLayers.removeAt(oldIndex);
+      }
     }
 
     QgsDebugMsg( QString( "Added %1" ).arg( item->text( 0 ) ) );
@@ -576,9 +586,8 @@
     btnChangeSpatialRefSys->setEnabled( FALSE );
   }
 
-  m_selectedLayers                  = newSelectedLayers;
-  m_selectedStylesForSelectedLayers = newSelectedStylesForSelectedLayers;
   m_selectedStyleIdForLayer         = newSelectedStyleIdForLayer;
+  updateLayerOrderTab(newSelectedLayers, newSelectedStylesForSelectedLayers);
 }
 
 
@@ -594,12 +603,24 @@
 
 QStringList QgsServerSourceSelect::selectedLayers()
 {
-  return m_selectedLayers;
+  //go through list in layer order tab
+  QStringList selectedLayerList;
+  for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
+  {
+    selectedLayerList << mLayerOrderTreeWidget->topLevelItem(i)->text(0);
+  }
+  return selectedLayerList;
 }
 
 QStringList QgsServerSourceSelect::selectedStylesForSelectedLayers()
 {
-  return m_selectedStylesForSelectedLayers;
+  //go through list in layer order tab
+  QStringList selectedStyleList;
+  for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
+  {
+    selectedStyleList << mLayerOrderTreeWidget->topLevelItem(i)->text(1);
+  }
+  return selectedStyleList;
 }
 
 
@@ -910,8 +931,105 @@
   btnAddWMS->setEnabled( tableWidgetWMSList->currentRow() != -1 );
 }
 
+void QgsServerSourceSelect::on_mLayerUpButton_clicked()
+{
+  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
+  if(selectionList.size() < 1)
+  {
+    return;
+  }
+ int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem(selectionList[0]);
+ if(selectedIndex < 1)
+ {
+   return; //item not existing or already on top
+ }
 
+ QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem(selectedIndex);
+ mLayerOrderTreeWidget->insertTopLevelItem(selectedIndex - 1, selectedItem);
+ mLayerOrderTreeWidget->clearSelection();
+ selectedItem->setSelected(true);
+}
 
+void QgsServerSourceSelect::on_mLayerDownButton_clicked()
+{
+QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
+  if(selectionList.size() < 1)
+  {
+    return;
+  }
+ int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem(selectionList[0]);
+ if(selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2)
+ {
+   return; //item not existing or already at bottom
+ }
+
+ QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem(selectedIndex);
+ mLayerOrderTreeWidget->insertTopLevelItem(selectedIndex + 1, selectedItem);
+ mLayerOrderTreeWidget->clearSelection();
+ selectedItem->setSelected(true);
+}
+
+void QgsServerSourceSelect::updateLayerOrderTab(const QStringList& newLayerList, const QStringList& newStyleList)
+{
+  //check, if each layer / style combination is already contained in the  layer order tab
+  //if not, add it to the top of the list
+
+  QStringList::const_iterator layerListIt = newLayerList.constBegin();
+  QStringList::const_iterator styleListIt = newStyleList.constBegin();
+
+  for( ; layerListIt != newLayerList.constEnd(); ++layerListIt, ++styleListIt)
+  {
+    bool combinationExists = false;
+    for(int i = 0; i < mLayerOrderTreeWidget->topLevelItemCount(); ++i)
+    {
+      QTreeWidgetItem* currentItem = mLayerOrderTreeWidget->topLevelItem(i);
+      if(currentItem->text(0) == *layerListIt && currentItem->text(1) == *styleListIt)
+      {
+        combinationExists = true;
+        break;
+      }
+    }
+
+   if(!combinationExists)
+    {
+      QTreeWidgetItem* newItem = new QTreeWidgetItem();
+      newItem->setText(0, *layerListIt);
+      newItem->setText(1, *styleListIt);
+      mLayerOrderTreeWidget->insertTopLevelItem(0, newItem);
+    }
+
+  }
+
+  //check, if each layer style combination in the layer order tab is still in newLayerList / newStyleList
+  //if not: remove it from the tree widget
+
+  if(mLayerOrderTreeWidget->topLevelItemCount() > 0)
+  {
+    for(int i = mLayerOrderTreeWidget->topLevelItemCount() - 1; i >= 0; --i)
+    {
+      QTreeWidgetItem* currentItem = mLayerOrderTreeWidget->topLevelItem(i);
+      bool combinationExists = false;
+
+      QStringList::const_iterator llIt = newLayerList.constBegin();
+      QStringList::const_iterator slIt = newStyleList.constBegin();
+      for( ; llIt != newLayerList.constEnd(); ++llIt, ++slIt)
+      {
+        if(*llIt == currentItem->text(0) && *slIt == currentItem->text(1))
+        {
+          combinationExists = true;
+          break;
+        }
+      }
+
+      if(!combinationExists)
+      {
+        mLayerOrderTreeWidget->takeTopLevelItem(i);
+      }
+     }
+  }
+
+}
+
 //
 //
 // ENDS

Modified: trunk/qgis/src/app/qgsserversourceselect.h
===================================================================
--- trunk/qgis/src/app/qgsserversourceselect.h	2009-05-26 18:07:37 UTC (rev 10849)
+++ trunk/qgis/src/app/qgsserversourceselect.h	2009-05-27 07:28:05 UTC (rev 10850)
@@ -148,6 +148,9 @@
     //! Returns a textual description for the EpsgCrsId number
     QString descriptionForEpsg( long epsg );
 
+    //! Keeps the layer order list up-to-date with changed layers and styles
+    void updateLayerOrderTab(const QStringList& newLayerList, const QStringList& newStyleList);
+
     //! Name for selected connection
     QString m_connName;
 
@@ -166,8 +169,8 @@
     //! Proxy Pass for selected connection
     QString m_connProxyPass;
 
-    QStringList m_selectedLayers;
-    QStringList m_selectedStylesForSelectedLayers;
+    //QStringList m_selectedLayers;
+    //QStringList m_selectedStylesForSelectedLayers;
     long m_Epsg;
 
     QMap<QString, QString> m_selectedStyleIdForLayer;
@@ -194,6 +197,8 @@
     void on_btnSearch_clicked();
     void on_btnAddWMS_clicked();
     void wmsSelectionChanged();
+    void on_mLayerUpButton_clicked();
+    void on_mLayerDownButton_clicked();
 };
 
 

Modified: trunk/qgis/src/ui/qgsserversourceselectbase.ui
===================================================================
--- trunk/qgis/src/ui/qgsserversourceselectbase.ui	2009-05-26 18:07:37 UTC (rev 10849)
+++ trunk/qgis/src/ui/qgsserversourceselectbase.ui	2009-05-27 07:28:05 UTC (rev 10850)
@@ -13,7 +13,9 @@
    <string>Add Layer(s) from a Server</string>
   </property>
   <property name="windowIcon" >
-   <iconset/>
+   <iconset>
+    <normaloff/>
+   </iconset>
   </property>
   <property name="sizeGripEnabled" >
    <bool>true</bool>
@@ -93,7 +95,7 @@
          <property name="sizeType" >
           <enum>QSizePolicy::Expanding</enum>
          </property>
-         <property name="sizeHint" >
+         <property name="sizeHint" stdset="0" >
           <size>
            <width>131</width>
            <height>30</height>
@@ -139,6 +141,61 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="tabLayerOrder" >
+      <attribute name="title" >
+       <string>Layer Order</string>
+      </attribute>
+      <layout class="QGridLayout" name="gridLayout" >
+       <item row="0" column="0" >
+        <widget class="QPushButton" name="mLayerUpButton" >
+         <property name="text" >
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="1" >
+        <widget class="QPushButton" name="mLayerDownButton" >
+         <property name="text" >
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="2" >
+        <spacer name="horizontalSpacer" >
+         <property name="orientation" >
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0" >
+          <size>
+           <width>391</width>
+           <height>30</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item row="1" column="0" colspan="3" >
+        <widget class="QTreeWidget" name="mLayerOrderTreeWidget" >
+         <property name="columnCount" >
+          <number>2</number>
+         </property>
+         <column>
+          <property name="text" >
+           <string>Layer</string>
+          </property>
+         </column>
+         <column>
+          <property name="text" >
+           <string>Style</string>
+          </property>
+         </column>
+        </widget>
+       </item>
+      </layout>
+      <zorder>mLayerUpButton</zorder>
+      <zorder>mLayerDownButton</zorder>
+      <zorder>horizontalSpacer</zorder>
+      <zorder>mLayerOrderTreeWidget</zorder>
+     </widget>
      <widget class="QWidget" name="tab_2" >
       <attribute name="title" >
        <string>Server Search</string>
@@ -236,7 +293,7 @@
         <property name="sizeType" >
          <enum>QSizePolicy::Expanding</enum>
         </property>
-        <property name="sizeHint" >
+        <property name="sizeHint" stdset="0" >
          <size>
           <width>441</width>
           <height>23</height>
@@ -281,7 +338,7 @@
      <property name="sizeType" >
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
        <width>284</width>
        <height>31</height>



More information about the QGIS-commit mailing list