Skip to content
Permalink
Browse files
adding touch maptool that allows panning, pinch zooming, double tap z…
…oomWithCenter, twofinger tap zoomOut

fixed toolbar button functionality
  • Loading branch information
mbernasocchi committed Mar 28, 2012
1 parent 3d53e29 commit 48a0612cdf99e8d7b647baa460e72d5514a95b16
@@ -108,7 +108,7 @@
<file>themes/default/mActionNewFolder.png</file>
<file>themes/default/mActionNewVectorLayer.png</file>
<file>themes/default/mActionNodeTool.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOpenTable.png</file>
<file>themes/default/mActionOptions.png</file>
<file>themes/default/mActionPan.png</file>
@@ -366,7 +366,10 @@
<file>themes/gis/mIconMssql.png</file>
<file>themes/gis/mIconConnect.png</file>
<file>themes/gis/mIconDbSchema.png</file>
<file>themes/gis/mActionTouch.png</file>
<file>themes/default/mActionAddMssqlLayer.png</file>
<file>themes/default/mActionTouch.png</file>
<file>themes/classic/mActionTouch.png</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -258,6 +258,10 @@ extern "C"
#include <windows.h>
#endif

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

class QTreeWidgetItem;


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

#ifdef ANDROID
#ifdef HAVE_TOUCH
//add reacting to long click in android
grabGesture( Qt::TapAndHoldGesture );
#endif
@@ -646,6 +650,9 @@ QgisApp::~QgisApp()
delete mMapTools.mZoomIn;
delete mMapTools.mZoomOut;
delete mMapTools.mPan;
#ifdef HAVE_TOUCH
delete mMapTools.mTouch;
#endif
delete mMapTools.mIdentify;
delete mMapTools.mFeatureAction;
delete mMapTools.mMeasureDist;
@@ -741,8 +748,8 @@ bool QgisApp::event( QEvent * event )
openFile( foe->file() );
done = true;
}
#ifdef ANDROID
else if ( event->type() == QEvent::Gesture )
#ifdef HAVE_TOUCH
else if (event->type() == QEvent::Gesture )
{
done = gestureEvent( static_cast<QGestureEvent*>( event ) );
}
@@ -820,6 +827,9 @@ void QgisApp::createActions()

// 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() ) );
@@ -1009,6 +1019,9 @@ 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 );
@@ -1529,6 +1542,9 @@ void QgisApp::setTheme( QString theThemeName )
mActionZoomOut->setIcon( getThemeIcon( "/mActionZoomOut.png" ) );
mActionZoomFullExtent->setIcon( getThemeIcon( "/mActionZoomFullExtent.png" ) );
mActionZoomToSelected->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
#ifdef HAVE_TOUCH
mActionTouch->setIcon( getThemeIcon( "/mActionTouch.png" ) );
#endif
mActionPan->setIcon( getThemeIcon( "/mActionPan.png" ) );
mActionZoomLast->setIcon( getThemeIcon( "/mActionZoomLast.png" ) );
mActionZoomNext->setIcon( getThemeIcon( "/mActionZoomNext.png" ) );
@@ -1660,6 +1676,10 @@ 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 QgsMapToolIdentify( mMapCanvas );
mMapTools.mIdentify->setAction( mActionIdentify );
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
@@ -1725,6 +1745,9 @@ void QgisApp::createCanvasTools()
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
//ensure that non edit tool is initialised or we will get crashes in some situations
mNonEditMapTool = mMapTools.mPan;
//#ifdef HAVE_TOUCH
// mNonEditMapTool = mMapTools.mTouch;
//#endif
}

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

QStringList sublayers = layer->subLayers();

QgsDebugMsg( "sublayers:\n " + sublayers.join( " \n" ) + "\n" );

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

if ( chooseSublayersDialog.exec() )
{
loadGDALSublayers( layer->source(), chooseSublayersDialog.getSelection() );
foreach( QString path, chooseSublayersDialog.getSelection() )
{
QString name = path;
name.replace( layer->source(), QFileInfo( layer->source() ).completeBaseName() );
QgsRasterLayer *rlayer = new QgsRasterLayer( path, name );
if ( rlayer && rlayer->isValid() )
{
addRasterLayer( rlayer );
}
}
}
}

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

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

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

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


@@ -2821,11 +2860,7 @@ void QgisApp::fileOpen()
deletePrintComposers();
removeAnnotationItems();
// clear out any stuff from previous project

//avoid multiple canvas redraws during loading of project files
bool bkRenderFlag = mMapCanvas->renderFlag();
mMapCanvas->setRenderFlag( false );

mMapCanvas->freeze( true );
removeAllLayers();

QgsProject::instance()->setFileName( fullPath );
@@ -2835,7 +2870,8 @@ void QgisApp::fileOpen()
QMessageBox::critical( this,
tr( "QGIS Project Read Error" ),
QgsProject::instance()->error() );
mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return;
}

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

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}

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

QApplication::setOverrideCursor( Qt::WaitCursor );

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

QApplication::restoreOverrideCursor();

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return false;
}

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

QApplication::restoreOverrideCursor();

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return true;
} // QgisApp::addProject(QString projectFile)

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

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

void QgisApp::zoomFull()
{
mMapCanvas->zoomToFullExtent();
@@ -7361,8 +7406,8 @@ QMenu* QgisApp::createPopupMenu()
return menu;
}

#ifdef ANDROID
bool QgisApp::gestureEvent( QGestureEvent *event )
#ifdef HAVE_TOUCH
bool QgisApp::gestureEvent(QGestureEvent *event)
{
if ( QGesture *tapAndHold = event->gesture( Qt::TapAndHoldGesture ) )
{
@@ -83,7 +83,7 @@ class QgsScaleComboBox;
#include <QPointer>
#include <QSslError>

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

#ifdef HAVE_TOUCH
QAction *actionTouch() { return mActionTouch; }
#endif

QAction *actionPan() { return mActionPan; }
QAction *actionPanToSelected() { return mActionPanToSelected; }
QAction *actionZoomIn() { return mActionZoomIn; }
@@ -767,6 +771,10 @@ class 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
@@ -992,6 +1000,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool* mZoomIn;
QgsMapTool* mZoomOut;
QgsMapTool* mPan;
#ifdef HAVE_TOUCH
QgsMapTool* mTouch;
#endif
QgsMapTool* mIdentify;
QgsMapTool* mFeatureAction;
QgsMapTool* mMeasureDist;
@@ -1169,9 +1180,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

QString mOldScale;

#ifdef ANDROID
bool gestureEvent( QGestureEvent *event );
void tapAndHoldTriggered( QTapAndHoldGesture *gesture );
#ifdef HAVE_TOUCH
bool gestureEvent(QGestureEvent *event);
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
#endif
};

@@ -80,6 +80,13 @@ qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
)

IF (WITH_TOUCH)
SET(QGIS_GUI_SRCS
${QGIS_GUI_SRCS}
qgsmaptooltouch.cpp
)
ENDIF (WITH_TOUCH)

SET(QGIS_GUI_MOC_HDRS

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

IF (WITH_TOUCH)
SET(QGIS_GUI_HDRS
${QGIS_GUI_HDRS}
qgsmaptooltouch.h
)
ENDIF (WITH_TOUCH)

SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsgenericprojectionselectorbase.h
@@ -1559,4 +1559,29 @@ void QgsMapCanvas::mapToolDestroyed()
{
QgsDebugMsg( "maptool destroyed" );
mMapTool = 0;
}
}

#ifdef HAVE_TOUCH
bool QgsMapCanvas::event( QEvent * e )
{
bool done = false;
if ( mDrawing )
{
return done;
}
if (e->type() == QEvent::Gesture )
{
// call handler of current map tool
if ( mMapTool )
{
done = mMapTool->gestureEvent( static_cast<QGestureEvent*>(e) );
}
}
else
{
// pass other events to base class
done = QGraphicsView::event( e );
}
return done;
}
#endif
@@ -30,6 +30,10 @@
#include <QGraphicsView>
#include <QtCore>

#ifdef HAVE_TOUCH
#include <QGestureEvent>
#endif

class QWheelEvent;
class QPixmap;
class QPaintEvent;
@@ -357,6 +361,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void zoomNextStatusChanged( bool );

protected:
#ifdef HAVE_TOUCH
//! Overridden standard event to be gestures aware
bool event( QEvent * e );
#endif

//! Overridden key press event
void keyPressEvent( QKeyEvent * e );

0 comments on commit 48a0612

Please sign in to comment.