Skip to content

Commit 496935e

Browse files
author
jef
committedMar 28, 2010
[FEATURE] wms-c scale slider and more selection improvements
git-svn-id: http://svn.osgeo.org/qgis/trunk@13184 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8bc1638 commit 496935e

9 files changed

+318
-8
lines changed
 

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ SET(QGIS_APP_SRCS
6767
qgssinglesymboldialog.cpp
6868
qgssnappingdialog.cpp
6969
qgsundowidget.cpp
70+
qgstilescalewidget.cpp
7071
qgsuniquevaluedialog.cpp
7172
qgsvectorlayerproperties.cpp
7273
qgsquerybuilder.cpp
@@ -176,6 +177,7 @@ SET (QGIS_APP_MOC_HDRS
176177
qgsdbtablemodel.h
177178
qgsspatialitetablemodel.h
178179
qgsundowidget.h
180+
qgstilescalewidget.h
179181
qgsquerybuilder.h
180182

181183
composer/qgsattributeselectiondialog.h

‎src/app/qgisapp.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
#include "qgsvectorfilewriter.h"
154154
#include "qgscredentialdialog.h"
155155
#include "qgsnetworkproxyfactory.h"
156+
#include "qgstilescalewidget.h"
156157

157158
#ifdef HAVE_QWT
158159
#include "qgsgpsinformationwidget.h"
@@ -342,6 +343,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
342343
, mSplash( splash )
343344
, mPythonUtils( NULL )
344345
, mNAM( NULL )
346+
, mpTileScaleWidget( NULL )
345347
#ifdef HAVE_QWT
346348
, mpGpsWidget( NULL )
347349
#endif
@@ -374,8 +376,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
374376
mSplash->showMessage( tr( "Setting up the GUI" ), Qt::AlignHCenter | Qt::AlignBottom );
375377
qApp->processEvents();
376378

377-
378-
379379
createActions();
380380
createActionGroups();
381381
createMenus();
@@ -586,6 +586,11 @@ void QgisApp::readSettings()
586586
// Add the recently accessed project file paths to the File menu
587587
mRecentProjectPaths = settings.value( "/UI/recentProjectsList" ).toStringList();
588588

589+
// Restore state of tile scale widget
590+
if ( settings.value( "/UI/tileScaleEnabled", false ).toBool() )
591+
{
592+
showTileScale();
593+
}
589594
#if HAVE_QWT
590595
// Restore state of GPS Tracker
591596
if ( settings.value( "/gps/widgetEnabled", false ).toBool() )
@@ -983,6 +988,12 @@ void QgisApp::createActions()
983988
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
984989
mActionRemoveLayer->setEnabled( false );
985990

991+
mActionTileScale = new QAction( getThemeIcon( "mActionTileScale.png" ), tr( "Tile scale slider" ), this );
992+
shortcuts->registerAction( mActionTileScale, tr( "", "Tile scale slider" ) );
993+
mActionTileScale->setStatusTip( tr( "Show tile scale slider" ) );
994+
connect( mActionTileScale, SIGNAL( triggered() ), this, SLOT( showTileScale() ) );
995+
mActionTileScale->setEnabled( true );
996+
986997
#ifdef HAVE_QWT
987998
mActionGpsTool = new QAction( getThemeIcon( "mActionGpsTool.png" ), tr( "Live GPS tracking" ), this );
988999
shortcuts->registerAction( mActionGpsTool, tr( "", "Live GPS tracking" ) );
@@ -1352,6 +1363,9 @@ void QgisApp::createMenus()
13521363
mViewMenu->addMenu( mToolbarMenu );
13531364
mViewMenu->addAction( mActionToggleFullScreen );
13541365
}
1366+
1367+
mViewMenu->addAction( mActionTileScale );
1368+
13551369
#ifdef HAVE_QWT
13561370
mViewMenu->addAction( mActionGpsTool );
13571371
#endif
@@ -2193,6 +2207,17 @@ void QgisApp::saveWindowState()
21932207
// store window geometry
21942208
settings.setValue( "/UI/geometry", saveGeometry() );
21952209

2210+
// Persist state of tile scale slider
2211+
if ( mpTileScaleWidget )
2212+
{
2213+
settings.setValue( "/UI/tileScaleEnabled", true );
2214+
delete mpTileScaleWidget;
2215+
}
2216+
else
2217+
{
2218+
settings.setValue( "/UI/tileScaleEnabled", false );
2219+
}
2220+
21962221
#if HAVE_QWT
21972222
// Persist state of GPS Tracker
21982223
if ( mpGpsWidget )
@@ -4499,6 +4524,32 @@ void QgisApp::showGpsTool()
44994524
#endif
45004525
}
45014526

4527+
void QgisApp::showTileScale()
4528+
{
4529+
if ( !mpTileScaleWidget )
4530+
{
4531+
mpTileScaleWidget = new QgsTileScaleWidget( mMapCanvas );
4532+
//create the dock widget
4533+
mpTileScaleDock = new QDockWidget( tr( "Tile scale" ), this );
4534+
mpTileScaleDock->setObjectName( "TileScale" );
4535+
mpTileScaleDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
4536+
addDockWidget( Qt::RightDockWidgetArea, mpTileScaleDock );
4537+
// add to the Panel submenu
4538+
mPanelMenu->addAction( mpTileScaleDock->toggleViewAction() );
4539+
// now add our widget to the dock - ownership of the widget is passed to the dock
4540+
mpTileScaleDock->setWidget( mpTileScaleWidget );
4541+
mpTileScaleWidget->show();
4542+
4543+
connect( mMapLegend, SIGNAL( currentLayerChanged( QgsMapLayer* ) ),
4544+
mpTileScaleWidget, SLOT( layerChanged( QgsMapLayer* ) ) );
4545+
4546+
}
4547+
else
4548+
{
4549+
mpTileScaleDock->toggleViewAction();
4550+
}
4551+
}
4552+
45024553
void QgisApp::zoomToLayerExtent()
45034554
{
45044555
mMapLegend->legendLayerZoom();

‎src/app/qgisapp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class QgsRasterLayer;
5858
class QgsRectangle;
5959
class QgsUndoWidget;
6060
class QgsVectorLayer;
61+
class QgsTileScaleWidget;
6162

6263
class QDomDocument;
6364
class QNetworkAccessManager;
@@ -274,6 +275,7 @@ class QgisApp : public QMainWindow
274275
QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
275276
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
276277
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
278+
QAction *actionTileScale() { return mActionTileScale; }
277279
#ifdef HAVE_QWT
278280
QAction *actionGpsTool() { return mActionGpsTool; }
279281
#endif
@@ -444,6 +446,8 @@ class QgisApp : public QMainWindow
444446
void removeLayer();
445447
//! Show GPS tool
446448
void showGpsTool();
449+
//! Show tile scale slider
450+
void showTileScale();
447451
//! zoom to extent of layer
448452
void zoomToLayerExtent();
449453
//! zoom to actual size of raster layer
@@ -848,6 +852,7 @@ class QgisApp : public QMainWindow
848852
QAction *mActionLayerSaveAs;
849853
QAction *mActionLayerSelectionSaveAs;
850854
QAction *mActionRemoveLayer;
855+
QAction *mActionTileScale;
851856
#ifdef HAVE_QWT
852857
QAction *mActionGpsTool;
853858
#endif
@@ -911,6 +916,7 @@ class QgisApp : public QMainWindow
911916
// docks ------------------------------------------
912917
QDockWidget *mLegendDock;
913918
QDockWidget *mOverviewDock;
919+
QDockWidget *mpTileScaleDock;
914920
#ifdef HAVE_QWT
915921
QDockWidget *mpGpsDock;
916922
#endif
@@ -1062,6 +1068,9 @@ class QgisApp : public QMainWindow
10621068

10631069
int mLastComposerId;
10641070

1071+
//! Persistent tile scale slider
1072+
QgsTileScaleWidget * mpTileScaleWidget;
1073+
10651074
#ifdef HAVE_QWT
10661075
//! Persistent GPS toolbox
10671076
QgsGPSInformationWidget * mpGpsWidget;

‎src/app/qgstilescalewidget.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/***************************************************************************
2+
qgstilescalewidget.cpp - slider to choose wms-c resolutions
3+
-------------------
4+
begin : 28 Mar 2010
5+
copyright: (C) 2010 Juergen E. Fischer < jef at norbit dot de >
6+
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: $ */
18+
19+
#include "qgstilescalewidget.h"
20+
#include "qgsmapcanvas.h"
21+
#include "qgsrasterlayer.h"
22+
#include "qgslogger.h"
23+
24+
QgsTileScaleWidget::QgsTileScaleWidget( QgsMapCanvas * mapCanvas, QWidget * parent, Qt::WindowFlags f )
25+
: QWidget( parent, f )
26+
, mMapCanvas( mapCanvas )
27+
{
28+
setupUi( this );
29+
30+
connect( mMapCanvas, SIGNAL( scaleChanged( double ) ), this, SLOT( scaleChanged( double ) ) );
31+
32+
layerChanged( mMapCanvas->currentLayer() );
33+
}
34+
35+
void QgsTileScaleWidget::layerChanged( QgsMapLayer *layer )
36+
{
37+
QgsRasterLayer *rl = qobject_cast<QgsRasterLayer *>( layer );
38+
39+
if ( !rl || rl->providerKey() != "wms" || !rl->publicSource().contains( "tiled=" ) )
40+
{
41+
mResolutions.clear();
42+
mSlider->setDisabled( true );
43+
}
44+
else
45+
{
46+
QString uri = rl->publicSource().mid( rl->publicSource().indexOf( "tiled=" ) + 6 );
47+
int pos = uri.indexOf( "," );
48+
if ( pos >= 0 )
49+
uri = uri.left( pos );
50+
QStringList params = uri.split( ";" );
51+
52+
params.takeFirst();
53+
params.takeFirst();
54+
55+
mResolutions.clear();
56+
foreach( QString r, params )
57+
mResolutions << r.toDouble();
58+
qSort( mResolutions );
59+
60+
for ( int i = 0; i < mResolutions.size(); i++ )
61+
QgsDebugMsg( QString( "found resolution %1: %2" ).arg( i ).arg( mResolutions[i] ) );
62+
63+
mSlider->setRange( 0, mResolutions.size() - 1 );
64+
mSlider->setTickInterval( 1 );
65+
mSlider->setInvertedAppearance( true );
66+
mSlider->setPageStep( 1 );
67+
mSlider->setTracking( false );
68+
69+
scaleChanged( mMapCanvas->scale() );
70+
71+
mSlider->setEnabled( true );
72+
show();
73+
}
74+
}
75+
76+
void QgsTileScaleWidget::scaleChanged( double scale )
77+
{
78+
if ( mResolutions.size() == 0 )
79+
return;
80+
81+
double mupp = mMapCanvas->mapUnitsPerPixel();
82+
QgsDebugMsg( QString( "resolution changed to %1" ).arg( mupp ) );
83+
84+
int i;
85+
for ( i = 0; i < mResolutions.size() && mResolutions[i] < mupp; i++ )
86+
QgsDebugMsg( QString( "test resolution %1: %2 d:%3" ).arg( i ).arg( mResolutions[i] ).arg( mupp - mResolutions[i] ) );
87+
88+
if ( i == mResolutions.size() ||
89+
( i > 0 && mResolutions[i] - mupp > mupp - mResolutions[i-1] ) )
90+
{
91+
QgsDebugMsg( "previous resolution" );
92+
i--;
93+
}
94+
95+
QgsDebugMsg( QString( "selected resolution %1: %2" ).arg( i ).arg( mResolutions[i] ) );
96+
mSlider->setValue( i );
97+
}
98+
99+
void QgsTileScaleWidget::on_mSlider_valueChanged( int value )
100+
{
101+
QgsDebugMsg( QString( "slider released at %1: %2" ).arg( mSlider->value() ).arg( mResolutions[mSlider->value()] ) );
102+
mMapCanvas->zoomByFactor( mResolutions[mSlider->value()] / mMapCanvas->mapUnitsPerPixel() );
103+
}

‎src/app/qgstilescalewidget.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/***************************************************************************
2+
qgstilescalewidget.cpp - slider to choose wms-c resolutions
3+
-------------------
4+
begin : 28 Mar 2010
5+
copyright: (C) 2010 Juergen E. Fischer < jef at norbit dot de >
6+
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
/* $Id: $ */
18+
19+
#ifndef QGSTILESCALEWIDGET_H
20+
#define QGSTILESCALEWIDGET_H
21+
22+
#include "ui_qgstilescalewidgetbase.h"
23+
24+
class QgsMapCanvas;
25+
class QgsMapLayer;
26+
class QwtSlider;
27+
28+
class QgsTileScaleWidget : public QWidget, private Ui::QgsTileScaleWidget
29+
{
30+
Q_OBJECT
31+
public:
32+
QgsTileScaleWidget( QgsMapCanvas *mapCanvas, QWidget * parent = 0, Qt::WindowFlags f = 0 );
33+
34+
public slots:
35+
void layerChanged( QgsMapLayer *layer );
36+
void scaleChanged( double );
37+
void on_mSlider_valueChanged( int );
38+
39+
private:
40+
QgsMapCanvas *mMapCanvas;
41+
QList<double> mResolutions;
42+
};
43+
44+
#endif // QGSTILESCALEWIDGET

‎src/app/qgswmssourceselect.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <qgisinterface.h>
3737

3838
#include <QButtonGroup>
39+
#include <QRadioButton>
3940
#include <QDomDocument>
4041
#include <QHeaderView>
4142
#include <QImageReader>
@@ -52,6 +53,7 @@
5253

5354
QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl )
5455
: QDialog( parent, fl )
56+
, mCurrentTileset( 0 )
5557
{
5658
setupUi( this );
5759

@@ -156,9 +158,6 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget * parent, Qt::WFlags fl )
156158
tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), false );
157159
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), false );
158160

159-
connect( tableWidgetWMSList, SIGNAL( itemSelectionChanged() ), this, SLOT( wmsSelectionChanged() ) );
160-
connect( lstTilesets, SIGNAL( itemSelectionChanged() ), this, SLOT( updateButtons() ) );
161-
162161
QSettings settings;
163162
QgsDebugMsg( "restoring geometry" );
164163
restoreGeometry( settings.value( "/Windows/WMSSourceSelect/geometry" ).toByteArray() );
@@ -171,6 +170,7 @@ QgsWMSSourceSelect::~QgsWMSSourceSelect()
171170
settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
172171
}
173172

173+
174174
void QgsWMSSourceSelect::populateConnectionList()
175175
{
176176
QSettings settings;
@@ -204,6 +204,8 @@ void QgsWMSSourceSelect::on_btnNew_clicked()
204204
{
205205
populateConnectionList();
206206
}
207+
208+
delete nc;
207209
}
208210

209211
void QgsWMSSourceSelect::on_btnEdit_clicked()
@@ -214,6 +216,8 @@ void QgsWMSSourceSelect::on_btnEdit_clicked()
214216
{
215217
populateConnectionList();
216218
}
219+
220+
delete nc;
217221
}
218222

219223
void QgsWMSSourceSelect::on_btnDelete_clicked()
@@ -368,6 +372,12 @@ bool QgsWMSSourceSelect::populateLayerList( QgsWmsProvider *wmsProvider )
368372
lstTilesets->setItem( i, 3, new QTableWidgetItem( tilesets[i].format ) );
369373
lstTilesets->setItem( i, 4, new QTableWidgetItem( tilesets[i].crs ) );
370374

375+
for ( int j = 0; j < 5; j++ )
376+
{
377+
QTableWidgetItem *item = lstTilesets->item( i, j );
378+
item->setFlags( item->flags() & ~Qt::ItemIsEditable );
379+
}
380+
371381
if ( !mMimeMap.contains( tilesets[i].format ) )
372382
{
373383
for ( int j = 0; j < 5; j++ )
@@ -765,8 +775,49 @@ void QgsWMSSourceSelect::on_lstLayers_itemSelectionChanged()
765775
updateButtons();
766776
}
767777

778+
void QgsWMSSourceSelect::on_lstTilesets_itemClicked( QTableWidgetItem *item )
779+
{
780+
QTableWidgetItem *rowItem = lstTilesets->item( lstTilesets->currentRow(), 0 );
781+
bool wasSelected = mCurrentTileset == rowItem;
782+
783+
lstTilesets->blockSignals( true );
784+
lstTilesets->clearSelection();
785+
if ( !wasSelected )
786+
{
787+
QgsDebugMsg( QString( "selecting current row %1" ).arg( lstTilesets->currentRow() ) );
788+
lstTilesets->selectRow( lstTilesets->currentRow() );
789+
mCurrentTileset = rowItem;
790+
}
791+
else
792+
{
793+
mCurrentTileset = 0;
794+
}
795+
lstTilesets->blockSignals( false );
796+
797+
updateButtons();
798+
}
799+
768800
void QgsWMSSourceSelect::updateButtons()
769801
{
802+
if ( !lstTilesets->selectedItems().isEmpty() )
803+
{
804+
// tileset selected => disable layer selection and layer order
805+
lstLayers->setEnabled( false );
806+
tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), false );
807+
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), lstTilesets->rowCount() > 0 );
808+
btnGrpImageEncoding->setEnabled( false );
809+
}
810+
else
811+
{
812+
// no tileset selected =>
813+
// disable layerorder, when no layers selected
814+
// disable tilesets, when layer are selected or no tilesets available
815+
lstLayers->setEnabled( true );
816+
tabServers->setTabEnabled( tabServers->indexOf( tabLayerOrder ), mLayerOrderTreeWidget->topLevelItemCount() > 0 );
817+
tabServers->setTabEnabled( tabServers->indexOf( tabTilesets ), mLayerOrderTreeWidget->topLevelItemCount() == 0 && lstTilesets->rowCount() );
818+
btnGrpImageEncoding->setEnabled( true );
819+
}
820+
770821
if ( lstTilesets->selectedItems().isEmpty() && mLayerOrderTreeWidget->topLevelItemCount() == 0 )
771822
{
772823
if ( lstTilesets->rowCount() == 0 )
@@ -1079,7 +1130,7 @@ void QgsWMSSourceSelect::on_btnAddWMS_clicked()
10791130
tabServers->setCurrentIndex( 0 );
10801131
}
10811132

1082-
void QgsWMSSourceSelect::wmsSelectionChanged()
1133+
void QgsWMSSourceSelect::on_tableWidgetWMSList_itemSelectionChanged()
10831134
{
10841135
btnAddWMS->setEnabled( tableWidgetWMSList->currentRow() != -1 );
10851136
}

‎src/app/qgswmssourceselect.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,16 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
183183
QString selectedImageEncoding();
184184

185185
QList<QTreeWidgetItem*> mCurrentSelection;
186+
QTableWidgetItem* mCurrentTileset;
186187

187188
private slots:
188189
void on_btnSearch_clicked();
189190
void on_btnAddWMS_clicked();
190-
void wmsSelectionChanged();
191+
void on_tableWidgetWMSList_itemSelectionChanged();
192+
void on_lstTilesets_itemClicked( QTableWidgetItem *item );
191193
void on_mLayerUpButton_clicked();
192194
void on_mLayerDownButton_clicked();
193195
void updateButtons();
194-
195196
};
196197

197198

‎src/ui/qgstilescalewidgetbase.ui

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsTileScaleWidget</class>
4+
<widget class="QWidget" name="QgsTileScaleWidget">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>114</width>
10+
<height>525</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="windowTitle">
20+
<string>Form</string>
21+
</property>
22+
<layout class="QHBoxLayout" name="horizontalLayout">
23+
<item>
24+
<widget class="QSlider" name="mSlider">
25+
<property name="orientation">
26+
<enum>Qt::Vertical</enum>
27+
</property>
28+
<property name="invertedAppearance">
29+
<bool>false</bool>
30+
</property>
31+
<property name="invertedControls">
32+
<bool>false</bool>
33+
</property>
34+
<property name="tickPosition">
35+
<enum>QSlider::TicksBelow</enum>
36+
</property>
37+
<property name="tickInterval">
38+
<number>0</number>
39+
</property>
40+
</widget>
41+
</item>
42+
</layout>
43+
</widget>
44+
<resources/>
45+
<connections/>
46+
</ui>

‎src/ui/qgswmssourceselectbase.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@
260260
<layout class="QGridLayout" name="gridLayout_3">
261261
<item row="0" column="0">
262262
<widget class="QTableWidget" name="lstTilesets">
263+
<property name="alternatingRowColors">
264+
<bool>true</bool>
265+
</property>
263266
<property name="selectionMode">
264267
<enum>QAbstractItemView::SingleSelection</enum>
265268
</property>

0 commit comments

Comments
 (0)
Please sign in to comment.