Skip to content

Commit

Permalink
Add a registry for GPSbabel formats
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 31, 2021
1 parent af9a72e commit 612af1f
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 158 deletions.
87 changes: 87 additions & 0 deletions python/core/auto_generated/gps/qgsbabelformatregistry.sip.in
@@ -0,0 +1,87 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/gps/qgsbabelformatregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsBabelFormatRegistry
{
%Docstring(signature="appended")
A registry for :py:class:`QgsAbstractBabelFormat` GPSBabel formats.

:py:class:`QgsBabelFormatRegistry` is not usually directly created, but rather accessed through
:py:func:`QgsApplication.gpsBabelFormatRegistry()`.

.. versionadded:: 3.22
%End

%TypeHeaderCode
#include "qgsbabelformatregistry.h"
%End
public:

QgsBabelFormatRegistry();
%Docstring
Constructor for QgsBabelFormatRegistry.

The registry will automatically be populated with standard formats, and with
devices previously configured and stored in QSettings.
%End
~QgsBabelFormatRegistry();


QStringList importFormatNames() const;
%Docstring
Returns a list of the names of all registered import formats.
%End

QgsAbstractBabelFormat *importFormat( const QString &name );
%Docstring
Returns a registered import format by ``name``.

.. seealso:: :py:func:`importFormatNames`
%End

QStringList deviceNames() const;
%Docstring
Returns a list of the names of all registered devices.
%End

QgsBabelGpsDeviceFormat *deviceFormat( const QString &name );
%Docstring
Returns a registered device format by ``name``.

.. seealso:: :py:func:`deviceNames`
%End

QMap< QString, QgsBabelGpsDeviceFormat * > devices() const;
%Docstring
Returns a map of device name to device format.

.. seealso:: :py:func:`deviceFormat`

.. seealso:: :py:func:`deviceNames`
%End

void reloadFromSettings();
%Docstring
Reloads the registry's members from the currently stored configuration.
%End

private:
QgsBabelFormatRegistry( const QgsBabelFormatRegistry &rh );
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/gps/qgsbabelformatregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsapplication.sip.in
Expand Up @@ -792,6 +792,13 @@ Returns the application's annotation item registry, used for annotation item typ
Returns the application's GPS connection registry, used for managing GPS connections.

.. versionadded:: 3.0
%End

static QgsBabelFormatRegistry *gpsBabelFormatRegistry() /KeepReference/;
%Docstring
Returns the application's GPSBabel format registry, used for managing GPSBabel formats.

.. versionadded:: 3.22
%End

static QgsPluginLayerRegistry *pluginLayerRegistry() /KeepReference/;
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -321,6 +321,7 @@
%Include auto_generated/geometry/qgswkbtypes.sip
%Include auto_generated/geometry/qgsray3d.sip
%Include auto_generated/gps/qgsbabelformat.sip
%Include auto_generated/gps/qgsbabelformatregistry.sip
%Include auto_generated/gps/qgsbabelgpsdevice.sip
%Include auto_generated/gps/qgsgpsconnection.sip
%Include auto_generated/gps/qgsgpsdconnection.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -52,6 +52,7 @@ set(QGIS_CORE_SRCS
geocoding/qgsgooglemapsgeocoder.cpp

gps/qgsbabelformat.cpp
gps/qgsbabelformatregistry.cpp
gps/qgsbabelgpsdevice.cpp
gps/qgsgpsconnection.cpp
gps/qgsgpsconnectionregistry.cpp
Expand Down Expand Up @@ -1286,6 +1287,7 @@ set(QGIS_CORE_HDRS
geometry/qgsray3d.h

gps/qgsbabelformat.h
gps/qgsbabelformatregistry.h
gps/qgsbabelgpsdevice.h
gps/qgsgpsconnection.h
gps/qgsgpsdconnection.h
Expand Down
154 changes: 154 additions & 0 deletions src/core/gps/qgsbabelformatregistry.cpp
@@ -0,0 +1,154 @@
/***************************************************************************
qgsbabelformatregistry.cpp
-------------------
begin : July 2021
copyright : (C) 2021 by 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 "qgsbabelformatregistry.h"
#include "qgsbabelformat.h"
#include "qgsbabelgpsdevice.h"
#include "qgssettings.h"
#include <QString>

QgsBabelFormatRegistry::QgsBabelFormatRegistry()
{
mImporters[QStringLiteral( "Shapefile" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "shape" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Routes | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Geocaching.com .loc" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "geo" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Magellan Mapsend" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "mapsend" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Routes | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Garmin PCX5" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "pcx" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Garmin Mapsource" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "mapsource" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Routes | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "GPSUtil" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "gpsutil" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "PocketStreets 2002/2003 Pushpin" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "psp" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "CoPilot Flight Planner" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "copilot" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Magellan Navigator Companion" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "magnav" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Holux" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "holux" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Topo by National Geographic" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "tpg" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "TopoMapPro" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "tmpro" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "GeocachingDB" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "gcdb" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Tiger" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "tiger" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "EasyGPS Binary Format" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "easygps" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Delorme Routes" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "saroute" ), Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Navicache" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "navicache" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "PSITrex" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "psitrex" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Routes | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Delorme GPS Log" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "gpl" ), Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "OziExplorer" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "ozi" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "NMEA Sentences" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "nmea" ), Qgis::BabelFormatCapability::Waypoints | Qgis::BabelFormatCapability::Tracks );
mImporters[QStringLiteral( "Delorme Street Atlas 2004 Plus" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "saplus" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Microsoft Streets and Trips" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "s_and_t" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "NIMA/GNIS Geographic Names" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "nima" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Maptech" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "mxf" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Mapopolis.com Mapconverter Application" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "mapconverter" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "GPSman" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "gpsman" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "GPSDrive" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "gpsdrive" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "Fugawi" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "fugawi" ), Qgis::BabelFormatCapability::Waypoints );
mImporters[QStringLiteral( "DNA" )] =
new QgsBabelSimpleImportFormat( QStringLiteral( "dna" ), Qgis::BabelFormatCapability::Waypoints );

reloadFromSettings();
}

QgsBabelFormatRegistry::~QgsBabelFormatRegistry()
{
qDeleteAll( mImporters );
qDeleteAll( mDevices );
}

QStringList QgsBabelFormatRegistry::importFormatNames() const
{
return mImporters.keys();
}

QgsAbstractBabelFormat *QgsBabelFormatRegistry::importFormat( const QString &name )
{
return mImporters.value( name );
}

QStringList QgsBabelFormatRegistry::deviceNames() const
{
return mDevices.keys();
}

QgsBabelGpsDeviceFormat *QgsBabelFormatRegistry::deviceFormat( const QString &name )
{
return mDevices.value( name );
}

QMap<QString, QgsBabelGpsDeviceFormat *> QgsBabelFormatRegistry::devices() const
{
return mDevices;
}

void QgsBabelFormatRegistry::reloadFromSettings()
{
qDeleteAll( mDevices );
mDevices.clear();

mDevices[QStringLiteral( "Garmin serial" )] =
new QgsBabelGpsDeviceFormat( QStringLiteral( "%babel -w -i garmin -o gpx %in %out" ),
QStringLiteral( "%babel -w -i gpx -o garmin %in %out" ),
QStringLiteral( "%babel -r -i garmin -o gpx %in %out" ),
QStringLiteral( "%babel -r -i gpx -o garmin %in %out" ),
QStringLiteral( "%babel -t -i garmin -o gpx %in %out" ),
QStringLiteral( "%babel -t -i gpx -o garmin %in %out" ) );

QgsSettings settings;
const QStringList deviceNames = settings.value( QStringLiteral( "Plugin-GPS/devicelist" ) ).toStringList();
for ( const QString &device : deviceNames )
{
const QString baseKey = QStringLiteral( "/Plugin-GPS/devices/%1" ).arg( device );
const QString wptDownload = settings.value( QStringLiteral( "%1/wptdownload" ).arg( baseKey ) ).toString();
const QString wptUpload = settings.value( QStringLiteral( "%1/wptupload" ).arg( baseKey ) ).toString();
const QString rteDownload = settings.value( QStringLiteral( "%1/rtedownload" ).arg( baseKey ) ).toString();
const QString rteUpload = settings.value( QStringLiteral( "%1/rteupload" ).arg( baseKey ) ).toString();
const QString trkDownload = settings.value( QStringLiteral( "%1/trkdownload" ).arg( baseKey ) ).toString();
const QString trkUpload = settings.value( QStringLiteral( "%1/trkupload" ).arg( baseKey ) ).toString();

mDevices[device] = new QgsBabelGpsDeviceFormat( wptDownload,
wptUpload,
rteDownload,
rteUpload,
trkDownload,
trkUpload );
}
}

102 changes: 102 additions & 0 deletions src/core/gps/qgsbabelformatregistry.h
@@ -0,0 +1,102 @@
/***************************************************************************
qgsbabelformatregistry.h
-------------------
begin : July 2021
copyright : (C) 2021 by 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 QGSBABELFORMATREGISTRY_H
#define QGSBABELFORMATREGISTRY_H

#include "qgis_core.h"
#include "qgis.h"

class QgsAbstractBabelFormat;
class QgsBabelGpsDeviceFormat;

/**
* \ingroup core
* \class QgsBabelFormatRegistry
* \brief A registry for QgsAbstractBabelFormat GPSBabel formats.
*
* QgsBabelFormatRegistry is not usually directly created, but rather accessed through
* QgsApplication::gpsBabelFormatRegistry().
*
* \since QGIS 3.22
*/
class CORE_EXPORT QgsBabelFormatRegistry
{
public:

/**
* Constructor for QgsBabelFormatRegistry.
*
* The registry will automatically be populated with standard formats, and with
* devices previously configured and stored in QSettings.
*/
QgsBabelFormatRegistry();
~QgsBabelFormatRegistry();

//! QgsBabelFormatRegistry cannot be copied.
QgsBabelFormatRegistry( const QgsBabelFormatRegistry &rh ) = delete;
//! QgsBabelFormatRegistry cannot be copied.
QgsBabelFormatRegistry &operator=( const QgsBabelFormatRegistry &rh ) = delete;

/**
* Returns a list of the names of all registered import formats.
*/
QStringList importFormatNames() const;

/**
* Returns a registered import format by \a name.
*
* \see importFormatNames().
*/
QgsAbstractBabelFormat *importFormat( const QString &name );

/**
* Returns a list of the names of all registered devices.
*/
QStringList deviceNames() const;

/**
* Returns a registered device format by \a name.
*
* \see deviceNames().
*/
QgsBabelGpsDeviceFormat *deviceFormat( const QString &name );

/**
* Returns a map of device name to device format.
*
* \see deviceFormat()
* \see deviceNames()
*/
QMap< QString, QgsBabelGpsDeviceFormat * > devices() const;

/**
* Reloads the registry's members from the currently stored configuration.
*/
void reloadFromSettings();

private:
#ifdef SIP_RUN
QgsBabelFormatRegistry( const QgsBabelFormatRegistry &rh );
#endif

//! Importers for external GPS data file formats
QMap< QString, QgsAbstractBabelFormat *> mImporters;
//! Upload/downloaders for GPS devices
QMap< QString, QgsBabelGpsDeviceFormat *> mDevices;
};


#endif // QGSBABELFORMATREGISTRY_H

0 comments on commit 612af1f

Please sign in to comment.