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

Akarsh Simha akarshsimha at gmail.com
Tue May 26 06:47:44 CEST 2009


SVN commit 972955 by asimha:

Applying Alexey Khudyakov's patch refactoring code in
astrocalc. Quoting from his description:

* addToStack is moved into addTreeItem for more succint code.

Thanks once again, Alexey!

CCMAIL: kstars-devel at kde.org



 M  +17 -31    astrocalc.cpp  
 M  +7 -3      astrocalc.h  


--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.cpp #972954:972955
@@ -143,42 +143,27 @@
     QTreeWidgetItem * timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), messageTime);
     timeItem->setIcon(0,timeIcon);
 
-    QTreeWidgetItem * jdItem = addTreeItem(timeItem, i18n("Julian Day"),
-                                           addToStack<modCalcJD>());
-    jdItem->setIcon(0,jdIcon);
-
-    addTreeItem(timeItem, i18n("Sidereal Time"),
-                addToStack<modCalcSidTime>());
-    addTreeItem(timeItem, i18n("Almanac"),
-                addToStack<modCalcDayLength>());
-    addTreeItem(timeItem, i18n("Equinoxes & Solstices"),
-                addToStack<modCalcEquinox>());
+    addTreeItem<modCalcJD>       (timeItem, i18n("Julian Day"))->setIcon(0,jdIcon);
+    addTreeItem<modCalcSidTime>  (timeItem, i18n("Sidereal Time"));
+    addTreeItem<modCalcDayLength>(timeItem, i18n("Almanac"));
+    addTreeItem<modCalcEquinox>  (timeItem, i18n("Equinoxes & Solstices"));
     //  dayItem->setIcon(0,sunsetIcon);
-
+                                
     // Coordinate-related entries
     QTreeWidgetItem * coordItem = addTreeTopItem(navigationPanel, i18n("Coordinate Converters"), messageCoord);
-    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>());
+    addTreeItem<modCalcGalCoord> (coordItem, i18n("Equatorial/Galactic"));
+    addTreeItem<modCalcApCoord>  (coordItem, i18n("Apparent Coordinates"));
+    addTreeItem<modCalcAltAz>    (coordItem, i18n("Horizontal Coordinates"));
+    addTreeItem<modCalcEclCoords>(coordItem, i18n("Ecliptic Coordinates"));
+    addTreeItem<modCalcAngDist>  (coordItem, i18n("Angular Distance"));
+    addTreeItem<modCalcGeodCoord>(coordItem, i18n("Geodetic Coordinates"));
+    addTreeItem<modCalcVlsr>     (coordItem, i18n("LSR Velocity"));
 
     // Solar System related entries
     QTreeWidgetItem * solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), messageSolar);
     solarItem->setIcon(0,solarIcon);
-    addTreeItem(solarItem, i18n("Planets Coordinates"),
-                addToStack<modCalcPlanets>());
-    addTreeItem(solarItem, i18n("Conjunctions"),
-                addToStack<ConjunctionsTool>());
+    addTreeItem<modCalcPlanets>  (solarItem, i18n("Planets Coordinates"));
+    addTreeItem<ConjunctionsTool>(solarItem, i18n("Conjunctions"));
     
     acStack->setCurrentWidget( splashScreen );
     connect(navigationPanel, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
@@ -193,10 +178,11 @@
     return t;
 }
 
-QTreeWidgetItem* AstroCalc::addTreeItem(QTreeWidgetItem* parent, QString title, QWidget* widget)
+template<typename T>
+QTreeWidgetItem* AstroCalc::addTreeItem(QTreeWidgetItem* parent, QString title)
 {
     QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
-    dispatchTable.insert(item, widget);
+    dispatchTable.insert(item, addToStack<T>());
     return item;
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.h #972954:972955
@@ -62,11 +62,15 @@
      */
     QTreeWidgetItem* addTreeTopItem(QTreeWidget* parent, QString title, QString html);
 
-    /** Add item to navigation panel. At the same time adds item to dispatchTable
+    /** Add item to navigation panel. At the same time adds item to
+        dispatchTable Template parameter is type of widget to be
+        constructed and added to widget stack. It must have T()
+        constructor.
+
         @param title  name of item
-        @param widget widget to be selected on click
      */
-    QTreeWidgetItem* addTreeItem(QTreeWidgetItem* parent, QString title, QWidget* widget);
+    template<typename T>
+    QTreeWidgetItem* addTreeItem(QTreeWidgetItem* parent, QString title);
 
     /** Lookup table for help texts. Maps navpanel item to help text. */
     QMap<QTreeWidgetItem*, QString>  htmlTable;


More information about the Kstars-devel mailing list