QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
@ QuoteFilePaths
File paths should be enclosed in quotations and escaped.
GpsFeatureType
Babel command flags.
Definition: qgis.h:666
@ Export
Format supports exporting.
@ Tracks
Format supports tracks.
@ Import
Format supports importing.
@ Waypoints
Format supports waypoints.
@ Routes
Format supports routes.
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
Default constructor.