From 26c444de14d71b0694e36def1688084ae4517e9a Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Thu, 20 Oct 2005 12:49:34 +0000 Subject: [PATCH] * Add the missing datasets * Fix a bug: Only create an object when needed svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=472317 --- libscience/chemicaldataobject.cpp | 41 ++++++++++++++++ libscience/chemicaldataobject.h | 6 +++ libscience/elementparser.cpp | 74 ++++++++++++++++++++++------- libscience/elementparser.h | 7 ++- libscience/tests/xmlreadingtest.cpp | 2 +- 5 files changed, 110 insertions(+), 20 deletions(-) diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp index d47004d..6a18949 100644 --- a/libscience/chemicaldataobject.cpp +++ b/libscience/chemicaldataobject.cpp @@ -74,4 +74,45 @@ bool ChemicalDataObject::operator==( const QString& v ) ChemicalDataObject::~ChemicalDataObject() {} + +QString ChemicalDataObject::dictRef() +{ + QString botype; + switch ( m_type ){ + case atomicNumber: + botype = "atomicNumber"; + break; + case symbol: + botype = "symbol"; + break; + case name: + botype = "name"; + break; + case mass: + botype = "mass"; + break; + case exactMass: + botype = "exactMass"; + break; + case ionization: + botype = "ionization"; + break; + case electronAffinity: + botype = "electronAffinity"; + break; + case electronegativityPauling: + botype = "electronegativityPauling"; + break; + case radiusCovalent: + botype = "radiusCovalent"; + break; + case radiusVDW: + botype = "radiusVDW"; + break; + } + + botype = botype.prepend( "bo:" ); + + return botype; +} diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h index b862bf4..ec1a564 100644 --- a/libscience/chemicaldataobject.h +++ b/libscience/chemicaldataobject.h @@ -144,6 +144,12 @@ class ChemicalDataObject */ bool operator== ( const QString& v); + /** + * @return the dictRef-attribut of the xml. This is an + * identifier. For example, for the mass it is 'bo:mass' + */ + QString dictRef(); + private: QVariant m_value; BlueObelisk m_type; diff --git a/libscience/elementparser.cpp b/libscience/elementparser.cpp index 2580f2b..f080f76 100644 --- a/libscience/elementparser.cpp +++ b/libscience/elementparser.cpp @@ -21,13 +21,17 @@ email : cniehaus@kde.org #include ElementSaxParser::ElementSaxParser() -: QXmlDefaultHandler(), currentElement_(0), - inElement_(false), - inName_(false), - inMass_( false ), - inExactMass_( false ), - inAtomicNumber_(false), - inSymbol_( false ) + : QXmlDefaultHandler(), currentElement_(0), + inName_(false), + inMass_(false), + inExactMass_(false), + inAtomicNumber_(false), + inSymbol_(false), + inIonization_(false), + inElectronAffinity_(false), + inElectronegativityPauling_(false), + inRadiusCovalent_(false), + inRadiusVDW_(false) { } @@ -39,16 +43,26 @@ bool ElementSaxParser::startElement(const QString&, const QString &localName, co } else if (inElement_ && localName == "scalar") { for (int i = 0; i < attrs.length(); ++i) { - if (attrs.value(i) == "bo:name") - inName_ = true; - if (attrs.value(i) == "bo:exactMass") - inExactMass_ = true; - if (attrs.value(i) == "bo:mass") - inMass_ = true; if (attrs.value(i) == "bo:atomicNumber") inAtomicNumber_ = true; - if (attrs.value(i) == "bo:symbol") + else if (attrs.value(i) == "bo:symbol") inSymbol_ = true; + else if (attrs.value(i) == "bo:name") + inName_ = true; + else if (attrs.value(i) == "bo:mass") + inMass_ = true; + else if (attrs.value(i) == "bo:exactMass") + inExactMass_ = true; + else if (attrs.value(i) == "bo:ionization") + inIonization_ = true; + else if (attrs.value(i) == "bo:electronAffinity") + inElectronAffinity_ = true; + else if (attrs.value(i) == "bo:electronegativityPauling") + inElectronegativityPauling_ = true; + else if (attrs.value(i) == "bo:radiusCovalent") + inRadiusCovalent_ = true; + else if (attrs.value(i) == "bo:radiusVDW") + inRadiusVDW_ = true; } } return true; @@ -59,8 +73,7 @@ bool ElementSaxParser::endElement ( const QString & namespaceURI, const QString if ( localName == "elementType" ) { elements_.append(currentElement_); -//X if ( currentElement_ ) -//X kdDebug() << "Number of ChemicalDataObject: " << currentElement_->dataList.count() << endl; + currentElement_ = 0; inElement_ = false; } @@ -98,12 +111,37 @@ bool ElementSaxParser::characters(const QString &ch) type = ChemicalDataObject::atomicNumber; inAtomicNumber_ = false; } + else if (inIonization_) { + value = ch.toDouble();; + type = ChemicalDataObject::ionization; + inIonization_ = false; + } + else if (inElectronAffinity_) { + value = ch.toDouble(); + type = ChemicalDataObject::electronAffinity; + inElectronAffinity_ = false; + } + else if (inElectronegativityPauling_) { + value = ch.toDouble(); + type = ChemicalDataObject::electronegativityPauling; + inElectronegativityPauling_ = false; + } + else if (inRadiusCovalent_) { + value = ch.toDouble(); + type = ChemicalDataObject::radiusCovalent; + inRadiusCovalent_ = false; + } + else if (inRadiusVDW_) { + value = ch.toDouble(); + type = ChemicalDataObject::radiusVDW; + inRadiusVDW_ = false; + } + else//it is a non known value. Do not create a wrong object but return + return true; dataobject->setData( value ); dataobject->setType( type ); -//X kdDebug() << dataobject->valueAsString() << endl; - if ( currentElement_ ) currentElement_->addData( dataobject ); diff --git a/libscience/elementparser.h b/libscience/elementparser.h index 27561ee..1acc4cc 100644 --- a/libscience/elementparser.h +++ b/libscience/elementparser.h @@ -39,6 +39,11 @@ class ElementSaxParser : public QXmlDefaultHandler inMass_, inExactMass_, inAtomicNumber_, - inSymbol_; + inSymbol_, + inIonization_, + inElectronAffinity_, + inElectronegativityPauling_, + inRadiusCovalent_, + inRadiusVDW_; }; #endif // ELEMENTPARSER_H diff --git a/libscience/tests/xmlreadingtest.cpp b/libscience/tests/xmlreadingtest.cpp index ada078f..c72e79f 100644 --- a/libscience/tests/xmlreadingtest.cpp +++ b/libscience/tests/xmlreadingtest.cpp @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) //Test: give me all data available //X foreach( ChemicalDataObject*o, list ){ //X if ( o ) -//X kdDebug() << o->valueAsString() << endl; +//X kdDebug() << "Name: " << o->dictRef() << " " << o->valueAsString() << endl; //X } } -- 2.47.3