1 // SPDX-License-Identifier: LGPL-2.1-or-later 2 // 3 // SPDX-FileCopyrightText: 2011-2012 Florian Eßer <f.esser@rwth-aachen.de> 4 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 5 // SPDX-FileCopyrightText: 2013 Roman Karlstetter <roman.karlstetter@googlemail.com> 6 // 7 8 #ifndef ELEVATIONPROFILEFLOATITEM_H 9 #define ELEVATIONPROFILEFLOATITEM_H 10 11 #include "AbstractFloatItem.h" 12 #include "DialogConfigurationInterface.h" 13 14 #include "ElevationProfileDataSource.h" 15 #include "ElevationProfilePlotAxis.h" 16 17 #include "GeoDataDocument.h" 18 #include "GeoDataLineString.h" 19 20 namespace Ui 21 { 22 class ElevationProfileConfigWidget; 23 } 24 25 namespace Marble 26 { 27 28 class ElevationProfileContextMenu; 29 class ElevationProfileDataSource; 30 class ElevationProfileTrackDataSource; 31 class ElevationProfileRouteDataSource; 32 class GeoDataPlacemark; 33 class MarbleWidget; 34 35 /** 36 * @short The class that creates an interactive elevation profile. 37 * 38 */ 39 40 class ElevationProfileFloatItem : public AbstractFloatItem, public DialogConfigurationInterface 41 { 42 Q_OBJECT 43 Q_PLUGIN_METADATA(IID "org.kde.marble.ElevationProfileFloatItem") 44 45 Q_INTERFACES( Marble::RenderPluginInterface ) 46 Q_INTERFACES( Marble::DialogConfigurationInterface ) 47 48 MARBLE_PLUGIN( ElevationProfileFloatItem ) 49 50 public: 51 explicit ElevationProfileFloatItem( const MarbleModel *marbleModel = nullptr ); 52 ~ElevationProfileFloatItem() override; 53 54 QStringList backendTypes() const override; 55 56 qreal zValue() const override; // Overriding LayerInterface to paint on top of the route 57 58 QString name() const override; 59 60 QString guiString() const override; 61 62 QString nameId() const override; 63 64 QString version() const override; 65 66 QString description() const override; 67 68 QString copyrightYears() const override; 69 70 QVector<PluginAuthor> pluginAuthors() const override; 71 72 QIcon icon() const override; 73 74 void initialize() override; 75 76 bool isInitialized() const override; 77 78 void setProjection( const ViewportParams *viewport ) override; 79 80 void paintContent( QPainter *painter ) override; 81 82 QDialog *configDialog() override; 83 84 protected: 85 bool eventFilter( QObject *object, QEvent *e ) override; 86 void contextMenuEvent( QWidget *w, QContextMenuEvent *e ) override; 87 88 private Q_SLOTS: 89 void handleDataUpdate(const GeoDataLineString &points, const QVector<QPointF> &eleData); 90 void updateVisiblePoints(); 91 void forceRepaint(); 92 void readSettings(); 93 void writeSettings(); 94 void toggleZoomToViewport(); 95 96 void switchToRouteDataSource(); 97 void switchToTrackDataSource(int index); 98 void switchDataSource(ElevationProfileDataSource *source); 99 100 101 Q_SIGNALS: 102 void dataUpdated(); 103 104 private: 105 ElevationProfileDataSource* m_activeDataSource; 106 ElevationProfileRouteDataSource m_routeDataSource; 107 ElevationProfileTrackDataSource m_trackDataSource; 108 QDialog *m_configDialog; 109 Ui::ElevationProfileConfigWidget *ui_configWidget; 110 111 int m_leftGraphMargin; 112 int m_eleGraphWidth; 113 qreal m_viewportWidth; 114 qreal m_eleGraphHeight; 115 qreal m_shrinkFactorY; 116 117 int m_fontHeight; 118 119 ElevationProfilePlotAxis m_axisX; 120 ElevationProfilePlotAxis m_axisY; 121 122 GeoDataDocument m_markerDocument; 123 GeoDataPlacemark *const m_markerPlacemark; 124 int m_documentIndex; 125 126 qreal m_cursorPositionX; 127 128 bool m_isInitialized; 129 130 friend class ElevationProfileContextMenu; 131 ElevationProfileContextMenu* m_contextMenu; 132 133 MarbleWidget* m_marbleWidget; 134 135 int m_firstVisiblePoint; 136 int m_lastVisiblePoint; 137 bool m_zoomToViewport; 138 QVector<QPointF> m_eleData; 139 GeoDataLineString m_points; 140 qreal m_minElevation; 141 qreal m_maxElevation; 142 qreal m_gain; 143 qreal m_loss; 144 145 QVector<QPointF> calculateElevationData(const GeoDataLineString &lineString) const; 146 void calculateStatistics(const QVector<QPointF> &eleData); 147 }; 148 149 150 } 151 152 #endif // ELEVATIONPROFILEFLOATITEM_H 153