[Marble-commits] KDE/kdeedu/marble/src/plugins/render/weather [POSSIBLY UNSAFE]
Bastian Holst
bastianholst at gmx.de
Wed Aug 19 19:30:55 CEST 2009
SVN commit 1013356 by bholst:
Marble's Weather item now displaying the full information on click.
M +54 -0 WeatherData.cpp
M +5 -0 WeatherData.h
M +32 -11 WeatherItem.cpp [POSSIBLY UNSAFE: system]
--- trunk/KDE/kdeedu/marble/src/plugins/render/weather/WeatherData.cpp #1013355:1013356
@@ -811,6 +811,60 @@
return d->isPositiveValue( d->m_humidity );
}
+QString WeatherData::humidityString() const
+{
+ return QString( "%1 %" ).arg( humidity() );
+}
+
+QString WeatherData::toHtml( WeatherData::TemperatureUnit temperatureUnit,
+ WeatherData::SpeedUnit speedUnit,
+ WeatherData::PressureUnit pressureUnit ) const
+{
+ QString html;
+ if ( hasValidPublishingTime() ) {
+ html += tr( "Publishing time: %1<br>" )
+ .arg( publishingTime().toLocalTime().toString() );
+ }
+ if ( hasValidCondition() ) {
+ html += tr( "Condition: %1<br>" )
+ .arg( conditionString() );
+ }
+ if ( hasValidTemperature() ) {
+ html += tr( "Temperature: %1<br>" )
+ .arg( temperatureString( temperatureUnit ) );
+ }
+ if ( hasValidMaxTemperature() ) {
+ html += tr( "Max temperature: %1<br>" )
+ .arg( maxTemperatureString( temperatureUnit ) );
+ }
+ if ( hasValidMinTemperature() ) {
+ html += tr( "Min temperature: %1<br>" )
+ .arg( minTemperatureString( temperatureUnit ) );
+ }
+ if ( hasValidWindDirection() ) {
+ html += tr( "Wind direction: %1<br>" )
+ .arg( windDirectionString() );
+ }
+ if ( hasValidWindSpeed() ) {
+ html += tr( "Wind speed: %1<br>" )
+ .arg( windSpeedString( speedUnit ) );
+ }
+ if ( hasValidPressure() ) {
+ html += tr( "Pressure: %1<br>" )
+ .arg( pressureString( pressureUnit ) );
+ }
+ if ( hasValidPressureDevelopment() ) {
+ html += tr( "Pressure development: %1<br>")
+ .arg( pressureDevelopmentString() );
+ }
+ if ( hasValidHumidity() ) {
+ html += tr( "Humidity: %1<br>" )
+ .arg( humidityString() );
+ }
+
+ return html;
+}
+
WeatherData& WeatherData::operator=( const WeatherData &other )
{
qAtomicAssign( d, other.d );
--- trunk/KDE/kdeedu/marble/src/plugins/render/weather/WeatherData.h #1013355:1013356
@@ -212,6 +212,11 @@
qreal humidity() const;
void setHumidity( qreal humidity );
bool hasValidHumidity() const;
+ QString humidityString() const;
+
+ QString toHtml( WeatherData::TemperatureUnit temperatureUnit,
+ WeatherData::SpeedUnit speedUnit,
+ WeatherData::PressureUnit pressureUnit ) const;
WeatherData& operator=( const WeatherData &other );
--- trunk/KDE/kdeedu/marble/src/plugins/render/weather/WeatherItem.cpp #1013355:1013356
@@ -83,6 +83,10 @@
updateLabels();
}
+ ~WeatherItemPrivate() {
+ delete m_browser;
+ }
+
void updateToolTip()
{
QLocale locale = QLocale::system();
@@ -233,19 +237,25 @@
QString windSpeedString()
{
- WeatherData::SpeedUnit speedUnit
- = (WeatherData::SpeedUnit) m_settings.value( "windSpeedUnit",
- WeatherData::kph ).toInt();
- return m_currentWeather.windSpeedString( speedUnit );
+ return m_currentWeather.windSpeedString( speedUnit() );
}
+ WeatherData::SpeedUnit speedUnit()
+ {
+ return (WeatherData::SpeedUnit) m_settings.value( "windSpeedUnit",
+ WeatherData::kph ).toInt();
+ }
+
QString pressureString()
{
- WeatherData::PressureUnit pressureUnit
- = (WeatherData::PressureUnit) m_settings.value( "pressureUnit",
- WeatherData::HectoPascal ).toInt();
- return m_currentWeather.pressureString( pressureUnit );
+ return m_currentWeather.pressureString( pressureUnit() );
}
+
+ WeatherData::PressureUnit pressureUnit()
+ {
+ return (WeatherData::PressureUnit) m_settings.value( "pressureUnit",
+ WeatherData::HectoPascal ).toInt();
+ }
WeatherData m_currentWeather;
QMap<QDate, WeatherData> m_forecastWeather;
@@ -423,7 +433,7 @@
void WeatherItem::openBrowser()
{
- qDebug() << "Open browser";
+ QLocale locale = QLocale::system();
if( !d->m_browser ) {
d->m_browser = new TinyWebBrowser();
}
@@ -433,9 +443,20 @@
html += "<h1>" + tr( "Weather for %1" ).arg( stationName() ) + "</h1>";
if ( d->m_currentWeather.isValid() ) {
html += "<h2>" + tr( "Current Observation" ) + "</h2>";
- html += tr( "Publishing Time: %1" )
- .arg( d->m_currentWeather.publishingTime().toLocalTime().toString() );
+ html += d->m_currentWeather.toHtml( d->temperatureUnit(),
+ d->speedUnit(),
+ d->pressureUnit() );
}
+ if ( !d->m_forecastWeather.isEmpty() ) {
+ html += "<h2>" + tr( "Forecasts" ) + "</h2>";
+ }
+ foreach ( WeatherData data, d->m_forecastWeather ) {
+ QDate date = data.dataDate();
+ html += "<h3>" + locale.standaloneDayName( date.dayOfWeek() ) + "</h3>";
+ html += data.toHtml( d->temperatureUnit(),
+ d->speedUnit(),
+ d->pressureUnit() );
+ }
html += "</body>";
html += "</html>";
More information about the Marble-commits
mailing list