]> Git trees. - libqmvoc.git/commitdiff
* Add real support for unit. Only for the units of BO, though
authorCarsten Niehaus <cniehaus@gmx.de>
Sun, 23 Oct 2005 15:18:05 +0000 (15:18 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Sun, 23 Oct 2005 15:18:05 +0000 (15:18 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473388

libscience/chemicaldataobject.cpp
libscience/chemicaldataobject.h
libscience/elementparser.cpp
libscience/elementparser.h

index 56d0239948a05c8aea97c69930babcecb68c94cd..20c62bcd26bb80c82b69985208d27e1c5f9b6680 100644 (file)
@@ -127,6 +127,12 @@ QString ChemicalDataObject::dictRef()
                case orbit:
                        botype = "orbit";
                        break;
+               case date:
+                       botype = "date";
+                       break;
+               case discoverer:
+                       botype = "discoverer";
+                       break;
                case period:
                        botype = "period";
                        break;
index cb606fab5b07dcef73358eeab5ff0641f2401bd1..02eb03f7ad66eb72677a42d24cd193511dfda676 100644 (file)
@@ -52,12 +52,14 @@ class ChemicalDataObject
                        electronegativityPauling/**< the electronegativity in the definition of Pauling*/,
                        radiusCovalent/**< the covalent radius */,
                        radiusVDW/**< the van der Waals radius */,
-                       meltingpoint,
-                       boilingpoint,
-                       periodTableBlock,
-                       nameOrigin,
-                       orbit,
-                       period
+                       meltingpoint/**< the meltingpoint */,
+                       boilingpoint/**< the boilingpoint */,
+                       periodTableBlock/**< the block of the element */,
+                       nameOrigin/**< the origin of the name */,
+                       orbit/**< the quantumorbit of the element */,
+                       period/**< the period of the element */,
+                       date/**< date of discovery of the element. When 0, the element has been known in ancient times. */,
+                       discoverer/** The name of the discoverer(s) */
                };
 
                /**
@@ -88,6 +90,7 @@ class ChemicalDataObject
 
                /**
                 * Set the data of this object to @p v
+                * @param v the value of the object
                 */
                void setData( QVariant v ){
                        m_value = v;
@@ -182,6 +185,10 @@ class ChemicalDataObject
                        return m_unit;
                }
 
+               /**
+                * set the unit of this object to @p unit
+                * @param the BlueObeliskUnit of this object
+                */
                void setUnit( BlueObeliskUnit unit ){
                        m_unit = unit;
                }
index a4a3c8afdd1a71197ab18a8d0a804e149a5592db..89a4f4a1c71022a14283a124983db51ac0339b9d 100644 (file)
@@ -42,11 +42,19 @@ ElementSaxParser::ElementSaxParser()
 
 bool ElementSaxParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
 {
-       if (localName == "elementType") {
+       if (localName == "elementType") 
+       {
                currentElement_ = new Element();
                inElement_ = true;
-       } else if (inElement_ && localName == "scalar") {
-               for (int i = 0; i < attrs.length(); ++i) {
+       } else if (inElement_ && localName == "scalar") 
+       {
+               for (int i = 0; i < attrs.length(); ++i) 
+               {
+                       if ( attrs.localName( i ) == "unit" )
+                       {
+                               currentUnit_ = unit( attrs.value( i ) );
+                               continue;
+                       }
 
                        if (attrs.value(i) == "bo:atomicNumber")
                                inAtomicNumber_ = true;
@@ -91,14 +99,22 @@ bool ElementSaxParser::endElement (  const QString & namespaceURI, const QString
                elements_.append(currentElement_);
                
                currentElement_ = 0;
+               currentDataObject_ = 0;
                inElement_ = false;
        }
+       else if ( localName == "scalar" )
+       {
+               if ( currentUnit_ != ChemicalDataObject::noUnit )
+                       currentDataObject_->setUnit( currentUnit_ );
+
+               currentUnit_ = ChemicalDataObject::noUnit;
+       }
        return true;
 }
 
 bool ElementSaxParser::characters(const QString &ch)
 {
-       ChemicalDataObject *dataobject = new ChemicalDataObject();
+       currentDataObject_ = new ChemicalDataObject();
        ChemicalDataObject::BlueObelisk type;
        QVariant value;
 
@@ -180,11 +196,11 @@ bool ElementSaxParser::characters(const QString &ch)
        else//it is a non known value. Do not create a wrong object but return
                return true;
 
-       dataobject->setData( value );
-       dataobject->setType( type );
+       currentDataObject_->setData( value );
+       currentDataObject_->setType( type );
 
        if ( currentElement_ )
-               currentElement_->addData( dataobject );
+               currentElement_->addData( currentDataObject_ );
 
        return true;
 }
@@ -193,3 +209,19 @@ QList<Element*> ElementSaxParser::getElements()
 {
        return elements_;
 }
+
+ChemicalDataObject::BlueObeliskUnit ElementSaxParser::unit( const QString& unit )
+{
+       if ( unit == "bo:kelvin" ) 
+               return ChemicalDataObject::kelvin;
+       else if ( unit == "bo:ev" )
+               return ChemicalDataObject::ev;
+       else if ( unit == "bo:nm" )
+               return ChemicalDataObject::nm;
+       else if ( unit == "bo:pm" )
+               return ChemicalDataObject::pm;
+       else if ( unit == "bo:noUnit" )
+               return ChemicalDataObject::noUnit;
+       else
+               return ChemicalDataObject::noUnit;
+}
index 58ed4e2d226fa0a24c5284d61b9288de6b78fcb5..f815ac9477b8a6596743c46cf2c7a27ff742e205 100644 (file)
 
 #include <qxml.h>
 
+#include "chemicaldataobject.h"
+
 class Element;
 
+
+/**
+ * @author Carsten Niehaus <cniehaus@kde.org>
+ */
 class ElementSaxParser : public QXmlDefaultHandler
 {
        public:
+               /**
+                * Constructor
+                */
                ElementSaxParser();
                bool startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs);
 
@@ -32,6 +41,15 @@ class ElementSaxParser : public QXmlDefaultHandler
                QList<Element*> getElements();
 
        private:
+               ChemicalDataObject *currentDataObject_;
+               ChemicalDataObject::BlueObeliskUnit currentUnit_;
+
+               /**
+                * @return the BlueObeliskUnit of a ChemicalDataObject corresponding to @p text
+                * @param text the attribute-text of the XML parsed
+                */
+               ChemicalDataObject::BlueObeliskUnit unit( const QString& text );
+               
                Element *currentElement_;
                QList<Element*> elements_;
                bool inElement_;