Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Itinerary
Commits
b7db61f7
Commit
b7db61f7
authored
Jun 13, 2021
by
Volker Krause
Browse files
Allow to export favorite locations to a GPX file
This is compatible with Nextcloud Maps and can be imported there.
parent
8b35b406
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/app/FavoriteLocationPage.qml
View file @
b7db61f7
...
...
@@ -7,6 +7,7 @@
import
QtQuick
2.5
import
QtQuick
.
Layouts
1.1
import
QtQuick
.
Controls
2.1
as
QQC2
import
Qt
.
labs
.
platform
1.1
as
Platform
import
QtLocation
5.11
as
QtLocation
import
QtPositioning
5.11
import
org
.
kde
.
kirigami
2.12
as
Kirigami
...
...
@@ -34,6 +35,15 @@ Kirigami.Page {
}
Platform.FileDialog
{
id
:
favoriteGpxExportDialog
fileMode
:
Platform
.
FileDialog
.
SaveFile
title
:
i18n
(
"
Export Favorite Locations
"
)
folder
:
Platform
.
StandardPaths
.
writableLocation
(
StandardPaths
.
DocumentsLocation
)
nameFilters
:
[
i18n
(
"
GPX Files (*.gpx)
"
)]
onAccepted
:
FavoriteLocationModel
.
exportToGpx
(
file
)
}
actions.main
:
Kirigami.Action
{
icon.name
:
"
crosshairs
"
text
:
i18n
(
"
Pick Location
"
)
...
...
@@ -66,6 +76,11 @@ Kirigami.Page {
FavoriteLocationModel
.
removeLocation
(
combo
.
currentIndex
);
combo
.
currentIndex
=
Math
.
min
(
prevIndex
,
combo
.
count
-
1
);
}
},
Kirigami.Action
{
text
:
i18n
(
"
Export to GPX
"
)
icon.name
:
"
export-symbolic
"
onTriggered
:
favoriteGpxExportDialog
.
open
()
}
]
...
...
src/app/favoritelocationmodel.cpp
View file @
b7db61f7
...
...
@@ -5,7 +5,9 @@
*/
#include "favoritelocationmodel.h"
#include "gpxexport.h"
#include "json.h"
#include "logging.h"
#include <KLocalizedString>
...
...
@@ -253,3 +255,20 @@ void FavoriteLocationModel::saveLocations() const
f
.
write
(
QJsonDocument
(
FavoriteLocation
::
toJson
(
m_locations
)).
toJson
());
}
void
FavoriteLocationModel
::
exportToGpx
(
const
QString
&
filePath
)
const
{
if
(
filePath
.
isEmpty
())
{
return
;
}
QFile
f
(
QUrl
(
filePath
).
isLocalFile
()
?
QUrl
(
filePath
).
toLocalFile
()
:
filePath
);
if
(
!
f
.
open
(
QFile
::
WriteOnly
))
{
qCWarning
(
Log
)
<<
f
.
errorString
()
<<
f
.
fileName
();
return
;
}
GpxExport
exporter
(
&
f
);
for
(
const
auto
&
fav
:
m_locations
)
{
exporter
.
writeFavoriteLocation
(
fav
);
}
}
src/app/favoritelocationmodel.h
View file @
b7db61f7
...
...
@@ -77,6 +77,9 @@ public:
*/
void
setFavoriteLocations
(
std
::
vector
<
FavoriteLocation
>
&&
locs
);
/** Export to GPX. */
Q_INVOKABLE
void
exportToGpx
(
const
QString
&
filePath
)
const
;
int
rowCount
(
const
QModelIndex
&
parent
=
{})
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
bool
setData
(
const
QModelIndex
&
index
,
const
QVariant
&
value
,
int
role
)
override
;
...
...
src/app/gpxexport.cpp
View file @
b7db61f7
...
...
@@ -5,6 +5,7 @@
*/
#include "gpxexport.h"
#include "favoritelocationmodel.h"
#include "transfer.h"
#include <KItinerary/Event>
...
...
@@ -106,3 +107,10 @@ void GpxExport::writeJourneySection(const KPublicTransport::JourneySection §
}
}
}
void
GpxExport
::
writeFavoriteLocation
(
const
FavoriteLocation
&
fav
)
{
m_writer
.
writeStartWaypoint
(
fav
.
latitude
(),
fav
.
longitude
());
m_writer
.
writeName
(
fav
.
name
());
m_writer
.
writeEndWaypoint
();
}
src/app/gpxexport.h
View file @
b7db61f7
...
...
@@ -11,6 +11,7 @@
#include <gpx/gpxwriter.h>
class
FavoriteLocation
;
class
Transfer
;
/** Trip group to GPX export. */
...
...
@@ -22,6 +23,7 @@ public:
void
writeReservation
(
const
QVariant
&
res
,
const
KPublicTransport
::
JourneySection
&
journey
=
{});
void
writeTransfer
(
const
Transfer
&
transfer
);
void
writeFavoriteLocation
(
const
FavoriteLocation
&
fav
);
inline
void
writeStartRoute
()
{
m_writer
.
writeStartRoute
();
}
inline
void
writeEndRoute
()
{
m_writer
.
writeEndRoute
();
}
...
...
src/gpx/gpxwriter.cpp
View file @
b7db61f7
...
...
@@ -45,6 +45,18 @@ void Gpx::Writer::writeEndRoute()
m_writer
.
writeEndElement
();
}
void
Gpx
::
Writer
::
writeStartWaypoint
(
float
latitude
,
float
longitude
)
{
m_writer
.
writeStartElement
(
QStringLiteral
(
"wpt"
));
m_writer
.
writeAttribute
(
QStringLiteral
(
"lat"
),
QString
::
number
(
latitude
));
m_writer
.
writeAttribute
(
QStringLiteral
(
"lon"
),
QString
::
number
(
longitude
));
}
void
Gpx
::
Writer
::
writeEndWaypoint
()
{
m_writer
.
writeEndElement
();
}
void
Gpx
::
Writer
::
writeStartRoutePoint
(
float
latitude
,
float
longitude
)
{
m_writer
.
writeStartElement
(
QStringLiteral
(
"rtept"
));
...
...
src/gpx/gpxwriter.h
View file @
b7db61f7
...
...
@@ -29,6 +29,9 @@ public:
void
writeStartRoute
();
void
writeEndRoute
();
void
writeStartWaypoint
(
float
latitude
,
float
longitude
);
void
writeEndWaypoint
();
void
writeStartRoutePoint
(
float
latitude
,
float
longitude
);
void
writeEndRoutePoint
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment