QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsbabelgpsdevice.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsbabelgpsdevice.cpp
3 --------------------------------------
4 Date : Sun Sep 16 12:04:15 AKDT 2007
5 Copyright : (C) 2007 by Gary E. Sherman
6 Email : sherman at mrcc dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#include "qgsbabelgpsdevice.h"
16
17#include <QRegularExpression>
18
19QgsBabelGpsDeviceFormat::QgsBabelGpsDeviceFormat( const QString &waypointDownloadCommand, const QString &waypointUploadCommand,
20 const QString &routeDownloadCommand, const QString &routeUploadCommand,
21 const QString &trackDownloadCommand, const QString &trackUploadCommand )
22{
23 const thread_local QRegularExpression whiteSpaceRx( QStringLiteral( "\\s" ) );
24
25 if ( !waypointDownloadCommand.isEmpty() )
26 {
27 mWaypointDownloadCommand = waypointDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
30 }
31 if ( !waypointUploadCommand.isEmpty() )
32 {
33 mWaypointUploadCommand = waypointUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
36 }
37 if ( !routeDownloadCommand.isEmpty() )
38 {
39 mRouteDownloadCommand = routeDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
42 }
43 if ( !routeUploadCommand.isEmpty() )
44 {
45 mRouteUploadCommand = routeUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
48 }
49 if ( !trackDownloadCommand.isEmpty() )
50 {
51 mTrackDownloadCommand = trackDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
54 }
55 if ( !trackUploadCommand.isEmpty() )
56 {
57 mTrackUploadCommand = trackUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
60 }
61}
62
63QStringList QgsBabelGpsDeviceFormat::importCommand( const QString &babel,
65 const QString &in,
66 const QString &out, Qgis::BabelCommandFlags flags ) const
67{
68 QStringList original;
69
70 switch ( type )
71 {
73 original = mWaypointDownloadCommand;
74 break;
76 original = mRouteDownloadCommand;
77 break;
79 original = mTrackDownloadCommand;
80 break;
81 }
82
83 QStringList copy;
84 copy.reserve( original.size() );
85 for ( const QString &iter : std::as_const( original ) )
86 {
87 if ( iter == QLatin1String( "%babel" ) )
88 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
89 else if ( iter == QLatin1String( "%type" ) )
90 copy.append( featureTypeToArgument( type ) );
91 else if ( iter == QLatin1String( "%in" ) )
92 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
93 else if ( iter == QLatin1String( "%out" ) )
94 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
95 else
96 copy.append( iter );
97 }
98 return copy;
99}
100
101QStringList QgsBabelGpsDeviceFormat::exportCommand( const QString &babel,
103 const QString &in,
104 const QString &out, Qgis::BabelCommandFlags flags ) const
105{
106 QStringList original;
107 switch ( type )
108 {
110 original = mWaypointUploadCommand;
111 break;
113 original = mRouteUploadCommand;
114 break;
116 original = mTrackUploadCommand;
117 break;
118 }
119
120 QStringList copy;
121 copy.reserve( original.size() );
122 for ( const QString &iter : std::as_const( original ) )
123 {
124 if ( iter == QLatin1String( "%babel" ) )
125 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
126 else if ( iter == QLatin1String( "%type" ) )
127 copy.append( featureTypeToArgument( type ) );
128 else if ( iter == QLatin1String( "%in" ) )
129 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
130 else if ( iter == QLatin1String( "%out" ) )
131 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
132 else
133 copy.append( iter );
134 }
135 return copy;
136}
137
138
139
QFlags< BabelCommandFlag > BabelCommandFlags
Babel command flags.
Definition qgis.h:2017
@ QuoteFilePaths
File paths should be enclosed in quotations and escaped.
Definition qgis.h:2014
GpsFeatureType
GPS feature types.
Definition qgis.h:2027
@ Waypoint
Waypoint.
Definition qgis.h:2028
@ Export
Format supports exporting.
Definition qgis.h:1996
@ Tracks
Format supports tracks.
Definition qgis.h:1999
@ Import
Format supports importing.
Definition qgis.h:1995
@ Waypoints
Format supports waypoints.
Definition qgis.h:1997
@ Routes
Format supports routes.
Definition qgis.h:1998
Qgis::BabelFormatCapabilities mCapabilities
static QString featureTypeToArgument(Qgis::GpsFeatureType type)
Converts a GPS feature type to the equivalent babel argument.
QStringList exportCommand(const QString &babel, Qgis::GpsFeatureType type, const QString &in, const QString &out, Qgis::BabelCommandFlags flags=Qgis::BabelCommandFlags()) const override
Generates a command for exporting GPS data into a different format using babel.
QStringList importCommand(const QString &babel, Qgis::GpsFeatureType type, const QString &in, const QString &out, Qgis::BabelCommandFlags flags=Qgis::BabelCommandFlags()) const override
Generates a command for importing data into a GPS format using babel.
QgsBabelGpsDeviceFormat()=default