File indexing completed on 2024-07-21 06:33:36

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #include "MapQuestPlugin.h"
0007 #include "MapQuestRunner.h"
0008 
0009 #include "ui_MapQuestConfigWidget.h"
0010 
0011 namespace Marble
0012 {
0013 
0014 MapQuestPlugin::MapQuestPlugin( 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 MapQuestPlugin::name() const
0023 {
0024     return tr( "MapQuest Routing" );
0025 }
0026 
0027 QString MapQuestPlugin::guiString() const
0028 {
0029     return tr( "MapQuest" );
0030 }
0031 
0032 QString MapQuestPlugin::nameId() const
0033 {
0034     return QStringLiteral("mapquest");
0035 }
0036 
0037 QString MapQuestPlugin::version() const
0038 {
0039     return QStringLiteral("1.0");
0040 }
0041 
0042 QString MapQuestPlugin::description() const
0043 {
0044     return tr( "Worldwide routing using mapquest.org" );
0045 }
0046 
0047 QString MapQuestPlugin::copyrightYears() const
0048 {
0049     return QStringLiteral("2012");
0050 }
0051 
0052 QVector<PluginAuthor> MapQuestPlugin::pluginAuthors() const
0053 {
0054     return QVector<PluginAuthor>()
0055             << PluginAuthor(QStringLiteral("Dennis Nienhüser"), QStringLiteral("nienhueser@kde.org"));
0056 }
0057 
0058 RoutingRunner *MapQuestPlugin::newRunner() const
0059 {
0060     return new MapQuestRunner;
0061 }
0062 
0063 class MapQuestConfigWidget : public RoutingRunnerPlugin::ConfigWidget
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068 
0069     MapQuestConfigWidget()
0070         : RoutingRunnerPlugin::ConfigWidget()
0071     {
0072         ui_configWidget = new Ui::MapQuestConfigWidget;
0073         ui_configWidget->setupUi( this );
0074 
0075         ui_configWidget->preference->addItem( tr( "Car (fastest way)" ), "fastest" );
0076         ui_configWidget->preference->addItem( tr( "Car (shortest way)" ), "shortest" );
0077         ui_configWidget->preference->addItem( tr( "Pedestrian" ), "pedestrian" );
0078         ui_configWidget->preference->addItem( tr( "Bicycle" ), "bicycle" );
0079         ui_configWidget->preference->addItem( tr( "Transit (Public Transport)" ), "multimodal" );
0080 
0081         ui_configWidget->ascending->addItem( tr( "Ignore" ), "DEFAULT_STRATEGY" );
0082         ui_configWidget->ascending->addItem( tr( "Avoid" ), "AVOID_UP_HILL" );
0083         ui_configWidget->ascending->addItem( tr( "Favor" ), "FAVOR_UP_HILL" );
0084 
0085         ui_configWidget->descending->addItem( tr( "Ignore" ), "DEFAULT_STRATEGY" );
0086         ui_configWidget->descending->addItem( tr( "Avoid" ), "AVOID_DOWN_HILL" );
0087         ui_configWidget->descending->addItem( tr( "Favor" ), "FAVOR_DOWN_HILL" );
0088     }
0089 
0090     void loadSettings( const QHash<QString, QVariant> &settings_ ) override
0091     {
0092         QHash<QString, QVariant> settings = settings_;
0093 
0094         // Check if all fields are filled and fill them with default values.
0095         if (!settings.contains(QStringLiteral("preference"))) {
0096             settings.insert(QStringLiteral("preference"), QStringLiteral("fastest"));
0097         }
0098         if (!settings.contains(QStringLiteral("ascending"))) {
0099             settings.insert(QStringLiteral("ascending"), QStringLiteral("DEFAULT_STRATEGY"));
0100         }
0101         if (!settings.contains(QStringLiteral("descending"))) {
0102             settings.insert(QStringLiteral("descending"), QStringLiteral("DEFAULT_STRATEGY"));
0103         }
0104         if (!settings.contains(QStringLiteral("appKey"))) {
0105             settings.insert(QStringLiteral("appKey"), QString());
0106         }
0107         ui_configWidget->appKey->setText(settings.value(QStringLiteral("appKey")).toString() );
0108         ui_configWidget->preference->setCurrentIndex(
0109                     ui_configWidget->preference->findData(settings.value(QStringLiteral("preference")).toString()));
0110         ui_configWidget->noMotorways->setCheckState( static_cast<Qt::CheckState>(settings.value(QStringLiteral("noMotorways")).toInt()));
0111         ui_configWidget->noTollways->setCheckState( static_cast<Qt::CheckState>(settings.value(QStringLiteral("noTollways")).toInt()));
0112         ui_configWidget->noFerries->setCheckState( static_cast<Qt::CheckState>(settings.value(QStringLiteral("noFerries")).toInt()));
0113         ui_configWidget->ascending->setCurrentIndex(
0114                     ui_configWidget->ascending->findData(settings.value(QStringLiteral("ascending")).toString()));
0115         ui_configWidget->descending->setCurrentIndex(
0116                     ui_configWidget->descending->findData(settings.value(QStringLiteral("descending")).toString()));
0117     }
0118 
0119     QHash<QString, QVariant> settings() const override
0120     {
0121         QHash<QString,QVariant> settings;
0122         settings.insert(QStringLiteral("appKey"), ui_configWidget->appKey->text());
0123         settings.insert(QStringLiteral("preference"),
0124                          ui_configWidget->preference->itemData( ui_configWidget->preference->currentIndex() ) );
0125         settings.insert(QStringLiteral("noMotorways"), ui_configWidget->noMotorways->checkState());
0126         settings.insert(QStringLiteral("noTollways"), ui_configWidget->noTollways->checkState());
0127         settings.insert(QStringLiteral("noFerries"), ui_configWidget->noFerries->checkState());
0128         settings.insert(QStringLiteral("ascending"),
0129                          ui_configWidget->ascending->itemData( ui_configWidget->ascending->currentIndex() ) );
0130         settings.insert(QStringLiteral("descending"),
0131                          ui_configWidget->descending->itemData( ui_configWidget->descending->currentIndex() ) );
0132         return settings;
0133     }
0134 private:
0135     Ui::MapQuestConfigWidget *ui_configWidget;
0136 };
0137 
0138 RoutingRunnerPlugin::ConfigWidget *MapQuestPlugin::configWidget()
0139 {
0140     return new MapQuestConfigWidget();
0141 }
0142 
0143 
0144 bool MapQuestPlugin::supportsTemplate( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
0145 {
0146     return
0147         (profileTemplate == RoutingProfilesModel::CarFastestTemplate)  ||
0148         (profileTemplate == RoutingProfilesModel::CarShortestTemplate) ||
0149         (profileTemplate == RoutingProfilesModel::BicycleTemplate)     ||
0150         (profileTemplate == RoutingProfilesModel::PedestrianTemplate);
0151 }
0152 
0153 QHash< QString, QVariant > MapQuestPlugin::templateSettings( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
0154 {
0155     QHash<QString, QVariant> result;
0156     switch ( profileTemplate ) {
0157     case RoutingProfilesModel::CarFastestTemplate:
0158         result.insert(QStringLiteral("preference"), QStringLiteral("fastest"));
0159         break;
0160     case RoutingProfilesModel::CarShortestTemplate:
0161         result.insert(QStringLiteral("preference"), QStringLiteral("shortest"));
0162         break;
0163     case RoutingProfilesModel::CarEcologicalTemplate:
0164         break;
0165     case RoutingProfilesModel::BicycleTemplate:
0166         result.insert(QStringLiteral("preference"), QStringLiteral("bicycle"));
0167         break;
0168     case RoutingProfilesModel::PedestrianTemplate:
0169         result.insert(QStringLiteral("preference"), QStringLiteral("pedestrian"));
0170         break;
0171     case RoutingProfilesModel::LastTemplate:
0172         Q_ASSERT( false );
0173         break;
0174     }
0175     return result;
0176 }
0177 
0178 }
0179 
0180 #include "MapQuestPlugin.moc" // needed for Q_OBJECT here in source
0181 
0182 #include "moc_MapQuestPlugin.cpp"