From 8c896ea2eebec91222f38ecc992c11093e7928f3 Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Sun, 23 Oct 2005 15:18:05 +0000 Subject: [PATCH] * Add real support for unit. Only for the units of BO, though svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=473388 --- libscience/chemicaldataobject.cpp | 6 ++++ libscience/chemicaldataobject.h | 19 +++++++++---- libscience/elementparser.cpp | 46 ++++++++++++++++++++++++++----- libscience/elementparser.h | 18 ++++++++++++ 4 files changed, 76 insertions(+), 13 deletions(-) diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp index 56d0239..20c62bc 100644 --- a/libscience/chemicaldataobject.cpp +++ b/libscience/chemicaldataobject.cpp @@ -127,6 +127,12 @@ QString ChemicalDataObject::dictRef() case orbit: botype = "orbit"; break; + case date: + botype = "date"; + break; + case discoverer: + botype = "discoverer"; + break; case period: botype = "period"; break; diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h index cb606fa..02eb03f 100644 --- a/libscience/chemicaldataobject.h +++ b/libscience/chemicaldataobject.h @@ -52,12 +52,14 @@ class ChemicalDataObject electronegativityPauling/**< the electronegativity in the definition of Pauling*/, radiusCovalent/**< the covalent radius */, radiusVDW/**< the van der Waals radius */, - meltingpoint, - boilingpoint, - periodTableBlock, - nameOrigin, - orbit, - period + meltingpoint/**< the meltingpoint */, + boilingpoint/**< the boilingpoint */, + periodTableBlock/**< the block of the element */, + nameOrigin/**< the origin of the name */, + orbit/**< the quantumorbit of the element */, + period/**< the period of the element */, + date/**< date of discovery of the element. When 0, the element has been known in ancient times. */, + discoverer/** The name of the discoverer(s) */ }; /** @@ -88,6 +90,7 @@ class ChemicalDataObject /** * Set the data of this object to @p v + * @param v the value of the object */ void setData( QVariant v ){ m_value = v; @@ -182,6 +185,10 @@ class ChemicalDataObject return m_unit; } + /** + * set the unit of this object to @p unit + * @param the BlueObeliskUnit of this object + */ void setUnit( BlueObeliskUnit unit ){ m_unit = unit; } diff --git a/libscience/elementparser.cpp b/libscience/elementparser.cpp index a4a3c8a..89a4f4a 100644 --- a/libscience/elementparser.cpp +++ b/libscience/elementparser.cpp @@ -42,11 +42,19 @@ ElementSaxParser::ElementSaxParser() bool ElementSaxParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) { - if (localName == "elementType") { + if (localName == "elementType") + { currentElement_ = new Element(); inElement_ = true; - } else if (inElement_ && localName == "scalar") { - for (int i = 0; i < attrs.length(); ++i) { + } else if (inElement_ && localName == "scalar") + { + for (int i = 0; i < attrs.length(); ++i) + { + if ( attrs.localName( i ) == "unit" ) + { + currentUnit_ = unit( attrs.value( i ) ); + continue; + } if (attrs.value(i) == "bo:atomicNumber") inAtomicNumber_ = true; @@ -91,14 +99,22 @@ bool ElementSaxParser::endElement ( const QString & namespaceURI, const QString elements_.append(currentElement_); currentElement_ = 0; + currentDataObject_ = 0; inElement_ = false; } + else if ( localName == "scalar" ) + { + if ( currentUnit_ != ChemicalDataObject::noUnit ) + currentDataObject_->setUnit( currentUnit_ ); + + currentUnit_ = ChemicalDataObject::noUnit; + } return true; } bool ElementSaxParser::characters(const QString &ch) { - ChemicalDataObject *dataobject = new ChemicalDataObject(); + currentDataObject_ = new ChemicalDataObject(); ChemicalDataObject::BlueObelisk type; QVariant value; @@ -180,11 +196,11 @@ bool ElementSaxParser::characters(const QString &ch) else//it is a non known value. Do not create a wrong object but return return true; - dataobject->setData( value ); - dataobject->setType( type ); + currentDataObject_->setData( value ); + currentDataObject_->setType( type ); if ( currentElement_ ) - currentElement_->addData( dataobject ); + currentElement_->addData( currentDataObject_ ); return true; } @@ -193,3 +209,19 @@ QList ElementSaxParser::getElements() { return elements_; } + +ChemicalDataObject::BlueObeliskUnit ElementSaxParser::unit( const QString& unit ) +{ + if ( unit == "bo:kelvin" ) + return ChemicalDataObject::kelvin; + else if ( unit == "bo:ev" ) + return ChemicalDataObject::ev; + else if ( unit == "bo:nm" ) + return ChemicalDataObject::nm; + else if ( unit == "bo:pm" ) + return ChemicalDataObject::pm; + else if ( unit == "bo:noUnit" ) + return ChemicalDataObject::noUnit; + else + return ChemicalDataObject::noUnit; +} diff --git a/libscience/elementparser.h b/libscience/elementparser.h index 58ed4e2..f815ac9 100644 --- a/libscience/elementparser.h +++ b/libscience/elementparser.h @@ -17,11 +17,20 @@ #include +#include "chemicaldataobject.h" + class Element; + +/** + * @author Carsten Niehaus + */ class ElementSaxParser : public QXmlDefaultHandler { public: + /** + * Constructor + */ ElementSaxParser(); bool startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs); @@ -32,6 +41,15 @@ class ElementSaxParser : public QXmlDefaultHandler QList getElements(); private: + ChemicalDataObject *currentDataObject_; + ChemicalDataObject::BlueObeliskUnit currentUnit_; + + /** + * @return the BlueObeliskUnit of a ChemicalDataObject corresponding to @p text + * @param text the attribute-text of the XML parsed + */ + ChemicalDataObject::BlueObeliskUnit unit( const QString& text ); + Element *currentElement_; QList elements_; bool inElement_; -- 2.47.3