File indexing completed on 2024-07-21 09:27:04

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2013 Mihail Ivchenko <ematirov@gmail.com>
0004 //
0005 
0006 #include "CycleStreetsPlugin.h"
0007 #include "CycleStreetsRunner.h"
0008 #include "MarbleGlobal.h"
0009 #include "MarbleLocale.h"
0010 
0011 #include "ui_CycleStreetsConfigWidget.h"
0012 
0013 namespace Marble
0014 {
0015 
0016 class CycleStreetsConfigWidget : public RoutingRunnerPlugin::ConfigWidget
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     CycleStreetsConfigWidget();
0022     void loadSettings( const QHash<QString, QVariant> &settings ) override;
0023     QHash<QString, QVariant> settings() const override;
0024 
0025 private:
0026     Ui::CycleStreetsConfigWidget *ui_configWidget;
0027 };
0028 
0029 CycleStreetsConfigWidget::CycleStreetsConfigWidget()
0030     : RoutingRunnerPlugin::ConfigWidget(),
0031       ui_configWidget( new Ui::CycleStreetsConfigWidget )
0032 {
0033     ui_configWidget->setupUi( this );
0034 
0035     ui_configWidget->plan->addItem( tr( "balanced" ), "balanced" );
0036     ui_configWidget->plan->addItem( tr( "fastest" ), "fastest" );
0037     ui_configWidget->plan->addItem( tr( "quietest" ), "quietest" );
0038 
0039     if ( MarbleGlobal::getInstance()->locale()->measurementSystem() == MarbleLocale::MetricSystem ) {
0040         ui_configWidget->speed->addItem( tr( "slow (16 km/h)" ), "16" );
0041         ui_configWidget->speed->addItem( tr( "normal (20 km/h)" ), "20" );
0042         ui_configWidget->speed->addItem( tr( "fast (24 km/h)") , "24" );
0043     } else {
0044         ui_configWidget->speed->addItem( tr( "slow (10 mph)" ), "16" );
0045         ui_configWidget->speed->addItem( tr( "normal (12 mph)" ), "20" );
0046         ui_configWidget->speed->addItem( tr( "fast (15 mph)") , "24" );
0047     }
0048 }
0049 
0050 void CycleStreetsConfigWidget::loadSettings( const QHash<QString, QVariant> &settings_ )
0051 {
0052     QHash<QString, QVariant> settings = settings_;
0053 
0054     // Check if all fields are filled and fill them with default values.
0055     if (!settings.contains(QStringLiteral("plan"))) {
0056         settings.insert(QStringLiteral("plan"), QStringLiteral("balanced"));
0057     }
0058     if (!settings.contains(QStringLiteral("speed"))) {
0059         settings.insert(QStringLiteral("speed"), QStringLiteral("20"));
0060     }
0061     ui_configWidget->plan->setCurrentIndex(
0062                 ui_configWidget->plan->findData(settings.value(QStringLiteral("plan"))));
0063     ui_configWidget->speed->setCurrentIndex(
0064                 ui_configWidget->speed->findData(settings.value(QStringLiteral("speed"))));
0065 }
0066 
0067 QHash<QString, QVariant> CycleStreetsConfigWidget::settings() const
0068 {
0069     QHash<QString,QVariant> settings;
0070     settings.insert(QStringLiteral("plan"),
0071                      ui_configWidget->plan->itemData( ui_configWidget->plan->currentIndex() ) );
0072     settings.insert(QStringLiteral("speed"),
0073                      ui_configWidget->speed->itemData( ui_configWidget->speed->currentIndex() ) );
0074     return settings;
0075 }
0076 
0077 CycleStreetsPlugin::CycleStreetsPlugin( QObject *parent ) :
0078     RoutingRunnerPlugin( parent )
0079 {
0080     setSupportedCelestialBodies(QStringList(QStringLiteral("earth")));
0081     setCanWorkOffline( false );
0082     setStatusMessage( tr ( "This service requires an Internet connection." ) );
0083 }
0084 
0085 QString CycleStreetsPlugin::name() const
0086 {
0087     return tr( "CycleStreets Routing" );
0088 }
0089 
0090 QString CycleStreetsPlugin::guiString() const
0091 {
0092     return tr( "CycleStreets" );
0093 }
0094 
0095 QString CycleStreetsPlugin::nameId() const
0096 {
0097     return QStringLiteral("cyclestreets");
0098 }
0099 
0100 QString CycleStreetsPlugin::version() const
0101 {
0102     return QStringLiteral("1.0");
0103 }
0104 
0105 QString CycleStreetsPlugin::description() const
0106 {
0107     return tr( "Bicycle routing for the United Kingdom using cyclestreets.net" );
0108 }
0109 
0110 QString CycleStreetsPlugin::copyrightYears() const
0111 {
0112     return QStringLiteral("2013");
0113 }
0114 
0115 QVector<PluginAuthor> CycleStreetsPlugin::pluginAuthors() const
0116 {
0117     return QVector<PluginAuthor>()
0118             << PluginAuthor(QStringLiteral("Mihail Ivchenko"), QStringLiteral("ematirov@gmail.com"));
0119 }
0120 
0121 RoutingRunner *CycleStreetsPlugin::newRunner() const
0122 {
0123     return new CycleStreetsRunner;
0124 }
0125 
0126 RoutingRunnerPlugin::ConfigWidget *CycleStreetsPlugin::configWidget()
0127 {
0128     return new CycleStreetsConfigWidget();
0129 }
0130 
0131 bool CycleStreetsPlugin::supportsTemplate( RoutingProfilesModel::ProfileTemplate profileTemplate ) const
0132 {
0133     return profileTemplate == RoutingProfilesModel::BicycleTemplate;
0134 }
0135 
0136 }
0137 
0138 #include "CycleStreetsPlugin.moc" // needed for Q_OBJECT here in source
0139 
0140 #include "moc_CycleStreetsPlugin.cpp"