Skip to content

Commit ee21580

Browse files
stevenmizunojef-n
authored andcommitted
GPS tracking improvements (apply #4071)
1 parent f71ecb9 commit ee21580

16 files changed

+1673
-568
lines changed

src/app/gps/qgsgpsinformationwidget.cpp

Lines changed: 615 additions & 211 deletions
Large diffs are not rendered by default.

src/app/gps/qgsgpsinformationwidget.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#include <qwt_plot_curve.h>
2626
#include <qwt_polar_plot.h>
2727
#include <qwt_polar_marker.h>
28+
2829
class QextSerialPort;
2930
class QgsGPSConnection;
3031
class QgsGPSTrackerThread;
3132
struct QgsGPSInformation;
32-
class QPointF;
33+
34+
class QgsLegend;
35+
class QFile;
36+
class QColor;
3337

3438
/**A dock widget that displays information from a GPS device and
3539
* allows the user to capture features using gps readings to
@@ -44,8 +48,11 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
4448
private slots:
4549
void on_mConnectButton_toggled( bool theFlag );
4650
void displayGPSInformation( const QgsGPSInformation& info );
47-
void setTrackColour( );
48-
void on_mBtnTrackColour_clicked( );
51+
void logNmeaSentence( const QString& nmeaString ); // added to handle 'raw' data
52+
void updateCloseFeatureButton( QgsMapLayer * lyr );
53+
void layerEditStateChanged();
54+
// void setTrackColor( ); // no longer used
55+
void on_mBtnTrackColor_clicked( );
4956
void on_mSpinTrackWidth_valueChanged( int theValue );
5057
void on_mBtnPosition_clicked( );
5158
void on_mBtnSignal_clicked( );
@@ -56,17 +63,24 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
5663
void on_mBtnAddVertex_clicked( );
5764
void on_mBtnCloseFeature_clicked( );
5865
void on_mBtnResetFeature_clicked( );
59-
void on_mCbxAutoAddVertices_toggled( bool theFlag );
66+
// not needed void on_mCbxAutoAddVertices_toggled( bool theFlag );
67+
void on_mBtnLogFile_clicked();
6068

6169
void connected( QgsGPSConnection * );
6270
void timedout();
6371

6472
private:
73+
enum FixStatus //GPS status
74+
{
75+
NoData, NoFix, Fix2D, Fix3D
76+
};
6577
void addVertex( );
6678
void connectGps();
6779
void connectGpsSlot( );
6880
void disconnectGps();
6981
void populateDevices();
82+
void setStatusIndicator( const FixStatus statusValue );
83+
void showStatusBarMessage( const QString& msg );
7084
QgsGPSConnection* mNmea;
7185
QgsMapCanvas * mpCanvas;
7286
QgsGpsMarker * mpMapMarker;
@@ -76,10 +90,17 @@ class QgsGPSInformationWidget: public QWidget, private Ui::QgsGPSInformationWidg
7690
QList< QwtPolarMarker * > mMarkerList;
7791
void createRubberBand( );
7892
QgsCoordinateReferenceSystem mWgs84CRS;
79-
QPointF gpsToPixelPosition( const QgsPoint& point );
93+
// not used QPointF gpsToPixelPosition( const QgsPoint& point );
8094
QgsRubberBand * mpRubberBand;
8195
QgsPoint mLastGpsPosition;
8296
QList<QgsPoint> mCaptureList;
97+
FixStatus mLastFixStatus;
98+
QString mDateTimeFormat; // user specified format string in registry (no UI presented)
99+
QgsLegend * mpLegend;
100+
QgsVectorLayer * mpLastLayer;
101+
QFile * mLogFile;
102+
QTextStream mLogFileTextStream;
103+
QColor mTrackColor;
83104
};
84105

85106
#endif // QGSGPSINFORMATIONWIDGET_H

src/app/gps/qgsgpsmarker.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
***************************************************************************/
1515

1616
#include <QPainter>
17-
#include <QSvgRenderer>
1817

1918
#include "qgsgpsmarker.h"
2019
#include "qgscoordinatetransform.h"
@@ -27,6 +26,11 @@ QgsGpsMarker::QgsGpsMarker( QgsMapCanvas* mapCanvas )
2726
{
2827
mSize = 16;
2928
mWgs84CRS.createFromOgcWmsCrs( "EPSG:4326" );
29+
mSvg.load( QString( ":/images/north_arrows/gpsarrow2.svg" ) );
30+
if ( ! mSvg.isValid() )
31+
{
32+
qDebug( "GPS marker not found!" );
33+
}
3034
}
3135

3236
void QgsGpsMarker::setSize( int theSize )
@@ -60,14 +64,18 @@ void QgsGpsMarker::setCenter( const QgsPoint& point )
6064

6165
void QgsGpsMarker::paint( QPainter* p )
6266
{
63-
QSvgRenderer mySVG;
64-
if ( !mySVG.load( QString( ":/images/north_arrows/gpsarrow2.svg" ) ) )
67+
if ( ! mSvg.isValid() )
6568
{
66-
qDebug( "GPS marker not found!" );
6769
return;
6870
}
71+
72+
// this needs to be done when the canvas is repainted to make for smoother map rendering
73+
// if not done the map could be panned, but the cursor position won't be updated until the next valid GPS fix is received
74+
QPointF pt = toCanvasCoordinates( mCenter );
75+
setPos( pt );
76+
6977
float myHalfSize = mSize / 2.0;
70-
mySVG.render( p, QRectF( 0 - myHalfSize , 0 - myHalfSize, mSize, mSize ) );
78+
mSvg.render( p, QRectF( 0 - myHalfSize , 0 - myHalfSize, mSize, mSize ) );
7179
}
7280

7381

src/app/gps/qgsgpsmarker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsmapcanvasitem.h"
2020
#include "qgscoordinatereferencesystem.h"
2121
#include "qgspoint.h"
22+
#include <QSvgRenderer>
2223

2324
class QPainter;
2425

@@ -50,6 +51,7 @@ class QgsGpsMarker : public QgsMapCanvasItem
5051

5152
private:
5253
QgsCoordinateReferenceSystem mWgs84CRS;
54+
QSvgRenderer mSvg;
5355

5456
};
5557

src/app/qgisapp.cpp

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
452452
addDockWidget( Qt::LeftDockWidgetArea, mBrowserWidget );
453453
mBrowserWidget->hide();
454454

455+
// create the GPS tool on starting QGIS - this is like the Browser
456+
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );
457+
//create the dock widget
458+
mpGpsDock = new QDockWidget( tr( "GPS Information" ), this );
459+
mpGpsDock->setObjectName( "GPSInformation" );
460+
mpGpsDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
461+
addDockWidget( Qt::LeftDockWidgetArea, mpGpsDock );
462+
// add to the Panel submenu
463+
// now add our widget to the dock - ownership of the widget is passed to the dock
464+
mpGpsDock->setWidget( mpGpsWidget );
465+
mpGpsDock->hide();
466+
455467
mInternalClipboard = new QgsClipboard; // create clipboard
456468
mQgisInterface = new QgisAppInterface( this ); // create the interfce
457469

@@ -630,6 +642,8 @@ QgisApp::~QgisApp()
630642

631643
delete mPythonUtils;
632644

645+
delete mpGpsWidget;
646+
633647
deletePrintComposers();
634648
removeAnnotationItems();
635649

@@ -729,11 +743,6 @@ void QgisApp::readSettings()
729743
{
730744
showTileScale();
731745
}
732-
// Restore state of GPS Tracker
733-
if ( settings.value( "/gps/widgetEnabled", false ).toBool() )
734-
{
735-
showGpsTool();
736-
}
737746
}
738747

739748

@@ -830,7 +839,6 @@ void QgisApp::createActions()
830839
connect( mActionSetLayerCRS, SIGNAL( triggered() ), this, SLOT( setLayerCRS() ) );
831840
connect( mActionSetProjectCRSFromLayer, SIGNAL( triggered() ), this, SLOT( setProjectCRSFromLayer() ) );
832841
connect( mActionTileScale, SIGNAL( triggered() ), this, SLOT( showTileScale() ) );
833-
connect( mActionGpsTool, SIGNAL( triggered() ), this, SLOT( showGpsTool() ) );
834842
connect( mActionLayerProperties, SIGNAL( triggered() ), this, SLOT( layerProperties() ) );
835843
connect( mActionLayerSubsetString, SIGNAL( triggered() ), this, SLOT( layerSubsetString() ) );
836844
connect( mActionAddToOverview, SIGNAL( triggered() ), this, SLOT( isInOverview() ) );
@@ -1871,17 +1879,6 @@ void QgisApp::saveWindowState()
18711879
settings.setValue( "/UI/tileScaleEnabled", false );
18721880
}
18731881

1874-
// Persist state of GPS Tracker
1875-
if ( mpGpsWidget )
1876-
{
1877-
settings.setValue( "/gps/widgetEnabled", true );
1878-
delete mpGpsWidget;
1879-
}
1880-
else
1881-
{
1882-
settings.setValue( "/gps/widgetEnabled", false );
1883-
}
1884-
18851882
QgsPluginRegistry::instance()->unloadAll();
18861883
}
18871884

@@ -4518,28 +4515,6 @@ void QgisApp::setProjectCRSFromLayer()
45184515
mMapCanvas->refresh();
45194516
}
45204517

4521-
void QgisApp::showGpsTool()
4522-
{
4523-
if ( !mpGpsWidget )
4524-
{
4525-
mpGpsWidget = new QgsGPSInformationWidget( mMapCanvas );
4526-
//create the dock widget
4527-
mpGpsDock = new QDockWidget( tr( "GPS Information" ), this );
4528-
mpGpsDock->setObjectName( "GPSInformation" );
4529-
mpGpsDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
4530-
addDockWidget( Qt::LeftDockWidgetArea, mpGpsDock );
4531-
// add to the Panel submenu
4532-
mPanelMenu->addAction( mpGpsDock->toggleViewAction() );
4533-
// now add our widget to the dock - ownership of the widget is passed to the dock
4534-
mpGpsDock->setWidget( mpGpsWidget );
4535-
mpGpsWidget->show();
4536-
}
4537-
else
4538-
{
4539-
mpGpsDock->setVisible( mpGpsDock->isHidden() );
4540-
}
4541-
}
4542-
45434518
void QgisApp::showTileScale()
45444519
{
45454520
if ( !mpTileScaleWidget )

src/app/qgisapp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
265265
QAction *actionSetLayerCRS() { return mActionSetLayerCRS; }
266266
QAction *actionSetProjectCRSFromLayer() { return mActionSetProjectCRSFromLayer; }
267267
QAction *actionTileScale() { return mActionTileScale; }
268-
QAction *actionGpsTool() { return mActionGpsTool; }
269268
QAction *actionLayerProperties() { return mActionLayerProperties; }
270269
QAction *actionLayerSubsetString() { return mActionLayerSubsetString; }
271270
QAction *actionAddToOverview() { return mActionAddToOverview; }
@@ -483,8 +482,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
483482
void setLayerCRS();
484483
//! Assign layer CRS to project
485484
void setProjectCRSFromLayer();
486-
//! Show GPS tool
487-
void showGpsTool();
488485
//! Show tile scale slider
489486
void showTileScale();
490487
//! zoom to extent of layer

src/core/gps/nmeatime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern "C"
3232
int hour; /**< Hours since midnight - [0,23] */
3333
int min; /**< Minutes after the hour - [0,59] */
3434
int sec; /**< Seconds after the minute - [0,59] */
35-
int hsec; /**< Hundredth part of second - [0,99] */
35+
int msec; /**< Thousandths part of second - [0,999] */
3636

3737
} nmeaTIME;
3838

src/core/gps/parse.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,22 @@ int _nmea_parse_time( const char *buff, int buff_sz, nmeaTIME *res )
7575
) );
7676
break;
7777
case sizeof( "hhmmss.s" ) - 1:
78+
success = ( 4 == nmea_scanf( buff, buff_sz,
79+
"%2d%2d%2d.%d", &( res->hour ), &( res->min ), &( res->sec ), &( res->msec )
80+
) );
81+
res->msec = res->msec * 100; // tenths sec * 100 = thousandths
82+
break;
7883
case sizeof( "hhmmss.ss" ) - 1:
84+
success = ( 4 == nmea_scanf( buff, buff_sz,
85+
"%2d%2d%2d.%d", &( res->hour ), &( res->min ), &( res->sec ), &( res->msec )
86+
) );
87+
res->msec = res->msec * 10; // hundredths sec * 10 = thousandths
88+
break;
7989
case sizeof( "hhmmss.sss" ) - 1:
8090
success = ( 4 == nmea_scanf( buff, buff_sz,
81-
"%2d%2d%2d.%d", &( res->hour ), &( res->min ), &( res->sec ), &( res->hsec )
91+
"%2d%2d%2d.%d", &( res->hour ), &( res->min ), &( res->sec ), &( res->msec )
8292
) );
93+
// already thousandths
8394
break;
8495
default:
8596
nmea_error( "Parse of time error (format error)!" );
@@ -380,7 +391,7 @@ void nmea_GPGGA2info( nmeaGPGGA *pack, nmeaINFO *info )
380391
info->utc.hour = pack->utc.hour;
381392
info->utc.min = pack->utc.min;
382393
info->utc.sec = pack->utc.sec;
383-
info->utc.hsec = pack->utc.hsec;
394+
info->utc.msec = pack->utc.msec;
384395
info->sig = pack->sig;
385396
info->HDOP = pack->HDOP;
386397
info->elv = pack->elv;

src/core/gps/qextserialport/qextserialenumerator.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313

1414
#ifdef Q_OS_WIN
1515
#ifdef __MINGW32__
16+
#ifdef _WIN32_WINNT
17+
#if _WIN32_WINNT < 0x0500
18+
#undef _WIN32_WINNT
19+
#define _WIN32_WINNT 0x0500
20+
#endif
21+
#else
1622
#define _WIN32_WINNT 0x0500
17-
#define _WIN32_WINDOWS 0x0500
18-
#define WINVER 0x0500
23+
#endif
1924
#endif
2025
#include <windows.h>
2126
#include <setupapi.h>

src/core/gps/qgsgpsconnection.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ void QgsGPSConnection::clearLastGPSInformation()
9494
mLastGPSInformation.satellitesInView.clear();
9595
mLastGPSInformation.speed = 0;
9696
mLastGPSInformation.vdop = 0;
97+
mLastGPSInformation.quality = -1; // valid values: 0,1,2, maybe others
98+
mLastGPSInformation.satellitesUsed = 0;
99+
mLastGPSInformation.fixMode = ' ';
100+
mLastGPSInformation.fixType = 0; // valid values: 1,2,3
101+
mLastGPSInformation.status = ' '; // valid values: A,V
97102
mLastGPSInformation.utcDateTime.setDate( QDate() );
103+
mLastGPSInformation.satPrn.clear();
98104
mLastGPSInformation.utcDateTime.setTime( QTime() );
105+
mLastGPSInformation.satInfoComplete = false;
99106
}

0 commit comments

Comments
 (0)