File indexing completed on 2024-12-08 06:35:36

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2011-2012 Florian Eßer <f.esser@rwth-aachen.de>
0004 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0005 // SPDX-FileCopyrightText: 2013 Roman Karlstetter <roman.karlstetter@googlemail.com>
0006 //
0007 
0008 #ifndef ELEVATIONPROFILEFLOATITEM_H
0009 #define ELEVATIONPROFILEFLOATITEM_H
0010 
0011 #include "AbstractFloatItem.h"
0012 #include "DialogConfigurationInterface.h"
0013 
0014 #include "ElevationProfileDataSource.h"
0015 #include "ElevationProfilePlotAxis.h"
0016 
0017 #include "GeoDataDocument.h"
0018 #include "GeoDataLineString.h"
0019 
0020 namespace Ui
0021 {
0022     class ElevationProfileConfigWidget;
0023 }
0024 
0025 namespace Marble
0026 {
0027 
0028 class ElevationProfileContextMenu;
0029 class ElevationProfileDataSource;
0030 class ElevationProfileTrackDataSource;
0031 class ElevationProfileRouteDataSource;
0032 class GeoDataPlacemark;
0033 class MarbleWidget;
0034 
0035 /**
0036  * @short The class that creates an interactive elevation profile.
0037  *
0038  */
0039 
0040 class ElevationProfileFloatItem : public AbstractFloatItem, public DialogConfigurationInterface
0041 {
0042     Q_OBJECT
0043     Q_PLUGIN_METADATA(IID "org.kde.marble.ElevationProfileFloatItem")
0044 
0045     Q_INTERFACES( Marble::RenderPluginInterface )
0046     Q_INTERFACES( Marble::DialogConfigurationInterface )
0047 
0048     MARBLE_PLUGIN( ElevationProfileFloatItem )
0049 
0050  public:
0051     explicit ElevationProfileFloatItem( const MarbleModel *marbleModel = nullptr );
0052     ~ElevationProfileFloatItem() override;
0053 
0054     QStringList backendTypes() const override;
0055 
0056     qreal zValue() const override; // Overriding LayerInterface to paint on top of the route
0057 
0058     QString name() const override;
0059 
0060     QString guiString() const override;
0061 
0062     QString nameId() const override;
0063 
0064     QString version() const override;
0065 
0066     QString description() const override;
0067 
0068     QString copyrightYears() const override;
0069 
0070     QVector<PluginAuthor> pluginAuthors() const override;
0071 
0072     QIcon icon() const override;
0073 
0074     void initialize() override;
0075 
0076     bool isInitialized() const override;
0077 
0078     void setProjection( const ViewportParams *viewport ) override;
0079 
0080     void paintContent( QPainter *painter ) override;
0081 
0082     QDialog *configDialog() override;
0083 
0084 protected:
0085     bool eventFilter( QObject *object, QEvent *e ) override;
0086     void contextMenuEvent( QWidget *w, QContextMenuEvent *e ) override;
0087 
0088  private Q_SLOTS:
0089     void handleDataUpdate(const GeoDataLineString &points, const QVector<QPointF> &eleData);
0090     void updateVisiblePoints();
0091     void forceRepaint();
0092     void readSettings();
0093     void writeSettings();
0094     void toggleZoomToViewport();
0095 
0096     void switchToRouteDataSource();
0097     void switchToTrackDataSource(int index);
0098     void switchDataSource(ElevationProfileDataSource *source);
0099 
0100 
0101 Q_SIGNALS:
0102     void dataUpdated();
0103 
0104  private:
0105     ElevationProfileDataSource* m_activeDataSource;
0106     ElevationProfileRouteDataSource m_routeDataSource;
0107     ElevationProfileTrackDataSource m_trackDataSource;
0108     QDialog *m_configDialog;
0109     Ui::ElevationProfileConfigWidget *ui_configWidget;
0110 
0111     int      m_leftGraphMargin;
0112     int      m_eleGraphWidth;
0113     qreal    m_viewportWidth;
0114     qreal    m_eleGraphHeight;
0115     qreal    m_shrinkFactorY;
0116 
0117     int      m_fontHeight;
0118 
0119     ElevationProfilePlotAxis m_axisX;
0120     ElevationProfilePlotAxis m_axisY;
0121 
0122     GeoDataDocument         m_markerDocument;
0123     GeoDataPlacemark *const m_markerPlacemark;
0124     int                     m_documentIndex;
0125 
0126     qreal    m_cursorPositionX;
0127 
0128     bool     m_isInitialized;
0129 
0130     friend class ElevationProfileContextMenu;
0131     ElevationProfileContextMenu*   m_contextMenu;
0132 
0133     MarbleWidget*     m_marbleWidget;
0134 
0135     int               m_firstVisiblePoint;
0136     int               m_lastVisiblePoint;
0137     bool              m_zoomToViewport;
0138     QVector<QPointF>    m_eleData;
0139     GeoDataLineString m_points;
0140     qreal             m_minElevation;
0141     qreal             m_maxElevation;
0142     qreal             m_gain;
0143     qreal             m_loss;
0144 
0145     QVector<QPointF> calculateElevationData(const GeoDataLineString &lineString) const;
0146     void calculateStatistics(const QVector<QPointF> &eleData);
0147 };
0148 
0149 
0150 }
0151 
0152 #endif // ELEVATIONPROFILEFLOATITEM_H