Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperate out gps logging code from gps digitizing related code
- Loading branch information
1 parent
0dfac0c
commit 77a1ca3
Showing
9 changed files
with
233 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/*************************************************************************** | ||
qgsappgpslogging.cpp | ||
------------------- | ||
begin : October 2022 | ||
copyright : (C) 2022 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsappgpslogging.h" | ||
#include "qgsgui.h" | ||
#include "qgisapp.h" | ||
#include "qgsmessagebar.h" | ||
#include "qgsgpsconnection.h" | ||
#include "qgsappgpsconnection.h" | ||
|
||
QgsAppGpsLogging::QgsAppGpsLogging( QgsAppGpsConnection *connection, QObject *parent ) | ||
: QgsGpsLogger( nullptr, parent ) | ||
, mConnection( connection ) | ||
{ | ||
connect( QgsProject::instance(), &QgsProject::transformContextChanged, this, [ = ] | ||
{ | ||
setTransformContext( QgsProject::instance()->transformContext() ); | ||
} ); | ||
setTransformContext( QgsProject::instance()->transformContext() ); | ||
|
||
setEllipsoid( QgsProject::instance()->ellipsoid() ); | ||
connect( QgsProject::instance(), &QgsProject::ellipsoidChanged, this, [ = ] | ||
{ | ||
setEllipsoid( QgsProject::instance()->ellipsoid() ); | ||
} ); | ||
|
||
connect( mConnection, &QgsAppGpsConnection::connected, this, &QgsAppGpsLogging::gpsConnected ); | ||
connect( mConnection, &QgsAppGpsConnection::disconnected, this, &QgsAppGpsLogging::gpsDisconnected ); | ||
|
||
connect( QgsGui::instance(), &QgsGui::optionsChanged, this, &QgsAppGpsLogging::updateGpsSettings ); | ||
updateGpsSettings(); | ||
} | ||
|
||
QgsAppGpsLogging::~QgsAppGpsLogging() | ||
{ | ||
} | ||
|
||
void QgsAppGpsLogging::setNmeaLogFile( const QString &filename ) | ||
{ | ||
if ( mLogFile ) | ||
{ | ||
stopLogging(); | ||
} | ||
|
||
mNmeaLogFile = filename; | ||
|
||
if ( mEnableNmeaLogging && !mNmeaLogFile.isEmpty() ) | ||
{ | ||
startLogging(); | ||
} | ||
} | ||
|
||
void QgsAppGpsLogging::setNmeaLoggingEnabled( bool enabled ) | ||
{ | ||
if ( enabled == static_cast< bool >( mLogFile ) ) | ||
return; | ||
|
||
if ( mLogFile && !enabled ) | ||
{ | ||
stopLogging(); | ||
} | ||
|
||
mEnableNmeaLogging = enabled; | ||
|
||
if ( mEnableNmeaLogging && !mNmeaLogFile.isEmpty() ) | ||
{ | ||
startLogging(); | ||
} | ||
} | ||
|
||
void QgsAppGpsLogging::setGpkgLogFile( const QString &filename ) | ||
{ | ||
|
||
} | ||
|
||
|
||
void QgsAppGpsLogging::gpsConnected() | ||
{ | ||
if ( !mLogFile && mEnableNmeaLogging && !mNmeaLogFile.isEmpty() ) | ||
{ | ||
startLogging(); | ||
} | ||
setConnection( mConnection->connection() ); | ||
} | ||
|
||
void QgsAppGpsLogging::gpsDisconnected() | ||
{ | ||
stopLogging(); | ||
setConnection( nullptr ); | ||
} | ||
|
||
void QgsAppGpsLogging::logNmeaSentence( const QString &nmeaString ) | ||
{ | ||
if ( mEnableNmeaLogging && mLogFile && mLogFile->isOpen() ) | ||
{ | ||
mLogFileTextStream << nmeaString << "\r\n"; // specifically output CR + LF (NMEA requirement) | ||
} | ||
} | ||
|
||
void QgsAppGpsLogging::startLogging() | ||
{ | ||
if ( !mLogFile ) | ||
{ | ||
mLogFile = std::make_unique< QFile >( mNmeaLogFile ); | ||
} | ||
|
||
if ( mLogFile->open( QIODevice::Append ) ) // open in binary and explicitly output CR + LF per NMEA | ||
{ | ||
mLogFileTextStream.setDevice( mLogFile.get() ); | ||
|
||
// crude way to separate chunks - use when manually editing file - NMEA parsers should discard | ||
mLogFileTextStream << "====" << "\r\n"; | ||
|
||
connect( mConnection, &QgsAppGpsConnection::nmeaSentenceReceived, this, &QgsAppGpsLogging::logNmeaSentence ); // added to handle raw data | ||
} | ||
else // error opening file | ||
{ | ||
mLogFile.reset(); | ||
|
||
// need to indicate why - this just reports that an error occurred | ||
QgisApp::instance()->messageBar()->pushCritical( QString(), tr( "Error opening log file." ) ); | ||
} | ||
} | ||
|
||
void QgsAppGpsLogging::stopLogging() | ||
{ | ||
if ( mLogFile && mLogFile->isOpen() ) | ||
{ | ||
disconnect( mConnection, &QgsAppGpsConnection::nmeaSentenceReceived, this, &QgsAppGpsLogging::logNmeaSentence ); | ||
mLogFile->close(); | ||
mLogFile.reset(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*************************************************************************** | ||
qgsappgpslogging.h | ||
------------------- | ||
begin : October 2022 | ||
copyright : (C) 2022 Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSAPPGPSLOGGING_H | ||
#define QGSAPPGPSLOGGING_H | ||
|
||
#include <QObject> | ||
|
||
#include "qgis_app.h" | ||
#include "qgssettingsentryimpl.h" | ||
#include "qgsgpslogger.h" | ||
|
||
#include <QTextStream> | ||
|
||
class QgsAppGpsConnection; | ||
class QFile; | ||
|
||
class APP_EXPORT QgsAppGpsLogging: public QgsGpsLogger | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
static const inline QgsSettingsEntryString settingLastLogFolder = QgsSettingsEntryString( QStringLiteral( "last-log-folder" ), QgsSettings::Prefix::GPS, QString(), QStringLiteral( "Last used folder for GPS log files" ) ); | ||
static const inline QgsSettingsEntryString settingLastGpkgLog = QgsSettingsEntryString( QStringLiteral( "last-gpkg-log" ), QgsSettings::Prefix::GPS, QString(), QStringLiteral( "Last used Geopackage/Spatialite file for logging GPS locations" ) ); | ||
|
||
QgsAppGpsLogging( QgsAppGpsConnection *connection, QObject *parent = nullptr ); | ||
~QgsAppGpsLogging() override; | ||
|
||
public slots: | ||
void setNmeaLogFile( const QString &filename ); | ||
void setNmeaLoggingEnabled( bool enabled ); | ||
void setGpkgLogFile( const QString &filename ); | ||
|
||
private slots: | ||
|
||
void gpsConnected(); | ||
void gpsDisconnected(); | ||
|
||
void logNmeaSentence( const QString &nmeaString ); // added to handle 'raw' data | ||
|
||
void startLogging(); | ||
void stopLogging(); | ||
|
||
private: | ||
QgsAppGpsConnection *mConnection = nullptr; | ||
|
||
QString mNmeaLogFile; | ||
bool mEnableNmeaLogging = false; | ||
|
||
std::unique_ptr< QFile > mLogFile; | ||
QTextStream mLogFileTextStream; | ||
}; | ||
|
||
#endif // QGSAPPGPSLOGGING_H |
Oops, something went wrong.