summaryrefslogtreecommitdiffstats
path: root/kweather/metar_parser.cpp
diff options
context:
space:
mode:
authorMavridis Philippe <mavridisf@gmail.com>2021-11-13 14:17:53 +0200
committerMavridis Philippe <mavridisf@gmail.com>2022-01-14 12:36:53 +0200
commit0e7033dd09c78eed673bfcde768483f6ad925ff7 (patch)
treea4f4484e6c154ff28c5d67697d6de976807fbf83 /kweather/metar_parser.cpp
parent5fea80f5693a74ee736300944c0c7204a663b92b (diff)
downloadtdetoys-0e7033dd09c78eed673bfcde768483f6ad925ff7.tar.gz
tdetoys-0e7033dd09c78eed673bfcde768483f6ad925ff7.zip
KWeather: updated icon handling.
The newly added class abstracts away icon names from the main code and has the ability to fall back to "safer" icon choices so as to ensure (if possible) icon theme consistency. Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
Diffstat (limited to 'kweather/metar_parser.cpp')
-rw-r--r--kweather/metar_parser.cpp86
1 files changed, 49 insertions, 37 deletions
diff --git a/kweather/metar_parser.cpp b/kweather/metar_parser.cpp
index 44e2c73..c7baa62 100644
--- a/kweather/metar_parser.cpp
+++ b/kweather/metar_parser.cpp
@@ -28,6 +28,7 @@ email : jratke@comcast.net
#include "metar_parser.h"
#include "stationdatabase.h"
+#include "weather_icon.h"
#include "sun.h"
// Temperature conversion macros
@@ -257,7 +258,7 @@ bool MetarParser::parseCurrent(const TQString &s)
if (sCode.contains("DZ"))
{
phenomena = i18n("Drizzle");
- weatherInfo.theWeather = "light_rain";
+ weatherInfo.theWeather = iconName( WeatherIcon::LightRain, false );
}
else if (sCode.contains("RA"))
{
@@ -272,32 +273,32 @@ bool MetarParser::parseCurrent(const TQString &s)
else if (sCode.contains("SG"))
{
phenomena = i18n("Snow Grains");
- weatherInfo.theWeather = "snow4";
+ weatherInfo.theWeather = iconName( WeatherIcon::Snow, false, 4 );
}
else if (sCode.contains("IC"))
{
phenomena = i18n("Ice Crystals");
- weatherInfo.theWeather = "hail";
+ weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
}
else if (sCode.contains("PE"))
{
phenomena = i18n("Ice Pellets");
- weatherInfo.theWeather = "hail";
+ weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
}
else if (s.contains("GR"))
{
phenomena = i18n("Hail");
- weatherInfo.theWeather = "hail";
+ weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
}
else if (sCode.contains("GS"))
{
phenomena = i18n("Small Hail Pellets");
- weatherInfo.theWeather = "hail";
+ weatherInfo.theWeather = iconName( WeatherIcon::Hail, false );
}
else if (s.contains("UP"))
{
phenomena = i18n("Unknown Precipitation");
- weatherInfo.theWeather = iconName("shower1");
+ weatherInfo.theWeather = iconName( WeatherIcon::Showers, isNight(weatherInfo.reportLocation), 1);
}
else if (sCode.contains("BR"))
{
@@ -721,24 +722,25 @@ bool MetarParser::parseStationNeedsMaintenance(const TQString &s)
void MetarParser::calcCurrentIcon()
{
- // Default to overcast clouds
- if ( weatherInfo.clouds == -1 )
- weatherInfo.clouds = 64;
+ bool night = isNight( weatherInfo.reportLocation );
if (weatherInfo.theWeather.isEmpty())
{
+
if (weatherInfo.clouds == 0)
- weatherInfo.theWeather = iconName("sunny");
+ weatherInfo.theWeather = iconName( WeatherIcon::Sunny, night );
else if (weatherInfo.clouds > 0 && weatherInfo.clouds <= 2)
- weatherInfo.theWeather = iconName("cloudy1");
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 1 );
else if ( weatherInfo.clouds > 2 && weatherInfo.clouds <= 4)
- weatherInfo.theWeather = iconName("cloudy2");
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 2 );
else if ( weatherInfo.clouds > 4 && weatherInfo.clouds <= 8)
- weatherInfo.theWeather = iconName("cloudy3");
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 3 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds < 63)
- weatherInfo.theWeather = iconName( "cloudy4" );
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 4 );
+ else if (weatherInfo.clouds < 0)
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, weatherInfo.clouds);
else
- weatherInfo.theWeather = "cloudy5";
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 );
}
else if (weatherInfo.theWeather == "tstorm")
{
@@ -746,11 +748,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- weatherInfo.theWeather = iconName("tstorm1");
+ weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- weatherInfo.theWeather = iconName("tstorm2");
+ weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 2 );
else
- weatherInfo.theWeather = "tstorm3";
+ weatherInfo.theWeather = iconName( WeatherIcon::Thunderstorm, night, 3 );
}
else if (weatherInfo.theWeather == "shower")
{
@@ -758,11 +760,11 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 10)
- weatherInfo.theWeather = iconName("shower1");
+ weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 1 );
else if ( weatherInfo.clouds > 10 && weatherInfo.clouds <= 20)
- weatherInfo.theWeather = iconName("shower2");
+ weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 2 );
else
- weatherInfo.theWeather = "shower3";
+ weatherInfo.theWeather = iconName( WeatherIcon::Showers, night, 3 );
}
else if (weatherInfo.theWeather == "snow")
{
@@ -770,22 +772,22 @@ void MetarParser::calcCurrentIcon()
weatherInfo.clouds = 30;
if (weatherInfo.clouds >= 0 && weatherInfo.clouds <= 8)
- weatherInfo.theWeather = iconName("snow1");
+ weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 1 );
else if ( weatherInfo.clouds > 8 && weatherInfo.clouds <= 16)
- weatherInfo.theWeather = iconName("snow2");
+ weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 2 );
else if (weatherInfo.clouds > 16 && weatherInfo.clouds <= 24)
- weatherInfo.theWeather = iconName("snow3");
+ weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 3 );
else
- weatherInfo.theWeather = "snow5";
+ weatherInfo.theWeather = iconName( WeatherIcon::Snow, night, 5 );
}
- else if (isNight(weatherInfo.reportLocation) && weatherInfo.theWeather == "mist")
- weatherInfo.theWeather = "mist_night";
- else if (isNight(weatherInfo.reportLocation) && weatherInfo.theWeather == "fog")
- weatherInfo.theWeather = "fog_night";
else if ( weatherInfo.theWeather == "mist" || weatherInfo.theWeather == "fog" )
{
if ( weatherInfo.clouds >= 63 )
- weatherInfo.theWeather = "cloudy5";
+ weatherInfo.theWeather = iconName( WeatherIcon::Cloudy, night, 5 );
+ else if ( weatherInfo.theWeather == "mist" )
+ weatherInfo.theWeather = iconName( WeatherIcon::Mist, night );
+ else if ( weatherInfo.theWeather == "fog" )
+ weatherInfo.theWeather = iconName( WeatherIcon::Fog, night );
}
kdDebug(12006) << "Clouds: " << weatherInfo.clouds << ", Icon: "
@@ -861,13 +863,23 @@ bool MetarParser::isNight(const TQString &stationID) const
}
}
-TQString MetarParser::iconName( const TQString &icon ) const
+TQString MetarParser::iconName( int condition, bool night, int strength ) const
{
- TQString _iconName = icon;
-
- if ( isNight( weatherInfo.reportLocation ) )
- _iconName += "_night";
-
+ TQString _iconName;
+ if( strength != 0 )
+ {
+ // Simple
+ WeatherIcon* wi = new WeatherIcon( condition, night, strength );
+ _iconName = wi->name();
+ delete wi;
+ }
+ else
+ {
+ // Ranged
+ WeatherIcon* wi = new WeatherIcon( condition, night );
+ _iconName = wi->name();
+ delete wi;
+ }
return _iconName;
}