[Kstars-devel] KDE/kdeedu/kstars/kstars/tools
Akarsh Simha
akarshsimha at gmail.com
Wed May 20 14:28:09 CEST 2009
SVN commit 970531 by asimha:
Commiting the 4th of Alexey Khudyakov's 5 patches refactoring code in
the KStars Astro-Calculator. Quoting from his description of the
patch:
gen{Time,Coord,Solar}Text functions are removed.
All dispatching in slotItemSelection is done via maps instead of long ladder
of `ifs'. Item name appears in source code only once.
Alexey confirms that this patch does not introduce new strings. Thanks
Alexey!
CCMAIL: kstars-devel at kde.org
M +88 -123 astrocalc.cpp
M +0 -15 astrocalc.h
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.cpp #970530:970531
@@ -45,6 +45,73 @@
DayFrame(0), AltAzFrame(0), PlanetsFrame(0), EquinoxFrame(0),
EclFrame(0), AngDistFrame(0)
{
+ // Long list of messages
+ QString message =
+ i18n("<QT>"
+ "<H2>KStars Astrocalculator</H2>"
+ "<P>"
+ "The KStars Astrocalculator contains several <B>modules</b> "
+ "which perform a variety of astronomy-related calculations. "
+ "The modules are organized into several categories: "
+ "<UL>"
+ "<LI><B>Time calculators: </B>"
+ "Convert between time systems, and predict the timing of celestial events</LI>"
+ "<LI><B>Coordinate converters: </B>"
+ "Convert between various coordinate systems</LI>"
+ "<LI><B>Solar system: </B>"
+ "Predict the position of any planet, from a given location on Earth at a given time</LI>"
+ "</UL>"
+ "</QT>"
+ );
+ QString messageTime =
+ i18n("<QT>"
+ "Section which includes algorithms for computing time ephemeris"
+ "<UL><LI>"
+ "<B>Julian Day:</B> Julian Day/Calendar conversion"
+ "</LI><LI>"
+ "<B>Sidereal Time:</B> Sidereal/Universal time conversion"
+ "</LI><LI>"
+ "<B>Almanac:</B> Rise/Set/Transit timing and position data "
+ "for the Sun and Moon"
+ "</LI><LI>"
+ "<B>Equinoxes & Solstices:</B> Equinoxes, Solstices and duration of the "
+ "seasons"
+ "</LI></UL>"
+ "</QT>");
+ QString messageCoord =
+ i18n("<QT>"
+ "Section with algorithms for the conversion of "
+ "different astronomical systems of coordinates"
+ "<UL><LI>"
+ "<B>Galactic:</B> Galactic/Equatorial coordinates conversion"
+ "</LI><LI>"
+ "<B>Apparent:</B> Computation of current equatorial coordinates"
+ " from a given epoch"
+ "</LI><LI>"
+ "<B>Ecliptic:</B> Ecliptic/Equatorial coordinates conversion"
+ "</LI><LI>"
+ "<B>Horizontal:</B> Computation of azimuth and elevation for a "
+ "given source, time, and location on the Earth"
+ "</LI><LI>"
+ "<B>Angular Distance:</B> Computation of angular distance between "
+ "two objects whose positions are given in equatorial coordinates"
+ "</LI><LI>"
+ "<B>Geodetic Coords:</B> Geodetic/XYZ coordinate conversion"
+ "</LI><LI>"
+ "<B>LSR Velocity:</B> Computation of the heliocentric, geocentric "
+ "and topocentric radial velocity of a source from its LSR velocity"
+ "</LI></UL>"
+ "</QT>");
+ QString messageSolar =
+ i18n("<QT>"
+ "Section with algorithms regarding information "
+ "on solar system bodies coordinates and times"
+ "<UL><LI>"
+ "<B>Planets Coords:</B> Coordinates for the planets, moon and sun "
+ "at a given time and from a given position on Earth "
+ "</LI></UL>"
+ "</QT>");
+
split = new QSplitter ( this );
setMainWidget(split);
setCaption( i18n("Calculator") );
@@ -54,37 +121,20 @@
navigationPanel->setColumnCount(1);
navigationPanel->setHeaderLabels( QStringList(i18n("Calculator modules")) );
navigationPanel->setSortingEnabled( false );
+ //FIXME: Would be better to make the navigationPanel fit its contents,
+ //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");
- //FIXME: Would be better to make the navigationPanel fit its contents,
- //but I wasn't able to make it work
- navigationPanel->setMinimumWidth( 200 );
-
//Populate widget stack
acStack = new QStackedWidget( split );
- QString message = i18n("<QT>"
- "<H2>KStars Astrocalculator</H2>"
- "<P>"
- "The KStars Astrocalculator contains several <B>modules</b> "
- "which perform a variety of astronomy-related calculations. "
- "The modules are organized into several categories: "
- "<UL>"
- "<LI><B>Time calculators: </B>"
- "Convert between time systems, and predict the timing of celestial events</LI>"
- "<LI><B>Coordinate converters: </B>"
- "Convert between various coordinate systems</LI>"
- "<LI><B>Solar system: </B>"
- "Predict the position of any planet, from a given location on Earth at a given time</LI>"
- "</UL>"
- "</QT>"
- );
-
splashScreen = new KTextEdit( message, acStack );
splashScreen->setReadOnly( true );
acStack->addWidget( splashScreen );
@@ -108,7 +158,7 @@
acStack->setCurrentWidget( splashScreen );
//Populate the tree widget
- QTreeWidgetItem * timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), "");
+ QTreeWidgetItem * timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), messageTime);
timeItem->setIcon(0,timeIcon);
QTreeWidgetItem * jdItem = addTreeItem(timeItem, i18n("Julian Day"), JDFrame );
@@ -119,7 +169,7 @@
addTreeItem(timeItem, i18n("Equinoxes & Solstices"), EquinoxFrame );
// dayItem->setIcon(0,sunsetIcon);
- QTreeWidgetItem * coordItem = addTreeTopItem(navigationPanel, i18n("Coordinate Converters"), "");
+ 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);
@@ -128,7 +178,7 @@
addTreeItem(coordItem, i18n("Geodetic Coordinates"), GeodCoordFrame);
addTreeItem(coordItem, i18n("LSR Velocity"), VlsrFrame);
- QTreeWidgetItem * solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), "");
+ QTreeWidgetItem * solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), messageSolar);
solarItem->setIcon(0,solarIcon);
addTreeItem(solarItem, i18n("Planets Coordinates"), PlanetsFrame);
addTreeItem(solarItem, i18n("Conjunctions"), ConjunctFrame);
@@ -165,112 +215,27 @@
void AstroCalc::slotItemSelection(QTreeWidgetItem *item)
{
- if (item==0L) return;
+ if ( item == 0)
+ return;
//DEBUG
kDebug() << "Item clicked: " << item->text(0);
QString s = item->text(0);
-
- if(!(s.compare(i18n("Time Calculators"))))
- genTimeText();
- if(!(s.compare(i18n("Coordinate Converters"))))
- genCoordText();
- if(!(s.compare(i18n("Solar System"))))
- genSolarText();
-
- //DEBUG
- kDebug() << "s = " << s;
- kDebug() << acStack << " : " << AltAzFrame;
-
- if(!(s.compare(i18n("Sidereal Time"))))
- acStack->setCurrentWidget( SidFrame );
- if(!(s.compare(i18n("Julian Day"))))
- acStack->setCurrentWidget( JDFrame );
- if(!(s.compare(i18n("Equatorial/Galactic"))))
- acStack->setCurrentWidget( GalFrame );
- if(!(s.compare(i18n("Apparent Coordinates"))))
- acStack->setCurrentWidget( AppFrame );
- if(!(s.compare(i18n("Horizontal Coordinates"))))
- acStack->setCurrentWidget( AltAzFrame );
- if(!(s.compare(i18n("Ecliptic Coordinates"))))
- acStack->setCurrentWidget( EclFrame );
- if(!(s.compare(i18n("Geodetic Coordinates"))))
- acStack->setCurrentWidget( GeodCoordFrame );
- if(!(s.compare(i18n("Almanac"))))
- acStack->setCurrentWidget( DayFrame );
- if(!(s.compare(i18n("Equinoxes & Solstices"))))
- acStack->setCurrentWidget( EquinoxFrame );
- if(!(s.compare(i18n("Planets Coordinates"))))
- acStack->setCurrentWidget( PlanetsFrame );
- if(!(s.compare(i18n("Conjunctions"))))
- acStack->setCurrentWidget( ConjunctFrame );
- if(!(s.compare(i18n("Angular Distance"))))
- acStack->setCurrentWidget( AngDistFrame );
- if(!(s.compare(i18n("LSR Velocity"))))
- acStack->setCurrentWidget( VlsrFrame );
+ // Lookup in HTML table
+ QMap<QString, QString>::iterator iterHTML = htmlTable.find(s);
+ if( iterHTML != htmlTable.end() ) {
+ splashScreen->setHtml(*iterHTML);
+ acStack->setCurrentWidget(splashScreen);
+ return;
+ }
+ // Lookup in frames table
+ QMap<QString, QWidget*>::iterator iter = dispatchTable.find(s);
+ if( iter != dispatchTable.end() ) {
+ acStack->setCurrentWidget( *iter );
+ }
}
-void AstroCalc::genTimeText(void)
-{
- splashScreen->setHtml(i18n("<QT>"
- "Section which includes algorithms for computing time ephemeris"
- "<UL><LI>"
- "<B>Julian Day:</B> Julian Day/Calendar conversion"
- "</LI><LI>"
- "<B>Sidereal Time:</B> Sidereal/Universal time conversion"
- "</LI><LI>"
- "<B>Almanac:</B> Rise/Set/Transit timing and position data "
- "for the Sun and Moon"
- "</LI><LI>"
- "<B>Equinoxes & Solstices:</B> Equinoxes, Solstices and duration of the "
- "seasons"
- "</LI></UL>"
- "</QT>"));
- acStack->setCurrentWidget( splashScreen );
-}
-
-void AstroCalc::genCoordText(void)
-{
- splashScreen->setHtml(i18n("<QT>"
- "Section with algorithms for the conversion of "
- "different astronomical systems of coordinates"
- "<UL><LI>"
- "<B>Galactic:</B> Galactic/Equatorial coordinates conversion"
- "</LI><LI>"
- "<B>Apparent:</B> Computation of current equatorial coordinates"
- " from a given epoch"
- "</LI><LI>"
- "<B>Ecliptic:</B> Ecliptic/Equatorial coordinates conversion"
- "</LI><LI>"
- "<B>Horizontal:</B> Computation of azimuth and elevation for a "
- "given source, time, and location on the Earth"
- "</LI><LI>"
- "<B>Angular Distance:</B> Computation of angular distance between "
- "two objects whose positions are given in equatorial coordinates"
- "</LI><LI>"
- "<B>Geodetic Coords:</B> Geodetic/XYZ coordinate conversion"
- "</LI><LI>"
- "<B>LSR Velocity:</B> Computation of the heliocentric, geocentric "
- "and topocentric radial velocity of a source from its LSR velocity"
- "</LI></UL>"
- "</QT>"));
- acStack->setCurrentWidget( splashScreen );
-}
-
-void AstroCalc::genSolarText(void)
-{
- splashScreen->setHtml(i18n("<QT>"
- "Section with algorithms regarding information "
- "on solar system bodies coordinates and times"
- "<UL><LI>"
- "<B>Planets Coords:</B> Coordinates for the planets, moon and sun "
- "at a given time and from a given position on Earth "
- "</LI></UL>"
- "</QT>"));
- acStack->setCurrentWidget( splashScreen );
-}
-
QSize AstroCalc::sizeHint() const
{
return QSize(640,430);
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.h #970530:970531
@@ -52,27 +52,12 @@
Q_OBJECT
public:
- /** construtor */
AstroCalc(QWidget *parent = 0);
- /** destructor */
~AstroCalc();
- /**Generate explanatory text for time modules. */
- void genTimeText(void);
-
- /**Generate explanatory text for coordinate modules. */
- void genCoordText(void);
-
- /**Generate explanatory text for geodetic modules. */
- void genGeodText(void);
-
- /**Generate explanatory text for solar system modules. */
- void genSolarText(void);
-
/**@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.
More information about the Kstars-devel
mailing list