[Kstars-devel] KDE/kdeedu/kstars/kstars/tools

Akarsh Simha akarshsimha at gmail.com
Wed May 20 14:33:04 CEST 2009


SVN commit 970533 by asimha:

Merging the last of Alexey Khudyakov's 5 patches refactoring code in
the KStars Astronomical Calculator. Quoting from Alexey's description
of the patch:

* Unneeded data fields are removed
* Documentation improved
* Unneeded forward class declarations and includes are removed

Thanks for the contributions, Alexey.

CCMAIL: kstars-devel at kde.org



 M  +44 -46    astrocalc.cpp  
 M  +14 -47    astrocalc.h  


--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.cpp #970532:970533
@@ -20,6 +20,7 @@
 #include <QSplitter>
 #include <QStackedWidget>
 #include <QTreeWidget>
+#include <QTreeWidgetItem>
 #include <KTextEdit>
 #include <klocale.h>
 #include <ktextedit.h>
@@ -40,12 +41,9 @@
 #include "conjunctions.h"
 
 AstroCalc::AstroCalc( QWidget* parent ) :
-        KDialog( parent ), JDFrame(0), GeodCoordFrame(0),
-        GalFrame(0), SidFrame(0), AppFrame(0),
-        DayFrame(0), AltAzFrame(0), PlanetsFrame(0), EquinoxFrame(0),
-        EclFrame(0), AngDistFrame(0)
+        KDialog( parent )
 {
-    // Long list of messages
+    // List of messages. Maybe there is better place for it...
     QString message =
         i18n("<QT>"
              "<H2>KStars Astrocalculator</H2>"
@@ -117,6 +115,7 @@
     setCaption( i18n("Calculator") );
     setButtons( KDialog::Close );
 
+    // Create navigation panel
     navigationPanel = new QTreeWidget(split);
     navigationPanel->setColumnCount(1);
     navigationPanel->setHeaderLabels( QStringList(i18n("Calculator modules")) );
@@ -125,64 +124,63 @@
     //but I wasn't able to make it work
     navigationPanel->setMinimumWidth( 200 );
 
-	// Load icons
-    QIcon jdIcon = QIcon ("jd.png");
-    QIcon geodIcon = QIcon ("geodetic.png");
-    QIcon solarIcon = QIcon ("geodetic.png");
-    QIcon sunsetIcon = QIcon ("sunset.png");
-    QIcon timeIcon = QIcon ("sunclock.png");
-
-    //Populate widget stack
     acStack = new QStackedWidget( split );
 
     splashScreen = new KTextEdit( message, acStack );
     splashScreen->setReadOnly( true );
     acStack->addWidget( splashScreen );
 
-    JDFrame        = addToStack<modCalcJD>();
-    GeodCoordFrame = addToStack<modCalcGeodCoord>();
-    GalFrame       = addToStack<modCalcGalCoord>();
 
-    SidFrame       = addToStack<modCalcSidTime>();
-    AppFrame       = addToStack<modCalcApCoord>();
-    DayFrame       = addToStack<modCalcDayLength>();
-
-    AltAzFrame     = addToStack<modCalcAltAz>();
-    PlanetsFrame   = addToStack<modCalcPlanets>();
-    EquinoxFrame   = addToStack<modCalcEquinox>();
-    EclFrame       = addToStack<modCalcEclCoords>();
-    AngDistFrame   = addToStack<modCalcAngDist>();
-    VlsrFrame      = addToStack<modCalcVlsr>();
-    ConjunctFrame  = addToStack<ConjunctionsTool>();
-
-    acStack->setCurrentWidget( splashScreen );
-	
-    //Populate the tree widget
+    // Load icons
+    QIcon jdIcon = QIcon ("jd.png");
+    QIcon geodIcon = QIcon ("geodetic.png");
+    QIcon solarIcon = QIcon ("geodetic.png");
+    // QIcon sunsetIcon = QIcon ("sunset.png"); // Its usage is commented out.
+    QIcon timeIcon = QIcon ("sunclock.png");
+    
+    /* Populate the tree widget and widget stack */
+    // Time-related entries
     QTreeWidgetItem * timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), messageTime);
     timeItem->setIcon(0,timeIcon);
 
-    QTreeWidgetItem * jdItem = addTreeItem(timeItem, i18n("Julian Day"), JDFrame );
+    QTreeWidgetItem * jdItem = addTreeItem(timeItem, i18n("Julian Day"),
+                                           addToStack<modCalcJD>());
     jdItem->setIcon(0,jdIcon);
 
-    addTreeItem(timeItem, i18n("Sidereal Time"), SidFrame );
-    addTreeItem(timeItem, i18n("Almanac"), DayFrame );
-    addTreeItem(timeItem, i18n("Equinoxes & Solstices"), EquinoxFrame );
-    //	dayItem->setIcon(0,sunsetIcon);
+    addTreeItem(timeItem, i18n("Sidereal Time"),
+                addToStack<modCalcSidTime>());
+    addTreeItem(timeItem, i18n("Almanac"),
+                addToStack<modCalcDayLength>());
+    addTreeItem(timeItem, i18n("Equinoxes & Solstices"),
+                addToStack<modCalcEquinox>());
+    //  dayItem->setIcon(0,sunsetIcon);
 
+    // Coordinate-related entries
     QTreeWidgetItem * coordItem = addTreeTopItem(navigationPanel, i18n("Coordinate Converters"), messageCoord);
-    addTreeItem(coordItem, i18n("Equatorial/Galactic"), GalFrame);
-    addTreeItem(coordItem, i18n("Apparent Coordinates"), AppFrame);
-    addTreeItem(coordItem, i18n("Horizontal Coordinates"), AltAzFrame);
-    addTreeItem(coordItem, i18n("Ecliptic Coordinates"), EclFrame);
-    addTreeItem(coordItem, i18n("Angular Distance"), AngDistFrame);
-    addTreeItem(coordItem, i18n("Geodetic Coordinates"), GeodCoordFrame);
-    addTreeItem(coordItem, i18n("LSR Velocity"), VlsrFrame);
+    addTreeItem(coordItem, i18n("Equatorial/Galactic"),
+                addToStack<modCalcGalCoord>());
+    addTreeItem(coordItem, i18n("Apparent Coordinates"),
+                addToStack<modCalcApCoord>());
+    addTreeItem(coordItem, i18n("Horizontal Coordinates"),
+                addToStack<modCalcAltAz>());
+    addTreeItem(coordItem, i18n("Ecliptic Coordinates"),
+                addToStack<modCalcEclCoords>());
+    addTreeItem(coordItem, i18n("Angular Distance"),
+                addToStack<modCalcAngDist>());
+    addTreeItem(coordItem, i18n("Geodetic Coordinates"),
+                addToStack<modCalcGeodCoord>());
+    addTreeItem(coordItem, i18n("LSR Velocity"),
+                addToStack<modCalcVlsr>());
 
+    // Solar System related entries
     QTreeWidgetItem * solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), messageSolar);
     solarItem->setIcon(0,solarIcon);
-    addTreeItem(solarItem, i18n("Planets Coordinates"), PlanetsFrame);
-    addTreeItem(solarItem, i18n("Conjunctions"), ConjunctFrame);
-	
+    addTreeItem(solarItem, i18n("Planets Coordinates"),
+                addToStack<modCalcPlanets>());
+    addTreeItem(solarItem, i18n("Conjunctions"),
+                addToStack<ConjunctionsTool>());
+    
+    acStack->setCurrentWidget( splashScreen );
     connect(navigationPanel, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
             SLOT(slotItemSelection(QTreeWidgetItem *)));
 }
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.h #970532:970533
@@ -18,29 +18,16 @@
 #ifndef ASTROCALC_H_
 #define ASTROCALC_H_
 
-#include <QTreeWidgetItem>
 #include <QMap>
+#include <QString>
 #include <kdialog.h>
 
-#include "dms.h"
 
 class QSplitter;
-class QString;
 class QStackedWidget;
+class QTreeWidget;
+class QTreeWidgetItem;
 class KTextEdit;
-class modCalcJD;
-class modCalcGeodCoord;
-class modCalcGalCoord;
-class modCalcSidTime;
-class modCalcApCoord;
-class modCalcDayLength;
-class modCalcAltAz;
-class modCalcEquinox;
-class modCalcPlanets;
-class modCalcEclCoords;
-class modCalcAngDist;
-class modCalcVlsr;
-class ConjunctionsTool;
 
 /** Astrocalc is the base class for the KStars astronomical calculator
  * @author: Pablo de Vicente
@@ -59,56 +46,36 @@
     /**@returns suggested size of calculator window. */
     QSize sizeHint() const;
 public slots:
-    /** Determine which item is selected in the navigation panel
-      * Generate the corresponding calculator module.
-      */
+    /** Display calculator module or help text based on item selected.
+	 */
     void slotItemSelection(QTreeWidgetItem *it);
 
 private:
     /** Create widget of type T and put it to widget stack. Widget must
-     *  have construtor of type T(QWidget*) */
+     *  have construtor of type T(QWidget*). Returns constructed widget. */
     template<typename T>
     inline T* addToStack();
     
-    /** Add top level item to navigation panel.
-        title - name of item
-        html  - string to be displayed in splash screen
+    /** Add top level item to navigation panel. At the same time adds item to htmlTable 
+        @param title name of item
+        @param html  string to be displayed in splash screen
      */
     QTreeWidgetItem* addTreeTopItem(QTreeWidget* parent, QString title, QString html);
 
-    /** Add item to navigation panel.
-        title - name of item
-        widget - widget to be selected on click
+    /** Add item to navigation panel. At the same time adds item to dispatchTable
+        @param title  name of item
+        @param widget widget to be selected on click
      */
     QTreeWidgetItem* addTreeItem(QTreeWidgetItem* parent, QString title, QWidget* widget);
 
-    /** Lookup table for help texts */
+    /** Lookup table for help texts. Maps navpanel item name to help text. */
     QMap<QString, QString>  htmlTable;
-    /** Lookup table for widgets */
+    /** Lookup table for widgets. Maps navpanel item name to widget to be displayed. */
     QMap<QString, QWidget*> dispatchTable;
     QSplitter *split;
     QTreeWidget *navigationPanel;
-    QString previousElection;
-
-    enum typeOfPanel {GenText, TimeText, GeoText, SolarText, CoordText, JD, SidTime, DayLength, Equinox, GeoCoord, Galactic, Apparent, AltAz, Planets, Ecliptic, AngDist, Vlsr};
-    typeOfPanel rightPanel;
-
-    QStringList ItemTitles;
     QStackedWidget *acStack;
     KTextEdit *splashScreen;
-    modCalcJD *JDFrame;
-    modCalcGeodCoord *GeodCoordFrame;
-    modCalcGalCoord *GalFrame;
-    modCalcSidTime *SidFrame;
-    modCalcApCoord *AppFrame;
-    modCalcDayLength *DayFrame;
-    modCalcAltAz *AltAzFrame;
-    modCalcPlanets *PlanetsFrame;
-    modCalcEquinox *EquinoxFrame;
-    modCalcEclCoords *EclFrame;
-    modCalcAngDist *AngDistFrame;
-    modCalcVlsr *VlsrFrame;
-    ConjunctionsTool *ConjunctFrame;
 };
 
 #endif


More information about the Kstars-devel mailing list