Skip to content
Permalink
Browse files

Rework map touch tool

Qt5 allows runtime detection of touch devices. This commit reworks
the current touch map tool by pulling its behavior into the normal
pan tool when a touch device is detected.

It avoids the need for a seperate map tool for touch interaction,
and also avoids having this tool always appear on the Windows
builds (regardless of the presence of a touch device)
  • Loading branch information
nyalldawson committed Feb 12, 2017
1 parent 9a7c829 commit c26ed69c6b06b023e6eb52e1af39b47cf8f918fd
@@ -268,23 +268,6 @@ IF (WITH_QTMOBILITY)
FIND_PACKAGE(QtMobility 1.1.0)
ENDIF (WITH_QTMOBILITY)

IF (ANDROID)
SET (DEFAULT_WITH_TOUCH TRUE)
ELSE (ANDROID)
SET (DEFAULT_WITH_TOUCH FALSE)
ENDIF (ANDROID)

#Add a touch mode if Qt has Qt Gestures
SET (WITH_TOUCH ${DEFAULT_WITH_TOUCH} CACHE BOOL "Determines if touch interface related code should be build")

IF (WITH_TOUCH)
# following variable is used in qgsconfig.h
SET (HAVE_TOUCH TRUE)
MESSAGE (STATUS "Touch support enabled")
ELSE (WITH_TOUCH)
MESSAGE (STATUS "Touch support disabled")
ENDIF (WITH_TOUCH)

# search for QScintilla2 (C++ lib)
FIND_PACKAGE(QScintilla REQUIRED)

@@ -48,8 +48,6 @@

#cmakedefine HAVE_ORACLE

#cmakedefine HAVE_TOUCH

#cmakedefine HAVE_OSGEARTHQT

#cmakedefine SERVER_SKIP_ECW
@@ -28,7 +28,6 @@ cmake -D BUILDNAME="cygwin" \
-D WITH_QSPATIALITE=TRUE \
-D WITH_SERVER=TRUE \
-D WITH_GLOBE=TRUE \
-D WITH_TOUCH=TRUE \
-D WITH_ORACLE=FALSE \
-D CMAKE_LEGACY_CYGWIN_WIN32=0 \
-D PYUIC4_PROGRAM=/usr/lib/python2.7/site-packages/PyQt4/pyuic4 \
@@ -167,7 +167,6 @@ cmake -G Ninja ^
-D WITH_GRASS7=TRUE ^
-D GRASS_PREFIX7=%GRASS72_PATH:\=/% ^
-D WITH_GLOBE=FALSE ^
-D WITH_TOUCH=TRUE ^
-D WITH_ORACLE=TRUE ^
-D WITH_CUSTOM_WIDGETS=TRUE ^
-D CMAKE_BUILD_TYPE=%BUILDCONF% ^
@@ -160,7 +160,6 @@ cmake -G Ninja ^
-D WITH_GRASS7=TRUE ^
-D GRASS_PREFIX7=%GRASS72_PATH:\=/% ^
-D WITH_GLOBE=FALSE ^
-D WITH_TOUCH=TRUE ^
-D WITH_ORACLE=TRUE ^
-D WITH_CUSTOM_WIDGETS=TRUE ^
-D CMAKE_CXX_FLAGS_RELEASE="/MD /MP /O2 /Ob2 /D NDEBUG" ^
@@ -130,10 +130,6 @@ ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} ARM)
ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")

IF(NOT WITH_TOUCH)
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} HAVE_TOUCH)
ENDIF(NOT WITH_TOUCH)

IF(NOT QT_MOBILITY_LOCATION_FOUND)
SET(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} MOBILITY_LOCATION)
ENDIF(NOT QT_MOBILITY_LOCATION_FOUND)
@@ -118,7 +118,6 @@
%Include qgsmaptoolidentify.sip
%Include qgsmaptoolidentifyfeature.sip
%Include qgsmaptoolpan.sip
%Include qgsmaptooltouch.sip
%Include qgsmaptoolzoom.sip
%Include qgsmaplayerstylemanagerwidget.sip
%Include qgsmessagebar.sip
@@ -404,8 +404,6 @@ class QgisInterface : QObject
// View menu actions
//! Get access to the native pan action. Call trigger() on it to set the default pan map tool.
virtual QAction *actionPan() = 0;
//! Get access to the native touch action.
virtual QAction *actionTouch() = 0;
//! Get access to the native pan to selected action. Call trigger() on it to pan the map canvas to the selection.
virtual QAction *actionPanToSelected() = 0;
//! Get access to the native zoom in action. Call trigger() on it to set the default zoom in map tool.
@@ -1,5 +1,3 @@
%Feature HAVE_TOUCH

/** \ingroup gui
* Map canvas is a class for displaying all GIS data types on a canvas.
*/
@@ -486,10 +484,9 @@ class QgsMapCanvas : QGraphicsView
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );

protected:
%If (HAVE_TOUCH)

//! Overridden standard event to be gestures aware
bool event( QEvent * e );
%End

//! Overridden key press event
void keyPressEvent( QKeyEvent * e );
@@ -71,10 +71,8 @@ class QgsMapTool : QObject
//! Key event for overriding. Default implementation does nothing.
virtual void keyReleaseEvent( QKeyEvent* e );

%If (HAVE_TOUCH)
//! gesture event for overriding. Default implementation does nothing.
virtual bool gestureEvent( QGestureEvent* e );
%End

/** Use this to associate a QAction to this maptool. Then when the setMapTool
* method of mapcanvas is called the action state will be set to on.

This file was deleted.

@@ -198,7 +198,6 @@ gzip ChangeLog
# Necessary for the test suite
#export LD_LIBRARY_PATH=%{_builddir}%{name}-%{version}/output/%{_lib}

#Info: TOUCH needs Qt >= 4.5
%cmake \
%{_cmake_skip_rpath} \
-D QGIS_LIB_SUBDIR=%{_lib} \
@@ -224,7 +223,6 @@ gzip ChangeLog
-D WITH_INTERNAL_SIX:BOOL=FALSE \
-D WITH_PYSPATIALITE:BOOL=FALSE \
-D WITH_SERVER:BOOL=TRUE \
-D WITH_TOUCH:BOOL=TRUE \
%{configure_with_spatialite} \
.
#-D WITH_QTMOBILITY:BOOL=TRUE \
@@ -360,10 +360,6 @@ extern "C"
#include <DbgHelp.h>
#endif

#ifdef HAVE_TOUCH
#include "qgsmaptooltouch.h"
#endif

class QTreeWidgetItem;

/** Set the application title bar text
@@ -1092,14 +1088,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QgsDebugMsg( "Tips are disabled" );
}

#ifdef HAVE_TOUCH
//add reacting to long click in touch
grabGesture( Qt::TapAndHoldGesture );
#else
//remove mActionTouch button
delete mActionTouch;
mActionTouch = nullptr;
#endif
if ( ! QTouchDevice::devices().isEmpty() )
{
//add reacting to long click in touch
grabGesture( Qt::TapAndHoldGesture );
}

// supposedly all actions have been added, now register them to the shortcut manager
QgsShortcutsManager::instance()->registerAllChildren( this );
@@ -1253,9 +1246,6 @@ QgisApp::~QgisApp()
delete mMapTools.mZoomIn;
delete mMapTools.mZoomOut;
delete mMapTools.mPan;
#ifdef HAVE_TOUCH
delete mMapTools.mTouch;
#endif
delete mMapTools.mAddFeature;
delete mMapTools.mAddPart;
delete mMapTools.mAddRing;
@@ -1496,12 +1486,10 @@ bool QgisApp::event( QEvent * event )
openFile( foe->file() );
done = true;
}
#ifdef HAVE_TOUCH
else if ( event->type() == QEvent::Gesture )
else if ( !QTouchDevice::devices().isEmpty() && event->type() == QEvent::Gesture )
{
done = gestureEvent( static_cast<QGestureEvent*>( event ) );
}
#endif
else
{
// pass other events to base class
@@ -1639,10 +1627,6 @@ void QgisApp::createActions()
connect( mActionOffsetCurve, SIGNAL( triggered() ), this, SLOT( offsetCurve() ) );

// View Menu Items

#ifdef HAVE_TOUCH
connect( mActionTouch, SIGNAL( triggered() ), this, SLOT( touch() ) );
#endif
connect( mActionPan, SIGNAL( triggered() ), this, SLOT( pan() ) );
connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) );
connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) );
@@ -1871,9 +1855,6 @@ void QgisApp::createActionGroups()
//
// Map Tool Group
mMapToolGroup = new QActionGroup( this );
#ifdef HAVE_TOUCH
mMapToolGroup->addAction( mActionTouch );
#endif
mMapToolGroup->addAction( mActionPan );
mMapToolGroup->addAction( mActionZoomIn );
mMapToolGroup->addAction( mActionZoomOut );
@@ -2682,9 +2663,6 @@ void QgisApp::setTheme( const QString& theThemeName )
mActionZoomFullExtent->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomFullExtent.svg" ) ) );
mActionZoomToSelected->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomToSelected.svg" ) ) );
mActionShowRasterCalculator->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowRasterCalculator.png" ) ) );
#ifdef HAVE_TOUCH
mActionTouch->setIcon( QgsApplication::getThemeIcon( "/mActionTouch.svg" ) );
#endif
mActionPan->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionPan.svg" ) ) );
mActionPanToSelected->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionPanToSelected.svg" ) ) );
mActionZoomLast->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomLast.svg" ) ) );
@@ -2861,10 +2839,6 @@ void QgisApp::createCanvasTools()
mMapTools.mZoomOut->setAction( mActionZoomOut );
mMapTools.mPan = new QgsMapToolPan( mMapCanvas );
mMapTools.mPan->setAction( mActionPan );
#ifdef HAVE_TOUCH
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
mMapTools.mTouch->setAction( mActionTouch );
#endif
mMapTools.mIdentify = new QgsMapToolIdentifyAction( mMapCanvas );
mMapTools.mIdentify->setAction( mActionIdentify );
connect( mMapTools.mIdentify, SIGNAL( copyToClipboard( QgsFeatureStore & ) ),
@@ -4591,15 +4565,10 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
}

// set the initial map tool
#ifndef HAVE_TOUCH
mMapCanvas->setMapTool( mMapTools.mPan );
mNonEditMapTool = mMapTools.mPan; // signals are not yet setup to catch this
#else
mMapCanvas->setMapTool( mMapTools.mTouch );
mNonEditMapTool = mMapTools.mTouch; // signals are not yet setup to catch this
#endif

} // QgisApp::fileNew(bool thePromptToSaveFlag)
}

bool QgisApp::fileNewFromTemplate( const QString& fileName )
{
@@ -5834,13 +5803,6 @@ void QgisApp::pan()
mMapCanvas->setMapTool( mMapTools.mPan );
}

#ifdef HAVE_TOUCH
void QgisApp::touch()
{
mMapCanvas->setMapTool( mMapTools.mTouch );
}
#endif

void QgisApp::zoomFull()
{
mMapCanvas->zoomToFullExtent();
@@ -12101,8 +12063,6 @@ void QgisApp::onLayerError( const QString& msg )
mInfoBar->pushCritical( tr( "Layer %1" ).arg( layer->name() ), msg );
}


#ifdef HAVE_TOUCH
bool QgisApp::gestureEvent( QGestureEvent *event )
{
if ( QGesture *tapAndHold = event->gesture( Qt::TapAndHoldGesture ) )
@@ -12125,7 +12085,6 @@ void QgisApp::tapAndHoldTriggered( QTapAndHoldGesture *gesture )
QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonRelease, receiver->mapFromGlobal( pos ), Qt::RightButton, Qt::RightButton, Qt::NoModifier ) );
}
}
#endif

#ifdef Q_OS_WIN
LONG WINAPI QgisApp::qgisCrashDump( struct _EXCEPTION_POINTERS *ExceptionInfo )
@@ -131,10 +131,8 @@ class QgsDiagramProperties;
#include "ui_qgisapp.h"
#include "qgis_app.h"

#ifdef HAVE_TOUCH
#include <QGestureEvent>
#include <QTapAndHoldGesture>
#endif

#ifdef Q_OS_WIN
#include <windows.h>
@@ -352,7 +350,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionSnappingOptions() { return mActionSnappingOptions; }
QAction *actionOffsetCurve() { return mActionOffsetCurve; }
QAction *actionPan() { return mActionPan; }
QAction *actionTouch() { return mActionTouch; }
QAction *actionPanToSelected() { return mActionPanToSelected; }
QAction *actionZoomIn() { return mActionZoomIn; }
QAction *actionZoomOut() { return mActionZoomOut; }
@@ -1222,10 +1219,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void zoomIn();
//! Set map tool to pan
void pan();
#ifdef HAVE_TOUCH
//! Set map tool to touch
void touch();
#endif
//! Identify feature(s) on the currently selected layer
void identify();
//! Measure distance
@@ -1590,9 +1583,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
: mZoomIn( nullptr )
, mZoomOut( nullptr )
, mPan( nullptr )
#ifdef HAVE_TOUCH
, mTouch( 0 )
#endif
, mIdentify( nullptr )
, mFeatureAction( nullptr )
, mMeasureDist( nullptr )
@@ -1639,9 +1629,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool *mZoomIn;
QgsMapTool *mZoomOut;
QgsMapTool *mPan;
#ifdef HAVE_TOUCH
QgsMapTool *mTouch;
#endif
QgsMapTool *mIdentify;
QgsMapTool *mFeatureAction;
QgsMapTool *mMeasureDist;
@@ -1865,10 +1852,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QStackedWidget* mCentralContainer;

int mProjOpen;
#ifdef HAVE_TOUCH

bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
#endif

friend class TestQgisAppPython;
};
@@ -573,7 +573,6 @@ QAction *QgisAppInterface::actionNodeTool() { return qgis->actionNodeTool(); }

//! View menu actions
QAction *QgisAppInterface::actionPan() { return qgis->actionPan(); }
QAction *QgisAppInterface::actionTouch() { return qgis->actionTouch(); }
QAction *QgisAppInterface::actionPanToSelected() { return qgis->actionPanToSelected(); }
QAction *QgisAppInterface::actionZoomIn() { return qgis->actionZoomIn(); }
QAction *QgisAppInterface::actionZoomOut() { return qgis->actionZoomOut(); }
@@ -392,7 +392,6 @@ class APP_EXPORT QgisAppInterface : public QgisInterface

//! View menu actions
virtual QAction *actionPan() override;
virtual QAction *actionTouch() override;
virtual QAction *actionPanToSelected() override;
virtual QAction *actionZoomIn() override;
virtual QAction *actionZoomOut() override;

0 comments on commit c26ed69

Please sign in to comment.
You can’t perform that action at this time.