summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Wójcik <chocimier@tlen.pl>2016-10-21 20:45:25 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-10-21 21:12:58 (GMT)
commitf5319d7e4329a5654486364fe6895b69f10c4199 (patch)
tree5ac646ac0e4cef43dc8229e403d69d24ce1a5d61
parent75330ca1072aa7e0f15077a3c85b4d1627739d00 (diff)
Allow showing bicycle and foot routes with Yours service
Differential Revision: https://phabricator.kde.org/D3116 (cherry picked from commit ee1c8e39aa9ba34d1ac4bef4739ac4e08f091662)
-rw-r--r--src/plugins/runner/yours/CMakeLists.txt4
-rw-r--r--src/plugins/runner/yours/YoursConfigWidget.ui51
-rw-r--r--src/plugins/runner/yours/YoursPlugin.cpp102
-rw-r--r--src/plugins/runner/yours/YoursPlugin.h5
-rw-r--r--src/plugins/runner/yours/YoursRunner.cpp16
-rw-r--r--src/plugins/runner/yours/YoursRunner.h1
6 files changed, 174 insertions, 5 deletions
diff --git a/src/plugins/runner/yours/CMakeLists.txt b/src/plugins/runner/yours/CMakeLists.txt
index 437269d..95b86a8 100644
--- a/src/plugins/runner/yours/CMakeLists.txt
+++ b/src/plugins/runner/yours/CMakeLists.txt
@@ -7,4 +7,8 @@ INCLUDE_DIRECTORIES(
set( yours_SRCS YoursRunner.cpp YoursPlugin.cpp )
+set( yours_UI YoursConfigWidget.ui )
+
+qt_wrap_ui( yours_SRCS ${yours_UI} )
+
marble_add_plugin( YoursPlugin ${yours_SRCS} )
diff --git a/src/plugins/runner/yours/YoursConfigWidget.ui b/src/plugins/runner/yours/YoursConfigWidget.ui
new file mode 100644
index 0000000..3ef4ad9
--- /dev/null
+++ b/src/plugins/runner/yours/YoursConfigWidget.ui
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>YoursConfigWidget</class>
+ <widget class="QWidget" name="YoursConfigWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>273</width>
+ <height>196</height>
+ </rect>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Transport:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="transport"/>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Method</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="fastest">
+ <property name="text">
+ <string>Fastest</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="shortest">
+ <property name="text">
+ <string>Shortest</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/runner/yours/YoursPlugin.cpp b/src/plugins/runner/yours/YoursPlugin.cpp
index bddd070..d6ade0b 100644
--- a/src/plugins/runner/yours/YoursPlugin.cpp
+++ b/src/plugins/runner/yours/YoursPlugin.cpp
@@ -6,11 +6,14 @@
// the source code.
//
// Copyright 2010 Dennis Nienhüser <nienhueser@kde.org>
+// Copyright 2016 Piotr Wójcik <chocimier@tlen.pl>
//
#include "YoursPlugin.h"
#include "YoursRunner.h"
+#include "ui_YoursConfigWidget.h"
+
namespace Marble
{
@@ -39,7 +42,7 @@ QString YoursPlugin::nameId() const
QString YoursPlugin::version() const
{
- return QStringLiteral("1.0");
+ return QStringLiteral("1.1");
}
QString YoursPlugin::description() const
@@ -49,13 +52,14 @@ QString YoursPlugin::description() const
QString YoursPlugin::copyrightYears() const
{
- return QStringLiteral("2010");
+ return QStringLiteral("2010, 2016");
}
QVector<PluginAuthor> YoursPlugin::pluginAuthors() const
{
return QVector<PluginAuthor>()
- << PluginAuthor(QStringLiteral("Dennis Nienhüser"), QStringLiteral("nienhueser@kde.org"));
+ << PluginAuthor(QStringLiteral("Dennis Nienhüser"), QStringLiteral("nienhueser@kde.org"))
+ << PluginAuthor(QStringLiteral("Piotr Wójcik"), QStringLiteral("chocimier@tlen.pl"));
}
RoutingRunner *YoursPlugin::newRunner() const
@@ -63,9 +67,99 @@ RoutingRunner *YoursPlugin::newRunner() const
return new YoursRunner;
}
+class YoursConfigWidget : public RoutingRunnerPlugin::ConfigWidget
+{
+public:
+ YoursConfigWidget()
+ : RoutingRunnerPlugin::ConfigWidget()
+ {
+ ui_configWidget = new Ui::YoursConfigWidget;
+ ui_configWidget->setupUi( this );
+ //TODO: read from profiles.xml
+ ui_configWidget->transport->addItem( tr( "Foot" ), "foot" );
+ ui_configWidget->transport->addItem( tr( "Bicycle" ), "bicycle" );
+ ui_configWidget->transport->addItem( tr( "Motorcar" ), "motorcar" );
+ }
+ virtual ~YoursConfigWidget()
+ {
+ delete ui_configWidget;
+ }
+ virtual void loadSettings( const QHash<QString, QVariant> &settings_ )
+ {
+ QHash<QString, QVariant> settings = settings_;
+
+ // Check if all fields are filled and fill them with default values.
+ if (!settings.contains(QStringLiteral("transport"))) {
+ settings.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
+ }
+ ui_configWidget->transport->setCurrentIndex(
+ ui_configWidget->transport->findData(settings.value(QStringLiteral("transport")).toString()));
+ if (settings.value(QStringLiteral("method")).toString() == QLatin1String("shortest")) {
+ ui_configWidget->shortest->setChecked( true );
+ } else {
+ ui_configWidget->fastest->setChecked( true );
+ }
+ }
+
+ virtual QHash<QString, QVariant> settings() const
+ {
+ QHash<QString,QVariant> settings;
+ settings.insert(QStringLiteral("transport"),
+ ui_configWidget->transport->itemData( ui_configWidget->transport->currentIndex() ) );
+
+ if ( ui_configWidget->shortest->isChecked() ) {
+ settings.insert(QStringLiteral("method"), QStringLiteral("shortest"));
+ } else {
+ settings.insert(QStringLiteral("method"), QStringLiteral("fastest"));
+ }
+ return settings;
+ }
+private:
+ Ui::YoursConfigWidget *ui_configWidget;
+};
+
+RoutingRunnerPlugin::ConfigWidget *YoursPlugin::configWidget()
+{
+ return new YoursConfigWidget();
+}
+
bool YoursPlugin::supportsTemplate( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
{
- return profileTemplate == RoutingProfilesModel::CarFastestTemplate;
+ QSet<RoutingProfilesModel::ProfileTemplate> availableTemplates;
+ availableTemplates.insert( RoutingProfilesModel::CarFastestTemplate );
+ availableTemplates.insert( RoutingProfilesModel::CarShortestTemplate );
+ availableTemplates.insert( RoutingProfilesModel::BicycleTemplate );
+ availableTemplates.insert( RoutingProfilesModel::PedestrianTemplate );
+ return availableTemplates.contains( profileTemplate );
+}
+
+QHash< QString, QVariant > YoursPlugin::templateSettings(RoutingProfilesModel::ProfileTemplate profileTemplate) const
+{
+ QHash<QString, QVariant> result;
+ switch ( profileTemplate ) {
+ case RoutingProfilesModel::CarFastestTemplate:
+ result.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
+ result.insert(QStringLiteral("method"), QStringLiteral("fastest"));
+ break;
+ case RoutingProfilesModel::CarShortestTemplate:
+ result.insert(QStringLiteral("transport"), QStringLiteral("motorcar"));
+ result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
+ break;
+ case RoutingProfilesModel::CarEcologicalTemplate:
+ break;
+ case RoutingProfilesModel::BicycleTemplate:
+ result.insert(QStringLiteral("transport"), QStringLiteral("bicycle"));
+ result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
+ break;
+ case RoutingProfilesModel::PedestrianTemplate:
+ result.insert(QStringLiteral("transport"), QStringLiteral("foot"));
+ result.insert(QStringLiteral("method"), QStringLiteral("shortest"));
+ break;
+ case RoutingProfilesModel::LastTemplate:
+ Q_ASSERT( false );
+ break;
+ }
+ return result;
}
}
diff --git a/src/plugins/runner/yours/YoursPlugin.h b/src/plugins/runner/yours/YoursPlugin.h
index 348cf8e..31f0669 100644
--- a/src/plugins/runner/yours/YoursPlugin.h
+++ b/src/plugins/runner/yours/YoursPlugin.h
@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2010 Dennis Nienhüser <nienhueser@kde.org>
+// Copyright 2016 Piotr Wójcik <chocimier@tlen.pl>
//
@@ -42,7 +43,11 @@ public:
virtual RoutingRunner *newRunner() const;
+ ConfigWidget* configWidget();
+
virtual bool supportsTemplate(RoutingProfilesModel::ProfileTemplate profileTemplate) const;
+
+ QHash< QString, QVariant > templateSettings(RoutingProfilesModel::ProfileTemplate profileTemplate) const;
};
}
diff --git a/src/plugins/runner/yours/YoursRunner.cpp b/src/plugins/runner/yours/YoursRunner.cpp
index 0b5d5ce..0cce29b 100644
--- a/src/plugins/runner/yours/YoursRunner.cpp
+++ b/src/plugins/runner/yours/YoursRunner.cpp
@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2010 Dennis Nienhüser <nienhueser@kde.org>
+// Copyright 2016 Piotr Wójcik <chocimier@tlen.pl>
//
#include "YoursRunner.h"
@@ -61,11 +62,24 @@ void YoursRunner::retrieveRoute( const RouteRequest *route )
//QString base = "http://nroets.dev.openstreetmap.org/demo/gosmore.php";
QString args = "?flat=%1&flon=%2&tlat=%3&tlon=%4";
args = args.arg( fLat, 0, 'f', 6 ).arg( fLon, 0, 'f', 6 ).arg( tLat, 0, 'f', 6 ).arg( tLon, 0, 'f', 6 );
- QString preferences = "&v=motorcar&fast=1&layer=mapnik";
+
+ QHash<QString, QVariant> settings = route->routingProfile().pluginSettings()[QStringLiteral("yours")];
+ QString transport = settings[QStringLiteral("transport")].toString();
+ QString fast;
+
+ if (settings[QStringLiteral("method")] == QLatin1String("shortest")) {
+ fast = "0";
+ } else {
+ fast = "1";
+ }
+
+ QString preferences = "&v=%1&fast=%2&layer=mapnik;";
+ preferences = preferences.arg(transport).arg(fast);
QString request = base + args + preferences;
// mDebug() << "GET: " << request;
m_request = QNetworkRequest( QUrl( request ) );
+ m_request.setRawHeader( "X-Yours-client", "Marble" );
QEventLoop eventLoop;
diff --git a/src/plugins/runner/yours/YoursRunner.h b/src/plugins/runner/yours/YoursRunner.h
index 847fa77..35fda2f 100644
--- a/src/plugins/runner/yours/YoursRunner.h
+++ b/src/plugins/runner/yours/YoursRunner.h
@@ -6,6 +6,7 @@
// the source code.
//
// Copyright 2010 Dennis Nienhüser <nienhueser@kde.org>
+// Copyright 2016 Piotr Wójcik <chocimier@tlen.pl>
//