From: Carsten Niehaus Date: Mon, 17 Mar 2008 13:37:23 +0000 (+0000) Subject: Now the units of the isotope-halflifes work X-Git-Tag: v4.0.71~24 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=1bf15d862f357c00fd8a6c34db196f63e82a4265;p=libqmvoc.git Now the units of the isotope-halflifes work svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=786620 --- diff --git a/libscience/isotope.cpp b/libscience/isotope.cpp index 7445154..3c94ecc 100644 --- a/libscience/isotope.cpp +++ b/libscience/isotope.cpp @@ -100,9 +100,9 @@ double Isotope::halflife() const return m_halflife.value().toDouble(); } -ChemicalDataObject Isotope::halflifeObject() const +QString Isotope::halflifeUnit() const { - return m_halflife; + return m_halflife.unitAsString(); } double Isotope::ecdecay() const diff --git a/libscience/isotope.h b/libscience/isotope.h index 9746512..6565075 100644 --- a/libscience/isotope.h +++ b/libscience/isotope.h @@ -1,7 +1,7 @@ #ifndef ISOTOPE_H #define ISOTOPE_H /*************************************************************************** - * Copyright (C) 2005 by Carsten Niehaus * + * Copyright (C) 2005-2008 by Carsten Niehaus * * cniehaus@kde.org * * * * This program is free software; you can redistribute it and/or modify * @@ -83,22 +83,33 @@ class SCIENCE_EXPORT Isotope QString spin() const; + /** + * @return the magnetic moment of the Isotope + */ QString magmoment() const; QString abundance() const; + /** + * @return for example '17' if halflife of this Isotope is 17 seconds + * @ref halflife() + */ double halflife() const; /** - * @return the ChemicalDataObject of the halflife of the Isotope + * @return for example 's' if the unit of the halflife of this Isotope is given in + * seconds */ - ChemicalDataObject halflifeObject() const; + QString halflifeUnit() const; /** * add the ChemicalDataObject @p o */ void addData( ChemicalDataObject o ); + /** + * Set the number of nucleons of the isotope to @number + */ void setNucleons( int number ); /** diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp index 6762146..9063689 100644 --- a/libscience/isotopeparser.cpp +++ b/libscience/isotopeparser.cpp @@ -1,5 +1,5 @@ /*************************************************************************** -copyright : (C) 2005 by Carsten Niehaus +copyright : (C) 2005-2008 by Carsten Niehaus email : cniehaus@kde.org ***************************************************************************/ /*************************************************************************** @@ -15,7 +15,7 @@ email : cniehaus@kde.org #include "chemicaldataobject.h" #include "isotope.h" -#include +#include class IsotopeParser::Private @@ -88,7 +88,6 @@ IsotopeParser::~IsotopeParser() bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) { -//X kDebug() << "IsotopeParser::startElement()"; if (localName == "isotopeList") { d->inElement = true; @@ -99,11 +98,9 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const if ( attrs.localName( i ) == "id" ) d->currentElementSymbol = attrs.value( i ); -//X kDebug() << "Symbol of the current Element: " << attrs.value( i ); } } else if ( d->inElement && localName == "isotope") { -//X kDebug() << "setting inIsotope true!"; d->currentIsotope = new Isotope(); d->currentIsotope->addData( ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) ); d->inIsotope = true; @@ -112,7 +109,6 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const if ( attrs.localName( i ) == "number" ) { d->currentIsotope->setNucleons( attrs.value( i ).toInt() ); -//X kDebug() << attrs.value( i ).toInt(); } } } else if (d->inIsotope && localName == "scalar") @@ -132,20 +128,17 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const else if (attrs.value(i) == "bo:halfLife"){ for (int i = 0; i < attrs.length(); ++i) { - qDebug() << attrs.localName( i ); if (attrs.localName(i) == "units") { - if ( attrs.value(i) == "siUnits:s" ) - { + if ( attrs.value(i) == "siUnits:s" ) { d->currentUnit = ChemicalDataObject::s; - } - else if ( attrs.value(i) == "siUnits:y" ) - { + } else if ( attrs.value(i) == "siUnits:y" ) { d->currentUnit = ChemicalDataObject::y; } else { d->currentUnit = ChemicalDataObject::noUnit; } } } + d->currentDataObject.setUnit( d->currentUnit ); d->inHalfLife = true; } @@ -178,7 +171,6 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const bool IsotopeParser::endElement( const QString&, const QString& localName, const QString& ) { -//X kDebug() << "IsotopeParser::endElement()"; if ( localName == "isotope" ) { d->isotopes.append(d->currentIsotope); @@ -188,7 +180,6 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const } else if ( localName == "isotopeList" ) {//a new list of isotopes start... -//X kDebug() << "setting d->inElement FALSE"; d->inElement = false; } @@ -197,8 +188,6 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const bool IsotopeParser::characters(const QString &ch) { -//X kDebug() << "IsotopeParser::characters() with ch: " << ch; - d->currentDataObject = ChemicalDataObject(); ChemicalDataObject::BlueObelisk type; QVariant value; @@ -224,7 +213,6 @@ bool IsotopeParser::characters(const QString &ch) } else if (d->inHalfLife) { value = ch.toDouble(); - if(ch=="-1"){value=-2;} type = ChemicalDataObject::halfLife; d->inHalfLife = false; } diff --git a/libscience/tests/isotopereadingtest.cpp b/libscience/tests/isotopereadingtest.cpp index 5c89846..1855a4e 100644 --- a/libscience/tests/isotopereadingtest.cpp +++ b/libscience/tests/isotopereadingtest.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005, 2006 by Carsten Niehaus * + * Copyright (C) 2005, 2006, 2008 by Carsten Niehaus * * * * 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 * @@ -47,9 +47,13 @@ int main(int argc, char *argv[]) foreach( Isotope* i, v ){ if ( i ) { - if (i->nucleons() == 50 ){ +//X if (i->nucleons() == 50 ){ +//X qDebug() << " Isotope of " << i->parentElementSymbol() << " with a mass of " << i->mass(); +//X qDebug() << " Halflife: " << i->halflife() << i->halflifeUnit( ); +//X } + if (i->parentElementSymbol() == "Ti" ){ qDebug() << " Isotope of " << i->parentElementSymbol() << " with a mass of " << i->mass(); - qDebug() << " Halflife: " << i->halflife() << i->halflifeObject().unitAsString( ); + qDebug() << " Halflife: " << i->halflife() << i->halflifeUnit( ); } } }