isotope.cpp \
spectrumparser.cpp \
elementparser.cpp \
+ isotopeparser.cpp \
tempunit.cpp \
chemicaldataobject.cpp
***************************************************************************/
#include "element.h"
-#include "spectrum.h"
-#include "isotope.h"
#include "tempunit.h"
#include "chemicaldataobject.h"
Isotope::~Isotope(){}
+
+ChemicalDataObject* Isotope::data() const
+{
+ return m_mass;
+}
+
+void Isotope::addData( ChemicalDataObject* o )
+{
+ if ( o->type() == ChemicalDataObject::exactMass )
+ m_mass = o;
+ else if ( o->type() == ChemicalDataObject::atomicNumber )
+ m_identifier = o;
+
+ return;
+}
+
+double Isotope::mass() const
+{
+ return m_mass->value().toDouble();
+}
+
+double Isotope::errorMargin() const
+{
+ return m_mass->errorValue().toDouble();
+}
+
+int Isotope::parentElementNumber() const
+{
+ return m_identifier->value().toInt();
+}
+
+QString Isotope::parentElementSymbol() const
+{
+ return m_parentElementSymbol;
+}
Isotope(ChemicalDataObject* mass, ChemicalDataObject* ID);
virtual ~Isotope();
+ ChemicalDataObject* data() const;
+
+ double mass() const;
+
+ double errorMargin() const;
+
+ int parentElementNumber() const;
+
+ QString parentElementSymbol() const;
+
+ void addData( ChemicalDataObject* o );
+
private:
/**
* the symbol of the element the isotope belongs to
*/
QString m_parentElementSymbol;
+ /**
+ * stores the infomation about the mass of the Isotope
+ */
ChemicalDataObject* m_mass;
+
+ /**
+ * stores the atomicNumber of the Isotope
+ */
ChemicalDataObject* m_identifier;
};
--- /dev/null
+/***************************************************************************
+copyright : (C) 2005 by Carsten Niehaus
+email : cniehaus@kde.org
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include "isotopeparser.h"
+#include "isotope.h"
+
+#include <qdom.h>
+#include <QList>
+#include <QFile>
+#include <QStringList>
+
+#include <kdebug.h>
+
+IsotopeParser::IsotopeParser()
+ : QXmlDefaultHandler(),
+ currentIsotope_(0),
+ inAtomicNumber_(false),
+ inExactMass_(false)
+{
+}
+
+bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
+{
+ if (localName == "isotope")
+ {
+ currentIsotope_ = new Isotope();
+ inIsotope_ = true;
+ } else if (inIsotope_ && localName == "scalar")
+ {
+ for (int i = 0; i < attrs.length(); ++i)
+ {
+ if (attrs.value(i) == "bo:atomicNumber")
+ inAtomicNumber_ = true;
+ else if (attrs.value(i) == "bo:exactMass")
+ inExactMass_ = true;
+ }
+ }
+ return true;
+}
+
+bool IsotopeParser::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName )
+{
+ if ( localName == "isotope" )
+ {
+ isotopes_.append(currentIsotope_);
+
+ currentIsotope_ = 0;
+ currentDataObject_ = 0;
+ inIsotope_ = false;
+ }
+
+ return true;
+}
+
+bool IsotopeParser::characters(const QString &ch)
+{
+ currentDataObject_ = new ChemicalDataObject();
+ ChemicalDataObject::BlueObelisk type;
+ QVariant value;
+
+ if ( inExactMass_ ){
+ value = ch.toDouble();
+ type = ChemicalDataObject::exactMass;
+ inExactMass_ = false;
+ }
+ else if (inAtomicNumber_) {
+ value = ch.toInt();
+ type = ChemicalDataObject::atomicNumber;
+ inAtomicNumber_ = false;
+ }
+ else//it is a non known value. Do not create a wrong object but return
+ return true;
+
+ currentDataObject_->setData( value );
+ currentDataObject_->setType( type );
+
+ if ( currentIsotope_ )
+ currentIsotope_->addData( currentDataObject_ );
+
+ return true;
+}
+
+QList<Isotope*> IsotopeParser::getIsotopes()
+{
+ return isotopes_;
+}
--- /dev/null
+#ifndef ISOTOPEPARSER_H
+#define ISOTOPEPARSER_H
+/***************************************************************************
+ copyright : (C) 2005 by Carsten Niehaus
+ email : cniehaus@kde.org
+ ***************************************************************************/
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <QList>
+
+#include <qxml.h>
+
+#include "chemicaldataobject.h"
+
+class Isotope;
+
+/**
+ * @author Carsten Niehaus <cniehaus@kde.org>
+ */
+class IsotopeParser : public QXmlDefaultHandler
+{
+ public:
+ /**
+ * Constructor
+ */
+ IsotopeParser();
+ bool startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs);
+
+ bool endElement ( const QString & namespaceURI, const QString & localName, const QString & qName );
+
+ bool characters(const QString &ch);
+
+ QList<Isotope*> getIsotopes();
+
+ private:
+ ChemicalDataObject *currentDataObject_;
+ ChemicalDataObject::BlueObeliskUnit currentUnit_;
+
+ Isotope* currentIsotope_;
+ QList<Isotope*> isotopes_;
+ bool inIsotope_;
+ bool inAtomicNumber_,
+ inExactMass_;
+};
+#endif // ISOTOPEPARSER_H
+