From 9a2be161ba820727df89e483259c3f80cffe8923 Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Tue, 18 Oct 2005 17:53:55 +0000 Subject: [PATCH] Commiting my new operators. I need some help here, perhaps pino can look at this svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=471765 --- libscience/chemicaldataobject.cpp | 22 ++++++++++++++++++++++ libscience/chemicaldataobject.h | 3 +++ libscience/element.cpp | 7 +++++-- libscience/element.h | 6 +++--- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp index 96c2c4b..1616486 100644 --- a/libscience/chemicaldataobject.cpp +++ b/libscience/chemicaldataobject.cpp @@ -33,3 +33,25 @@ QString ChemicalDataObject::valueAsString() { return m_value.toString(); } + +bool ChemicalDataObject::operator==( const int v ) +{ + if ( m_value.type() != QVariant::Int ) + return false; + + if ( m_value.toInt() == v ) + return true; + + return false; +} + +bool ChemicalDataObject::operator==( const QString& v ) +{ + if ( m_value.type() != QVariant::String ) + return false; + + if ( m_value.toString() == v ) + return true; + + return false; +} diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h index e5d3257..f07a78f 100644 --- a/libscience/chemicaldataobject.h +++ b/libscience/chemicaldataobject.h @@ -53,6 +53,9 @@ class ChemicalDataObject radiusCovalent/**< the covalent radius */, radiusVDW/**< the van der Waals radius */ }; + + bool operator== ( const int ); + bool operator== ( const QString& ); /** * public constructor diff --git a/libscience/element.cpp b/libscience/element.cpp index 22b5f4d..0b5de82 100644 --- a/libscience/element.cpp +++ b/libscience/element.cpp @@ -38,12 +38,14 @@ Element::Element() m_abundance = 0; } -QVariant Element::data(ChemicalDataObject::BlueObelisk type) +ChemicalDataObject* Element::data(ChemicalDataObject::BlueObelisk type) { foreach( ChemicalDataObject*o, dataList ) { if ( o->type() == type ) - return o->value(); + return o; } + + return 0; } QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) @@ -52,6 +54,7 @@ QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) if ( o->type() == type ) return o->valueAsString(); } + return ""; } Isotope* Element::isotopeByNucleons( int numberOfNucleons ) diff --git a/libscience/element.h b/libscience/element.h index cbe682b..716db5e 100644 --- a/libscience/element.h +++ b/libscience/element.h @@ -431,17 +431,17 @@ class Element{ return m_Color; } - QList dataList; - void addData( ChemicalDataObject*o ){ dataList.append( o ); } - QVariant data( ChemicalDataObject::BlueObelisk type ); + ChemicalDataObject* data( ChemicalDataObject::BlueObelisk type ); QString dataAsString( ChemicalDataObject::BlueObelisk type ); private: + QList dataList; + /** * the integer num represents the number of the element */ -- 2.47.3