From: Carsten Niehaus Date: Mon, 31 Oct 2005 12:43:07 +0000 (+0000) Subject: second stop, more close to the cml-syntax X-Git-Tag: v3.80.2~238 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=37d75de97e31f13dace7d735714b9957c4e13406;p=libqmvoc.git second stop, more close to the cml-syntax svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=476063 --- diff --git a/libscience/spectrumparser.cpp b/libscience/spectrumparser.cpp index 4128609..2dd5df0 100644 --- a/libscience/spectrumparser.cpp +++ b/libscience/spectrumparser.cpp @@ -23,44 +23,34 @@ email : cniehaus@kde.org SpectrumParser::SpectrumParser() : QXmlDefaultHandler(), currentSpectrum_(0), - inAtomicNumber_(false), - inExactMass_(false), - inAbundance_(false) + currentPeak_( 0 ) { - currentElementSymbol_ = ""; } bool SpectrumParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) { - if (localName == "isotope") + if (localName == "spectrum") { currentSpectrum_ = new Spectrum(); inSpectrum_ = true; - //now save the symbol of the current element - for (int i = 0; i < attrs.length(); ++i) - { - if ( attrs.localName( i ) == "elementType" ) - currentElementSymbol_ = attrs.value( i ); - } - } else if (inSpectrum_ && localName == "scalar") - { +//X //now save the element of the current spectrum +//X for (int i = 0; i < attrs.length(); ++i) +//X { +//X if ( attrs.localName( i ) == "elementType" ) +//X currentElementSymbol_ = attrs.value( i ); +//X } + } else if (inSpectrum_ && localName == "peakList") { + inPeakList_ = true; + } + else if (inSpectrum_ && inPeakList_ && localName == "peak") { 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; + if (attrs.value(i) == "xValue") + inXValue_ = true; else if (attrs.value(i) == "bo:exactMass") - inExactMass_ = true; + inYValue_ = true; } - } else if (inSpectrum_ && localName == "bo:relativeAbundance") { - kdDebug() << "bo:relativeAbundance" << endl; - inAbundance_ = true; } return true; } @@ -92,20 +82,15 @@ bool SpectrumParser::characters(const QString &ch) ChemicalDataObject::BlueObelisk type; QVariant value; - if ( inExactMass_ ){ + if ( inXValue_ ){ value = ch.toDouble(); type = ChemicalDataObject::exactMass; - inExactMass_ = false; + inXValue_ = false; } - else if (inAtomicNumber_) { + else if (inYValue_) { value = ch.toInt(); type = ChemicalDataObject::atomicNumber; - inAtomicNumber_ = false; - } - else if ( inAbundance_ ){ - value = ch; - type = ChemicalDataObject::relativeAbundance; - inAbundance_ = false; + inYValue_ = false; } else//it is a non known value. Do not create a wrong object but return return true; diff --git a/libscience/spectrumparser.h b/libscience/spectrumparser.h index 8f6b39f..ecee3f6 100644 --- a/libscience/spectrumparser.h +++ b/libscience/spectrumparser.h @@ -16,6 +16,8 @@ #include #include +#include "spectrum.h" + #include "chemicaldataobject.h" class Spectrum; @@ -44,15 +46,21 @@ class SpectrumParser : public QXmlDefaultHandler QVariant currentErrorValue_; - QString currentElementSymbol_; - Spectrum* currentSpectrum_; + Spectrum::peak* currentPeak_; + QList spectra_; + + bool inMetadata_; + bool inSpectrum_; - bool inAtomicNumber_, - inExactMass_; + bool inSpectrumList_; - bool inAbundance_; + bool inPeakList_; + bool inPeak_; + + bool inXValue_; + bool inYValue_; }; #endif // SPECTRUMPARSER_H diff --git a/libscience/tests/Makefile.am b/libscience/tests/Makefile.am index a4d9ac3..41849be 100644 --- a/libscience/tests/Makefile.am +++ b/libscience/tests/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/libkdeedu/libscience $(all_includes) AM_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS) $(KDE_RPATH) -check_PROGRAMS = xmlreadingtest isotopereadingtest +check_PROGRAMS = xmlreadingtest isotopereadingtest cmlspectest xmlreadingtest_SOURCES = xmlreadingtest.cpp xmlreadingtest_LDFLAGS = $(all_libraries) @@ -11,4 +11,8 @@ xmlreadingtest_LDADD = ../libscience.la isotopereadingtest_SOURCES = isotopereadingtest.cpp isotopereadingtest_LDFLAGS = $(all_libraries) isotopereadingtest_LDADD = ../libscience.la + +cmlspectest_SOURCES = cmlspectest.cpp +cmlspectest_LDFLAGS = $(all_libraries) +cmlspectest_LDADD = ../libscience.la METASOURCES = AUTO diff --git a/libscience/tests/cmlspectest.cpp b/libscience/tests/cmlspectest.cpp new file mode 100644 index 0000000..9374002 --- /dev/null +++ b/libscience/tests/cmlspectest.cpp @@ -0,0 +1,28 @@ +#include "../spectrumparser.h" +#include "../spectrum.h" +#include +#include + +int main(int argc, char *argv[]) +{ + SpectrumParser * parser = new SpectrumParser(); + QFile xmlFile("cmlspec_example.cml"); + QXmlInputSource source(xmlFile); + QXmlSimpleReader reader; + + reader.setContentHandler(parser); + reader.parse(source); + +//X QList v = parser->getIsotopes(); +//X +//X foreach( Isotope* e, v ){ +//X if ( e ) +//X { +//X ChemicalDataObject* o = e->data(); +//X kdDebug() << "Name: " << o->dictRef() << " " << o->valueAsString() << " errorMargin: " << e->errorMargin() << " parent Element: " << e->parentElementSymbol() << endl; +//X } +//X +//X } + + return 0; +}