Projects/Plasma/Weather/Applets

From KDE TechBase
Revision as of 01:12, 1 August 2008 by Rytilahti (talk | contribs) (minifix)

Introduction

This page currently only includes some helpful things for applet developers. For the data format, see the Ion development page.

Helpful utils

Namespace WeatherFormula, which can be utilised by including plasma/weather/formulas.h (hopefully <Plasma/Weather/Formulas> later on..) inside your applet, provides some helpful functions for you to convert the data gotten from the ions.

The functions related to handling units can use the following units:

  • Celsius
  • Fahrenheit
  • Kelvin
  • Kilometers
  • MetersPerSecond
  • Miles
  • Kilopascals
  • InchesHG
  • Millibars
  • Hectopascals
  • Centimeters
  • Millimeters
  • Inches
  • Knots
  • Beaufort

These are packed inside WeatherFormula::Unit enum and they are ready for you to use already. See the following sections for a small guide how they can be useful for you.


convert()

Signature

float convert(float value, int srcUnit, int destUnit)

value is the value to be converted.

srcUnit is the unit from where to convert as WeatherFormula::Unit.

destUnit is the unit to where to convert as WeatherFormula::Unit.

Usage

Convert function can be used to convert the given value between different units. This makes it easy for applet developer to represent a value given by an ion in a selected format.

For example the conversion of value from meters per second to miles per hour can be done like this: WeatherFormula::convert(value, WeatherFormula::MetersPerSecond, WeatherFormula::Miles);

To make conversions even easier the ion developers are advised to use the same units when passing data to applets, so that one can pass an integer given by an ion directly to this function.


getUnitString()

Signature

QString getUnitString(int unit, bool plain=false)

unit being the unit as WeatherFormula::Unit.

plain being whether you want to have the unit in user presentable form or not.

Usage

This function allows you as the developer to get a string based on the given WeatherFormula::Unit. This can be useful when you want to display a given format as a string in your user interface or you want to use it to decide which picture to display.

To get a localized string to be used directly in the user interface you can just call it this way: WeatherFormula::getUnitString(WeatherFormula::Beaufort); which gives you i18nized version of Bft.

To get a plain string, for example to use to load an image based on it, you just set plain to true: WeatherFormula::getUnitString(WeatherFormula::Beaufort, true); which returns "bft" to you.


degreesToCardinal()

Signature

QString degreesToCardinal(float degrees)

degrees being the degrees to be converted.

Usage

This function can be used to convert the wind and solar degrees to a cardinal value (like used in compasses). For example 32° converts to NNE.

Using this function is simple, just call: WeatherFormula::degreesToCardinal(degrees); and you will be provided by a cardinal value for the given degree.