QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 <QRegularExpression>
16 
17 #include "qgsbabelgpsdevice.h"
18 
19 
20 QgsBabelGpsDeviceFormat::QgsBabelGpsDeviceFormat( const QString &waypointDownloadCommand, const QString &waypointUploadCommand,
21  const QString &routeDownloadCommand, const QString &routeUploadCommand,
22  const QString &trackDownloadCommand, const QString &trackUploadCommand )
23 {
24  const thread_local QRegularExpression whiteSpaceRx( QStringLiteral( "\\s" ) );
25 
26 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
27  if ( !waypointDownloadCommand.isEmpty() )
28  {
29  mWaypointDownloadCommand = waypointDownloadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
32  }
33  if ( !waypointUploadCommand.isEmpty() )
34  {
35  mWaypointUploadCommand = waypointUploadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
38  }
39  if ( !routeDownloadCommand.isEmpty() )
40  {
41  mRouteDownloadCommand = routeDownloadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
44  }
45  if ( !routeUploadCommand.isEmpty() )
46  {
47  mRouteUploadCommand = routeUploadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
50  }
51  if ( !trackDownloadCommand.isEmpty() )
52  {
53  mTrackDownloadCommand = trackDownloadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
56  }
57  if ( !trackUploadCommand.isEmpty() )
58  {
59  mTrackUploadCommand = trackUploadCommand.split( whiteSpaceRx, QString::SkipEmptyParts );
62  }
63 #else
64 
65  if ( !waypointDownloadCommand.isEmpty() )
66  {
67  mWaypointDownloadCommand = waypointDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
70  }
71  if ( !waypointUploadCommand.isEmpty() )
72  {
73  mWaypointUploadCommand = waypointUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
76  }
77  if ( !routeDownloadCommand.isEmpty() )
78  {
79  mRouteDownloadCommand = routeDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
82  }
83  if ( !routeUploadCommand.isEmpty() )
84  {
85  mRouteUploadCommand = routeUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
88  }
89  if ( !trackDownloadCommand.isEmpty() )
90  {
91  mTrackDownloadCommand = trackDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
94  }
95  if ( !trackUploadCommand.isEmpty() )
96  {
97  mTrackUploadCommand = trackUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
100  }
101 #endif
102 }
103 
104 QStringList QgsBabelGpsDeviceFormat::importCommand( const QString &babel,
106  const QString &in,
107  const QString &out, Qgis::BabelCommandFlags flags ) const
108 {
109  QStringList original;
110 
111  switch ( type )
112  {
114  original = mWaypointDownloadCommand;
115  break;
117  original = mRouteDownloadCommand;
118  break;
120  original = mTrackDownloadCommand;
121  break;
122  }
123 
124  QStringList copy;
125  copy.reserve( original.size() );
126  for ( const QString &iter : std::as_const( original ) )
127  {
128  if ( iter == QLatin1String( "%babel" ) )
129  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
130  else if ( iter == QLatin1String( "%type" ) )
131  copy.append( featureTypeToArgument( type ) );
132  else if ( iter == QLatin1String( "%in" ) )
133  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
134  else if ( iter == QLatin1String( "%out" ) )
135  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
136  else
137  copy.append( iter );
138  }
139  return copy;
140 }
141 
142 QStringList QgsBabelGpsDeviceFormat::exportCommand( const QString &babel,
144  const QString &in,
145  const QString &out, Qgis::BabelCommandFlags flags ) const
146 {
147  QStringList original;
148  switch ( type )
149  {
151  original = mWaypointUploadCommand;
152  break;
154  original = mRouteUploadCommand;
155  break;
157  original = mTrackUploadCommand;
158  break;
159  }
160 
161  QStringList copy;
162  copy.reserve( original.size() );
163  for ( const QString &iter : std::as_const( original ) )
164  {
165  if ( iter == QLatin1String( "%babel" ) )
166  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
167  else if ( iter == QLatin1String( "%type" ) )
168  copy.append( featureTypeToArgument( type ) );
169  else if ( iter == QLatin1String( "%in" ) )
170  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
171  else if ( iter == QLatin1String( "%out" ) )
172  copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
173  else
174  copy.append( iter );
175  }
176  return copy;
177 }
178 
179 
180 
Qgis::GpsFeatureType::Waypoint
@ Waypoint
Waypoint.
Qgis::BabelFormatCapability::Tracks
@ Tracks
Format supports tracks.
qgsbabelgpsdevice.h
QgsBabelGpsDeviceFormat::QgsBabelGpsDeviceFormat
QgsBabelGpsDeviceFormat()=default
Default constructor.
QgsBabelGpsDeviceFormat::exportCommand
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.
Definition: qgsbabelgpsdevice.cpp:142
Qgis::BabelFormatCapability::Waypoints
@ Waypoints
Format supports waypoints.
Qgis::BabelCommandFlag::QuoteFilePaths
@ QuoteFilePaths
File paths should be enclosed in quotations and escaped.
QgsBabelGpsDeviceFormat::importCommand
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.
Definition: qgsbabelgpsdevice.cpp:104
QgsAbstractBabelFormat::mCapabilities
Qgis::BabelFormatCapabilities mCapabilities
Definition: qgsbabelformat.h:98
Qgis::BabelFormatCapability::Export
@ Export
Format supports exporting.
Qgis::GpsFeatureType::Route
@ Route
Route.
Qgis::GpsFeatureType
GpsFeatureType
Babel command flags.
Definition: qgis.h:886
Qgis::BabelFormatCapability::Import
@ Import
Format supports importing.
Qgis::BabelFormatCapability::Routes
@ Routes
Format supports routes.
Qgis::GpsFeatureType::Track
@ Track
Track.
QgsAbstractBabelFormat::featureTypeToArgument
static QString featureTypeToArgument(Qgis::GpsFeatureType type)
Converts a GPS feature type to the equivalent babel argument.
Definition: qgsbabelformat.cpp:27