QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 <QRegularExpression>
16
17#include "qgsbabelgpsdevice.h"
18
19
20QgsBabelGpsDeviceFormat::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 ( !waypointDownloadCommand.isEmpty() )
27 {
28 mWaypointDownloadCommand = waypointDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
31 }
32 if ( !waypointUploadCommand.isEmpty() )
33 {
34 mWaypointUploadCommand = waypointUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
37 }
38 if ( !routeDownloadCommand.isEmpty() )
39 {
40 mRouteDownloadCommand = routeDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
43 }
44 if ( !routeUploadCommand.isEmpty() )
45 {
46 mRouteUploadCommand = routeUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
49 }
50 if ( !trackDownloadCommand.isEmpty() )
51 {
52 mTrackDownloadCommand = trackDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
55 }
56 if ( !trackUploadCommand.isEmpty() )
57 {
58 mTrackUploadCommand = trackUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
61 }
62}
63
64QStringList QgsBabelGpsDeviceFormat::importCommand( const QString &babel,
66 const QString &in,
67 const QString &out, Qgis::BabelCommandFlags flags ) const
68{
69 QStringList original;
70
71 switch ( type )
72 {
74 original = mWaypointDownloadCommand;
75 break;
77 original = mRouteDownloadCommand;
78 break;
80 original = mTrackDownloadCommand;
81 break;
82 }
83
84 QStringList copy;
85 copy.reserve( original.size() );
86 for ( const QString &iter : std::as_const( original ) )
87 {
88 if ( iter == QLatin1String( "%babel" ) )
89 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
90 else if ( iter == QLatin1String( "%type" ) )
91 copy.append( featureTypeToArgument( type ) );
92 else if ( iter == QLatin1String( "%in" ) )
93 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
94 else if ( iter == QLatin1String( "%out" ) )
95 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
96 else
97 copy.append( iter );
98 }
99 return copy;
100}
101
102QStringList QgsBabelGpsDeviceFormat::exportCommand( const QString &babel,
104 const QString &in,
105 const QString &out, Qgis::BabelCommandFlags flags ) const
106{
107 QStringList original;
108 switch ( type )
109 {
111 original = mWaypointUploadCommand;
112 break;
114 original = mRouteUploadCommand;
115 break;
117 original = mTrackUploadCommand;
118 break;
119 }
120
121 QStringList copy;
122 copy.reserve( original.size() );
123 for ( const QString &iter : std::as_const( original ) )
124 {
125 if ( iter == QLatin1String( "%babel" ) )
126 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( babel ) : babel );
127 else if ( iter == QLatin1String( "%type" ) )
128 copy.append( featureTypeToArgument( type ) );
129 else if ( iter == QLatin1String( "%in" ) )
130 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( in ) : in );
131 else if ( iter == QLatin1String( "%out" ) )
132 copy.append( ( flags & Qgis::BabelCommandFlag::QuoteFilePaths ) ? QStringLiteral( "\"%1\"" ).arg( out ) : out );
133 else
134 copy.append( iter );
135 }
136 return copy;
137}
138
139
140
QFlags< BabelCommandFlag > BabelCommandFlags
Babel command flags.
Definition qgis.h:1864
@ QuoteFilePaths
File paths should be enclosed in quotations and escaped.
GpsFeatureType
GPS feature types.
Definition qgis.h:1874
@ 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