From 11d87361f9222995b263c2761ef4fd08d6416dd9 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 1 Sep 2005 16:50:47 +0000 Subject: [PATCH] first bunch of updates from 3.5 branch and compiling fixes svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=455913 --- kalzium/src/element.cpp | 103 +++++++++++++++--------------- kalzium/src/element.h | 81 +++++++++++++++++------ kalzium/src/isotope.cpp | 3 +- kalzium/src/isotope.h | 56 ++++++++-------- kalzium/src/spectrum.cpp | 28 ++++---- kalzium/src/spectrum.h | 10 +-- kalzium/src/tempunit.cpp | 134 +++++++++++++++++++++++++++++++++++++++ kalzium/src/tempunit.h | 92 +++++++++++++++++++++++++++ 8 files changed, 389 insertions(+), 118 deletions(-) create mode 100644 kalzium/src/tempunit.cpp create mode 100644 kalzium/src/tempunit.h diff --git a/kalzium/src/element.cpp b/kalzium/src/element.cpp index d920c00..26f4911 100644 --- a/kalzium/src/element.cpp +++ b/kalzium/src/element.cpp @@ -23,23 +23,37 @@ #include "spectrum.h" #include "isotope.h" #include "kalziumdataobject.h" +#include "kalziumutils.h" #include #include #include #include +#include #include #include #include #include -#include - Element::Element() { m_radioactive = false; m_artificial = false; + m_abundance = 0; +} + +Isotope* Element::isotopeByNucleons( int numberOfNucleons ) +{ + QList::ConstIterator it = m_isotopeList.begin(); + const QList::ConstIterator itEnd = m_isotopeList.end(); + + for ( ; it != itEnd; ++it ) + { + if ( ( ( *it )->neutrons() + ( *it )->protones() ) == numberOfNucleons ) + return *it; + } + return 0; } QString Element::parsedOrbits( bool canBeEmpty ) @@ -58,30 +72,10 @@ QString Element::parsedOrbits( bool canBeEmpty ) return orbits; } - -double Element::strippedValue( double num ) -{ - if ( !finite( num ) ) - return num; - - double power; - power = 1e-6; - while ( power < num ) - power *= 10; - - num = num / power * 10000; - num = round( num ); - - return num * power / 10000; -} - - Element::~Element() { } - - double Element::meanmass() { return m_mass/m_number; @@ -158,11 +152,11 @@ const QString Element::adjustUnits( const int type ) break; case 1://Kelvin to Celsius val-=273.15; - v = i18n( "%1 is the temperature in Celsius", "%1 C" ).arg( QString::number( val ) ); + v = i18n( "%1 is the temperature in Celsius", "%1 %2C" ).arg( QString::number( val ) ).arg( "\xB0" ); break; case 2: // Kelvin to Fahrenheit val = val * 1.8 - 459.67; - v = i18n( "%1 is the temperature in Fahrenheit", "%1 F" ).arg( QString::number( val ) ); + v = i18n( "%1 is the temperature in Fahrenheit", "%1 %2F" ).arg( QString::number( val ) ).arg("\xB0"); break; } } @@ -253,7 +247,8 @@ void Element::drawStateOfMatter( QPainter* p, double temp ) QString text; QFont symbol_font = p->font(); - symbol_font.setPointSize( 18 ); + + symbol_font.setPointSize( 10 ); QFont f = p->font(); f.setPointSize( 9 ); @@ -261,7 +256,7 @@ void Element::drawStateOfMatter( QPainter* p, double temp ) //top left p->setPen( Qt::black ); - text = QString::number( strippedValue( mass( ) ) ); + text = QString::number( KalziumUtils::strippedValue( mass( ) ) ); p->drawText( X,Y ,ELEMENTSIZE,h_small,Qt::AlignCenter, text ); text = QString::number( number() ); @@ -274,7 +269,7 @@ void Element::drawStateOfMatter( QPainter* p, double temp ) p->setPen( Qt::black ); p->drawRect( X, Y,ELEMENTSIZE+1,ELEMENTSIZE+1); } - + QColor Element::currentColor( const double temp ) { QColor color; @@ -315,7 +310,7 @@ void Element::drawGradient( QPainter* p, const QString& value, const QColor& c) setElementColor( c ); //the height of a "line" inside an element - int h_small = 15; //the size for the small units like elementnumber + int h_small = 10; //the size for the small units like elementnumber //The X-coordiante int X = xPos(); @@ -328,16 +323,18 @@ void Element::drawGradient( QPainter* p, const QString& value, const QColor& c) p->setPen( Qt::black ); QFont symbol_font = p->font(); - symbol_font.setPointSize( 18 ); QFont f = p->font(); - f.setPointSize( 9 ); - + + f.setPointSize( KalziumUtils::maxSize(value, QRect( X,Y+ELEMENTSIZE-h_small, ELEMENTSIZE, h_small ),f, p ) ); p->setFont( f ); p->drawText( X,Y+ELEMENTSIZE-h_small , ELEMENTSIZE, h_small,Qt::AlignCenter, value ); + const QRect rect = QRect( X,Y,ELEMENTSIZE-2,ELEMENTSIZE-10 ); + int goodsize = KalziumUtils::maxSize( symbol(), rect, symbol_font, p ); + symbol_font.setPointSize( goodsize ); p->setFont( symbol_font ); - p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignCenter, symbol() ); + p->drawText( X+1,Y+5, ELEMENTSIZE-2,ELEMENTSIZE-10,Qt::AlignCenter, symbol() ); //border p->setPen( Qt::black ); @@ -347,7 +344,7 @@ void Element::drawGradient( QPainter* p, const QString& value, const QColor& c) void Element::drawSelf( QPainter* p, bool simple, bool isCrystal ) { //the height of a "line" inside an element - int h_small = 15; //the size for the small units like elementnumber + int h_small = 12; //the size for the small units like elementnumber //The X-coordiante int X = xPos(); @@ -357,15 +354,30 @@ void Element::drawSelf( QPainter* p, bool simple, bool isCrystal ) p->setPen( elementColor() ); p->fillRect( X, Y,ELEMENTSIZE,ELEMENTSIZE, elementColor() ); + p->setPen( Qt::black ); QString text; QFont symbol_font = p->font(); - symbol_font.setPointSize( 18 ); + + const int max = ELEMENTSIZE-10; + + const QRect rect = QRect( X,Y,ELEMENTSIZE-2,max ); + + int goodsize = KalziumUtils::maxSize( symbol(), rect, symbol_font, p ); + symbol_font.setPointSize( goodsize ); + p->setFont( symbol_font ); + + if ( !simple ) + p->drawText( X+1,Y+5, ELEMENTSIZE-2,max,Qt::AlignCenter, symbol() ); + else + p->drawText( X+1,Y+5, ELEMENTSIZE-2,max,Qt::AlignHCenter, symbol() ); + QFont f = p->font(); - f.setPointSize( 9 ); - + + QRect smallRect( X,Y ,ELEMENTSIZE-4,h_small ); + f.setPointSize( KalziumUtils::maxSize( QString::number( number() ), smallRect, f, p ) ); + p->setFont( f ); - p->setPen( Qt::black ); if ( !simple ) {//the user only wants a simple periodic table, don't weight the cell @@ -389,24 +401,15 @@ void Element::drawSelf( QPainter* p, bool simple, bool isCrystal ) text = i18n( "Crystalsystem hexagonal dense packed", "hdp" ); else if ( structure == "ccp" ) text = i18n( "Crystalsystem cubic close packed", "ccp" ); -// else -// text = QString::null; } else - text = QString::number( strippedValue( mass( ) ) ); - p->drawText( X,Y ,ELEMENTSIZE,h_small,Qt::AlignCenter, text ); + text = QString::number( KalziumUtils::strippedValue( mass( ) ) ); + p->drawText( X+2,Y ,ELEMENTSIZE-4 ,h_small,Qt::AlignCenter, text ); } - + text = QString::number( number() ); - p->drawText( X,Y+ELEMENTSIZE-h_small , ELEMENTSIZE, h_small,Qt::AlignCenter, text ); - - p->setFont( symbol_font ); - if ( !simple ) - p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignCenter, symbol() ); - else - p->drawText( X,Y, ELEMENTSIZE,ELEMENTSIZE,Qt::AlignHCenter, symbol() ); + p->drawText( X+2,Y+ELEMENTSIZE-h_small , ELEMENTSIZE-4, h_small,Qt::AlignCenter, text ); - p->setPen( Qt::black ); p->drawRect( X, Y,ELEMENTSIZE+1,ELEMENTSIZE+1); } diff --git a/kalzium/src/element.h b/kalzium/src/element.h index 008a643..e0212dd 100644 --- a/kalzium/src/element.h +++ b/kalzium/src/element.h @@ -23,20 +23,22 @@ #define ELEMENTSIZE 40 #include -#include +#include class Element; class QDomDocument; class QPainter; class QPoint; +class QFont; +class QRect; class Spectrum; class Isotope; struct coordinate; -typedef QValueList EList; -typedef QValueList CList; -typedef QValueList doubleList; +typedef QList EList; +typedef QList CList; +typedef QList doubleList; struct coordinate{ int x; @@ -55,6 +57,12 @@ class Element{ Element(); virtual ~Element(); + + /** + * @returns a pointer to the istope with @p numberOfNucleons + * nucleons + */ + Isotope* isotopeByNucleons( int numberOfNucleons ); enum RADIUSTYPE { @@ -71,14 +79,23 @@ class Element{ return m_number; } + /** + * @return if the Element is radioactive + */ bool radioactive() const{ return m_radioactive; } + /** + * @return if the Element is artificial + */ bool artificial() const{ return m_artificial; } + /** + * @return the information where the name of the Element comes from + */ QString nameOrigin() const{ return m_origin; } @@ -92,6 +109,11 @@ class Element{ void setEA( double value ) { m_EA = value; } void setMeltingpoint( double value ) { m_MP = value; } void setBoilingpoint( double value ) { m_BP = value; } + + /** + * sets the density of the Element + * @param value the density of the Element + */ void setDensity( double value ) { m_Density = value; } /** @@ -106,6 +128,12 @@ class Element{ void setBiologicalMeaning( int value ) { m_biological = value; } void setNumber( int num ){ m_number = num; } + /** + * set the abundance in crustal rocks [pm] + * @param abundance the abundace in crustal rocks + */ + void setAbundance( int abundance ){ m_abundance = abundance; } + void setScientist( const QString& value ) { m_scientist = value; } void setCrysatalstructure( const QString& value ) { m_crystalstructure = value; } void setName( const QString& value ) { m_name = value; } @@ -118,26 +146,28 @@ class Element{ void setOxydation( const QString& value ) { m_oxstage = value; } void setAcidicbehaviour( const QString& value ) { m_acidbeh = value; } void setIsotopes( const QString& value ) { m_isotopes = value; } - + void setArtificial(){ m_artificial = true; } void setRadioactive(){ m_radioactive = true; } + + void setIonisationList( doubleList l ){ m_ionenergies = l; } - void setIonisationList( doubleList l ){ - m_ionenergies = l; - } - - QValueList isotopes() const{ + QList isotopes() const{ return m_isotopeList; } - QValueList spectrumList() const{ + QList spectrumList() const{ return m_spectrumList; } - void setIsotopeList( QValueList list ){ + void setIsotopeList( QList list ){ m_isotopeList = list; } + /** + * sets the Spectrum of the Element + * @param spec the Spectrum of the Element + */ void setSpectrum( Spectrum *spec ){ m_spectrum = spec; } @@ -149,10 +179,17 @@ class Element{ return m_hasSpectrum; } + /** + * define if the element has a known Spectrum + * @param value if true, the Element has a Spectrum + */ void setHasSepctrum(bool value){ m_hasSpectrum = value; } + /** + * @return the Spectrum of the element + */ Spectrum* spectrum() const{ return m_spectrum; } @@ -193,6 +230,13 @@ class Element{ int biological() const { return m_biological; } + + /** + * @return the abundance in crustal rocks in parts per million + */ + int abundance() const { + return 12; + } /** * @return the symbol of the element @@ -373,12 +417,6 @@ class Element{ IONICRADIUS }; - /** - * calculate the 4-digit value of the value @p w - * @return the 4-digit value - */ - static double strippedValue( double w ); - QPoint pos() const; QPoint coords() const; @@ -401,9 +439,9 @@ class Element{ bool m_hasSpectrum; - QValueList m_isotopeList; + QList m_isotopeList; - QValueList m_spectrumList; + QList m_spectrumList; QColor m_Color; @@ -425,7 +463,8 @@ class Element{ int m_number, m_date, m_biological, - m_period; + m_period, + m_abundance; QString m_symbol, m_name, diff --git a/kalzium/src/isotope.cpp b/kalzium/src/isotope.cpp index 2395f04..a8908bd 100644 --- a/kalzium/src/isotope.cpp +++ b/kalzium/src/isotope.cpp @@ -22,7 +22,7 @@ #include #include -Isotope::Isotope( int neutrons, int protones, double percentage, double weight, double halflife, QString format, bool alphadecay, bool betaplusdecay, bool betaminusdecay, bool ecdecay, double alphapercentage, double betapluspercentage, double betaminuspercentage, double ecpercentage, double decayenergy, QString spin, QString magmoment) +Isotope::Isotope( int neutrons, int protones, double percentage, double weight, double halflife, QString format, double alphadecay, double betaplusdecay, double betaminusdecay, double ecdecay, double alphapercentage, double betapluspercentage, double betaminuspercentage, double ecpercentage, QString spin, QString magmoment) { m_neutrons = neutrons; m_protones = protones; @@ -35,7 +35,6 @@ Isotope::Isotope( int neutrons, int protones, double percentage, double weight, m_betaminusdecay = betaminusdecay; m_ecdecay = ecdecay; - m_decayenergy = decayenergy; m_spin = spin; m_magmoment = magmoment; diff --git a/kalzium/src/isotope.h b/kalzium/src/isotope.h index 063c29a..681bc67 100644 --- a/kalzium/src/isotope.h +++ b/kalzium/src/isotope.h @@ -37,15 +37,14 @@ class Isotope double weight, double halflife, QString format, - bool alphadecay, - bool betaplusdecay, - bool betaminusdecay, - bool ecdecay, + double alphadecay, + double betaplusdecay, + double betaminusdecay, + double ecdecay, double alphapercentage, double betapluspercentage, double betaminuspercentage, double ecpercentage, - double decayenergy, QString spin, QString magmoment); @@ -82,6 +81,13 @@ class Isotope return m_protones; } + /** + * @return the number of nucleons of ths isotope + */ + int nucleons() const{ + return m_protones+m_neutrons; + } + /** * the weight of the isotope */ @@ -90,34 +96,33 @@ class Isotope } /** - * @return true if the isotopes decays in alpha rays + * @return the energy of isotope's alpha decay */ - bool alphadecay() const{ + double alphadecay() const{ return m_alphadecay; } /** - * @return true if the isotopes decays in beta plus rays + * @return the energy of isotope's beta plus decay */ - bool betaplusdecay() const{ + double betaplusdecay() const{ return m_betaplusdecay; } /** - * @return true if the isotopes decays in beta-minus rays + * @return the energy of isotope's beta-minus decay */ - bool betaminusdecay() const{ + double betaminusdecay() const{ return m_betaminusdecay; } - bool ecdecay() const{ + /** + * @return the energy of isotope's EC- decay + */ + double ecdecay() const{ return m_ecdecay; } - - double decayenergy() const{ - return m_decayenergy; - } - + QString spin() const{ return m_spin; } @@ -196,16 +201,15 @@ class Isotope */ int m_protones; - ///Specify if the decay is of this kind - bool m_alphadecay; - ///Specify if the decay is of this kind - bool m_betaplusdecay; - ///Specify if the decay is of this kind - bool m_betaminusdecay; - ///Specify if the decay is of this kind - bool m_ecdecay; + ///Specify if the decay is the energy + double m_alphadecay; + ///Specify if the decay is the energy + double m_betaplusdecay; + ///Specify if the decay is the energy + double m_betaminusdecay; + ///Specify if the decay is the energy + double m_ecdecay; - double m_decayenergy; /** *spin and parity diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index 474b48e..4482c40 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -28,8 +28,8 @@ double Spectrum::minBand() { double value = ( *m_bandlist.begin() ).wavelength; - QValueList::const_iterator it = m_bandlist.begin(); - const QValueList::const_iterator itEnd = m_bandlist.end(); + QList::const_iterator it = m_bandlist.begin(); + const QList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { if ( value > ( *it ).wavelength ) @@ -41,8 +41,8 @@ double Spectrum::minBand() double Spectrum::maxBand() { double value = ( *m_bandlist.begin() ).wavelength; - QValueList::const_iterator it = m_bandlist.begin(); - const QValueList::const_iterator itEnd = m_bandlist.end(); + QList::const_iterator it = m_bandlist.begin(); + const QList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { if ( value < ( *it ).wavelength ) @@ -56,8 +56,8 @@ Spectrum* Spectrum::adjustToWavelength( double min, double max ) { Spectrum *spec = new Spectrum(); - QValueList::const_iterator it = m_bandlist.begin(); - const QValueList::const_iterator itEnd = m_bandlist.end(); + QList::const_iterator it = m_bandlist.begin(); + const QList::const_iterator itEnd = m_bandlist.end(); for ( ; it != itEnd; ++it ) { @@ -75,8 +75,8 @@ Spectrum* Spectrum::adjustToWavelength( double min, double max ) void Spectrum::adjustIntensities() { int maxInt = 0; - QValueList::Iterator it = m_bandlist.begin(); - const QValueList::Iterator itEnd = m_bandlist.end(); + QList::Iterator it = m_bandlist.begin(); + const QList::Iterator itEnd = m_bandlist.end(); //find the highest intensity for ( ; it != itEnd; ++it ) @@ -101,12 +101,12 @@ void Spectrum::adjustIntensities() } } -QValueList Spectrum::wavelengths( double min, double max ) +QList Spectrum::wavelengths( double min, double max ) { - QValueList list; + QList list; - QValueList::const_iterator it = m_bandlist.begin(); - const QValueList::const_iterator itEnd = m_bandlist.end(); + QList::const_iterator it = m_bandlist.begin(); + const QList::const_iterator itEnd = m_bandlist.end(); for ( ; it != itEnd; ++it ) { @@ -125,8 +125,8 @@ QString Spectrum::bandsAsHtml() html += ""; - QValueList::const_iterator it = m_bandlist.begin(); - const QValueList::const_iterator itEnd = m_bandlist.end(); + QList::const_iterator it = m_bandlist.begin(); + const QList::const_iterator itEnd = m_bandlist.end(); for (;it!=itEnd;++it) { html += QString( "" ) diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index 32c5890..ca31023 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -22,7 +22,7 @@ ***************************************************************************/ #include -#include +#include class QPixmap; class Element; @@ -103,9 +103,9 @@ class Spectrum * @param min the lowest allowed wavalength in nanometer * @param max the highest allowed wavalength in nanometer * - * @return the wavelength in a QValueList + * @return the wavelength in a QList */ - QValueList wavelengths( double min, double max ); + QList wavelengths( double min, double max ); /** * @return the smallest wavelength @@ -124,7 +124,7 @@ class Spectrum /** * @return the list of bands of the spectrum */ - QValueList* bandlist(){ + QList* bandlist(){ return &m_bandlist; } @@ -162,7 +162,7 @@ class Spectrum /** * the internal dataset */ - QValueList m_bandlist; + QList m_bandlist; /** * the cached values of the highest and lowest wavelength diff --git a/kalzium/src/tempunit.cpp b/kalzium/src/tempunit.cpp new file mode 100644 index 0000000..e044f79 --- /dev/null +++ b/kalzium/src/tempunit.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (C) 2005 by Pino Toscano * + * toscano.pino@tiscali.it * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "tempunit.h" + +double TempUnit::convert( double value, TempUnit::Unit from, TempUnit::Unit to ) +{ + /** + * These are the four formula needed to convert from + * Kelvin the the other units: + + Kelvin Celsius °C = K - 273,15 + Kelvin Fahrenheit °F = K × 1,8 - 459,67 + Kelvin Rankine °Ra = K × 1,8 + Kelvin Reaumur °R = ( K - 273,15 ) × 0,8 + */ + + if ( from != Kelvin ) + value = convertToKelvin( value, from ); + + //now 'value' is in Kelvin + switch( to ) + { + case Celsius: + return value - 273.16; + case Fahrenheit: + return value * 1.8 - 459.67; + case Rankine: + return value * 1.8; + case Reaumur: + return ( value - 273.15 )* 0.8; + case Kelvin: + return value; + } + return value; +} + +double TempUnit::convertToKelvin( const double value, TempUnit::Unit from ) +{ + switch( from ) + { + case Kelvin: + return value; + case Celsius: + return value + 273.16; + case Fahrenheit: + return ( value + 459.67 )/1.8; + case Rankine: + return value / 1.8; + case Reaumur: + return ( value * 1.25 ) + 273.15; + } + return value; +} + +double TempUnit::convert( const double value, int from, int to ) +{ + return convert( value, (TempUnit::Unit)from, (TempUnit::Unit)to ); +} + +QStringList TempUnit::unitListSymbols() +{ + QStringList list; + list << "K"; + list << QString::fromUtf8("°C"); + list << QString::fromUtf8("°F"); + list << QString::fromUtf8("°Ra"); + list << QString::fromUtf8("°R"); + return list; +} + +QString TempUnit::unitListSymbol( int i ) +{ + QStringList l = unitListSymbols(); + if ( ( i < 0 ) || ( i >= (int)l.count() ) ) + return l[0]; + return l[i]; +} + +QPair TempUnit::rangeForUnit( TempUnit::Unit u ) +{ + switch( u ) + { + case Kelvin: + { + return QPair( 0.0, 5000.0 ); + break; + } + case Celsius: + { + return QPair( -273.16, 4726.84 ); + break; + } + case Fahrenheit: + { + return QPair( -459.67, 8540.33 ); + break; + } + case Rankine: + { + return QPair( 0.0, 9000.0 ); + break; + } + case Reaumur: + { + return QPair( -218.52, 3781.48 ); + break; + } + } + return QPair( 0.0, 5000.0 ); +} + +QPair TempUnit::rangeForUnit( int u ) +{ + return rangeForUnit( (TempUnit::Unit)u ); +} + diff --git a/kalzium/src/tempunit.h b/kalzium/src/tempunit.h new file mode 100644 index 0000000..f7de2c9 --- /dev/null +++ b/kalzium/src/tempunit.h @@ -0,0 +1,92 @@ +#ifndef TEMPUNIT_H +#define TEMPUNIT_H +/*************************************************************************** + * Copyright (C) 2005 by Pino Toscano * + * toscano.pino@tiscali.it * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include + +/** + * This class obtains all the info needed to work with the units of measure + * of temperature. + * + * It has static methods you can call to get the various infos. The most + * important methods is convert(), that performs conversions. + * + * @author Pino Toscano + */ +class TempUnit +{ + public: + + enum Unit { Kelvin = 0, + Celsius, + Fahrenheit, + Rankine, + Reaumur + }; + + /** + * Convert the temperature unit @p value given in the unit + * @p from to the unit @p to. + * + * @return the value converted + */ + static double convert( double value, + TempUnit::Unit from, + TempUnit::Unit to ); + + + /** + * @param value the temperature to convert + * @param from the unit from which to convert + * + * @return the temperature to Kelvin + */ + static double convertToKelvin( const double value, + TempUnit::Unit from ); + + /** + * @overload + */ + static double convert( const double value, + int from, + int to ); + + /** + * @return a list with the symbols of the temperature units + * we support + */ + static QStringList unitListSymbols(); + + /** + * @return the symbol of the @p i -th unit + */ + static QString unitListSymbol( int i ); + + static QPair rangeForUnit( TempUnit::Unit u ); + + /** + * @overload + */ + static QPair rangeForUnit( int u ); + +}; +#endif // TEMPUNIT_H -- 2.47.3