From: Carsten Niehaus Date: Tue, 18 Oct 2005 12:10:49 +0000 (+0000) Subject: * Finish ChemicalDataObject X-Git-Tag: v3.80.2~290 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=d7c34041a709c0098f2ad4bc18cbcd78bc902d1f;p=libqmvoc.git * Finish ChemicalDataObject * tests adopted to it * svn:ignore svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=471676 --- diff --git a/libscience/Makefile.am b/libscience/Makefile.am index bd2a3d6..879fdd7 100644 --- a/libscience/Makefile.am +++ b/libscience/Makefile.am @@ -10,7 +10,8 @@ libscience_la_SOURCES = \ isotope.cpp \ spectrumparser.cpp \ elementparser.cpp \ - tempunit.cpp + tempunit.cpp \ + chemicaldataobject.cpp libscience_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 4:0:0 libscience_la_LIBADD = $(LIB_KDEUI) diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp new file mode 100644 index 0000000..96c2c4b --- /dev/null +++ b/libscience/chemicaldataobject.cpp @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2005 by Carsten Niehaus * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include "chemicaldataobject.h" + +ChemicalDataObject::ChemicalDataObject( QVariant v, BlueObelisk type ) +{ + m_value = v; + m_type = type; +}; + +ChemicalDataObject::ChemicalDataObject() +{ +} + +QString ChemicalDataObject::valueAsString() +{ + return m_value.toString(); +} diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h new file mode 100644 index 0000000..e5d3257 --- /dev/null +++ b/libscience/chemicaldataobject.h @@ -0,0 +1,132 @@ +#ifndef CHEMICALDATAOBJECT_H +#define CHEMICALDATAOBJECT_H +/*************************************************************************** + * Copyright (C) 2005 by Carsten Niehaus * + * 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. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include + +/** + * A ChemicalDataObject is an object which contains information about + * a chemical element. This can for example be a boilingpoint. The information + * is stored in a QVariant. + * This class supports the CML-format defined by the BlueObelisk-Project. + * + * @author Carsten Niehaus #include @@ -37,6 +38,22 @@ Element::Element() m_abundance = 0; } +QVariant Element::data(ChemicalDataObject::BlueObelisk type) +{ + foreach( ChemicalDataObject*o, dataList ) { + if ( o->type() == type ) + return o->value(); + } +} + +QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) +{ + foreach( ChemicalDataObject*o, dataList ) { + if ( o->type() == type ) + return o->valueAsString(); + } +} + Isotope* Element::isotopeByNucleons( int numberOfNucleons ) { QList::ConstIterator it = m_isotopeList.begin(); @@ -268,18 +285,3 @@ double Element::radius( RADIUSTYPE type ) return 0.0; } - -ChemicalDataObject::ChemicalDataObject( QVariant v, BlueObelisk type ) -{ - m_value = v; - m_type = type; -}; - -ChemicalDataObject::ChemicalDataObject() -{ -} - -QString ChemicalDataObject::valueAsString() -{ - return m_value.toString(); -} diff --git a/libscience/element.h b/libscience/element.h index 0c88c40..cbe682b 100644 --- a/libscience/element.h +++ b/libscience/element.h @@ -24,16 +24,18 @@ #include #include -#include +#include "chemicaldataobject.h" -class Element; class QDomDocument; class QPainter; class QPoint; class QFont; class QRect; + class Spectrum; class Isotope; +class Element; +class ChemicalDataObject; struct coordinate; @@ -429,6 +431,16 @@ class Element{ return m_Color; } + QList dataList; + + void addData( ChemicalDataObject*o ){ + dataList.append( o ); + } + + QVariant data( ChemicalDataObject::BlueObelisk type ); + + QString dataAsString( ChemicalDataObject::BlueObelisk type ); + private: /** * the integer num represents the number of the element @@ -483,105 +495,4 @@ class Element{ doubleList m_ionenergies; }; -/** - * @author Carsten Niehaus dataList.count() << endl; currentElement_ = 0; inElement_ = false; } @@ -63,23 +69,44 @@ bool ElementSaxParser::endElement ( const QString & namespaceURI, const QString bool ElementSaxParser::characters(const QString &ch) { + ChemicalDataObject *dataobject = new ChemicalDataObject(); + ChemicalDataObject::BlueObelisk type; + QVariant value; + if (inName_) { - currentElement_->setName(ch); + value = ch; + type = ChemicalDataObject::name; inName_ = false; } - if ( inMass_ ){ - currentElement_->setMass( ch.toDouble() ); + else if ( inMass_ ){ + value = ch.toDouble(); + type = ChemicalDataObject::mass; inMass_ = false; } - if (inSymbol_) { - currentElement_->setSymbol(ch); + else if ( inExactMass_ ){ + value = ch.toDouble(); + type = ChemicalDataObject::exactMass; + inExactMass_ = false; + } + else if (inSymbol_) { + value = ch; + type = ChemicalDataObject::symbol; inSymbol_ = false; } - if (inAtomicNumber_) { - currentElement_->setNumber(ch.toInt()); + else if (inAtomicNumber_) { + value = ch.toInt(); + type = ChemicalDataObject::atomicNumber; inAtomicNumber_ = false; } + dataobject->setData( value ); + dataobject->setType( type ); + +//X kdDebug() << dataobject->valueAsString() << endl; + + if ( currentElement_ ) + currentElement_->addData( dataobject ); + return true; } diff --git a/libscience/elementparser.h b/libscience/elementparser.h index af1aa5b..27561ee 100644 --- a/libscience/elementparser.h +++ b/libscience/elementparser.h @@ -37,6 +37,7 @@ class ElementSaxParser : public QXmlDefaultHandler bool inElement_; bool inName_, inMass_, + inExactMass_, inAtomicNumber_, inSymbol_; }; diff --git a/libscience/tests/xmlreadingtest.cpp b/libscience/tests/xmlreadingtest.cpp index 0badd10..9aa3af0 100644 --- a/libscience/tests/xmlreadingtest.cpp +++ b/libscience/tests/xmlreadingtest.cpp @@ -16,6 +16,7 @@ int main(int argc, char *argv[]) QFile xmlFile(argv[1]); QXmlInputSource source(xmlFile); QXmlSimpleReader reader; + reader.setContentHandler(parser); reader.parse(source); @@ -23,10 +24,19 @@ int main(int argc, char *argv[]) foreach( Element* e, v ){ if ( e ) - kdDebug() << "(" << e->number() << ", " << - e->elementName() << ", " << e->symbol() << ") " << - ", mass: " << e->mass() << - endl; + { + QList list = e->dataList; + + //Give me the name of the element + kdDebug() << "Name: " << e->dataAsString( ChemicalDataObject::name ) << endl; + +//X //give me all you have +//X foreach( ChemicalDataObject*o, list ){ +//X if ( o ) +//X kdDebug() << o->valueAsString() << endl; +//X } + } + } return 0;