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

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_ALTERNATIVEROUTESMODEL_H
0007 #define MARBLE_ALTERNATIVEROUTESMODEL_H
0008 
0009 #include "marble_export.h"
0010 
0011 #include <QAbstractListModel>
0012 
0013 /**
0014   * A QAbstractItemModel that contains a list of routing instructions.
0015   * Each item represents a routing step in the way from source to
0016   * destination. Steps near the source come first, steps near the target
0017   * last.
0018   */
0019 namespace Marble
0020 {
0021 
0022 class RouteRequest;
0023 class GeoDataDocument;
0024 class GeoDataLineString;
0025 
0026 class MARBLE_EXPORT AlternativeRoutesModel : public QAbstractListModel
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     enum WritePolicy {
0032         Instant,
0033         Lazy
0034     };
0035 
0036     /** Constructor */
0037     explicit AlternativeRoutesModel( QObject *parent = nullptr );
0038 
0039     /** Destructor */
0040     ~AlternativeRoutesModel() override;
0041 
0042     // Model querying
0043 
0044     /** Overload of QAbstractListModel */
0045     int rowCount ( const QModelIndex &parent = QModelIndex() ) const override;
0046 
0047     /** Overload of QAbstractListModel */
0048     QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
0049 
0050     /** Overload of QAbstractListModel */
0051     QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
0052 
0053     const GeoDataDocument *route(int index) const;
0054 
0055     // Model data filling
0056 
0057     /** Invalidate the current alternative routes and prepare for new ones to arrive */
0058     void newRequest( RouteRequest *request );
0059 
0060     /**
0061       * Old data in the model is discarded, the parsed content of the provided document
0062       * is used as the new model data and a model reset is done
0063       * @param document The route to add
0064       * @param policy In lazy mode (default), a short amount of time is waited for
0065       *   other addRoute() calls before adding the route to the model. Otherwise, the
0066       *   model is changed immediately.
0067       */
0068     void addRoute( GeoDataDocument* document, WritePolicy policy = Lazy );
0069 
0070     /** Remove all alternative routes from the model */
0071     void clear();
0072 
0073     const GeoDataDocument *currentRoute() const;
0074 
0075     /** Returns the waypoints contained in the route as a linestring */
0076     static const GeoDataLineString* waypoints( const GeoDataDocument* document );
0077 
0078 public Q_SLOTS:
0079     void setCurrentRoute( int index );
0080 
0081 Q_SIGNALS:
0082     void currentRouteChanged(const GeoDataDocument *newRoute);
0083     void currentRouteChanged( int index );
0084 
0085 private Q_SLOTS:
0086     void addRestrainedRoutes();
0087 
0088 private:
0089     class Private;
0090     Private *const d;
0091 };
0092 
0093 } // namespace Marble
0094 
0095 #endif