[QGIS Commit] r13184 - in trunk/qgis/src: app ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Mar 28 16:18:08 EDT 2010


Author: jef
Date: 2010-03-28 16:18:07 -0400 (Sun, 28 Mar 2010)
New Revision: 13184

Added:
   trunk/qgis/src/app/qgstilescalewidget.cpp
   trunk/qgis/src/app/qgstilescalewidget.h
   trunk/qgis/src/ui/qgstilescalewidgetbase.ui
Modified:
   trunk/qgis/src/app/CMakeLists.txt
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/app/qgswmssourceselect.cpp
   trunk/qgis/src/app/qgswmssourceselect.h
   trunk/qgis/src/ui/qgswmssourceselectbase.ui
Log:
[FEATURE] wms-c scale slider and more selection improvements

Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/app/CMakeLists.txt	2010-03-28 20:18:07 UTC (rev 13184)
@@ -67,6 +67,7 @@
   qgssinglesymboldialog.cpp
   qgssnappingdialog.cpp
   qgsundowidget.cpp
+  qgstilescalewidget.cpp
   qgsuniquevaluedialog.cpp
   qgsvectorlayerproperties.cpp
   qgsquerybuilder.cpp
@@ -176,6 +177,7 @@
   qgsdbtablemodel.h
   qgsspatialitetablemodel.h
   qgsundowidget.h
+  qgstilescalewidget.h
   qgsquerybuilder.h
 
   composer/qgsattributeselectiondialog.h

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/app/qgisapp.cpp	2010-03-28 20:18:07 UTC (rev 13184)
@@ -153,6 +153,7 @@
 #include "qgsvectorfilewriter.h"
 #include "qgscredentialdialog.h"
 #include "qgsnetworkproxyfactory.h"
+#include "qgstilescalewidget.h"
 
 #ifdef HAVE_QWT
 #include "qgsgpsinformationwidget.h"
@@ -342,6 +343,7 @@
     , mSplash( splash )
     , mPythonUtils( NULL )
     , mNAM( NULL )
+    , mpTileScaleWidget( NULL )
 #ifdef HAVE_QWT
     , mpGpsWidget( NULL )
 #endif
@@ -374,8 +376,6 @@
   mSplash->showMessage( tr( "Setting up the GUI" ), Qt::AlignHCenter | Qt::AlignBottom );
   qApp->processEvents();
 
-
-
   createActions();
   createActionGroups();
   createMenus();
@@ -586,6 +586,11 @@
   // Add the recently accessed project file paths to the File menu
   mRecentProjectPaths = settings.value( "/UI/recentProjectsList" ).toStringList();
 
+  // Restore state of tile scale widget
+  if ( settings.value( "/UI/tileScaleEnabled", false ).toBool() )
+  {
+    showTileScale();
+  }
 #if HAVE_QWT
   // Restore state of GPS Tracker
   if ( settings.value( "/gps/widgetEnabled", false ).toBool() )
@@ -983,6 +988,12 @@
   connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
   mActionRemoveLayer->setEnabled( false );
 
+  mActionTileScale = new QAction( getThemeIcon( "mActionTileScale.png" ), tr( "Tile scale slider" ), this );
+  shortcuts->registerAction( mActionTileScale, tr( "", "Tile scale slider" ) );
+  mActionTileScale->setStatusTip( tr( "Show tile scale slider" ) );
+  connect( mActionTileScale, SIGNAL( triggered() ), this, SLOT( showTileScale() ) );
+  mActionTileScale->setEnabled( true );
+
 #ifdef HAVE_QWT
   mActionGpsTool = new QAction( getThemeIcon( "mActionGpsTool.png" ), tr( "Live GPS tracking" ), this );
   shortcuts->registerAction( mActionGpsTool, tr( "", "Live GPS tracking" ) );
@@ -1352,6 +1363,9 @@
     mViewMenu->addMenu( mToolbarMenu );
     mViewMenu->addAction( mActionToggleFullScreen );
   }
+
+  mViewMenu->addAction( mActionTileScale );
+
 #ifdef HAVE_QWT
   mViewMenu->addAction( mActionGpsTool );
 #endif
@@ -2193,6 +2207,17 @@
   // store window geometry
   settings.setValue( "/UI/geometry", saveGeometry() );
 
+  // Persist state of tile scale slider
+  if ( mpTileScaleWidget )
+  {
+    settings.setValue( "/UI/tileScaleEnabled", true );
+    delete mpTileScaleWidget;
+  }
+  else
+  {
+    settings.setValue( "/UI/tileScaleEnabled", false );
+  }
+
 #if HAVE_QWT
   // Persist state of GPS Tracker
   if ( mpGpsWidget )
@@ -4499,6 +4524,32 @@
 #endif
 }
 
+void QgisApp::showTileScale()
+{
+  if ( !mpTileScaleWidget )
+  {
+    mpTileScaleWidget = new QgsTileScaleWidget( mMapCanvas );
+    //create the dock widget
+    mpTileScaleDock = new QDockWidget( tr( "Tile scale" ), this );
+    mpTileScaleDock->setObjectName( "TileScale" );
+    mpTileScaleDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
+    addDockWidget( Qt::RightDockWidgetArea, mpTileScaleDock );
+    // add to the Panel submenu
+    mPanelMenu->addAction( mpTileScaleDock->toggleViewAction() );
+    // now add our widget to the dock - ownership of the widget is passed to the dock
+    mpTileScaleDock->setWidget( mpTileScaleWidget );
+    mpTileScaleWidget->show();
+
+    connect( mMapLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
+             mpTileScaleWidget, SLOT( layerChanged( QgsMapLayer* ) ) );
+
+  }
+  else
+  {
+    mpTileScaleDock->toggleViewAction();
+  }
+}
+
 void QgisApp::zoomToLayerExtent()
 {
   mMapLegend->legendLayerZoom();

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/app/qgisapp.h	2010-03-28 20:18:07 UTC (rev 13184)
@@ -58,6 +58,7 @@
 class QgsRectangle;
 class QgsUndoWidget;
 class QgsVectorLayer;
+class QgsTileScaleWidget;
 
 class QDomDocument;
 class QNetworkAccessManager;
@@ -274,6 +275,7 @@
     QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
     QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
     QAction *actionRemoveLayer() { return mActionRemoveLayer; }
+    QAction *actionTileScale() { return mActionTileScale; }
 #ifdef HAVE_QWT
     QAction *actionGpsTool() { return mActionGpsTool; }
 #endif
@@ -444,6 +446,8 @@
     void removeLayer();
     //! Show GPS tool
     void showGpsTool();
+    //! Show tile scale slider
+    void showTileScale();
     //! zoom to extent of layer
     void zoomToLayerExtent();
     //! zoom to actual size of raster layer
@@ -848,6 +852,7 @@
     QAction *mActionLayerSaveAs;
     QAction *mActionLayerSelectionSaveAs;
     QAction *mActionRemoveLayer;
+    QAction *mActionTileScale;
 #ifdef HAVE_QWT
     QAction *mActionGpsTool;
 #endif
@@ -911,6 +916,7 @@
     // docks ------------------------------------------
     QDockWidget *mLegendDock;
     QDockWidget *mOverviewDock;
+    QDockWidget *mpTileScaleDock;
 #ifdef HAVE_QWT
     QDockWidget *mpGpsDock;
 #endif
@@ -1062,6 +1068,9 @@
 
     int mLastComposerId;
 
+    //! Persistent tile scale slider
+    QgsTileScaleWidget * mpTileScaleWidget;
+
 #ifdef HAVE_QWT
     //! Persistent GPS toolbox
     QgsGPSInformationWidget * mpGpsWidget;

Added: trunk/qgis/src/app/qgstilescalewidget.cpp
===================================================================
--- trunk/qgis/src/app/qgstilescalewidget.cpp	                        (rev 0)
+++ trunk/qgis/src/app/qgstilescalewidget.cpp	2010-03-28 20:18:07 UTC (rev 13184)
@@ -0,0 +1,103 @@
+/***************************************************************************
+    qgstilescalewidget.cpp  - slider to choose wms-c resolutions
+                             -------------------
+    begin    : 28 Mar 2010
+    copyright: (C) 2010 Juergen E. Fischer < jef at norbit dot de >
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id: $ */
+
+#include "qgstilescalewidget.h"
+#include "qgsmapcanvas.h"
+#include "qgsrasterlayer.h"
+#include "qgslogger.h"
+
+QgsTileScaleWidget::QgsTileScaleWidget( QgsMapCanvas * mapCanvas, QWidget * parent, Qt::WindowFlags f )
+    : QWidget( parent, f )
+    , mMapCanvas( mapCanvas )
+{
+  setupUi( this );
+
+  connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( scaleChanged( double ) ) );
+
+  layerChanged( mMapCanvas->currentLayer() );
+}
+
+void QgsTileScaleWidget::layerChanged( QgsMapLayer *layer )
+{
+  QgsRasterLayer *rl = qobject_cast<QgsRasterLayer *>( layer );
+
+  if ( !rl || rl->providerKey() != "wms" || !rl->publicSource().contains( "tiled=" ) )
+  {
+    mResolutions.clear();
+    mSlider->setDisabled( true );
+  }
+  else
+  {
+    QString uri = rl->publicSource().mid( rl->publicSource().indexOf( "tiled=" ) + 6 );
+    int pos = uri.indexOf( "," );
+    if ( pos >= 0 )
+      uri = uri.left( pos );
+    QStringList params = uri.split( ";" );
+
+    params.takeFirst();
+    params.takeFirst();
+
+    mResolutions.clear();
+    foreach( QString r, params )
+    mResolutions << r.toDouble();
+    qSort( mResolutions );
+
+    for ( int i = 0; i < mResolutions.size(); i++ )
+      QgsDebugMsg( QString( "found resolution %1: %2" ).arg( i ).arg( mResolutions[i] ) );
+
+    mSlider->setRange( 0, mResolutions.size() - 1 );
+    mSlider->setTickInterval( 1 );
+    mSlider->setInvertedAppearance( true );
+    mSlider->setPageStep( 1 );
+    mSlider->setTracking( false );
+
+    scaleChanged( mMapCanvas->scale() );
+
+    mSlider->setEnabled( true );
+    show();
+  }
+}
+
+void QgsTileScaleWidget::scaleChanged( double scale )
+{
+  if ( mResolutions.size() == 0 )
+    return;
+
+  double mupp = mMapCanvas->mapUnitsPerPixel();
+  QgsDebugMsg( QString( "resolution changed to %1" ).arg( mupp ) );
+
+  int i;
+  for ( i = 0; i < mResolutions.size() && mResolutions[i] < mupp; i++ )
+    QgsDebugMsg( QString( "test resolution %1: %2 d:%3" ).arg( i ).arg( mResolutions[i] ).arg( mupp - mResolutions[i] ) );
+
+  if ( i == mResolutions.size() ||
+       ( i > 0 && mResolutions[i] - mupp > mupp - mResolutions[i-1] ) )
+  {
+    QgsDebugMsg( "previous resolution" );
+    i--;
+  }
+
+  QgsDebugMsg( QString( "selected resolution %1: %2" ).arg( i ).arg( mResolutions[i] ) );
+  mSlider->setValue( i );
+}
+
+void QgsTileScaleWidget::on_mSlider_valueChanged( int value )
+{
+  QgsDebugMsg( QString( "slider released at %1: %2" ).arg( mSlider->value() ).arg( mResolutions[mSlider->value()] ) );
+  mMapCanvas->zoomByFactor( mResolutions[mSlider->value()] / mMapCanvas->mapUnitsPerPixel() );
+}

Added: trunk/qgis/src/app/qgstilescalewidget.h
===================================================================
--- trunk/qgis/src/app/qgstilescalewidget.h	                        (rev 0)
+++ trunk/qgis/src/app/qgstilescalewidget.h	2010-03-28 20:18:07 UTC (rev 13184)
@@ -0,0 +1,44 @@
+/***************************************************************************
+    qgstilescalewidget.cpp  - slider to choose wms-c resolutions
+                             -------------------
+    begin    : 28 Mar 2010
+    copyright: (C) 2010 Juergen E. Fischer < jef at norbit dot de >
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+/* $Id: $ */
+
+#ifndef QGSTILESCALEWIDGET_H
+#define QGSTILESCALEWIDGET_H
+
+#include "ui_qgstilescalewidgetbase.h"
+
+class QgsMapCanvas;
+class QgsMapLayer;
+class QwtSlider;
+
+class QgsTileScaleWidget : public QWidget, private Ui::QgsTileScaleWidget
+{
+    Q_OBJECT
+  public:
+    QgsTileScaleWidget( QgsMapCanvas *mapCanvas, QWidget * parent = 0, Qt::WindowFlags f = 0 );
+
+  public slots:
+    void layerChanged( QgsMapLayer *layer );
+    void scaleChanged( double );
+    void on_mSlider_valueChanged( int );
+
+  private:
+    QgsMapCanvas *mMapCanvas;
+    QList<double> mResolutions;
+};
+
+#endif // QGSTILESCALEWIDGET

Modified: trunk/qgis/src/app/qgswmssourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.cpp	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/app/qgswmssourceselect.cpp	2010-03-28 20:18:07 UTC (rev 13184)
@@ -36,6 +36,7 @@
 #include <qgisinterface.h>
 
 #include <QButtonGroup>
+#include <QRadioButton>
 #include <QDomDocument>
 #include <QHeaderView>
 #include <QImageReader>
@@ -52,6 +53,7 @@
 
 QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl )
     : QDialog( parent, fl )
+    , mCurrentTileset( 0 )
 {
   setupUi( this );
 
@@ -156,9 +158,6 @@
   tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), false );
   tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), false );
 
-  connect( tableWidgetWMSList, SIGNAL( itemSelectionChanged() ), this, SLOT( wmsSelectionChanged() ) );
-  connect( lstTilesets, SIGNAL( itemSelectionChanged() ), this, SLOT( updateButtons() ) );
-
   QSettings settings;
   QgsDebugMsg( "restoring geometry" );
   restoreGeometry( settings.value( "/Windows/WMSSourceSelect/geometry" ).toByteArray() );
@@ -171,6 +170,7 @@
   settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
 }
 
+
 void QgsWMSSourceSelect::populateConnectionList()
 {
   QSettings settings;
@@ -204,6 +204,8 @@
   {
     populateConnectionList();
   }
+
+  delete nc;
 }
 
 void QgsWMSSourceSelect::on_btnEdit_clicked()
@@ -214,6 +216,8 @@
   {
     populateConnectionList();
   }
+
+  delete nc;
 }
 
 void QgsWMSSourceSelect::on_btnDelete_clicked()
@@ -368,6 +372,12 @@
       lstTilesets->setItem( i, 3, new QTableWidgetItem( tilesets[i].format ) );
       lstTilesets->setItem( i, 4, new QTableWidgetItem( tilesets[i].crs ) );
 
+      for ( int j = 0; j < 5; j++ )
+      {
+        QTableWidgetItem *item = lstTilesets->item( i, j );
+        item->setFlags( item->flags() & ~Qt::ItemIsEditable );
+      }
+
       if ( !mMimeMap.contains( tilesets[i].format ) )
       {
         for ( int j = 0; j < 5; j++ )
@@ -765,8 +775,49 @@
   updateButtons();
 }
 
+void QgsWMSSourceSelect::on_lstTilesets_itemClicked( QTableWidgetItem *item )
+{
+  QTableWidgetItem *rowItem = lstTilesets->item( lstTilesets->currentRow(), 0 );
+  bool wasSelected = mCurrentTileset == rowItem;
+
+  lstTilesets->blockSignals( true );
+  lstTilesets->clearSelection();
+  if ( !wasSelected )
+  {
+    QgsDebugMsg( QString( "selecting current row %1" ).arg( lstTilesets->currentRow() ) );
+    lstTilesets->selectRow( lstTilesets->currentRow() );
+    mCurrentTileset = rowItem;
+  }
+  else
+  {
+    mCurrentTileset = 0;
+  }
+  lstTilesets->blockSignals( false );
+
+  updateButtons();
+}
+
 void QgsWMSSourceSelect::updateButtons()
 {
+  if ( !lstTilesets->selectedItems().isEmpty() )
+  {
+    // tileset selected => disable layer selection and layer order
+    lstLayers->setEnabled( false );
+    tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), false );
+    tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), lstTilesets->rowCount() > 0 );
+    btnGrpImageEncoding->setEnabled( false );
+  }
+  else
+  {
+    // no tileset selected =>
+    //   disable layerorder, when no layers selected
+    //   disable tilesets, when layer are selected or no tilesets available
+    lstLayers->setEnabled( true );
+    tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), mLayerOrderTreeWidget->topLevelItemCount() > 0 );
+    tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ),  mLayerOrderTreeWidget->topLevelItemCount() == 0  && lstTilesets->rowCount() );
+    btnGrpImageEncoding->setEnabled( true );
+  }
+
   if ( lstTilesets->selectedItems().isEmpty() && mLayerOrderTreeWidget->topLevelItemCount() == 0 )
   {
     if ( lstTilesets->rowCount() == 0 )
@@ -1079,7 +1130,7 @@
   tabServers->setCurrentIndex( 0 );
 }
 
-void QgsWMSSourceSelect::wmsSelectionChanged()
+void QgsWMSSourceSelect::on_tableWidgetWMSList_itemSelectionChanged()
 {
   btnAddWMS->setEnabled( tableWidgetWMSList->currentRow() != -1 );
 }

Modified: trunk/qgis/src/app/qgswmssourceselect.h
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.h	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/app/qgswmssourceselect.h	2010-03-28 20:18:07 UTC (rev 13184)
@@ -183,15 +183,16 @@
     QString selectedImageEncoding();
 
     QList<QTreeWidgetItem*> mCurrentSelection;
+    QTableWidgetItem* mCurrentTileset;
 
   private slots:
     void on_btnSearch_clicked();
     void on_btnAddWMS_clicked();
-    void wmsSelectionChanged();
+    void on_tableWidgetWMSList_itemSelectionChanged();
+    void on_lstTilesets_itemClicked( QTableWidgetItem *item );
     void on_mLayerUpButton_clicked();
     void on_mLayerDownButton_clicked();
     void updateButtons();
-
 };
 
 

Added: trunk/qgis/src/ui/qgstilescalewidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgstilescalewidgetbase.ui	                        (rev 0)
+++ trunk/qgis/src/ui/qgstilescalewidgetbase.ui	2010-03-28 20:18:07 UTC (rev 13184)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QgsTileScaleWidget</class>
+ <widget class="QWidget" name="QgsTileScaleWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>114</width>
+    <height>525</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QSlider" name="mSlider">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="invertedAppearance">
+      <bool>false</bool>
+     </property>
+     <property name="invertedControls">
+      <bool>false</bool>
+     </property>
+     <property name="tickPosition">
+      <enum>QSlider::TicksBelow</enum>
+     </property>
+     <property name="tickInterval">
+      <number>0</number>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

Modified: trunk/qgis/src/ui/qgswmssourceselectbase.ui
===================================================================
--- trunk/qgis/src/ui/qgswmssourceselectbase.ui	2010-03-28 15:34:08 UTC (rev 13183)
+++ trunk/qgis/src/ui/qgswmssourceselectbase.ui	2010-03-28 20:18:07 UTC (rev 13184)
@@ -260,6 +260,9 @@
       <layout class="QGridLayout" name="gridLayout_3">
        <item row="0" column="0">
         <widget class="QTableWidget" name="lstTilesets">
+         <property name="alternatingRowColors">
+          <bool>true</bool>
+         </property>
          <property name="selectionMode">
           <enum>QAbstractItemView::SingleSelection</enum>
          </property>



More information about the QGIS-commit mailing list