Skip to content
Permalink
Browse files
[FEATURE] wms-c scale slider and more selection improvements
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 496935e9e623835bcd401eb455b098068513fe9c
@@ -67,6 +67,7 @@ SET(QGIS_APP_SRCS
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgsundowidget.cpp
qgstilescalewidget.cpp
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
@@ -176,6 +177,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdbtablemodel.h
qgsspatialitetablemodel.h
qgsundowidget.h
qgstilescalewidget.h
qgsquerybuilder.h

composer/qgsattributeselectiondialog.h
@@ -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 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
, mSplash( splash )
, mPythonUtils( NULL )
, mNAM( NULL )
, mpTileScaleWidget( NULL )
#ifdef HAVE_QWT
, mpGpsWidget( NULL )
#endif
@@ -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();
@@ -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() )
@@ -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" ) );
@@ -1352,6 +1363,9 @@ void QgisApp::createMenus()
mViewMenu->addMenu( mToolbarMenu );
mViewMenu->addAction( mActionToggleFullScreen );
}

mViewMenu->addAction( mActionTileScale );

#ifdef HAVE_QWT
mViewMenu->addAction( mActionGpsTool );
#endif
@@ -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 )
@@ -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();
@@ -58,6 +58,7 @@ class QgsRasterLayer;
class QgsRectangle;
class QgsUndoWidget;
class QgsVectorLayer;
class QgsTileScaleWidget;

class QDomDocument;
class QNetworkAccessManager;
@@ -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
@@ -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
@@ -848,6 +852,7 @@ class QgisApp : public QMainWindow
QAction *mActionLayerSaveAs;
QAction *mActionLayerSelectionSaveAs;
QAction *mActionRemoveLayer;
QAction *mActionTileScale;
#ifdef HAVE_QWT
QAction *mActionGpsTool;
#endif
@@ -911,6 +916,7 @@ class QgisApp : public QMainWindow
// docks ------------------------------------------
QDockWidget *mLegendDock;
QDockWidget *mOverviewDock;
QDockWidget *mpTileScaleDock;
#ifdef HAVE_QWT
QDockWidget *mpGpsDock;
#endif
@@ -1062,6 +1068,9 @@ class QgisApp : public QMainWindow

int mLastComposerId;

//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

#ifdef HAVE_QWT
//! Persistent GPS toolbox
QgsGPSInformationWidget * mpGpsWidget;
@@ -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() );
}
@@ -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

0 comments on commit 496935e

Please sign in to comment.