]> Git trees. - libqmvoc.git/commitdiff
* Make the operator== works
authorCarsten Niehaus <cniehaus@gmx.de>
Wed, 19 Oct 2005 11:01:59 +0000 (11:01 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Wed, 19 Oct 2005 11:01:59 +0000 (11:01 +0000)
* Adding the tests for the operators in tests/xmlreadingtest.cpp
* The QList<ChemicalDataObject*> is now private in class Element

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=471958

libscience/chemicaldataobject.cpp
libscience/chemicaldataobject.h
libscience/element.cpp
libscience/element.h
libscience/tests/xmlreadingtest.cpp

index 347726bbb1d097b0eb82435f6dc5bc51d7b81f24..d47004d8aa5e3a1d9845775e7d3dae6573067498 100644 (file)
@@ -19,6 +19,8 @@
  ***************************************************************************/
 #include "chemicaldataobject.h"
 
+#include <kdebug.h>
+
 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()
+{}
+       
index f07a78f5d4c3cad71821d438c6281a01f79fb2c3..b862bf4980fea7baa58f3cd2142c84b549bd582c 100644 (file)
@@ -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;
index 0b5de82d82274ca11cfc02607fbaea92db752138..eb116c6a6be0a21c38311e92aba49f8a87874d69 100644 (file)
@@ -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)
index b943cf1fc42192174a5a0b9778c197cbd6869d64..e21c75a4395369245fe303af869568cdb94fbeab 100644 (file)
@@ -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<ChemicalDataObject*> dataList;
-
+               /**
+                * @return the data of the Element
+                */
+               QList<ChemicalDataObject*> data()const{
+                       return dataList;
+               }
        private:
+               /**
+                * this QList stores all information about an element
+                */
+               QList<ChemicalDataObject*> dataList;
 
                /**
                 * the integer num represents the number of the element
index 9aa3af065ac81cb893c0ad39e4cc215ce7c0c621..ada078f6586076e51568b93ca0940e0d3b9165e6 100644 (file)
@@ -25,12 +25,20 @@ int main(int argc, char *argv[])
        foreach( Element* e, v ){
                if ( e )
                {
-                       QList<ChemicalDataObject*> list = e->dataList;
+                       QList<ChemicalDataObject*> 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;