File indexing completed on 2024-06-23 03:50:29

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #include "OpenRouteServicePlugin.h"
0007 #include "OpenRouteServiceRunner.h"
0008 
0009 #include "ui_OpenRouteServiceConfigWidget.h"
0010 
0011 namespace Marble
0012 {
0013 
0014 OpenRouteServicePlugin::OpenRouteServicePlugin( QObject *parent ) :
0015     RoutingRunnerPlugin( parent )
0016 {
0017     setSupportedCelestialBodies(QStringList(QStringLiteral("earth")));
0018     setCanWorkOffline( false );
0019     setStatusMessage( tr ( "This service requires an Internet connection." ) );
0020 }
0021 
0022 QString OpenRouteServicePlugin::name() const
0023 {
0024     return tr( "OpenRouteService Routing" );
0025 }
0026 
0027 QString OpenRouteServicePlugin::guiString() const
0028 {
0029     return tr( "OpenRouteService" );
0030 }
0031 
0032 QString OpenRouteServicePlugin::nameId() const
0033 {
0034     return QStringLiteral("openrouteservice");
0035 }
0036 
0037 QString OpenRouteServicePlugin::version() const
0038 {
0039     return QStringLiteral("1.0");
0040 }
0041 
0042 QString OpenRouteServicePlugin::description() const
0043 {
0044     return tr( "Routing in Europe using openrouteservice.org" );
0045 }
0046 
0047 QString OpenRouteServicePlugin::copyrightYears() const
0048 {
0049     return QStringLiteral("2010");
0050 }
0051 
0052 QVector<PluginAuthor> OpenRouteServicePlugin::pluginAuthors() const
0053 {
0054     return QVector<PluginAuthor>()
0055             << PluginAuthor(QStringLiteral("Dennis Nienhüser"), QStringLiteral("nienhueser@kde.org"));
0056 }
0057 
0058 RoutingRunner *OpenRouteServicePlugin::newRunner() const
0059 {
0060     return new OpenRouteServiceRunner;
0061 }
0062 
0063 class OpenRouteServiceConfigWidget : public RoutingRunnerPlugin::ConfigWidget
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068 
0069     OpenRouteServiceConfigWidget()
0070         : RoutingRunnerPlugin::ConfigWidget()
0071     {
0072         ui_configWidget = new Ui::OpenRouteServiceConfigWidget;
0073         ui_configWidget->setupUi( this );
0074 
0075         ui_configWidget->preference->addItem( tr( "Car (recommended way)" ), "Recommended" );
0076         ui_configWidget->preference->addItem( tr( "Car (fastest way)" ), "Fastest" );
0077         ui_configWidget->preference->addItem( tr( "Car (shortest way)" ), "Shortest" );
0078         ui_configWidget->preference->addItem( tr( "Pedestrian (shortest way)" ), "Pedestrian" );
0079         ui_configWidget->preference->addItem( tr( "Bicycle (shortest track)" ), "Bicycle" );
0080         ui_configWidget->preference->addItem( tr( "Bicycle (Mountainbike)" ), "BicycleMTB" );
0081         ui_configWidget->preference->addItem( tr( "Bicycle (Racer)" ), "BicycleRacer" );
0082         ui_configWidget->preference->addItem( tr( "Bicycle (safest track)" ), "BicycleSafety" );
0083         ui_configWidget->preference->addItem( tr( "Bicycle (preferred Cycleway/-route)" ), "BicycleTour" );
0084     }
0085 
0086     void loadSettings( const QHash<QString, QVariant> &settings_ ) override
0087     {
0088         QHash<QString, QVariant> settings = settings_;
0089 
0090         // Check if all fields are filled and fill them with default values.
0091         if (!settings.contains(QStringLiteral("preference"))) {
0092             settings.insert(QStringLiteral("preference"), QStringLiteral("Fastest"));
0093         }
0094         ui_configWidget->preference->setCurrentIndex(
0095             ui_configWidget->preference->findData(settings.value(QStringLiteral("preference")).toString()));
0096         ui_configWidget->noMotorways->setCheckState(static_cast<Qt::CheckState>(settings.value(QStringLiteral("noMotorways")).toInt()));
0097         ui_configWidget->noTollways->setCheckState(static_cast<Qt::CheckState>(settings.value(QStringLiteral("noTollways")).toInt()));
0098         ui_configWidget->noFerries->setCheckState(static_cast<Qt::CheckState>(settings.value(QStringLiteral("noFerries")).toInt()));
0099     }
0100 
0101     QHash<QString, QVariant> settings() const override
0102     {
0103         QHash<QString,QVariant> settings;
0104         settings.insert(QStringLiteral("preference"),
0105                         ui_configWidget->preference->itemData( ui_configWidget->preference->currentIndex() ) );
0106         settings.insert(QStringLiteral("noMotorways"), ui_configWidget->noMotorways->checkState());
0107         settings.insert(QStringLiteral("noTollways"), ui_configWidget->noTollways->checkState());
0108         settings.insert(QStringLiteral("noFerries"), ui_configWidget->noFerries->checkState());
0109         return settings;
0110     }
0111 private:
0112     Ui::OpenRouteServiceConfigWidget *ui_configWidget;
0113 };
0114 
0115 RoutingRunnerPlugin::ConfigWidget *OpenRouteServicePlugin::configWidget()
0116 {
0117     return new OpenRouteServiceConfigWidget();
0118 }
0119 
0120 
0121 bool OpenRouteServicePlugin::supportsTemplate( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
0122 {
0123     return
0124         (profileTemplate == RoutingProfilesModel::CarFastestTemplate)  ||
0125         (profileTemplate == RoutingProfilesModel::CarShortestTemplate) ||
0126         (profileTemplate == RoutingProfilesModel::BicycleTemplate)     ||
0127         (profileTemplate == RoutingProfilesModel::PedestrianTemplate);
0128 }
0129 
0130 QHash< QString, QVariant > OpenRouteServicePlugin::templateSettings( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
0131 {
0132     QHash<QString, QVariant> result;
0133     switch ( profileTemplate ) {
0134         case RoutingProfilesModel::CarFastestTemplate:
0135             result.insert(QStringLiteral("preference"), QStringLiteral("Fastest"));
0136             break;
0137         case RoutingProfilesModel::CarShortestTemplate:
0138             result.insert(QStringLiteral("preference"), QStringLiteral("Shortest"));
0139             break;
0140         case RoutingProfilesModel::CarEcologicalTemplate:
0141             break;
0142         case RoutingProfilesModel::BicycleTemplate:
0143             result.insert(QStringLiteral("preference"), QStringLiteral("Bicycle"));
0144             break;
0145         case RoutingProfilesModel::PedestrianTemplate:
0146             result.insert(QStringLiteral("preference"), QStringLiteral("Pedestrian"));
0147             break;
0148         case RoutingProfilesModel::LastTemplate:
0149             Q_ASSERT( false );
0150             break;
0151     }
0152     return result;
0153 }
0154 
0155 }
0156 
0157 #include "OpenRouteServicePlugin.moc" // needed for Q_OBJECT here in source
0158 
0159 #include "moc_OpenRouteServicePlugin.cpp"