libosmscout  1.1.1
ElevationChartWidget.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_CLIENT_QT_ELEVATIONCHARTWIDGET_H
2 #define OSMSCOUT_CLIENT_QT_ELEVATIONCHARTWIDGET_H
3 
4 /*
5  OSMScout - a Qt backend for libosmscout and libosmscout-map
6  Copyright (C) 2021 Lukáš Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
24 #include <osmscout/OverlayObject.h>
26 #include <osmscout/util/Locale.h>
27 
28 #include <QQuickPaintedItem>
29 #include <QColor>
30 
31 namespace osmscout {
32 
33 class OSMSCOUT_CLIENT_QT_API ElevationChartWidget : public QQuickPaintedItem {
34  Q_OBJECT
35  Q_PROPERTY(QObject *way READ getWay WRITE setWay NOTIFY wayChanged)
36  Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged)
37  Q_PROPERTY(QColor lineColor READ getLineColor WRITE setLineColor NOTIFY lineColorChanged)
38  Q_PROPERTY(qreal lineWidth READ getLineWidth WRITE setLineWidth NOTIFY lineWidthChanged)
39  Q_PROPERTY(QColor gradientTopColor READ getGradientTopColor WRITE setGradientTopColor NOTIFY gradientTopColorChanged)
40  Q_PROPERTY(QColor gradientBottomColor READ getGradientBottomColor WRITE setGradientBottomColor NOTIFY gradientBottomColorChanged)
41  Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor NOTIFY textColorChanged)
42  Q_PROPERTY(int textPixelSize READ getTextPixelSize WRITE setTextPixelSize NOTIFY textPixelSizeChanged)
43  Q_PROPERTY(int textPadding READ getTextPadding WRITE setTextPadding NOTIFY textPaddingChanged)
44 
45  Q_PROPERTY(qint64 pointCount READ getPointCount NOTIFY pointsUpdated)
46  Q_PROPERTY(double lowestElevation READ getLowestElevation NOTIFY pointsUpdated)
47  Q_PROPERTY(double highestElevation READ getHighestElevation NOTIFY pointsUpdated)
48  Q_PROPERTY(double ascent READ getAscent NOTIFY pointsUpdated)
49  Q_PROPERTY(double descent READ getDescent NOTIFY pointsUpdated)
50 
51 signals:
52  void wayChanged();
53  void loadingChanged();
54  void elevationProfileRequest(std::shared_ptr<OverlayWay> way,
55  int requestId,
56  osmscout::BreakerRef breaker);
57  void lineColorChanged();
58  void lineWidthChanged();
59  void gradientTopColorChanged();
60  void gradientBottomColorChanged();
61  void textColorChanged();
62  void textPixelSizeChanged();
63  void textPaddingChanged();
64  void pointsUpdated();
65 
66 public slots:
67  void onError(int requestId);
68  void onElevationProfileAppend(ElevationModule::ElevationPoints points, int requestId);
69  void onLoadingFinished(int requestId);
70 
71 public:
72  explicit ElevationChartWidget(QQuickItem* parent = nullptr);
73  ~ElevationChartWidget() override;
74 
75  void paint(QPainter *painter) override;
76 
77  QObject* getWay() const;
78  void setWay(QObject* o);
79 
80  bool isLoading() const
81  {
82  return loading;
83  }
84 
85  QColor getLineColor() const
86  {
87  return lineColor;
88  }
89 
90  void setLineColor(const QColor &color);
91 
92  qreal getLineWidth() const
93  {
94  return lineWidth;
95  }
96 
97  void setLineWidth(qreal w);
98 
99  QColor getGradientTopColor() const
100  {
101  return gradientTopColor;
102  }
103 
104  void setGradientTopColor(const QColor &c);
105 
106  QColor getGradientBottomColor() const
107  {
108  return gradientBottomColor;
109  }
110 
111  void setGradientBottomColor(const QColor &c);
112 
113  QColor getTextColor() const
114  {
115  return textColor;
116  }
117 
118  void setTextColor(const QColor &c);
119 
120  int getTextPixelSize() const
121  {
122  return textPixelSize;
123  }
124 
125  void setTextPixelSize(int size);
126 
127  int getTextPadding() const
128  {
129  return textPadding;
130  }
131 
132  void setTextPadding(int size);
133 
134  qint64 getPointCount() const
135  {
136  return points.size();
137  }
138 
139  double getLowestElevation() const
140  {
141  if (lowest.has_value()) {
142  return lowest->elevation.AsMeter();
143  }
144  return 0;
145  }
146 
147  double getHighestElevation() const
148  {
149  if (highest.has_value()) {
150  return highest->elevation.AsMeter();
151  }
152  return 0;
153  }
154 
155  double getAscent() const
156  {
157  return ascent.AsMeter();
158  }
159 
160  double getDescent() const
161  {
162  return descent.AsMeter();
163  }
164 
165 protected:
166  void reset();
167 
168 private:
169  ElevationModule* elevationModule=nullptr;
170  std::shared_ptr<OverlayWay> way;
171  osmscout::BreakerRef breaker;
172  bool loading=false;
173  int requestId=0;
174 
176  std::optional<ElevationPoint> lowest;
177  std::optional<ElevationPoint> highest;
178  osmscout::Distance ascent;
179  osmscout::Distance descent;
180 
181  QColor lineColor=Qt::darkBlue;
182  QColor textColor=Qt::darkBlue;
183  QColor gradientTopColor=QColor(lineColor.red(), lineColor.green(), lineColor.blue(), 0xA0);
184  QColor gradientBottomColor=Qt::transparent;
185  qreal lineWidth=5;
186  int textPixelSize=14;
187  int textPadding=4;
188 
189  Locale locale=Locale::ByEnvironment();
190 };
191 
192 }
193 
194 #endif // OSMSCOUT_CLIENT_QT_ELEVATIONCHARTWIDGET_H
#define OSMSCOUT_CLIENT_QT_API
Definition: ClientQtImportExport.h:45
int getTextPixelSize() const
Definition: ElevationChartWidget.h:120
QColor getGradientBottomColor() const
Definition: ElevationChartWidget.h:106
std::vector< osmscout::ElevationPoint > ElevationPoints
Definition: ElevationModule.h:41
std::shared_ptr< Breaker > BreakerRef
Definition: Breaker.h:65
STL namespace.
int getTextPadding() const
Definition: ElevationChartWidget.h:127
qreal getLineWidth() const
Definition: ElevationChartWidget.h:92
double getAscent() const
Definition: ElevationChartWidget.h:155
QColor getTextColor() const
Definition: ElevationChartWidget.h:113
Definition: OverlayObject.h:189
Definition: Area.h:38
double getLowestElevation() const
Definition: ElevationChartWidget.h:139
double getDescent() const
Definition: ElevationChartWidget.h:160
QColor getLineColor() const
Definition: ElevationChartWidget.h:85
Definition: ElevationModule.h:37
qint64 getPointCount() const
Definition: ElevationChartWidget.h:134
double getHighestElevation() const
Definition: ElevationChartWidget.h:147
Definition: ElevationChartWidget.h:33
QColor getGradientTopColor() const
Definition: ElevationChartWidget.h:99