]> Git trees. - libqmvoc.git/commitdiff
ok, the reading is now done, all 111 elements are read from XML and the
authorCarsten Niehaus <cniehaus@gmx.de>
Sun, 13 Mar 2005 18:01:33 +0000 (18:01 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Sun, 13 Mar 2005 18:01:33 +0000 (18:01 +0000)
data is put into the internal data structure.

TODO: make use of that data :-)

svn path=/trunk/kdeedu/kalzium/src/element.cpp; revision=397331

kalzium/src/element.cpp
kalzium/src/element.h

index 481459b13d93daa466558143733abccace07a017..e9767b8bcfb5bbca9ea08215b2eb81c61255b028 100644 (file)
 #include <qmap.h>
 #include <kdebug.h>
 #include <klocale.h>
+#include <kmessagebox.h>
+#include <kurl.h>
+#include <klocale.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+#include <kfiledialog.h>
+#include <kmessagebox.h>
 
 #include <math.h>
 
@@ -34,41 +41,17 @@ Element::Element( int num )
 {
        m_number = num;
 
-       /*
-        * this object is static because this reduces the access to the file 
-        * by 90% (strace counts 16 calls instead of 116 )
-        */
-       static KSimpleConfig config ( locate( "data", "kalzium/kalziumrc" ) );
-       
-       if ( config.hasGroup( QString::number( num ) ) )
-
-       config.setGroup( QString::number( num ) );
-       m_name=config.readEntry( "Name", "Unknown" );
-       m_symbol=config.readEntry( "Symbol", "Unknown" );
-       m_weight=config.readDoubleNumEntry( "Weight",0.0 );
-
-       m_oxstage=config.readEntry( "Ox","0" );
-       m_acidbeh=config.readEntry( "acidbeh","0" );
-       m_isotopes=config.readEntry( "Isotopes", "0" );
-
-       m_block=config.readEntry( "Block","s" );
-       m_EN=config.readDoubleNumEntry( "EN", -1 );
-       m_MP=config.readDoubleNumEntry( "MP", -1 );
-       m_IE=config.readDoubleNumEntry( "IE", -1 );
-       m_IE2=config.readDoubleNumEntry( "IE2", -1 );
-       m_AR=config.readDoubleNumEntry( "AR", -1 );
-       m_BP=config.readDoubleNumEntry( "BP", -1 );
-       m_Density=config.readDoubleNumEntry( "Density", -1 );
-       m_group=config.readEntry( "Group","1" );
-       m_family=config.readEntry( "Family","1" );
-       m_orbits=config.readEntry( "Orbits","0" );
-       m_biological=config.readNumEntry(  "biological" , -1 );
-       m_az=config.readNumEntry( "az",-1 );
-       m_date=config.readNumEntry( "date",-1 );
+//X    m_IE=config.readDoubleNumEntry( "IE", -1 );
+//X    m_IE2=config.readDoubleNumEntry( "IE2", -1 );
 
        setupXY();
 }
 
+Element::Element()
+{
+       setupXY();
+};
+
 QString Element::parsedOrbits()
 {
        if ( m_orbits == "0" )
@@ -373,7 +356,7 @@ void Element::drawSelf( QPainter* p, bool useSimpleView )
        int h_small = 15; //the size for the small units like elementnumber
 
        //The X-coordiante
-       int X;
+       int X = 0;
        
        if ( useSimpleView )
        {//use the small periodic table without the d- and f-Block
@@ -456,16 +439,106 @@ void Element::setupXY()
 
 KalziumDataObject::KalziumDataObject()
 {
-       for( int i = 1 ; i < 112 ; ++i )
+       QDomDocument doc( "datadocument" );
+
+       KURL url;
+       url.setPath( locate("data", "kalzium/data/"));
+       url.setFileName( "data.xml" );
+       QFile layoutFile( url.path() );
+
+       if (!layoutFile.exists())
        {
-               Element *e = new Element( i );
-               coordinate point; point.x =  e->x; point.y = e->y;
+               KMessageBox::information( 0, i18n("data.xml doesn't exist"), i18n( "Loading File - Error" ) );
+       }
+
+       if (!layoutFile.open(IO_ReadOnly))
+               KMessageBox::information( 0, i18n("data.xml io-errro"), i18n( "Loading File - IO_ReadOnly" ) );
 
-               CoordinateList.append( point );
-               ElementList.append( e );
+       ///Check if document is well-formed
+       if (!doc.setContent(&layoutFile))
+       {
+               kdDebug() << "wrong xml" << endl;
+               layoutFile.close();
        }
+       layoutFile.close();
+
+       ElementList = readData( doc );
+
+       kdDebug() << ElementList.count() << " elements read" << endl;
+
+       //X     for( int i = 1 ; i < 112 ; ++i )
+       //X     {
+       //X             Element *e = new Element( i );
+       //X             coordinate point; point.x =  e->x; point.y = e->y;
+       //X 
+       //X             CoordinateList.append( point );
+       //X             ElementList.append( e );
+       //X     }
 }
 
 KalziumDataObject::~KalziumDataObject()
 {}
 
+EList KalziumDataObject::readData(  QDomDocument &dataDocument )
+{
+       EList list;
+       QDomNodeList elementNodes; //the list of all element
+       QDomElement  domElement;   //a single element
+
+       //read in all elements
+       elementNodes = dataDocument.elementsByTagName( "element" );
+
+       for ( uint i = 0; i < elementNodes.count(); ++i )
+       {//iterate through all elements
+               domElement = ( const QDomElement& ) elementNodes.item( i ).toElement();
+               
+               double weight = domElement.namedItem( "weight" ).toElement().text().toDouble();
+               double en = domElement.namedItem( "electronegativity" ).toElement().text().toDouble();
+               double mp = domElement.namedItem( "meltingpoint" ).toElement().text().toDouble();
+               double bp = domElement.namedItem( "boilingpoint" ).toElement().text().toDouble();
+               double density = domElement.namedItem( "density" ).toElement().text().toDouble();
+               double atomic_radius = domElement.namedItem( "radius" ).namedItem( "atomic" ).toElement().text().toDouble();
+               
+               int bio = domElement.namedItem( "biologicalmeaning" ).toElement().text().toInt();
+               int az = domElement.namedItem( "aggregation" ).toElement().text().toInt();
+               int date = domElement.namedItem( "date" ).toElement().text().toInt();
+               
+               QString scientist = domElement.namedItem( "date" ).toElement().attributeNode( "scientist" ).value();
+               QString name = domElement.namedItem( "name" ).toElement().text();
+               QString block = domElement.namedItem( "block" ).toElement().text();
+               QString group = domElement.namedItem( "group" ).toElement().text();
+               QString family = domElement.namedItem( "family" ).toElement().text();
+               QString orbits = domElement.namedItem( "orbits" ).toElement().text();
+               QString symbol = domElement.namedItem( "symbol" ).toElement().text();
+               QString oxydation = domElement.namedItem( "oxydation" ).toElement().text();
+               QString acidicbehaviour = domElement.namedItem( "acidicbehaviour" ).toElement().text();
+               QString isotopes = domElement.namedItem( "isotopes" ).toElement().text();
+       
+               Element *e = new Element();
+               e->setDate(date);
+               e->setBiologicalMeaning(bio);
+               e->setAggregation(az);
+               
+               e->setScientist(scientist);
+               e->setName(name);
+               e->setBlock(block);
+               e->setGroup(group);
+               e->setFamily(family);
+               e->setOrbits(orbits);
+               e->setSymbol(symbol);
+               e->setOxydation(oxydation);
+               e->setAcidicbehaviour(acidicbehaviour);
+               e->setIsotopes(isotopes);
+               
+               e->setWeight( weight ); 
+               e->setEN( en );
+               e->setMeltingpoint( mp );
+               e->setBoilingpoint( bp );
+               e->setDensity( density );
+               e->setAtomicRadius( atomic_radius );
+
+               list.append( e );
+       }
+       
+       return list;
+}
index 7a05ae127dbcfeab8094cc8921ac173029f1779e..3a47ead5950a12177deb906acd9e234532e5a8b1 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <ksimpleconfig.h>
 #include <kstandarddirs.h>
+#include <qdom.h>
+#include <qfile.h>
 
 class Element;
 
@@ -46,6 +48,9 @@ class KalziumDataObject
                EList ElementList;
                
                CList CoordinateList;
+
+       private:
+               EList readData( QDomDocument &dataDocument );
 };
 
 struct coordinate{
@@ -63,6 +68,8 @@ struct coordinate{
 class Element{
        public:
                Element( int );
+               Element( );
+
                virtual ~Element();
 
                /**
@@ -72,6 +79,29 @@ class Element{
                        return m_number;
                }
                
+               void setWeight( double value ) { m_weight = value; }
+               void setEN( double value ) { m_EN = value; }
+               void setMeltingpoint( double value ) { m_MP = value; }
+               void setBoilingpoint( double value ) { m_BP = value; }
+               void setDensity( double value ) { m_Density = value; }
+               void setAtomicRadius( double value ) { m_AR = value; }
+
+               void setDate( int date ) { m_date = date; }
+               void setBiologicalMeaning( int value ) { m_biological = value; }
+               void setAggregation( int value ) { m_az = value; }
+
+               void setScientist( QString value ) { m_scientist = value; }
+               void setName( QString value ) { m_name = value; }
+               void setBlock( QString value ) { m_block = value; }
+               void setGroup( QString value ) { m_group = value; }
+               void setFamily( QString value ) { m_family = value; }
+               void setOrbits( QString value ) { m_orbits = value; }
+               void setSymbol( QString value ) { m_symbol = value; }
+               void setOxydation( QString value ) { m_oxstage = value; }
+               void setAcidicbehaviour( QString value ) { m_acidbeh = value; }
+               void setIsotopes( QString value ) { m_isotopes = value; }
+               
+               
                /**
                 * @return the date of discovery of the element
                 */
@@ -106,7 +136,8 @@ class Element{
                 * @return the condition of aggrgation of the element at 
                 * room temperature. 0 means solid, 1 means liquid, 2 means vapor
                 */
-               int az() const {return m_az;
+               int az() const {
+                       return m_az;
                }
                
                /**
@@ -305,7 +336,8 @@ class Element{
                        m_family,
                        m_acidbeh,
                        m_orbits,
-                       m_isotopes;
+                       m_isotopes,
+                       m_scientist;
                
        public:
                /**