]> Git trees. - libqmvoc.git/commitdiff
* The isotopeparser is now parsing the more important info, several steps still ...
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 24 Oct 2005 13:00:05 +0000 (13:00 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 24 Oct 2005 13:00:05 +0000 (13:00 +0000)
* added a testapplication to test the parser

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

libscience/isotope.cpp
libscience/isotope.h
libscience/isotopeparser.cpp
libscience/isotopeparser.h
libscience/tests/Makefile.am
libscience/tests/isotopereadingtest.cpp [new file with mode: 0644]

index 34d1b5689d692a955b4015ddd97cfb8dee9864a6..b55b54c3ba6fd7a61b019c3a8c7a72fe000cb980 100644 (file)
@@ -58,9 +58,9 @@ double Isotope::mass() const
        return m_mass->value().toDouble();
 }
 
-double Isotope::errorMargin() const
+QString Isotope::errorMargin() const
 {
-       return m_mass->errorValue().toDouble();
+       return m_mass->errorValue().toString();
 }
 
 int Isotope::parentElementNumber() const
index a8cd963dcbed0c68956efaeba305142a0130e007..07a7e1a34915485f0b4dfb01a5b6838254fc20ba 100644 (file)
@@ -40,7 +40,7 @@ class Isotope
 
                double mass() const;
 
-               double errorMargin() const;
+               QString errorMargin() const;
 
                int parentElementNumber() const;
 
index ab23acde1699311c60d8a5084c1c6294da3f2a41..0aae9d36af2d527c3a72db5acc98a39c9528d4ae 100644 (file)
@@ -38,6 +38,13 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const
        {
                for (int i = 0; i < attrs.length(); ++i) 
                {
+
+                       if ( attrs.localName( i ) == "errorValue" )
+                       {
+                               currentErrorValue_ = QVariant( attrs.value( i ) );
+                               continue;
+                       }
+                       
                        if (attrs.value(i) == "bo:atomicNumber")
                                inAtomicNumber_ = true;
                        else if (attrs.value(i) == "bo:exactMass")
@@ -57,6 +64,12 @@ bool IsotopeParser::endElement (  const QString & namespaceURI, const QString &
                currentDataObject_ = 0;
                inIsotope_ = false;
        }
+       else if ( localName == "scalar" )
+       {
+               if ( currentDataObject_->type() == ChemicalDataObject::exactMass ){
+                       currentDataObject_->setErrorValue( currentErrorValue_ );
+               }
+       }
 
        return true;
 }
index c34b509c49819398b81ec16044c037ae48056c17..d34d0229569aa2b661eb275b54854b80700194fa 100644 (file)
@@ -42,6 +42,8 @@ class IsotopeParser : public QXmlDefaultHandler
        private:
                ChemicalDataObject *currentDataObject_;
                ChemicalDataObject::BlueObeliskUnit currentUnit_;
+
+               QVariant currentErrorValue_;
                
                Isotope* currentIsotope_;
                QList<Isotope*> isotopes_;
index 2dba645cf89f52bed6d4bd1a3d03dfe54dfb3d50..a4d9ac33979905093df1d038721ca62a02dc1a89 100644 (file)
@@ -2,10 +2,13 @@ INCLUDES = -I$(top_srcdir)/libkdeedu/libscience $(all_includes)
 
 AM_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) $(KDE_RPATH)
 
-check_PROGRAMS = xmlreadingtest
+check_PROGRAMS = xmlreadingtest isotopereadingtest
 
 xmlreadingtest_SOURCES = xmlreadingtest.cpp
 xmlreadingtest_LDFLAGS = $(all_libraries)
 xmlreadingtest_LDADD = ../libscience.la
 
+isotopereadingtest_SOURCES = isotopereadingtest.cpp
+isotopereadingtest_LDFLAGS = $(all_libraries)
+isotopereadingtest_LDADD = ../libscience.la
 METASOURCES = AUTO
diff --git a/libscience/tests/isotopereadingtest.cpp b/libscience/tests/isotopereadingtest.cpp
new file mode 100644 (file)
index 0000000..8549860
--- /dev/null
@@ -0,0 +1,36 @@
+/* Sample parsing with QT's SAX2 by Riku Leino <tsoots@gmail.com> */
+
+#include "../isotopeparser.h"
+#include "../isotope.h"
+#include <kdebug.h>
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+       if (argc < 2 || argc > 2) {
+               std::cout << "Usage: elements <XML_FILE>\n";
+               return 1;
+       }
+
+       IsotopeParser * parser = new IsotopeParser();
+       QFile xmlFile(argv[1]);
+       QXmlInputSource source(xmlFile);
+       QXmlSimpleReader reader;
+
+       reader.setContentHandler(parser);
+       reader.parse(source);
+
+       QList<Isotope*> v = parser->getIsotopes();
+
+       foreach( Isotope* e, v ){
+               if ( e )
+               {
+                       ChemicalDataObject* o = e->data();
+                       kdDebug() << "Name: " << o->dictRef() << " " << o->valueAsString()  << " errorMargin: " << e->errorMargin() << " parent Element: " << e->parentElementSymbol() << endl;
+                       
+               }
+
+       }
+
+       return 0;
+}