Skip to content

Commit

Permalink
[FEATURE] wms-c scale slider and more selection improvements
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13184 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 28, 2010
1 parent 8bc1638 commit 496935e
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SET(QGIS_APP_SRCS
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgsundowidget.cpp
qgstilescalewidget.cpp
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
Expand Down Expand Up @@ -176,6 +177,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdbtablemodel.h
qgsspatialitetablemodel.h
qgsundowidget.h
qgstilescalewidget.h
qgsquerybuilder.h

composer/qgsattributeselectiondialog.h
Expand Down
55 changes: 53 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#include "qgsvectorfilewriter.h"
#include "qgscredentialdialog.h"
#include "qgsnetworkproxyfactory.h"
#include "qgstilescalewidget.h"

#ifdef HAVE_QWT
#include "qgsgpsinformationwidget.h"
Expand Down Expand Up @@ -342,6 +343,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mSplash( splash )
, mPythonUtils( NULL )
, mNAM( NULL )
, mpTileScaleWidget( NULL )
#ifdef HAVE_QWT
, mpGpsWidget( NULL )
#endif
Expand Down Expand Up @@ -374,8 +376,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mSplash->showMessage( tr( "Setting up the GUI" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();



createActions();
createActionGroups();
createMenus();
Expand Down Expand Up @@ -586,6 +586,11 @@ void QgisApp::readSettings()
// 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() )
Expand Down Expand Up @@ -983,6 +988,12 @@ void QgisApp::createActions()
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" ) );
Expand Down Expand Up @@ -1352,6 +1363,9 @@ void QgisApp::createMenus()
mViewMenu->addMenu( mToolbarMenu );
mViewMenu->addAction( mActionToggleFullScreen );
}

mViewMenu->addAction( mActionTileScale );

#ifdef HAVE_QWT
mViewMenu->addAction( mActionGpsTool );
#endif
Expand Down Expand Up @@ -2193,6 +2207,17 @@ void QgisApp::saveWindowState()
// 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 )
Expand Down Expand Up @@ -4499,6 +4524,32 @@ void QgisApp::showGpsTool()
#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();
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class QgsRasterLayer;
class QgsRectangle;
class QgsUndoWidget;
class QgsVectorLayer;
class QgsTileScaleWidget;

class QDomDocument;
class QNetworkAccessManager;
Expand Down Expand Up @@ -274,6 +275,7 @@ class QgisApp : public QMainWindow
QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
QAction *actionTileScale() { return mActionTileScale; }
#ifdef HAVE_QWT
QAction *actionGpsTool() { return mActionGpsTool; }
#endif
Expand Down Expand Up @@ -444,6 +446,8 @@ class QgisApp : public QMainWindow
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
Expand Down Expand Up @@ -848,6 +852,7 @@ class QgisApp : public QMainWindow
QAction *mActionLayerSaveAs;
QAction *mActionLayerSelectionSaveAs;
QAction *mActionRemoveLayer;
QAction *mActionTileScale;
#ifdef HAVE_QWT
QAction *mActionGpsTool;
#endif
Expand Down Expand Up @@ -911,6 +916,7 @@ class QgisApp : public QMainWindow
// docks ------------------------------------------
QDockWidget *mLegendDock;
QDockWidget *mOverviewDock;
QDockWidget *mpTileScaleDock;
#ifdef HAVE_QWT
QDockWidget *mpGpsDock;
#endif
Expand Down Expand Up @@ -1062,6 +1068,9 @@ class QgisApp : public QMainWindow

int mLastComposerId;

//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

#ifdef HAVE_QWT
//! Persistent GPS toolbox
QgsGPSInformationWidget * mpGpsWidget;
Expand Down
103 changes: 103 additions & 0 deletions src/app/qgstilescalewidget.cpp
Original file line number Diff line number Diff line change
@@ -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() );
}
44 changes: 44 additions & 0 deletions src/app/qgstilescalewidget.h
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 496935e

Please sign in to comment.