Commit 57262264 authored by Stuart Dilts's avatar Stuart Dilts
Browse files

Convert daily temp chart and hourly display units properly

The daily temperature graph and the hourly info now displays the
correct values when the temperature setting is not Celsius.
+ Add new function Kweather::convertTemp to convert double values in
  Celsius to the desired temperature.
parent 50762416
Pipeline #71866 passed with stage
in 21 seconds
......@@ -13,14 +13,20 @@
namespace Kweather
{
static const QString WEATHER_LOCATIONS_CFG_GROUP = QStringLiteral("WeatherLocations");
static QString tempConverter(double temp)
static double convertTemp(double temp)
{
if (KWeatherSettings().temperatureUnits() == "Fahrenheit") {
return QString::number(qRound(temp * 1.8 + 32)) + "°";
return temp * 1.8 + 32;
} else {
return QString::number(qRound(temp)) + "°";
return temp;
}
};
static QString tempConverter(double temp) {
return QString::number(qRound(convertTemp(temp))) + "°";
}
enum class WindDirection { N, NW, W, SW, S, SE, E, NE };
enum class Backend { NMI, OWM };
struct ResolvedWeatherDesc {
......
......@@ -54,7 +54,7 @@ public:
QString windSpeed() const;
QString temperature() const
{
return QString::number(hour().temperature(), 'f', 1);
return Kweather::tempConverter(hour().temperature());
}
QString temperatureRounded() const
{
......
......@@ -205,7 +205,8 @@ void WeatherLocation::updateChart()
m_maxTempList.clear();
m_xAxisList.clear();
for (const auto &day : m_forecast->dailyWeatherForecast()) {
m_maxTempList.append(day.maxTemp());
const auto tempToUse = Kweather::convertTemp(day.maxTemp());
m_maxTempList.append(tempToUse);
m_xAxisList.append(QLocale::system().toString(day.date(), QStringLiteral("ddd")));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment