Skip to content

Commit 48a0612

Browse files
committed
adding touch maptool that allows panning, pinch zooming, double tap zoomWithCenter, twofinger tap zoomOut
fixed toolbar button functionality
1 parent 3d53e29 commit 48a0612

14 files changed

+356
-26
lines changed

images/images.qrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<file>themes/default/mActionNewFolder.png</file>
109109
<file>themes/default/mActionNewVectorLayer.png</file>
110110
<file>themes/default/mActionNodeTool.png</file>
111-
<file>themes/default/mActionOffsetCurve.png</file>
111+
<file>themes/default/mActionOffsetCurve.png</file>
112112
<file>themes/default/mActionOpenTable.png</file>
113113
<file>themes/default/mActionOptions.png</file>
114114
<file>themes/default/mActionPan.png</file>
@@ -366,7 +366,10 @@
366366
<file>themes/gis/mIconMssql.png</file>
367367
<file>themes/gis/mIconConnect.png</file>
368368
<file>themes/gis/mIconDbSchema.png</file>
369+
<file>themes/gis/mActionTouch.png</file>
369370
<file>themes/default/mActionAddMssqlLayer.png</file>
371+
<file>themes/default/mActionTouch.png</file>
372+
<file>themes/classic/mActionTouch.png</file>
370373
</qresource>
371374
<qresource prefix="/images/tips">
372375
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
2.15 KB
Loading
2.15 KB
Loading

images/themes/gis/mActionTouch.png

2.15 KB
Loading

src/app/qgisapp.cpp

+65-20
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ extern "C"
258258
#include <windows.h>
259259
#endif
260260

261+
#ifdef HAVE_TOUCH
262+
#include "qgsmaptooltouch.h"
263+
#endif
264+
261265
class QTreeWidgetItem;
262266

263267

@@ -626,7 +630,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
626630
// request notification of FileOpen events (double clicking a file icon in Mac OS X Finder)
627631
QgsApplication::setFileOpenEventReceiver( this );
628632

629-
#ifdef ANDROID
633+
#ifdef HAVE_TOUCH
630634
//add reacting to long click in android
631635
grabGesture( Qt::TapAndHoldGesture );
632636
#endif
@@ -646,6 +650,9 @@ QgisApp::~QgisApp()
646650
delete mMapTools.mZoomIn;
647651
delete mMapTools.mZoomOut;
648652
delete mMapTools.mPan;
653+
#ifdef HAVE_TOUCH
654+
delete mMapTools.mTouch;
655+
#endif
649656
delete mMapTools.mIdentify;
650657
delete mMapTools.mFeatureAction;
651658
delete mMapTools.mMeasureDist;
@@ -741,8 +748,8 @@ bool QgisApp::event( QEvent * event )
741748
openFile( foe->file() );
742749
done = true;
743750
}
744-
#ifdef ANDROID
745-
else if ( event->type() == QEvent::Gesture )
751+
#ifdef HAVE_TOUCH
752+
else if (event->type() == QEvent::Gesture )
746753
{
747754
done = gestureEvent( static_cast<QGestureEvent*>( event ) );
748755
}
@@ -820,6 +827,9 @@ void QgisApp::createActions()
820827

821828
// View Menu Items
822829

830+
#ifdef HAVE_TOUCH
831+
connect( mActionTouch, SIGNAL( triggered() ), this, SLOT( touch() ) );
832+
#endif
823833
connect( mActionPan, SIGNAL( triggered() ), this, SLOT( pan() ) );
824834
connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) );
825835
connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) );
@@ -1009,6 +1019,9 @@ void QgisApp::createActionGroups()
10091019
//
10101020
// Map Tool Group
10111021
mMapToolGroup = new QActionGroup( this );
1022+
#ifdef HAVE_TOUCH
1023+
mMapToolGroup->addAction( mActionTouch );
1024+
#endif
10121025
mMapToolGroup->addAction( mActionPan );
10131026
mMapToolGroup->addAction( mActionZoomIn );
10141027
mMapToolGroup->addAction( mActionZoomOut );
@@ -1529,6 +1542,9 @@ void QgisApp::setTheme( QString theThemeName )
15291542
mActionZoomOut->setIcon( getThemeIcon( "/mActionZoomOut.png" ) );
15301543
mActionZoomFullExtent->setIcon( getThemeIcon( "/mActionZoomFullExtent.png" ) );
15311544
mActionZoomToSelected->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
1545+
#ifdef HAVE_TOUCH
1546+
mActionTouch->setIcon( getThemeIcon( "/mActionTouch.png" ) );
1547+
#endif
15321548
mActionPan->setIcon( getThemeIcon( "/mActionPan.png" ) );
15331549
mActionZoomLast->setIcon( getThemeIcon( "/mActionZoomLast.png" ) );
15341550
mActionZoomNext->setIcon( getThemeIcon( "/mActionZoomNext.png" ) );
@@ -1660,6 +1676,10 @@ void QgisApp::createCanvasTools()
16601676
mMapTools.mZoomOut->setAction( mActionZoomOut );
16611677
mMapTools.mPan = new QgsMapToolPan( mMapCanvas );
16621678
mMapTools.mPan->setAction( mActionPan );
1679+
#ifdef HAVE_TOUCH
1680+
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
1681+
mMapTools.mTouch->setAction( mActionTouch );
1682+
#endif
16631683
mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas );
16641684
mMapTools.mIdentify->setAction( mActionIdentify );
16651685
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
@@ -1725,6 +1745,9 @@ void QgisApp::createCanvasTools()
17251745
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
17261746
//ensure that non edit tool is initialised or we will get crashes in some situations
17271747
mNonEditMapTool = mMapTools.mPan;
1748+
//#ifdef HAVE_TOUCH
1749+
// mNonEditMapTool = mMapTools.mTouch;
1750+
//#endif
17281751
}
17291752

17301753
void QgisApp::createOverview()
@@ -2275,10 +2298,11 @@ bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QS
22752298
// present a dialog to choose GDAL raster sublayers
22762299
void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
22772300
{
2278-
if ( !layer || layer->subLayers().size() < 1 )
2301+
if ( !layer )
22792302
return;
22802303

22812304
QStringList sublayers = layer->subLayers();
2305+
22822306
QgsDebugMsg( "sublayers:\n " + sublayers.join( " \n" ) + "\n" );
22832307

22842308
// if promptLayers=Load all, load all sublayers without prompting
@@ -2303,7 +2327,16 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
23032327

23042328
if ( chooseSublayersDialog.exec() )
23052329
{
2306-
loadGDALSublayers( layer->source(), chooseSublayersDialog.getSelection() );
2330+
foreach( QString path, chooseSublayersDialog.getSelection() )
2331+
{
2332+
QString name = path;
2333+
name.replace( layer->source(), QFileInfo( layer->source() ).completeBaseName() );
2334+
QgsRasterLayer *rlayer = new QgsRasterLayer( path, name );
2335+
if ( rlayer && rlayer->isValid() )
2336+
{
2337+
addRasterLayer( rlayer );
2338+
}
2339+
}
23072340
}
23082341
}
23092342

@@ -2316,9 +2349,11 @@ bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
23162349

23172350
QSettings settings;
23182351
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", 1 ).toInt();
2352+
// 0 = always -> always ask (if there are existing sublayers)
2353+
// 1 = if needed -> ask if layer has no bands, but has sublayers
2354+
// 2 = never
23192355

2320-
// return true if promptLayers=Always or if promptLayers!=Never and there are no bands
2321-
return promptLayers == 0 || ( promptLayers != 2 && layer->bandCount() == 0 );
2356+
return promptLayers == 0 || ( promptLayers == 1 && layer->bandCount() == 0 );
23222357
}
23232358

23242359
// This method will load with GDAL the layers in parameter.
@@ -2732,6 +2767,10 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
27322767
// set the initial map tool
27332768
mMapCanvas->setMapTool( mMapTools.mPan );
27342769
mNonEditMapTool = mMapTools.mPan; // signals are not yet setup to catch this
2770+
#ifdef HAVE_TOUCH
2771+
mMapCanvas->setMapTool( mMapTools.mTouch );
2772+
mNonEditMapTool = mMapTools.mTouch; // signals are not yet setup to catch this
2773+
#endif
27352774
} // QgisApp::fileNew(bool thePromptToSaveFlag)
27362775

27372776

@@ -2821,11 +2860,7 @@ void QgisApp::fileOpen()
28212860
deletePrintComposers();
28222861
removeAnnotationItems();
28232862
// clear out any stuff from previous project
2824-
2825-
//avoid multiple canvas redraws during loading of project files
2826-
bool bkRenderFlag = mMapCanvas->renderFlag();
2827-
mMapCanvas->setRenderFlag( false );
2828-
2863+
mMapCanvas->freeze( true );
28292864
removeAllLayers();
28302865

28312866
QgsProject::instance()->setFileName( fullPath );
@@ -2835,7 +2870,8 @@ void QgisApp::fileOpen()
28352870
QMessageBox::critical( this,
28362871
tr( "QGIS Project Read Error" ),
28372872
QgsProject::instance()->error() );
2838-
mMapCanvas->setRenderFlag( bkRenderFlag );
2873+
mMapCanvas->freeze( false );
2874+
mMapCanvas->refresh();
28392875
return;
28402876
}
28412877

@@ -2847,7 +2883,8 @@ void QgisApp::fileOpen()
28472883
// add this to the list of recently used project files
28482884
saveRecentProjectPath( fullPath, settings );
28492885

2850-
mMapCanvas->setRenderFlag( bkRenderFlag );
2886+
mMapCanvas->freeze( false );
2887+
mMapCanvas->refresh();
28512888
}
28522889

28532890
} // QgisApp::fileOpen
@@ -2859,8 +2896,7 @@ void QgisApp::fileOpen()
28592896
*/
28602897
bool QgisApp::addProject( QString projectFile )
28612898
{
2862-
bool bkRenderFlag = mMapCanvas->renderFlag();
2863-
mMapCanvas->setRenderFlag( false );
2899+
mMapCanvas->freeze( true );
28642900

28652901
QApplication::setOverrideCursor( Qt::WaitCursor );
28662902

@@ -2878,7 +2914,8 @@ bool QgisApp::addProject( QString projectFile )
28782914

28792915
QApplication::restoreOverrideCursor();
28802916

2881-
mMapCanvas->setRenderFlag( bkRenderFlag );
2917+
mMapCanvas->freeze( false );
2918+
mMapCanvas->refresh();
28822919
return false;
28832920
}
28842921

@@ -2914,7 +2951,8 @@ bool QgisApp::addProject( QString projectFile )
29142951

29152952
QApplication::restoreOverrideCursor();
29162953

2917-
mMapCanvas->setRenderFlag( bkRenderFlag );
2954+
mMapCanvas->freeze( false );
2955+
mMapCanvas->refresh();
29182956
return true;
29192957
} // QgisApp::addProject(QString projectFile)
29202958

@@ -3362,6 +3400,13 @@ void QgisApp::pan()
33623400
mMapCanvas->setMapTool( mMapTools.mPan );
33633401
}
33643402

3403+
#ifdef HAVE_TOUCH
3404+
void QgisApp::touch()
3405+
{
3406+
mMapCanvas->setMapTool( mMapTools.mTouch );
3407+
}
3408+
#endif
3409+
33653410
void QgisApp::zoomFull()
33663411
{
33673412
mMapCanvas->zoomToFullExtent();
@@ -7361,8 +7406,8 @@ QMenu* QgisApp::createPopupMenu()
73617406
return menu;
73627407
}
73637408

7364-
#ifdef ANDROID
7365-
bool QgisApp::gestureEvent( QGestureEvent *event )
7409+
#ifdef HAVE_TOUCH
7410+
bool QgisApp::gestureEvent(QGestureEvent *event)
73667411
{
73677412
if ( QGesture *tapAndHold = event->gesture( Qt::TapAndHoldGesture ) )
73687413
{

src/app/qgisapp.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class QgsScaleComboBox;
8383
#include <QPointer>
8484
#include <QSslError>
8585

86-
#ifdef ANDROID
86+
#ifdef HAVE_TOUCH
8787
#include <QGestureEvent>
8888
#include <QTapAndHoldGesture>
8989
#endif
@@ -244,6 +244,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
244244
QAction *actionSnappingOptions() { return mActionSnappingOptions; }
245245
QAction *actionOffsetCurve() { return mActionOffsetCurve; }
246246

247+
#ifdef HAVE_TOUCH
248+
QAction *actionTouch() { return mActionTouch; }
249+
#endif
250+
247251
QAction *actionPan() { return mActionPan; }
248252
QAction *actionPanToSelected() { return mActionPanToSelected; }
249253
QAction *actionZoomIn() { return mActionZoomIn; }
@@ -767,6 +771,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
767771
void zoomIn();
768772
//! Set map tool to pan
769773
void pan();
774+
#ifdef HAVE_TOUCH
775+
//! Set map tool to touch
776+
void touch();
777+
#endif
770778
//! Identify feature(s) on the currently selected layer
771779
void identify();
772780
//! Measure distance
@@ -992,6 +1000,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
9921000
QgsMapTool* mZoomIn;
9931001
QgsMapTool* mZoomOut;
9941002
QgsMapTool* mPan;
1003+
#ifdef HAVE_TOUCH
1004+
QgsMapTool* mTouch;
1005+
#endif
9951006
QgsMapTool* mIdentify;
9961007
QgsMapTool* mFeatureAction;
9971008
QgsMapTool* mMeasureDist;
@@ -1169,9 +1180,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
11691180

11701181
QString mOldScale;
11711182

1172-
#ifdef ANDROID
1173-
bool gestureEvent( QGestureEvent *event );
1174-
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
1183+
#ifdef HAVE_TOUCH
1184+
bool gestureEvent(QGestureEvent *event);
1185+
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
11751186
#endif
11761187
};
11771188

src/gui/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ qgsexpressionhighlighter.cpp
8080
qgsquerybuilder.cpp
8181
)
8282

83+
IF (WITH_TOUCH)
84+
SET(QGIS_GUI_SRCS
85+
${QGIS_GUI_SRCS}
86+
qgsmaptooltouch.cpp
87+
)
88+
ENDIF (WITH_TOUCH)
89+
8390
SET(QGIS_GUI_MOC_HDRS
8491

8592
symbology-ng/qgsdashspacedialog.h
@@ -185,6 +192,13 @@ attributetable/qgsattributetableidcolumnpair.h
185192
attributetable/qgsattributetabledelegate.h
186193
)
187194

195+
IF (WITH_TOUCH)
196+
SET(QGIS_GUI_HDRS
197+
${QGIS_GUI_HDRS}
198+
qgsmaptooltouch.h
199+
)
200+
ENDIF (WITH_TOUCH)
201+
188202
SET(QGIS_GUI_UI_HDRS
189203
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
190204
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsgenericprojectionselectorbase.h

src/gui/qgsmapcanvas.cpp

+26-1
Original file line numberDiff line numberDiff line change
@@ -1559,4 +1559,29 @@ void QgsMapCanvas::mapToolDestroyed()
15591559
{
15601560
QgsDebugMsg( "maptool destroyed" );
15611561
mMapTool = 0;
1562-
}
1562+
}
1563+
1564+
#ifdef HAVE_TOUCH
1565+
bool QgsMapCanvas::event( QEvent * e )
1566+
{
1567+
bool done = false;
1568+
if ( mDrawing )
1569+
{
1570+
return done;
1571+
}
1572+
if (e->type() == QEvent::Gesture )
1573+
{
1574+
// call handler of current map tool
1575+
if ( mMapTool )
1576+
{
1577+
done = mMapTool->gestureEvent( static_cast<QGestureEvent*>(e) );
1578+
}
1579+
}
1580+
else
1581+
{
1582+
// pass other events to base class
1583+
done = QGraphicsView::event( e );
1584+
}
1585+
return done;
1586+
}
1587+
#endif

src/gui/qgsmapcanvas.h

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include <QGraphicsView>
3131
#include <QtCore>
3232

33+
#ifdef HAVE_TOUCH
34+
#include <QGestureEvent>
35+
#endif
36+
3337
class QWheelEvent;
3438
class QPixmap;
3539
class QPaintEvent;
@@ -357,6 +361,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
357361
void zoomNextStatusChanged( bool );
358362

359363
protected:
364+
#ifdef HAVE_TOUCH
365+
//! Overridden standard event to be gestures aware
366+
bool event( QEvent * e );
367+
#endif
368+
360369
//! Overridden key press event
361370
void keyPressEvent( QKeyEvent * e );
362371

0 commit comments

Comments
 (0)