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

Akarsh Simha akarshsimha at gmail.com
Tue May 19 06:42:20 CEST 2009


SVN commit 969847 by asimha:

Applying Alexey Khudyakov's second patch refactoring the astro
calculator.  Quoting from his description:

Widget in stack are allocated and put in stack by template
function. This saves some copy-pasting.

CCMAIL: kstars-devel at kde.org



 M  +22 -27    astrocalc.cpp  
 M  +8 -4      astrocalc.h  


--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.cpp #969846:969847
@@ -71,7 +71,7 @@
     new QTreeWidgetItem(timeItem,QStringList(i18n("Sidereal Time")) );
     new QTreeWidgetItem(timeItem,QStringList(i18n("Almanac")) );
     new QTreeWidgetItem(timeItem,QStringList(i18n("Equinoxes & Solstices")) );
-    //	dayItem->setIcon(0,sunsetIcon);
+    //  dayItem->setIcon(0,sunsetIcon);
 
     QTreeWidgetItem * coordItem = new QTreeWidgetItem(navigationPanel,QStringList(i18n("Coordinate Converters")) );
     new QTreeWidgetItem(coordItem,QStringList(i18n("Equatorial/Galactic")) );
@@ -115,34 +115,21 @@
     splashScreen->setReadOnly( true );
     acStack->addWidget( splashScreen );
 
-    JDFrame = new modCalcJD( acStack );
-    acStack->addWidget( JDFrame );
-    GeodCoordFrame = new modCalcGeodCoord( acStack );
-    acStack->addWidget( GeodCoordFrame );
-    GalFrame = new modCalcGalCoord( acStack );
-    acStack->addWidget( GalFrame );
+    JDFrame        = addToStack<modCalcJD>();
+    GeodCoordFrame = addToStack<modCalcGeodCoord>();
+    GalFrame       = addToStack<modCalcGalCoord>();
 
-    SidFrame = new modCalcSidTime( acStack );
-    acStack->addWidget( SidFrame );
-    AppFrame = new modCalcApCoord( acStack );
-    acStack->addWidget( AppFrame );
-    DayFrame = new modCalcDayLength( acStack );
-    acStack->addWidget( DayFrame );
+    SidFrame       = addToStack<modCalcSidTime>();
+    AppFrame       = addToStack<modCalcApCoord>();
+    DayFrame       = addToStack<modCalcDayLength>();
 
-    AltAzFrame = new modCalcAltAz( acStack );
-    acStack->addWidget( AltAzFrame );
-    PlanetsFrame = new modCalcPlanets( acStack );
-    acStack->addWidget( PlanetsFrame );
-    EquinoxFrame = new modCalcEquinox( acStack );
-    acStack->addWidget( EquinoxFrame );
-    EclFrame = new modCalcEclCoords( acStack );
-    acStack->addWidget( EclFrame );
-    AngDistFrame = new modCalcAngDist( acStack );
-    acStack->addWidget( AngDistFrame );
-    VlsrFrame = new modCalcVlsr( acStack );
-    acStack->addWidget( VlsrFrame );
-    ConjunctFrame = new ConjunctionsTool( acStack );
-    acStack->addWidget( ConjunctFrame );
+    AltAzFrame     = addToStack<modCalcAltAz>();
+    PlanetsFrame   = addToStack<modCalcPlanets>();
+    EquinoxFrame   = addToStack<modCalcEquinox>();
+    EclFrame       = addToStack<modCalcEclCoords>();
+    AngDistFrame   = addToStack<modCalcAngDist>();
+    VlsrFrame      = addToStack<modCalcVlsr>();
+    ConjunctFrame  = addToStack<ConjunctionsTool>();
 
     acStack->setCurrentWidget( splashScreen );
 
@@ -150,6 +137,14 @@
             SLOT(slotItemSelection(QTreeWidgetItem *)));
 }
 
+template<typename T>
+T* AstroCalc::addToStack()
+{
+    T* t = new T( acStack );
+    acStack->addWidget(t);
+    return t;
+}
+
 AstroCalc::~AstroCalc()
 {
 }
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.h #969846:969847
@@ -73,13 +73,17 @@
     QSize sizeHint() const;
 
 public slots:
-    /**Determine which item is selected in the function menu QListBox.
-    	*Generate the corresponding calculator module.
-    	*/
+    /** Determine which item is selected in the navigation panel
+      * Generate the corresponding calculator module.
+      */
     void slotItemSelection(QTreeWidgetItem *it);
 
 private:
-
+    /** Create widget of type T and put it to widget stack. Widget must
+     *  have construtor of type T(QWidget*) */
+    template<typename T>
+    inline T* addToStack();
+    
     QSplitter *split;
     QTreeWidget *navigationPanel;
     QString previousElection;


More information about the Kstars-devel mailing list