-
Notifications
You must be signed in to change notification settings - Fork 22
/
WeatherDialog.h
226 lines (189 loc) · 6.55 KB
/
WeatherDialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
File: WeatherDialog.h
Created on: 24/11/2016
Author: Felix de las Pozas Alvarez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WEATHERDIALOG_H_
#define WEATHERDIALOG_H_
// Project
#include <Utils.h>
// Qt
#include "ui_WeatherDialog.h"
#include "ui_ErrorWidget.h"
#include <QDialog>
#include <qwebview.h>
#include <QWidget>
// C++
#include <memory>
namespace QtCharts
{
class QChart;
class QChartView;
class QLineSeries;
}
class QWebView;
class WeatherWidget;
class PollutionWidget;
/** \class ErrorWidget
* \brief Widget to show an error message in a forecast tab.
*
*/
class ErrorWidget
: public QWidget
, private Ui::ErrorWidget
{
Q_OBJECT
public:
explicit ErrorWidget(const QString &text)
{ setupUi(this); m_text->setText(text); }
virtual ~ErrorWidget()
{};
};
/** \class WeatherDialog
* \brief Implements the dialog showing the current weather and the forecast.
*
*/
class WeatherDialog
: public QDialog
, public Ui_WeatherDialog
{
Q_OBJECT
public:
/** \brief WeatherDialog class constructor.
* \param[in] parent pointer of the widget parent of this one.
* \param[in] flags window flags.
*
*/
WeatherDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
/** \brief WeatherDialog class virtual destructor.
*
*/
virtual ~WeatherDialog();
/** \brief Sets the weather and forecast data.
* \param[in] current current weather data.
* \param[in] data forecast data.
* \param[in] config application configuration.
*
*/
void setWeatherData(const ForecastData ¤t, const Forecast &data, Configuration &config);
/** \brief Sets the pollution forecast data.
* \param[in] data pollution forecast data.
*
*/
void setPollutionData(const Pollution &data);
/** \brief Returns true if the maps tab is visible and false otherwise.
*
*/
bool mapsEnabled() const;
signals:
void mapsEnabled(bool);
protected:
virtual void showEvent(QShowEvent *e) override;
virtual void changeEvent(QEvent *e) override;
private slots:
/** \brief Shows weather data when the user hovers on spline series.
* \param[in] point hover point.
* \param[in] state true when user has hovered over the series and false when hover has moved away from the series.
*
*/
void onChartHover(const QPointF &point, bool state);
/** \brief Shows weather data when the user hovers on a bar series.
* \param[in] state true when user has hovered over the series and false when hover has moved away from the series.
* \param[in] index Barset value index.
*
*/
void onChartHover(bool state, int index);
/** \brief Hides/show the series when the legend marker is clicked.
*
*/
void onLegendMarkerClicked();
/** \brief Resets the chart's zoom to the original one.
*
*/
void onResetButtonPressed();
/** \brief Updates the GUI when the user changes the tab.
* \param[in] index index of the current tab.
*
*/
void onTabChanged(int index);
/** \brief Shows the maps tab once it has finished loading.
* \param[in] value true on load success and false otherwise.
*
*/
void onLoadFinished(bool value);
/** \brief Shows/hides the maps tab.
*
*/
void onMapsButtonPressed();
/** \brief Helper method to update the maps tab title on load progress.
* \param[in] progress progress value in [0-100].
*
*/
void onLoadProgress(int progress);
/** \brief Updates the state of the reset chart zoom button.
*
*/
void onAreaChanged();
/** \brief Updates the background of the pollution chart on zoom.
* \param[in] begin Begin point in X axis.
* \param[in] end End point in X axis.
*
*/
void onPollutionAreaChanged(QDateTime begin, QDateTime end);
/** \brief Updates the background of the forecast chart on zoom.
* \param[in] begin Begin point in X axis.
* \param[in] end End point in X axis.
*
*/
void onForecastAreaChanged(QDateTime begin, QDateTime end);
private:
/** \brief Returns the color of the given aqi value.
* \param[in] aqiValue aqi value in [1,5].
*
*/
QColor pollutionColor(const int aqiValue);
/** \brief Updates the values of map layers in the configuration.
*
*/
void updateMapLayerValues();
/** \brief Loads and translated the web page of the maps.
*
*/
void loadMaps();
/** \brief Removes the maps tab.
*
*/
void removeMaps();
/** \brief Updates the visible series ranges.
* \param[in] chart QChart object to update axes ranges.
*
*/
void updateAxesRanges(QtCharts::QChart *chart);
/** \brief Computes and returns the gradient for the given dates.
* \param[in] begin Begin point in X axis.
* \param[in] end End point in X axis.
*
*/
QLinearGradient sunriseSunsetGradient(QDateTime begin, QDateTime end);
ErrorWidget *m_weatherError; /** Weather forecast error widget. */
ErrorWidget *m_pollutionError; /** Pollution forecast error widget */
QtCharts::QChartView *m_weatherChart; /** weather forecast chart view. */
QtCharts::QChartView *m_pollutionChart; /** pollution forecast chart view. */
const Forecast *m_forecast; /** forecast data. */
const Pollution *m_pollution; /** pollution data. */
Configuration *m_config; /** configuration data for tooltip. */
std::shared_ptr<WeatherWidget> m_weatherTooltip; /** weather char tooltip widget. */
std::shared_ptr<PollutionWidget> m_pollutionTooltip; /** pollution chart tooltip widget. */
QWebView *m_webpage; /** maps webpage. */
};
#endif // WEATHERDIALOG_H_