Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FEATURE] wms-c scale slider and more selection improvements
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13184 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
jef
committed
Mar 28, 2010
1 parent
70aaa00
commit de5a7e6
Showing
9 changed files
with
318 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.