]> Git trees. - libqmvoc.git/commitdiff
* Add the missing datasets
authorCarsten Niehaus <cniehaus@gmx.de>
Thu, 20 Oct 2005 12:49:34 +0000 (12:49 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Thu, 20 Oct 2005 12:49:34 +0000 (12:49 +0000)
* Fix a bug: Only create an object when needed

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=472317

libscience/chemicaldataobject.cpp
libscience/chemicaldataobject.h
libscience/elementparser.cpp
libscience/elementparser.h
libscience/tests/xmlreadingtest.cpp

index d47004d8aa5e3a1d9845775e7d3dae6573067498..6a1894900d54d3509651ffa845f886fa25f6cf7b 100644 (file)
@@ -74,4 +74,45 @@ bool ChemicalDataObject::operator==( const QString& v )
 
 ChemicalDataObject::~ChemicalDataObject()
 {}
+
+QString ChemicalDataObject::dictRef()
+{
+       QString botype;
+       switch ( m_type ){
+               case atomicNumber:
+                       botype = "atomicNumber";
+                       break;
+               case symbol:
+                       botype = "symbol";
+                       break;
+               case name:
+                       botype = "name";
+                       break;
+               case mass:
+                       botype = "mass";
+                       break;
+               case exactMass:
+                       botype = "exactMass";
+                       break;
+               case ionization:
+                       botype = "ionization";
+                       break;
+               case electronAffinity:
+                       botype = "electronAffinity";
+                       break;
+               case electronegativityPauling:
+                       botype = "electronegativityPauling";
+                       break;
+               case radiusCovalent:
+                       botype = "radiusCovalent";
+                       break;
+               case radiusVDW:
+                       botype = "radiusVDW";
+                       break;
+       }
+       
+       botype = botype.prepend( "bo:" );
+       
+       return botype;
+}
        
index b862bf4980fea7baa58f3cd2142c84b549bd582c..ec1a564cedbb8a06207dfcc7af0e6ff04294f070 100644 (file)
@@ -144,6 +144,12 @@ class ChemicalDataObject
                 */
                bool operator== ( const QString& v);
 
+               /**
+                * @return the dictRef-attribut of the xml. This is an
+                * identifier. For example, for the mass it is 'bo:mass'
+                */
+               QString dictRef();
+               
        private:
                QVariant m_value;
                BlueObelisk m_type;
index 2580f2b9750671b3b138694ccf4bf9f434829ae1..f080f769150cbab02809a93f00916adcab36b8dd 100644 (file)
@@ -21,13 +21,17 @@ email                : cniehaus@kde.org
 #include <kdebug.h>
 
 ElementSaxParser::ElementSaxParser()
-: QXmlDefaultHandler(), currentElement_(0), 
-       inElement_(false), 
-       inName_(false), 
-       inMass_( false ),
-       inExactMass_( false ),
-       inAtomicNumber_(false), 
-       inSymbol_( false )
+       : QXmlDefaultHandler(), currentElement_(0), 
+       inName_(false),
+       inMass_(false),
+       inExactMass_(false),
+       inAtomicNumber_(false),
+       inSymbol_(false),
+       inIonization_(false),
+       inElectronAffinity_(false),
+       inElectronegativityPauling_(false),
+       inRadiusCovalent_(false),
+       inRadiusVDW_(false)
 {
 }
 
@@ -39,16 +43,26 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co
        } else if (inElement_ && localName == "scalar") {
                for (int i = 0; i < attrs.length(); ++i) {
 
-                       if (attrs.value(i) == "bo:name")
-                               inName_ = true;
-                       if (attrs.value(i) == "bo:exactMass")
-                               inExactMass_ = true;
-                       if (attrs.value(i) == "bo:mass")
-                               inMass_ = true;
                        if (attrs.value(i) == "bo:atomicNumber")
                                inAtomicNumber_ = true;
-                       if (attrs.value(i) == "bo:symbol")
+                       else if (attrs.value(i) == "bo:symbol")
                                inSymbol_ = true;
+                       else if (attrs.value(i) == "bo:name")
+                               inName_ = true;
+                       else if (attrs.value(i) == "bo:mass")
+                               inMass_ = true;
+                       else if (attrs.value(i) == "bo:exactMass")
+                               inExactMass_ = true;
+                       else if (attrs.value(i) == "bo:ionization")
+                               inIonization_ = true;
+                       else if (attrs.value(i) == "bo:electronAffinity")
+                               inElectronAffinity_ = true;
+                       else if (attrs.value(i) == "bo:electronegativityPauling")
+                               inElectronegativityPauling_ = true;
+                       else if (attrs.value(i) == "bo:radiusCovalent")
+                               inRadiusCovalent_ = true;
+                       else if (attrs.value(i) == "bo:radiusVDW")
+                               inRadiusVDW_ = true;
                }
        }
        return true;
@@ -59,8 +73,7 @@ bool ElementSaxParser::endElement (  const QString & namespaceURI, const QString
        if ( localName == "elementType" )
        {
                elements_.append(currentElement_);
-//X            if ( currentElement_ )
-//X                    kdDebug() << "Number of ChemicalDataObject: " << currentElement_->dataList.count() << endl;
+               
                currentElement_ = 0;
                inElement_ = false;
        }
@@ -98,12 +111,37 @@ bool ElementSaxParser::characters(const QString &ch)
                type = ChemicalDataObject::atomicNumber; 
                inAtomicNumber_ = false;
        }
+       else if (inIonization_) {
+               value = ch.toDouble();;
+               type = ChemicalDataObject::ionization; 
+               inIonization_ = false;
+       }
+       else if (inElectronAffinity_) {
+               value = ch.toDouble();
+               type = ChemicalDataObject::electronAffinity; 
+               inElectronAffinity_ = false;
+       }
+       else if (inElectronegativityPauling_) {
+               value = ch.toDouble();
+               type = ChemicalDataObject::electronegativityPauling; 
+               inElectronegativityPauling_ = false;
+       }
+       else if (inRadiusCovalent_) {
+               value = ch.toDouble();
+               type = ChemicalDataObject::radiusCovalent; 
+               inRadiusCovalent_ = false;
+       }
+       else if (inRadiusVDW_) {
+               value = ch.toDouble();
+               type = ChemicalDataObject::radiusVDW; 
+               inRadiusVDW_ = false;
+       }
+       else//it is a non known value. Do not create a wrong object but return
+               return true;
 
        dataobject->setData( value );
        dataobject->setType( type );
 
-//X    kdDebug() << dataobject->valueAsString() << endl;
-
        if ( currentElement_ )
                currentElement_->addData( dataobject );
 
index 27561ee1881e3c3114c41d591c44bbd943ca16dc..1acc4ccf733e5f9eaf0d09e8d1a483096539f275 100644 (file)
@@ -39,6 +39,11 @@ class ElementSaxParser : public QXmlDefaultHandler
                         inMass_,
                         inExactMass_,
                         inAtomicNumber_,
-                        inSymbol_;
+                        inSymbol_,
+                        inIonization_,
+                        inElectronAffinity_,
+                        inElectronegativityPauling_,
+                        inRadiusCovalent_,
+                        inRadiusVDW_;
 };
 #endif // ELEMENTPARSER_H
index ada078f6586076e51568b93ca0940e0d3b9165e6..c72e79f7b5091a371f1f38830c89531f78a3656d 100644 (file)
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
                        //Test: give me all data available
 //X                    foreach( ChemicalDataObject*o, list ){
 //X                            if ( o )
-//X                                    kdDebug() << o->valueAsString() << endl;
+//X                                    kdDebug() << "Name: " << o->dictRef() << " " << o->valueAsString() << endl;
 //X                    }
                }