• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • weather
WeatherData.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2009 Bastian Holst <bastianholst@gmx.de>
9 //
10 
11 // Self
12 #include "WeatherData.h"
13 
14 // Marble
15 #include "MarbleGlobal.h"
16 #include "MarbleDirs.h"
17 #include "MarbleDebug.h"
18 
19 // Qt
20 #include <QAtomicInt>
21 #include <QDate>
22 #include <QDateTime>
23 #include <QHash>
24 #include <QLocale>
25 #include <QImage>
26 
27 #include <cmath>
28 
29 namespace Marble
30 {
31 
32 // Factors
33 // m/s to knots
34 const qreal MPS2KN = 1.9437;
35 const qreal KN2MPS = 1 / MPS2KN;
36 // m/s to kilometer per hour
37 const qreal MPS2KPH = 3.6;
38 const qreal KPH2MPS = 1 / MPS2KPH;
39 // m/s to miles per hour
40 const qreal MPS2MPH = MPS2KPH * KM2MI;
41 const qreal MPH2MPS = 1 / MPS2MPH;
42 // HectoPascal to KiloPascal
43 const qreal HPA2KPA = 10;
44 const qreal KPA2HPA = 1/HPA2KPA;
45 // Bar to HectoPascal
46 const qreal BAR2HPA = 1000;
47 const qreal HPA2BAR = 1/BAR2HPA;
48 // mmHg to HectoPascal
49 const qreal HG2HPA = 1.33;
50 const qreal HPA2HG = 1/HG2HPA;
51 // inchHg to HectoPascal
52 const qreal IHG2HPA = HG2HPA * 25.4;
53 const qreal HPA2IHG = HPA2HG / 25.4;
54 
55 // Summands
56 // Kelvin to degree Celsius
57 const qreal KEL2CEL = -273.15;
58 const qreal CEL2KEL = -KEL2CEL;
59 
60 class WeatherDataPrivate
61 {
62  Q_DECLARE_TR_FUNCTIONS ( WeatherDataPrivate )
63 
64  public:
65  WeatherDataPrivate()
66  : m_pubTime(),
67  m_dataDate(),
68  m_condition( WeatherData::ConditionNotAvailable ),
69  m_windDirection( WeatherData::DirectionNotAvailable ),
70  m_windSpeed( -1.0 ),
71  m_temperature( -1.0 ),
72  m_maxTemperature( -1.0 ),
73  m_minTemperature( -1.0 ),
74  m_visibility( WeatherData::VisibilityNotAvailable ),
75  m_pressure( -1.0 ),
76  m_pressureDevelopment( WeatherData::PressureDevelopmentNotAvailable ),
77  m_humidity( -1.0 ),
78  ref( 1 )
79  {
80  initializeIcons();
81  }
82 
83  WeatherDataPrivate( const WeatherDataPrivate &other )
84  : m_pubTime( other.m_pubTime ),
85  m_dataDate( other.m_dataDate ),
86  m_condition( other.m_condition ),
87  m_windDirection( other.m_windDirection ),
88  m_windSpeed( other.m_windSpeed ),
89  m_temperature( other.m_temperature ),
90  m_maxTemperature( other.m_maxTemperature ),
91  m_minTemperature( other.m_minTemperature ),
92  m_visibility( other.m_visibility ),
93  m_pressure( other.m_pressure ),
94  m_pressureDevelopment( other.m_pressureDevelopment ),
95  m_humidity( other.m_humidity ),
96  ref( other.ref )
97  {
98  initializeIcons();
99  }
100 
101  static void initializeIcons()
102  {
103  if( s_iconPath.size() == 0 ) {
104  // Clouds
105  s_iconPath.insert( WeatherData::ConditionNotAvailable,
106  MarbleDirs::path( "weather/weather-none-available.png" ) );
107  s_iconPath.insert( WeatherData::ClearDay,
108  MarbleDirs::path( "weather/weather-clear.png" ) );
109  s_iconPath.insert( WeatherData::ClearNight,
110  MarbleDirs::path( "weather/weather-clear-night.png" ) );
111  s_iconPath.insert( WeatherData::FewCloudsDay,
112  MarbleDirs::path( "weather/weather-few-clouds.png" ) );
113  s_iconPath.insert( WeatherData::FewCloudsNight,
114  MarbleDirs::path( "weather/weather-few-clouds-night.png" ) );
115  s_iconPath.insert( WeatherData::PartlyCloudyDay,
116  MarbleDirs::path( "weather/weather-clouds.png" ) );
117  s_iconPath.insert( WeatherData::PartlyCloudyNight,
118  MarbleDirs::path( "weather/weather-clouds-night.png" ) );
119  s_iconPath.insert( WeatherData::Overcast,
120  MarbleDirs::path( "weather/weather-many-clouds.png" ) );
121 
122  // Rain
123  s_iconPath.insert( WeatherData::LightShowersDay,
124  MarbleDirs::path( "weather/weather-showers-scattered-day.png" ) );
125  s_iconPath.insert( WeatherData::LightShowersNight,
126  MarbleDirs::path( "weather/weather-showers-scattered-night.png" ) );
127  s_iconPath.insert( WeatherData::ShowersDay,
128  MarbleDirs::path( "weather/weather-showers-day.png" ) );
129  s_iconPath.insert( WeatherData::ShowersNight,
130  MarbleDirs::path( "weather/weather-showers-night.png" ) );
131  s_iconPath.insert( WeatherData::LightRain,
132  MarbleDirs::path( "weather/weather-showers-scattered.png" ) );
133  s_iconPath.insert( WeatherData::Rain,
134  MarbleDirs::path( "weather/weather-showers.png" ) );
135 
136  // Special
137  s_iconPath.insert( WeatherData::ChanceThunderstormDay,
138  MarbleDirs::path( "weather/weather-storm-day.png" ) );
139  s_iconPath.insert( WeatherData::ChanceThunderstormNight,
140  MarbleDirs::path( "weather/weather-storm-night.png" ) );
141  s_iconPath.insert( WeatherData::Thunderstorm,
142  MarbleDirs::path( "weather/weather-storm.png" ) );
143  s_iconPath.insert( WeatherData::Hail,
144  MarbleDirs::path( "weather/weather-hail.png" ) );
145  s_iconPath.insert( WeatherData::ChanceSnowDay,
146  MarbleDirs::path( "weather/weather-snow-scattered-day.png" ) );
147  s_iconPath.insert( WeatherData::ChanceSnowNight,
148  MarbleDirs::path( "weather/weather-snow-scattered-night.png" ) );
149  s_iconPath.insert( WeatherData::LightSnow,
150  MarbleDirs::path( "weather/weather-snow-scattered.png" ) );
151  s_iconPath.insert( WeatherData::Snow,
152  MarbleDirs::path( "weather/weather-snow.png" ) );
153  s_iconPath.insert( WeatherData::RainSnow,
154  MarbleDirs::path( "weather/weather-snow-rain.png" ) );
155  s_iconPath.insert( WeatherData::Mist,
156  MarbleDirs::path( "weather/weather-mist.png" ) );
157  s_iconPath.insert( WeatherData::SandStorm,
158  MarbleDirs::path( "weather/weather-none-available.png" ) );
159  }
160  }
161 
162  static qreal fromKelvin( qreal temp, WeatherData::TemperatureUnit format )
163  {
164  if( WeatherData::Kelvin == format ) {
165  return temp;
166  }
167  else if ( WeatherData::Celsius == format ) {
168  return temp + KEL2CEL;
169  }
170  else if ( WeatherData::Fahrenheit == format ) {
171  return ( temp * 1.8 ) - 459.67;
172  }
173  else {
174  mDebug() << "Wrong temperature format";
175  return 0;
176  }
177  }
178 
179  static qreal toKelvin( qreal temp, WeatherData::TemperatureUnit format )
180  {
181  if( WeatherData::Kelvin == format ) {
182  return temp;
183  }
184  else if ( WeatherData::Celsius == format ) {
185  return temp + CEL2KEL;
186  }
187  else if ( WeatherData::Fahrenheit == format ) {
188  return ( temp + 459.67 ) / 1.8;
189  }
190  else {
191  mDebug() << "Wrong temperature format";
192  return 0;
193  }
194  }
195 
196  static bool isPositiveValue( qreal value )
197  {
198  // A small tolerance
199  if( value > -0.5 ) {
200  return true;
201  }
202  return false;
203  }
204 
205  static QString generateTemperatureString( qreal temp, WeatherData::TemperatureUnit format )
206  {
207  QLocale locale = QLocale::system();
208  // We round to integer.
209  QString string = locale.toString( floor( fromKelvin( temp, format ) + 0.5 ) );
210  switch ( format ) {
211  case WeatherData::Kelvin:
212  string += " K";
213  break;
214  case WeatherData::Celsius:
215  string += " \xb0 C";
216  break;
217  case WeatherData::Fahrenheit:
218  string += " \xb0 F";
219  break;
220  }
221  return string;
222  }
223 
224 
225  WeatherDataPrivate& operator=( const WeatherDataPrivate &other )
226  {
227  m_pubTime = other.m_pubTime;
228  m_dataDate = other.m_dataDate;
229  m_condition = other.m_condition;
230  m_windDirection = other.m_windDirection;
231  m_windSpeed = other.m_windSpeed;
232  m_temperature = other.m_temperature;
233  m_maxTemperature = other.m_maxTemperature;
234  m_minTemperature = other.m_minTemperature;
235  m_visibility = other.m_visibility;
236  m_pressure = other.m_pressure;
237  m_pressureDevelopment = other.m_pressureDevelopment;
238  m_humidity = other.m_humidity;
239 
240  ref = other.ref;
241  return *this;
242  }
243 
244  QDateTime m_pubTime;
245  QDate m_dataDate;
246  WeatherData::WeatherCondition m_condition;
247  WeatherData::WindDirection m_windDirection;
248 
249  // Wind speed stored in m/s
250  qreal m_windSpeed;
251 
252  // Temperatures stored in Kelvin
253  qreal m_temperature;
254  qreal m_maxTemperature;
255  qreal m_minTemperature;
256 
257  WeatherData::Visibility m_visibility;
258 
259  // Pressure stored in hecto pascal
260  qreal m_pressure;
261 
262  WeatherData::PressureDevelopment m_pressureDevelopment;
263 
264  // Relative humidity
265  qreal m_humidity;
266 
267  QAtomicInt ref;
268 
269  static QHash<WeatherData::WeatherCondition, QImage> s_icons;
270  static QHash<WeatherData::WeatherCondition, QString> s_iconPath;
271  static WeatherData::TemperatureUnit s_standardTemperatureUnit;
272 };
273 
274 QHash<WeatherData::WeatherCondition, QImage> WeatherDataPrivate::s_icons = QHash<WeatherData::WeatherCondition, QImage>();
275 QHash<WeatherData::WeatherCondition, QString> WeatherDataPrivate::s_iconPath = QHash<WeatherData::WeatherCondition, QString>();
276 WeatherData::TemperatureUnit WeatherDataPrivate::s_standardTemperatureUnit = WeatherData::Celsius;
277 
278 WeatherData::WeatherData()
279  : d( new WeatherDataPrivate() )
280 {
281 }
282 
283 WeatherData::WeatherData( const WeatherData &other )
284  : d( other.d )
285 {
286  d->ref.ref();
287 }
288 
289 WeatherData::~WeatherData()
290 {
291  if ( !d->ref.deref() )
292  delete d;
293 }
294 
295 bool WeatherData::isValid() const
296 {
297  return hasValidPublishingTime()
298  || hasValidDataDate()
299  || hasValidCondition()
300  || hasValidWindDirection()
301  || hasValidWindSpeed()
302  || hasValidTemperature()
303  || hasValidMaxTemperature()
304  || hasValidMinTemperature()
305  || hasValidVisibility()
306  || hasValidPressure()
307  || hasValidPressureDevelopment()
308  || hasValidHumidity();
309 }
310 
311 QDateTime WeatherData::publishingTime() const
312 {
313  return d->m_pubTime;
314 }
315 
316 void WeatherData::setPublishingTime( const QDateTime& dateTime )
317 {
318  detach();
319  d->m_pubTime = dateTime.toUTC();
320 }
321 
322 bool WeatherData::hasValidPublishingTime() const
323 {
324  return d->m_pubTime.isValid();
325 }
326 
327 QDate WeatherData::dataDate() const
328 {
329  return d->m_dataDate;
330 }
331 
332 void WeatherData::setDataDate( const QDate& date )
333 {
334  detach();
335  d->m_dataDate = date;
336 }
337 
338 bool WeatherData::hasValidDataDate() const
339 {
340  return d->m_dataDate.isValid();
341 }
342 
343 WeatherData::WeatherCondition WeatherData::condition() const
344 {
345  return d->m_condition;
346 }
347 
348 void WeatherData::setCondition( WeatherData::WeatherCondition condition )
349 {
350  detach();
351  d->m_condition = condition;
352 }
353 
354 bool WeatherData::hasValidCondition() const
355 {
356  return d->m_condition != WeatherData::ConditionNotAvailable;
357 }
358 
359 QString WeatherData::conditionString() const
360 {
361  switch ( condition() ) {
362  case ClearDay:
363  return tr( "sunny" );
364  case ClearNight:
365  return tr( "clear" );
366  case FewCloudsDay:
367  case FewCloudsNight:
368  return tr( "few clouds" );
369  case PartlyCloudyDay:
370  case PartlyCloudyNight:
371  return tr( "partly cloudy" );
372  case Overcast:
373  return tr( "overcast" );
374  case LightShowersDay:
375  case LightShowersNight:
376  return tr( "light showers" );
377  case ShowersDay:
378  case ShowersNight:
379  return tr( "showers" );
380  case LightRain:
381  return tr( "light rain" );
382  case Rain:
383  return tr( "rain" );
384  case ChanceThunderstormDay:
385  case ChanceThunderstormNight:
386  return tr( "occasionally thunderstorm" );
387  case Thunderstorm:
388  return tr( "thunderstorm" );
389  case Hail:
390  return tr( "hail" );
391  case ChanceSnowDay:
392  case ChanceSnowNight:
393  return tr( "occasionally snow" );
394  case LightSnow:
395  return tr( "light snow" );
396  case Snow:
397  return tr( "snow" );
398  case RainSnow:
399  return tr( "rain and snow" );
400  case Mist:
401  return tr( "mist" );
402  case SandStorm:
403  return tr( "sandstorm" );
404  default:
405  return "Condition not available";
406  }
407 }
408 
409 QImage WeatherData::icon() const
410 {
411  QImage icon = WeatherDataPrivate::s_icons.value( condition() );
412 
413  // If the icon is in the hash, simply return it.
414  if ( !icon.isNull() ) {
415  return icon;
416  }
417  // If it isn't in the hash, the icon will be created (from the value stored in s_iconPath).
418  else {
419  icon = QImage( WeatherDataPrivate::s_iconPath.value( condition() ) );
420  WeatherDataPrivate::s_icons.insert( condition(), icon );
421  return icon;
422  }
423 }
424 
425 QString WeatherData::iconSource() const
426 {
427  QString const invalid = MarbleDirs::path( "weather/weather-none-available.png" );
428  QString const icon = WeatherDataPrivate::s_iconPath.value( condition() );
429  return icon == invalid ? "" : icon;
430 }
431 
432 WeatherData::WindDirection WeatherData::windDirection() const
433 {
434  return d->m_windDirection;
435 }
436 
437 void WeatherData::setWindDirection( WeatherData::WindDirection direction )
438 {
439  detach();
440  d->m_windDirection = direction;
441 }
442 
443 bool WeatherData::hasValidWindDirection() const
444 {
445  return d->m_windDirection != WeatherData::DirectionNotAvailable;
446 }
447 
448 QString WeatherData::windDirectionString() const
449 {
450  switch ( windDirection() ) {
451  case N:
452  return tr( "N" );
453  case NNE:
454  return tr( "NNE" );
455  case NE:
456  return tr( "NE" );
457  case ENE:
458  return tr( "ENE" );
459  case E:
460  return tr( "E" );
461  case SSE:
462  return tr( "SSE" );
463  case SE:
464  return tr( "SE" );
465  case ESE:
466  return tr( "ESE" );
467  case S:
468  return tr( "S" );
469  case NNW:
470  return tr( "NNW" );
471  case NW:
472  return tr( "NW" );
473  case WNW:
474  return tr( "WNW" );
475  case W:
476  return tr( "W" );
477  case SSW:
478  return tr( "SSW" );
479  case SW:
480  return tr( "SW" );
481  case WSW:
482  return tr( "WSW" );
483  default:
484  return "";
485  }
486 }
487 
488 qreal WeatherData::windSpeed( WeatherData::SpeedUnit format ) const
489 {
490  if ( WeatherData::mps == format ) {
491  return d->m_windSpeed;
492  }
493  if ( WeatherData::kph == format ) {
494  return d->m_windSpeed * MPS2KPH;
495  }
496  else if ( WeatherData::mph == format ) {
497  return d->m_windSpeed * MPS2MPH;
498  }
499  else if ( WeatherData::knots == format ) {
500  return d->m_windSpeed * MPS2KN;
501  }
502  else if ( WeatherData::beaufort == format ) {
503  if( d->m_windSpeed < 0.3 )
504  return 0;
505  else if( d->m_windSpeed < 1.6 )
506  return 1;
507  else if( d->m_windSpeed < 3.4 )
508  return 2;
509  else if( d->m_windSpeed < 5.5 )
510  return 3;
511  else if( d->m_windSpeed < 8.0 )
512  return 4;
513  else if( d->m_windSpeed < 10.8 )
514  return 5;
515  else if( d->m_windSpeed < 13.9 )
516  return 6;
517  else if( d->m_windSpeed < 17.2 )
518  return 7;
519  else if( d->m_windSpeed < 20.8 )
520  return 8;
521  else if( d->m_windSpeed < 24.5 )
522  return 9;
523  else if( d->m_windSpeed < 28.5 )
524  return 10;
525  else if( d->m_windSpeed < 32.7 )
526  return 11;
527  else
528  return 12;
529  }
530  else {
531  mDebug() << "Wrong speed format";
532  return 0;
533  }
534 }
535 
536 void WeatherData::setWindSpeed( qreal speed, WeatherData::SpeedUnit format )
537 {
538  detach();
539  if ( WeatherData::mps == format ) {
540  d->m_windSpeed = speed;
541  }
542  if ( WeatherData::kph == format ) {
543  d->m_windSpeed = speed * KPH2MPS;
544  }
545  else if ( WeatherData::mph == format ) {
546  d->m_windSpeed = speed * MPH2MPS;
547  }
548  else if ( WeatherData::knots == format ) {
549  d->m_windSpeed = speed * KN2MPS;
550  }
551  else if ( WeatherData::beaufort == format ) {
552  int rounded = (int) speed;
553  if( 0 == rounded )
554  d->m_windSpeed = 0.15;
555  else if( 1 == rounded )
556  d->m_windSpeed = 0.95;
557  else if( 2 == rounded )
558  d->m_windSpeed = 2.5;
559  else if( 3 == rounded )
560  d->m_windSpeed = 4.45;
561  else if( 4 == rounded )
562  d->m_windSpeed = 6.75;
563  else if( 5 == rounded )
564  d->m_windSpeed = 9.4;
565  else if( 6 == rounded )
566  d->m_windSpeed = 12.35;
567  else if( 7 == rounded )
568  d->m_windSpeed = 15.55;
569  else if( 8 == rounded )
570  d->m_windSpeed = 19.0;
571  else if( 9 == rounded )
572  d->m_windSpeed = 22.65;
573  else if( 10 == rounded )
574  d->m_windSpeed = 26.5;
575  else if( 11 == rounded )
576  d->m_windSpeed = 30.6;
577  else
578  d->m_windSpeed = 34;
579  }
580  else {
581  mDebug() << "Wrong speed format";
582  }
583 }
584 
585 bool WeatherData::hasValidWindSpeed() const
586 {
587  return d->isPositiveValue( d->m_windSpeed );
588 }
589 
590 QString WeatherData::windSpeedString( WeatherData::SpeedUnit unit ) const
591 {
592  QLocale locale = QLocale::system();
593  // We round to integer.
594  QString string = locale.toString( floor( windSpeed( unit ) + 0.5 ) );
595  string += ' ';
596  switch ( unit ) {
597  case WeatherData::kph:
598  string += QObject::tr("km/h");
599  break;
600  case WeatherData::mph:
601  string += QObject::tr("mph");
602  break;
603  case WeatherData::mps:
604  string += QObject::tr( "m/s" );
605  break;
606  case WeatherData::knots:
607  string += QObject::tr( "knots" );
608  break;
609  case WeatherData::beaufort:
610  string += QObject::tr( "Beaufort" );
611  break;
612  }
613  return string;
614 }
615 
616 qreal WeatherData::temperature( WeatherData::TemperatureUnit format ) const
617 {
618  return d->fromKelvin( d->m_temperature, format );
619 }
620 
621 void WeatherData::setTemperature( qreal temp, WeatherData::TemperatureUnit format )
622 {
623  detach();
624  d->m_temperature = d->toKelvin( temp, format );
625 }
626 
627 bool WeatherData::hasValidTemperature() const
628 {
629  return d->isPositiveValue( d->m_temperature );
630 }
631 
632 QString WeatherData::temperatureString( WeatherData::TemperatureUnit format ) const
633 {
634  return d->generateTemperatureString( d->m_temperature,
635  format );
636 }
637 
638 qreal WeatherData::maxTemperature( WeatherData::TemperatureUnit format ) const
639 {
640  return d->fromKelvin( d->m_maxTemperature, format );
641 }
642 
643 void WeatherData::setMaxTemperature( qreal temp, WeatherData::TemperatureUnit format )
644 {
645  detach();
646  d->m_maxTemperature = d->toKelvin( temp, format );
647 }
648 
649 QString WeatherData::maxTemperatureString( WeatherData::TemperatureUnit format ) const
650 {
651  return d->generateTemperatureString( d->m_maxTemperature,
652  format );
653 }
654 
655 bool WeatherData::hasValidMaxTemperature() const
656 {
657  return d->isPositiveValue( d->m_maxTemperature );
658 }
659 
660 qreal WeatherData::minTemperature( WeatherData::TemperatureUnit format ) const
661 {
662  return d->fromKelvin( d->m_minTemperature, format );
663 }
664 
665 QString WeatherData::minTemperatureString( WeatherData::TemperatureUnit format ) const
666 {
667  return d->generateTemperatureString( d->m_minTemperature,
668  format );
669 }
670 
671 void WeatherData::setMinTemperature( qreal temp, WeatherData::TemperatureUnit format )
672 {
673  detach();
674  d->m_minTemperature = d->toKelvin( temp, format );
675 }
676 
677 bool WeatherData::hasValidMinTemperature() const
678 {
679  return d->isPositiveValue( d->m_minTemperature );
680 }
681 
682 WeatherData::Visibility WeatherData::visibility() const
683 {
684  return d->m_visibility;
685 }
686 
687 void WeatherData::setVisibilty( WeatherData::Visibility visibility )
688 {
689  detach();
690  d->m_visibility = visibility;
691 }
692 
693 bool WeatherData::hasValidVisibility() const
694 {
695  return d->m_visibility != WeatherData::VisibilityNotAvailable;
696 }
697 
698 qreal WeatherData::pressure( WeatherData::PressureUnit format ) const
699 {
700  if ( WeatherData::HectoPascal == format ) {
701  return d->m_pressure;
702  }
703  else if ( WeatherData::KiloPascal == format ) {
704  return d->m_pressure * HPA2KPA;
705  }
706  else if ( WeatherData::Bar == format ) {
707  return d->m_pressure * HPA2BAR;
708  }
709  else if ( WeatherData::mmHg == format ) {
710  return d->m_pressure * HPA2HG;
711  }
712  else if ( WeatherData::inchHg == format ) {
713  return d->m_pressure * HPA2IHG;
714  }
715  else {
716  mDebug() << "Wrong pressure format";
717  return 0;
718  }
719 }
720 
721 void WeatherData::setPressure( qreal pressure, WeatherData::PressureUnit format )
722 {
723  detach();
724  if ( WeatherData::HectoPascal == format ) {
725  d->m_pressure = pressure;
726  }
727  else if ( WeatherData::KiloPascal == format ) {
728  d->m_pressure = pressure * KPA2HPA;
729  }
730  else if ( WeatherData::Bar == format ) {
731  d->m_pressure = pressure * BAR2HPA;
732  }
733  else if ( WeatherData::mmHg == format ) {
734  d->m_pressure = pressure * HG2HPA;
735  }
736  else if ( WeatherData::inchHg == format ) {
737  d->m_pressure = pressure * IHG2HPA;
738  }
739  else {
740  mDebug() << "Wrong pressure format";
741  }
742 }
743 
744 bool WeatherData::hasValidPressure() const
745 {
746  return d->isPositiveValue( d->m_pressure );
747 }
748 
749 QString WeatherData::pressureString( WeatherData::PressureUnit unit ) const
750 {
751  QLocale locale = QLocale::system();
752  // We round to integer.
753  QString string = locale.toString( pressure( unit ), 'f', 2 );
754  string += ' ';
755  switch ( unit ) {
756  case WeatherData::HectoPascal:
757  string += tr( "hPa" );
758  break;
759  case WeatherData::KiloPascal:
760  string += tr( "kPa" );
761  break;
762  case WeatherData::Bar:
763  string += tr( "Bar" );
764  break;
765  case WeatherData::mmHg:
766  string += tr( "mmHg" );
767  break;
768  case WeatherData::inchHg:
769  string += tr( "inch Hg" );
770  break;
771  }
772  return string;
773 }
774 
775 WeatherData::PressureDevelopment WeatherData::pressureDevelopment() const
776 {
777  return d->m_pressureDevelopment;
778 }
779 
780 void WeatherData::setPressureDevelopment( WeatherData::PressureDevelopment pressureDevelopment )
781 {
782  detach();
783  d->m_pressureDevelopment = pressureDevelopment;
784 }
785 
786 bool WeatherData::hasValidPressureDevelopment() const
787 {
788  return d->m_pressureDevelopment != WeatherData::PressureDevelopmentNotAvailable;
789 }
790 
791 QString WeatherData::pressureDevelopmentString() const
792 {
793  switch ( pressureDevelopment() ) {
794  case Rising:
795  return tr( "rising", "air pressure is rising" );
796  case NoChange:
797  return tr( "steady", "air pressure has no change" );
798  case Falling:
799  return tr( "falling", "air pressure falls" );
800  default:
801  return "";
802  }
803 }
804 
805 qreal WeatherData::humidity() const
806 {
807  return d->m_humidity;
808 }
809 
810 void WeatherData::setHumidity( qreal humidity )
811 {
812  detach();
813  d->m_humidity = humidity;
814 }
815 
816 bool WeatherData::hasValidHumidity() const
817 {
818  return d->isPositiveValue( d->m_humidity );
819 }
820 
821 QString WeatherData::humidityString() const
822 {
823  return QString( "%1 %" ).arg( humidity() );
824 }
825 
826 QString WeatherData::toHtml( WeatherData::TemperatureUnit temperatureUnit,
827  WeatherData::SpeedUnit speedUnit,
828  WeatherData::PressureUnit pressureUnit ) const
829 {
830  QString html;
831  if ( hasValidPublishingTime() ) {
832  html += tr( "Publishing time: %1<br>" )
833  .arg( publishingTime().toLocalTime().toString() );
834  }
835  if ( hasValidCondition() ) {
836  html += tr( "Condition: %1<br>" )
837  .arg( conditionString() );
838  }
839  if ( hasValidTemperature() ) {
840  html += tr( "Temperature: %1<br>" )
841  .arg( temperatureString( temperatureUnit ) );
842  }
843  if ( hasValidMaxTemperature() ) {
844  html += tr( "Max temperature: %1<br>" )
845  .arg( maxTemperatureString( temperatureUnit ) );
846  }
847  if ( hasValidMinTemperature() ) {
848  html += tr( "Min temperature: %1<br>" )
849  .arg( minTemperatureString( temperatureUnit ) );
850  }
851  if ( hasValidWindDirection() ) {
852  html += tr( "Wind direction: %1<br>" )
853  .arg( windDirectionString() );
854  }
855  if ( hasValidWindSpeed() ) {
856  html += tr( "Wind speed: %1<br>" )
857  .arg( windSpeedString( speedUnit ) );
858  }
859  if ( hasValidPressure() ) {
860  html += tr( "Pressure: %1<br>" )
861  .arg( pressureString( pressureUnit ) );
862  }
863  if ( hasValidPressureDevelopment() ) {
864  html += tr( "Pressure development: %1<br>")
865  .arg( pressureDevelopmentString() );
866  }
867  if ( hasValidHumidity() ) {
868  html += tr( "Humidity: %1<br>" )
869  .arg( humidityString() );
870  }
871 
872  return html;
873 }
874 
875 WeatherData& WeatherData::operator=( const WeatherData &other )
876 {
877  qAtomicAssign( d, other.d );
878  return *this;
879 }
880 
881 void WeatherData::detach()
882 {
883  qAtomicDetach( d );
884 }
885 
886 } // namespace Marble
Marble::WeatherData::hasValidCondition
bool hasValidCondition() const
Definition: WeatherData.cpp:354
Marble::WeatherData::Rain
Definition: WeatherData.h:46
Marble::WeatherData::pressure
qreal pressure(WeatherData::PressureUnit format=WeatherData::HectoPascal) const
Definition: WeatherData.cpp:698
Marble::WeatherData::NW
Definition: WeatherData.h:75
Marble::MPH2MPS
const qreal MPH2MPS
Definition: WeatherData.cpp:41
Marble::WeatherData::LightShowersNight
Definition: WeatherData.h:42
Marble::WeatherData::inchHg
Definition: WeatherData.h:120
Marble::WeatherData::WindDirection
WindDirection
Definition: WeatherData.h:64
Marble::WeatherData::setCondition
void setCondition(WeatherData::WeatherCondition condition)
Definition: WeatherData.cpp:348
Marble::WeatherData::hasValidWindDirection
bool hasValidWindDirection() const
Definition: WeatherData.cpp:443
Marble::WeatherData::mps
Definition: WeatherData.h:104
Marble::MPS2KPH
const qreal MPS2KPH
Definition: WeatherData.cpp:37
Marble::WeatherData::hasValidPressureDevelopment
bool hasValidPressureDevelopment() const
Definition: WeatherData.cpp:786
Marble::WeatherData::Hail
Definition: WeatherData.h:51
QDateTime::toUTC
QDateTime toUTC() const
Marble::MarbleDirs::path
static QString path(const QString &relativePath)
Definition: MarbleDirs.cpp:59
Marble::HPA2IHG
const qreal HPA2IHG
Definition: WeatherData.cpp:53
QLocale::toString
QString toString(qlonglong i) const
Marble::WeatherData::setPressure
void setPressure(qreal pressure, WeatherData::PressureUnit format=WeatherData::HectoPascal)
Definition: WeatherData.cpp:721
Marble::WeatherData::minTemperatureString
QString minTemperatureString(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:665
Marble::WeatherData::icon
QImage icon() const
Get the icon showing the current condition.
Definition: WeatherData.cpp:409
Marble::KPA2HPA
const qreal KPA2HPA
Definition: WeatherData.cpp:44
Marble::WeatherData::setPressureDevelopment
void setPressureDevelopment(WeatherData::PressureDevelopment)
Definition: WeatherData.cpp:780
Marble::WeatherData::SW
Definition: WeatherData.h:79
Marble::WeatherData::publishingTime
QDateTime publishingTime() const
Get the time when the data was published.
Definition: WeatherData.cpp:311
Marble::WeatherData::PressureUnit
PressureUnit
Definition: WeatherData.h:115
Marble::WeatherData::LightShowersDay
Definition: WeatherData.h:41
Marble::WeatherData::ConditionNotAvailable
Definition: WeatherData.h:32
Marble::WeatherData::dataDate
QDate dataDate() const
Get the date the data is meant for.
Definition: WeatherData.cpp:327
Marble::WeatherData::windDirection
WeatherData::WindDirection windDirection() const
Definition: WeatherData.cpp:432
Marble::WeatherData::humidity
qreal humidity() const
Definition: WeatherData.cpp:805
Marble::HPA2BAR
const qreal HPA2BAR
Definition: WeatherData.cpp:47
Marble::WeatherData::hasValidDataDate
bool hasValidDataDate() const
Checks, if the data item has a valid data date.
Definition: WeatherData.cpp:338
Marble::WeatherData::setMaxTemperature
void setMaxTemperature(qreal temp, WeatherData::TemperatureUnit format=WeatherData::Kelvin)
Definition: WeatherData.cpp:643
Marble::BAR2HPA
const qreal BAR2HPA
Definition: WeatherData.cpp:46
Marble::WeatherData::WeatherCondition
WeatherCondition
Definition: WeatherData.h:30
QImage::isNull
bool isNull() const
Marble::WeatherData::Bar
Definition: WeatherData.h:118
MarbleDebug.h
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::WeatherData::SpeedUnit
SpeedUnit
Definition: WeatherData.h:101
Marble::WeatherData::TemperatureUnit
TemperatureUnit
Definition: WeatherData.h:109
Marble::HPA2KPA
const qreal HPA2KPA
Definition: WeatherData.cpp:43
Marble::WeatherData::PressureDevelopmentNotAvailable
Definition: WeatherData.h:88
Marble::WeatherData::Mist
Definition: WeatherData.h:57
Marble::WeatherData::~WeatherData
~WeatherData()
Definition: WeatherData.cpp:289
QLocale::system
QLocale system()
Marble::WeatherData::humidityString
QString humidityString() const
Definition: WeatherData.cpp:821
Marble::WeatherData::hasValidHumidity
bool hasValidHumidity() const
Definition: WeatherData.cpp:816
Marble::WeatherData::WNW
Definition: WeatherData.h:76
Marble::WeatherData
Definition: WeatherData.h:26
Marble::WeatherData::hasValidPressure
bool hasValidPressure() const
Definition: WeatherData.cpp:744
Marble::WeatherData::beaufort
Definition: WeatherData.h:106
Marble::WeatherData::isValid
bool isValid() const
Definition: WeatherData.cpp:295
Marble::WeatherData::setWindSpeed
void setWindSpeed(qreal speed, WeatherData::SpeedUnit format=WeatherData::mps)
Definition: WeatherData.cpp:536
Marble::WeatherData::pressureDevelopment
WeatherData::PressureDevelopment pressureDevelopment() const
Definition: WeatherData.cpp:775
Marble::WeatherData::hasValidPublishingTime
bool hasValidPublishingTime() const
Checks, if the data item has a valid publishing time.
Definition: WeatherData.cpp:322
Marble::WeatherData::LightRain
Definition: WeatherData.h:45
QHash
Marble::WeatherData::SSW
Definition: WeatherData.h:78
Marble::WeatherData::KiloPascal
Definition: WeatherData.h:117
Marble::WeatherData::Falling
Definition: WeatherData.h:87
Marble::WeatherData::condition
WeatherData::WeatherCondition condition() const
Definition: WeatherData.cpp:343
Marble::WeatherData::setDataDate
void setDataDate(const QDate &date)
Set the date the data is meant for.
Definition: WeatherData.cpp:332
MarbleDirs.h
Marble::WeatherData::setVisibilty
void setVisibilty(WeatherData::Visibility visibility)
Definition: WeatherData.cpp:687
Marble::WeatherData::pressureString
QString pressureString(WeatherData::PressureUnit format=WeatherData::HectoPascal) const
Definition: WeatherData.cpp:749
Marble::WeatherData::ClearDay
Definition: WeatherData.h:33
Marble::WeatherData::Kelvin
Definition: WeatherData.h:112
Marble::CEL2KEL
const qreal CEL2KEL
Definition: WeatherData.cpp:58
QDate
Marble::WeatherData::NE
Definition: WeatherData.h:67
QAtomicInt
Marble::WeatherData::maxTemperature
qreal maxTemperature(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:638
Marble::WeatherData::ChanceSnowNight
Definition: WeatherData.h:53
Marble::WeatherData::Celsius
Definition: WeatherData.h:110
Marble::WeatherData::Overcast
Definition: WeatherData.h:39
QString
Marble::WeatherData::hasValidWindSpeed
bool hasValidWindSpeed() const
Definition: WeatherData.cpp:585
MarbleGlobal.h
Marble::WeatherData::Rising
Definition: WeatherData.h:85
Marble::MPS2KN
const qreal MPS2KN
Definition: WeatherData.cpp:34
Marble::WeatherData::SandStorm
Definition: WeatherData.h:58
Marble::WeatherData::W
Definition: WeatherData.h:77
Marble::WeatherData::kph
Definition: WeatherData.h:102
QLocale
Marble::WeatherData::N
Definition: WeatherData.h:65
Marble::WeatherData::PartlyCloudyNight
Definition: WeatherData.h:38
Marble::KM2MI
const qreal KM2MI
Definition: MarbleGlobal.h:203
Marble::WeatherData::maxTemperatureString
QString maxTemperatureString(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:649
Marble::WeatherData::hasValidTemperature
bool hasValidTemperature() const
Definition: WeatherData.cpp:627
Marble::WeatherData::ChanceSnowDay
Definition: WeatherData.h:52
Marble::HG2HPA
const qreal HG2HPA
Definition: WeatherData.cpp:49
QImage
Marble::WeatherData::HectoPascal
Definition: WeatherData.h:116
Marble::WeatherData::ShowersNight
Definition: WeatherData.h:44
Marble::WeatherData::WSW
Definition: WeatherData.h:80
Marble::WeatherData::operator=
WeatherData & operator=(const WeatherData &other)
Definition: WeatherData.cpp:875
Marble::WeatherData::WeatherData
WeatherData()
Definition: WeatherData.cpp:278
Marble::WeatherData::setTemperature
void setTemperature(qreal temp, WeatherData::TemperatureUnit format=WeatherData::Kelvin)
Definition: WeatherData.cpp:621
Marble::WeatherData::detach
void detach()
Definition: WeatherData.cpp:881
Marble::WeatherData::VisibilityNotAvailable
Definition: WeatherData.h:98
Marble::WeatherData::Visibility
Visibility
Definition: WeatherData.h:91
direction
qreal direction
Definition: tools/osm-addresses/OsmParser.cpp:40
Marble::WeatherData::Thunderstorm
Definition: WeatherData.h:50
Marble::WeatherData::hasValidMaxTemperature
bool hasValidMaxTemperature() const
Definition: WeatherData.cpp:655
Marble::WeatherData::windDirectionString
QString windDirectionString() const
Definition: WeatherData.cpp:448
Marble::WeatherData::mph
Definition: WeatherData.h:103
Marble::WeatherData::ENE
Definition: WeatherData.h:68
Marble::WeatherData::mmHg
Definition: WeatherData.h:119
Marble::WeatherData::PartlyCloudyDay
Definition: WeatherData.h:37
Marble::WeatherData::hasValidVisibility
bool hasValidVisibility() const
Definition: WeatherData.cpp:693
Marble::WeatherData::temperature
qreal temperature(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:616
Marble::WeatherData::windSpeed
qreal windSpeed(WeatherData::SpeedUnit format=WeatherData::mps) const
Definition: WeatherData.cpp:488
Marble::WeatherData::SSE
Definition: WeatherData.h:70
Marble::WeatherData::iconSource
QString iconSource() const
Definition: WeatherData.cpp:425
Marble::HPA2HG
const qreal HPA2HG
Definition: WeatherData.cpp:50
Marble::WeatherData::setMinTemperature
void setMinTemperature(qreal temp, WeatherData::TemperatureUnit format=WeatherData::Kelvin)
Definition: WeatherData.cpp:671
Marble::WeatherData::setHumidity
void setHumidity(qreal humidity)
Definition: WeatherData.cpp:810
Marble::WeatherData::DirectionNotAvailable
Definition: WeatherData.h:81
Marble::KPH2MPS
const qreal KPH2MPS
Definition: WeatherData.cpp:38
Marble::WeatherData::SE
Definition: WeatherData.h:71
Marble::KN2MPS
const qreal KN2MPS
Definition: WeatherData.cpp:35
Marble::WeatherData::minTemperature
qreal minTemperature(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:660
Marble::WeatherData::ClearNight
Definition: WeatherData.h:34
Marble::WeatherData::FewCloudsNight
Definition: WeatherData.h:36
Marble::WeatherData::Snow
Definition: WeatherData.h:55
Marble::WeatherData::LightSnow
Definition: WeatherData.h:54
Marble::WeatherData::pressureDevelopmentString
QString pressureDevelopmentString() const
Definition: WeatherData.cpp:791
Marble::WeatherData::S
Definition: WeatherData.h:73
Marble::WeatherData::RainSnow
Definition: WeatherData.h:56
Marble::WeatherData::ChanceThunderstormNight
Definition: WeatherData.h:49
Marble::WeatherData::temperatureString
QString temperatureString(WeatherData::TemperatureUnit format=WeatherData::Kelvin) const
Definition: WeatherData.cpp:632
Marble::WeatherData::ESE
Definition: WeatherData.h:72
Marble::WeatherData::setPublishingTime
void setPublishingTime(const QDateTime &dateTime)
Set the time when the data was published.
Definition: WeatherData.cpp:316
Marble::WeatherData::ShowersDay
Definition: WeatherData.h:43
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::MPS2MPH
const qreal MPS2MPH
Definition: WeatherData.cpp:40
WeatherData.h
Marble::WeatherData::Fahrenheit
Definition: WeatherData.h:111
Marble::WeatherData::conditionString
QString conditionString() const
Definition: WeatherData.cpp:359
Marble::WeatherData::knots
Definition: WeatherData.h:105
Marble::WeatherData::NoChange
Definition: WeatherData.h:86
Marble::KEL2CEL
const qreal KEL2CEL
Definition: WeatherData.cpp:57
Marble::WeatherData::PressureDevelopment
PressureDevelopment
Definition: WeatherData.h:84
Marble::WeatherData::toHtml
QString toHtml(WeatherData::TemperatureUnit temperatureUnit, WeatherData::SpeedUnit speedUnit, WeatherData::PressureUnit pressureUnit) const
Definition: WeatherData.cpp:826
Marble::WeatherData::windSpeedString
QString windSpeedString(WeatherData::SpeedUnit unit=WeatherData::kph) const
Definition: WeatherData.cpp:590
Marble::WeatherData::hasValidMinTemperature
bool hasValidMinTemperature() const
Definition: WeatherData.cpp:677
Marble::WeatherData::NNE
Definition: WeatherData.h:66
Marble::WeatherData::NNW
Definition: WeatherData.h:74
Marble::WeatherData::visibility
WeatherData::Visibility visibility() const
Definition: WeatherData.cpp:682
QDateTime
Marble::WeatherData::FewCloudsDay
Definition: WeatherData.h:35
Marble::WeatherData::setWindDirection
void setWindDirection(WeatherData::WindDirection direction)
Definition: WeatherData.cpp:437
Marble::WeatherData::ChanceThunderstormDay
Definition: WeatherData.h:48
Marble::WeatherData::E
Definition: WeatherData.h:69
Marble::IHG2HPA
const qreal IHG2HPA
Definition: WeatherData.cpp:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal