Skip to content

Commit 34f10f1

Browse files
committedMar 31, 2012
Merge pull request #112 from mbernasocchi/android
Android goodies (touch maptool, with-touch mode, ui edits, ...)
2 parents 401aea2 + 76ba1f6 commit 34f10f1

20 files changed

+401
-32
lines changed
 

‎CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,30 @@ IF (ANDROID)
8787
ELSE (ANDROID)
8888
SET (DEFAULT_WITH_QTMOBILITY FALSE)
8989
ENDIF (ANDROID)
90-
SET (WITH_QTMOBILITY ${DEFAULT_WITH_QTMOBILITY} CACHE BOOL "Determines QtMobility related code should be build (for example internal GPS)")
90+
SET (WITH_QTMOBILITY ${DEFAULT_WITH_QTMOBILITY} CACHE BOOL "Determines if QtMobility related code should be build (for example internal GPS)")
9191
IF (WITH_QTMOBILITY)
9292
FIND_PACKAGE(QtMobility 1.1.0)
9393
ENDIF (WITH_QTMOBILITY)
9494

95+
IF (ANDROID)
96+
SET (DEFAULT_WITH_TOUCH TRUE)
97+
ELSE (ANDROID)
98+
SET (DEFAULT_WITH_TOUCH FALSE)
99+
ENDIF (ANDROID)
100+
#Add a touch mode if Qt has Qt Gestures (starting from 4.6)
101+
IF ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
102+
SET (WITH_TOUCH ${DEFAULT_WITH_TOUCH} CACHE BOOL "Determines if touch interface related code should be build")
103+
ELSE ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
104+
SET (WITH_TOUCH FALSE)
105+
ENDIF ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
106+
IF (WITH_TOUCH)
107+
ADD_DEFINITIONS(-DHAVE_TOUCH)
108+
MESSAGE (STATUS "Touch support enabled")
109+
ELSE (WITH_TOUCH)
110+
MESSAGE (STATUS "Touch support disabled")
111+
ENDIF (WITH_TOUCH)
112+
113+
95114
SET (WITH_GLOBE FALSE CACHE BOOL "Determines whether Globe plugin should be built")
96115
IF (WITH_GLOBE)
97116
SET(QT_USE_QTOPENGL 1)
@@ -472,9 +491,7 @@ LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/core ${CMAKE_BINARY_DIR}/src/gui)
472491

473492
#############################################################
474493
# create qgsversion.h
475-
476494
FIND_FILE(GIT_MARKER index PATHS ${CMAKE_SOURCE_DIR}/.git)
477-
478495
IF (GIT_MARKER)
479496
FIND_PROGRAM(GIT git PATHS c:/cygwin/bin)
480497
IF(GIT)

‎images/images.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@
374374
<file>themes/gis/mIconMssql.png</file>
375375
<file>themes/gis/mIconConnect.png</file>
376376
<file>themes/gis/mIconDbSchema.png</file>
377+
<file>themes/gis/mActionTouch.png</file>
377378
<file>themes/default/mActionAddMssqlLayer.png</file>
379+
<file>themes/default/mActionTouch.png</file>
380+
<file>themes/classic/mActionTouch.png</file>
378381
</qresource>
379382
<qresource prefix="/images/tips">
380383
<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

Lines changed: 65 additions & 20 deletions
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

@@ -638,7 +642,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
638642
// request notification of FileOpen events (double clicking a file icon in Mac OS X Finder)
639643
QgsApplication::setFileOpenEventReceiver( this );
640644

641-
#ifdef ANDROID
645+
#ifdef HAVE_TOUCH
642646
//add reacting to long click in android
643647
grabGesture( Qt::TapAndHoldGesture );
644648
#endif
@@ -658,6 +662,9 @@ QgisApp::~QgisApp()
658662
delete mMapTools.mZoomIn;
659663
delete mMapTools.mZoomOut;
660664
delete mMapTools.mPan;
665+
#ifdef HAVE_TOUCH
666+
delete mMapTools.mTouch;
667+
#endif
661668
delete mMapTools.mIdentify;
662669
delete mMapTools.mFeatureAction;
663670
delete mMapTools.mMeasureDist;
@@ -753,8 +760,8 @@ bool QgisApp::event( QEvent * event )
753760
openFile( foe->file() );
754761
done = true;
755762
}
756-
#ifdef ANDROID
757-
else if ( event->type() == QEvent::Gesture )
763+
#ifdef HAVE_TOUCH
764+
else if (event->type() == QEvent::Gesture )
758765
{
759766
done = gestureEvent( static_cast<QGestureEvent*>( event ) );
760767
}
@@ -832,6 +839,9 @@ void QgisApp::createActions()
832839

833840
// View Menu Items
834841

842+
#ifdef HAVE_TOUCH
843+
connect( mActionTouch, SIGNAL( triggered() ), this, SLOT( touch() ) );
844+
#endif
835845
connect( mActionPan, SIGNAL( triggered() ), this, SLOT( pan() ) );
836846
connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) );
837847
connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) );
@@ -1021,6 +1031,9 @@ void QgisApp::createActionGroups()
10211031
//
10221032
// Map Tool Group
10231033
mMapToolGroup = new QActionGroup( this );
1034+
#ifdef HAVE_TOUCH
1035+
mMapToolGroup->addAction( mActionTouch );
1036+
#endif
10241037
mMapToolGroup->addAction( mActionPan );
10251038
mMapToolGroup->addAction( mActionZoomIn );
10261039
mMapToolGroup->addAction( mActionZoomOut );
@@ -1541,6 +1554,9 @@ void QgisApp::setTheme( QString theThemeName )
15411554
mActionZoomOut->setIcon( getThemeIcon( "/mActionZoomOut.png" ) );
15421555
mActionZoomFullExtent->setIcon( getThemeIcon( "/mActionZoomFullExtent.png" ) );
15431556
mActionZoomToSelected->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
1557+
#ifdef HAVE_TOUCH
1558+
mActionTouch->setIcon( getThemeIcon( "/mActionTouch.png" ) );
1559+
#endif
15441560
mActionPan->setIcon( getThemeIcon( "/mActionPan.png" ) );
15451561
mActionZoomLast->setIcon( getThemeIcon( "/mActionZoomLast.png" ) );
15461562
mActionZoomNext->setIcon( getThemeIcon( "/mActionZoomNext.png" ) );
@@ -1672,6 +1688,10 @@ void QgisApp::createCanvasTools()
16721688
mMapTools.mZoomOut->setAction( mActionZoomOut );
16731689
mMapTools.mPan = new QgsMapToolPan( mMapCanvas );
16741690
mMapTools.mPan->setAction( mActionPan );
1691+
#ifdef HAVE_TOUCH
1692+
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
1693+
mMapTools.mTouch->setAction( mActionTouch );
1694+
#endif
16751695
mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas );
16761696
mMapTools.mIdentify->setAction( mActionIdentify );
16771697
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
@@ -1737,6 +1757,9 @@ void QgisApp::createCanvasTools()
17371757
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
17381758
//ensure that non edit tool is initialised or we will get crashes in some situations
17391759
mNonEditMapTool = mMapTools.mPan;
1760+
//#ifdef HAVE_TOUCH
1761+
// mNonEditMapTool = mMapTools.mTouch;
1762+
//#endif
17401763
}
17411764

17421765
void QgisApp::createOverview()
@@ -2287,10 +2310,11 @@ bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QS
22872310
// present a dialog to choose GDAL raster sublayers
22882311
void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
22892312
{
2290-
if ( !layer || layer->subLayers().size() < 1 )
2313+
if ( !layer )
22912314
return;
22922315

22932316
QStringList sublayers = layer->subLayers();
2317+
22942318
QgsDebugMsg( "sublayers:\n " + sublayers.join( " \n" ) + "\n" );
22952319

22962320
// if promptLayers=Load all, load all sublayers without prompting
@@ -2315,7 +2339,16 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
23152339

23162340
if ( chooseSublayersDialog.exec() )
23172341
{
2318-
loadGDALSublayers( layer->source(), chooseSublayersDialog.getSelection() );
2342+
foreach( QString path, chooseSublayersDialog.getSelection() )
2343+
{
2344+
QString name = path;
2345+
name.replace( layer->source(), QFileInfo( layer->source() ).completeBaseName() );
2346+
QgsRasterLayer *rlayer = new QgsRasterLayer( path, name );
2347+
if ( rlayer && rlayer->isValid() )
2348+
{
2349+
addRasterLayer( rlayer );
2350+
}
2351+
}
23192352
}
23202353
}
23212354

@@ -2328,9 +2361,11 @@ bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
23282361

23292362
QSettings settings;
23302363
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", 1 ).toInt();
2364+
// 0 = always -> always ask (if there are existing sublayers)
2365+
// 1 = if needed -> ask if layer has no bands, but has sublayers
2366+
// 2 = never
23312367

2332-
// return true if promptLayers=Always or if promptLayers!=Never and there are no bands
2333-
return promptLayers == 0 || ( promptLayers != 2 && layer->bandCount() == 0 );
2368+
return promptLayers == 0 || ( promptLayers == 1 && layer->bandCount() == 0 );
23342369
}
23352370

23362371
// This method will load with GDAL the layers in parameter.
@@ -2744,6 +2779,10 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
27442779
// set the initial map tool
27452780
mMapCanvas->setMapTool( mMapTools.mPan );
27462781
mNonEditMapTool = mMapTools.mPan; // signals are not yet setup to catch this
2782+
#ifdef HAVE_TOUCH
2783+
mMapCanvas->setMapTool( mMapTools.mTouch );
2784+
mNonEditMapTool = mMapTools.mTouch; // signals are not yet setup to catch this
2785+
#endif
27472786
} // QgisApp::fileNew(bool thePromptToSaveFlag)
27482787

27492788

@@ -2833,11 +2872,7 @@ void QgisApp::fileOpen()
28332872
deletePrintComposers();
28342873
removeAnnotationItems();
28352874
// clear out any stuff from previous project
2836-
2837-
//avoid multiple canvas redraws during loading of project files
2838-
bool bkRenderFlag = mMapCanvas->renderFlag();
2839-
mMapCanvas->setRenderFlag( false );
2840-
2875+
mMapCanvas->freeze( true );
28412876
removeAllLayers();
28422877

28432878
QgsProject::instance()->setFileName( fullPath );
@@ -2847,7 +2882,8 @@ void QgisApp::fileOpen()
28472882
QMessageBox::critical( this,
28482883
tr( "QGIS Project Read Error" ),
28492884
QgsProject::instance()->error() );
2850-
mMapCanvas->setRenderFlag( bkRenderFlag );
2885+
mMapCanvas->freeze( false );
2886+
mMapCanvas->refresh();
28512887
return;
28522888
}
28532889

@@ -2859,7 +2895,8 @@ void QgisApp::fileOpen()
28592895
// add this to the list of recently used project files
28602896
saveRecentProjectPath( fullPath, settings );
28612897

2862-
mMapCanvas->setRenderFlag( bkRenderFlag );
2898+
mMapCanvas->freeze( false );
2899+
mMapCanvas->refresh();
28632900
}
28642901

28652902
} // QgisApp::fileOpen
@@ -2871,8 +2908,7 @@ void QgisApp::fileOpen()
28712908
*/
28722909
bool QgisApp::addProject( QString projectFile )
28732910
{
2874-
bool bkRenderFlag = mMapCanvas->renderFlag();
2875-
mMapCanvas->setRenderFlag( false );
2911+
mMapCanvas->freeze( true );
28762912

28772913
QApplication::setOverrideCursor( Qt::WaitCursor );
28782914

@@ -2890,7 +2926,8 @@ bool QgisApp::addProject( QString projectFile )
28902926

28912927
QApplication::restoreOverrideCursor();
28922928

2893-
mMapCanvas->setRenderFlag( bkRenderFlag );
2929+
mMapCanvas->freeze( false );
2930+
mMapCanvas->refresh();
28942931
return false;
28952932
}
28962933

@@ -2926,7 +2963,8 @@ bool QgisApp::addProject( QString projectFile )
29262963

29272964
QApplication::restoreOverrideCursor();
29282965

2929-
mMapCanvas->setRenderFlag( bkRenderFlag );
2966+
mMapCanvas->freeze( false );
2967+
mMapCanvas->refresh();
29302968
return true;
29312969
} // QgisApp::addProject(QString projectFile)
29322970

@@ -3374,6 +3412,13 @@ void QgisApp::pan()
33743412
mMapCanvas->setMapTool( mMapTools.mPan );
33753413
}
33763414

3415+
#ifdef HAVE_TOUCH
3416+
void QgisApp::touch()
3417+
{
3418+
mMapCanvas->setMapTool( mMapTools.mTouch );
3419+
}
3420+
#endif
3421+
33773422
void QgisApp::zoomFull()
33783423
{
33793424
mMapCanvas->zoomToFullExtent();
@@ -7373,8 +7418,8 @@ QMenu* QgisApp::createPopupMenu()
73737418
return menu;
73747419
}
73757420

7376-
#ifdef ANDROID
7377-
bool QgisApp::gestureEvent( QGestureEvent *event )
7421+
#ifdef HAVE_TOUCH
7422+
bool QgisApp::gestureEvent(QGestureEvent *event)
73787423
{
73797424
if ( QGesture *tapAndHold = event->gesture( Qt::TapAndHoldGesture ) )
73807425
{

‎src/app/qgisapp.h

Lines changed: 16 additions & 4 deletions
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; }
@@ -772,6 +776,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
772776
void zoomIn();
773777
//! Set map tool to pan
774778
void pan();
779+
#ifdef HAVE_TOUCH
780+
//! Set map tool to touch
781+
void touch();
782+
#endif
775783
//! Identify feature(s) on the currently selected layer
776784
void identify();
777785
//! Measure distance
@@ -999,6 +1007,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
9991007
QgsMapTool* mZoomIn;
10001008
QgsMapTool* mZoomOut;
10011009
QgsMapTool* mPan;
1010+
#ifdef HAVE_TOUCH
1011+
QgsMapTool* mTouch;
1012+
#endif
10021013
QgsMapTool* mIdentify;
10031014
QgsMapTool* mFeatureAction;
10041015
QgsMapTool* mMeasureDist;
@@ -1176,14 +1187,15 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
11761187

11771188
QString mOldScale;
11781189

1179-
#ifdef ANDROID
1180-
bool gestureEvent( QGestureEvent *event );
1181-
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
1190+
#ifdef HAVE_TOUCH
1191+
bool gestureEvent(QGestureEvent *event);
1192+
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
11821193
#endif
11831194
};
11841195

11851196
#ifdef ANDROID
11861197
#define QGIS_ICON_SIZE 32
1198+
//TODO find a better default fontsize maybe using DPI detection or so
11871199
#define QGIS_DEFAULT_FONTSIZE 8
11881200
#else
11891201
#define QGIS_ICON_SIZE 24

‎src/app/qgsattributetabledialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
129129
connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( close() ) );
130130

131131
connect( searchButton, SIGNAL( clicked() ), this, SLOT( search() ) );
132+
connect( mCloseButton, SIGNAL( clicked() ), this, SLOT( close() ) );
132133
connect( mAddFeature, SIGNAL( clicked() ), this, SLOT( addFeature() ) );
133134

134135
connect( mView->verticalHeader(), SIGNAL( sectionClicked( int ) ), this, SLOT( updateRowSelection( int ) ) );

‎src/app/qgsoptions.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,13 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
301301
chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() );
302302

303303
//Changed to default to true as of QGIS 1.7
304-
chkUseSymbologyNG->setChecked( settings.value( "/qgis/use_symbology_ng", true ).toBool() );
304+
//TODO: remove hack when http://hub.qgis.org/issues/5170 is fixed
305+
#ifdef ANDROID
306+
bool use_symbology_ng_default = false;
307+
#else
308+
bool use_symbology_ng_default = true;
309+
#endif
310+
chkUseSymbologyNG->setChecked( settings.value( "/qgis/use_symbology_ng", use_symbology_ng_default ).toBool() );
305311

306312
// Slightly awkard here at the settings value is true to use QImage,
307313
// but the checkbox is true to use QPixmap

‎src/core/qgsvectorlayer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
119119

120120
QSettings settings;
121121
//Changed to default to true as of QGIS 1.7
122-
if ( settings.value( "/qgis/use_symbology_ng", true ).toBool() && hasGeometryType() )
122+
//TODO: remove hack when http://hub.qgis.org/issues/5170 is fixed
123+
#ifdef ANDROID
124+
bool use_symbology_ng_default = false;
125+
#else
126+
bool use_symbology_ng_default = true;
127+
#endif
128+
if ( settings.value( "/qgis/use_symbology_ng", use_symbology_ng_default ).toBool() && hasGeometryType() )
123129
{
124130
// using symbology-ng!
125131
setUsingRendererV2( true );

‎src/gui/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
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

Lines changed: 26 additions & 1 deletion
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

Lines changed: 9 additions & 0 deletions
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

‎src/gui/qgsmaptool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ void QgsMapTool::keyReleaseEvent( QKeyEvent *e )
141141
Q_UNUSED( e );
142142
}
143143

144+
#ifdef HAVE_TOUCH
145+
bool QgsMapTool::gestureEvent( QGestureEvent *e )
146+
{
147+
Q_UNUSED( e );
148+
}
149+
#endif
150+
144151
void QgsMapTool::renderComplete()
145152
{
146153
}

‎src/gui/qgsmaptool.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <QString>
2121
#include <QObject>
2222

23+
#ifdef HAVE_TOUCH
24+
#include <QGestureEvent>
25+
#endif
26+
2327
class QgsMapLayer;
2428
class QgsMapCanvas;
2529
class QKeyEvent;
@@ -62,6 +66,11 @@ class GUI_EXPORT QgsMapTool : public QObject
6266
//! Added in version 1.1
6367
virtual void keyReleaseEvent( QKeyEvent* e );
6468

69+
#ifdef HAVE_TOUCH
70+
//! gesture event for overriding. Default implementation does nothing.
71+
virtual bool gestureEvent( QGestureEvent* e );
72+
#endif
73+
6574
//! Called when rendering has finished. Default implementation does nothing.
6675
virtual void renderComplete();
6776

‎src/gui/qgsmaptooltouch.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/***************************************************************************
2+
qgsmaptooltouch.cpp - map tool for zooming and panning using qgestures
3+
----------------------
4+
begin : February 2012
5+
copyright : (C) 2012 by Marco Bernasocchi
6+
email : marco at bernawebdesign.ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsmaptooltouch.h"
17+
#include "qgsmapcanvas.h"
18+
#include "qgscursors.h"
19+
#include "qgsmaptopixel.h"
20+
#include <QBitmap>
21+
#include <QCursor>
22+
#include <QMouseEvent>
23+
#include <qgslogger.h>
24+
25+
26+
QgsMapToolTouch::QgsMapToolTouch( QgsMapCanvas* canvas )
27+
: QgsMapTool( canvas ), mDragging( false ), mPinching( false )
28+
{
29+
// set cursor
30+
// QBitmap panBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
31+
// QBitmap panBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
32+
// mCursor = QCursor( panBmp, panBmpMask, 5, 5 );
33+
}
34+
35+
QgsMapToolTouch::~QgsMapToolTouch()
36+
{
37+
mCanvas->ungrabGesture(Qt::PinchGesture);
38+
}
39+
40+
void QgsMapToolTouch::activate()
41+
{
42+
mCanvas->grabGesture(Qt::PinchGesture);
43+
QgsMapTool::activate();
44+
}
45+
46+
void QgsMapToolTouch::deactivate()
47+
{
48+
mCanvas->ungrabGesture(Qt::PinchGesture);
49+
QgsMapTool::deactivate();
50+
}
51+
52+
void QgsMapToolTouch::canvasMoveEvent( QMouseEvent * e )
53+
{
54+
if ( !mPinching )
55+
{
56+
if (( e->buttons() & Qt::LeftButton ) )
57+
{
58+
mDragging = true;
59+
// move map and other canvas items
60+
mCanvas->panAction( e );
61+
}
62+
}
63+
}
64+
65+
void QgsMapToolTouch::canvasReleaseEvent( QMouseEvent * e )
66+
{
67+
if ( !mPinching )
68+
{
69+
if ( e->button() == Qt::LeftButton )
70+
{
71+
if ( mDragging )
72+
{
73+
mCanvas->panActionEnd( e->pos() );
74+
mDragging = false;
75+
}
76+
else // add pan to mouse cursor
77+
{
78+
// transform the mouse pos to map coordinates
79+
QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( e->x(), e->y() );
80+
mCanvas->setExtent( QgsRectangle( center, center ) );
81+
mCanvas->refresh();
82+
}
83+
}
84+
}
85+
}
86+
87+
void QgsMapToolTouch::canvasDoubleClickEvent( QMouseEvent *e )
88+
{
89+
if ( !mPinching )
90+
{
91+
mCanvas->zoomWithCenter(e->x(), e->y(), true);
92+
}
93+
}
94+
95+
bool QgsMapToolTouch::gestureEvent(QGestureEvent *event)
96+
{
97+
qDebug() << "gesture " << event;
98+
if (QGesture *gesture = event->gesture(Qt::PinchGesture))
99+
{
100+
mPinching = true;
101+
pinchTriggered(static_cast<QPinchGesture *>(gesture));
102+
}
103+
return true;
104+
}
105+
106+
107+
void QgsMapToolTouch::pinchTriggered(QPinchGesture *gesture)
108+
{
109+
if (gesture->state() == Qt::GestureFinished) {
110+
//a very small totalScaleFactor indicates a two finger tap (pinch gesture without pinching)
111+
if (0.98 < gesture->totalScaleFactor() && gesture->totalScaleFactor() < 1.02 )
112+
{
113+
mCanvas->zoomOut();
114+
}
115+
else
116+
{
117+
//Transfor global coordinates to widget coordinates
118+
QPoint pos = gesture->centerPoint().toPoint();
119+
pos = mCanvas->mapFromGlobal( pos );
120+
// transform the mouse pos to map coordinates
121+
QgsPoint center = mCanvas->getCoordinateTransform()->toMapPoint( pos.x(),pos.y() );
122+
QgsRectangle r = mCanvas->extent();
123+
r.scale( 1/gesture->totalScaleFactor(), &center );
124+
mCanvas->setExtent( r );
125+
mCanvas->refresh();
126+
}
127+
mPinching = false;
128+
}
129+
}

‎src/gui/qgsmaptooltouch.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/***************************************************************************
2+
qgsmaptooltouch.h - map tool for zooming and panning using qgestures
3+
----------------------
4+
begin : February 2012
5+
copyright : (C) 2012 by Marco Bernasocchi
6+
email : marco at bernawebdesign.ch
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSMAPTOOLTOUCH_H
17+
#define QGSMAPTOOLTOUCH_H
18+
19+
#include "qgsmaptool.h"
20+
#include <QGestureEvent>
21+
#include <QPinchGesture>
22+
23+
class QgsMapCanvas;
24+
25+
26+
/** \ingroup gui
27+
* A map tool for panning the map.
28+
* @see QgsMapTool
29+
*/
30+
class GUI_EXPORT QgsMapToolTouch : public QgsMapTool
31+
{
32+
public:
33+
//! constructor
34+
QgsMapToolTouch( QgsMapCanvas* canvas );
35+
36+
~QgsMapToolTouch();
37+
38+
void activate();
39+
void deactivate();
40+
41+
//! Overridden mouse move event
42+
virtual void canvasMoveEvent( QMouseEvent * e );
43+
44+
//! Overridden mouse release event
45+
virtual void canvasReleaseEvent( QMouseEvent * e );
46+
47+
//! Overridden Mouse double click event.
48+
virtual void canvasDoubleClickEvent( QMouseEvent * e );
49+
50+
virtual bool isTransient() { return true; }
51+
52+
private:
53+
54+
//! Flag to indicate a map canvas drag operation is taking place
55+
bool mDragging;
56+
//! Flag to indicate a pinch gesture is taking place
57+
bool mPinching;
58+
bool gestureEvent(QGestureEvent *event);
59+
void pinchTriggered(QPinchGesture *gesture);
60+
};
61+
62+
#endif

‎src/plugins/compass/compass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
***************************************************************************/
1919

2020
#include "compass.h"
21+
#include "qgslogger.h"
2122

2223
Compass::Compass()
2324
{
@@ -61,7 +62,7 @@ bool Compass::start()
6162
mSensor.start();
6263
if ( !mSensor.isActive() )
6364
{
64-
qDebug() << "Compasssensor didn't start!" << endl;
65+
QgsDebugMsg( "Compasssensor didn't start!" );
6566
return false;
6667
}
6768
return true;
@@ -72,7 +73,7 @@ bool Compass::stop()
7273
mSensor.stop();
7374
if ( mSensor.isActive() )
7475
{
75-
qDebug() << "Compasssensor didn't stop!" << endl;
76+
QgsDebugMsg( "Compasssensor didn't stop!" );
7677
return false;
7778
}
7879
return true;

‎src/ui/qgisapp.ui

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
<attribute name="toolBarBreak">
312312
<bool>false</bool>
313313
</attribute>
314+
<addaction name="mActionTouch"/>
314315
<addaction name="mActionPan"/>
315316
<addaction name="mActionPanToSelected"/>
316317
<addaction name="mActionZoomIn"/>
@@ -1620,6 +1621,21 @@
16201621
<string>Pan Map to Selection</string>
16211622
</property>
16221623
</action>
1624+
<action name="mActionTouch">
1625+
<property name="checkable">
1626+
<bool>true</bool>
1627+
</property>
1628+
<property name="icon">
1629+
<iconset resource="../../images/images.qrc">
1630+
<normaloff>:/images/themes/gis/mActionTouch.png</normaloff>:/images/themes/gis/mActionTouch.png</iconset>
1631+
</property>
1632+
<property name="text">
1633+
<string>Touch zoom and pan</string>
1634+
</property>
1635+
<property name="toolTip">
1636+
<string>Touch zoom and pan</string>
1637+
</property>
1638+
</action>
16231639
<action name="mActionOffsetCurve">
16241640
<property name="checkable">
16251641
<bool>true</bool>

‎src/ui/qgsattributetabledialog.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@
9898
</property>
9999
</widget>
100100
</item>
101+
<item>
102+
<widget class="QPushButton" name="mCloseButton">
103+
<property name="text">
104+
<string>Close</string>
105+
</property>
106+
</widget>
107+
</item>
101108
</layout>
102109
</item>
103110
<item row="1" column="0">

0 commit comments

Comments
 (0)
Please sign in to comment.