From: Carsten Niehaus Date: Wed, 19 Oct 2005 11:01:59 +0000 (+0000) Subject: * Make the operator== works X-Git-Tag: v3.80.2~286 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=ac82ed370cb1a852ee000271375f1a545f36b226;p=libqmvoc.git * Make the operator== works * Adding the tests for the operators in tests/xmlreadingtest.cpp * The QList is now private in class Element svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=471958 --- diff --git a/libscience/chemicaldataobject.cpp b/libscience/chemicaldataobject.cpp index 347726b..d47004d 100644 --- a/libscience/chemicaldataobject.cpp +++ b/libscience/chemicaldataobject.cpp @@ -19,6 +19,8 @@ ***************************************************************************/ #include "chemicaldataobject.h" +#include + ChemicalDataObject::ChemicalDataObject( QVariant v, BlueObelisk type ) { m_value = v; @@ -36,16 +38,40 @@ QString ChemicalDataObject::valueAsString() bool ChemicalDataObject::operator==( const int v ) { + kdDebug() << "ChemicalDataObject::operator==() with int" << endl; if ( m_value.type() != QVariant::Int ) return false; return m_value.toInt() == v; } +bool ChemicalDataObject::operator==( const bool v ) +{ + kdDebug() << "ChemicalDataObject::operator==() with bool" << endl; + if ( m_value.type() != QVariant::Bool ) + return false; + + return m_value.toBool() == v; +} + +bool ChemicalDataObject::operator==( const double v ) +{ + kdDebug() << "ChemicalDataObject::operator==() with double" << endl; + if ( m_value.type() != QVariant::Double ) + return false; + + return m_value.toDouble() == v; +} + bool ChemicalDataObject::operator==( const QString& v ) { + kdDebug() << "ChemicalDataObject::operator==() with QString" << endl; if ( m_value.type() != QVariant::String ) return false; return m_value.toString() == v; } + +ChemicalDataObject::~ChemicalDataObject() +{} + diff --git a/libscience/chemicaldataobject.h b/libscience/chemicaldataobject.h index f07a78f..b862bf4 100644 --- a/libscience/chemicaldataobject.h +++ b/libscience/chemicaldataobject.h @@ -54,9 +54,6 @@ class ChemicalDataObject radiusVDW/**< the van der Waals radius */ }; - bool operator== ( const int ); - bool operator== ( const QString& ); - /** * public constructor */ @@ -126,6 +123,26 @@ class ChemicalDataObject void setType( int type ){ m_type = ( BlueObelisk ) type; } + + /** + * Compare the value @v with the data of this object + */ + bool operator== ( const int v); + + /** + * Compare the value @v with the data of this object + */ + bool operator== ( const double v); + + /** + * Compare the value @v with the data of this object + */ + bool operator== ( const bool v); + + /** + * Compare the value @v with the data of this object + */ + bool operator== ( const QString& v); private: QVariant m_value; diff --git a/libscience/element.cpp b/libscience/element.cpp index 0b5de82..eb116c6 100644 --- a/libscience/element.cpp +++ b/libscience/element.cpp @@ -38,14 +38,12 @@ Element::Element() m_abundance = 0; } -ChemicalDataObject* Element::data(ChemicalDataObject::BlueObelisk type) +ChemicalDataObject& Element::data(ChemicalDataObject::BlueObelisk type) { foreach( ChemicalDataObject*o, dataList ) { if ( o->type() == type ) - return o; + return *o; } - - return 0; } QString Element::dataAsString(ChemicalDataObject::BlueObelisk type) diff --git a/libscience/element.h b/libscience/element.h index b943cf1..e21c75a 100644 --- a/libscience/element.h +++ b/libscience/element.h @@ -376,8 +376,6 @@ class Element{ */ double meanmass(); - int x, y; //for the RegularPeriodicTableView - /** * adjusts the units for the data. The user can * for example define if Fahrenheit, Kelvin or @@ -431,17 +429,37 @@ class Element{ return m_Color; } + /** + * add the ChemicalDataObject @p o to this Element + * @param o the ChemicalDataObject to be added + */ void addData( ChemicalDataObject*o ){ dataList.append( o ); } - ChemicalDataObject* data( ChemicalDataObject::BlueObelisk type ); + /** + * @return the ChemicalDataObject which stores the information + * of the type @p type + * @param type the type of the requested data + */ + ChemicalDataObject& data( ChemicalDataObject::BlueObelisk type ); + /** + * @return the requested data of the type @p type as a QString + */ QString dataAsString( ChemicalDataObject::BlueObelisk type ); - QList dataList; - + /** + * @return the data of the Element + */ + QList data()const{ + return dataList; + } private: + /** + * this QList stores all information about an element + */ + QList dataList; /** * the integer num represents the number of the element diff --git a/libscience/tests/xmlreadingtest.cpp b/libscience/tests/xmlreadingtest.cpp index 9aa3af0..ada078f 100644 --- a/libscience/tests/xmlreadingtest.cpp +++ b/libscience/tests/xmlreadingtest.cpp @@ -25,12 +25,20 @@ int main(int argc, char *argv[]) foreach( Element* e, v ){ if ( e ) { - QList list = e->dataList; + QList list = e->data(); - //Give me the name of the element - kdDebug() << "Name: " << e->dataAsString( ChemicalDataObject::name ) << endl; + //Test: Check if the string-comparison works +//X if ( e->data( ChemicalDataObject::name ) == "Helium" ) +//X kdDebug() << "Mass: " << e->dataAsString( ChemicalDataObject::mass ) << endl; -//X //give me all you have + //Test: Check if the double-comparison works +//X if ( e->data( ChemicalDataObject::mass ) == 4.002602 ) +//X kdDebug() << "Correct mass found" << endl; + + //Test: Give me the name of the element +//X kdDebug() << "Name: " << e->dataAsString( ChemicalDataObject::name ) << endl; + + //Test: give me all data available //X foreach( ChemicalDataObject*o, list ){ //X if ( o ) //X kdDebug() << o->valueAsString() << endl;