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;
}
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;
#include <QFile>
#include <qxml.h>
+#include "spectrum.h"
+
#include "chemicaldataobject.h"
class Spectrum;
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
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)
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
--- /dev/null
+#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;
+}