]> Git trees. - libqmvoc.git/commitdiff
second stop, more close to the cml-syntax
authorCarsten Niehaus <cniehaus@gmx.de>
Mon, 31 Oct 2005 12:43:07 +0000 (12:43 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Mon, 31 Oct 2005 12:43:07 +0000 (12:43 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=476063

libscience/spectrumparser.cpp
libscience/spectrumparser.h
libscience/tests/Makefile.am
libscience/tests/cmlspectest.cpp [new file with mode: 0644]

index 4128609c5d1c1d1a2f20d956409c1d0c9faa9f44..2dd5df00631b1f73271681fd42aa471305dba601 100644 (file)
@@ -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;
index 8f6b39f6cdb2e3f23a17541c24c57035c9e3d985..ecee3f6097380e9c8cfb95c96796cf5b590f9a4a 100644 (file)
@@ -16,6 +16,8 @@
 #include <QFile>
 #include <qxml.h>
 
+#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<Spectrum*> spectra_;
+
+               bool inMetadata_;
+               
                bool inSpectrum_;
-               bool inAtomicNumber_,
-                        inExactMass_;
+               bool inSpectrumList_;
 
-               bool inAbundance_;
+               bool inPeakList_;
+               bool inPeak_;
+               
+               bool inXValue_;
+               bool inYValue_;
 };
 #endif // SPECTRUMPARSER_H
 
index a4d9ac33979905093df1d038721ca62a02dc1a89..41849be7986136af160489c0ec1cbaea90cb5d69 100644 (file)
@@ -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 (file)
index 0000000..9374002
--- /dev/null
@@ -0,0 +1,28 @@
+#include "../spectrumparser.h"
+#include "../spectrum.h"
+#include <kdebug.h>
+#include <iostream>
+
+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<Isotope*> 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;
+}