From d62a54e2439f596a1254fcbab6f0cecfba1e7268 Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Mon, 24 Oct 2005 13:00:05 +0000 Subject: [PATCH] * The isotopeparser is now parsing the more important info, several steps still missing though * added a testapplication to test the parser svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473677 --- libscience/isotope.cpp | 4 +-- libscience/isotope.h | 2 +- libscience/isotopeparser.cpp | 13 +++++++++ libscience/isotopeparser.h | 2 ++ libscience/tests/Makefile.am | 5 +++- libscience/tests/isotopereadingtest.cpp | 36 +++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 libscience/tests/isotopereadingtest.cpp diff --git a/libscience/isotope.cpp b/libscience/isotope.cpp index 34d1b56..b55b54c 100644 --- a/libscience/isotope.cpp +++ b/libscience/isotope.cpp @@ -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 diff --git a/libscience/isotope.h b/libscience/isotope.h index a8cd963..07a7e1a 100644 --- a/libscience/isotope.h +++ b/libscience/isotope.h @@ -40,7 +40,7 @@ class Isotope double mass() const; - double errorMargin() const; + QString errorMargin() const; int parentElementNumber() const; diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp index ab23acd..0aae9d3 100644 --- a/libscience/isotopeparser.cpp +++ b/libscience/isotopeparser.cpp @@ -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; } diff --git a/libscience/isotopeparser.h b/libscience/isotopeparser.h index c34b509..d34d022 100644 --- a/libscience/isotopeparser.h +++ b/libscience/isotopeparser.h @@ -42,6 +42,8 @@ class IsotopeParser : public QXmlDefaultHandler private: ChemicalDataObject *currentDataObject_; ChemicalDataObject::BlueObeliskUnit currentUnit_; + + QVariant currentErrorValue_; Isotope* currentIsotope_; QList isotopes_; diff --git a/libscience/tests/Makefile.am b/libscience/tests/Makefile.am index 2dba645..a4d9ac3 100644 --- a/libscience/tests/Makefile.am +++ b/libscience/tests/Makefile.am @@ -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 index 0000000..8549860 --- /dev/null +++ b/libscience/tests/isotopereadingtest.cpp @@ -0,0 +1,36 @@ +/* Sample parsing with QT's SAX2 by Riku Leino */ + +#include "../isotopeparser.h" +#include "../isotope.h" +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc < 2 || argc > 2) { + std::cout << "Usage: elements \n"; + return 1; + } + + IsotopeParser * parser = new IsotopeParser(); + QFile xmlFile(argv[1]); + QXmlInputSource source(xmlFile); + QXmlSimpleReader reader; + + reader.setContentHandler(parser); + reader.parse(source); + + QList 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; +} -- 2.47.3