Skip to content
Permalink
Browse files

[needs-docs][gps] Fix mouse cursor GPS distance display for touch scr…

…een devices

On touch screen devices, we can't show the GPS distance status bar message
as the cursor moves (because there's no "hover" mouse move events to trigger
this from). So for these devices, use a tap-and-hold event to trigger the
"current GPS distance from finger" status bar message.
  • Loading branch information
nyalldawson committed Feb 5, 2020
1 parent d2639bc commit ff839a4456ffa537b52d050b78ad17c2512fd4b1
@@ -1020,6 +1020,13 @@ This signal will be emitted during a pan operation as the user moves the map,
giving the total distance and bearing between the map position at the
start of the pan and the current pan position.

.. versionadded:: 3.12
%End

void tapAndHoldGestureOccurred( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );
%Docstring
Emitted whenever a tap and hold ``gesture`` occurs at the specified map point.

.. versionadded:: 3.12
%End

@@ -94,6 +94,7 @@ QgsGpsInformationWidget::QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidg
connect( mBtnResetFeature, &QToolButton::clicked, this, &QgsGpsInformationWidget::mBtnResetFeature_clicked );
connect( mBtnLogFile, &QPushButton::clicked, this, &QgsGpsInformationWidget::mBtnLogFile_clicked );
connect( mMapCanvas, &QgsMapCanvas::xyCoordinates, this, &QgsGpsInformationWidget::cursorCoordinateChanged );
connect( mMapCanvas, &QgsMapCanvas::tapAndHoldGestureOccurred, this, &QgsGpsInformationWidget::tapAndHold );

mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );

@@ -1555,6 +1556,22 @@ void QgsGpsInformationWidget::updateTimestampDestinationFields( QgsMapLayer *map
mPopulatingFields = false;
}

void QgsGpsInformationWidget::tapAndHold( const QgsPointXY &mapPoint, QTapAndHoldGesture * )
{
if ( !mNmea )
return;

try
{
mLastCursorPosWgs84 = mCanvasToWgs84Transform.transform( mapPoint );
updateGpsDistanceStatusMessage();
}
catch ( QgsCsException & )
{

}
}

void QgsGpsInformationWidget::switchAcquisition()
{
if ( mAcquisitionInterval > 0 )
@@ -54,6 +54,11 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
public:
QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr );
~QgsGpsInformationWidget() override;

public slots:
void tapAndHold( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );


private slots:
void mConnectButton_toggled( bool flag );
void displayGPSInformation( const QgsGpsInformation &info );
@@ -87,6 +92,7 @@ class APP_EXPORT QgsGpsInformationWidget: public QgsPanelWidget, private Ui::Qgs
* Updates compatible fields for timestamp recording
*/
void updateTimestampDestinationFields( QgsMapLayer *mapLayer );

private:
enum FixStatus //GPS status
{
@@ -194,6 +194,7 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
// Enable touch event on Windows.
// Qt on Windows needs to be told it can take touch events or else it ignores them.
grabGesture( Qt::PinchGesture );
grabGesture( Qt::TapAndHoldGesture );
viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
#endif

@@ -2337,6 +2338,14 @@ bool QgsMapCanvas::event( QEvent *e )
{
if ( e->type() == QEvent::Gesture )
{
if ( QTapAndHoldGesture *tapAndHoldGesture = qobject_cast< QTapAndHoldGesture * >( static_cast<QGestureEvent *>( e )->gesture( Qt::TapAndHoldGesture ) ) )
{
QPointF pos = tapAndHoldGesture->position();
pos = mapFromGlobal( QPoint( pos.x(), pos.y() ) );
QgsPointXY mapPoint = getCoordinateTransform()->toMapCoordinates( pos.x(), pos.y() );
emit tapAndHoldGestureOccurred( mapPoint, tapAndHoldGesture );
}

// call handler of current map tool
if ( mMapTool )
{
@@ -916,6 +916,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
*/
void panDistanceBearingChanged( double distance, QgsUnitTypes::DistanceUnit unit, double bearing );

/**
* Emitted whenever a tap and hold \a gesture occurs at the specified map point.
* \since QGIS 3.12
*/
void tapAndHoldGestureOccurred( const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture );

protected:

bool event( QEvent *e ) override;
@@ -115,7 +115,6 @@ bool QgsMapToolPan::gestureEvent( QGestureEvent *event )
if ( QTouchDevice::devices().isEmpty() )
return true; // no touch support

qDebug() << "gesture " << event;
if ( QGesture *gesture = event->gesture( Qt::PinchGesture ) )
{
mPinching = true;

0 comments on commit ff839a4

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