Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #112 from mbernasocchi/android
Android goodies (touch maptool, with-touch mode, ui edits, ...)
  • Loading branch information
timlinux committed Mar 31, 2012
2 parents 401aea2 + 76ba1f6 commit 34f10f1
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 32 deletions.
23 changes: 20 additions & 3 deletions CMakeLists.txt
Expand Up @@ -87,11 +87,30 @@ IF (ANDROID)
ELSE (ANDROID)
SET (DEFAULT_WITH_QTMOBILITY FALSE)
ENDIF (ANDROID)
SET (WITH_QTMOBILITY ${DEFAULT_WITH_QTMOBILITY} CACHE BOOL "Determines QtMobility related code should be build (for example internal GPS)")
SET (WITH_QTMOBILITY ${DEFAULT_WITH_QTMOBILITY} CACHE BOOL "Determines if QtMobility related code should be build (for example internal GPS)")
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 (starting from 4.6)
IF ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
SET (WITH_TOUCH ${DEFAULT_WITH_TOUCH} CACHE BOOL "Determines if touch interface related code should be build")
ELSE ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
SET (WITH_TOUCH FALSE)
ENDIF ( (QT_VERSION_MAJOR EQUAL 4 AND QT_VERSION_MINOR GREATER 5) OR QT_VERSION_MAJOR GREATER 4 )
IF (WITH_TOUCH)
ADD_DEFINITIONS(-DHAVE_TOUCH)
MESSAGE (STATUS "Touch support enabled")
ELSE (WITH_TOUCH)
MESSAGE (STATUS "Touch support disabled")
ENDIF (WITH_TOUCH)


SET (WITH_GLOBE FALSE CACHE BOOL "Determines whether Globe plugin should be built")
IF (WITH_GLOBE)
SET(QT_USE_QTOPENGL 1)
Expand Down Expand Up @@ -472,9 +491,7 @@ LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/core ${CMAKE_BINARY_DIR}/src/gui)

#############################################################
# create qgsversion.h

FIND_FILE(GIT_MARKER index PATHS ${CMAKE_SOURCE_DIR}/.git)

IF (GIT_MARKER)
FIND_PROGRAM(GIT git PATHS c:/cygwin/bin)
IF(GIT)
Expand Down
3 changes: 3 additions & 0 deletions images/images.qrc
Expand Up @@ -374,7 +374,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>
Expand Down
Binary file added images/themes/classic/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/gis/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 65 additions & 20 deletions src/app/qgisapp.cpp
Expand Up @@ -258,6 +258,10 @@ extern "C"
#include <windows.h>
#endif

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

class QTreeWidgetItem;


Expand Down Expand Up @@ -638,7 +642,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
Expand All @@ -658,6 +662,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;
Expand Down Expand Up @@ -753,8 +760,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 ) );
}
Expand Down Expand Up @@ -832,6 +839,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() ) );
Expand Down Expand Up @@ -1021,6 +1031,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 );
Expand Down Expand Up @@ -1541,6 +1554,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" ) );
Expand Down Expand Up @@ -1672,6 +1688,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 );
Expand Down Expand Up @@ -1737,6 +1757,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()
Expand Down Expand Up @@ -2287,10 +2310,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
Expand All @@ -2315,7 +2339,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 );
}
}
}
}

Expand All @@ -2328,9 +2361,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.
Expand Down Expand Up @@ -2744,6 +2779,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)


Expand Down Expand Up @@ -2833,11 +2872,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 );
Expand All @@ -2847,7 +2882,8 @@ void QgisApp::fileOpen()
QMessageBox::critical( this,
tr( "QGIS Project Read Error" ),
QgsProject::instance()->error() );
mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return;
}

Expand All @@ -2859,7 +2895,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
Expand All @@ -2871,8 +2908,7 @@ void QgisApp::fileOpen()
*/
bool QgisApp::addProject( QString projectFile )
{
bool bkRenderFlag = mMapCanvas->renderFlag();
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze( true );

QApplication::setOverrideCursor( Qt::WaitCursor );

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

QApplication::restoreOverrideCursor();

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

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

QApplication::restoreOverrideCursor();

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

Expand Down Expand Up @@ -3374,6 +3412,13 @@ void QgisApp::pan()
mMapCanvas->setMapTool( mMapTools.mPan );
}

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

void QgisApp::zoomFull()
{
mMapCanvas->zoomToFullExtent();
Expand Down Expand Up @@ -7373,8 +7418,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 ) )
{
Expand Down
20 changes: 16 additions & 4 deletions src/app/qgisapp.h
Expand Up @@ -83,7 +83,7 @@ class QgsScaleComboBox;
#include <QPointer>
#include <QSslError>

#ifdef ANDROID
#ifdef HAVE_TOUCH
#include <QGestureEvent>
#include <QTapAndHoldGesture>
#endif
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -772,6 +776,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
Expand Down Expand Up @@ -999,6 +1007,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;
Expand Down Expand Up @@ -1176,14 +1187,15 @@ 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
};

#ifdef ANDROID
#define QGIS_ICON_SIZE 32
//TODO find a better default fontsize maybe using DPI detection or so
#define QGIS_DEFAULT_FONTSIZE 8
#else
#define QGIS_ICON_SIZE 24
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -129,6 +129,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
connect( mLayer, SIGNAL( layerDeleted() ), this, SLOT( close() ) );

connect( searchButton, SIGNAL( clicked() ), this, SLOT( search() ) );
connect( mCloseButton, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( mAddFeature, SIGNAL( clicked() ), this, SLOT( addFeature() ) );

connect( mView->verticalHeader(), SIGNAL( sectionClicked( int ) ), this, SLOT( updateRowSelection( int ) ) );
Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsoptions.cpp
Expand Up @@ -301,7 +301,13 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() );

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

// Slightly awkard here at the settings value is true to use QImage,
// but the checkbox is true to use QPixmap
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -119,7 +119,13 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,

QSettings settings;
//Changed to default to true as of QGIS 1.7
if ( settings.value( "/qgis/use_symbology_ng", true ).toBool() && hasGeometryType() )
//TODO: remove hack when http://hub.qgis.org/issues/5170 is fixed
#ifdef ANDROID
bool use_symbology_ng_default = false;
#else
bool use_symbology_ng_default = true;
#endif
if ( settings.value( "/qgis/use_symbology_ng", use_symbology_ng_default ).toBool() && hasGeometryType() )
{
// using symbology-ng!
setUsingRendererV2( true );
Expand Down

0 comments on commit 34f10f1

Please sign in to comment.