From 139df4f6c69e6720aca07bfc91558477f2caf41c Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Mon, 24 Oct 2005 13:14:21 +0000 Subject: [PATCH] Add support for the elementsymbol svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473682 --- libscience/isotope.cpp | 5 +++++ libscience/isotope.h | 2 ++ libscience/isotopeparser.cpp | 9 +++++++++ libscience/isotopeparser.h | 2 ++ 4 files changed, 18 insertions(+) diff --git a/libscience/isotope.cpp b/libscience/isotope.cpp index b55b54c..8c3badf 100644 --- a/libscience/isotope.cpp +++ b/libscience/isotope.cpp @@ -72,3 +72,8 @@ QString Isotope::parentElementSymbol() const { return m_parentElementSymbol; } + +void Isotope::setParentSymbol( const QString& symbol ) +{ + m_parentElementSymbol = symbol; +} diff --git a/libscience/isotope.h b/libscience/isotope.h index 07a7e1a..6396bc7 100644 --- a/libscience/isotope.h +++ b/libscience/isotope.h @@ -48,6 +48,8 @@ class Isotope void addData( ChemicalDataObject* o ); + void setParentSymbol( const QString& symbol ); + private: /** * the symbol of the element the isotope belongs to diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp index 0aae9d3..50a25e6 100644 --- a/libscience/isotopeparser.cpp +++ b/libscience/isotopeparser.cpp @@ -26,6 +26,7 @@ IsotopeParser::IsotopeParser() inAtomicNumber_(false), inExactMass_(false) { + currentElementSymbol_ = ""; } bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) @@ -34,6 +35,13 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const { currentIsotope_ = new Isotope(); inIsotope_ = 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 (inIsotope_ && localName == "scalar") { for (int i = 0; i < attrs.length(); ++i) @@ -58,6 +66,7 @@ bool IsotopeParser::endElement ( const QString & namespaceURI, const QString & { if ( localName == "isotope" ) { + currentIsotope_->setParentSymbol( currentElementSymbol_ ); isotopes_.append(currentIsotope_); currentIsotope_ = 0; diff --git a/libscience/isotopeparser.h b/libscience/isotopeparser.h index d34d022..f2c58b6 100644 --- a/libscience/isotopeparser.h +++ b/libscience/isotopeparser.h @@ -44,6 +44,8 @@ class IsotopeParser : public QXmlDefaultHandler ChemicalDataObject::BlueObeliskUnit currentUnit_; QVariant currentErrorValue_; + + QString currentElementSymbol_; Isotope* currentIsotope_; QList isotopes_; -- 2.47.3