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_ROUTINGLAYER_H
0007 #define MARBLE_ROUTINGLAYER_H
0008 
0009 #include "LayerInterface.h"
0010 
0011 #include "MarbleGlobal.h"
0012 
0013 #include <QObject>
0014 #include <QRect>
0015 
0016 class QItemSelectionModel;
0017 class QModelIndex;
0018 
0019 namespace Marble
0020 {
0021 
0022 class MarbleWidget;
0023 class MarblePlacemarkModel;
0024 class RoutingLayerPrivate;
0025 
0026 /**
0027   * @brief A paint layer that serves as a view on a route model
0028   */
0029 class RoutingLayer: public QObject, public LayerInterface
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     /**
0035       * @brief Constructor
0036       * @param widget The marble widget used for geopos <-> screenpos transformations
0037       *   and repainting of (small) areas. Must not be null
0038       * @param parent Optional parent widget
0039       */
0040     explicit RoutingLayer( MarbleWidget *widget, QWidget *parent = nullptr );
0041 
0042     /** Destructor */
0043     ~RoutingLayer() override;
0044 
0045     /** Reimplemented from LayerInterface. We'll hover above the surface */
0046     QStringList renderPosition() const override;
0047 
0048     /** Reimplemented from LayerInterface. */
0049     qreal zValue() const override;
0050 
0051     /** Reimplemented from LayerInterface. Paints route items and placemarks */
0052     bool render( GeoPainter *painter, ViewportParams *viewport,
0053                  const QString &renderPos = "NONE", GeoSceneLayer *layer = nullptr ) override;
0054 
0055     RenderState renderState() const override;
0056 
0057     /**
0058       * Set the proxy model another QAbstractItemView uses that should share
0059       * its selection model with us. Needed because this class uses an unfiltered
0060       * model which has different indices than a filtered one.
0061       */
0062     void synchronizeWith( QItemSelectionModel *selection );
0063 
0064     /**
0065       * Set the placemark model to use. Implicitly removes the routing model.
0066       */
0067     void setPlacemarkModel ( MarblePlacemarkModel *model );
0068 
0069     /**
0070       * Set the view context to determine whether the map is used interactively
0071       */
0072     void setViewContext( ViewContext viewContext );
0073 
0074     /**
0075      * Determine whether the route can be edited by the user (via points added,
0076      * route cleared)
0077      */
0078     void setInteractive( bool interactive );
0079 
0080     /**
0081      * Returns whether the route is interactive (true by default if not changed
0082      * by setInteractive)
0083      */
0084     bool isInteractive() const;
0085 
0086     QString runtimeTrace() const override;
0087 
0088 Q_SIGNALS:
0089     /**
0090       * A placemark was selected (clicked) by the user. The index belongs to
0091       * the model set via setModel
0092       */
0093     void placemarkSelected( const QModelIndex &index );
0094 
0095     void repaintNeeded( const QRect &rect = QRect() );
0096 
0097 public:
0098     /** Overriding QWidget, used to make the layer interactive */
0099     bool eventFilter( QObject *obj, QEvent *event ) override;
0100 
0101 private Q_SLOTS:
0102     void removeViaPoint();
0103 
0104     void showAlternativeRoutes();
0105 
0106     /** Export route to a file */
0107     void exportRoute();
0108 
0109     /**
0110       * Paint a dashed route when downloading a new route, a solid one otherwise.
0111       */
0112     void updateRouteState();
0113 
0114     /**
0115       * The viewport has changed, recalculate positions accordingly
0116       */
0117     void setViewportChanged();
0118 
0119 private:
0120     RoutingLayerPrivate *const d;
0121     friend class RoutingLayerPrivate;
0122 
0123 };
0124 
0125 } // namespace Marble
0126 
0127 #endif