File indexing completed on 2024-04-28 03:49:29

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_ROUTINGMANAGER_H
0007 #define MARBLE_ROUTINGMANAGER_H
0008 
0009 #include "marble_export.h"
0010 #include "RoutingProfile.h"
0011 
0012 namespace Marble
0013 {
0014 
0015 class RoutingManagerPrivate;
0016 class RoutingModel;
0017 class RouteRequest;
0018 class MarbleModel;
0019 class GeoDataDocument;
0020 class AlternativeRoutesModel;
0021 class RoutingProfilesModel;
0022 
0023 /**
0024   * Delegates data retrieval and model updates to the appropriate
0025   * routing provider.
0026   */
0027 class MARBLE_EXPORT RoutingManager : public QObject
0028 {
0029     Q_OBJECT
0030     Q_PROPERTY( State state READ state NOTIFY stateChanged )
0031     Q_PROPERTY( bool guidanceModeEnabled READ guidanceModeEnabled WRITE setGuidanceModeEnabled NOTIFY guidanceModeEnabledChanged )
0032 
0033 public:
0034     enum State {
0035         Downloading, // A new route is downloaded in the background
0036         Retrieved // No download in progress
0037     };
0038 
0039     /** Constructor */
0040     explicit RoutingManager( MarbleModel *marbleModel, QObject *parent = nullptr );
0041 
0042     /** Destructor */
0043     ~RoutingManager() override;
0044 
0045     /**
0046       * Provides access to the model which contains all possible routing profiles
0047       */
0048     RoutingProfilesModel *profilesModel();
0049 
0050     /**
0051       * Provides access to the routing model which contains a list
0052       * of routing instructions describing steps to get from the
0053       * source to the destination.
0054       * @see retrieveDirections
0055       */
0056     RoutingModel *routingModel();
0057 
0058     const RoutingModel *routingModel() const;
0059 
0060     /**
0061       * Provides access to the model which contains a list of
0062       * alternative routes
0063       */
0064     AlternativeRoutesModel* alternativeRoutesModel();
0065 
0066     /**
0067       * Returns the current route request
0068       */
0069     RouteRequest* routeRequest();
0070 
0071     /**
0072      * @brief Returns whether a route is being downloaded
0073      * @return
0074      */
0075     State state() const;
0076 
0077     /**
0078       * Saves the current route request and the current route to disk
0079       */
0080     void writeSettings() const;
0081 
0082     /**
0083       * Restores a previously saved route request and route from disk, if any
0084       */
0085     void readSettings();
0086 
0087     /**
0088       * Saves the current route to the file with the given filename. Existing files
0089       * will be overwritten. The route is saved in kml format.
0090       */
0091     void saveRoute( const QString &filename ) const;
0092 
0093     /**
0094       * Opens the given filename (kml format) and loads the route contained in it
0095       */
0096     void loadRoute( const QString &filename );
0097 
0098     /**
0099       * Generates a routing profile with default settings for the given transport type
0100       */
0101     RoutingProfile defaultProfile( RoutingProfile::TransportType transportType ) const;
0102 
0103     /**
0104       * Set whether a warning message should be shown to the user before
0105       * starting guidance mode.
0106       */
0107     void setShowGuidanceModeStartupWarning( bool show );
0108 
0109     /**
0110       * Returns true (default) if a warning is shown to the user when starting guidance
0111       * mode.
0112       */
0113     bool showGuidanceModeStartupWarning() const;
0114 
0115     /**
0116      * Set last directory the user opened a route from.
0117      */
0118     void setLastOpenPath( const QString &path );
0119 
0120     /**
0121      * Return last directory the user opened a route from.
0122      */
0123     QString lastOpenPath() const;
0124 
0125     /**
0126      * Set last directory the user saved a route to.
0127      */
0128     void setLastSavePath( const QString &path );
0129 
0130     /**
0131      * Return last directory the user saved a route to.
0132      */
0133     QString lastSavePath() const;
0134 
0135     /**
0136      * Set color for standard route rendering
0137      */
0138     void setRouteColorStandard( const QColor& color );
0139 
0140     /**
0141      * Get color for standard route rendering
0142      */
0143     QColor routeColorStandard() const;
0144 
0145     /**
0146      * Set color for highlighted route rendering
0147      */
0148     void setRouteColorHighlighted( const QColor& color );
0149 
0150     /**
0151      * Get color for highlighted route rendering
0152      */
0153     QColor routeColorHighlighted() const;
0154 
0155     /**
0156      * Set color for alternative route rendering
0157      */
0158     void setRouteColorAlternative( const QColor& color );
0159 
0160     /**
0161      * Get color for alternative route rendering
0162      */
0163     QColor routeColorAlternative() const;
0164 
0165     bool guidanceModeEnabled() const;
0166 
0167 public Q_SLOTS:
0168     /** Reverse the previously requested route, i.e. swap start and destination (and via points, if any) */
0169     void reverseRoute();
0170 
0171     /** Retrieve a route suiting the routeRequest */
0172     void retrieveRoute();
0173 
0174     /** Clear all via points */
0175     void clearRoute();
0176 
0177     /** Toggle turn by turn navigation mode */
0178     void setGuidanceModeEnabled( bool enabled );
0179 
0180 Q_SIGNALS:
0181     /**
0182       * Directions and waypoints for the given route are being downloaded or have
0183       * been retrieved -- newState tells which of both
0184       */
0185     void stateChanged( RoutingManager::State newState );
0186 
0187     void routeRetrieved( GeoDataDocument* route );
0188 
0189     void guidanceModeEnabledChanged( bool enabled );
0190 
0191 private:
0192     Q_PRIVATE_SLOT( d, void addRoute( GeoDataDocument* route ) )
0193 
0194     Q_PRIVATE_SLOT( d, void routingFinished() )
0195 
0196     Q_PRIVATE_SLOT(d, void setCurrentRoute(const GeoDataDocument *route))
0197 
0198     Q_PRIVATE_SLOT( d, void recalculateRoute( bool deviated ) )
0199 
0200 private:
0201     friend class RoutingManagerPrivate;
0202     RoutingManagerPrivate *const d;
0203 };
0204 
0205 } // namespace Marble
0206 
0207 #endif