[Kstars-devel] branches/kstars/unfrozen/kstars/kstars/tools

Jason Harris kstars at 30doradus.org
Thu Jul 3 07:37:36 CEST 2008


SVN commit 827476 by harris:

Use the new KSPlanetBase PLANET enum in the PlanetViewer tool.  Also some other 
cosmetic fixes.

CCMAIL: kstars-devel at kde.org



 M  +24 -23    planetviewer.cpp  
 M  +4 -5      planetviewer.h  


--- branches/kstars/unfrozen/kstars/kstars/tools/planetviewer.cpp #827475:827476
@@ -71,24 +71,20 @@
     resize( 500, 500 );
     pw->map->QWidget::setFocus(); //give keyboard focus to the plot widget for key and mouse events
 
-    pName[0] = "Mercury"; pColor[0] = "slateblue";
-    pName[1] = "Venus";   pColor[1] = "lightgreen";
-    pName[2] = "Earth";   pColor[2] = "deepskyblue";
-    pName[3] = "Mars";    pColor[3] = "orangered";
-    pName[4] = "Jupiter"; pColor[4] = "goldenrod";
-    pName[5] = "Saturn";  pColor[5] = "khaki";
-    pName[6] = "Uranus";  pColor[6] = "lightseagreen";
-    pName[7] = "Neptune"; pColor[7] = "dodgerblue";
-    pName[8] = "Pluto";   pColor[8] = "gray";
-
     setCenterPlanet(QString());
 
-    KStars *ks = (KStars*)parent;
-    for ( int i=0; i<8; ++i )
-        PlanetList.append( new KSPlanet( ks->data(), pName[i], QString(), QColor( pColor[i] ) ) );
-    PlanetList.append( new KSPluto( ks->data() ) );
+    KStarsData *data = KStarsData::Instance();
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::MERCURY ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::VENUS ) );
+    PlanetList.append( new KSPlanet( data, i18n("Earth") ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::MARS ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::JUPITER ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::SATURN ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::URANUS ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::NEPTUNE ) );
+    PlanetList.append( KSPlanetBase::createPlanet( KSPlanetBase::PLUTO ) );
 
-    ut = ks->data()->ut();
+    ut = data->ut();
     KSNumbers num( ut.djd() );
 
     for ( uint i=0; i<9; ++i ) {
@@ -121,6 +117,10 @@
 {
 }
 
+QString PlanetViewer::planetName(uint i) const {
+    return PlanetList[i]->name();
+}
+
 void PlanetViewer::tick() {
     //Update the time/date
     ut.setDJD( ut.djd() + scale*0.1 );
@@ -177,7 +177,7 @@
             points.at(0)->setX( p->rsun()*c*c2 );
             points.at(0)->setY( p->rsun()*s*c2 );
 
-            if ( centerPlanet() == pName[i] ) {
+            if ( centerPlanet() == p->name() ) {
                 QRectF dataRect = pw->map->dataRect();
                 double xc = (dataRect.right() + dataRect.left())*0.5;
                 double yc = (dataRect.bottom() + dataRect.top())*0.5;
@@ -213,18 +213,19 @@
     //Read in the orbit curves
     KPlotObject *orbit[9];
     for ( unsigned int i=0; i<9; ++i ) {
+        KSPlanetBase *p = PlanetList[i];
         orbit[i] = new KPlotObject( Qt::white, KPlotObject::Lines, 1.0 );
 
         QFile orbitFile;
-        if ( KSUtils::openDataFile( orbitFile, pName[i].toLower() + ".orbit" ) ) {
+        if ( KSUtils::openDataFile( orbitFile, p->name().toLower() + ".orbit" ) ) {
             KSFileReader fileReader( orbitFile ); // close file is included
-						double x,y;
+            double x,y;
             while ( fileReader.hasMoreLines() ) {
                 QString line = fileReader.readLine();
                 QStringList fields = line.split( " ", QString::SkipEmptyParts );
-								if ( fields.size() == 3 ) {
+                if ( fields.size() == 3 ) {
                     x = fields[0].toDouble();
-    								y = fields[1].toDouble();
+                    y = fields[1].toDouble();
                     orbit[i]->addPoint( x, y );
                 }
             }
@@ -234,13 +235,13 @@
     }
 
     for ( unsigned int i=0; i<9; ++i ) {
-        planet[i] = new KPlotObject( pColor[i], KPlotObject::Points, 6, KPlotObject::Circle );
+        KSPlanetBase *p = PlanetList[i];
+        planet[i] = new KPlotObject( p->color(), KPlotObject::Points, 6, KPlotObject::Circle );
 
         double s, c;
-        KSPlanetBase *p = PlanetList[i];
         p->helEcLong()->SinCos( s, c );
 
-        planet[i]->addPoint( p->rsun()*c, p->rsun()*s, i18n(pName[i].toLocal8Bit()) );
+        planet[i]->addPoint( p->rsun()*c, p->rsun()*s, p->translatedName() );
         pw->map->addPlotObject( planet[i] );
     }
 
--- branches/kstars/unfrozen/kstars/kstars/tools/planetviewer.h #827475:827476
@@ -52,11 +52,11 @@
     PlanetViewer(QWidget *parent = 0);
     ~PlanetViewer();
 
-    QString centerPlanet() const { return CenterPlanet; }
-    void setCenterPlanet( const QString &cp ) { CenterPlanet = cp; }
+    inline QString centerPlanet() const { return CenterPlanet; }
+    inline void setCenterPlanet( const QString &cp ) { CenterPlanet = cp; }
 
-    KPlotObject* planetObject(uint i) const { return planet[i]; }
-    QString planetName(uint i) const { return pName[i]; }
+    inline KPlotObject* planetObject(uint i) const { return planet[i]; }
+    QString planetName(uint i) const;
 
 protected:
     virtual void keyPressEvent( QKeyEvent *e );
@@ -80,7 +80,6 @@
     bool isClockRunning;
     QTimer tmr;
     int UpdateInterval[9], LastUpdate[9];
-    QString pName[9], pColor[9];
     QString CenterPlanet;
 
     QList<KSPlanetBase*> PlanetList;


More information about the Kstars-devel mailing list