Skip to content

Commit

Permalink
Merge pull request #30354 from elpaso/gps-time
Browse files Browse the repository at this point in the history
GPS timestamp support
  • Loading branch information
elpaso committed Jun 24, 2019
2 parents a812bee + 9b1d080 commit a843288
Show file tree
Hide file tree
Showing 8 changed files with 659 additions and 103 deletions.
3 changes: 3 additions & 0 deletions resources/qgis_global_settings.ini
Expand Up @@ -116,3 +116,6 @@ default_checks=
enable_problem_resolution=false


[gps]
# Default for GPS leap seconds correction as of 2019-06-19
leapSecondsCorrection=18
329 changes: 252 additions & 77 deletions src/app/gps/qgsgpsinformationwidget.cpp

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions src/app/gps/qgsgpsinformationwidget.h
Expand Up @@ -18,9 +18,10 @@
#define QGSGPSINFORMATIONWIDGET_H

#include "ui_qgsgpsinformationwidgetbase.h"

#include "qgis_app.h"
#include "gmath.h"
#include "info.h"
#include "nmeatime.h"
#include "qgsgpsmarker.h"
#include "qgsmaptoolcapture.h"
#include <qwt_plot_curve.h>
Expand All @@ -35,6 +36,7 @@ class QgsGpsConnection;
class QgsGpsTrackerThread;
struct QgsGpsInformation;
class QgsMapCanvas;
class QgsFeature;

class QFile;
class QColor;
Expand All @@ -43,13 +45,12 @@ class QColor;
* A dock widget that displays information from a GPS device and
* allows the user to capture features using gps readings to
* specify the geometry.*/
class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidgetBase
class APP_EXPORT QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidgetBase
{
Q_OBJECT
public:
QgsGpsInformationWidget( QgsMapCanvas *thepCanvas, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
QgsGpsInformationWidget( QgsMapCanvas *mapCanvas, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr );
~QgsGpsInformationWidget() override;

private slots:
void mConnectButton_toggled( bool flag );
void displayGPSInformation( const QgsGpsInformation &info );
Expand All @@ -76,6 +77,12 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg
void switchAcquisition();
void cboAcquisitionIntervalEdited();
void cboDistanceThresholdEdited();
void timestampFormatChanged( int index );

/**
* Updates compatible fields for timestamp recording
*/
void updateTimestampDestinationFields( QgsMapLayer *mapLayer );
private:
enum FixStatus //GPS status
{
Expand All @@ -90,11 +97,13 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg
void showStatusBarMessage( const QString &msg );
void setAcquisitionInterval( uint );
void setDistanceThreshold( uint );
void updateTimeZones();
QVariant timestamp( QgsVectorLayer *vlayer, int idx );
QgsGpsConnection *mNmea = nullptr;
QgsMapCanvas *mpCanvas = nullptr;
QgsGpsMarker *mpMapMarker = nullptr;
QwtPlot *mpPlot = nullptr;
QwtPlotCurve *mpCurve = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsGpsMarker *mMapMarker = nullptr;
QwtPlot *mPlot = nullptr;
QwtPlotCurve *mCurve = nullptr;
#ifdef WITH_QWTPOLAR
QwtPolarPlot *mpSatellitesWidget = nullptr;
QwtPolarGrid *mpSatellitesGrid = nullptr;
Expand All @@ -104,21 +113,27 @@ class QgsGpsInformationWidget: public QWidget, private Ui::QgsGpsInformationWidg

QgsCoordinateReferenceSystem mWgs84CRS;
// not used QPointF gpsToPixelPosition( const QgsPoint& point );
QgsRubberBand *mpRubberBand = nullptr;
QgsRubberBand *mRubberBand = nullptr;
QgsPointXY mLastGpsPosition;
QList<QgsPointXY> mCaptureList;
FixStatus mLastFixStatus;
QString mDateTimeFormat; // user specified format string in registry (no UI presented)
QPointer< QgsVectorLayer > mpLastLayer;
QPointer< QgsVectorLayer > mLastLayer;
QFile *mLogFile = nullptr;
QTextStream mLogFileTextStream;
QIntValidator *mAcquisitionIntValidator = nullptr;
QIntValidator *mDistanceThresholdValidator = nullptr;
nmeaPOS mLastNmeaPosition;
nmeaTIME mLastNmeaTime;
std::unique_ptr<QTimer> mAcquisitionTimer;
bool mAcquisitionEnabled = true;
unsigned int mAcquisitionInterval = 0;
int mAcquisitionInterval = 0;
unsigned int mDistanceThreshold = 0;
//! Temporary storage of preferred fields
QMap<QString, QString> mPreferredTimestampFields;
//! Flag when updating fields
bool mPopulatingFields = false;
friend class TestQgsGpsInformationWidget;
};

#endif // QGSGPSINFORMATIONWIDGET_H
17 changes: 8 additions & 9 deletions src/app/gps/qgsgpsmarker.cpp
Expand Up @@ -14,23 +14,22 @@
***************************************************************************/

#include <QPainter>
#include <QObject>

#include "qgsgpsmarker.h"
#include "qgscoordinatetransform.h"
#include "qgsmapcanvas.h"
#include "qgsexception.h"
#include "qgsproject.h"
#include "qgsmessagelog.h"


QgsGpsMarker::QgsGpsMarker( QgsMapCanvas *mapCanvas )
: QgsMapCanvasItem( mapCanvas )
{
mSize = 16;
mWgs84CRS = QgsCoordinateReferenceSystem::fromOgcWmsCrs( QStringLiteral( "EPSG:4326" ) );
mSvg.load( QStringLiteral( ":/images/north_arrows/gpsarrow2.svg" ) );
if ( ! mSvg.isValid() )
{
qDebug( "GPS marker not found!" );
}
}

void QgsGpsMarker::setSize( int size )
Expand All @@ -50,7 +49,7 @@ void QgsGpsMarker::setCenter( const QgsPointXY &point )
}
catch ( QgsCsException &e ) //silently ignore transformation exceptions
{
Q_UNUSED( e )
QgsMessageLog::logMessage( QObject::tr( "Error transforming the map center point: %1" ).arg( e.what() ), QStringLiteral( "GPS" ), Qgis::Warning );
return;
}
}
Expand All @@ -75,15 +74,15 @@ void QgsGpsMarker::paint( QPainter *p )
QPointF pt = toCanvasCoordinates( mCenter );
setPos( pt );

float myHalfSize = mSize / 2.0;
mSvg.render( p, QRectF( 0 - myHalfSize, 0 - myHalfSize, mSize, mSize ) );
double halfSize = mSize / 2.0;
mSvg.render( p, QRectF( 0 - halfSize, 0 - halfSize, mSize, mSize ) );
}


QRectF QgsGpsMarker::boundingRect() const
{
float myHalfSize = mSize / 2.0;
return QRectF( -myHalfSize, -myHalfSize, 2.0 * myHalfSize, 2.0 * myHalfSize );
double halfSize = mSize / 2.0;
return QRectF( -halfSize, -halfSize, 2.0 * halfSize, 2.0 * halfSize );
}

void QgsGpsMarker::updatePosition()
Expand Down
72 changes: 66 additions & 6 deletions src/ui/qgsgpsinformationwidgetbase.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>215</width>
<width>324</width>
<height>591</height>
</rect>
</property>
Expand Down Expand Up @@ -157,8 +157,8 @@ gray = no data
<rect>
<x>0</x>
<y>0</y>
<width>214</width>
<height>505</height>
<width>121</width>
<height>488</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -578,8 +578,8 @@ gray = no data
<rect>
<x>0</x>
<y>0</y>
<width>241</width>
<height>696</height>
<width>306</width>
<height>1000</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
Expand Down Expand Up @@ -1026,7 +1026,7 @@ gray = no data
<property name="verticalSpacing">
<number>2</number>
</property>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Track</string>
Expand Down Expand Up @@ -1098,6 +1098,61 @@ gray = no data
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="mGboxTimestamp">
<property name="title">
<string>Timestamp properties</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="toolTip">
<string>Specify the field where the GPS timestamp will be saved, only string or datetime fields are supported</string>
</property>
<property name="text">
<string>Destination</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsFieldComboBox" name="mCboTimestampField"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mLblTimestampFormat">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mCboTimestampFormat"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mLblTimeZone">
<property name="text">
<string>Timezone</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="mCboTimeZones"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="mLeapSeconds"/>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="mCbxLeapSeconds">
<property name="toolTip">
<string>Apply leap seconds correction by adding the seconds to GPS timestamp</string>
</property>
<property name="text">
<string>Leap seconds</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1319,6 +1374,11 @@ gray = no data
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
<customwidget>
<class>QgsFieldComboBox</class>
<extends>QComboBox</extends>
<header>qgsfieldcombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mBtnCloseFeature</tabstop>
Expand Down
2 changes: 2 additions & 0 deletions tests/src/app/CMakeLists.txt
Expand Up @@ -3,6 +3,7 @@
# the UI file won't be wrapped!
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/external/nmea
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/expression
Expand Down Expand Up @@ -124,3 +125,4 @@ ADD_QGIS_TEST(projectproperties testqgsprojectproperties.cpp)
ADD_QGIS_TEST(layoutvaliditychecks testqgsapplayoutvaliditychecks.cpp)
ADD_QGIS_TEST(meshcalculator testqgsmeshcalculatordialog.cpp)
ADD_QGIS_TEST(meshlayerpropertiesdialog testqgsmeshlayerpropertiesdialog.cpp)
ADD_QGIS_TEST(gpsinformationwidget testqgsgpsinformationwidget.cpp)

0 comments on commit a843288

Please sign in to comment.