]> Git trees. - libqmvoc.git/commitdiff
Now the units of the isotope-halflifes work
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 17 Mar 2008 13:37:23 +0000 (13:37 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 17 Mar 2008 13:37:23 +0000 (13:37 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=786620

libscience/isotope.cpp
libscience/isotope.h
libscience/isotopeparser.cpp
libscience/tests/isotopereadingtest.cpp

index 7445154c70eb07089a62ca3911c3e2e0c7236973..3c94eccad6505543aa39b5de7620b95d02fd5320 100644 (file)
@@ -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
index 9746512cd0d0fdfcb6c6f67918b75b5dcee4c803..6565075fc73556e7d33309ca698c7bad46fbc58d 100644 (file)
@@ -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 );
                
                /**
index 676214621167f52dab1c7ec4254eb01f9b54cb11..9063689db2a03e6513068f8b1bae243c4564d064 100644 (file)
@@ -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 <kdebug.h>
+#include <QDebug>
 
 
 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;
        }
index 5c89846aed4dfe86d8fb6647aca005a83f1cec2a..1855a4ecb4cb71398c9775a74bd558699cb1addc 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005, 2006 by Carsten Niehaus <cniehaus@kde.org>        *
+ *   Copyright (C) 2005, 2006, 2008 by Carsten Niehaus <cniehaus@kde.org>  *
  *                                                                         *
  *   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( );
             }
         }
     }