Skip to content
GitLab
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
536402f2
Commit
536402f2
authored
Apr 14, 2018
by
Volker Krause
Browse files
Proper implementation for show on map
Still misses an Intent-based Android variant though.
parent
e7a7639a
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/app/CMakeLists.txt
View file @
536402f2
...
...
@@ -18,6 +18,7 @@ target_link_libraries(itinerary PUBLIC
add_executable
(
itinerary-app
main.cpp
applicationcontroller.cpp
pkpassimageprovider.cpp
qml.qrc
)
...
...
src/app/PlaceDelegate.qml
View file @
536402f2
...
...
@@ -47,10 +47,9 @@ Item {
QQC2.ToolButton
{
icon.name
:
"
map-symbolic
"
visible
:
place
.
geo
.
isValid
visible
:
place
.
geo
.
isValid
||
!
place
.
address
.
isEmpty
onClicked
:
{
// TODO
Qt
.
openUrlExternally
(
"
https://www.openstreetmap.org/#map=17/
"
+
place
.
geo
.
latitude
+
"
/
"
+
place
.
geo
.
longitude
);
_appController
.
showOnMap
(
place
);
}
}
QQC2.ToolButton
{
...
...
src/app/applicationcontroller.cpp
0 → 100644
View file @
536402f2
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"applicationcontroller.h"
#include
<KItinerary/JsonLdDocument>
#include
<KItinerary/Place>
#include
<QDesktopServices>
#include
<QUrl>
#include
<QUrlQuery>
using
namespace
KItinerary
;
ApplicationController
::
ApplicationController
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
ApplicationController
::~
ApplicationController
()
=
default
;
void
ApplicationController
::
showOnMap
(
const
QVariant
&
place
)
{
if
(
place
.
isNull
())
{
return
;
}
// TODO Android implementation
const
auto
geo
=
JsonLdDocument
::
readProperty
(
place
,
"geo"
).
value
<
GeoCoordinates
>
();
if
(
geo
.
isValid
())
{
// zoom out further from airports, they are larger and you usually want to go further away from them
const
auto
zoom
=
place
.
userType
()
==
qMetaTypeId
<
Airport
>
()
?
12
:
17
;
QUrl
url
;
url
.
setScheme
(
QStringLiteral
(
"https"
));
url
.
setHost
(
QStringLiteral
(
"www.openstreetmap.org"
));
url
.
setPath
(
QStringLiteral
(
"/"
));
const
QString
fragment
=
QLatin1String
(
"map="
)
+
QString
::
number
(
zoom
)
+
QLatin1Char
(
'/'
)
+
QString
::
number
(
geo
.
latitude
())
+
QLatin1Char
(
'/'
)
+
QString
::
number
(
geo
.
longitude
());
url
.
setFragment
(
fragment
);
QDesktopServices
::
openUrl
(
url
);
return
;
}
const
auto
addr
=
JsonLdDocument
::
readProperty
(
place
,
"address"
).
value
<
PostalAddress
>
();
if
(
!
addr
.
isEmpty
())
{
QUrl
url
;
url
.
setScheme
(
QStringLiteral
(
"https"
));
url
.
setHost
(
QStringLiteral
(
"www.openstreetmap.org"
));
url
.
setPath
(
QStringLiteral
(
"/search"
));
const
QString
queryString
=
addr
.
streetAddress
()
+
QLatin1String
(
", "
)
+
addr
.
postalCode
()
+
QLatin1Char
(
' '
)
+
addr
.
addressLocality
()
+
QLatin1String
(
", "
)
+
addr
.
addressCountry
();
QUrlQuery
query
;
query
.
addQueryItem
(
QStringLiteral
(
"query"
),
queryString
);
url
.
setQuery
(
query
);
QDesktopServices
::
openUrl
(
url
);
}
}
src/app/applicationcontroller.h
0 → 100644
View file @
536402f2
/*
Copyright (C) 2018 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef APPLICATIONCONTROLLER_H
#define APPLICATIONCONTROLLER_H
#include
<QObject>
class
ApplicationController
:
public
QObject
{
Q_OBJECT
public:
explicit
ApplicationController
(
QObject
*
parent
=
nullptr
);
~
ApplicationController
();
Q_INVOKABLE
void
showOnMap
(
const
QVariant
&
place
);
};
#endif // APPLICATIONCONTROLLER_H
src/app/main.cpp
View file @
536402f2
...
...
@@ -18,6 +18,7 @@
#include
"itinerary_version.h"
#include
"logging.h"
#include
"applicationcontroller.h"
#include
"pkpassmanager.h"
#include
"timelinemodel.h"
#include
"pkpassimageprovider.h"
...
...
@@ -101,6 +102,8 @@ int main(int argc, char **argv)
timelineModel
.
setPkPassManager
(
&
passMgr
);
timelineModel
.
setReservationManager
(
&
resMgr
);
ApplicationController
appController
;
qmlRegisterUncreatableType
<
KPkPass
::
Barcode
>
(
"org.kde.pkpass"
,
1
,
0
,
"Barcode"
,
{});
qmlRegisterUncreatableType
<
KPkPass
::
Field
>
(
"org.kde.pkpass"
,
1
,
0
,
"Field"
,
{});
...
...
@@ -111,6 +114,7 @@ int main(int argc, char **argv)
engine
.
rootContext
()
->
setContextProperty
(
QStringLiteral
(
"_pkpassManager"
),
&
passMgr
);
engine
.
rootContext
()
->
setContextProperty
(
QStringLiteral
(
"_reservationManager"
),
&
resMgr
);
engine
.
rootContext
()
->
setContextProperty
(
QStringLiteral
(
"_timelineModel"
),
&
timelineModel
);
engine
.
rootContext
()
->
setContextProperty
(
QStringLiteral
(
"_appController"
),
&
appController
);
engine
.
load
(
QStringLiteral
(
":/main.qml"
));
for
(
const
auto
&
file
:
parser
.
positionalArguments
())
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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