QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
gps
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
#include <QString>
19
20
using namespace
Qt::StringLiterals;
21
22
QgsBabelGpsDeviceFormat::QgsBabelGpsDeviceFormat
(
23
const
QString &waypointDownloadCommand,
24
const
QString &waypointUploadCommand,
25
const
QString &routeDownloadCommand,
26
const
QString &routeUploadCommand,
27
const
QString &trackDownloadCommand,
28
const
QString &trackUploadCommand
29
)
30
{
31
const
thread_local
QRegularExpression whiteSpaceRx( u
"\\s"
_s );
32
33
if
( !waypointDownloadCommand.isEmpty() )
34
{
35
mWaypointDownloadCommand = waypointDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
36
mCapabilities
|=
Qgis::BabelFormatCapability::Waypoints
;
37
mCapabilities
|=
Qgis::BabelFormatCapability::Import
;
38
}
39
if
( !waypointUploadCommand.isEmpty() )
40
{
41
mWaypointUploadCommand = waypointUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
42
mCapabilities
|=
Qgis::BabelFormatCapability::Waypoints
;
43
mCapabilities
|=
Qgis::BabelFormatCapability::Export
;
44
}
45
if
( !routeDownloadCommand.isEmpty() )
46
{
47
mRouteDownloadCommand = routeDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
48
mCapabilities
|=
Qgis::BabelFormatCapability::Routes
;
49
mCapabilities
|=
Qgis::BabelFormatCapability::Import
;
50
}
51
if
( !routeUploadCommand.isEmpty() )
52
{
53
mRouteUploadCommand = routeUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
54
mCapabilities
|=
Qgis::BabelFormatCapability::Routes
;
55
mCapabilities
|=
Qgis::BabelFormatCapability::Export
;
56
}
57
if
( !trackDownloadCommand.isEmpty() )
58
{
59
mTrackDownloadCommand = trackDownloadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
60
mCapabilities
|=
Qgis::BabelFormatCapability::Tracks
;
61
mCapabilities
|=
Qgis::BabelFormatCapability::Import
;
62
}
63
if
( !trackUploadCommand.isEmpty() )
64
{
65
mTrackUploadCommand = trackUploadCommand.split( whiteSpaceRx, Qt::SkipEmptyParts );
66
mCapabilities
|=
Qgis::BabelFormatCapability::Tracks
;
67
mCapabilities
|=
Qgis::BabelFormatCapability::Export
;
68
}
69
}
70
71
QStringList
QgsBabelGpsDeviceFormat::importCommand
(
const
QString &babel,
Qgis::GpsFeatureType
type,
const
QString &in,
const
QString &out,
Qgis::BabelCommandFlags
flags )
const
72
{
73
QStringList original;
74
75
switch
( type )
76
{
77
case
Qgis::GpsFeatureType::Waypoint
:
78
original = mWaypointDownloadCommand;
79
break
;
80
case
Qgis::GpsFeatureType::Route
:
81
original = mRouteDownloadCommand;
82
break
;
83
case
Qgis::GpsFeatureType::Track
:
84
original = mTrackDownloadCommand;
85
break
;
86
}
87
88
QStringList copy;
89
copy.reserve( original.size() );
90
for
(
const
QString &iter : std::as_const( original ) )
91
{
92
if
( iter ==
"%babel"
_L1 )
93
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( babel ) : babel );
94
else
if
( iter ==
"%type"
_L1 )
95
copy.append(
featureTypeToArgument
( type ) );
96
else
if
( iter ==
"%in"
_L1 )
97
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( in ) : in );
98
else
if
( iter ==
"%out"
_L1 )
99
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( out ) : out );
100
else
101
copy.append( iter );
102
}
103
return
copy;
104
}
105
106
QStringList
QgsBabelGpsDeviceFormat::exportCommand
(
const
QString &babel,
Qgis::GpsFeatureType
type,
const
QString &in,
const
QString &out,
Qgis::BabelCommandFlags
flags )
const
107
{
108
QStringList original;
109
switch
( type )
110
{
111
case
Qgis::GpsFeatureType::Waypoint
:
112
original = mWaypointUploadCommand;
113
break
;
114
case
Qgis::GpsFeatureType::Route
:
115
original = mRouteUploadCommand;
116
break
;
117
case
Qgis::GpsFeatureType::Track
:
118
original = mTrackUploadCommand;
119
break
;
120
}
121
122
QStringList copy;
123
copy.reserve( original.size() );
124
for
(
const
QString &iter : std::as_const( original ) )
125
{
126
if
( iter ==
"%babel"
_L1 )
127
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( babel ) : babel );
128
else
if
( iter ==
"%type"
_L1 )
129
copy.append(
featureTypeToArgument
( type ) );
130
else
if
( iter ==
"%in"
_L1 )
131
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( in ) : in );
132
else
if
( iter ==
"%out"
_L1 )
133
copy.append( ( flags &
Qgis::BabelCommandFlag::QuoteFilePaths
) ? u
"\"%1\""
_s.arg( out ) : out );
134
else
135
copy.append( iter );
136
}
137
return
copy;
138
}
Qgis::BabelCommandFlags
QFlags< BabelCommandFlag > BabelCommandFlags
Babel command flags.
Definition
qgis.h:2187
Qgis::BabelCommandFlag::QuoteFilePaths
@ QuoteFilePaths
File paths should be enclosed in quotations and escaped.
Definition
qgis.h:2184
Qgis::GpsFeatureType
GpsFeatureType
GPS feature types.
Definition
qgis.h:2197
Qgis::GpsFeatureType::Waypoint
@ Waypoint
Waypoint.
Definition
qgis.h:2198
Qgis::GpsFeatureType::Track
@ Track
Track.
Definition
qgis.h:2200
Qgis::GpsFeatureType::Route
@ Route
Route.
Definition
qgis.h:2199
Qgis::BabelFormatCapability::Export
@ Export
Format supports exporting.
Definition
qgis.h:2166
Qgis::BabelFormatCapability::Tracks
@ Tracks
Format supports tracks.
Definition
qgis.h:2169
Qgis::BabelFormatCapability::Import
@ Import
Format supports importing.
Definition
qgis.h:2165
Qgis::BabelFormatCapability::Waypoints
@ Waypoints
Format supports waypoints.
Definition
qgis.h:2167
Qgis::BabelFormatCapability::Routes
@ Routes
Format supports routes.
Definition
qgis.h:2168
QgsAbstractBabelFormat::mCapabilities
Qgis::BabelFormatCapabilities mCapabilities
Definition
qgsbabelformat.h:89
QgsAbstractBabelFormat::featureTypeToArgument
static QString featureTypeToArgument(Qgis::GpsFeatureType type)
Converts a GPS feature type to the equivalent babel argument.
Definition
qgsbabelformat.cpp:29
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:106
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:71
QgsBabelGpsDeviceFormat::QgsBabelGpsDeviceFormat
QgsBabelGpsDeviceFormat()=default
qgsbabelgpsdevice.h
Generated on
for QGIS API Documentation by
1.17.0